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.265 by root, Thu Jun 1 02:59:46 2006 UTC vs.
Revision 1.271 by root, Fri Jun 2 22:13:47 2006 UTC

40 40
41 $LAYOUT = $layout; 41 $LAYOUT = $layout;
42} 42}
43 43
44sub check_tooltip { 44sub check_tooltip {
45 return if $ENV{CFPLUS_DEBUG} & 8;
46
45 if (!$GRAB) { 47 if (!$GRAB) {
46 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 48 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
47 if (length $widget->{tooltip}) { 49 if (length $widget->{tooltip}) {
48
49 if ($TOOLTIP->{owner} != $widget) { 50 if ($TOOLTIP->{owner} != $widget) {
50 $TOOLTIP->hide; 51 $TOOLTIP->hide;
51 52
52 $TOOLTIP->{owner} = $widget; 53 $TOOLTIP->{owner} = $widget;
53 54
170sub rescale_widgets { 171sub rescale_widgets {
171 my ($sx, $sy) = @_; 172 my ($sx, $sy) = @_;
172 173
173 for my $widget (values %WIDGET) { 174 for my $widget (values %WIDGET) {
174 if ($widget->{is_toplevel}) { 175 if ($widget->{is_toplevel}) {
175 $widget->{x} += $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 176 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
176 $widget->{y} += $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 177 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
177 178
178 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; 179 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/;
179 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 180 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
180 $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; 181 $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w};
181 $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; 182 $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/;
182 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; 183 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
183 $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; 184 $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h};
184 185
185 $widget->{x} -= $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 186 $widget->{x} -= int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
186 $widget->{y} -= $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 187 $widget->{y} -= int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
187 188
188 } 189 }
189 } 190 }
190 191
191 reconfigure_widgets; 192 reconfigure_widgets;
438 439
439 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus 440 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus
440 unless $FOCUS; 441 unless $FOCUS;
441} 442}
442 443
443sub mouse_motion { } 444sub mouse_motion { 0 }
444sub button_up { } 445sub button_up { 0 }
445sub key_down { } 446sub key_down { 0 }
446sub key_up { } 447sub key_up { 0 }
447 448
448sub button_down { 449sub button_down {
449 my ($self, $ev, $x, $y) = @_; 450 my ($self, $ev, $x, $y) = @_;
450 451
451 $self->focus_in; 452 $self->focus_in;
452}
453 453
454sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } 454 0
455sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } 455}
456sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
457sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
458sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
459 456
460sub find_widget { 457sub find_widget {
461 my ($self, $x, $y) = @_; 458 my ($self, $x, $y) = @_;
462 459
463 return () unless $self->{can_events}; 460 return () unless $self->{can_events};
525 522
526 $self->realloc; 523 $self->realloc;
527 $self->update; 524 $self->update;
528} 525}
529 526
527# using global variables seems a bit hacky, but passing through all drawing
528# functions seems pointless.
529our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn
530
530sub draw { 531sub draw {
531 my ($self) = @_; 532 my ($self) = @_;
532 533
533 return unless $self->{h} && $self->{w}; 534 return unless $self->{h} && $self->{w};
535
536 # update screen rectangle
537 local $draw_x = $draw_x + $self->{x};
538 local $draw_y = $draw_y + $self->{y};
539 local $draw_w = $draw_x + $self->{w};
540 local $draw_h = $draw_y + $self->{h};
541
542 # skip widgets that are entirely outside the drawing area
543 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
544 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
534 545
535 glPushMatrix; 546 glPushMatrix;
536 glTranslate $self->{x}, $self->{y}, 0; 547 glTranslate $self->{x}, $self->{y}, 0;
537 $self->_draw; 548 $self->_draw;
538 glPopMatrix; 549 glPopMatrix;
803 $self->SUPER::size_allocate ($w, $h); 814 $self->SUPER::size_allocate ($w, $h);
804 $self->update; 815 $self->update;
805} 816}
806 817
807sub _render { 818sub _render {
819 my ($self) = @_;
820
808 $_[0]{children}[0]->draw; 821 $self->{children}[0]->draw;
809} 822}
810 823
811sub render_child { 824sub render_child {
812 my ($self) = @_; 825 my ($self) = @_;
813 826
814 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 827 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
815 glClearColor 0, 0, 0, 0; 828 glClearColor 0, 0, 0, 0;
816 glClear GL_COLOR_BUFFER_BIT; 829 glClear GL_COLOR_BUFFER_BIT;
817 830
831 {
832 package CFClient::UI::Base;
833
834 ($draw_x, $draw_y, $draw_w, $draw_h) =
835 (0, 0, $self->{w}, $self->{h});
836 }
837
818 $self->_render; 838 $self->_render;
819 }; 839 };
820} 840}
821 841
822sub _draw { 842sub _draw {
823 my ($self) = @_; 843 my ($self) = @_;
824 844
825 my ($w, $h) = ($self->w, $self->h); 845 my ($w, $h) = @$self{qw(w h)};
826 846
827 my $tex = $self->{texture} 847 my $tex = $self->{texture}
828 or return; 848 or return;
829 849
830 glEnable GL_TEXTURE_2D; 850 glEnable GL_TEXTURE_2D;
912 } 932 }
913} 933}
914 934
915sub _render { 935sub _render {
916 my ($self) = @_; 936 my ($self) = @_;
937
938 local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x};
939 local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y};
917 940
918 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; 941 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
919 942
920 $self->SUPER::_render; 943 $self->SUPER::_render;
921} 944}
1029my @border = 1052my @border =
1030 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1053 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1031 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1054 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1032 1055
1033sub new { 1056sub new {
1034 my $class = shift; 1057 my ($class, %arg) = @_;
1058
1059 my $title = delete $arg{title};
1035 1060
1036 my $self = $class->SUPER::new ( 1061 my $self = $class->SUPER::new (
1037 bg => [1, 1, 1, 1], 1062 bg => [1, 1, 1, 1],
1038 border_bg => [1, 1, 1, 1], 1063 border_bg => [1, 1, 1, 1],
1039 border => 0.6, 1064 border => 0.6,
1040 can_events => 1, 1065 can_events => 1,
1041 min_w => 16, 1066 min_w => 16,
1042 min_h => 16, 1067 min_h => 16,
1043 @_ 1068 %arg,
1044 ); 1069 );
1045 1070
1046 $self->{title} &&= new CFClient::UI::Label 1071 $self->{title} = new CFClient::UI::Label
1047 align => 0, 1072 align => 0,
1048 valign => 1, 1073 valign => 1,
1049 text => $self->{title}, 1074 text => $title,
1050 fontsize => $self->{border}; 1075 fontsize => $self->{border}
1076 if defined $title;
1051 1077
1052 $self 1078 $self
1079}
1080
1081sub add {
1082 my ($self, @widgets) = @_;
1083
1084 $self->SUPER::add (@widgets);
1085 $self->CFClient::UI::Container::add ($self->{title}) if $self->{title};
1053} 1086}
1054 1087
1055sub border { 1088sub border {
1056 int $_[0]{border} * $::FONTSIZE 1089 int $_[0]{border} * $::FONTSIZE
1057} 1090}
1058 1091
1059sub size_request { 1092sub size_request {
1060 my ($self) = @_; 1093 my ($self) = @_;
1094
1095 $self->{title}->size_request
1096 if $self->{title};
1061 1097
1062 my ($w, $h) = $self->SUPER::size_request; 1098 my ($w, $h) = $self->SUPER::size_request;
1063 1099
1064 ( 1100 (
1065 $w + $self->border * 2, 1101 $w + $self->border * 2,
1068} 1104}
1069 1105
1070sub size_allocate { 1106sub size_allocate {
1071 my ($self, $w, $h) = @_; 1107 my ($self, $w, $h) = @_;
1072 1108
1109 if ($self->{title}) {
1110 $self->{title}{w} = $w;
1111 $self->{title}{h} = $h;
1112 $self->{title}->size_allocate ($w, $h);
1113 }
1114
1115 my $border = $self->border;
1116
1073 $h -= List::Util::max 0, $self->border * 2; 1117 $h -= List::Util::max 0, $border * 2;
1074 $w -= List::Util::max 0, $self->border * 2; 1118 $w -= List::Util::max 0, $border * 2;
1075 1119
1076 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
1077 if $self->{title};
1078
1079 $self->child->configure ($self->border, $self->border, $w, $h); 1120 $self->child->configure ($border, $border, $w, $h);
1080} 1121}
1081 1122
1082sub button_down { 1123sub button_down {
1083 my ($self, $ev, $x, $y) = @_; 1124 my ($self, $ev, $x, $y) = @_;
1084 1125
1118 1159
1119 ($x, $y) = ($ev->{x}, $ev->{y}); 1160 ($x, $y) = ($ev->{x}, $ev->{y});
1120 1161
1121 $self->move_abs ($bx + $x - $ox, $by + $y - $oy); 1162 $self->move_abs ($bx + $x - $ox, $by + $y - $oy);
1122 }; 1163 };
1164 } else {
1165 return 0;
1166 }
1167
1123 } 1168 1
1124} 1169}
1125 1170
1126sub button_up { 1171sub button_up {
1127 my ($self, $ev, $x, $y) = @_; 1172 my ($self, $ev, $x, $y) = @_;
1128 1173
1129 delete $self->{motion}; 1174 !!delete $self->{motion}
1130} 1175}
1131 1176
1132sub mouse_motion { 1177sub mouse_motion {
1133 my ($self, $ev, $x, $y) = @_; 1178 my ($self, $ev, $x, $y) = @_;
1134 1179
1135 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1180 $self->{motion}->($ev, $x, $y) if $self->{motion};
1181
1182 !!$self->{motion}
1136} 1183}
1137 1184
1138sub _draw { 1185sub _draw {
1139 my ($self) = @_; 1186 my ($self) = @_;
1140 1187
1188 my $child = $self->{children}[0];
1189
1141 my ($w, $h ) = ($self->{w}, $self->{h}); 1190 my ($w, $h ) = ($self->{w}, $self->{h});
1142 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 1191 my ($cw, $ch) = ($child->{w}, $child->{h});
1143 1192
1144 glEnable GL_TEXTURE_2D; 1193 glEnable GL_TEXTURE_2D;
1145 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1194 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1146 1195
1147 my $border = $self->border; 1196 my $border = $self->border;
1162 $bg->draw_quad_alpha ($border, $border, $cw, $ch); 1211 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
1163 } 1212 }
1164 1213
1165 glDisable GL_TEXTURE_2D; 1214 glDisable GL_TEXTURE_2D;
1166 1215
1167 $self->{title}->draw if $self->{title};
1168
1169 $self->child->draw; 1216 $child->draw;
1217
1218 if ($self->{title}) {
1219 glTranslate 0, $border - $self->{h};
1220 $self->{title}->_draw;
1221 }
1170} 1222}
1171 1223
1172############################################################################# 1224#############################################################################
1173 1225
1174package CFClient::UI::Table; 1226package CFClient::UI::Table;
1522} 1574}
1523 1575
1524sub size_allocate { 1576sub size_allocate {
1525 my ($self, $w, $h) = @_; 1577 my ($self, $w, $h) = @_;
1526 1578
1579 delete $self->{ox};
1580
1527 delete $self->{texture} 1581 delete $self->{texture}
1528 ;#d# 1582 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w};
1529} 1583}
1530 1584
1531sub set_fontsize { 1585sub set_fontsize {
1532 my ($self, $fontsize) = @_; 1586 my ($self, $fontsize) = @_;
1533 1587
1548 $self->{layout}->set_width ($self->{w}); 1602 $self->{layout}->set_width ($self->{w});
1549 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1603 $self->{layout}->set_ellipsise ($self->{ellipsise});
1550 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1604 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1551 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1605 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1552 1606
1553 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1607 new_from_layout CFClient::Texture $self->{layout}
1608 };
1554 1609
1610 unless (exists $self->{ox}) {
1555 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 1611 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1556 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} 1612 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x}
1557 : ($self->{w} - $tex->{w}) * 0.5); 1613 : ($self->{w} - $tex->{w}) * 0.5);
1558 1614
1559 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 1615 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
1560 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1616 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y}
1561 : ($self->{h} - $tex->{h}) * 0.5); 1617 : ($self->{h} - $tex->{h}) * 0.5);
1562
1563 $tex
1564 }; 1618 };
1565 1619
1566 glEnable GL_TEXTURE_2D; 1620 glEnable GL_TEXTURE_2D;
1567 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1621 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1568 1622
1663 $self->{cursor} = length $text; 1717 $self->{cursor} = length $text;
1664 } elsif ($uni == 27) { 1718 } elsif ($uni == 27) {
1665 $self->_emit ('escape'); 1719 $self->_emit ('escape');
1666 } elsif ($uni) { 1720 } elsif ($uni) {
1667 substr $text, $self->{cursor}++, 0, chr $uni; 1721 substr $text, $self->{cursor}++, 0, chr $uni;
1722 } else {
1723 return 0;
1668 } 1724 }
1669 1725
1670 $self->_set_text ($text); 1726 $self->_set_text ($text);
1671 1727
1672 $self->realloc; 1728 $self->realloc;
1729
1730 1
1673} 1731}
1674 1732
1675sub focus_in { 1733sub focus_in {
1676 my ($self) = @_; 1734 my ($self) = @_;
1677 1735
1692 utf8::encode $text; 1750 utf8::encode $text;
1693 $self->{cursor} = length substr $text, 0, $idx; 1751 $self->{cursor} = length substr $text, 0, $idx;
1694 1752
1695 $self->_set_text ($self->{text}); 1753 $self->_set_text ($self->{text});
1696 $self->update; 1754 $self->update;
1755
1756 1
1697} 1757}
1698 1758
1699sub mouse_motion { 1759sub mouse_motion {
1700 my ($self, $ev, $x, $y) = @_; 1760 my ($self, $ev, $x, $y) = @_;
1701# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# 1761# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
1762
1763 0
1702} 1764}
1703 1765
1704sub _draw { 1766sub _draw {
1705 my ($self) = @_; 1767 my ($self) = @_;
1706 1768
1783 } else { 1845 } else {
1784 $self->set_text ($self->{history_saveback}); 1846 $self->set_text ($self->{history_saveback});
1785 } 1847 }
1786 1848
1787 } else { 1849 } else {
1788 $self->SUPER::key_down ($ev); 1850 return $self->SUPER::key_down ($ev)
1851 }
1852
1789 } 1853 1
1790
1791} 1854}
1792 1855
1793############################################################################# 1856#############################################################################
1794 1857
1795package CFClient::UI::Button; 1858package CFClient::UI::Button;
1824 my ($self, $ev, $x, $y) = @_; 1887 my ($self, $ev, $x, $y) = @_;
1825 1888
1826 $self->emit ("activate") 1889 $self->emit ("activate")
1827 if $x >= 0 && $x < $self->{w} 1890 if $x >= 0 && $x < $self->{w}
1828 && $y >= 0 && $y < $self->{h}; 1891 && $y >= 0 && $y < $self->{h};
1892
1893 1
1829} 1894}
1830 1895
1831sub _draw { 1896sub _draw {
1832 my ($self) = @_; 1897 my ($self) = @_;
1833 1898
1887 1952
1888 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} 1953 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
1889 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { 1954 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
1890 $self->{state} = !$self->{state}; 1955 $self->{state} = !$self->{state};
1891 $self->_emit (changed => $self->{state}); 1956 $self->_emit (changed => $self->{state});
1957 } else {
1958 return 0
1959 }
1960
1892 } 1961 1
1893} 1962}
1894 1963
1895sub _draw { 1964sub _draw {
1896 my ($self) = @_; 1965 my ($self) = @_;
1897 1966
2235 2304
2236 $self->SUPER::button_down ($ev, $x, $y); 2305 $self->SUPER::button_down ($ev, $x, $y);
2237 2306
2238 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 2307 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2239 2308
2240 $self->mouse_motion ($ev, $x, $y); 2309 $self->mouse_motion ($ev, $x, $y)
2241} 2310}
2242 2311
2243sub mouse_motion { 2312sub mouse_motion {
2244 my ($self, $ev, $x, $y) = @_; 2313 my ($self, $ev, $x, $y) = @_;
2245 2314
2249 my (undef, $lo, $hi, $page) = @{$self->{range}}; 2318 my (undef, $lo, $hi, $page) = @{$self->{range}};
2250 2319
2251 $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); 2320 $x = ($x - $self->{click}[1]) / ($w * $self->{scale});
2252 2321
2253 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); 2322 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
2323 } else {
2324 return 0;
2325 }
2326
2254 } 2327 1
2255} 2328}
2256 2329
2257sub update { 2330sub update {
2258 my ($self) = @_; 2331 my ($self) = @_;
2259 2332
2837 my ($self, $ev, $x, $y) = @_; 2910 my ($self, $ev, $x, $y) = @_;
2838 2911
2839 # TODO: should use vbox->find_widget or so 2912 # TODO: should use vbox->find_widget or so
2840 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); 2913 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2841 $self->{hover} = $self->{item}{$HOVER}; 2914 $self->{hover} = $self->{item}{$HOVER};
2915
2916 0
2842} 2917}
2843 2918
2844sub button_up { 2919sub button_up {
2845 my ($self, $ev, $x, $y) = @_; 2920 my ($self, $ev, $x, $y) = @_;
2846 2921
2848 undef $GRAB; 2923 undef $GRAB;
2849 $self->hide; 2924 $self->hide;
2850 2925
2851 $self->_emit ("popdown"); 2926 $self->_emit ("popdown");
2852 $self->{hover}[1]->() if $self->{hover}; 2927 $self->{hover}[1]->() if $self->{hover};
2928 } else {
2929 return 0
2930 }
2931
2853 } 2932 1
2854} 2933}
2855 2934
2856############################################################################# 2935#############################################################################
2857 2936
2858package CFClient::UI::Statusbox; 2937package CFClient::UI::Statusbox;
3105 $rec = $::CONN->stop_record if $::CONN; 3184 $rec = $::CONN->stop_record if $::CONN;
3106 return unless ref $rec eq 'ARRAY'; 3185 return unless ref $rec eq 'ARRAY';
3107 $self->set_command_list ($rec); 3186 $self->set_command_list ($rec);
3108} 3187}
3109 3188
3110# if $commit is true, the binding will be set after the user entered a key combo 3189
3190sub ask_for_bind_and_commit {
3191 my ($self) = @_;
3192 $self->ask_for_bind (1);
3193}
3194
3111sub ask_for_bind { 3195sub ask_for_bind {
3112 my ($self, $commit) = @_; 3196 my ($self, $commit) = @_;
3113 3197
3114 CFClient::Binder::open_binding_dialog (sub { 3198 CFClient::Binder::open_binding_dialog (sub {
3115 my ($mod, $sym) = @_; 3199 my ($mod, $sym) = @_;
3372 $_->() 3456 $_->()
3373 for values %{delete $self->{refresh_hook}}; 3457 for values %{delete $self->{refresh_hook}};
3374 } 3458 }
3375 3459
3376 if ($self->{realloc}) { 3460 if ($self->{realloc}) {
3461 my %queue;
3377 my @queue; 3462 my @queue;
3463 my $widget;
3378 3464
3465 outer:
3379 while () { 3466 while () {
3380 if ($self->{realloc}) { 3467 if (my $realloc = delete $self->{realloc}) {
3381 #TODO use array-of-depth approach 3468 for $widget (values %$realloc) {
3469 $widget->{visible} or next; # do not resize invisible widgets
3382 3470
3383 use sort 'stable'; 3471 $queue{$widget+0}++ and next; # duplicates are common
3384 3472
3385 @queue = sort { $a->{visible} <=> $b->{visible} } 3473 push @{ $queue[$widget->{visible}] }, $widget;
3386 @queue, values %{delete $self->{realloc}}; 3474 }
3387 } 3475 }
3388 3476
3477 while () {
3478 @queue or last outer;
3479
3389 my $widget = pop @queue || last; 3480 $widget = pop @{ $queue[-1] || [] }
3481 and last;
3482
3483 pop @queue;
3484 }
3390 3485
3391 $widget->{visible} or last; # do not resize invisible widgets 3486 delete $queue{$widget+0};
3392 3487
3393 my ($w, $h) = $widget->size_request; 3488 my ($w, $h) = $widget->size_request;
3394 3489
3395 $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; 3490 $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2;
3396 $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; 3491 $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2;
3404 $widget->{req_h} = $h; 3499 $widget->{req_h} = $h;
3405 3500
3406 $self->{size_alloc}{$widget+0} = $widget; 3501 $self->{size_alloc}{$widget+0} = $widget;
3407 3502
3408 if (my $parent = $widget->{parent}) { 3503 if (my $parent = $widget->{parent}) {
3409 $self->{realloc}{$parent+0} = $parent; 3504 $self->{realloc}{$parent+0} = $parent
3410 #unshift @queue, $parent; 3505 unless $queue{$parent+0};
3506
3411 $parent->{force_size_alloc} = 1; 3507 $parent->{force_size_alloc} = 1;
3412 $self->{size_alloc}{$parent+0} = $parent; 3508 $self->{size_alloc}{$parent+0} = $parent;
3413 } 3509 }
3414 } 3510 }
3415 3511
3431 3527
3432 $w = int $w + 0.5; 3528 $w = int $w + 0.5;
3433 $h = int $h + 0.5; 3529 $h = int $h + 0.5;
3434 3530
3435 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { 3531 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
3532 $widget->{old_w} = $widget->{w};
3533 $widget->{old_h} = $widget->{h};
3534
3436 $widget->{w} = $w; 3535 $widget->{w} = $w;
3437 $widget->{h} = $h; 3536 $widget->{h} = $h;
3438 3537
3439 $widget->emit (size_allocate => $w, $h); 3538 $widget->emit (size_allocate => $w, $h);
3440 } 3539 }
3455 glLoadIdentity; 3554 glLoadIdentity;
3456 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; 3555 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3457 glMatrixMode GL_MODELVIEW; 3556 glMatrixMode GL_MODELVIEW;
3458 glLoadIdentity; 3557 glLoadIdentity;
3459 3558
3559 {
3560 package CFClient::UI::Base;
3561
3562 ($draw_x, $draw_y, $draw_w, $draw_h) =
3563 (0, 0, $self->{w}, $self->{h});
3564 }
3565
3460 $self->_draw; 3566 $self->_draw;
3461} 3567}
3462 3568
3463############################################################################# 3569#############################################################################
3464 3570

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines