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.364 by root, Sat Dec 23 10:18:27 2006 UTC vs.
Revision 1.387 by root, Fri Jul 20 18:19:45 2007 UTC

22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { 22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub {
23 if (!$GRAB) { 23 if (!$GRAB) {
24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
25 if (length $widget->{tooltip}) { 25 if (length $widget->{tooltip}) {
26 if ($TOOLTIP->{owner} != $widget) { 26 if ($TOOLTIP->{owner} != $widget) {
27 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
27 $TOOLTIP->hide; 28 $TOOLTIP->hide;
28 29
29 $TOOLTIP->{owner} = $widget; 30 $TOOLTIP->{owner} = $widget;
31 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner};
30 32
31 return if $ENV{CFPLUS_DEBUG} & 8; 33 return if $ENV{CFPLUS_DEBUG} & 8;
32 34
33 my $tip = $widget->{tooltip}; 35 my $tip = $widget->{tooltip};
34 36
42 } 44 }
43 } 45 }
44 } 46 }
45 47
46 $TOOLTIP->hide; 48 $TOOLTIP->hide;
49 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
47 delete $TOOLTIP->{owner}; 50 delete $TOOLTIP->{owner};
48}); 51});
49 52
50sub get_layout { 53sub get_layout {
51 my $layout; 54 my $layout;
265 $self->hide; 268 $self->hide;
266 $self->emit ("destroy"); 269 $self->emit ("destroy");
267 %$self = (); 270 %$self = ();
268} 271}
269 272
273sub TO_JSON {
274 { __widget_ref__ => $_[0]{s_id} }
275}
276
270sub show { 277sub show {
271 my ($self) = @_; 278 my ($self) = @_;
272 279
273 return if $self->{parent}; 280 return if $self->{parent};
274 281
313sub set_visibility { 320sub set_visibility {
314 my ($self, $visible) = @_; 321 my ($self, $visible) = @_;
315 322
316 return if $self->{visible} == $visible; 323 return if $self->{visible} == $visible;
317 324
318 $visible ? $self->hide 325 $visible ? $self->show
319 : $self->show; 326 : $self->hide;
320} 327}
321 328
322sub toggle_visibility { 329sub toggle_visibility {
323 my ($self) = @_; 330 my ($self) = @_;
324 331
540 547
541 # parent 548 # parent
542 $self->{parent} && $self->{parent}->emit ($signal, @args) 549 $self->{parent} && $self->{parent}->emit ($signal, @args)
543} 550}
544 551
545sub find_widget { 552#sub find_widget {
546 my ($self, $x, $y) = @_; 553# in .xs
547
548 return () unless $self->{can_events};
549
550 return $self
551 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
552 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
553
554 ()
555}
556 554
557sub set_parent { 555sub set_parent {
558 my ($self, $parent) = @_; 556 my ($self, $parent) = @_;
559 557
560 CFPlus::weaken ($self->{parent} = $parent); 558 CFPlus::weaken ($self->{parent} = $parent);
937 935
938############################################################################# 936#############################################################################
939 937
940package CFPlus::UI::ViewPort; 938package CFPlus::UI::ViewPort;
941 939
940use List::Util qw(min max);
941
942our @ISA = CFPlus::UI::Window::; 942our @ISA = CFPlus::UI::Window::;
943 943
944sub new { 944sub new {
945 my $class = shift; 945 my $class = shift;
946 946
977} 977}
978 978
979sub set_offset { 979sub set_offset {
980 my ($self, $x, $y) = @_; 980 my ($self, $x, $y) = @_;
981 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}) {
982 $self->{view_x} = int $x; 986 $self->{view_x} = $x;
983 $self->{view_y} = int $y; 987 $self->{view_y} = $y;
984 988
989 $self->emit (changed => $x, $y);
985 $self->update; 990 $self->update;
991 }
986} 992}
987 993
988# 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
989sub coord2local { 995sub coord2local {
990 my ($self, $x, $y) = @_; 996 my ($self, $x, $y) = @_;
1005 my ($self, $x, $y) = @_; 1011 my ($self, $x, $y) = @_;
1006 1012
1007 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 1013 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
1008 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1014 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
1009 ) { 1015 ) {
1010 $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})
1011 } else { 1017 } else {
1012 $self->CFPlus::UI::Base::find_widget ($x, $y) 1018 $self->CFPlus::UI::Base::find_widget ($x, $y)
1013 } 1019 }
1014} 1020}
1015 1021
1026 1032
1027############################################################################# 1033#############################################################################
1028 1034
1029package CFPlus::UI::ScrolledWindow; 1035package CFPlus::UI::ScrolledWindow;
1030 1036
1031our @ISA = CFPlus::UI::HBox::; 1037our @ISA = CFPlus::UI::Table::;
1032 1038
1033sub new { 1039sub new {
1034 my ($class, %arg) = @_; 1040 my ($class, %arg) = @_;
1035 1041
1036 my $child = delete $arg{child}; 1042 my $child = delete $arg{child};
1037 1043
1038 my $self; 1044 my $self;
1039 1045
1040 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
1041 vertical => 1, 1056 vertical => 1,
1042 range => [0, 0, 1, 0.01], # HACK fix 1057 range => [0, 0, 1, 0.01], # HACK fix
1043 on_changed => sub { 1058 on_changed => sub {
1044 $self->{vp}->set_offset (0, $_[1]); 1059 $self->{vpos} = $_[1];
1060 $self->{vp}->set_offset ($self->{hpos}, $self->{vpos});
1045 }, 1061 },
1046 ; 1062 ;
1047 1063
1048 $self = $class->SUPER::new ( 1064 $self = $class->SUPER::new (
1049 vp => (new CFPlus::UI::ViewPort expand => 1), 1065 scroll_x => 0,
1066 scroll_y => 1,
1050 can_events => 1, 1067 can_events => 1,
1051 slider => $slider, 1068 hslider => $hslider,
1069 vslider => $vslider,
1070 col_expand => [1, 0],
1071 row_expand => [1, 0],
1052 %arg, 1072 %arg,
1053 ); 1073 );
1054 1074
1055 $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
1056 $self->add ($child) if $child; 1091 $self->add ($child) if $child;
1057 1092
1058 $self 1093 $self
1059} 1094}
1060 1095
1064 my ($self, $widget) = @_; 1099 my ($self, $widget) = @_;
1065 1100
1066 $self->{vp}->add ($self->{child} = $widget); 1101 $self->{vp}->add ($self->{child} = $widget);
1067} 1102}
1068 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
1069sub invoke_mouse_wheel { 1135sub invoke_mouse_wheel {
1070 my ($self, $ev) = @_; 1136 my ($self, $ev) = @_;
1071 1137
1072 return 0 unless $ev->{dy}; # only vertical movements 1138 return 0 unless $ev->{dy}; # only vertical movements for now
1073 1139
1074 $self->{slider}->emit (mouse_wheel => $ev); 1140 $self->{vslider}->emit (mouse_wheel => $ev);
1075 1141
1076 1 1142 1
1077} 1143}
1078 1144
1079sub update_slider { 1145sub invoke_button_down {
1080 my ($self) = @_; 1146 my ($self, $ev, $x, $y) = @_;
1081 1147
1082 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); 1148 if ($ev->{button} == 2) {
1083} 1149 $self->grab_focus;
1084 1150
1085sub update { 1151 my $ox = $self->{vp}{view_x} + $ev->{x};
1086 my ($self) = @_; 1152 my $oy = $self->{vp}{view_y} + $ev->{y};
1153
1154 $self->{motion} = sub {
1155 my ($ev, $x, $y) = @_;
1087 1156
1088 $self->SUPER::update; 1157 $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y});
1158 $self->update;
1159 };
1089 1160
1090 $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
1091} 1186}
1092 1187
1093sub invoke_size_allocate { 1188sub invoke_size_allocate {
1094 my ($self, $w, $h) = @_; 1189 my ($self, $w, $h) = @_;
1095 1190
1096 $self->update_slider; 1191 $self->update_slider;
1097
1098 $self->SUPER::invoke_size_allocate ($w, $h) 1192 $self->SUPER::invoke_size_allocate ($w, $h)
1099} 1193}
1100 1194
1101############################################################################# 1195#############################################################################
1102 1196
1252 1346
1253my @border = 1347my @border =
1254 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 1348 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1255 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);
1256 1350
1351my @icon =
1352 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
1353 qw(x1_move.png x1_resize.png);
1354
1257sub new { 1355sub new {
1258 my ($class, %arg) = @_; 1356 my ($class, %arg) = @_;
1259 1357
1260 my $self = $class->SUPER::new ( 1358 my $self = $class->SUPER::new (
1261 bg => [1, 1, 1, 1], 1359 bg => [1, 1, 1, 1],
1429 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1527 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1430 1528
1431 my $border = $self->border; 1529 my $border = $self->border;
1432 1530
1433 glColor @{ $self->{border_bg} }; 1531 glColor @{ $self->{border_bg} };
1434 $border[0]->draw_quad_alpha (0, 0, $w, $border); 1532 $border[0]->draw_quad_alpha ( 0, 0, $w, $border);
1435 $border[1]->draw_quad_alpha (0, $border, $border, $ch); 1533 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch);
1436 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1534 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1437 $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);
1438 1550
1439 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1551 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1440 glColor @{ $self->{bg} }; 1552 glColor @{ $self->{bg} };
1441 1553
1442 # TODO: repeat texture not scale 1554 # TODO: repeat texture not scale
1473 1585
1474sub new { 1586sub new {
1475 my $class = shift; 1587 my $class = shift;
1476 1588
1477 $class->SUPER::new ( 1589 $class->SUPER::new (
1590 children => [],
1478 col_expand => [], 1591 col_expand => [],
1592 row_expand => [],
1479 @_, 1593 @_,
1480 ) 1594 )
1481} 1595}
1482 1596
1483sub children { 1597sub children {
1484 grep $_, map @$_, grep $_, @{ $_[0]{children} } 1598 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1485} 1599}
1486 1600
1601# TODO: store row/col info in child widget and use standard add/del
1487sub add { 1602sub add {
1488 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;
1489 1611
1490 while (@_) { 1612 while (@_) {
1491 my ($x, $y, $child) = splice @_, 0, 3, (); 1613 my ($col, $row, $child) = splice @_, 0, 3, ();
1614
1492 $child->set_parent ($self); 1615 $child->set_parent ($self);
1493 $self->{children}[$y][$x] = $child; 1616 $self->{children}[$row][$col] = $child;
1494 } 1617 }
1495 1618
1496 $self->{force_realloc} = 1; 1619 $self->{force_realloc} = 1;
1497 $self->{force_size_alloc} = 1; 1620 $self->{force_size_alloc} = 1;
1498 $self->realloc; 1621 $self->realloc;
1499} 1622}
1500 1623
1501sub remove { 1624sub remove {
1502 my ($self, $child) = @_; 1625 my ($self, $child) = @_;
1503 1626
1504 # TODO: not yet implemented 1627 for (@{ $self->{children} }) {
1628 for (@{ $_ || [] }) {
1629 $_ = undef if $_ == $child;
1630 }
1631 }
1505} 1632}
1506 1633
1507# 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?
1508sub clear { 1635sub clear {
1509 my ($self) = @_; 1636 my ($self) = @_;
1558 my ($ws, $hs) = $self->get_wh; 1685 my ($ws, $hs) = $self->get_wh;
1559 1686
1560 my $req_w = (sum @$ws) || 1; 1687 my $req_w = (sum @$ws) || 1;
1561 my $req_h = (sum @$hs) || 1; 1688 my $req_h = (sum @$hs) || 1;
1562 1689
1563 # TODO: nicer code && do row_expand 1690 # TODO: nicer code
1564 my @col_expand = @{$self->{col_expand}}; 1691 my @col_expand = @{$self->{col_expand}};
1565 @col_expand = (1) x @$ws unless @col_expand; 1692 @col_expand = (1) x @$ws unless @col_expand;
1566 my $col_expand = (sum @col_expand) || 1; 1693 my $col_expand = (sum @col_expand) || 1;
1567 1694
1568 # linearly scale sizes
1569 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1695 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1570 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
1571 1696
1572 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
1573 CFPlus::UI::harmonize $hs; 1705 CFPlus::UI::harmonize $hs;
1574 1706
1575 my $y; 1707 my $y;
1576 1708
1577 for my $r (0 .. $#{$self->{children}}) { 1709 for my $r (0 .. $#{$self->{children}}) {
1617 my ($self) = @_; 1749 my ($self) = @_;
1618 1750
1619 for (grep $_, @{$self->{children}}) { 1751 for (grep $_, @{$self->{children}}) {
1620 $_->draw for grep $_, @$_; 1752 $_->draw for grep $_, @$_;
1621 } 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
1622} 1836}
1623 1837
1624############################################################################# 1838#############################################################################
1625 1839
1626package CFPlus::UI::Box; 1840package CFPlus::UI::Box;
1966 my $mod = $ev->{mod}; 2180 my $mod = $ev->{mod};
1967 my $sym = $ev->{sym}; 2181 my $sym = $ev->{sym};
1968 my $uni = $ev->{unicode}; 2182 my $uni = $ev->{unicode};
1969 2183
1970 my $text = $self->get_text; 2184 my $text = $self->get_text;
2185
2186 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
1971 2187
1972 if ($uni == 8) { 2188 if ($uni == 8) {
1973 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2189 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1974 } elsif ($uni == 127) { 2190 } elsif ($uni == 127) {
1975 substr $text, $self->{cursor}, 1, ""; 2191 substr $text, $self->{cursor}, 1, "";
2182 2398
2183use CFPlus::OpenGL; 2399use CFPlus::OpenGL;
2184 2400
2185my @tex = 2401my @tex =
2186 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } 2402 map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 }
2187 qw(b1_button_active.png); 2403 qw(b1_button_inactive.png b1_button_active.png);
2188 2404
2189sub new { 2405sub new {
2190 my $class = shift; 2406 my $class = shift;
2191 2407
2192 $class->SUPER::new ( 2408 $class->SUPER::new (
2193 padding_x => 4, 2409 padding_x => 4,
2194 padding_y => 4, 2410 padding_y => 4,
2195 fg => [1, 1, 1], 2411 fg => [1.0, 1.0, 1.0],
2196 active_fg => [0, 0, 1], 2412 active_fg => [0.8, 0.8, 0.8],
2197 can_hover => 1, 2413 can_hover => 1,
2198 align => 0, 2414 align => 0,
2199 valign => 0, 2415 valign => 0,
2200 can_events => 1, 2416 can_events => 1,
2201 @_ 2417 @_
2219 2435
2220 glEnable GL_TEXTURE_2D; 2436 glEnable GL_TEXTURE_2D;
2221 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2437 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2222 glColor 0, 0, 0, 1; 2438 glColor 0, 0, 0, 1;
2223 2439
2440 my $tex = $tex[$GRAB == $self];
2224 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2441 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2225 2442
2226 glDisable GL_TEXTURE_2D; 2443 glDisable GL_TEXTURE_2D;
2227 2444
2228 $self->SUPER::_draw; 2445 $self->SUPER::_draw;
2229} 2446}
2830 #font => default_font 3047 #font => default_font
2831 @_, 3048 @_,
2832 3049
2833 layout => (new CFPlus::Layout), 3050 layout => (new CFPlus::Layout),
2834 par => [], 3051 par => [],
3052 max_par => 0,
2835 height => 0, 3053 height => 0,
2836 children => [ 3054 children => [
2837 (new CFPlus::UI::Empty expand => 1), 3055 (new CFPlus::UI::Empty expand => 1),
2838 (new CFPlus::UI::Slider vertical => 1), 3056 (new CFPlus::UI::Slider vertical => 1),
2839 ], 3057 ],
2962 wrapped => 1, 3180 wrapped => 1,
2963 }; 3181 };
2964 3182
2965 $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; 3183 $self->add (@{ $para->{widget} }) if @{ $para->{widget} };
2966 push @{$self->{par}}, $para; 3184 push @{$self->{par}}, $para;
3185 }
3186
3187 if (my $max = $self->{max_par}) {
3188 shift @{$self->{par}} while @{$self->{par}} > $max;
2967 } 3189 }
2968 3190
2969 $self->{need_reflow}++; 3191 $self->{need_reflow}++;
2970 $self->update; 3192 $self->update;
2971} 3193}
3279 3501
3280sub new { 3502sub new {
3281 my $class = shift; 3503 my $class = shift;
3282 3504
3283 my $self = $class->SUPER::new ( 3505 my $self = $class->SUPER::new (
3506 size_w => 32,
3507 size_h => 8,
3284 aspect => 1, 3508 aspect => 1,
3285 can_events => 0, 3509 can_events => 0,
3286 @_, 3510 @_,
3287 ); 3511 );
3288 3512
3289 if ($self->{anim} && $self->{animspeed}) { 3513 if ($self->{anim} && $self->{animspeed}) {
3290 CFPlus::weaken (my $widget = $self); 3514 CFPlus::weaken (my $widget = $self);
3291 3515
3516 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3517 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed};
3292 $self->{timer} = Event->timer ( 3518 $self->{timer} = Event->timer (
3293 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3294 hard => 1, 3519 parked => 1,
3295 interval => $self->{animspeed},
3296 cb => sub { 3520 cb => sub {
3521 return unless $::CONN && $widget;
3522
3297 ++$widget->{frame}; 3523 ++$widget->{frame};
3524 $widget->update_face;
3298 $widget->update; 3525 $widget->update;
3526
3527 $widget->update_timer;
3299 }, 3528 },
3300 ); 3529 );
3530
3531 $self->update_face;
3532 $self->update_timer;
3301 } 3533 }
3302 3534
3303 $self 3535 $self
3304} 3536}
3305 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
3306sub size_request { 3568sub size_request {
3307 (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)
3308} 3584}
3309 3585
3310sub update { 3586sub update {
3311 my ($self) = @_; 3587 my ($self) = @_;
3312 3588
3313 return unless $self->{visible}; 3589 return unless $self->{visible};
3314 3590
3315 $self->SUPER::update; 3591 $self->SUPER::update;
3316} 3592}
3317 3593
3594sub invoke_visibility_change {
3595 my ($self) = @_;
3596
3597 $self->update_timer;
3598
3599 0
3600}
3601
3318sub _draw { 3602sub _draw {
3319 my ($self) = @_; 3603 my ($self) = @_;
3320 3604
3321 return unless $::CONN; 3605 return unless $::CONN;
3322 3606
3323 $self->SUPER::_draw; 3607 $self->SUPER::_draw;
3324 3608
3325 my $face;
3326
3327 if ($self->{frame}) {
3328 my $anim = $::CONN->{anim}[$self->{anim}]; 3609 my $faceid = $::CONN->{faceid}[$self->{face}]
3329 3610 or return;
3330 $face = $anim->[ $self->{frame} % @$anim ]
3331 if $anim && @$anim;
3332 }
3333 3611
3334 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; 3612 my $tex = $::CONN->{texture}[$faceid];
3335 3613
3336 if ($tex) { 3614 if ($tex) {
3337 glEnable GL_TEXTURE_2D; 3615 glEnable GL_TEXTURE_2D;
3338 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3616 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3339 glColor 0, 0, 0, 1; 3617 glColor 0, 0, 0, 1;
3343} 3621}
3344 3622
3345sub destroy { 3623sub destroy {
3346 my ($self) = @_; 3624 my ($self) = @_;
3347 3625
3348 $self->{timer}->cancel 3626 (delete $self->{timer})->cancel
3349 if $self->{timer}; 3627 if $self->{timer};
3350 3628
3351 $self->SUPER::destroy; 3629 $self->SUPER::destroy;
3352} 3630}
3353 3631
3997 while ($self->{post_alloc_hook}) { 4275 while ($self->{post_alloc_hook}) {
3998 $_->() 4276 $_->()
3999 for values %{delete $self->{post_alloc_hook}}; 4277 for values %{delete $self->{post_alloc_hook}};
4000 } 4278 }
4001 4279
4002
4003 glViewport 0, 0, $::WIDTH, $::HEIGHT; 4280 glViewport 0, 0, $::WIDTH, $::HEIGHT;
4004 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 4281 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
4005 glClear GL_COLOR_BUFFER_BIT; 4282 glClear GL_COLOR_BUFFER_BIT;
4006 4283
4007 glMatrixMode GL_PROJECTION; 4284 glMatrixMode GL_PROJECTION;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines