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.112 by root, Sat Apr 15 12:29:46 2006 UTC vs.
Revision 1.121 by root, Mon Apr 17 19:21:00 2006 UTC

7 7
8use CFClient; 8use CFClient;
9 9
10our ($FOCUS, $HOVER, $GRAB); # various widgets 10our ($FOCUS, $HOVER, $GRAB); # various widgets
11 11
12our $TOPLEVEL; 12our $ROOT;
13our $BUTTON_STATE; 13our $BUTTON_STATE;
14 14
15# class methods for events 15# class methods for events
16sub feed_sdl_key_down_event { 16sub feed_sdl_key_down_event {
17 $FOCUS->key_down ($_[0]) if $FOCUS; 17 $FOCUS->key_down ($_[0]) if $FOCUS;
24sub feed_sdl_button_down_event { 24sub feed_sdl_button_down_event {
25 my ($ev) = @_; 25 my ($ev) = @_;
26 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 26 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
27 27
28 if (!$BUTTON_STATE) { 28 if (!$BUTTON_STATE) {
29 my $widget = $TOPLEVEL->find_widget ($x, $y); 29 my $widget = $ROOT->find_widget ($x, $y);
30 30
31 $GRAB = $widget; 31 $GRAB = $widget;
32 $GRAB->update if $GRAB; 32 $GRAB->update if $GRAB;
33 } 33 }
34 34
35 $BUTTON_STATE |= 1 << ($ev->button - 1); 35 $BUTTON_STATE |= 1 << ($ev->button - 1);
36 36
37 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; 37 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
38} 38}
39 39
40sub feed_sdl_button_up_event { 40sub feed_sdl_button_up_event {
41 my ($ev) = @_; 41 my ($ev) = @_;
42 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 42 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
43 43
44 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 44 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
45 45
46 $BUTTON_STATE &= ~(1 << ($ev->button - 1)); 46 $BUTTON_STATE &= ~(1 << ($ev->button - 1));
47 47
48 $GRAB->button_up ($ev, $GRAB->translate ($x, $y)) if $GRAB; 48 $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
49 49
50 if (!$BUTTON_STATE) { 50 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 51 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 52 $grab->update if $grab;
53 $GRAB->update if $GRAB; 53 $GRAB->update if $GRAB;
56 56
57sub feed_sdl_motion_event { 57sub feed_sdl_motion_event {
58 my ($ev) = @_; 58 my ($ev) = @_;
59 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 59 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
60 60
61 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 61 my $widget = $GRAB || $ROOT->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 && $hover->{can_hover}; 66 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER && $HOVER->{can_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->coord2local ($x, $y)) if $HOVER;
71} 71}
72 72
73# convert position array to integers 73# convert position array to integers
74sub harmonize { 74sub harmonize {
75 my ($vals) = @_; 75 my ($vals) = @_;
76 76
77 my $rem = 0; 77 my $rem = 0;
78 78
79 for ($vals) { 79 for (@$vals) {
80 my $i = int $_ + $rem; 80 my $i = int $_ + $rem;
81 $rem += $_ - $i; 81 $rem += $_ - $i;
82 $_ = $i; 82 $_ = $i;
83 } 83 }
84} 84}
112 $self 112 $self
113} 113}
114 114
115sub move { 115sub move {
116 my ($self, $x, $y, $z) = @_; 116 my ($self, $x, $y, $z) = @_;
117 $self->{x} = $x; 117 $self->{x} = int $x;
118 $self->{y} = $y; 118 $self->{y} = int $y;
119 $self->{z} = $z if defined $z; 119 $self->{z} = $z if defined $z;
120} 120}
121 121
122sub needs_redraw { 122sub needs_redraw {
123 0 123 0
146 my ($self, $x, $y, $w, $h) = @_; 146 my ($self, $x, $y, $w, $h) = @_;
147 147
148 $self->_size_allocate ($x, $y, $w, $h); 148 $self->_size_allocate ($x, $y, $w, $h);
149} 149}
150 150
151# return top left coordinates
152sub _topleft {
153 my ($self, $x, $y) = @_;
154
155 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y});
156}
157
151# translate global coordinates to local coordinate system 158# translate global coordinates to local coordinate system
152sub translate { 159sub coord2local {
153 my ($self, $x, $y) = @_; 160 my ($self, $x, $y) = @_;
154 161
155 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); 162 my ($X, $Y) = $self->_topleft;
163 ($x - $X, $y - $Y)
164}
165
166# translate local coordinates to global coordinate system
167sub coord2global {
168 my ($self, $x, $y) = @_;
169
170 my ($X, $Y) = $self->_topleft;
171 ($x + $X, $y + $Y)
156} 172}
157 173
158sub focus_in { 174sub focus_in {
159 my ($self) = @_; 175 my ($self) = @_;
160 176
161 return if $FOCUS == $self; 177 return if $FOCUS == $self;
162 return unless $self->{can_focus}; 178 return unless $self->{can_focus};
163 179
164 my $focus = $FOCUS; $FOCUS = $self; 180 my $focus = $FOCUS; $FOCUS = $self;
181
182 $self->emit (focus_in => $focus);
183
165 $focus->update if $focus; 184 $focus->update if $focus;
166 $FOCUS->update; 185 $FOCUS->update;
167} 186}
168 187
169sub focus_out { 188sub focus_out {
170 my ($self) = @_; 189 my ($self) = @_;
171 190
172 return unless $FOCUS == $self; 191 return unless $FOCUS == $self;
173 192
174 my $focus = $FOCUS; undef $FOCUS; 193 my $focus = $FOCUS; undef $FOCUS;
194
195 $self->emit (focus_out => $focus);
196
175 $focus->update if $focus; #? 197 $focus->update if $focus; #?
176} 198}
177 199
178sub mouse_motion { } 200sub mouse_motion { }
179sub button_up { } 201sub button_up { }
233 255
234 () 256 ()
235} 257}
236 258
237sub set_parent { 259sub set_parent {
238 my ($self, $par) = @_; 260 my ($self, $parent) = @_;
239 261
240 $self->{parent} = $par;
241 Scalar::Util::weaken $self->{parent}; 262 Scalar::Util::weaken ($self->{parent} = $parent);
242}
243
244sub get_parent {
245 $_[0]->{parent}
246} 263}
247 264
248sub update { 265sub update {
249 my ($self) = @_; 266 my ($self) = @_;
250 267
339 356
340 $self 357 $self
341} 358}
342 359
343sub add { 360sub add {
344 my ($self, $chld) = @_; 361 my ($self, $child) = @_;
345 362
346 $chld->set_parent ($self); 363 $child->set_parent ($self);
364
365 use sort 'stable';
347 366
348 $self->{children} = [ 367 $self->{children} = [
349 sort { $a->{z} <=> $b->{z} } 368 sort { $a->{z} <=> $b->{z} }
350 @{$self->{children}}, $chld 369 @{$self->{children}}, $child
351 ]; 370 ];
352 371
353 $self->{w} = $self->{h} = -1; 372 $self->{w} = $self->{h} = -1;
354 $self->update; 373 $self->update;
355} 374}
552 # TODO: user_x, user_y, overwrite moveto? 571 # TODO: user_x, user_y, overwrite moveto?
553 572
554 $class->SUPER::new ( 573 $class->SUPER::new (
555 bg => [1, 1, 1, 1], 574 bg => [1, 1, 1, 1],
556 border_bg => [1, 1, 1, 1], 575 border_bg => [1, 1, 1, 1],
557 border => $::FONTSIZE * 0.8, 576 border => int $::FONTSIZE * 0.8,
558 @_ 577 @_
559 ) 578 )
560} 579}
561 580
562sub size_request { 581sub size_request {
685 @_ 704 @_
686 ) 705 )
687} 706}
688 707
689sub add { 708sub add {
690 my ($self, $x, $y, $chld) = @_; 709 my ($self, $x, $y, $child) = @_;
691 710
711 $child->set_parent ($self);
692 $self->{children}[$y][$x] = $chld; 712 $self->{children}[$y][$x] = $child;
693 $chld->set_parent ($self);
694 713
695 $self->{w} = $self->{h} = -1; 714 $self->{w} = $self->{h} = -1;
715 $self->update;
716}
717
718# TODO: move to container class maybe? send childs a signal on removal?
719sub clear {
720 my ($self) = @_;
721
722 delete $self->{children};
696 $self->update; 723 $self->update;
697} 724}
698 725
699sub get_wh { 726sub get_wh {
700 my ($self) = @_; 727 my ($self) = @_;
929 my $self = $class->SUPER::new ( 956 my $self = $class->SUPER::new (
930 fg => [1, 1, 1], 957 fg => [1, 1, 1],
931 fontsize => $::FONTSIZE, 958 fontsize => $::FONTSIZE,
932 text => "", 959 text => "",
933 align => -1, 960 align => -1,
961 valign => -1,
934 padding => 2, 962 padding => 2,
935 layout => new CFClient::Layout, 963 layout => new CFClient::Layout,
936 %arg 964 %arg
937 ); 965 );
938 966
939 $self->set_text ($self->{text}); 967 $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d#
968
969 $self->set_text (delete $self->{text}) if exists $self->{text};
970 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
940 971
941 $self 972 $self
942} 973}
943 974
944sub escape_text { 975sub escape_text {
952} 983}
953 984
954sub set_text { 985sub set_text {
955 my ($self, $text) = @_; 986 my ($self, $text) = @_;
956 987
957 $self->{text} = $text;
958 $self->{layout}->set_markup ($text); 988 $self->{layout}->set_text ($text);
959 989
960 delete $self->{texture}; 990 delete $self->{texture};
961# $self->{w} = $self->{h} = -1;
962 $self->update; 991 $self->update;
963} 992}
964 993
965sub get_text { 994sub set_markup {
966 my ($self, $text) = @_; 995 my ($self, $markup) = @_;
967 996
968 $self->{text} 997 $self->{layout}->set_markup ($markup);
998
999 delete $self->{texture};
1000 $self->update;
969} 1001}
970 1002
971sub size_request { 1003sub size_request {
972 my ($self) = @_; 1004 my ($self) = @_;
973 1005
974 $self->{layout}->set_width; 1006 $self->{layout}->set_width;
975 $self->{layout}->set_height ($self->{fontsize}); 1007 $self->{layout}->set_height ($self->{fontsize});
1008
976 my ($w, $h) = $self->{layout}->size; 1009 my ($w, $h) = $self->{layout}->size;
977 1010
978 ( 1011 (
979 $w + $self->{padding} * 2, 1012 $w + $self->{padding} * 2,
980 $h + $self->{padding} * 2, 1013 $h + $self->{padding} * 2,
999sub _draw { 1032sub _draw {
1000 my ($self) = @_; 1033 my ($self) = @_;
1001 1034
1002 my $tex = $self->{texture} ||= do { 1035 my $tex = $self->{texture} ||= do {
1003 $self->{layout}->set_width ($self->{w}); 1036 $self->{layout}->set_width ($self->{w});
1004 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); 1037 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize});
1005 new_from_layout CFClient::Texture $self->{layout} 1038 new_from_layout CFClient::Texture $self->{layout}
1006 }; 1039 };
1007 1040
1008 glEnable GL_BLEND; 1041 glEnable GL_BLEND;
1009 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1042 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1015 my $x = 1048 my $x =
1016 $self->{align} < 0 ? $self->{padding} 1049 $self->{align} < 0 ? $self->{padding}
1017 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1050 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1018 : ($self->{w} - $tex->{w}) * 0.5; 1051 : ($self->{w} - $tex->{w}) * 0.5;
1019 1052
1020 $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); 1053 my $y =
1054 $self->{valign} < 0 ? $self->{padding}
1055 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1056 : ($self->{h} - $tex->{h}) * 0.5;
1057
1058 $tex->draw_quad (int $x, int $y);
1021 1059
1022 glDisable GL_TEXTURE_2D; 1060 glDisable GL_TEXTURE_2D;
1023 glDisable GL_BLEND; 1061 glDisable GL_BLEND;
1024} 1062}
1025 1063
1026############################################################################# 1064#############################################################################
1027 1065
1028package CFClient::UI::Entry; 1066package CFClient::UI::EntryBase;
1029 1067
1030our @ISA = CFClient::UI::Label::; 1068our @ISA = CFClient::UI::Label::;
1031 1069
1032use SDL; 1070use SDL;
1033use SDL::OpenGL; 1071use SDL::OpenGL;
1040 bg => [0, 0, 0, 0.2], 1078 bg => [0, 0, 0, 0.2],
1041 active_bg => [1, 1, 1, 0.5], 1079 active_bg => [1, 1, 1, 0.5],
1042 active_fg => [0, 0, 0], 1080 active_fg => [0, 0, 0],
1043 can_hover => 1, 1081 can_hover => 1,
1044 can_focus => 1, 1082 can_focus => 1,
1083 valign => 0,
1045 @_ 1084 @_
1046 ) 1085 )
1047} 1086}
1048 1087
1049sub _set_text { 1088sub _set_text {
1050 my ($self, $text) = @_; 1089 my ($self, $text) = @_;
1051 1090
1052 my $old_text = $self->{text}; 1091 delete $self->{cur_h};
1092
1093 return if $self->{text} eq $text;
1053 1094
1054 $self->{last_activity} = $::NOW; 1095 $self->{last_activity} = $::NOW;
1055
1056 $self->{text} = $text; 1096 $self->{text} = $text;
1057 $self->{layout}->set_width ($self->{w});
1058 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1059 1097
1060 $text =~ s/./*/g if $self->{hidden}; 1098 $text =~ s/./*/g if $self->{hidden};
1099 $self->{layout}->set_text ("$text ");
1061 1100
1062 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1101 $self->emit (changed => $self->{text});
1102}
1063 1103
1064 $text = substr $text, 0, $self->{cursor}; 1104sub get_text {
1065 utf8::encode $text; 1105 $_[0]{text}
1066
1067 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
1068
1069 $self->emit (changed => $self->{text}) # XXX: is this the right place to do this?
1070 if $old_text ne $self->{text};
1071} 1106}
1072 1107
1073sub size_request { 1108sub size_request {
1074 my ($self) = @_; 1109 my ($self) = @_;
1075 1110
1179 1214
1180 $self->SUPER::_draw; 1215 $self->SUPER::_draw;
1181 1216
1182 #TODO: force update every cursor change :( 1217 #TODO: force update every cursor change :(
1183 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1218 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1219
1220 unless (exists $self->{cur_h}) {
1221 my $text = substr $self->{text}, 0, $self->{cursor};
1222 utf8::encode $text;
1223
1224 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1225 }
1226
1184 glColor @{$self->{fg}}; 1227 glColor @{$self->{fg}};
1185 glBegin GL_LINES; 1228 glBegin GL_LINES;
1186 glVertex $self->{cur_x}, $self->{cur_y}; 1229 glVertex $self->{cur_x}, $self->{cur_y};
1187 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1230 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h};
1188 glEnd; 1231 glEnd;
1189 } 1232 }
1190} 1233}
1191 1234
1192package CFClient::UI::LineEntry; 1235package CFClient::UI::Entry;
1193 1236
1194our @ISA = CFClient::UI::Entry::; 1237our @ISA = CFClient::UI::EntryBase::;
1195 1238
1196use SDL; 1239use SDL;
1197use SDL::OpenGL; 1240use SDL::OpenGL;
1198 1241
1199sub key_down { 1242sub key_down {
1248 1291
1249sub _draw { 1292sub _draw {
1250 my ($self) = @_; 1293 my ($self) = @_;
1251 1294
1252 local $self->{fg} = $self->{fg}; 1295 local $self->{fg} = $self->{fg};
1253 my $tex = $tex[0];
1254
1255 glEnable GL_BLEND;
1256 glEnable GL_TEXTURE_2D;
1257 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1258 1296
1259 if ($GRAB == $self) { 1297 if ($GRAB == $self) {
1260 $self->{fg} = $self->{active_fg}; 1298 $self->{fg} = $self->{active_fg};
1261 } 1299 }
1262 1300
1263 glBindTexture GL_TEXTURE_2D, $tex->{name}; 1301 glEnable GL_BLEND;
1302 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1303 glEnable GL_TEXTURE_2D;
1264 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1304 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1305 glColor 0, 0, 0, 1;
1265 1306
1266 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 1307 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h});
1267 1308
1268 glDisable GL_TEXTURE_2D; 1309 glDisable GL_TEXTURE_2D;
1269 glDisable GL_BLEND; 1310 glDisable GL_BLEND;
1270 1311
1271 $self->SUPER::_draw; 1312 $self->SUPER::_draw;
1575 1616
1576 return unless $self->{h} > 0; 1617 return unless $self->{h} > 0;
1577 1618
1578 delete $self->{texture}; 1619 delete $self->{texture};
1579 1620
1580 $TOPLEVEL->on_refresh ($self, sub { 1621 $ROOT->on_refresh ($self, sub {
1581 if (delete $self->{need_reflow}) { 1622 if (delete $self->{need_reflow}) {
1582 my $height = 0; 1623 my $height = 0;
1583 1624
1584 $height += $_->[0] = $self->text_height ($_->[2]) 1625 $height += $_->[0] = $self->text_height ($_->[2])
1585 for @{$self->{par}}; 1626 for @{$self->{par}};
1753 0.1, 0.1, 0.1, 1794 0.1, 0.1, 0.1,
1754 ; 1795 ;
1755 glEnable GL_CONVOLUTION_2D; 1796 glEnable GL_CONVOLUTION_2D;
1756 } 1797 }
1757 1798
1758 my $tex = new CFClient::Texture 1799 $self->{fow_texture} = new CFClient::Texture
1759 w => $w, 1800 w => $w,
1760 h => $h, 1801 h => $h,
1761 data => $data, 1802 data => $data,
1762 internalformat => GL_ALPHA, 1803 internalformat => GL_ALPHA,
1763 format => GL_ALPHA; 1804 format => GL_ALPHA;
1768 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1809 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1769 glEnable GL_TEXTURE_2D; 1810 glEnable GL_TEXTURE_2D;
1770 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1811 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1771 1812
1772 glColor +($::CFG->{fow_intensity}) x 3, 1; 1813 glColor +($::CFG->{fow_intensity}) x 3, 1;
1773 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1814 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1774 1815
1775 glDisable GL_TEXTURE_2D; 1816 glDisable GL_TEXTURE_2D;
1776 glDisable GL_BLEND; 1817 glDisable GL_BLEND;
1777 } 1818 }
1778 1819
1784 glEnable GL_BLEND; 1825 glEnable GL_BLEND;
1785 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1826 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1786 glEnable GL_TEXTURE_2D; 1827 glEnable GL_TEXTURE_2D;
1787 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1828 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1788 1829
1830 $self->{mapmap_texture} =
1789 CFClient::Texture->new ( 1831 new CFClient::Texture
1790 w => $w, 1832 w => $w,
1791 h => $h, 1833 h => $h,
1792 data => $::MAP->mapmap ($w, $h), 1834 data => $::MAP->mapmap ($w, $h),
1793 type => GL_UNSIGNED_INT_8_8_8_8_REV 1835 type => GL_UNSIGNED_INT_8_8_8_8_REV;
1794 )->draw_quad (100, 100); 1836
1837 $self->{mapmap_texture}->draw_quad (100, 100);
1795 1838
1796 glDisable GL_TEXTURE_2D; 1839 glDisable GL_TEXTURE_2D;
1797 glDisable GL_BLEND; 1840 glDisable GL_BLEND;
1798 } 1841 }
1799 # HACK END 1842 # HACK END
1945sub toggle_flopper { 1988sub toggle_flopper {
1946 my ($self) = @_; 1989 my ($self) = @_;
1947 1990
1948 # TODO: use animation 1991 # TODO: use animation
1949 if ($self->{state} = !$self->{state}) { 1992 if ($self->{state} = !$self->{state}) {
1950 $CFClient::UI::TOPLEVEL->add ($self->{other}); 1993 $CFClient::UI::ROOT->add ($self->{other});
1951 $self->{other}->move ( 1994 $self->{other}->move ($self->coord2global (0, $self->{h}));
1952 ($::WIDTH - $self->{other}{w}) * 0.5, 1995 $self->emit ("open");
1953 ($::HEIGHT - $self->{other}{h}) * 0.5,
1954 );
1955 } else { 1996 } else {
1956 $CFClient::UI::TOPLEVEL->remove ($self->{other}); 1997 $CFClient::UI::ROOT->remove ($self->{other});
1998 $self->emit ("close");
1957 } 1999 }
1958}
1959 2000
1960############################################################################# 2001 $self->emit (changed => $self->{state});
2002}
1961 2003
2004#############################################################################
2005
1962package CFClient::UI::Toplevel; 2006package CFClient::UI::Root;
1963 2007
1964our @ISA = CFClient::UI::Container::; 2008our @ISA = CFClient::UI::Container::;
1965 2009
1966use SDL::OpenGL; 2010use SDL::OpenGL;
1967 2011
1976 2020
1977 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 2021 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request)
1978 for @{$self->{children}}; 2022 for @{$self->{children}};
1979} 2023}
1980 2024
1981sub translate { 2025sub _topleft {
1982 my ($self, $x, $y) = @_; 2026 my ($self, $x, $y) = @_;
1983 2027
1984 ($x, $y) 2028 ($x, $y)
1985} 2029}
1986 2030
1994sub add { 2038sub add {
1995 my ($self, $widget) = @_; 2039 my ($self, $widget) = @_;
1996 2040
1997 $self->SUPER::add ($widget); 2041 $self->SUPER::add ($widget);
1998 2042
1999 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 2043 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2000} 2044}
2001 2045
2002sub on_refresh { 2046sub on_refresh {
2003 my ($self, $id, $cb) = @_; 2047 my ($self, $id, $cb) = @_;
2004 2048
2027 2071
2028############################################################################# 2072#############################################################################
2029 2073
2030package CFClient::UI; 2074package CFClient::UI;
2031 2075
2032$TOPLEVEL = new CFClient::UI::Toplevel; 2076$ROOT = new CFClient::UI::Root;
2033 2077
20341 20781
2035 2079

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines