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.105 by root, Fri Apr 14 14:55:28 2006 UTC vs.
Revision 1.107 by root, Fri Apr 14 20:27:35 2006 UTC

732 my $col_expand = (sum @col_expand) || 1; 732 my $col_expand = (sum @col_expand) || 1;
733 733
734 # linearly scale sizes 734 # linearly scale sizes
735 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 735 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
736 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; 736 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
737
738 $_ = int $_ for @$ws; #TODO: avoid rounding problems
739 $_ = int $_ for @$hs; #TODO: avoid rounding problems
737 740
738 my $y; 741 my $y;
739 742
740 for my $r (0 .. $#{$self->{children}}) { 743 for my $r (0 .. $#{$self->{children}}) {
741 my $row = $self->{children}[$r] 744 my $row = $self->{children}[$r]
1424 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1427 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1425 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 1428 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1426 1429
1427 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1430 my ($value, $lo, $hi, $page) = @{$self->{range}};
1428 1431
1432 $hi = $value + 1 if $lo == $hi;
1433
1429 my $inner_pad_px = $self->_calc_inner_pad_px ($w); 1434 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
1430 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
1431 1436
1432 $page = int $page * $inner_w / ($hi - $lo); 1437 $page = int $page * $inner_w / ($hi - $lo);
1433 $value = int +($value - $lo) * $inner_w / ($hi - $lo); 1438 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
1479 (new CFClient::UI::Empty expand => 1), 1484 (new CFClient::UI::Empty expand => 1),
1480 (new CFClient::UI::Slider vertical => 1), 1485 (new CFClient::UI::Slider vertical => 1),
1481 ], 1486 ],
1482 ); 1487 );
1483 1488
1489 $self->{children}[1]->connect (changed => sub {
1490 $self->update;
1491 });
1492
1484 $self 1493 $self
1494}
1495
1496sub set_fontsize {
1497 my ($self, $fontsize) = @_;
1498
1499 $self->{fontsize} = $fontsize;
1500 $self->reflow;
1485} 1501}
1486 1502
1487sub text_height { 1503sub text_height {
1488 my ($self, $text) = @_; 1504 my ($self, $text) = @_;
1489 1505
1497} 1513}
1498 1514
1499sub reflow { 1515sub reflow {
1500 my ($self) = @_; 1516 my ($self) = @_;
1501 1517
1502 my $height = 0; 1518 $self->{need_reflow}++;
1503 1519 $self->update;
1504 for (@{$self->{par}}) {
1505 $height += $_->[0] = $self->text_height ($_->[2]);
1506 }
1507
1508 $self->{height} = $height;
1509
1510 $self->{range} = [$height - $self->{h}, 0, $height, $self->{h}];
1511} 1520}
1512 1521
1513sub size_request { 1522sub size_request {
1514 my ($self) = @_; 1523 my ($self) = @_;
1515 1524
1523 1532
1524 $self->{layout}->set_height ($self->{fontsize}); 1533 $self->{layout}->set_height ($self->{fontsize});
1525 $self->{layout}->set_width ($self->{w}); 1534 $self->{layout}->set_width ($self->{w});
1526 1535
1527 $self->reflow; 1536 $self->reflow;
1528 $self->update;
1529} 1537}
1530 1538
1531sub add_paragraph { 1539sub add_paragraph {
1532 my ($self, $color, $text) = @_; 1540 my ($self, $color, $text) = @_;
1533 1541
1548 1556
1549 $self->SUPER::update; 1557 $self->SUPER::update;
1550 1558
1551 return unless $self->{h} > 0; 1559 return unless $self->{h} > 0;
1552 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
1553 $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 {
1554 glClearColor 0, 0, 0, 1; 1578 glClearColor 0, 0, 0, 1;
1555 glClear GL_COLOR_BUFFER_BIT; 1579 glClear GL_COLOR_BUFFER_BIT;
1556 1580
1557 my $y0 = $self->{height} - $self->{h};
1558 my $y1 = $self->{height};
1559
1560 glEnable GL_BLEND; 1581 glEnable GL_BLEND;
1561 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1582 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1562 glEnable GL_TEXTURE_2D; 1583 glEnable GL_TEXTURE_2D;
1563 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1584 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1564 1585
1586 my $top = int $self->{children}[1]{range}[0];
1587
1588 my $y0 = $top;
1589 my $y1 = $top + $self->{h};
1590
1565 my $y = 0; 1591 my $y = 0;
1566 1592
1567 my $layout = $self->{layout}; 1593 my $layout = $self->{layout};
1568 1594
1569 for my $par (@{$self->{par}}) { 1595 for my $par (@{$self->{par}}) {
1570 my $h = $par->[0]; 1596 my $h = $par->[0];
1571 1597
1572 if ($y0 < $y + $h && $y < $y1) { 1598 if ($y0 < $y + $h && $y < $y1) {
1573 $layout->set_text ($par->[2]); 1599 $layout->set_text ($par->[2]);
1574 1600
1575 glColor @{ $par->[1] }; 1601 glColor @{ $par->[1] };
1576 my ($W, $H) = $layout->size; 1602 my ($W, $H) = $layout->size;
1577 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;
1578 } 1607 }
1579 1608
1580 $y += $h;
1581 }
1582
1583 glDisable GL_TEXTURE_2D; 1609 glDisable GL_TEXTURE_2D;
1584 glDisable GL_BLEND; 1610 glDisable GL_BLEND;
1611 };
1585 }; 1612 });
1586} 1613}
1587 1614
1588sub _draw { 1615sub _draw {
1589 my ($self) = @_; 1616 my ($self) = @_;
1590 1617
1592 glEnable GL_TEXTURE_2D; 1619 glEnable GL_TEXTURE_2D;
1593 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1620 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1594 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 1621 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
1595 glDisable GL_TEXTURE_2D; 1622 glDisable GL_TEXTURE_2D;
1596 } 1623 }
1624
1625 $self->{children}[1]->draw;
1597 1626
1598} 1627}
1599 1628
1600############################################################################# 1629#############################################################################
1601 1630
1852 1881
1853package CFClient::UI::Toplevel; 1882package CFClient::UI::Toplevel;
1854 1883
1855our @ISA = CFClient::UI::Container::; 1884our @ISA = CFClient::UI::Container::;
1856 1885
1886use SDL::OpenGL;
1887
1857sub size_request { 1888sub size_request {
1858 ($::WIDTH, $::HEIGHT) 1889 ($::WIDTH, $::HEIGHT)
1859} 1890}
1860 1891
1861sub size_allocate { 1892sub size_allocate {
1886 $self->SUPER::add ($widget); 1917 $self->SUPER::add ($widget);
1887 1918
1888 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 1919 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request);
1889} 1920}
1890 1921
1922sub on_refresh {
1923 my ($self, $id, $cb) = @_;
1924
1925 $self->{refresh_hook}{$id} = $cb;
1926}
1927
1891sub draw { 1928sub draw {
1892 my ($self) = @_; 1929 my ($self) = @_;
1893 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
1894 $self->_draw; 1945 $self->_draw;
1895} 1946}
1896 1947
1897############################################################################# 1948#############################################################################
1898 1949

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines