… | |
… | |
7 | |
7 | |
8 | use CFClient; |
8 | use CFClient; |
9 | |
9 | |
10 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
10 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
11 | |
11 | |
12 | our $TOPLEVEL; |
12 | our $ROOT; |
13 | our $BUTTON_STATE; |
13 | our $BUTTON_STATE; |
14 | |
14 | |
15 | # class methods for events |
15 | # class methods for events |
16 | sub feed_sdl_key_down_event { |
16 | sub feed_sdl_key_down_event { |
17 | $FOCUS->key_down ($_[0]) if $FOCUS; |
17 | $FOCUS->key_down ($_[0]) if $FOCUS; |
… | |
… | |
24 | sub feed_sdl_button_down_event { |
24 | sub 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 | |
40 | sub feed_sdl_button_up_event { |
40 | sub 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 | |
57 | sub feed_sdl_motion_event { |
57 | sub 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 |
74 | sub harmonize { |
74 | sub 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 | |
115 | sub move { |
115 | sub 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 | |
122 | sub needs_redraw { |
122 | sub 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 |
|
|
152 | sub _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 |
152 | sub translate { |
159 | sub 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 |
|
|
167 | sub coord2global { |
|
|
168 | my ($self, $x, $y) = @_; |
|
|
169 | |
|
|
170 | my ($X, $Y) = $self->_topleft; |
|
|
171 | ($x + $X, $y + $Y) |
156 | } |
172 | } |
157 | |
173 | |
158 | sub focus_in { |
174 | sub 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 | |
169 | sub focus_out { |
188 | sub 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 | |
178 | sub mouse_motion { } |
200 | sub mouse_motion { } |
179 | sub button_up { } |
201 | sub button_up { } |
… | |
… | |
203 | glPopMatrix; |
225 | glPopMatrix; |
204 | |
226 | |
205 | if ($self == $HOVER && $self->{can_hover}) { |
227 | if ($self == $HOVER && $self->{can_hover}) { |
206 | my ($x, $y) = @$self{qw(x y)}; |
228 | my ($x, $y) = @$self{qw(x y)}; |
207 | |
229 | |
208 | glColor 0, 0, 1, 0.2; |
230 | glColor 1, 0.8, 0.5, 0.2; |
209 | glEnable GL_BLEND; |
231 | glEnable GL_BLEND; |
210 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
232 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
211 | glBegin GL_QUADS; |
233 | glBegin GL_QUADS; |
212 | glVertex $x , $y; |
234 | glVertex $x , $y; |
213 | glVertex $x + $self->{w}, $y; |
235 | glVertex $x + $self->{w}, $y; |
… | |
… | |
233 | |
255 | |
234 | () |
256 | () |
235 | } |
257 | } |
236 | |
258 | |
237 | sub set_parent { |
259 | sub 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 | |
|
|
244 | sub get_parent { |
|
|
245 | $_[0]->{parent} |
|
|
246 | } |
263 | } |
247 | |
264 | |
248 | sub update { |
265 | sub update { |
249 | my ($self) = @_; |
266 | my ($self) = @_; |
250 | |
267 | |
… | |
… | |
339 | |
356 | |
340 | $self |
357 | $self |
341 | } |
358 | } |
342 | |
359 | |
343 | sub add { |
360 | sub 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 | |
562 | sub size_request { |
581 | sub size_request { |
… | |
… | |
685 | @_ |
704 | @_ |
686 | ) |
705 | ) |
687 | } |
706 | } |
688 | |
707 | |
689 | sub add { |
708 | sub 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? |
|
|
719 | sub clear { |
|
|
720 | my ($self) = @_; |
|
|
721 | |
|
|
722 | delete $self->{children}; |
696 | $self->update; |
723 | $self->update; |
697 | } |
724 | } |
698 | |
725 | |
699 | sub get_wh { |
726 | sub 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 | |
944 | sub escape_text { |
975 | sub escape_text { |
… | |
… | |
952 | } |
983 | } |
953 | |
984 | |
954 | sub set_text { |
985 | sub 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 | |
965 | sub get_text { |
994 | sub 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 | |
971 | sub size_request { |
1003 | sub 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, |
… | |
… | |
999 | sub _draw { |
1032 | sub _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; |
1010 | glEnable GL_TEXTURE_2D; |
1043 | glEnable GL_TEXTURE_2D; |
1011 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1044 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1012 | |
1045 | |
1013 | glColor @{$self->{fg}}; |
1046 | glColor @{$self->{fg}}; |
1014 | |
1047 | |
1015 | my $x = |
1048 | $self->{ox} = int ( |
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 |
|
|
1052 | ); |
1019 | |
1053 | |
1020 | $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); |
1054 | $self->{oy} = int ( |
|
|
1055 | $self->{valign} < 0 ? $self->{padding} |
|
|
1056 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
|
|
1057 | : ($self->{h} - $tex->{h}) * 0.5 |
|
|
1058 | ); |
|
|
1059 | |
|
|
1060 | $tex->draw_quad ($self->{ox}, $self->{oy}); |
1021 | |
1061 | |
1022 | glDisable GL_TEXTURE_2D; |
1062 | glDisable GL_TEXTURE_2D; |
1023 | glDisable GL_BLEND; |
1063 | glDisable GL_BLEND; |
1024 | } |
1064 | } |
1025 | |
1065 | |
1026 | ############################################################################# |
1066 | ############################################################################# |
1027 | |
1067 | |
1028 | package CFClient::UI::Entry; |
1068 | package CFClient::UI::EntryBase; |
1029 | |
1069 | |
1030 | our @ISA = CFClient::UI::Label::; |
1070 | our @ISA = CFClient::UI::Label::; |
1031 | |
1071 | |
1032 | use SDL; |
1072 | use SDL; |
1033 | use SDL::OpenGL; |
1073 | use SDL::OpenGL; |
… | |
… | |
1040 | bg => [0, 0, 0, 0.2], |
1080 | bg => [0, 0, 0, 0.2], |
1041 | active_bg => [1, 1, 1, 0.5], |
1081 | active_bg => [1, 1, 1, 0.5], |
1042 | active_fg => [0, 0, 0], |
1082 | active_fg => [0, 0, 0], |
1043 | can_hover => 1, |
1083 | can_hover => 1, |
1044 | can_focus => 1, |
1084 | can_focus => 1, |
|
|
1085 | valign => 0, |
1045 | @_ |
1086 | @_ |
1046 | ) |
1087 | ) |
1047 | } |
1088 | } |
1048 | |
1089 | |
1049 | sub _set_text { |
1090 | sub _set_text { |
1050 | my ($self, $text) = @_; |
1091 | my ($self, $text) = @_; |
1051 | |
1092 | |
1052 | my $old_text = $self->{text}; |
1093 | delete $self->{cur_h}; |
|
|
1094 | |
|
|
1095 | return if $self->{text} eq $text; |
1053 | |
1096 | |
1054 | $self->{last_activity} = $::NOW; |
1097 | $self->{last_activity} = $::NOW; |
1055 | |
|
|
1056 | $self->{text} = $text; |
1098 | $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 | |
1099 | |
1060 | $text =~ s/./*/g if $self->{hidden}; |
1100 | $text =~ s/./*/g if $self->{hidden}; |
|
|
1101 | $self->{layout}->set_text ("$text "); |
1061 | |
1102 | |
1062 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1103 | $self->emit (changed => $self->{text}); |
|
|
1104 | } |
1063 | |
1105 | |
1064 | $text = substr $text, 0, $self->{cursor}; |
1106 | sub get_text { |
1065 | utf8::encode $text; |
1107 | $_[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 | } |
1108 | } |
1072 | |
1109 | |
1073 | sub size_request { |
1110 | sub size_request { |
1074 | my ($self) = @_; |
1111 | my ($self) = @_; |
1075 | |
1112 | |
… | |
… | |
1179 | |
1216 | |
1180 | $self->SUPER::_draw; |
1217 | $self->SUPER::_draw; |
1181 | |
1218 | |
1182 | #TODO: force update every cursor change :( |
1219 | #TODO: force update every cursor change :( |
1183 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
1220 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
|
|
1221 | |
|
|
1222 | unless (exists $self->{cur_h}) { |
|
|
1223 | my $text = substr $self->{text}, 0, $self->{cursor}; |
|
|
1224 | utf8::encode $text; |
|
|
1225 | |
|
|
1226 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
|
|
1227 | } |
|
|
1228 | |
1184 | glColor @{$self->{fg}}; |
1229 | glColor @{$self->{fg}}; |
1185 | glBegin GL_LINES; |
1230 | glBegin GL_LINES; |
1186 | glVertex $self->{cur_x}, $self->{cur_y}; |
|
|
1187 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1231 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
|
|
1232 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
1188 | glEnd; |
1233 | glEnd; |
1189 | } |
1234 | } |
1190 | } |
1235 | } |
1191 | |
1236 | |
1192 | package CFClient::UI::LineEntry; |
1237 | package CFClient::UI::Entry; |
1193 | |
1238 | |
1194 | our @ISA = CFClient::UI::Entry::; |
1239 | our @ISA = CFClient::UI::EntryBase::; |
1195 | |
1240 | |
1196 | use SDL; |
1241 | use SDL; |
1197 | use SDL::OpenGL; |
1242 | use SDL::OpenGL; |
1198 | |
1243 | |
1199 | sub key_down { |
1244 | sub key_down { |
… | |
… | |
1229 | |
1274 | |
1230 | $class->SUPER::new ( |
1275 | $class->SUPER::new ( |
1231 | padding => 4, |
1276 | padding => 4, |
1232 | fg => [1, 1, 1], |
1277 | fg => [1, 1, 1], |
1233 | bg => [1, 1, 1, 0.2], |
1278 | bg => [1, 1, 1, 0.2], |
1234 | active_fg => [1, 1, 0], |
1279 | active_fg => [0, 0, 1], |
1235 | can_hover => 1, |
1280 | can_hover => 1, |
1236 | @_ |
1281 | @_ |
1237 | ) |
1282 | ) |
1238 | } |
1283 | } |
1239 | |
1284 | |
… | |
… | |
1248 | |
1293 | |
1249 | sub _draw { |
1294 | sub _draw { |
1250 | my ($self) = @_; |
1295 | my ($self) = @_; |
1251 | |
1296 | |
1252 | local $self->{fg} = $self->{fg}; |
1297 | 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 | |
1298 | |
1259 | if ($GRAB == $self) { |
1299 | if ($GRAB == $self) { |
1260 | $self->{fg} = $self->{active_fg}; |
1300 | $self->{fg} = $self->{active_fg}; |
1261 | } |
1301 | } |
1262 | |
1302 | |
1263 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
1303 | glEnable GL_BLEND; |
|
|
1304 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1305 | glEnable GL_TEXTURE_2D; |
1264 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1306 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1307 | glColor 0, 0, 0, 1; |
1265 | |
1308 | |
1266 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
1309 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1267 | |
1310 | |
1268 | glDisable GL_TEXTURE_2D; |
1311 | glDisable GL_TEXTURE_2D; |
1269 | glDisable GL_BLEND; |
1312 | glDisable GL_BLEND; |
1270 | |
1313 | |
1271 | $self->SUPER::_draw; |
1314 | $self->SUPER::_draw; |
… | |
… | |
1575 | |
1618 | |
1576 | return unless $self->{h} > 0; |
1619 | return unless $self->{h} > 0; |
1577 | |
1620 | |
1578 | delete $self->{texture}; |
1621 | delete $self->{texture}; |
1579 | |
1622 | |
1580 | $TOPLEVEL->on_refresh ($self, sub { |
1623 | $ROOT->on_refresh ($self, sub { |
1581 | if (delete $self->{need_reflow}) { |
1624 | if (delete $self->{need_reflow}) { |
1582 | my $height = 0; |
1625 | my $height = 0; |
1583 | |
1626 | |
1584 | $height += $_->[0] = $self->text_height ($_->[2]) |
1627 | $height += $_->[0] = $self->text_height ($_->[2]) |
1585 | for @{$self->{par}}; |
1628 | for @{$self->{par}}; |
… | |
… | |
1753 | 0.1, 0.1, 0.1, |
1796 | 0.1, 0.1, 0.1, |
1754 | ; |
1797 | ; |
1755 | glEnable GL_CONVOLUTION_2D; |
1798 | glEnable GL_CONVOLUTION_2D; |
1756 | } |
1799 | } |
1757 | |
1800 | |
1758 | my $tex = new CFClient::Texture |
1801 | $self->{fow_texture} = new CFClient::Texture |
1759 | w => $w, |
1802 | w => $w, |
1760 | h => $h, |
1803 | h => $h, |
1761 | data => $data, |
1804 | data => $data, |
1762 | internalformat => GL_ALPHA, |
1805 | internalformat => GL_ALPHA, |
1763 | format => GL_ALPHA; |
1806 | format => GL_ALPHA; |
… | |
… | |
1768 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1811 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1769 | glEnable GL_TEXTURE_2D; |
1812 | glEnable GL_TEXTURE_2D; |
1770 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1813 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1771 | |
1814 | |
1772 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1815 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1773 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
1816 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
1774 | |
1817 | |
1775 | glDisable GL_TEXTURE_2D; |
1818 | glDisable GL_TEXTURE_2D; |
1776 | glDisable GL_BLEND; |
1819 | glDisable GL_BLEND; |
1777 | } |
1820 | } |
1778 | |
1821 | |
… | |
… | |
1784 | glEnable GL_BLEND; |
1827 | glEnable GL_BLEND; |
1785 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1828 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1786 | glEnable GL_TEXTURE_2D; |
1829 | glEnable GL_TEXTURE_2D; |
1787 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1830 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1788 | |
1831 | |
|
|
1832 | $self->{mapmap_texture} = |
1789 | CFClient::Texture->new ( |
1833 | new CFClient::Texture |
1790 | w => $w, |
1834 | w => $w, |
1791 | h => $h, |
1835 | h => $h, |
1792 | data => $::MAP->mapmap ($w, $h), |
1836 | data => $::MAP->mapmap ($w, $h), |
1793 | type => GL_UNSIGNED_INT_8_8_8_8_REV |
1837 | type => GL_UNSIGNED_INT_8_8_8_8_REV; |
1794 | )->draw_quad (100, 100); |
1838 | |
|
|
1839 | $self->{mapmap_texture}->draw_quad (100, 100); |
1795 | |
1840 | |
1796 | glDisable GL_TEXTURE_2D; |
1841 | glDisable GL_TEXTURE_2D; |
1797 | glDisable GL_BLEND; |
1842 | glDisable GL_BLEND; |
1798 | } |
1843 | } |
1799 | # HACK END |
1844 | # HACK END |
… | |
… | |
1841 | |
1886 | |
1842 | my $mod = $ev->key_mod; |
1887 | my $mod = $ev->key_mod; |
1843 | my $sym = $ev->key_sym; |
1888 | my $sym = $ev->key_sym; |
1844 | |
1889 | |
1845 | if ($sym == SDLK_KP5) { |
1890 | if ($sym == SDLK_KP5) { |
1846 | $::CONN->user_send ("command stay fire"); |
1891 | $::CONN->user_send ("stay fire"); |
1847 | } elsif ($sym == SDLK_a) { |
1892 | } elsif ($sym == SDLK_a) { |
1848 | $::CONN->user_send ("command apply"); |
1893 | $::CONN->user_send ("apply"); |
1849 | } elsif ($sym == SDLK_QUOTE) { |
1894 | } elsif ($sym == SDLK_QUOTE) { |
1850 | $self->emit ('activate_console'); |
1895 | $self->emit ('activate_console'); |
1851 | } elsif ($sym == SDLK_SLASH) { |
1896 | } elsif ($sym == SDLK_SLASH) { |
1852 | $self->emit ('activate_console' => '/'); |
1897 | $self->emit ('activate_console' => '/'); |
1853 | } elsif (exists $DIR{$sym}) { |
1898 | } elsif (exists $DIR{$sym}) { |
1854 | if ($mod & KMOD_SHIFT) { |
1899 | if ($mod & KMOD_SHIFT) { |
1855 | $self->{shft}++; |
1900 | $self->{shft}++; |
1856 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1901 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
1857 | } elsif ($mod & KMOD_CTRL) { |
1902 | } elsif ($mod & KMOD_CTRL) { |
1858 | $self->{ctrl}++; |
1903 | $self->{ctrl}++; |
1859 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
1904 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
1860 | } else { |
1905 | } else { |
1861 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
1906 | $::CONN->user_send ("$DIR{$sym}[1]"); |
1862 | } |
1907 | } |
1863 | } |
1908 | } |
1864 | } |
1909 | } |
1865 | |
1910 | |
1866 | sub key_up { |
1911 | sub key_up { |
… | |
… | |
1868 | |
1913 | |
1869 | my $mod = $ev->key_mod; |
1914 | my $mod = $ev->key_mod; |
1870 | my $sym = $ev->key_sym; |
1915 | my $sym = $ev->key_sym; |
1871 | |
1916 | |
1872 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1917 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1873 | $::CONN->user_send ("command fire_stop"); |
1918 | $::CONN->user_send ("fire_stop"); |
1874 | } |
1919 | } |
1875 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1920 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1876 | $::CONN->user_send ("command run_stop"); |
1921 | $::CONN->user_send ("run_stop"); |
1877 | } |
1922 | } |
1878 | } |
1923 | } |
1879 | |
1924 | |
1880 | ############################################################################# |
1925 | ############################################################################# |
1881 | |
1926 | |
… | |
… | |
1945 | sub toggle_flopper { |
1990 | sub toggle_flopper { |
1946 | my ($self) = @_; |
1991 | my ($self) = @_; |
1947 | |
1992 | |
1948 | # TODO: use animation |
1993 | # TODO: use animation |
1949 | if ($self->{state} = !$self->{state}) { |
1994 | if ($self->{state} = !$self->{state}) { |
1950 | $CFClient::UI::TOPLEVEL->add ($self->{other}); |
1995 | $CFClient::UI::ROOT->add ($self->{other}); |
1951 | $self->{other}->move ( |
1996 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
1952 | ($::WIDTH - $self->{other}{w}) * 0.5, |
1997 | $self->emit ("open"); |
1953 | ($::HEIGHT - $self->{other}{h}) * 0.5, |
|
|
1954 | ); |
|
|
1955 | } else { |
1998 | } else { |
1956 | $CFClient::UI::TOPLEVEL->remove ($self->{other}); |
1999 | $CFClient::UI::ROOT->remove ($self->{other}); |
|
|
2000 | $self->emit ("close"); |
1957 | } |
2001 | } |
1958 | } |
|
|
1959 | |
2002 | |
1960 | ############################################################################# |
2003 | $self->emit (changed => $self->{state}); |
|
|
2004 | } |
1961 | |
2005 | |
|
|
2006 | ############################################################################# |
|
|
2007 | |
1962 | package CFClient::UI::Toplevel; |
2008 | package CFClient::UI::Root; |
1963 | |
2009 | |
1964 | our @ISA = CFClient::UI::Container::; |
2010 | our @ISA = CFClient::UI::Container::; |
1965 | |
2011 | |
1966 | use SDL::OpenGL; |
2012 | use SDL::OpenGL; |
1967 | |
2013 | |
… | |
… | |
1976 | |
2022 | |
1977 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
2023 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
1978 | for @{$self->{children}}; |
2024 | for @{$self->{children}}; |
1979 | } |
2025 | } |
1980 | |
2026 | |
1981 | sub translate { |
2027 | sub _topleft { |
1982 | my ($self, $x, $y) = @_; |
2028 | my ($self, $x, $y) = @_; |
1983 | |
2029 | |
1984 | ($x, $y) |
2030 | ($x, $y) |
1985 | } |
2031 | } |
1986 | |
2032 | |
… | |
… | |
1994 | sub add { |
2040 | sub add { |
1995 | my ($self, $widget) = @_; |
2041 | my ($self, $widget) = @_; |
1996 | |
2042 | |
1997 | $self->SUPER::add ($widget); |
2043 | $self->SUPER::add ($widget); |
1998 | |
2044 | |
1999 | $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); |
2045 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
2000 | } |
2046 | } |
2001 | |
2047 | |
2002 | sub on_refresh { |
2048 | sub on_refresh { |
2003 | my ($self, $id, $cb) = @_; |
2049 | my ($self, $id, $cb) = @_; |
2004 | |
2050 | |
… | |
… | |
2027 | |
2073 | |
2028 | ############################################################################# |
2074 | ############################################################################# |
2029 | |
2075 | |
2030 | package CFClient::UI; |
2076 | package CFClient::UI; |
2031 | |
2077 | |
2032 | $TOPLEVEL = new CFClient::UI::Toplevel; |
2078 | $ROOT = new CFClient::UI::Root; |
2033 | |
2079 | |
2034 | 1 |
2080 | 1 |
2035 | |
2081 | |