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.367 by root, Fri Apr 27 00:59:14 2007 UTC vs.
Revision 1.387 by root, Fri Jul 20 18:19:45 2007 UTC

268 $self->hide; 268 $self->hide;
269 $self->emit ("destroy"); 269 $self->emit ("destroy");
270 %$self = (); 270 %$self = ();
271} 271}
272 272
273sub TO_JSON {
274 { __widget_ref__ => $_[0]{s_id} }
275}
276
273sub show { 277sub show {
274 my ($self) = @_; 278 my ($self) = @_;
275 279
276 return if $self->{parent}; 280 return if $self->{parent};
277 281
316sub set_visibility { 320sub set_visibility {
317 my ($self, $visible) = @_; 321 my ($self, $visible) = @_;
318 322
319 return if $self->{visible} == $visible; 323 return if $self->{visible} == $visible;
320 324
321 $visible ? $self->hide 325 $visible ? $self->show
322 : $self->show; 326 : $self->hide;
323} 327}
324 328
325sub toggle_visibility { 329sub toggle_visibility {
326 my ($self) = @_; 330 my ($self) = @_;
327 331
543 547
544 # parent 548 # parent
545 $self->{parent} && $self->{parent}->emit ($signal, @args) 549 $self->{parent} && $self->{parent}->emit ($signal, @args)
546} 550}
547 551
548sub find_widget { 552#sub find_widget {
549 my ($self, $x, $y) = @_; 553# in .xs
550
551 return () unless $self->{can_events};
552
553 return $self
554 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
555 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
556
557 ()
558}
559 554
560sub set_parent { 555sub set_parent {
561 my ($self, $parent) = @_; 556 my ($self, $parent) = @_;
562 557
563 CFPlus::weaken ($self->{parent} = $parent); 558 CFPlus::weaken ($self->{parent} = $parent);
940 935
941############################################################################# 936#############################################################################
942 937
943package CFPlus::UI::ViewPort; 938package CFPlus::UI::ViewPort;
944 939
940use List::Util qw(min max);
941
945our @ISA = CFPlus::UI::Window::; 942our @ISA = CFPlus::UI::Window::;
946 943
947sub new { 944sub new {
948 my $class = shift; 945 my $class = shift;
949 946
980} 977}
981 978
982sub set_offset { 979sub set_offset {
983 my ($self, $x, $y) = @_; 980 my ($self, $x, $y) = @_;
984 981
982 my $x = max 0, min $self->child->{w} - $self->{w}, int $x;
983 my $y = max 0, min $self->child->{h} - $self->{h}, int $y;
984
985 if ($x != $self->{view_x} or $y != $self->{view_y}) {
985 $self->{view_x} = int $x; 986 $self->{view_x} = $x;
986 $self->{view_y} = int $y; 987 $self->{view_y} = $y;
987 988
989 $self->emit (changed => $x, $y);
988 $self->update; 990 $self->update;
991 }
989} 992}
990 993
991# hmm, this does not work for topleft of $self... but we should not ask for that 994# hmm, this does not work for topleft of $self... but we should not ask for that
992sub coord2local { 995sub coord2local {
993 my ($self, $x, $y) = @_; 996 my ($self, $x, $y) = @_;
1008 my ($self, $x, $y) = @_; 1011 my ($self, $x, $y) = @_;
1009 1012
1010 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 1013 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
1011 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1014 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
1012 ) { 1015 ) {
1013 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) 1016 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
1014 } else { 1017 } else {
1015 $self->CFPlus::UI::Base::find_widget ($x, $y) 1018 $self->CFPlus::UI::Base::find_widget ($x, $y)
1016 } 1019 }
1017} 1020}
1018 1021
1029 1032
1030############################################################################# 1033#############################################################################
1031 1034
1032package CFPlus::UI::ScrolledWindow; 1035package CFPlus::UI::ScrolledWindow;
1033 1036
1034our @ISA = CFPlus::UI::HBox::; 1037our @ISA = CFPlus::UI::Table::;
1035 1038
1036sub new { 1039sub new {
1037 my ($class, %arg) = @_; 1040 my ($class, %arg) = @_;
1038 1041
1039 my $child = delete $arg{child}; 1042 my $child = delete $arg{child};
1040 1043
1041 my $self; 1044 my $self;
1042 1045
1043 my $slider = new CFPlus::UI::Slider 1046 my $hslider = new CFPlus::UI::Slider
1047 vertical => 0,
1048 range => [0, 0, 1, 0.01], # HACK fix
1049 on_changed => sub {
1050 $self->{hpos} = $_[1];
1051 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1052 },
1053 ;
1054
1055 my $vslider = new CFPlus::UI::Slider
1044 vertical => 1, 1056 vertical => 1,
1045 range => [0, 0, 1, 0.01], # HACK fix 1057 range => [0, 0, 1, 0.01], # HACK fix
1046 on_changed => sub { 1058 on_changed => sub {
1047 $self->{vp}->set_offset (0, $_[1]); 1059 $self->{vpos} = $_[1];
1060 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1048 }, 1061 },
1049 ; 1062 ;
1050 1063
1051 $self = $class->SUPER::new ( 1064 $self = $class->SUPER::new (
1052 vp => (new CFPlus::UI::ViewPort expand => 1), 1065 scroll_x => 0,
1066 scroll_y => 1,
1053 can_events => 1, 1067 can_events => 1,
1054 slider => $slider, 1068 hslider => $hslider,
1069 vslider => $vslider,
1070 col_expand => [1, 0],
1071 row_expand => [1, 0],
1055 %arg, 1072 %arg,
1056 ); 1073 );
1057 1074
1058 $self->SUPER::add ($self->{vp}, $self->{slider}); 1075 $self->{vp} = new CFPlus::UI::ViewPort
1076 expand => 1,
1077 scroll_x => $self->{scroll_x},
1078 scroll_y => $self->{scroll_y},
1079 on_changed => sub {
1080 my ($vp, $x, $y) = @_;
1081
1082 $vp->{parent}{hslider}->set_value ($x);
1083 $vp->{parent}{vslider}->set_value ($y);
1084
1085 0
1086 },
1087 ;
1088
1089 $self->SUPER::add_at (0, 0, $self->{vp});
1090
1059 $self->add ($child) if $child; 1091 $self->add ($child) if $child;
1060 1092
1061 $self 1093 $self
1062} 1094}
1063 1095
1067 my ($self, $widget) = @_; 1099 my ($self, $widget) = @_;
1068 1100
1069 $self->{vp}->add ($self->{child} = $widget); 1101 $self->{vp}->add ($self->{child} = $widget);
1070} 1102}
1071 1103
1104sub update_slider {
1105 my ($self) = @_;
1106
1107 my $child = ($self->{vp} or return)->child;
1108
1109 my ($w1, $w2) = ($child->{w}, $self->{vp}{w});
1110 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]);
1111
1112 my $visible = $w1 > $w2;
1113 if ($visible != $self->{hslider}{visible}) {
1114 $visible ? $self->SUPER::add_at (0, 1, $self->{hslider})
1115 : $self->{hslider}->hide;
1116 }
1117
1118 my ($h1, $h2) = ($child->{h}, $self->{vp}{h});
1119 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]);
1120
1121 my $visible = $h1 > $h2;
1122 if ($visible != $self->{vslider}{visible}) {
1123 $visible ? $self->SUPER::add_at (1, 0, $self->{vslider})
1124 : $self->{vslider}->hide;
1125 }
1126}
1127
1128sub update {
1129 my ($self) = @_;
1130
1131 $self->update_slider;
1132 $self->SUPER::update;
1133}
1134
1072sub invoke_mouse_wheel { 1135sub invoke_mouse_wheel {
1073 my ($self, $ev) = @_; 1136 my ($self, $ev) = @_;
1074 1137
1075 return 0 unless $ev->{dy}; # only vertical movements 1138 return 0 unless $ev->{dy}; # only vertical movements for now
1076 1139
1077 $self->{slider}->emit (mouse_wheel => $ev); 1140 $self->{vslider}->emit (mouse_wheel => $ev);
1078 1141
1079 1 1142 1
1080} 1143}
1081 1144
1082sub update_slider { 1145sub invoke_button_down {
1083 my ($self) = @_; 1146 my ($self, $ev, $x, $y) = @_;
1084 1147
1085 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); 1148 if ($ev->{button} == 2) {
1086} 1149 $self->grab_focus;
1087 1150
1088sub update { 1151 my $ox = $self->{vp}{view_x} + $ev->{x};
1089 my ($self) = @_; 1152 my $oy = $self->{vp}{view_y} + $ev->{y};
1153
1154 $self->{motion} = sub {
1155 my ($ev, $x, $y) = @_;
1090 1156
1091 $self->SUPER::update; 1157 $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y});
1158 $self->update;
1159 };
1092 1160
1093 $self->update_slider; 1161 return 1;
1162 }
1163
1164 0
1165}
1166
1167sub invoke_button_up {
1168 my ($self, $ev, $x, $y) = @_;
1169
1170 if (delete $self->{motion}) {
1171 return 1;
1172 }
1173
1174 0
1175}
1176
1177sub invoke_mouse_motion {
1178 my ($self, $ev, $x, $y) = @_;
1179
1180 if ($self->{motion}) {
1181 $self->{motion}->($ev, $x, $y);
1182 return 1;
1183 }
1184
1185 0
1094} 1186}
1095 1187
1096sub invoke_size_allocate { 1188sub invoke_size_allocate {
1097 my ($self, $w, $h) = @_; 1189 my ($self, $w, $h) = @_;
1098 1190
1099 $self->update_slider; 1191 $self->update_slider;
1100
1101 $self->SUPER::invoke_size_allocate ($w, $h) 1192 $self->SUPER::invoke_size_allocate ($w, $h)
1102} 1193}
1103 1194
1104############################################################################# 1195#############################################################################
1105 1196
1255 1346
1256my @border = 1347my @border =
1257 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1348 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1258 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1349 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1259 1350
1351my @icon =
1352 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1353 qw(x1_move.png x1_resize.png);
1354
1260sub new { 1355sub new {
1261 my ($class, %arg) = @_; 1356 my ($class, %arg) = @_;
1262 1357
1263 my $self = $class->SUPER::new ( 1358 my $self = $class->SUPER::new (
1264 bg => [1, 1, 1, 1], 1359 bg => [1, 1, 1, 1],
1432 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1527 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1433 1528
1434 my $border = $self->border; 1529 my $border = $self->border;
1435 1530
1436 glColor @{ $self->{border_bg} }; 1531 glColor @{ $self->{border_bg} };
1437 $border[0]->draw_quad_alpha (0, 0, $w, $border); 1532 $border[0]->draw_quad_alpha ( 0, 0, $w, $border);
1438 $border[1]->draw_quad_alpha (0, $border, $border, $ch); 1533 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch);
1439 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1534 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1440 $border[3]->draw_quad_alpha (0, $h - $border, $w, $border); 1535 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border);
1536
1537 # move
1538 my $w2 = ($w - $border) * .5;
1539 my $h2 = ($h - $border) * .5;
1540 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border);
1541 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border);
1542 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border);
1543
1544 # resize
1545 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border);
1546 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border)
1547 unless $self->{has_close_button};
1548 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border);
1549 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border);
1441 1550
1442 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1551 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1443 glColor @{ $self->{bg} }; 1552 glColor @{ $self->{bg} };
1444 1553
1445 # TODO: repeat texture not scale 1554 # TODO: repeat texture not scale
1476 1585
1477sub new { 1586sub new {
1478 my $class = shift; 1587 my $class = shift;
1479 1588
1480 $class->SUPER::new ( 1589 $class->SUPER::new (
1590 children => [],
1481 col_expand => [], 1591 col_expand => [],
1592 row_expand => [],
1482 @_, 1593 @_,
1483 ) 1594 )
1484} 1595}
1485 1596
1486sub children { 1597sub children {
1487 grep $_, map @$_, grep $_, @{ $_[0]{children} } 1598 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1488} 1599}
1489 1600
1601# TODO: store row/col info in child widget and use standard add/del
1490sub add { 1602sub add {
1491 my ($self) = shift; 1603 my $self = shift;
1604
1605 Carp::cluck "please use the add_at method instead of calling add, thank you.\n";#d#
1606 $self->add_at (@_);
1607}
1608
1609sub add_at {
1610 my $self = shift;
1492 1611
1493 while (@_) { 1612 while (@_) {
1494 my ($x, $y, $child) = splice @_, 0, 3, (); 1613 my ($col, $row, $child) = splice @_, 0, 3, ();
1614
1495 $child->set_parent ($self); 1615 $child->set_parent ($self);
1496 $self->{children}[$y][$x] = $child; 1616 $self->{children}[$row][$col] = $child;
1497 } 1617 }
1498 1618
1499 $self->{force_realloc} = 1; 1619 $self->{force_realloc} = 1;
1500 $self->{force_size_alloc} = 1; 1620 $self->{force_size_alloc} = 1;
1501 $self->realloc; 1621 $self->realloc;
1502} 1622}
1503 1623
1504sub remove { 1624sub remove {
1505 my ($self, $child) = @_; 1625 my ($self, $child) = @_;
1506 1626
1507 # TODO: not yet implemented 1627 for (@{ $self->{children} }) {
1628 for (@{ $_ || [] }) {
1629 $_ = undef if $_ == $child;
1630 }
1631 }
1508} 1632}
1509 1633
1510# TODO: move to container class maybe? send children a signal on removal? 1634# TODO: move to container class maybe? send children a signal on removal?
1511sub clear { 1635sub clear {
1512 my ($self) = @_; 1636 my ($self) = @_;
1561 my ($ws, $hs) = $self->get_wh; 1685 my ($ws, $hs) = $self->get_wh;
1562 1686
1563 my $req_w = (sum @$ws) || 1; 1687 my $req_w = (sum @$ws) || 1;
1564 my $req_h = (sum @$hs) || 1; 1688 my $req_h = (sum @$hs) || 1;
1565 1689
1566 # TODO: nicer code && do row_expand 1690 # TODO: nicer code
1567 my @col_expand = @{$self->{col_expand}}; 1691 my @col_expand = @{$self->{col_expand}};
1568 @col_expand = (1) x @$ws unless @col_expand; 1692 @col_expand = (1) x @$ws unless @col_expand;
1569 my $col_expand = (sum @col_expand) || 1; 1693 my $col_expand = (sum @col_expand) || 1;
1570 1694
1571 # linearly scale sizes
1572 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1695 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1573 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
1574 1696
1575 CFPlus::UI::harmonize $ws; 1697 CFPlus::UI::harmonize $ws;
1698
1699 my @row_expand = @{$self->{row_expand}};
1700 @row_expand = (1) x @$ws unless @row_expand;
1701 my $row_expand = (sum @row_expand) || 1;
1702
1703 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1704
1576 CFPlus::UI::harmonize $hs; 1705 CFPlus::UI::harmonize $hs;
1577 1706
1578 my $y; 1707 my $y;
1579 1708
1580 for my $r (0 .. $#{$self->{children}}) { 1709 for my $r (0 .. $#{$self->{children}}) {
1620 my ($self) = @_; 1749 my ($self) = @_;
1621 1750
1622 for (grep $_, @{$self->{children}}) { 1751 for (grep $_, @{$self->{children}}) {
1623 $_->draw for grep $_, @$_; 1752 $_->draw for grep $_, @$_;
1624 } 1753 }
1754}
1755
1756#############################################################################
1757
1758package CFPlus::UI::Fixed;
1759
1760use List::Util qw(min max);
1761
1762our @ISA = CFPlus::UI::Container::;
1763
1764sub add {
1765 my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_;
1766
1767 $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h];
1768 $self->SUPER::add ($child);
1769}
1770
1771sub _scale($$$) {
1772 my ($mode, $val, $max) = @_;
1773
1774 $mode eq "abs" ? $val
1775 : $mode eq "rel" ? $val * $max
1776 : 0
1777}
1778
1779sub size_request {
1780 my ($self) = @_;
1781
1782 my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0);
1783
1784 # determine overall size by querying abs widgets
1785 for my $child ($self->visible_children) {
1786 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} };
1787
1788 if ($pos eq "abs") {
1789 $w = _scale $size, $w, $child->{req_w};
1790 $h = _scale $size, $h, $child->{req_h};
1791
1792 $x1 = min $x1, $x; $x2 = max $x2, $x + $w;
1793 $y1 = min $y1, $y; $y2 = max $y2, $y + $h;
1794 }
1795 }
1796
1797 my $W = $x2 - $x1;
1798 my $H = $y2 - $y1;
1799
1800 # now layout remaining widgets
1801 for my $child ($self->visible_children) {
1802 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} };
1803
1804 if ($pos ne "abs") {
1805 $x = _scale $pos, $x, $W;
1806 $y = _scale $pos, $x, $H;
1807 $w = _scale $size, $w, $child->{req_w};
1808 $h = _scale $size, $h, $child->{req_h};
1809
1810 $x1 = min $x1, $x; $x2 = max $x2, $x + $w;
1811 $y1 = min $y1, $y; $y2 = max $y2, $y + $h;
1812 }
1813 }
1814
1815 my $W = $x2 - $x1;
1816 my $H = $y2 - $y1;
1817
1818 ($W, $H)
1819}
1820
1821sub invoke_size_allocate {
1822 my ($self, $W, $H) = @_;
1823
1824 for my $child ($self->visible_children) {
1825 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} };
1826
1827 $x = _scale $pos, $x, $W;
1828 $y = _scale $pos, $x, $H;
1829 $w = _scale $size, $w, $child->{req_w};
1830 $h = _scale $size, $h, $child->{req_h};
1831
1832 $child->configure ($x, $y, $w, $h);
1833 }
1834
1835 1
1625} 1836}
1626 1837
1627############################################################################# 1838#############################################################################
1628 1839
1629package CFPlus::UI::Box; 1840package CFPlus::UI::Box;
2187 2398
2188use CFPlus::OpenGL; 2399use CFPlus::OpenGL;
2189 2400
2190my @tex = 2401my @tex =
2191 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2402 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2192 qw(b1_button_active.png); 2403 qw(b1_button_inactive.png b1_button_active.png);
2193 2404
2194sub new { 2405sub new {
2195 my $class = shift; 2406 my $class = shift;
2196 2407
2197 $class->SUPER::new ( 2408 $class->SUPER::new (
2198 padding_x => 4, 2409 padding_x => 4,
2199 padding_y => 4, 2410 padding_y => 4,
2200 fg => [1, 1, 1], 2411 fg => [1.0, 1.0, 1.0],
2201 active_fg => [0, 0, 1], 2412 active_fg => [0.8, 0.8, 0.8],
2202 can_hover => 1, 2413 can_hover => 1,
2203 align => 0, 2414 align => 0,
2204 valign => 0, 2415 valign => 0,
2205 can_events => 1, 2416 can_events => 1,
2206 @_ 2417 @_
2224 2435
2225 glEnable GL_TEXTURE_2D; 2436 glEnable GL_TEXTURE_2D;
2226 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2437 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2227 glColor 0, 0, 0, 1; 2438 glColor 0, 0, 0, 1;
2228 2439
2440 my $tex = $tex[$GRAB == $self];
2229 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2441 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2230 2442
2231 glDisable GL_TEXTURE_2D; 2443 glDisable GL_TEXTURE_2D;
2232 2444
2233 $self->SUPER::_draw; 2445 $self->SUPER::_draw;
2234} 2446}
3289 3501
3290sub new { 3502sub new {
3291 my $class = shift; 3503 my $class = shift;
3292 3504
3293 my $self = $class->SUPER::new ( 3505 my $self = $class->SUPER::new (
3506 size_w => 32,
3507 size_h => 8,
3294 aspect => 1, 3508 aspect => 1,
3295 can_events => 0, 3509 can_events => 0,
3296 @_, 3510 @_,
3297 ); 3511 );
3298 3512
3299 if ($self->{anim} && $self->{animspeed}) { 3513 if ($self->{anim} && $self->{animspeed}) {
3300 CFPlus::weaken (my $widget = $self); 3514 CFPlus::weaken (my $widget = $self);
3301 3515
3516 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3517 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed};
3302 $self->{timer} = Event->timer ( 3518 $self->{timer} = Event->timer (
3303 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3304 hard => 1, 3519 parked => 1,
3305 interval => $self->{animspeed},
3306 cb => sub { 3520 cb => sub {
3521 return unless $::CONN && $widget;
3522
3307 ++$widget->{frame}; 3523 ++$widget->{frame};
3524 $widget->update_face;
3308 $widget->update; 3525 $widget->update;
3526
3527 $widget->update_timer;
3309 }, 3528 },
3310 ); 3529 );
3530
3531 $self->update_face;
3532 $self->update_timer;
3311 } 3533 }
3312 3534
3313 $self 3535 $self
3314} 3536}
3315 3537
3538sub update_timer {
3539 my ($self) = @_;
3540
3541 return unless $self->{timer};
3542
3543 if ($self->{visible}) {
3544 $self->{timer}->at (
3545 $self->{anim_start}
3546 + $self->{animspeed}
3547 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed}
3548 );
3549 $self->{timer}->start;
3550 } else {
3551 $self->{timer}->stop;
3552 }
3553}
3554
3555sub update_face {
3556 my ($self) = @_;
3557
3558 return unless $::CONN;
3559
3560 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3561 if ($anim && @$anim) {
3562 delete $self->{wait_face};
3563 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3564 }
3565 }
3566}
3567
3316sub size_request { 3568sub size_request {
3317 (32, 8) 3569 my ($self) = @_;
3570
3571 if ($::CONN) {
3572 if (my $faceid = $::CONN->{faceid}[$self->{face}]) {
3573 if (my $tex = $::CONN->{texture}[$faceid]) {
3574 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3575 } else {
3576 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub {
3577 $self->realloc;
3578 });
3579 }
3580 }
3581 }
3582
3583 ($self->{size_w} || 8, $self->{size_h} || 8)
3318} 3584}
3319 3585
3320sub update { 3586sub update {
3321 my ($self) = @_; 3587 my ($self) = @_;
3322 3588
3323 return unless $self->{visible}; 3589 return unless $self->{visible};
3324 3590
3325 $self->SUPER::update; 3591 $self->SUPER::update;
3326} 3592}
3327 3593
3594sub invoke_visibility_change {
3595 my ($self) = @_;
3596
3597 $self->update_timer;
3598
3599 0
3600}
3601
3328sub _draw { 3602sub _draw {
3329 my ($self) = @_; 3603 my ($self) = @_;
3330 3604
3331 return unless $::CONN; 3605 return unless $::CONN;
3332 3606
3333 $self->SUPER::_draw; 3607 $self->SUPER::_draw;
3334 3608
3335 my $face;
3336
3337 if ($self->{frame}) {
3338 my $anim = $::CONN->{anim}[$self->{anim}]; 3609 my $faceid = $::CONN->{faceid}[$self->{face}]
3339 3610 or return;
3340 $face = $anim->[ $self->{frame} % @$anim ]
3341 if $anim && @$anim;
3342 }
3343 3611
3344 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; 3612 my $tex = $::CONN->{texture}[$faceid];
3345 3613
3346 if ($tex) { 3614 if ($tex) {
3347 glEnable GL_TEXTURE_2D; 3615 glEnable GL_TEXTURE_2D;
3348 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3616 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3349 glColor 0, 0, 0, 1; 3617 glColor 0, 0, 0, 1;
3353} 3621}
3354 3622
3355sub destroy { 3623sub destroy {
3356 my ($self) = @_; 3624 my ($self) = @_;
3357 3625
3358 $self->{timer}->cancel 3626 (delete $self->{timer})->cancel
3359 if $self->{timer}; 3627 if $self->{timer};
3360 3628
3361 $self->SUPER::destroy; 3629 $self->SUPER::destroy;
3362} 3630}
3363 3631
4007 while ($self->{post_alloc_hook}) { 4275 while ($self->{post_alloc_hook}) {
4008 $_->() 4276 $_->()
4009 for values %{delete $self->{post_alloc_hook}}; 4277 for values %{delete $self->{post_alloc_hook}};
4010 } 4278 }
4011 4279
4012
4013 glViewport 0, 0, $::WIDTH, $::HEIGHT; 4280 glViewport 0, 0, $::WIDTH, $::HEIGHT;
4014 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 4281 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
4015 glClear GL_COLOR_BUFFER_BIT; 4282 glClear GL_COLOR_BUFFER_BIT;
4016 4283
4017 glMatrixMode GL_PROJECTION; 4284 glMatrixMode GL_PROJECTION;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines