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.104 by elmex, Fri Apr 14 14:02:52 2006 UTC vs.
Revision 1.105 by root, Fri Apr 14 14:55:28 2006 UTC

61 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 61 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
62 62
63 if ($widget != $HOVER) { 63 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget; 64 my $hover = $HOVER; $HOVER = $widget;
65 65
66 $hover->update if $hover; 66 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER; 67 $HOVER->update if $HOVER && $HOVER->{can_hover};
68 } 68 }
69 69
70 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; 70 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER;
71} 71}
72 72
439} 439}
440 440
441sub render_chld { 441sub render_chld {
442 my ($self) = @_; 442 my ($self) = @_;
443 443
444 $self->{texture} = 444 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
445 CFClient::Texture->new_from_opengl ( 445 glClearColor 0, 0, 0, 1;
446 $self->{w}, $self->{h}, sub { $self->child->draw } 446 glClear GL_COLOR_BUFFER_BIT;
447 ); 447 $self->child->draw;
448 };
448} 449}
449 450
450sub size_allocate { 451sub size_allocate {
451 my ($self, $x, $y, $w, $h) = @_; 452 my ($self, $x, $y, $w, $h) = @_;
452 453
831 } 832 }
832 833
833 my $y = 0; 834 my $y = 0;
834 for (0 .. $#$children) { 835 for (0 .. $#$children) {
835 my $child = $children->[$_]; 836 my $child = $children->[$_];
836 my $h = $h[$_]; 837 my $h = int $h[$_];
837 $child->size_allocate ($y, 0, $h, $w); 838 $child->size_allocate ($y, 0, $h, $w);
838 839
839 $y += $h; 840 $y += $h;
840 } 841 }
841} 842}
885 } 886 }
886 887
887 my $y = 0; 888 my $y = 0;
888 for (0 .. $#$children) { 889 for (0 .. $#$children) {
889 my $child = $children->[$_]; 890 my $child = $children->[$_];
890 my $h = $h[$_]; 891 my $h = int $h[$_];
891 $child->size_allocate (0, $y, $w, $h); 892 $child->size_allocate (0, $y, $w, $h);
892 893
893 $y += $h; 894 $y += $h;
894 } 895 }
895} 896}
904 905
905sub new { 906sub new {
906 my ($class, %arg) = @_; 907 my ($class, %arg) = @_;
907 908
908 my $self = $class->SUPER::new ( 909 my $self = $class->SUPER::new (
909 fg => [1, 1, 1], 910 fg => [1, 1, 1],
910 height => $::FONTSIZE, 911 fontsize => $::FONTSIZE,
911 text => "", 912 text => "",
912 align => -1, 913 align => -1,
913 padding => 2, 914 padding => 2,
914 layout => new CFClient::Layout, 915 layout => new CFClient::Layout,
915 %arg 916 %arg
916 ); 917 );
917 918
918 $self->set_text ($self->{text}); 919 $self->set_text ($self->{text});
919 920
949 950
950sub size_request { 951sub size_request {
951 my ($self) = @_; 952 my ($self) = @_;
952 953
953 $self->{layout}->set_width; 954 $self->{layout}->set_width;
954 $self->{layout}->set_height ($self->{height}); 955 $self->{layout}->set_height ($self->{fontsize});
955 my ($w, $h) = $self->{layout}->size; 956 my ($w, $h) = $self->{layout}->size;
956 957
957 ( 958 (
958 $w + $self->{padding} * 2, 959 $w + $self->{padding} * 2,
959 $h + $self->{padding} * 2, 960 $h + $self->{padding} * 2,
978sub _draw { 979sub _draw {
979 my ($self) = @_; 980 my ($self) = @_;
980 981
981 my $tex = $self->{texture} ||= do { 982 my $tex = $self->{texture} ||= do {
982 $self->{layout}->set_width ($self->{w}); 983 $self->{layout}->set_width ($self->{w});
983 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); 984 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
984 new_from_layout CFClient::Texture $self->{layout} 985 new_from_layout CFClient::Texture $self->{layout}
985 }; 986 };
986 987
987 glEnable GL_BLEND; 988 glEnable GL_BLEND;
988 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 989 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
989 glEnable GL_TEXTURE_2D; 990 glEnable GL_TEXTURE_2D;
990 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 991 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
991 992
992 glColor @{$self->{fg}}; 993 glColor @{$self->{fg}};
993 994
994 my $x = 995 my $x =
995 $self->{align} < 0 ? $self->{padding} 996 $self->{align} < 0 ? $self->{padding}
996 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 997 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
997 : ($self->{w} - $tex->{w}) * 0.5; 998 : ($self->{w} - $tex->{w}) * 0.5;
998 999
999 glTranslate int $x, int +($self->{h} - $tex->{h}) * 0.5, 0; 1000 $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5);
1000 $tex->draw_quad (0, 0);
1001 1001
1002 glDisable GL_TEXTURE_2D; 1002 glDisable GL_TEXTURE_2D;
1003 glDisable GL_BLEND; 1003 glDisable GL_BLEND;
1004} 1004}
1005 1005
1033 1033
1034 $self->{last_activity} = $::NOW; 1034 $self->{last_activity} = $::NOW;
1035 1035
1036 $self->{text} = $text; 1036 $self->{text} = $text;
1037 $self->{layout}->set_width ($self->{w}); 1037 $self->{layout}->set_width ($self->{w});
1038 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); 1038 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1039 1039
1040 $text =~ s/./*/g if $self->{hidden}; 1040 $text =~ s/./*/g if $self->{hidden};
1041 1041
1042 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1042 $self->{layout}->set_markup ($self->escape_text ($text) . " ");
1043 1043
1465 1465
1466sub new { 1466sub new {
1467 my $class = shift; 1467 my $class = shift;
1468 1468
1469 my $self = $class->SUPER::new ( 1469 my $self = $class->SUPER::new (
1470 req_w => $::WIDTH / 6,
1471 req_h => $::HEIGHT / 6,
1472 fontsize => $::FONTSIZE,
1473 @_,
1474
1475 layout => (new CFClient::Layout),
1470 par => [], 1476 par => [],
1471 @_, 1477 height => 0,
1472 children => [ 1478 children => [
1473 (new CFClient::UI::Empty expand => 1), 1479 (new CFClient::UI::Empty expand => 1),
1474 (new CFClient::UI::Slider vertical => 1), 1480 (new CFClient::UI::Slider vertical => 1),
1475 ], 1481 ],
1476 ); 1482 );
1477 1483
1478 $self 1484 $self
1479} 1485}
1480 1486
1487sub text_height {
1488 my ($self, $text) = @_;
1489
1490 my $layout = $self->{layout};
1491
1492 $layout->set_height ($self->{fontsize});
1493 $layout->set_width ($self->{w});
1494 $layout->set_text ($text);
1495
1496 ($layout->size)[1]
1497}
1498
1499sub reflow {
1500 my ($self) = @_;
1501
1502 my $height = 0;
1503
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}
1512
1513sub size_request {
1514 my ($self) = @_;
1515
1516 ($self->{req_w}, $self->{req_h})
1517}
1518
1519sub size_allocate {
1520 my ($self, $x, $y, $w, $h) = @_;
1521
1522 $self->SUPER::size_allocate ($x, $y, $w, $h);
1523
1524 $self->{layout}->set_height ($self->{fontsize});
1525 $self->{layout}->set_width ($self->{w});
1526
1527 $self->reflow;
1528 $self->update;
1529}
1530
1481sub add_paragraph { 1531sub add_paragraph {
1482 my ($self, $color, $text) = @_; 1532 my ($self, $color, $text) = @_;
1483 1533
1534 #TODO: intelligently "reformat" paragraph
1535
1536 my $height = $self->text_height ($text);
1537
1538 $self->{height} += $height;
1539
1484 push @{$self->{par}}, [$color, $text]; 1540 push @{$self->{par}}, [$height, $color, $text];
1485 my $count = scalar @{$self->{par}}; 1541
1486 $self->{children}[1]{range} = [$count - 1, 0, $count, 1]; 1542 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
1487 $self->{children}[1]->update; 1543 $self->{children}[1]->update;
1488} 1544}
1489 1545
1546sub update {
1547 my ($self) = @_;
1548
1549 $self->SUPER::update;
1550
1551 return unless $self->{h} > 0;
1552
1553 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
1554 glClearColor 0, 0, 0, 1;
1555 glClear GL_COLOR_BUFFER_BIT;
1556
1557 my $y0 = $self->{height} - $self->{h};
1558 my $y1 = $self->{height};
1559
1560 glEnable GL_BLEND;
1561 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1562 glEnable GL_TEXTURE_2D;
1563 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1564
1565 my $y = 0;
1566
1567 my $layout = $self->{layout};
1568
1569 for my $par (@{$self->{par}}) {
1570 my $h = $par->[0];
1571
1572 if ($y0 < $y + $h && $y < $y1) {
1573 $layout->set_text ($par->[2]);
1574
1575 glColor @{ $par->[1] };
1576 my ($W, $H) = $layout->size;
1577 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0);
1578 }
1579
1580 $y += $h;
1581 }
1582
1583 glDisable GL_TEXTURE_2D;
1584 glDisable GL_BLEND;
1585 };
1586}
1587
1490sub _draw { 1588sub _draw {
1491 my ($self) = @_; 1589 my ($self) = @_;
1492 1590
1493 my $par = $self->{par}; 1591 if ($self->{texture}) {
1494
1495 my $bottom = (scalar @$par) - 1;
1496
1497 my $w = $self->{children}[0]{w};
1498 my $y = $self->{h};
1499
1500 glEnable GL_BLEND;
1501 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1502 glEnable GL_TEXTURE_2D; 1592 glEnable GL_TEXTURE_2D;
1503 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1593 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1504 1594 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
1505 # TODO: everything!
1506 while ($y > 0 && $bottom >= 0) {
1507 my $par = $par->[$bottom--];
1508
1509 my $layout = new CFClient::Layout;
1510
1511 $layout->set_height ($::FONTSIZE);
1512 $layout->set_width ($w);
1513 $layout->set_text ($par->[1]);
1514 my $tex = new_from_layout CFClient::Texture $layout;
1515 $y -= $tex->{h};
1516
1517 glColor @{ $par->[0] };
1518 $tex->draw_quad (0, $y);
1519 }
1520
1521 glDisable GL_TEXTURE_2D; 1595 glDisable GL_TEXTURE_2D;
1522 glDisable GL_BLEND; 1596 }
1597
1523} 1598}
1524 1599
1525############################################################################# 1600#############################################################################
1526 1601
1527package CFClient::UI::MapWidget; 1602package CFClient::UI::MapWidget;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines