ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.106 by root, Fri Apr 14 15:14:25 2006 UTC vs.
Revision 1.107 by root, Fri Apr 14 20:27:35 2006 UTC

1427 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1427 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1428 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 1428 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1429 1429
1430 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1430 my ($value, $lo, $hi, $page) = @{$self->{range}};
1431 1431
1432 $hi = $value + 1 if $lo == $hi;
1433
1432 my $inner_pad_px = $self->_calc_inner_pad_px ($w); 1434 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
1433 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right 1435 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1434 1436
1435 $page = int $page * $inner_w / ($hi - $lo); 1437 $page = int $page * $inner_w / ($hi - $lo);
1436 $value = int +($value - $lo) * $inner_w / ($hi - $lo); 1438 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
1482 (new CFClient::UI::Empty expand => 1), 1484 (new CFClient::UI::Empty expand => 1),
1483 (new CFClient::UI::Slider vertical => 1), 1485 (new CFClient::UI::Slider vertical => 1),
1484 ], 1486 ],
1485 ); 1487 );
1486 1488
1489 $self->{children}[1]->connect (changed => sub {
1490 $self->update;
1491 });
1492
1487 $self 1493 $self
1494}
1495
1496sub set_fontsize {
1497 my ($self, $fontsize) = @_;
1498
1499 $self->{fontsize} = $fontsize;
1500 $self->reflow;
1488} 1501}
1489 1502
1490sub text_height { 1503sub text_height {
1491 my ($self, $text) = @_; 1504 my ($self, $text) = @_;
1492 1505
1500} 1513}
1501 1514
1502sub reflow { 1515sub reflow {
1503 my ($self) = @_; 1516 my ($self) = @_;
1504 1517
1505 my $height = 0; 1518 $self->{need_reflow}++;
1506 1519 $self->update;
1507 for (@{$self->{par}}) {
1508 $height += $_->[0] = $self->text_height ($_->[2]);
1509 }
1510
1511 $self->{height} = $height;
1512
1513 $self->{range} = [$height - $self->{h}, 0, $height, $self->{h}];
1514} 1520}
1515 1521
1516sub size_request { 1522sub size_request {
1517 my ($self) = @_; 1523 my ($self) = @_;
1518 1524
1526 1532
1527 $self->{layout}->set_height ($self->{fontsize}); 1533 $self->{layout}->set_height ($self->{fontsize});
1528 $self->{layout}->set_width ($self->{w}); 1534 $self->{layout}->set_width ($self->{w});
1529 1535
1530 $self->reflow; 1536 $self->reflow;
1531 $self->update;
1532} 1537}
1533 1538
1534sub add_paragraph { 1539sub add_paragraph {
1535 my ($self, $color, $text) = @_; 1540 my ($self, $color, $text) = @_;
1536 1541
1551 1556
1552 $self->SUPER::update; 1557 $self->SUPER::update;
1553 1558
1554 return unless $self->{h} > 0; 1559 return unless $self->{h} > 0;
1555 1560
1561 delete $self->{texture};
1562
1563 $TOPLEVEL->on_refresh ($self, sub {
1564 if (delete $self->{need_reflow}) {
1565 my $height = 0;
1566
1567 $height += $_->[0] = $self->text_height ($_->[2])
1568 for @{$self->{par}};
1569
1570 $self->{height} = $height;
1571
1572 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
1573
1574 delete $self->{texture};
1575 }
1576
1556 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 1577 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
1557 glClearColor 0, 0, 0, 1; 1578 glClearColor 0, 0, 0, 1;
1558 glClear GL_COLOR_BUFFER_BIT; 1579 glClear GL_COLOR_BUFFER_BIT;
1559 1580
1560 my $y0 = $self->{height} - $self->{h};
1561 my $y1 = $self->{height};
1562
1563 glEnable GL_BLEND; 1581 glEnable GL_BLEND;
1564 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1582 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1565 glEnable GL_TEXTURE_2D; 1583 glEnable GL_TEXTURE_2D;
1566 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1584 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1567 1585
1586 my $top = int $self->{children}[1]{range}[0];
1587
1588 my $y0 = $top;
1589 my $y1 = $top + $self->{h};
1590
1568 my $y = 0; 1591 my $y = 0;
1569 1592
1570 my $layout = $self->{layout}; 1593 my $layout = $self->{layout};
1571 1594
1572 for my $par (@{$self->{par}}) { 1595 for my $par (@{$self->{par}}) {
1573 my $h = $par->[0]; 1596 my $h = $par->[0];
1574 1597
1575 if ($y0 < $y + $h && $y < $y1) { 1598 if ($y0 < $y + $h && $y < $y1) {
1576 $layout->set_text ($par->[2]); 1599 $layout->set_text ($par->[2]);
1577 1600
1578 glColor @{ $par->[1] }; 1601 glColor @{ $par->[1] };
1579 my ($W, $H) = $layout->size; 1602 my ($W, $H) = $layout->size;
1580 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); 1603 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0);
1604 }
1605
1606 $y += $h;
1581 } 1607 }
1582 1608
1583 $y += $h;
1584 }
1585
1586 glDisable GL_TEXTURE_2D; 1609 glDisable GL_TEXTURE_2D;
1587 glDisable GL_BLEND; 1610 glDisable GL_BLEND;
1611 };
1588 }; 1612 });
1589} 1613}
1590 1614
1591sub _draw { 1615sub _draw {
1592 my ($self) = @_; 1616 my ($self) = @_;
1593 1617
1857 1881
1858package CFClient::UI::Toplevel; 1882package CFClient::UI::Toplevel;
1859 1883
1860our @ISA = CFClient::UI::Container::; 1884our @ISA = CFClient::UI::Container::;
1861 1885
1886use SDL::OpenGL;
1887
1862sub size_request { 1888sub size_request {
1863 ($::WIDTH, $::HEIGHT) 1889 ($::WIDTH, $::HEIGHT)
1864} 1890}
1865 1891
1866sub size_allocate { 1892sub size_allocate {
1891 $self->SUPER::add ($widget); 1917 $self->SUPER::add ($widget);
1892 1918
1893 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 1919 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request);
1894} 1920}
1895 1921
1922sub on_refresh {
1923 my ($self, $id, $cb) = @_;
1924
1925 $self->{refresh_hook}{$id} = $cb;
1926}
1927
1896sub draw { 1928sub draw {
1897 my ($self) = @_; 1929 my ($self) = @_;
1898 1930
1931 while (my $rcb = delete $self->{refresh_hook}) {
1932 $_->() for values %$rcb;
1933 }
1934
1935 glViewport 0, 0, $::WIDTH, $::HEIGHT;
1936 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
1937 glClear GL_COLOR_BUFFER_BIT;
1938
1939 glMatrixMode GL_PROJECTION;
1940 glLoadIdentity;
1941 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000;
1942 glMatrixMode GL_MODELVIEW;
1943 glLoadIdentity;
1944
1899 $self->_draw; 1945 $self->_draw;
1900} 1946}
1901 1947
1902############################################################################# 1948#############################################################################
1903 1949

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines