… | |
… | |
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) = @_; |
… | |
… | |
225 | glPopMatrix; |
241 | glPopMatrix; |
226 | |
242 | |
227 | if ($self == $HOVER && $self->{can_hover}) { |
243 | if ($self == $HOVER && $self->{can_hover}) { |
228 | my ($x, $y) = @$self{qw(x y)}; |
244 | my ($x, $y) = @$self{qw(x y)}; |
229 | |
245 | |
230 | glColor 0, 0, 1, 0.2; |
246 | glColor 1, 0.8, 0.5, 0.2; |
231 | glEnable GL_BLEND; |
247 | glEnable GL_BLEND; |
232 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
248 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
233 | glBegin GL_QUADS; |
249 | glBegin GL_QUADS; |
234 | glVertex $x , $y; |
250 | glVertex $x , $y; |
235 | glVertex $x + $self->{w}, $y; |
251 | glVertex $x + $self->{w}, $y; |
… | |
… | |
260 | my ($self, $parent) = @_; |
276 | my ($self, $parent) = @_; |
261 | |
277 | |
262 | Scalar::Util::weaken ($self->{parent} = $parent); |
278 | Scalar::Util::weaken ($self->{parent} = $parent); |
263 | } |
279 | } |
264 | |
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 | |
265 | sub update { |
295 | sub update { |
266 | my ($self) = @_; |
296 | my ($self) = @_; |
267 | |
297 | |
268 | $self->{parent}->update |
298 | $self->{parent}->update |
269 | if $self->{parent}; |
299 | if $self->{parent}; |
270 | } |
300 | } |
271 | |
301 | |
272 | sub connect { |
302 | sub connect { |
273 | my ($self, $signal, $cb) = @_; |
303 | my ($self, $signal, $cb) = @_; |
274 | |
304 | |
275 | push @{ $self->{cb}{$signal} }, $cb; |
305 | push @{ $self->{signal_cb}{$signal} }, $cb; |
276 | } |
306 | } |
277 | |
307 | |
278 | sub emit { |
308 | sub emit { |
279 | my ($self, $signal, @args) = @_; |
309 | my ($self, $signal, @args) = @_; |
280 | |
310 | |
|
|
311 | for my $cb (@{$self->{signal_cb}{$signal} || []}) { |
281 | $_->($self, @args) |
312 | $cb->($self, @args); |
282 | for @{$self->{cb}{$signal} || []}; |
313 | } |
283 | } |
314 | } |
284 | |
315 | |
285 | sub DESTROY { |
316 | sub DESTROY { |
286 | my ($self) = @_; |
317 | my ($self) = @_; |
287 | |
318 | |
… | |
… | |
293 | package CFClient::UI::DrawBG; |
324 | package CFClient::UI::DrawBG; |
294 | |
325 | |
295 | our @ISA = CFClient::UI::Base::; |
326 | our @ISA = CFClient::UI::Base::; |
296 | |
327 | |
297 | use strict; |
328 | use strict; |
298 | use SDL::OpenGL; |
329 | use CFClient::OpenGL; |
299 | |
330 | |
300 | sub new { |
331 | sub new { |
301 | my $class = shift; |
332 | my $class = shift; |
302 | |
333 | |
303 | # range [value, low, high, page] |
334 | # range [value, low, high, page] |
… | |
… | |
367 | $self->{children} = [ |
398 | $self->{children} = [ |
368 | sort { $a->{z} <=> $b->{z} } |
399 | sort { $a->{z} <=> $b->{z} } |
369 | @{$self->{children}}, $child |
400 | @{$self->{children}}, $child |
370 | ]; |
401 | ]; |
371 | |
402 | |
372 | $self->{w} = $self->{h} = -1; |
403 | $child->check_size; |
373 | $self->update; |
|
|
374 | } |
404 | } |
375 | |
405 | |
376 | sub remove { |
406 | sub remove { |
377 | my ($self, $widget) = @_; |
407 | my ($self, $child) = @_; |
378 | |
408 | |
|
|
409 | delete $child->{parent}; |
|
|
410 | |
379 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
411 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
380 | |
412 | |
381 | $self->size_allocate (0, 0, $self->{w}, $self->{h}); |
413 | $self->check_size; |
382 | } |
414 | } |
383 | |
415 | |
384 | sub find_widget { |
416 | sub find_widget { |
385 | my ($self, $x, $y) = @_; |
417 | my ($self, $x, $y) = @_; |
386 | |
418 | |
… | |
… | |
416 | |
448 | |
417 | $class->SUPER::new (children => [$child], %arg) |
449 | $class->SUPER::new (children => [$child], %arg) |
418 | } |
450 | } |
419 | |
451 | |
420 | sub add { |
452 | sub add { |
421 | my ($self, $widget) = @_; |
453 | my ($self, $child) = @_; |
422 | |
454 | |
423 | $self->{children} = []; |
455 | $self->{children} = []; |
424 | |
456 | |
425 | $self->SUPER::add ($widget); |
457 | $self->SUPER::add ($child); |
426 | } |
458 | } |
427 | |
459 | |
428 | sub remove { |
460 | sub remove { |
429 | my ($self, $widget) = @_; |
461 | my ($self, $widget) = @_; |
430 | |
462 | |
… | |
… | |
439 | sub size_request { |
471 | sub size_request { |
440 | $_[0]{children}[0]->size_request |
472 | $_[0]{children}[0]->size_request |
441 | } |
473 | } |
442 | |
474 | |
443 | sub size_allocate { |
475 | sub size_allocate { |
444 | my ($self, $x, $y, $w, $h) = @_; |
476 | my ($self, $w, $h) = @_; |
445 | |
477 | |
446 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
447 | |
|
|
448 | $self->{children}[0]->size_allocate (0, 0, $w, $h); |
478 | $self->{children}[0]->configure (0, 0, $w, $h); |
449 | } |
479 | } |
450 | |
480 | |
451 | ############################################################################# |
481 | ############################################################################# |
452 | |
482 | |
453 | package CFClient::UI::Window; |
483 | package CFClient::UI::Window; |
454 | |
484 | |
455 | our @ISA = CFClient::UI::Bin::; |
485 | our @ISA = CFClient::UI::Bin::; |
456 | |
486 | |
457 | use SDL::OpenGL; |
487 | use CFClient::OpenGL; |
458 | |
488 | |
459 | sub new { |
489 | sub new { |
460 | my ($class, %arg) = @_; |
490 | my ($class, %arg) = @_; |
461 | |
491 | |
462 | my $self = $class->SUPER::new (%arg); |
492 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
479 | $self->child->draw; |
509 | $self->child->draw; |
480 | }; |
510 | }; |
481 | } |
511 | } |
482 | |
512 | |
483 | sub size_allocate { |
513 | sub size_allocate { |
484 | my ($self, $x, $y, $w, $h) = @_; |
514 | my ($self, $w, $h) = @_; |
485 | |
515 | |
486 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
487 | |
|
|
488 | $self->child->size_allocate (0, 0, $w, $h); |
516 | $self->child->configure (0, 0, $w, $h); |
489 | |
517 | |
490 | $self->render_chld; |
518 | $self->render_chld; |
491 | } |
519 | } |
492 | |
520 | |
493 | sub _draw { |
521 | sub _draw { |
… | |
… | |
509 | glDisable GL_TEXTURE_2D; |
537 | glDisable GL_TEXTURE_2D; |
510 | } |
538 | } |
511 | |
539 | |
512 | ############################################################################# |
540 | ############################################################################# |
513 | |
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 | |
514 | package CFClient::UI::Frame; |
566 | package CFClient::UI::Frame; |
515 | |
567 | |
516 | our @ISA = CFClient::UI::Bin::; |
568 | our @ISA = CFClient::UI::Bin::; |
517 | |
569 | |
518 | use SDL::OpenGL; |
570 | use CFClient::OpenGL; |
519 | |
571 | |
520 | sub size_request { |
572 | sub size_request { |
521 | my ($self) = @_; |
573 | my ($self) = @_; |
522 | my $chld = $self->child |
574 | my $chld = $self->child |
523 | or return (0, 0); |
575 | or return (0, 0); |
… | |
… | |
528 | } |
580 | } |
529 | |
581 | |
530 | sub size_allocate { |
582 | sub size_allocate { |
531 | my ($self, $x, $y, $w, $h) = @_; |
583 | my ($self, $x, $y, $w, $h) = @_; |
532 | |
584 | |
533 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
534 | |
|
|
535 | $self->child->size_allocate (2, 2, $w - 4, $h - 4); |
585 | $self->child->configure (2, 2, $w - 4, $h - 4); |
536 | } |
586 | } |
537 | |
587 | |
538 | sub _draw { |
588 | sub _draw { |
539 | my ($self) = @_; |
589 | my ($self) = @_; |
540 | |
590 | |
… | |
… | |
557 | |
607 | |
558 | package CFClient::UI::FancyFrame; |
608 | package CFClient::UI::FancyFrame; |
559 | |
609 | |
560 | our @ISA = CFClient::UI::Bin::; |
610 | our @ISA = CFClient::UI::Bin::; |
561 | |
611 | |
562 | use SDL::OpenGL; |
612 | use CFClient::OpenGL; |
563 | |
613 | |
564 | my @tex = |
614 | my @tex = |
565 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
615 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
566 | 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); |
567 | |
617 | |
… | |
… | |
571 | # TODO: user_x, user_y, overwrite moveto? |
621 | # TODO: user_x, user_y, overwrite moveto? |
572 | |
622 | |
573 | $class->SUPER::new ( |
623 | $class->SUPER::new ( |
574 | bg => [1, 1, 1, 1], |
624 | bg => [1, 1, 1, 1], |
575 | border_bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
576 | border => int $::FONTSIZE * 0.8, |
626 | border => 0.8, |
577 | @_ |
627 | @_ |
578 | ) |
628 | ) |
579 | } |
629 | } |
580 | |
630 | |
|
|
631 | sub border { |
|
|
632 | int $_[0]{border} * $::FONTSIZE |
|
|
633 | } |
|
|
634 | |
581 | sub size_request { |
635 | sub size_request { |
582 | my ($self) = @_; |
636 | my ($self) = @_; |
583 | |
637 | |
584 | 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}; |
585 | |
639 | |
586 | my ($w, $h) = $self->SUPER::size_request; |
640 | my ($w, $h) = $self->SUPER::size_request; |
587 | |
641 | |
588 | ( |
642 | ( |
589 | $w + $self->{border} * 2, |
643 | $w + $self->border * 2, |
590 | $h + $self->{border} * 2, |
644 | $h + $self->border * 2, |
591 | ) |
645 | ) |
592 | } |
646 | } |
593 | |
647 | |
594 | sub size_allocate { |
648 | sub size_allocate { |
595 | my ($self, $x, $y, $w, $h) = @_; |
649 | my ($self, $w, $h) = @_; |
596 | |
650 | |
597 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
598 | |
|
|
599 | $h -= List::Util::max 0, $self->{border} * 2; |
651 | $h -= List::Util::max 0, $self->border * 2; |
600 | $w -= List::Util::max 0, $self->{border} * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
601 | |
653 | |
602 | $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
603 | } |
655 | } |
604 | |
656 | |
605 | sub button_down { |
657 | sub button_down { |
606 | my ($self, $ev, $x, $y) = @_; |
658 | my ($self, $ev, $x, $y) = @_; |
607 | |
659 | |
|
|
660 | my $border = $self->border; |
|
|
661 | |
608 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
662 | if ($x < $self->{w} && $x >= $self->{w} - $border |
609 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
663 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
610 | |
664 | |
611 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
665 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
612 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
666 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
613 | |
667 | |
614 | $self->{motion} = sub { |
668 | $self->{motion} = sub { |
… | |
… | |
616 | |
670 | |
617 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
671 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
618 | |
672 | |
619 | $self->{user_w} = $bw + $x - $ox; |
673 | $self->{user_w} = $bw + $x - $ox; |
620 | $self->{user_h} = $bh + $y - $oy; |
674 | $self->{user_h} = $bh + $y - $oy; |
621 | $self->update; |
675 | $self->check_size; |
622 | }; |
676 | }; |
623 | |
677 | |
624 | } elsif ($x >= 0 && $x < $self->{w} |
678 | } elsif ($x >= 0 && $x < $self->{w} |
625 | && $y >= 0 && $y < $self->{border}) { |
679 | && $y >= 0 && $y < $border) { |
626 | |
680 | |
627 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
681 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
628 | my ($bx, $by) = ($self->{x}, $self->{y}); |
682 | my ($bx, $by) = ($self->{x}, $self->{y}); |
629 | |
683 | |
630 | $self->{motion} = sub { |
684 | $self->{motion} = sub { |
… | |
… | |
659 | glEnable GL_BLEND; |
713 | glEnable GL_BLEND; |
660 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
714 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
661 | glEnable GL_TEXTURE_2D; |
715 | glEnable GL_TEXTURE_2D; |
662 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
716 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
663 | |
717 | |
|
|
718 | my $border = $self->border; |
|
|
719 | |
664 | glColor @{ $self->{border_bg} }; |
720 | glColor @{ $self->{border_bg} }; |
665 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
721 | $tex[1]->draw_quad (0, 0, $w, $border); |
666 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
722 | $tex[3]->draw_quad (0, $border, $border, $ch); |
667 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
723 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
668 | $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); |
724 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
669 | |
725 | |
670 | my $bg = $tex[0]; |
726 | my $bg = $tex[0]; |
671 | |
727 | |
672 | # TODO: repeat texture not scale |
728 | # TODO: repeat texture not scale |
673 | my $rep_x = $cw / $bg->{w}; |
729 | my $rep_x = $cw / $bg->{w}; |
… | |
… | |
676 | glColor @{ $self->{bg} }; |
732 | glColor @{ $self->{bg} }; |
677 | |
733 | |
678 | $bg->{s} = $rep_x; |
734 | $bg->{s} = $rep_x; |
679 | $bg->{t} = $rep_y; |
735 | $bg->{t} = $rep_y; |
680 | $bg->{wrap_mode} = 1; |
736 | $bg->{wrap_mode} = 1; |
681 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
682 | |
738 | |
683 | glDisable GL_TEXTURE_2D; |
739 | glDisable GL_TEXTURE_2D; |
684 | glDisable GL_BLEND; |
740 | glDisable GL_BLEND; |
685 | |
741 | |
686 | $self->child->draw; |
742 | $self->child->draw; |
… | |
… | |
692 | |
748 | |
693 | our @ISA = CFClient::UI::Base::; |
749 | our @ISA = CFClient::UI::Base::; |
694 | |
750 | |
695 | use List::Util qw(max sum); |
751 | use List::Util qw(max sum); |
696 | |
752 | |
697 | use SDL::OpenGL; |
753 | use CFClient::OpenGL; |
698 | |
754 | |
699 | sub new { |
755 | sub new { |
700 | my $class = shift; |
756 | my $class = shift; |
701 | |
757 | |
702 | $class->SUPER::new ( |
758 | $class->SUPER::new ( |
… | |
… | |
709 | my ($self, $x, $y, $child) = @_; |
765 | my ($self, $x, $y, $child) = @_; |
710 | |
766 | |
711 | $child->set_parent ($self); |
767 | $child->set_parent ($self); |
712 | $self->{children}[$y][$x] = $child; |
768 | $self->{children}[$y][$x] = $child; |
713 | |
769 | |
714 | $self->{w} = $self->{h} = -1; |
770 | $child->check_size; |
715 | $self->update; |
|
|
716 | } |
771 | } |
717 | |
772 | |
718 | # 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? |
719 | sub clear { |
774 | sub clear { |
720 | my ($self) = @_; |
775 | my ($self) = @_; |
… | |
… | |
755 | (sum @$hs), |
810 | (sum @$hs), |
756 | ) |
811 | ) |
757 | } |
812 | } |
758 | |
813 | |
759 | sub size_allocate { |
814 | sub size_allocate { |
760 | my ($self, $x, $y, $w, $h) = @_; |
815 | my ($self, $w, $h) = @_; |
761 | |
|
|
762 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
763 | |
816 | |
764 | my ($ws, $hs) = $self->get_wh; |
817 | my ($ws, $hs) = $self->get_wh; |
765 | |
818 | |
766 | my $req_w = sum @$ws; |
819 | my $req_w = sum @$ws; |
767 | my $req_h = sum @$hs; |
820 | my $req_h = sum @$hs; |
… | |
… | |
789 | |
842 | |
790 | for my $c (0 .. $#$row) { |
843 | for my $c (0 .. $#$row) { |
791 | my $col_w = $ws->[$c]; |
844 | my $col_w = $ws->[$c]; |
792 | |
845 | |
793 | if (my $widget = $row->[$c]) { |
846 | if (my $widget = $row->[$c]) { |
794 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
847 | $widget->configure ($x, $y, $col_w, $row_h); |
795 | } |
848 | } |
796 | |
849 | |
797 | $x += $col_w; |
850 | $x += $col_w; |
798 | } |
851 | } |
799 | |
852 | |
… | |
… | |
844 | (List::Util::max map $_->[1], @alloc), |
897 | (List::Util::max map $_->[1], @alloc), |
845 | ) |
898 | ) |
846 | } |
899 | } |
847 | |
900 | |
848 | sub size_allocate { |
901 | sub size_allocate { |
849 | my ($self, $x, $y, $w, $h) = @_; |
902 | my ($self, $w, $h) = @_; |
850 | |
|
|
851 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
852 | |
903 | |
853 | ($h, $w) = ($w, $h); |
904 | ($h, $w) = ($w, $h); |
854 | |
905 | |
855 | my $children = $self->{children}; |
906 | my $children = $self->{children}; |
856 | |
907 | |
… | |
… | |
878 | |
929 | |
879 | my $y = 0; |
930 | my $y = 0; |
880 | for (0 .. $#$children) { |
931 | for (0 .. $#$children) { |
881 | my $child = $children->[$_]; |
932 | my $child = $children->[$_]; |
882 | my $h = $h[$_]; |
933 | my $h = $h[$_]; |
883 | $child->size_allocate ($y, 0, $h, $w); |
934 | $child->configure ($y, 0, $h, $w); |
884 | |
935 | |
885 | $y += $h; |
936 | $y += $h; |
886 | } |
937 | } |
|
|
938 | |
|
|
939 | 1 |
887 | } |
940 | } |
888 | |
941 | |
889 | ############################################################################# |
942 | ############################################################################# |
890 | |
943 | |
891 | package CFClient::UI::VBox; |
944 | package CFClient::UI::VBox; |
… | |
… | |
904 | (List::Util::sum map $_->[1], @alloc), |
957 | (List::Util::sum map $_->[1], @alloc), |
905 | ) |
958 | ) |
906 | } |
959 | } |
907 | |
960 | |
908 | sub size_allocate { |
961 | sub size_allocate { |
909 | my ($self, $x, $y, $w, $h) = @_; |
962 | my ($self, $w, $h) = @_; |
910 | |
|
|
911 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
912 | |
963 | |
913 | my $children = $self->{children}; |
964 | my $children = $self->{children}; |
914 | |
965 | |
915 | my @h = map +($_->size_request)[1], @$children; |
966 | my @h = map +($_->size_request)[1], @$children; |
916 | |
967 | |
… | |
… | |
934 | |
985 | |
935 | my $y = 0; |
986 | my $y = 0; |
936 | for (0 .. $#$children) { |
987 | for (0 .. $#$children) { |
937 | my $child = $children->[$_]; |
988 | my $child = $children->[$_]; |
938 | my $h = $h[$_]; |
989 | my $h = $h[$_]; |
939 | $child->size_allocate (0, $y, $w, $h); |
990 | $child->configure (0, $y, $w, $h); |
940 | |
991 | |
941 | $y += $h; |
992 | $y += $h; |
942 | } |
993 | } |
|
|
994 | |
|
|
995 | 1 |
943 | } |
996 | } |
944 | |
997 | |
945 | ############################################################################# |
998 | ############################################################################# |
946 | |
999 | |
947 | package CFClient::UI::Label; |
1000 | package CFClient::UI::Label; |
948 | |
1001 | |
949 | our @ISA = CFClient::UI::Base::; |
1002 | our @ISA = CFClient::UI::Base::; |
950 | |
1003 | |
951 | use SDL::OpenGL; |
1004 | use CFClient::OpenGL; |
952 | |
1005 | |
953 | sub new { |
1006 | sub new { |
954 | my ($class, %arg) = @_; |
1007 | my ($class, %arg) = @_; |
955 | |
1008 | |
956 | my $self = $class->SUPER::new ( |
1009 | my $self = $class->SUPER::new ( |
957 | fg => [1, 1, 1], |
1010 | fg => [1, 1, 1], |
958 | fontsize => $::FONTSIZE, |
1011 | fontsize => 1, |
959 | text => "", |
1012 | text => "", |
960 | align => -1, |
1013 | align => -1, |
961 | valign => -1, |
1014 | valign => -1, |
962 | padding => 2, |
1015 | padding => 2, |
963 | layout => new CFClient::Layout, |
1016 | layout => new CFClient::Layout, |
… | |
… | |
1002 | |
1055 | |
1003 | sub size_request { |
1056 | sub size_request { |
1004 | my ($self) = @_; |
1057 | my ($self) = @_; |
1005 | |
1058 | |
1006 | $self->{layout}->set_width; |
1059 | $self->{layout}->set_width; |
1007 | $self->{layout}->set_height ($self->{fontsize}); |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1008 | |
1061 | |
1009 | my ($w, $h) = $self->{layout}->size; |
1062 | my ($w, $h) = $self->{layout}->size; |
1010 | |
1063 | |
1011 | ( |
1064 | ( |
1012 | $w + $self->{padding} * 2, |
1065 | $w + $self->{padding} * 2, |
1013 | $h + $self->{padding} * 2, |
1066 | $h + $self->{padding} * 2, |
1014 | ) |
1067 | ) |
1015 | } |
1068 | } |
1016 | |
1069 | |
1017 | sub size_allocate { |
1070 | sub size_allocate { |
1018 | my ($self, $x, $y, $w, $h) = @_; |
1071 | my ($self, $w, $h) = @_; |
1019 | |
|
|
1020 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1021 | |
1072 | |
1022 | delete $self->{texture}; |
1073 | delete $self->{texture}; |
1023 | } |
|
|
1024 | |
|
|
1025 | sub update { |
|
|
1026 | my ($self) = @_; |
|
|
1027 | |
|
|
1028 | delete $self->{texture}; |
|
|
1029 | $self->SUPER::update; |
|
|
1030 | } |
1074 | } |
1031 | |
1075 | |
1032 | sub _draw { |
1076 | sub _draw { |
1033 | my ($self) = @_; |
1077 | my ($self) = @_; |
1034 | |
1078 | |
1035 | my $tex = $self->{texture} ||= do { |
1079 | my $tex = $self->{texture} ||= do { |
1036 | $self->{layout}->set_width ($self->{w}); |
1080 | $self->{layout}->set_width ($self->{w}); |
1037 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); |
1081 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1038 | new_from_layout CFClient::Texture $self->{layout} |
1082 | new_from_layout CFClient::Texture $self->{layout} |
1039 | }; |
1083 | }; |
1040 | |
1084 | |
1041 | glEnable GL_BLEND; |
1085 | glEnable GL_BLEND; |
1042 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1086 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1043 | glEnable GL_TEXTURE_2D; |
1087 | glEnable GL_TEXTURE_2D; |
1044 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1088 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1045 | |
1089 | |
1046 | glColor @{$self->{fg}}; |
1090 | glColor @{$self->{fg}}; |
1047 | |
1091 | |
1048 | my $x = |
1092 | $self->{ox} = int ( |
1049 | $self->{align} < 0 ? $self->{padding} |
1093 | $self->{align} < 0 ? $self->{padding} |
1050 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1094 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1051 | : ($self->{w} - $tex->{w}) * 0.5; |
1095 | : ($self->{w} - $tex->{w}) * 0.5 |
|
|
1096 | ); |
1052 | |
1097 | |
1053 | my $y = |
1098 | $self->{oy} = int ( |
1054 | $self->{valign} < 0 ? $self->{padding} |
1099 | $self->{valign} < 0 ? $self->{padding} |
1055 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1100 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1056 | : ($self->{h} - $tex->{h}) * 0.5; |
1101 | : ($self->{h} - $tex->{h}) * 0.5 |
|
|
1102 | ); |
1057 | |
1103 | |
1058 | $tex->draw_quad (int $x, int $y); |
1104 | $tex->draw_quad ($self->{ox}, $self->{oy}); |
1059 | |
1105 | |
1060 | glDisable GL_TEXTURE_2D; |
1106 | glDisable GL_TEXTURE_2D; |
1061 | glDisable GL_BLEND; |
1107 | glDisable GL_BLEND; |
1062 | } |
1108 | } |
1063 | |
1109 | |
… | |
… | |
1065 | |
1111 | |
1066 | package CFClient::UI::EntryBase; |
1112 | package CFClient::UI::EntryBase; |
1067 | |
1113 | |
1068 | our @ISA = CFClient::UI::Label::; |
1114 | our @ISA = CFClient::UI::Label::; |
1069 | |
1115 | |
1070 | use SDL; |
1116 | use CFClient::OpenGL; |
1071 | use SDL::OpenGL; |
|
|
1072 | |
1117 | |
1073 | sub new { |
1118 | sub new { |
1074 | my $class = shift; |
1119 | my $class = shift; |
1075 | |
1120 | |
1076 | $class->SUPER::new ( |
1121 | $class->SUPER::new ( |
… | |
… | |
1090 | |
1135 | |
1091 | delete $self->{cur_h}; |
1136 | delete $self->{cur_h}; |
1092 | |
1137 | |
1093 | return if $self->{text} eq $text; |
1138 | return if $self->{text} eq $text; |
1094 | |
1139 | |
|
|
1140 | delete $self->{texture}; |
|
|
1141 | |
1095 | $self->{last_activity} = $::NOW; |
1142 | $self->{last_activity} = $::NOW; |
1096 | $self->{text} = $text; |
1143 | $self->{text} = $text; |
1097 | |
1144 | |
1098 | $text =~ s/./*/g if $self->{hidden}; |
1145 | $text =~ s/./*/g if $self->{hidden}; |
1099 | $self->{layout}->set_text ("$text "); |
1146 | $self->{layout}->set_text ("$text "); |
… | |
… | |
1112 | |
1159 | |
1113 | ($w + 1, $h) # add 1 for cursor |
1160 | ($w + 1, $h) # add 1 for cursor |
1114 | } |
1161 | } |
1115 | |
1162 | |
1116 | sub size_allocate { |
1163 | sub size_allocate { |
1117 | my ($self, $x, $y, $w, $h) = @_; |
1164 | my ($self, $w, $h) = @_; |
1118 | |
|
|
1119 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
|
|
1120 | |
1165 | |
1121 | $self->_set_text ($self->{text}); |
1166 | $self->_set_text ($self->{text}); |
1122 | } |
1167 | } |
1123 | |
1168 | |
1124 | sub set_text { |
1169 | sub set_text { |
… | |
… | |
1130 | } |
1175 | } |
1131 | |
1176 | |
1132 | sub key_down { |
1177 | sub key_down { |
1133 | my ($self, $ev) = @_; |
1178 | my ($self, $ev) = @_; |
1134 | |
1179 | |
1135 | my $mod = $ev->key_mod; |
1180 | my $mod = $ev->{mod}; |
1136 | my $sym = $ev->key_sym; |
1181 | my $sym = $ev->{sym}; |
1137 | |
|
|
1138 | my $uni = $ev->key_unicode; |
1182 | my $uni = $ev->{unicode}; |
1139 | |
1183 | |
1140 | my $text = $self->get_text; |
1184 | my $text = $self->get_text; |
1141 | |
1185 | |
1142 | if ($sym == SDLK_BACKSPACE) { |
1186 | if ($sym == 8) { |
1143 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1187 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1144 | } elsif ($sym == SDLK_DELETE) { |
1188 | } elsif ($sym == 127) { |
1145 | substr $text, $self->{cursor}, 1, ""; |
1189 | substr $text, $self->{cursor}, 1, ""; |
1146 | } elsif ($sym == SDLK_LEFT) { |
1190 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1147 | --$self->{cursor} if $self->{cursor}; |
1191 | --$self->{cursor} if $self->{cursor}; |
1148 | } elsif ($sym == SDLK_RIGHT) { |
1192 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1149 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1193 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1150 | } elsif ($sym == SDLK_HOME) { |
1194 | } elsif ($sym == CFClient::SDLK_HOME) { |
1151 | $self->{cursor} = 0; |
1195 | $self->{cursor} = 0; |
1152 | } elsif ($sym == SDLK_END) { |
1196 | } elsif ($sym == CFClient::SDLK_END) { |
1153 | $self->{cursor} = length $text; |
1197 | $self->{cursor} = length $text; |
1154 | } elsif ($sym == SDLK_ESCAPE) { |
1198 | } elsif ($sym == 27) { |
1155 | $self->emit ('escape'); |
1199 | $self->emit ('escape'); |
1156 | } elsif ($uni) { |
1200 | } elsif ($uni) { |
1157 | substr $text, $self->{cursor}++, 0, chr $uni; |
1201 | substr $text, $self->{cursor}++, 0, chr $uni; |
1158 | } |
1202 | } |
1159 | |
1203 | |
… | |
… | |
1224 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
1268 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
1225 | } |
1269 | } |
1226 | |
1270 | |
1227 | glColor @{$self->{fg}}; |
1271 | glColor @{$self->{fg}}; |
1228 | glBegin GL_LINES; |
1272 | glBegin GL_LINES; |
1229 | glVertex $self->{cur_x}, $self->{cur_y}; |
|
|
1230 | 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}; |
1231 | glEnd; |
1275 | glEnd; |
1232 | } |
1276 | } |
1233 | } |
1277 | } |
1234 | |
1278 | |
1235 | package CFClient::UI::Entry; |
1279 | package CFClient::UI::Entry; |
1236 | |
1280 | |
1237 | our @ISA = CFClient::UI::EntryBase::; |
1281 | our @ISA = CFClient::UI::EntryBase::; |
1238 | |
1282 | |
1239 | use SDL; |
1283 | use CFClient::OpenGL; |
1240 | use SDL::OpenGL; |
|
|
1241 | |
1284 | |
1242 | sub key_down { |
1285 | sub key_down { |
1243 | my ($self, $ev) = @_; |
1286 | my ($self, $ev) = @_; |
1244 | |
1287 | |
1245 | my $sym = $ev->key_sym; |
1288 | my $sym = $ev->{sym}; |
1246 | |
1289 | |
1247 | if ($sym == SDLK_RETURN) { |
1290 | if ($sym == 13) { |
1248 | $self->emit (activate => $self->get_text); |
1291 | $self->emit (activate => $self->get_text); |
1249 | $self->update; |
1292 | $self->update; |
1250 | |
1293 | |
1251 | } else { |
1294 | } else { |
1252 | $self->SUPER::key_down ($ev); |
1295 | $self->SUPER::key_down ($ev); |
… | |
… | |
1258 | |
1301 | |
1259 | package CFClient::UI::Button; |
1302 | package CFClient::UI::Button; |
1260 | |
1303 | |
1261 | our @ISA = CFClient::UI::Label::; |
1304 | our @ISA = CFClient::UI::Label::; |
1262 | |
1305 | |
1263 | use SDL; |
1306 | use CFClient::OpenGL; |
1264 | use SDL::OpenGL; |
|
|
1265 | |
1307 | |
1266 | my @tex = |
1308 | my @tex = |
1267 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1309 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1268 | qw(b1_button_active.png); |
1310 | qw(b1_button_active.png); |
1269 | |
1311 | |
… | |
… | |
1272 | |
1314 | |
1273 | $class->SUPER::new ( |
1315 | $class->SUPER::new ( |
1274 | padding => 4, |
1316 | padding => 4, |
1275 | fg => [1, 1, 1], |
1317 | fg => [1, 1, 1], |
1276 | bg => [1, 1, 1, 0.2], |
1318 | bg => [1, 1, 1, 0.2], |
1277 | active_fg => [1, 1, 0], |
1319 | active_fg => [0, 0, 1], |
1278 | can_hover => 1, |
1320 | can_hover => 1, |
|
|
1321 | align => 0, |
|
|
1322 | valign => 0, |
1279 | @_ |
1323 | @_ |
1280 | ) |
1324 | ) |
1281 | } |
1325 | } |
1282 | |
1326 | |
1283 | sub button_up { |
1327 | sub button_up { |
… | |
… | |
1320 | |
1364 | |
1321 | my @tex = |
1365 | my @tex = |
1322 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1366 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1323 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1367 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1324 | |
1368 | |
1325 | use SDL; |
1369 | use CFClient::OpenGL; |
1326 | use SDL::OpenGL; |
|
|
1327 | |
1370 | |
1328 | sub new { |
1371 | sub new { |
1329 | my $class = shift; |
1372 | my $class = shift; |
1330 | |
1373 | |
1331 | $class->SUPER::new ( |
1374 | $class->SUPER::new ( |
… | |
… | |
1342 | my ($self) = @_; |
1385 | my ($self) = @_; |
1343 | |
1386 | |
1344 | ($self->{padding} * 2 + 6) x 2 |
1387 | ($self->{padding} * 2 + 6) x 2 |
1345 | } |
1388 | } |
1346 | |
1389 | |
1347 | sub size_allocate { |
|
|
1348 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1349 | |
|
|
1350 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
1351 | } |
|
|
1352 | |
|
|
1353 | sub button_down { |
1390 | sub button_down { |
1354 | my ($self, $ev, $x, $y) = @_; |
1391 | my ($self, $ev, $x, $y) = @_; |
1355 | |
1392 | |
1356 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1393 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1357 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1394 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
… | |
… | |
1383 | glDisable GL_BLEND; |
1420 | glDisable GL_BLEND; |
1384 | } |
1421 | } |
1385 | |
1422 | |
1386 | ############################################################################# |
1423 | ############################################################################# |
1387 | |
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 | |
1388 | package CFClient::UI::Slider; |
1532 | package CFClient::UI::Slider; |
1389 | |
1533 | |
1390 | use strict; |
1534 | use strict; |
1391 | |
1535 | |
1392 | use SDL::OpenGL; |
1536 | use CFClient::OpenGL; |
1393 | |
1537 | |
1394 | our @ISA = CFClient::UI::DrawBG::; |
1538 | our @ISA = CFClient::UI::DrawBG::; |
1395 | |
1539 | |
1396 | my @tex = |
1540 | my @tex = |
1397 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1541 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1407 | # TODO: calculations are off |
1551 | # TODO: calculations are off |
1408 | my $self = $class->SUPER::new ( |
1552 | my $self = $class->SUPER::new ( |
1409 | fg => [1, 1, 1], |
1553 | fg => [1, 1, 1], |
1410 | active_fg => [0, 0, 0], |
1554 | active_fg => [0, 0, 0], |
1411 | range => [0, 0, 100, 10], |
1555 | range => [0, 0, 100, 10], |
1412 | req_w => 40, |
1556 | req_w => 20, |
1413 | req_h => 13, |
1557 | req_h => 20, |
1414 | vertical => 0, |
1558 | vertical => 0, |
1415 | can_hover => 1, |
1559 | can_hover => 1, |
1416 | inner_pad => 5, |
1560 | inner_pad => 5, |
1417 | @_ |
1561 | @_ |
1418 | ); |
1562 | ); |
… | |
… | |
1522 | |
1666 | |
1523 | package CFClient::UI::TextView; |
1667 | package CFClient::UI::TextView; |
1524 | |
1668 | |
1525 | our @ISA = CFClient::UI::HBox::; |
1669 | our @ISA = CFClient::UI::HBox::; |
1526 | |
1670 | |
1527 | use SDL::OpenGL; |
1671 | use CFClient::OpenGL; |
1528 | |
1672 | |
1529 | sub new { |
1673 | sub new { |
1530 | my $class = shift; |
1674 | my $class = shift; |
1531 | |
1675 | |
1532 | my $self = $class->SUPER::new ( |
1676 | my $self = $class->SUPER::new ( |
1533 | req_w => $::WIDTH / 6, |
|
|
1534 | req_h => $::HEIGHT / 6, |
|
|
1535 | fontsize => $::FONTSIZE, |
1677 | fontsize => 1, |
1536 | @_, |
1678 | @_, |
1537 | |
1679 | |
1538 | layout => (new CFClient::Layout), |
1680 | layout => (new CFClient::Layout), |
1539 | par => [], |
1681 | par => [], |
1540 | height => 0, |
1682 | height => 0, |
… | |
… | |
1561 | sub text_height { |
1703 | sub text_height { |
1562 | my ($self, $text) = @_; |
1704 | my ($self, $text) = @_; |
1563 | |
1705 | |
1564 | my $layout = $self->{layout}; |
1706 | my $layout = $self->{layout}; |
1565 | |
1707 | |
1566 | $layout->set_height ($self->{fontsize}); |
1708 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
1567 | $layout->set_width ($self->{w}); |
1709 | $layout->set_width ($self->{w}); |
1568 | $layout->set_text ($text); |
1710 | $layout->set_text ($text); |
1569 | |
1711 | |
1570 | ($layout->size)[1] |
1712 | ($layout->size)[1] |
1571 | } |
1713 | } |
… | |
… | |
1575 | |
1717 | |
1576 | $self->{need_reflow}++; |
1718 | $self->{need_reflow}++; |
1577 | $self->update; |
1719 | $self->update; |
1578 | } |
1720 | } |
1579 | |
1721 | |
1580 | sub size_request { |
|
|
1581 | my ($self) = @_; |
|
|
1582 | |
|
|
1583 | ($self->{req_w}, $self->{req_h}) |
|
|
1584 | } |
|
|
1585 | |
|
|
1586 | sub size_allocate { |
1722 | sub size_allocate { |
1587 | my ($self, $x, $y, $w, $h) = @_; |
1723 | my ($self, $w, $h) = @_; |
1588 | |
1724 | |
1589 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
1725 | $self->SUPER::size_allocate ($w, $h); |
1590 | |
1726 | |
1591 | $self->{layout}->set_height ($self->{fontsize}); |
1727 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1592 | $self->{layout}->set_width ($self->{w}); |
1728 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1593 | |
1729 | |
1594 | $self->reflow; |
1730 | $self->reflow; |
1595 | } |
1731 | } |
1596 | |
1732 | |
1597 | sub add_paragraph { |
1733 | sub add_paragraph { |
… | |
… | |
1684 | |
1820 | |
1685 | } |
1821 | } |
1686 | |
1822 | |
1687 | ############################################################################# |
1823 | ############################################################################# |
1688 | |
1824 | |
1689 | package CFClient::UI::MapWidget; |
|
|
1690 | |
|
|
1691 | use strict; |
|
|
1692 | |
|
|
1693 | use List::Util qw(min max); |
|
|
1694 | |
|
|
1695 | use SDL; |
|
|
1696 | use SDL::OpenGL; |
|
|
1697 | |
|
|
1698 | our @ISA = CFClient::UI::Base::; |
|
|
1699 | |
|
|
1700 | sub new { |
|
|
1701 | my $class = shift; |
|
|
1702 | |
|
|
1703 | $class->SUPER::new ( |
|
|
1704 | z => -1, |
|
|
1705 | can_focus => 1, |
|
|
1706 | list => (glGenLists 1), |
|
|
1707 | @_ |
|
|
1708 | ) |
|
|
1709 | } |
|
|
1710 | |
|
|
1711 | sub key_down { |
|
|
1712 | print "MAPKEYDOWN\n"; |
|
|
1713 | } |
|
|
1714 | |
|
|
1715 | sub key_up { |
|
|
1716 | } |
|
|
1717 | |
|
|
1718 | sub button_down { |
|
|
1719 | my ($self, $ev, $x, $y) = @_; |
|
|
1720 | |
|
|
1721 | $self->focus_in; |
|
|
1722 | |
|
|
1723 | if ($ev->button == 2) { |
|
|
1724 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1725 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1726 | |
|
|
1727 | $self->{motion} = sub { |
|
|
1728 | my ($ev, $x, $y) = @_; |
|
|
1729 | |
|
|
1730 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1731 | |
|
|
1732 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1733 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1734 | |
|
|
1735 | $self->update; |
|
|
1736 | }; |
|
|
1737 | } |
|
|
1738 | } |
|
|
1739 | |
|
|
1740 | sub button_up { |
|
|
1741 | my ($self, $ev, $x, $y) = @_; |
|
|
1742 | |
|
|
1743 | delete $self->{motion}; |
|
|
1744 | } |
|
|
1745 | |
|
|
1746 | sub mouse_motion { |
|
|
1747 | my ($self, $ev, $x, $y) = @_; |
|
|
1748 | |
|
|
1749 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1750 | } |
|
|
1751 | |
|
|
1752 | sub size_request { |
|
|
1753 | ( |
|
|
1754 | 1 + 32 * int $::WIDTH / 32, |
|
|
1755 | 1 + 32 * int $::HEIGHT / 32, |
|
|
1756 | ) |
|
|
1757 | } |
|
|
1758 | |
|
|
1759 | sub update { |
|
|
1760 | my ($self) = @_; |
|
|
1761 | |
|
|
1762 | $self->{need_update} = 1; |
|
|
1763 | $self->SUPER::update; |
|
|
1764 | } |
|
|
1765 | |
|
|
1766 | sub draw { |
|
|
1767 | my ($self) = @_; |
|
|
1768 | |
|
|
1769 | if (delete $self->{need_update}) { |
|
|
1770 | glNewList $self->{list}, GL_COMPILE; |
|
|
1771 | |
|
|
1772 | if ($::MAP) { |
|
|
1773 | my $sw = int $::WIDTH / 32; |
|
|
1774 | my $sh = int $::HEIGHT / 32; |
|
|
1775 | |
|
|
1776 | my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
1777 | my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
1778 | |
|
|
1779 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
|
|
1780 | |
|
|
1781 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
|
|
1782 | |
|
|
1783 | if ($::CFG->{fow_enable}) { |
|
|
1784 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1785 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1786 | glConvolutionFilter2D |
|
|
1787 | GL_CONVOLUTION_2D, |
|
|
1788 | GL_ALPHA, |
|
|
1789 | 3, 3, |
|
|
1790 | GL_ALPHA, GL_FLOAT, |
|
|
1791 | pack "f*", |
|
|
1792 | 0.1, 0.1, 0.1, |
|
|
1793 | 0.1, 0.2, 0.1, |
|
|
1794 | 0.1, 0.1, 0.1, |
|
|
1795 | ; |
|
|
1796 | glEnable GL_CONVOLUTION_2D; |
|
|
1797 | } |
|
|
1798 | |
|
|
1799 | $self->{fow_texture} = new CFClient::Texture |
|
|
1800 | w => $w, |
|
|
1801 | h => $h, |
|
|
1802 | data => $data, |
|
|
1803 | internalformat => GL_ALPHA, |
|
|
1804 | format => GL_ALPHA; |
|
|
1805 | |
|
|
1806 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1807 | |
|
|
1808 | glEnable GL_BLEND; |
|
|
1809 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1810 | glEnable GL_TEXTURE_2D; |
|
|
1811 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1812 | |
|
|
1813 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1814 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1815 | |
|
|
1816 | glDisable GL_TEXTURE_2D; |
|
|
1817 | glDisable GL_BLEND; |
|
|
1818 | } |
|
|
1819 | |
|
|
1820 | # HACK BEGIN |
|
|
1821 | { |
|
|
1822 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
1823 | my ($w, $h) = (250, 250); |
|
|
1824 | |
|
|
1825 | glEnable GL_BLEND; |
|
|
1826 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1827 | glEnable GL_TEXTURE_2D; |
|
|
1828 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1829 | |
|
|
1830 | $self->{mapmap_texture} = |
|
|
1831 | new CFClient::Texture |
|
|
1832 | w => $w, |
|
|
1833 | h => $h, |
|
|
1834 | data => $::MAP->mapmap ($w, $h), |
|
|
1835 | type => GL_UNSIGNED_INT_8_8_8_8_REV; |
|
|
1836 | |
|
|
1837 | $self->{mapmap_texture}->draw_quad (100, 100); |
|
|
1838 | |
|
|
1839 | glDisable GL_TEXTURE_2D; |
|
|
1840 | glDisable GL_BLEND; |
|
|
1841 | } |
|
|
1842 | # HACK END |
|
|
1843 | } |
|
|
1844 | |
|
|
1845 | glEndList; |
|
|
1846 | } |
|
|
1847 | |
|
|
1848 | glPushMatrix; |
|
|
1849 | glCallList $self->{list}; |
|
|
1850 | glPopMatrix; |
|
|
1851 | |
|
|
1852 | if ($FOCUS != $self) { |
|
|
1853 | glColor 64/255, 64/255, 64/255; |
|
|
1854 | glLogicOp GL_AND; |
|
|
1855 | glEnable GL_COLOR_LOGIC_OP; |
|
|
1856 | glBegin GL_QUADS; |
|
|
1857 | glVertex 0, 0; |
|
|
1858 | glVertex 0, $::HEIGHT; |
|
|
1859 | glVertex $::WIDTH, $::HEIGHT; |
|
|
1860 | glVertex $::WIDTH, 0; |
|
|
1861 | glEnd; |
|
|
1862 | glDisable GL_COLOR_LOGIC_OP; |
|
|
1863 | } |
|
|
1864 | } |
|
|
1865 | |
|
|
1866 | my %DIR = ( |
|
|
1867 | SDLK_KP8, [1, "north"], |
|
|
1868 | SDLK_KP9, [2, "northeast"], |
|
|
1869 | SDLK_KP6, [3, "east"], |
|
|
1870 | SDLK_KP3, [4, "southeast"], |
|
|
1871 | SDLK_KP2, [5, "south"], |
|
|
1872 | SDLK_KP1, [6, "southwest"], |
|
|
1873 | SDLK_KP4, [7, "west"], |
|
|
1874 | SDLK_KP7, [8, "northwest"], |
|
|
1875 | |
|
|
1876 | SDLK_UP, [1, "north"], |
|
|
1877 | SDLK_RIGHT, [3, "east"], |
|
|
1878 | SDLK_DOWN, [5, "south"], |
|
|
1879 | SDLK_LEFT, [7, "west"], |
|
|
1880 | ); |
|
|
1881 | |
|
|
1882 | sub key_down { |
|
|
1883 | my ($self, $ev) = @_; |
|
|
1884 | |
|
|
1885 | my $mod = $ev->key_mod; |
|
|
1886 | my $sym = $ev->key_sym; |
|
|
1887 | |
|
|
1888 | if ($sym == SDLK_KP5) { |
|
|
1889 | $::CONN->user_send ("command stay fire"); |
|
|
1890 | } elsif ($sym == SDLK_a) { |
|
|
1891 | $::CONN->user_send ("command apply"); |
|
|
1892 | } elsif ($sym == SDLK_QUOTE) { |
|
|
1893 | $self->emit ('activate_console'); |
|
|
1894 | } elsif ($sym == SDLK_SLASH) { |
|
|
1895 | $self->emit ('activate_console' => '/'); |
|
|
1896 | } elsif (exists $DIR{$sym}) { |
|
|
1897 | if ($mod & KMOD_SHIFT) { |
|
|
1898 | $self->{shft}++; |
|
|
1899 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
|
|
1900 | } elsif ($mod & KMOD_CTRL) { |
|
|
1901 | $self->{ctrl}++; |
|
|
1902 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
|
|
1903 | } else { |
|
|
1904 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
|
|
1905 | } |
|
|
1906 | } |
|
|
1907 | } |
|
|
1908 | |
|
|
1909 | sub key_up { |
|
|
1910 | my ($self, $ev) = @_; |
|
|
1911 | |
|
|
1912 | my $mod = $ev->key_mod; |
|
|
1913 | my $sym = $ev->key_sym; |
|
|
1914 | |
|
|
1915 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
|
|
1916 | $::CONN->user_send ("command fire_stop"); |
|
|
1917 | } |
|
|
1918 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
1919 | $::CONN->user_send ("command run_stop"); |
|
|
1920 | } |
|
|
1921 | } |
|
|
1922 | |
|
|
1923 | ############################################################################# |
|
|
1924 | |
|
|
1925 | package CFClient::UI::Animator; |
1825 | package CFClient::UI::Animator; |
1926 | |
1826 | |
1927 | use SDL::OpenGL; |
1827 | use CFClient::OpenGL; |
1928 | |
1828 | |
1929 | our @ISA = CFClient::UI::Bin::; |
1829 | our @ISA = CFClient::UI::Bin::; |
1930 | |
1830 | |
1931 | sub moveto { |
1831 | sub moveto { |
1932 | my ($self, $x, $y) = @_; |
1832 | my ($self, $x, $y) = @_; |
… | |
… | |
2005 | |
1905 | |
2006 | package CFClient::UI::Root; |
1906 | package CFClient::UI::Root; |
2007 | |
1907 | |
2008 | our @ISA = CFClient::UI::Container::; |
1908 | our @ISA = CFClient::UI::Container::; |
2009 | |
1909 | |
2010 | use SDL::OpenGL; |
1910 | use CFClient::OpenGL; |
|
|
1911 | |
|
|
1912 | sub check_size { |
|
|
1913 | my ($self) = @_; |
|
|
1914 | |
|
|
1915 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
|
|
1916 | } |
2011 | |
1917 | |
2012 | sub size_request { |
1918 | sub size_request { |
2013 | ($::WIDTH, $::HEIGHT) |
1919 | ($::WIDTH, $::HEIGHT) |
2014 | } |
1920 | } |
2015 | |
1921 | |
2016 | sub size_allocate { |
1922 | sub configure { |
2017 | my ($self, $x, $y, $w, $h) = @_; |
1923 | my ($self, $x, $y, $w, $h) = @_; |
2018 | |
1924 | |
2019 | $self->_size_allocate ($x, $y, $w, $h); |
1925 | $self->SUPER::configure ($x, $y, $w, $h); |
2020 | |
1926 | |
2021 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
1927 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
2022 | for @{$self->{children}}; |
1928 | for @{$self->{children}}; |
2023 | } |
1929 | } |
2024 | |
1930 | |
2025 | sub _topleft { |
1931 | sub _topleft { |
2026 | my ($self, $x, $y) = @_; |
1932 | my ($self, $x, $y) = @_; |
… | |
… | |
2029 | } |
1935 | } |
2030 | |
1936 | |
2031 | sub update { |
1937 | sub update { |
2032 | my ($self) = @_; |
1938 | my ($self) = @_; |
2033 | |
1939 | |
2034 | $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); |
1940 | $self->check_size; |
2035 | ::refresh (); |
1941 | ::refresh (); |
2036 | } |
1942 | } |
2037 | |
1943 | |
2038 | sub add { |
1944 | sub add { |
2039 | my ($self, $widget) = @_; |
1945 | my ($self, $child) = @_; |
2040 | |
1946 | |
2041 | $self->SUPER::add ($widget); |
1947 | $self->SUPER::add ($child); |
2042 | |
|
|
2043 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
|
|
2044 | } |
1948 | } |
2045 | |
1949 | |
2046 | sub on_refresh { |
1950 | sub on_refresh { |
2047 | my ($self, $id, $cb) = @_; |
1951 | my ($self, $id, $cb) = @_; |
2048 | |
1952 | |