… | |
… | |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
22 | } |
22 | } |
23 | |
23 | |
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->{x}, $ev->{y}); |
27 | |
27 | |
28 | if (!$BUTTON_STATE) { |
28 | if (!$BUTTON_STATE) { |
29 | my $widget = $ROOT->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->coord2local ($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->{x}, $ev->{y}); |
43 | |
43 | |
44 | my $widget = $GRAB || $ROOT->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->coord2local ($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; |
… | |
… | |
54 | } |
54 | } |
55 | } |
55 | } |
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->{x}, $ev->{y}); |
60 | |
60 | |
61 | my $widget = $GRAB || $ROOT->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; |
… | |
… | |
87 | |
87 | |
88 | package CFClient::UI::Base; |
88 | package CFClient::UI::Base; |
89 | |
89 | |
90 | use strict; |
90 | use strict; |
91 | |
91 | |
92 | use SDL::OpenGL; |
92 | use CFClient::OpenGL; |
93 | |
93 | |
94 | sub new { |
94 | sub new { |
95 | my $class = shift; |
95 | my $class = shift; |
96 | |
96 | |
97 | my $self = bless { |
97 | my $self = bless { |
98 | x => 0, |
98 | x => 0, |
99 | y => 0, |
99 | y => 0, |
100 | z => 0, |
100 | z => 0, |
101 | w => -1, |
|
|
102 | h => -1, |
|
|
103 | @_ |
101 | @_ |
104 | }, $class; |
102 | }, $class; |
105 | |
103 | |
106 | for (keys %$self) { |
104 | for (keys %$self) { |
107 | if (/^connect_(.*)$/) { |
105 | if (/^connect_(.*)$/) { |
… | |
… | |
110 | } |
108 | } |
111 | |
109 | |
112 | $self |
110 | $self |
113 | } |
111 | } |
114 | |
112 | |
|
|
113 | sub show { |
|
|
114 | my ($self) = @_; |
|
|
115 | |
|
|
116 | return if $self->{parent}; |
|
|
117 | |
|
|
118 | $CFClient::UI::ROOT->add ($self); |
|
|
119 | } |
|
|
120 | |
|
|
121 | sub hide { |
|
|
122 | my ($self) = @_; |
|
|
123 | |
|
|
124 | return unless $self->{parent}; |
|
|
125 | |
|
|
126 | $self->{parent}->remove ($self); |
|
|
127 | } |
|
|
128 | |
115 | sub move { |
129 | sub move { |
116 | my ($self, $x, $y, $z) = @_; |
130 | my ($self, $x, $y, $z) = @_; |
|
|
131 | |
117 | $self->{x} = int $x; |
132 | $self->{x} = int $x; |
118 | $self->{y} = int $y; |
133 | $self->{y} = int $y; |
119 | $self->{z} = $z if defined $z; |
134 | $self->{z} = $z if defined $z; |
|
|
135 | |
|
|
136 | $self->update; |
120 | } |
137 | } |
121 | |
138 | |
122 | sub needs_redraw { |
139 | sub needs_redraw { |
123 | 0 |
140 | 0 |
124 | } |
141 | } |
… | |
… | |
126 | sub size_request { |
143 | sub size_request { |
127 | require Carp; |
144 | require Carp; |
128 | Carp::confess "size_request is abtract"; |
145 | Carp::confess "size_request is abtract"; |
129 | } |
146 | } |
130 | |
147 | |
131 | sub _size_allocate { |
148 | sub configure { |
132 | my ($self, $x, $y, $w, $h) = @_; |
149 | my ($self, $x, $y, $w, $h) = @_; |
133 | |
150 | |
134 | $self->{x} = $x; |
151 | $self->{x} = $x; |
135 | $self->{y} = $y; |
152 | $self->{y} = $y; |
136 | |
153 | |
137 | return unless $self->{w} != $w || $self->{h} != $h; |
154 | return unless $self->{w} != $w || $self->{h} != $h; |
138 | |
155 | |
139 | $self->{w} = $w; |
156 | $self->{w} = $w; |
140 | $self->{h} = $h; |
157 | $self->{h} = $h; |
141 | |
158 | |
142 | 1 |
159 | $self->size_allocate ($w, $h); |
|
|
160 | $self->update; |
143 | } |
161 | } |
144 | |
162 | |
145 | sub size_allocate { |
163 | sub size_allocate { |
146 | my ($self, $x, $y, $w, $h) = @_; |
164 | # nothing to be done |
147 | |
|
|
148 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
149 | } |
165 | } |
150 | |
166 | |
151 | # return top left coordinates |
167 | # return top left coordinates |
152 | sub _topleft { |
168 | sub _topleft { |
153 | my ($self, $x, $y) = @_; |
169 | my ($self, $x, $y) = @_; |
… | |
… | |
176 | |
192 | |
177 | return if $FOCUS == $self; |
193 | return if $FOCUS == $self; |
178 | return unless $self->{can_focus}; |
194 | return unless $self->{can_focus}; |
179 | |
195 | |
180 | my $focus = $FOCUS; $FOCUS = $self; |
196 | my $focus = $FOCUS; $FOCUS = $self; |
|
|
197 | |
|
|
198 | $self->emit (focus_in => $focus); |
|
|
199 | |
181 | $focus->update if $focus; |
200 | $focus->update if $focus; |
182 | $FOCUS->update; |
201 | $FOCUS->update; |
183 | } |
202 | } |
184 | |
203 | |
185 | sub focus_out { |
204 | sub focus_out { |
186 | my ($self) = @_; |
205 | my ($self) = @_; |
187 | |
206 | |
188 | return unless $FOCUS == $self; |
207 | return unless $FOCUS == $self; |
189 | |
208 | |
190 | my $focus = $FOCUS; undef $FOCUS; |
209 | my $focus = $FOCUS; undef $FOCUS; |
|
|
210 | |
|
|
211 | $self->emit (focus_out => $focus); |
|
|
212 | |
191 | $focus->update if $focus; #? |
213 | $focus->update if $focus; #? |
192 | } |
214 | } |
193 | |
215 | |
194 | sub mouse_motion { } |
216 | sub mouse_motion { } |
195 | sub button_up { } |
217 | sub button_up { } |
… | |
… | |
219 | glPopMatrix; |
241 | glPopMatrix; |
220 | |
242 | |
221 | if ($self == $HOVER && $self->{can_hover}) { |
243 | if ($self == $HOVER && $self->{can_hover}) { |
222 | my ($x, $y) = @$self{qw(x y)}; |
244 | my ($x, $y) = @$self{qw(x y)}; |
223 | |
245 | |
224 | glColor 0, 0, 1, 0.2; |
246 | glColor 1, 0.8, 0.5, 0.2; |
225 | glEnable GL_BLEND; |
247 | glEnable GL_BLEND; |
226 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
248 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
227 | glBegin GL_QUADS; |
249 | glBegin GL_QUADS; |
228 | glVertex $x , $y; |
250 | glVertex $x , $y; |
229 | glVertex $x + $self->{w}, $y; |
251 | glVertex $x + $self->{w}, $y; |
… | |
… | |
254 | my ($self, $parent) = @_; |
276 | my ($self, $parent) = @_; |
255 | |
277 | |
256 | Scalar::Util::weaken ($self->{parent} = $parent); |
278 | Scalar::Util::weaken ($self->{parent} = $parent); |
257 | } |
279 | } |
258 | |
280 | |
|
|
281 | sub check_size { |
|
|
282 | my ($self) = @_; |
|
|
283 | |
|
|
284 | my ($w, $h) = $self->size_request; |
|
|
285 | |
|
|
286 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
|
|
287 | $self->{req_w} = $w; |
|
|
288 | $self->{req_h} = $h; |
|
|
289 | |
|
|
290 | $self->{parent}->check_size |
|
|
291 | if $self->{parent}; |
|
|
292 | } |
|
|
293 | } |
|
|
294 | |
259 | sub update { |
295 | sub update { |
260 | my ($self) = @_; |
296 | my ($self) = @_; |
261 | |
297 | |
262 | $self->{parent}->update |
298 | $self->{parent}->update |
263 | if $self->{parent}; |
299 | if $self->{parent}; |
264 | } |
300 | } |
265 | |
301 | |
266 | sub connect { |
302 | sub connect { |
267 | my ($self, $signal, $cb) = @_; |
303 | my ($self, $signal, $cb) = @_; |
268 | |
304 | |
269 | push @{ $self->{cb}{$signal} }, $cb; |
305 | push @{ $self->{signal_cb}{$signal} }, $cb; |
270 | } |
306 | } |
271 | |
307 | |
272 | sub emit { |
308 | sub emit { |
273 | my ($self, $signal, @args) = @_; |
309 | my ($self, $signal, @args) = @_; |
274 | |
310 | |
|
|
311 | for my $cb (@{$self->{signal_cb}{$signal} || []}) { |
275 | $_->($self, @args) |
312 | $cb->($self, @args); |
276 | for @{$self->{cb}{$signal} || []}; |
313 | } |
277 | } |
314 | } |
278 | |
315 | |
279 | sub DESTROY { |
316 | sub DESTROY { |
280 | my ($self) = @_; |
317 | my ($self) = @_; |
281 | |
318 | |
… | |
… | |
287 | package CFClient::UI::DrawBG; |
324 | package CFClient::UI::DrawBG; |
288 | |
325 | |
289 | our @ISA = CFClient::UI::Base::; |
326 | our @ISA = CFClient::UI::Base::; |
290 | |
327 | |
291 | use strict; |
328 | use strict; |
292 | use SDL::OpenGL; |
329 | use CFClient::OpenGL; |
293 | |
330 | |
294 | sub new { |
331 | sub new { |
295 | my $class = shift; |
332 | my $class = shift; |
296 | |
333 | |
297 | # range [value, low, high, page] |
334 | # range [value, low, high, page] |
… | |
… | |
361 | $self->{children} = [ |
398 | $self->{children} = [ |
362 | sort { $a->{z} <=> $b->{z} } |
399 | sort { $a->{z} <=> $b->{z} } |
363 | @{$self->{children}}, $child |
400 | @{$self->{children}}, $child |
364 | ]; |
401 | ]; |
365 | |
402 | |
366 | $self->{w} = $self->{h} = -1; |
403 | $child->check_size; |
367 | $self->update; |
|
|
368 | } |
404 | } |
369 | |
405 | |
370 | sub remove { |
406 | sub remove { |
371 | my ($self, $widget) = @_; |
407 | my ($self, $child) = @_; |
372 | |
408 | |
|
|
409 | delete $child->{parent}; |
|
|
410 | |
373 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
411 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
374 | |
412 | |
375 | $self->size_allocate (0, 0, $self->{w}, $self->{h}); |
413 | $self->check_size; |
376 | } |
414 | } |
377 | |
415 | |
378 | sub find_widget { |
416 | sub find_widget { |
379 | my ($self, $x, $y) = @_; |
417 | my ($self, $x, $y) = @_; |
380 | |
418 | |
… | |
… | |
410 | |
448 | |
411 | $class->SUPER::new (children => [$child], %arg) |
449 | $class->SUPER::new (children => [$child], %arg) |
412 | } |
450 | } |
413 | |
451 | |
414 | sub add { |
452 | sub add { |
415 | my ($self, $widget) = @_; |
453 | my ($self, $child) = @_; |
416 | |
454 | |
417 | $self->{children} = []; |
455 | $self->{children} = []; |
418 | |
456 | |
419 | $self->SUPER::add ($widget); |
457 | $self->SUPER::add ($child); |
420 | } |
458 | } |
421 | |
459 | |
422 | sub remove { |
460 | sub remove { |
423 | my ($self, $widget) = @_; |
461 | my ($self, $widget) = @_; |
424 | |
462 | |
… | |
… | |
433 | sub size_request { |
471 | sub size_request { |
434 | $_[0]{children}[0]->size_request |
472 | $_[0]{children}[0]->size_request |
435 | } |
473 | } |
436 | |
474 | |
437 | sub size_allocate { |
475 | sub size_allocate { |
438 | my ($self, $x, $y, $w, $h) = @_; |
476 | my ($self, $w, $h) = @_; |
439 | |
477 | |
440 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
441 | |
|
|
442 | $self->{children}[0]->size_allocate (0, 0, $w, $h); |
478 | $self->{children}[0]->configure (0, 0, $w, $h); |
443 | } |
479 | } |
444 | |
480 | |
445 | ############################################################################# |
481 | ############################################################################# |
446 | |
482 | |
447 | package CFClient::UI::Window; |
483 | package CFClient::UI::Window; |
448 | |
484 | |
449 | our @ISA = CFClient::UI::Bin::; |
485 | our @ISA = CFClient::UI::Bin::; |
450 | |
486 | |
451 | use SDL::OpenGL; |
487 | use CFClient::OpenGL; |
452 | |
488 | |
453 | sub new { |
489 | sub new { |
454 | my ($class, %arg) = @_; |
490 | my ($class, %arg) = @_; |
455 | |
491 | |
456 | my $self = $class->SUPER::new (%arg); |
492 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
473 | $self->child->draw; |
509 | $self->child->draw; |
474 | }; |
510 | }; |
475 | } |
511 | } |
476 | |
512 | |
477 | sub size_allocate { |
513 | sub size_allocate { |
478 | my ($self, $x, $y, $w, $h) = @_; |
514 | my ($self, $w, $h) = @_; |
479 | |
515 | |
480 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
481 | |
|
|
482 | $self->child->size_allocate (0, 0, $w, $h); |
516 | $self->child->configure (0, 0, $w, $h); |
483 | |
517 | |
484 | $self->render_chld; |
518 | $self->render_chld; |
485 | } |
519 | } |
486 | |
520 | |
487 | sub _draw { |
521 | sub _draw { |
… | |
… | |
503 | glDisable GL_TEXTURE_2D; |
537 | glDisable GL_TEXTURE_2D; |
504 | } |
538 | } |
505 | |
539 | |
506 | ############################################################################# |
540 | ############################################################################# |
507 | |
541 | |
|
|
542 | package CFClient::UI::ViewPort; |
|
|
543 | |
|
|
544 | our @ISA = CFClient::UI::Window::; |
|
|
545 | |
|
|
546 | sub new { die } |
|
|
547 | |
|
|
548 | sub size_request { |
|
|
549 | my ($self) = @_; |
|
|
550 | |
|
|
551 | @$self{qw(child_w child_h)} = $self->child->size_request; |
|
|
552 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
|
|
553 | |
|
|
554 | @$self{qw(child_w child_h)} |
|
|
555 | } |
|
|
556 | |
|
|
557 | sub _draw { |
|
|
558 | my ($self) = @_; |
|
|
559 | |
|
|
560 | $self->{children}[1]->draw; |
|
|
561 | } |
|
|
562 | |
|
|
563 | |
|
|
564 | ############################################################################# |
|
|
565 | |
508 | package CFClient::UI::Frame; |
566 | package CFClient::UI::Frame; |
509 | |
567 | |
510 | our @ISA = CFClient::UI::Bin::; |
568 | our @ISA = CFClient::UI::Bin::; |
511 | |
569 | |
512 | use SDL::OpenGL; |
570 | use CFClient::OpenGL; |
513 | |
571 | |
514 | sub size_request { |
572 | sub size_request { |
515 | my ($self) = @_; |
573 | my ($self) = @_; |
516 | my $chld = $self->child |
574 | my $chld = $self->child |
517 | or return (0, 0); |
575 | or return (0, 0); |
… | |
… | |
522 | } |
580 | } |
523 | |
581 | |
524 | sub size_allocate { |
582 | sub size_allocate { |
525 | my ($self, $x, $y, $w, $h) = @_; |
583 | my ($self, $x, $y, $w, $h) = @_; |
526 | |
584 | |
527 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
528 | |
|
|
529 | $self->child->size_allocate (2, 2, $w - 4, $h - 4); |
585 | $self->child->configure (2, 2, $w - 4, $h - 4); |
530 | } |
586 | } |
531 | |
587 | |
532 | sub _draw { |
588 | sub _draw { |
533 | my ($self) = @_; |
589 | my ($self) = @_; |
534 | |
590 | |
… | |
… | |
551 | |
607 | |
552 | package CFClient::UI::FancyFrame; |
608 | package CFClient::UI::FancyFrame; |
553 | |
609 | |
554 | our @ISA = CFClient::UI::Bin::; |
610 | our @ISA = CFClient::UI::Bin::; |
555 | |
611 | |
556 | use SDL::OpenGL; |
612 | use CFClient::OpenGL; |
557 | |
613 | |
558 | my @tex = |
614 | my @tex = |
559 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
615 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
560 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
616 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
561 | |
617 | |
… | |
… | |
565 | # TODO: user_x, user_y, overwrite moveto? |
621 | # TODO: user_x, user_y, overwrite moveto? |
566 | |
622 | |
567 | $class->SUPER::new ( |
623 | $class->SUPER::new ( |
568 | bg => [1, 1, 1, 1], |
624 | bg => [1, 1, 1, 1], |
569 | border_bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
570 | border => int $::FONTSIZE * 0.8, |
626 | border => 0.8, |
571 | @_ |
627 | @_ |
572 | ) |
628 | ) |
573 | } |
629 | } |
574 | |
630 | |
|
|
631 | sub border { |
|
|
632 | int $_[0]{border} * $::FONTSIZE |
|
|
633 | } |
|
|
634 | |
575 | sub size_request { |
635 | sub size_request { |
576 | my ($self) = @_; |
636 | my ($self) = @_; |
577 | |
637 | |
578 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
638 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
579 | |
639 | |
580 | my ($w, $h) = $self->SUPER::size_request; |
640 | my ($w, $h) = $self->SUPER::size_request; |
581 | |
641 | |
582 | ( |
642 | ( |
583 | $w + $self->{border} * 2, |
643 | $w + $self->border * 2, |
584 | $h + $self->{border} * 2, |
644 | $h + $self->border * 2, |
585 | ) |
645 | ) |
586 | } |
646 | } |
587 | |
647 | |
588 | sub size_allocate { |
648 | sub size_allocate { |
589 | my ($self, $x, $y, $w, $h) = @_; |
649 | my ($self, $w, $h) = @_; |
590 | |
650 | |
591 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
592 | |
|
|
593 | $h -= List::Util::max 0, $self->{border} * 2; |
651 | $h -= List::Util::max 0, $self->border * 2; |
594 | $w -= List::Util::max 0, $self->{border} * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
595 | |
653 | |
596 | $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
597 | } |
655 | } |
598 | |
656 | |
599 | sub button_down { |
657 | sub button_down { |
600 | my ($self, $ev, $x, $y) = @_; |
658 | my ($self, $ev, $x, $y) = @_; |
601 | |
659 | |
|
|
660 | my $border = $self->border; |
|
|
661 | |
602 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
662 | if ($x < $self->{w} && $x >= $self->{w} - $border |
603 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
663 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
604 | |
664 | |
605 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
665 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
606 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
666 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
607 | |
667 | |
608 | $self->{motion} = sub { |
668 | $self->{motion} = sub { |
… | |
… | |
610 | |
670 | |
611 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
671 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
612 | |
672 | |
613 | $self->{user_w} = $bw + $x - $ox; |
673 | $self->{user_w} = $bw + $x - $ox; |
614 | $self->{user_h} = $bh + $y - $oy; |
674 | $self->{user_h} = $bh + $y - $oy; |
615 | $self->update; |
675 | $self->check_size; |
616 | }; |
676 | }; |
617 | |
677 | |
618 | } elsif ($x >= 0 && $x < $self->{w} |
678 | } elsif ($x >= 0 && $x < $self->{w} |
619 | && $y >= 0 && $y < $self->{border}) { |
679 | && $y >= 0 && $y < $border) { |
620 | |
680 | |
621 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
681 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
622 | my ($bx, $by) = ($self->{x}, $self->{y}); |
682 | my ($bx, $by) = ($self->{x}, $self->{y}); |
623 | |
683 | |
624 | $self->{motion} = sub { |
684 | $self->{motion} = sub { |
… | |
… | |
653 | glEnable GL_BLEND; |
713 | glEnable GL_BLEND; |
654 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
714 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
655 | glEnable GL_TEXTURE_2D; |
715 | glEnable GL_TEXTURE_2D; |
656 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
716 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
657 | |
717 | |
|
|
718 | my $border = $self->border; |
|
|
719 | |
658 | glColor @{ $self->{border_bg} }; |
720 | glColor @{ $self->{border_bg} }; |
659 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
721 | $tex[1]->draw_quad (0, 0, $w, $border); |
660 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
722 | $tex[3]->draw_quad (0, $border, $border, $ch); |
661 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
723 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
662 | $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); |
724 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
663 | |
725 | |
664 | my $bg = $tex[0]; |
726 | my $bg = $tex[0]; |
665 | |
727 | |
666 | # TODO: repeat texture not scale |
728 | # TODO: repeat texture not scale |
667 | my $rep_x = $cw / $bg->{w}; |
729 | my $rep_x = $cw / $bg->{w}; |
… | |
… | |
670 | glColor @{ $self->{bg} }; |
732 | glColor @{ $self->{bg} }; |
671 | |
733 | |
672 | $bg->{s} = $rep_x; |
734 | $bg->{s} = $rep_x; |
673 | $bg->{t} = $rep_y; |
735 | $bg->{t} = $rep_y; |
674 | $bg->{wrap_mode} = 1; |
736 | $bg->{wrap_mode} = 1; |
675 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
676 | |
738 | |
677 | glDisable GL_TEXTURE_2D; |
739 | glDisable GL_TEXTURE_2D; |
678 | glDisable GL_BLEND; |
740 | glDisable GL_BLEND; |
679 | |
741 | |
680 | $self->child->draw; |
742 | $self->child->draw; |
… | |
… | |
686 | |
748 | |
687 | our @ISA = CFClient::UI::Base::; |
749 | our @ISA = CFClient::UI::Base::; |
688 | |
750 | |
689 | use List::Util qw(max sum); |
751 | use List::Util qw(max sum); |
690 | |
752 | |
691 | use SDL::OpenGL; |
753 | use CFClient::OpenGL; |
692 | |
754 | |
693 | sub new { |
755 | sub new { |
694 | my $class = shift; |
756 | my $class = shift; |
695 | |
757 | |
696 | $class->SUPER::new ( |
758 | $class->SUPER::new ( |
… | |
… | |
703 | my ($self, $x, $y, $child) = @_; |
765 | my ($self, $x, $y, $child) = @_; |
704 | |
766 | |
705 | $child->set_parent ($self); |
767 | $child->set_parent ($self); |
706 | $self->{children}[$y][$x] = $child; |
768 | $self->{children}[$y][$x] = $child; |
707 | |
769 | |
708 | $self->{w} = $self->{h} = -1; |
770 | $child->check_size; |
709 | $self->update; |
|
|
710 | } |
771 | } |
711 | |
772 | |
712 | # TODO: move to container class maybe? send childs a signal on removal? |
773 | # TODO: move to container class maybe? send childs a signal on removal? |
713 | sub clear { |
774 | sub clear { |
714 | my ($self) = @_; |
775 | my ($self) = @_; |
… | |
… | |
749 | (sum @$hs), |
810 | (sum @$hs), |
750 | ) |
811 | ) |
751 | } |
812 | } |
752 | |
813 | |
753 | sub size_allocate { |
814 | sub size_allocate { |
754 | my ($self, $x, $y, $w, $h) = @_; |
815 | my ($self, $w, $h) = @_; |
755 | |
|
|
756 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
757 | |
816 | |
758 | my ($ws, $hs) = $self->get_wh; |
817 | my ($ws, $hs) = $self->get_wh; |
759 | |
818 | |
760 | my $req_w = sum @$ws; |
819 | my $req_w = sum @$ws; |
761 | my $req_h = sum @$hs; |
820 | my $req_h = sum @$hs; |
… | |
… | |
783 | |
842 | |
784 | for my $c (0 .. $#$row) { |
843 | for my $c (0 .. $#$row) { |
785 | my $col_w = $ws->[$c]; |
844 | my $col_w = $ws->[$c]; |
786 | |
845 | |
787 | if (my $widget = $row->[$c]) { |
846 | if (my $widget = $row->[$c]) { |
788 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
847 | $widget->configure ($x, $y, $col_w, $row_h); |
789 | } |
848 | } |
790 | |
849 | |
791 | $x += $col_w; |
850 | $x += $col_w; |
792 | } |
851 | } |
793 | |
852 | |
… | |
… | |
838 | (List::Util::max map $_->[1], @alloc), |
897 | (List::Util::max map $_->[1], @alloc), |
839 | ) |
898 | ) |
840 | } |
899 | } |
841 | |
900 | |
842 | sub size_allocate { |
901 | sub size_allocate { |
843 | my ($self, $x, $y, $w, $h) = @_; |
902 | my ($self, $w, $h) = @_; |
844 | |
|
|
845 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
846 | |
903 | |
847 | ($h, $w) = ($w, $h); |
904 | ($h, $w) = ($w, $h); |
848 | |
905 | |
849 | my $children = $self->{children}; |
906 | my $children = $self->{children}; |
850 | |
907 | |
… | |
… | |
872 | |
929 | |
873 | my $y = 0; |
930 | my $y = 0; |
874 | for (0 .. $#$children) { |
931 | for (0 .. $#$children) { |
875 | my $child = $children->[$_]; |
932 | my $child = $children->[$_]; |
876 | my $h = $h[$_]; |
933 | my $h = $h[$_]; |
877 | $child->size_allocate ($y, 0, $h, $w); |
934 | $child->configure ($y, 0, $h, $w); |
878 | |
935 | |
879 | $y += $h; |
936 | $y += $h; |
880 | } |
937 | } |
|
|
938 | |
|
|
939 | 1 |
881 | } |
940 | } |
882 | |
941 | |
883 | ############################################################################# |
942 | ############################################################################# |
884 | |
943 | |
885 | package CFClient::UI::VBox; |
944 | package CFClient::UI::VBox; |
… | |
… | |
898 | (List::Util::sum map $_->[1], @alloc), |
957 | (List::Util::sum map $_->[1], @alloc), |
899 | ) |
958 | ) |
900 | } |
959 | } |
901 | |
960 | |
902 | sub size_allocate { |
961 | sub size_allocate { |
903 | my ($self, $x, $y, $w, $h) = @_; |
962 | my ($self, $w, $h) = @_; |
904 | |
|
|
905 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
906 | |
963 | |
907 | my $children = $self->{children}; |
964 | my $children = $self->{children}; |
908 | |
965 | |
909 | my @h = map +($_->size_request)[1], @$children; |
966 | my @h = map +($_->size_request)[1], @$children; |
910 | |
967 | |
… | |
… | |
928 | |
985 | |
929 | my $y = 0; |
986 | my $y = 0; |
930 | for (0 .. $#$children) { |
987 | for (0 .. $#$children) { |
931 | my $child = $children->[$_]; |
988 | my $child = $children->[$_]; |
932 | my $h = $h[$_]; |
989 | my $h = $h[$_]; |
933 | $child->size_allocate (0, $y, $w, $h); |
990 | $child->configure (0, $y, $w, $h); |
934 | |
991 | |
935 | $y += $h; |
992 | $y += $h; |
936 | } |
993 | } |
|
|
994 | |
|
|
995 | 1 |
937 | } |
996 | } |
938 | |
997 | |
939 | ############################################################################# |
998 | ############################################################################# |
940 | |
999 | |
941 | package CFClient::UI::Label; |
1000 | package CFClient::UI::Label; |
942 | |
1001 | |
943 | our @ISA = CFClient::UI::Base::; |
1002 | our @ISA = CFClient::UI::Base::; |
944 | |
1003 | |
945 | use SDL::OpenGL; |
1004 | use CFClient::OpenGL; |
946 | |
1005 | |
947 | sub new { |
1006 | sub new { |
948 | my ($class, %arg) = @_; |
1007 | my ($class, %arg) = @_; |
949 | |
1008 | |
950 | my $self = $class->SUPER::new ( |
1009 | my $self = $class->SUPER::new ( |
951 | fg => [1, 1, 1], |
1010 | fg => [1, 1, 1], |
952 | fontsize => $::FONTSIZE, |
1011 | fontsize => 1, |
953 | text => "", |
1012 | text => "", |
954 | align => -1, |
1013 | align => -1, |
955 | valign => -1, |
1014 | valign => -1, |
956 | padding => 2, |
1015 | padding => 2, |
957 | layout => new CFClient::Layout, |
1016 | layout => new CFClient::Layout, |
958 | %arg |
1017 | %arg |
959 | ); |
1018 | ); |
960 | |
1019 | |
961 | $self->set_text ($self->{text}); |
1020 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
|
|
1021 | |
|
|
1022 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
|
|
1023 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
962 | |
1024 | |
963 | $self |
1025 | $self |
964 | } |
1026 | } |
965 | |
1027 | |
966 | sub escape_text { |
1028 | sub escape_text { |
… | |
… | |
974 | } |
1036 | } |
975 | |
1037 | |
976 | sub set_text { |
1038 | sub set_text { |
977 | my ($self, $text) = @_; |
1039 | my ($self, $text) = @_; |
978 | |
1040 | |
979 | $self->{text} = $text; |
|
|
980 | $self->{layout}->set_markup ($text); |
1041 | $self->{layout}->set_text ($text); |
981 | |
1042 | |
982 | delete $self->{texture}; |
1043 | delete $self->{texture}; |
983 | # $self->{w} = $self->{h} = -1; |
|
|
984 | $self->update; |
1044 | $self->update; |
985 | } |
1045 | } |
986 | |
1046 | |
987 | sub get_text { |
1047 | sub set_markup { |
988 | my ($self, $text) = @_; |
1048 | my ($self, $markup) = @_; |
989 | |
1049 | |
990 | $self->{text} |
1050 | $self->{layout}->set_markup ($markup); |
|
|
1051 | |
|
|
1052 | delete $self->{texture}; |
|
|
1053 | $self->update; |
991 | } |
1054 | } |
992 | |
1055 | |
993 | sub size_request { |
1056 | sub size_request { |
994 | my ($self) = @_; |
1057 | my ($self) = @_; |
995 | |
1058 | |
996 | $self->{layout}->set_width; |
1059 | $self->{layout}->set_width; |
997 | $self->{layout}->set_height ($self->{fontsize}); |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1061 | |
998 | my ($w, $h) = $self->{layout}->size; |
1062 | my ($w, $h) = $self->{layout}->size; |
999 | |
1063 | |
1000 | ( |
1064 | ( |
1001 | $w + $self->{padding} * 2, |
1065 | $w + $self->{padding} * 2, |
1002 | $h + $self->{padding} * 2, |
1066 | $h + $self->{padding} * 2, |
1003 | ) |
1067 | ) |
1004 | } |
1068 | } |
1005 | |
1069 | |
1006 | sub size_allocate { |
1070 | sub size_allocate { |
1007 | my ($self, $x, $y, $w, $h) = @_; |
1071 | my ($self, $w, $h) = @_; |
1008 | |
|
|
1009 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1010 | |
1072 | |
1011 | delete $self->{texture}; |
1073 | delete $self->{texture}; |
1012 | } |
|
|
1013 | |
|
|
1014 | sub update { |
|
|
1015 | my ($self) = @_; |
|
|
1016 | |
|
|
1017 | delete $self->{texture}; |
|
|
1018 | $self->SUPER::update; |
|
|
1019 | } |
1074 | } |
1020 | |
1075 | |
1021 | sub _draw { |
1076 | sub _draw { |
1022 | my ($self) = @_; |
1077 | my ($self) = @_; |
1023 | |
1078 | |
1024 | my $tex = $self->{texture} ||= do { |
1079 | my $tex = $self->{texture} ||= do { |
1025 | $self->{layout}->set_width ($self->{w}); |
1080 | $self->{layout}->set_width ($self->{w}); |
1026 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
1081 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1027 | new_from_layout CFClient::Texture $self->{layout} |
1082 | new_from_layout CFClient::Texture $self->{layout} |
1028 | }; |
1083 | }; |
1029 | |
1084 | |
1030 | glEnable GL_BLEND; |
1085 | glEnable GL_BLEND; |
1031 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1086 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1032 | glEnable GL_TEXTURE_2D; |
1087 | glEnable GL_TEXTURE_2D; |
1033 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1088 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1034 | |
1089 | |
1035 | glColor @{$self->{fg}}; |
1090 | glColor @{$self->{fg}}; |
1036 | |
1091 | |
1037 | my $x = |
1092 | $self->{ox} = int ( |
1038 | $self->{align} < 0 ? $self->{padding} |
1093 | $self->{align} < 0 ? $self->{padding} |
1039 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1094 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1040 | : ($self->{w} - $tex->{w}) * 0.5; |
1095 | : ($self->{w} - $tex->{w}) * 0.5 |
|
|
1096 | ); |
1041 | |
1097 | |
1042 | my $y = |
1098 | $self->{oy} = int ( |
1043 | $self->{valign} < 0 ? $self->{padding} |
1099 | $self->{valign} < 0 ? $self->{padding} |
1044 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1100 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1045 | : ($self->{h} - $tex->{h}) * 0.5; |
1101 | : ($self->{h} - $tex->{h}) * 0.5 |
|
|
1102 | ); |
1046 | |
1103 | |
1047 | $tex->draw_quad (int $x, int $y); |
1104 | $tex->draw_quad ($self->{ox}, $self->{oy}); |
1048 | |
1105 | |
1049 | glDisable GL_TEXTURE_2D; |
1106 | glDisable GL_TEXTURE_2D; |
1050 | glDisable GL_BLEND; |
1107 | glDisable GL_BLEND; |
1051 | } |
1108 | } |
1052 | |
1109 | |
1053 | ############################################################################# |
1110 | ############################################################################# |
1054 | |
1111 | |
1055 | package CFClient::UI::Entry; |
1112 | package CFClient::UI::EntryBase; |
1056 | |
1113 | |
1057 | our @ISA = CFClient::UI::Label::; |
1114 | our @ISA = CFClient::UI::Label::; |
1058 | |
1115 | |
1059 | use SDL; |
1116 | use CFClient::OpenGL; |
1060 | use SDL::OpenGL; |
|
|
1061 | |
1117 | |
1062 | sub new { |
1118 | sub new { |
1063 | my $class = shift; |
1119 | my $class = shift; |
1064 | |
1120 | |
1065 | $class->SUPER::new ( |
1121 | $class->SUPER::new ( |
… | |
… | |
1075 | } |
1131 | } |
1076 | |
1132 | |
1077 | sub _set_text { |
1133 | sub _set_text { |
1078 | my ($self, $text) = @_; |
1134 | my ($self, $text) = @_; |
1079 | |
1135 | |
1080 | my $old_text = $self->{text}; |
1136 | delete $self->{cur_h}; |
|
|
1137 | |
|
|
1138 | return if $self->{text} eq $text; |
|
|
1139 | |
|
|
1140 | delete $self->{texture}; |
1081 | |
1141 | |
1082 | $self->{last_activity} = $::NOW; |
1142 | $self->{last_activity} = $::NOW; |
1083 | |
|
|
1084 | $self->{text} = $text; |
1143 | $self->{text} = $text; |
1085 | $self->{layout}->set_width ($self->{w}); |
|
|
1086 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
|
|
1087 | |
1144 | |
1088 | $text =~ s/./*/g if $self->{hidden}; |
1145 | $text =~ s/./*/g if $self->{hidden}; |
|
|
1146 | $self->{layout}->set_text ("$text "); |
1089 | |
1147 | |
1090 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1148 | $self->emit (changed => $self->{text}); |
|
|
1149 | } |
1091 | |
1150 | |
1092 | $text = substr $text, 0, $self->{cursor}; |
1151 | sub get_text { |
1093 | utf8::encode $text; |
1152 | $_[0]{text} |
1094 | |
|
|
1095 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
|
|
1096 | |
|
|
1097 | $self->emit (changed => $self->{text}) # XXX: is this the right place to do this? |
|
|
1098 | if $old_text ne $self->{text}; |
|
|
1099 | } |
1153 | } |
1100 | |
1154 | |
1101 | sub size_request { |
1155 | sub size_request { |
1102 | my ($self) = @_; |
1156 | my ($self) = @_; |
1103 | |
1157 | |
… | |
… | |
1105 | |
1159 | |
1106 | ($w + 1, $h) # add 1 for cursor |
1160 | ($w + 1, $h) # add 1 for cursor |
1107 | } |
1161 | } |
1108 | |
1162 | |
1109 | sub size_allocate { |
1163 | sub size_allocate { |
1110 | my ($self, $x, $y, $w, $h) = @_; |
1164 | my ($self, $w, $h) = @_; |
1111 | |
|
|
1112 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
|
|
1113 | |
1165 | |
1114 | $self->_set_text ($self->{text}); |
1166 | $self->_set_text ($self->{text}); |
1115 | } |
1167 | } |
1116 | |
1168 | |
1117 | sub set_text { |
1169 | sub set_text { |
… | |
… | |
1123 | } |
1175 | } |
1124 | |
1176 | |
1125 | sub key_down { |
1177 | sub key_down { |
1126 | my ($self, $ev) = @_; |
1178 | my ($self, $ev) = @_; |
1127 | |
1179 | |
1128 | my $mod = $ev->key_mod; |
1180 | my $mod = $ev->{mod}; |
1129 | my $sym = $ev->key_sym; |
1181 | my $sym = $ev->{sym}; |
1130 | |
|
|
1131 | my $uni = $ev->key_unicode; |
1182 | my $uni = $ev->{unicode}; |
1132 | |
1183 | |
1133 | my $text = $self->get_text; |
1184 | my $text = $self->get_text; |
1134 | |
1185 | |
1135 | if ($sym == SDLK_BACKSPACE) { |
1186 | if ($sym == 8) { |
1136 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1187 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1137 | } elsif ($sym == SDLK_DELETE) { |
1188 | } elsif ($sym == 127) { |
1138 | substr $text, $self->{cursor}, 1, ""; |
1189 | substr $text, $self->{cursor}, 1, ""; |
1139 | } elsif ($sym == SDLK_LEFT) { |
1190 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1140 | --$self->{cursor} if $self->{cursor}; |
1191 | --$self->{cursor} if $self->{cursor}; |
1141 | } elsif ($sym == SDLK_RIGHT) { |
1192 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1142 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1193 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1143 | } elsif ($sym == SDLK_HOME) { |
1194 | } elsif ($sym == CFClient::SDLK_HOME) { |
1144 | $self->{cursor} = 0; |
1195 | $self->{cursor} = 0; |
1145 | } elsif ($sym == SDLK_END) { |
1196 | } elsif ($sym == CFClient::SDLK_END) { |
1146 | $self->{cursor} = length $text; |
1197 | $self->{cursor} = length $text; |
1147 | } elsif ($sym == SDLK_ESCAPE) { |
1198 | } elsif ($sym == 27) { |
1148 | $self->emit ('escape'); |
1199 | $self->emit ('escape'); |
1149 | } elsif ($uni) { |
1200 | } elsif ($uni) { |
1150 | substr $text, $self->{cursor}++, 0, chr $uni; |
1201 | substr $text, $self->{cursor}++, 0, chr $uni; |
1151 | } |
1202 | } |
1152 | |
1203 | |
… | |
… | |
1207 | |
1258 | |
1208 | $self->SUPER::_draw; |
1259 | $self->SUPER::_draw; |
1209 | |
1260 | |
1210 | #TODO: force update every cursor change :( |
1261 | #TODO: force update every cursor change :( |
1211 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
1262 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
|
|
1263 | |
|
|
1264 | unless (exists $self->{cur_h}) { |
|
|
1265 | my $text = substr $self->{text}, 0, $self->{cursor}; |
|
|
1266 | utf8::encode $text; |
|
|
1267 | |
|
|
1268 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
|
|
1269 | } |
|
|
1270 | |
1212 | glColor @{$self->{fg}}; |
1271 | glColor @{$self->{fg}}; |
1213 | glBegin GL_LINES; |
1272 | glBegin GL_LINES; |
1214 | glVertex $self->{cur_x}, $self->{cur_y}; |
|
|
1215 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1273 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
|
|
1274 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
1216 | glEnd; |
1275 | glEnd; |
1217 | } |
1276 | } |
1218 | } |
1277 | } |
1219 | |
1278 | |
1220 | package CFClient::UI::LineEntry; |
1279 | package CFClient::UI::Entry; |
1221 | |
1280 | |
1222 | our @ISA = CFClient::UI::Entry::; |
1281 | our @ISA = CFClient::UI::EntryBase::; |
1223 | |
1282 | |
1224 | use SDL; |
1283 | use CFClient::OpenGL; |
1225 | use SDL::OpenGL; |
|
|
1226 | |
1284 | |
1227 | sub key_down { |
1285 | sub key_down { |
1228 | my ($self, $ev) = @_; |
1286 | my ($self, $ev) = @_; |
1229 | |
1287 | |
1230 | my $sym = $ev->key_sym; |
1288 | my $sym = $ev->{sym}; |
1231 | |
1289 | |
1232 | if ($sym == SDLK_RETURN) { |
1290 | if ($sym == 13) { |
1233 | $self->emit (activate => $self->get_text); |
1291 | $self->emit (activate => $self->get_text); |
1234 | $self->update; |
1292 | $self->update; |
1235 | |
1293 | |
1236 | } else { |
1294 | } else { |
1237 | $self->SUPER::key_down ($ev); |
1295 | $self->SUPER::key_down ($ev); |
… | |
… | |
1243 | |
1301 | |
1244 | package CFClient::UI::Button; |
1302 | package CFClient::UI::Button; |
1245 | |
1303 | |
1246 | our @ISA = CFClient::UI::Label::; |
1304 | our @ISA = CFClient::UI::Label::; |
1247 | |
1305 | |
1248 | use SDL; |
1306 | use CFClient::OpenGL; |
1249 | use SDL::OpenGL; |
|
|
1250 | |
1307 | |
1251 | my @tex = |
1308 | my @tex = |
1252 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1309 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1253 | qw(b1_button_active.png); |
1310 | qw(b1_button_active.png); |
1254 | |
1311 | |
… | |
… | |
1257 | |
1314 | |
1258 | $class->SUPER::new ( |
1315 | $class->SUPER::new ( |
1259 | padding => 4, |
1316 | padding => 4, |
1260 | fg => [1, 1, 1], |
1317 | fg => [1, 1, 1], |
1261 | bg => [1, 1, 1, 0.2], |
1318 | bg => [1, 1, 1, 0.2], |
1262 | active_fg => [1, 1, 0], |
1319 | active_fg => [0, 0, 1], |
1263 | can_hover => 1, |
1320 | can_hover => 1, |
|
|
1321 | align => 0, |
|
|
1322 | valign => 0, |
1264 | @_ |
1323 | @_ |
1265 | ) |
1324 | ) |
1266 | } |
1325 | } |
1267 | |
1326 | |
1268 | sub button_up { |
1327 | sub button_up { |
… | |
… | |
1276 | |
1335 | |
1277 | sub _draw { |
1336 | sub _draw { |
1278 | my ($self) = @_; |
1337 | my ($self) = @_; |
1279 | |
1338 | |
1280 | local $self->{fg} = $self->{fg}; |
1339 | local $self->{fg} = $self->{fg}; |
1281 | my $tex = $tex[0]; |
|
|
1282 | |
|
|
1283 | glEnable GL_BLEND; |
|
|
1284 | glEnable GL_TEXTURE_2D; |
|
|
1285 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1286 | |
1340 | |
1287 | if ($GRAB == $self) { |
1341 | if ($GRAB == $self) { |
1288 | $self->{fg} = $self->{active_fg}; |
1342 | $self->{fg} = $self->{active_fg}; |
1289 | } |
1343 | } |
1290 | |
1344 | |
1291 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
1345 | glEnable GL_BLEND; |
|
|
1346 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1347 | glEnable GL_TEXTURE_2D; |
1292 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1348 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1349 | glColor 0, 0, 0, 1; |
1293 | |
1350 | |
1294 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
1351 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1295 | |
1352 | |
1296 | glDisable GL_TEXTURE_2D; |
1353 | glDisable GL_TEXTURE_2D; |
1297 | glDisable GL_BLEND; |
1354 | glDisable GL_BLEND; |
1298 | |
1355 | |
1299 | $self->SUPER::_draw; |
1356 | $self->SUPER::_draw; |
… | |
… | |
1307 | |
1364 | |
1308 | my @tex = |
1365 | my @tex = |
1309 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1366 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1310 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1367 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1311 | |
1368 | |
1312 | use SDL; |
1369 | use CFClient::OpenGL; |
1313 | use SDL::OpenGL; |
|
|
1314 | |
1370 | |
1315 | sub new { |
1371 | sub new { |
1316 | my $class = shift; |
1372 | my $class = shift; |
1317 | |
1373 | |
1318 | $class->SUPER::new ( |
1374 | $class->SUPER::new ( |
… | |
… | |
1329 | my ($self) = @_; |
1385 | my ($self) = @_; |
1330 | |
1386 | |
1331 | ($self->{padding} * 2 + 6) x 2 |
1387 | ($self->{padding} * 2 + 6) x 2 |
1332 | } |
1388 | } |
1333 | |
1389 | |
1334 | sub size_allocate { |
|
|
1335 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1336 | |
|
|
1337 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
1338 | } |
|
|
1339 | |
|
|
1340 | sub button_down { |
1390 | sub button_down { |
1341 | my ($self, $ev, $x, $y) = @_; |
1391 | my ($self, $ev, $x, $y) = @_; |
1342 | |
1392 | |
1343 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1393 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1344 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1394 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
… | |
… | |
1370 | glDisable GL_BLEND; |
1420 | glDisable GL_BLEND; |
1371 | } |
1421 | } |
1372 | |
1422 | |
1373 | ############################################################################# |
1423 | ############################################################################# |
1374 | |
1424 | |
|
|
1425 | package CFClient::UI::VGauge; |
|
|
1426 | |
|
|
1427 | our @ISA = CFClient::UI::Base::; |
|
|
1428 | |
|
|
1429 | use CFClient::OpenGL; |
|
|
1430 | |
|
|
1431 | my %tex = ( |
|
|
1432 | food => [ |
|
|
1433 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1434 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1435 | ], |
|
|
1436 | grace => [ |
|
|
1437 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1438 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1439 | ], |
|
|
1440 | hp => [ |
|
|
1441 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1442 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1443 | ], |
|
|
1444 | mana => [ |
|
|
1445 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1446 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1447 | ], |
|
|
1448 | ); |
|
|
1449 | |
|
|
1450 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1451 | sub new { |
|
|
1452 | my $class = shift; |
|
|
1453 | |
|
|
1454 | my $self = $class->SUPER::new (gauge => 'food', @_); |
|
|
1455 | |
|
|
1456 | $self |
|
|
1457 | } |
|
|
1458 | |
|
|
1459 | sub size_request { |
|
|
1460 | my ($self) = @_; |
|
|
1461 | |
|
|
1462 | my $tex = $tex{$self->{gauge}}[0]; |
|
|
1463 | |
|
|
1464 | @$tex{qw(w h)} |
|
|
1465 | } |
|
|
1466 | |
|
|
1467 | sub set_max { |
|
|
1468 | my ($self, $max) = @_; |
|
|
1469 | |
|
|
1470 | $self->{max_val} = $max; |
|
|
1471 | } |
|
|
1472 | |
|
|
1473 | sub set_value { |
|
|
1474 | my ($self, $val, $max) = @_; |
|
|
1475 | |
|
|
1476 | $self->set_max ($max) |
|
|
1477 | if defined $max; |
|
|
1478 | |
|
|
1479 | $max = $self->{max_val}; |
|
|
1480 | $self->{val} = $val; |
|
|
1481 | |
|
|
1482 | $self->update; |
|
|
1483 | } |
|
|
1484 | |
|
|
1485 | sub _draw { |
|
|
1486 | my ($self) = @_; |
|
|
1487 | |
|
|
1488 | my $tex = $tex{$self->{gauge}}; |
|
|
1489 | |
|
|
1490 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1491 | |
|
|
1492 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1493 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1494 | |
|
|
1495 | my $t1 = $tex->[0]; |
|
|
1496 | my $t2 = $tex->[1]; |
|
|
1497 | |
|
|
1498 | glEnable GL_BLEND; |
|
|
1499 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1500 | glEnable GL_TEXTURE_2D; |
|
|
1501 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1502 | |
|
|
1503 | my $h1 = $self->{h} - $ycut * $self->{h}; |
|
|
1504 | my $h2 = $ycut * $self->{h}; |
|
|
1505 | |
|
|
1506 | my $yp = 0; |
|
|
1507 | |
|
|
1508 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
|
|
1509 | glBegin GL_QUADS; |
|
|
1510 | glTexCoord 0 , 0; glVertex 0 , $yp; |
|
|
1511 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
|
|
1512 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
|
|
1513 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
|
|
1514 | glEnd; |
|
|
1515 | |
|
|
1516 | $yp += $h1; |
|
|
1517 | |
|
|
1518 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
|
|
1519 | glBegin GL_QUADS; |
|
|
1520 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
|
|
1521 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
|
|
1522 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
|
|
1523 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
|
|
1524 | glEnd; |
|
|
1525 | |
|
|
1526 | glDisable GL_BLEND; |
|
|
1527 | glDisable GL_TEXTURE_2D; |
|
|
1528 | } |
|
|
1529 | |
|
|
1530 | ############################################################################# |
|
|
1531 | |
1375 | package CFClient::UI::Slider; |
1532 | package CFClient::UI::Slider; |
1376 | |
1533 | |
1377 | use strict; |
1534 | use strict; |
1378 | |
1535 | |
1379 | use SDL::OpenGL; |
1536 | use CFClient::OpenGL; |
1380 | |
1537 | |
1381 | our @ISA = CFClient::UI::DrawBG::; |
1538 | our @ISA = CFClient::UI::DrawBG::; |
1382 | |
1539 | |
1383 | my @tex = |
1540 | my @tex = |
1384 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1541 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1394 | # TODO: calculations are off |
1551 | # TODO: calculations are off |
1395 | my $self = $class->SUPER::new ( |
1552 | my $self = $class->SUPER::new ( |
1396 | fg => [1, 1, 1], |
1553 | fg => [1, 1, 1], |
1397 | active_fg => [0, 0, 0], |
1554 | active_fg => [0, 0, 0], |
1398 | range => [0, 0, 100, 10], |
1555 | range => [0, 0, 100, 10], |
1399 | req_w => 40, |
1556 | req_w => 20, |
1400 | req_h => 13, |
1557 | req_h => 20, |
1401 | vertical => 0, |
1558 | vertical => 0, |
1402 | can_hover => 1, |
1559 | can_hover => 1, |
1403 | inner_pad => 5, |
1560 | inner_pad => 5, |
1404 | @_ |
1561 | @_ |
1405 | ); |
1562 | ); |
… | |
… | |
1509 | |
1666 | |
1510 | package CFClient::UI::TextView; |
1667 | package CFClient::UI::TextView; |
1511 | |
1668 | |
1512 | our @ISA = CFClient::UI::HBox::; |
1669 | our @ISA = CFClient::UI::HBox::; |
1513 | |
1670 | |
1514 | use SDL::OpenGL; |
1671 | use CFClient::OpenGL; |
1515 | |
1672 | |
1516 | sub new { |
1673 | sub new { |
1517 | my $class = shift; |
1674 | my $class = shift; |
1518 | |
1675 | |
1519 | my $self = $class->SUPER::new ( |
1676 | my $self = $class->SUPER::new ( |
1520 | req_w => $::WIDTH / 6, |
|
|
1521 | req_h => $::HEIGHT / 6, |
|
|
1522 | fontsize => $::FONTSIZE, |
1677 | fontsize => 1, |
1523 | @_, |
1678 | @_, |
1524 | |
1679 | |
1525 | layout => (new CFClient::Layout), |
1680 | layout => (new CFClient::Layout), |
1526 | par => [], |
1681 | par => [], |
1527 | height => 0, |
1682 | height => 0, |
… | |
… | |
1548 | sub text_height { |
1703 | sub text_height { |
1549 | my ($self, $text) = @_; |
1704 | my ($self, $text) = @_; |
1550 | |
1705 | |
1551 | my $layout = $self->{layout}; |
1706 | my $layout = $self->{layout}; |
1552 | |
1707 | |
1553 | $layout->set_height ($self->{fontsize}); |
1708 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
1554 | $layout->set_width ($self->{w}); |
1709 | $layout->set_width ($self->{w}); |
1555 | $layout->set_text ($text); |
1710 | $layout->set_text ($text); |
1556 | |
1711 | |
1557 | ($layout->size)[1] |
1712 | ($layout->size)[1] |
1558 | } |
1713 | } |
… | |
… | |
1562 | |
1717 | |
1563 | $self->{need_reflow}++; |
1718 | $self->{need_reflow}++; |
1564 | $self->update; |
1719 | $self->update; |
1565 | } |
1720 | } |
1566 | |
1721 | |
1567 | sub size_request { |
|
|
1568 | my ($self) = @_; |
|
|
1569 | |
|
|
1570 | ($self->{req_w}, $self->{req_h}) |
|
|
1571 | } |
|
|
1572 | |
|
|
1573 | sub size_allocate { |
1722 | sub size_allocate { |
1574 | my ($self, $x, $y, $w, $h) = @_; |
1723 | my ($self, $w, $h) = @_; |
1575 | |
1724 | |
1576 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
1725 | $self->SUPER::size_allocate ($w, $h); |
1577 | |
1726 | |
1578 | $self->{layout}->set_height ($self->{fontsize}); |
1727 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1579 | $self->{layout}->set_width ($self->{w}); |
1728 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1580 | |
1729 | |
1581 | $self->reflow; |
1730 | $self->reflow; |
1582 | } |
1731 | } |
1583 | |
1732 | |
1584 | sub add_paragraph { |
1733 | sub add_paragraph { |
… | |
… | |
1671 | |
1820 | |
1672 | } |
1821 | } |
1673 | |
1822 | |
1674 | ############################################################################# |
1823 | ############################################################################# |
1675 | |
1824 | |
1676 | package CFClient::UI::MapWidget; |
|
|
1677 | |
|
|
1678 | use strict; |
|
|
1679 | |
|
|
1680 | use List::Util qw(min max); |
|
|
1681 | |
|
|
1682 | use SDL; |
|
|
1683 | use SDL::OpenGL; |
|
|
1684 | |
|
|
1685 | our @ISA = CFClient::UI::Base::; |
|
|
1686 | |
|
|
1687 | sub new { |
|
|
1688 | my $class = shift; |
|
|
1689 | |
|
|
1690 | $class->SUPER::new ( |
|
|
1691 | z => -1, |
|
|
1692 | can_focus => 1, |
|
|
1693 | list => (glGenLists 1), |
|
|
1694 | @_ |
|
|
1695 | ) |
|
|
1696 | } |
|
|
1697 | |
|
|
1698 | sub key_down { |
|
|
1699 | print "MAPKEYDOWN\n"; |
|
|
1700 | } |
|
|
1701 | |
|
|
1702 | sub key_up { |
|
|
1703 | } |
|
|
1704 | |
|
|
1705 | sub button_down { |
|
|
1706 | my ($self, $ev, $x, $y) = @_; |
|
|
1707 | |
|
|
1708 | $self->focus_in; |
|
|
1709 | |
|
|
1710 | if ($ev->button == 2) { |
|
|
1711 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1712 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1713 | |
|
|
1714 | $self->{motion} = sub { |
|
|
1715 | my ($ev, $x, $y) = @_; |
|
|
1716 | |
|
|
1717 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1718 | |
|
|
1719 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1720 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1721 | |
|
|
1722 | $self->update; |
|
|
1723 | }; |
|
|
1724 | } |
|
|
1725 | } |
|
|
1726 | |
|
|
1727 | sub button_up { |
|
|
1728 | my ($self, $ev, $x, $y) = @_; |
|
|
1729 | |
|
|
1730 | delete $self->{motion}; |
|
|
1731 | } |
|
|
1732 | |
|
|
1733 | sub mouse_motion { |
|
|
1734 | my ($self, $ev, $x, $y) = @_; |
|
|
1735 | |
|
|
1736 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1737 | } |
|
|
1738 | |
|
|
1739 | sub size_request { |
|
|
1740 | ( |
|
|
1741 | 1 + 32 * int $::WIDTH / 32, |
|
|
1742 | 1 + 32 * int $::HEIGHT / 32, |
|
|
1743 | ) |
|
|
1744 | } |
|
|
1745 | |
|
|
1746 | sub update { |
|
|
1747 | my ($self) = @_; |
|
|
1748 | |
|
|
1749 | $self->{need_update} = 1; |
|
|
1750 | $self->SUPER::update; |
|
|
1751 | } |
|
|
1752 | |
|
|
1753 | sub draw { |
|
|
1754 | my ($self) = @_; |
|
|
1755 | |
|
|
1756 | if (delete $self->{need_update}) { |
|
|
1757 | glNewList $self->{list}, GL_COMPILE; |
|
|
1758 | |
|
|
1759 | if ($::MAP) { |
|
|
1760 | my $sw = int $::WIDTH / 32; |
|
|
1761 | my $sh = int $::HEIGHT / 32; |
|
|
1762 | |
|
|
1763 | my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
1764 | my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
1765 | |
|
|
1766 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
|
|
1767 | |
|
|
1768 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
|
|
1769 | |
|
|
1770 | if ($::CFG->{fow_enable}) { |
|
|
1771 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1772 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1773 | glConvolutionFilter2D |
|
|
1774 | GL_CONVOLUTION_2D, |
|
|
1775 | GL_ALPHA, |
|
|
1776 | 3, 3, |
|
|
1777 | GL_ALPHA, GL_FLOAT, |
|
|
1778 | pack "f*", |
|
|
1779 | 0.1, 0.1, 0.1, |
|
|
1780 | 0.1, 0.2, 0.1, |
|
|
1781 | 0.1, 0.1, 0.1, |
|
|
1782 | ; |
|
|
1783 | glEnable GL_CONVOLUTION_2D; |
|
|
1784 | } |
|
|
1785 | |
|
|
1786 | my $tex = new CFClient::Texture |
|
|
1787 | w => $w, |
|
|
1788 | h => $h, |
|
|
1789 | data => $data, |
|
|
1790 | internalformat => GL_ALPHA, |
|
|
1791 | format => GL_ALPHA; |
|
|
1792 | |
|
|
1793 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1794 | |
|
|
1795 | glEnable GL_BLEND; |
|
|
1796 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1797 | glEnable GL_TEXTURE_2D; |
|
|
1798 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1799 | |
|
|
1800 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1801 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1802 | |
|
|
1803 | glDisable GL_TEXTURE_2D; |
|
|
1804 | glDisable GL_BLEND; |
|
|
1805 | } |
|
|
1806 | |
|
|
1807 | # HACK BEGIN |
|
|
1808 | { |
|
|
1809 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
1810 | my ($w, $h) = (250, 250); |
|
|
1811 | |
|
|
1812 | glEnable GL_BLEND; |
|
|
1813 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1814 | glEnable GL_TEXTURE_2D; |
|
|
1815 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1816 | |
|
|
1817 | CFClient::Texture->new ( |
|
|
1818 | w => $w, |
|
|
1819 | h => $h, |
|
|
1820 | data => $::MAP->mapmap ($w, $h), |
|
|
1821 | type => GL_UNSIGNED_INT_8_8_8_8_REV |
|
|
1822 | )->draw_quad (100, 100); |
|
|
1823 | |
|
|
1824 | glDisable GL_TEXTURE_2D; |
|
|
1825 | glDisable GL_BLEND; |
|
|
1826 | } |
|
|
1827 | # HACK END |
|
|
1828 | } |
|
|
1829 | |
|
|
1830 | glEndList; |
|
|
1831 | } |
|
|
1832 | |
|
|
1833 | glPushMatrix; |
|
|
1834 | glCallList $self->{list}; |
|
|
1835 | glPopMatrix; |
|
|
1836 | |
|
|
1837 | if ($FOCUS != $self) { |
|
|
1838 | glColor 64/255, 64/255, 64/255; |
|
|
1839 | glLogicOp GL_AND; |
|
|
1840 | glEnable GL_COLOR_LOGIC_OP; |
|
|
1841 | glBegin GL_QUADS; |
|
|
1842 | glVertex 0, 0; |
|
|
1843 | glVertex 0, $::HEIGHT; |
|
|
1844 | glVertex $::WIDTH, $::HEIGHT; |
|
|
1845 | glVertex $::WIDTH, 0; |
|
|
1846 | glEnd; |
|
|
1847 | glDisable GL_COLOR_LOGIC_OP; |
|
|
1848 | } |
|
|
1849 | } |
|
|
1850 | |
|
|
1851 | my %DIR = ( |
|
|
1852 | SDLK_KP8, [1, "north"], |
|
|
1853 | SDLK_KP9, [2, "northeast"], |
|
|
1854 | SDLK_KP6, [3, "east"], |
|
|
1855 | SDLK_KP3, [4, "southeast"], |
|
|
1856 | SDLK_KP2, [5, "south"], |
|
|
1857 | SDLK_KP1, [6, "southwest"], |
|
|
1858 | SDLK_KP4, [7, "west"], |
|
|
1859 | SDLK_KP7, [8, "northwest"], |
|
|
1860 | |
|
|
1861 | SDLK_UP, [1, "north"], |
|
|
1862 | SDLK_RIGHT, [3, "east"], |
|
|
1863 | SDLK_DOWN, [5, "south"], |
|
|
1864 | SDLK_LEFT, [7, "west"], |
|
|
1865 | ); |
|
|
1866 | |
|
|
1867 | sub key_down { |
|
|
1868 | my ($self, $ev) = @_; |
|
|
1869 | |
|
|
1870 | my $mod = $ev->key_mod; |
|
|
1871 | my $sym = $ev->key_sym; |
|
|
1872 | |
|
|
1873 | if ($sym == SDLK_KP5) { |
|
|
1874 | $::CONN->user_send ("command stay fire"); |
|
|
1875 | } elsif ($sym == SDLK_a) { |
|
|
1876 | $::CONN->user_send ("command apply"); |
|
|
1877 | } elsif ($sym == SDLK_QUOTE) { |
|
|
1878 | $self->emit ('activate_console'); |
|
|
1879 | } elsif ($sym == SDLK_SLASH) { |
|
|
1880 | $self->emit ('activate_console' => '/'); |
|
|
1881 | } elsif (exists $DIR{$sym}) { |
|
|
1882 | if ($mod & KMOD_SHIFT) { |
|
|
1883 | $self->{shft}++; |
|
|
1884 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
|
|
1885 | } elsif ($mod & KMOD_CTRL) { |
|
|
1886 | $self->{ctrl}++; |
|
|
1887 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
|
|
1888 | } else { |
|
|
1889 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
|
|
1890 | } |
|
|
1891 | } |
|
|
1892 | } |
|
|
1893 | |
|
|
1894 | sub key_up { |
|
|
1895 | my ($self, $ev) = @_; |
|
|
1896 | |
|
|
1897 | my $mod = $ev->key_mod; |
|
|
1898 | my $sym = $ev->key_sym; |
|
|
1899 | |
|
|
1900 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
|
|
1901 | $::CONN->user_send ("command fire_stop"); |
|
|
1902 | } |
|
|
1903 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
1904 | $::CONN->user_send ("command run_stop"); |
|
|
1905 | } |
|
|
1906 | } |
|
|
1907 | |
|
|
1908 | ############################################################################# |
|
|
1909 | |
|
|
1910 | package CFClient::UI::Animator; |
1825 | package CFClient::UI::Animator; |
1911 | |
1826 | |
1912 | use SDL::OpenGL; |
1827 | use CFClient::OpenGL; |
1913 | |
1828 | |
1914 | our @ISA = CFClient::UI::Bin::; |
1829 | our @ISA = CFClient::UI::Bin::; |
1915 | |
1830 | |
1916 | sub moveto { |
1831 | sub moveto { |
1917 | my ($self, $x, $y) = @_; |
1832 | my ($self, $x, $y) = @_; |
… | |
… | |
1990 | |
1905 | |
1991 | package CFClient::UI::Root; |
1906 | package CFClient::UI::Root; |
1992 | |
1907 | |
1993 | our @ISA = CFClient::UI::Container::; |
1908 | our @ISA = CFClient::UI::Container::; |
1994 | |
1909 | |
1995 | use SDL::OpenGL; |
1910 | use CFClient::OpenGL; |
|
|
1911 | |
|
|
1912 | sub check_size { |
|
|
1913 | my ($self) = @_; |
|
|
1914 | |
|
|
1915 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
|
|
1916 | } |
1996 | |
1917 | |
1997 | sub size_request { |
1918 | sub size_request { |
1998 | ($::WIDTH, $::HEIGHT) |
1919 | ($::WIDTH, $::HEIGHT) |
1999 | } |
1920 | } |
2000 | |
1921 | |
2001 | sub size_allocate { |
1922 | sub configure { |
2002 | my ($self, $x, $y, $w, $h) = @_; |
1923 | my ($self, $x, $y, $w, $h) = @_; |
2003 | |
1924 | |
2004 | $self->_size_allocate ($x, $y, $w, $h); |
1925 | $self->SUPER::configure ($x, $y, $w, $h); |
2005 | |
1926 | |
2006 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
1927 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
2007 | for @{$self->{children}}; |
1928 | for @{$self->{children}}; |
2008 | } |
1929 | } |
2009 | |
1930 | |
2010 | sub _topleft { |
1931 | sub _topleft { |
2011 | my ($self, $x, $y) = @_; |
1932 | my ($self, $x, $y) = @_; |
… | |
… | |
2014 | } |
1935 | } |
2015 | |
1936 | |
2016 | sub update { |
1937 | sub update { |
2017 | my ($self) = @_; |
1938 | my ($self) = @_; |
2018 | |
1939 | |
2019 | $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); |
1940 | $self->check_size; |
2020 | ::refresh (); |
1941 | ::refresh (); |
2021 | } |
1942 | } |
2022 | |
1943 | |
2023 | sub add { |
1944 | sub add { |
2024 | my ($self, $widget) = @_; |
1945 | my ($self, $child) = @_; |
2025 | |
1946 | |
2026 | $self->SUPER::add ($widget); |
1947 | $self->SUPER::add ($child); |
2027 | |
|
|
2028 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
|
|
2029 | } |
1948 | } |
2030 | |
1949 | |
2031 | sub on_refresh { |
1950 | sub on_refresh { |
2032 | my ($self, $id, $cb) = @_; |
1951 | my ($self, $id, $cb) = @_; |
2033 | |
1952 | |