… | |
… | |
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; |
… | |
… | |
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) = @_; |
… | |
… | |
284 | } |
300 | } |
285 | |
301 | |
286 | sub connect { |
302 | sub connect { |
287 | my ($self, $signal, $cb) = @_; |
303 | my ($self, $signal, $cb) = @_; |
288 | |
304 | |
289 | push @{ $self->{cb}{$signal} }, $cb; |
305 | push @{ $self->{signal_cb}{$signal} }, $cb; |
290 | } |
306 | } |
291 | |
307 | |
292 | sub emit { |
308 | sub emit { |
293 | my ($self, $signal, @args) = @_; |
309 | my ($self, $signal, @args) = @_; |
294 | |
310 | |
|
|
311 | for my $cb (@{$self->{signal_cb}{$signal} || []}) { |
295 | $_->($self, @args) |
312 | $cb->($self, @args); |
296 | for @{$self->{cb}{$signal} || []}; |
313 | } |
297 | } |
314 | } |
298 | |
315 | |
299 | sub DESTROY { |
316 | sub DESTROY { |
300 | my ($self) = @_; |
317 | my ($self) = @_; |
301 | |
318 | |
… | |
… | |
381 | $self->{children} = [ |
398 | $self->{children} = [ |
382 | sort { $a->{z} <=> $b->{z} } |
399 | sort { $a->{z} <=> $b->{z} } |
383 | @{$self->{children}}, $child |
400 | @{$self->{children}}, $child |
384 | ]; |
401 | ]; |
385 | |
402 | |
386 | $self->{w} = $self->{h} = -1; |
|
|
387 | |
|
|
388 | $child->check_size; |
403 | $child->check_size; |
389 | } |
404 | } |
390 | |
405 | |
391 | sub remove { |
406 | sub remove { |
392 | my ($self, $widget) = @_; |
407 | my ($self, $child) = @_; |
393 | |
408 | |
|
|
409 | delete $child->{parent}; |
|
|
410 | |
394 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
411 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
395 | |
412 | |
396 | $self->check_size; |
413 | $self->check_size; |
397 | } |
414 | } |
398 | |
415 | |
399 | sub find_widget { |
416 | sub find_widget { |
… | |
… | |
431 | |
448 | |
432 | $class->SUPER::new (children => [$child], %arg) |
449 | $class->SUPER::new (children => [$child], %arg) |
433 | } |
450 | } |
434 | |
451 | |
435 | sub add { |
452 | sub add { |
436 | my ($self, $widget) = @_; |
453 | my ($self, $child) = @_; |
437 | |
454 | |
438 | $self->{children} = []; |
455 | $self->{children} = []; |
439 | |
456 | |
440 | $self->SUPER::add ($widget); |
457 | $self->SUPER::add ($child); |
441 | } |
458 | } |
442 | |
459 | |
443 | sub remove { |
460 | sub remove { |
444 | my ($self, $widget) = @_; |
461 | my ($self, $widget) = @_; |
445 | |
462 | |
… | |
… | |
454 | sub size_request { |
471 | sub size_request { |
455 | $_[0]{children}[0]->size_request |
472 | $_[0]{children}[0]->size_request |
456 | } |
473 | } |
457 | |
474 | |
458 | sub size_allocate { |
475 | sub size_allocate { |
459 | my ($self, $x, $y, $w, $h) = @_; |
476 | my ($self, $w, $h) = @_; |
460 | |
477 | |
461 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
462 | |
|
|
463 | $self->{children}[0]->size_allocate (0, 0, $w, $h); |
478 | $self->{children}[0]->configure (0, 0, $w, $h); |
464 | } |
479 | } |
465 | |
480 | |
466 | ############################################################################# |
481 | ############################################################################# |
467 | |
482 | |
468 | package CFClient::UI::Window; |
483 | package CFClient::UI::Window; |
… | |
… | |
494 | $self->child->draw; |
509 | $self->child->draw; |
495 | }; |
510 | }; |
496 | } |
511 | } |
497 | |
512 | |
498 | sub size_allocate { |
513 | sub size_allocate { |
499 | my ($self, $x, $y, $w, $h) = @_; |
514 | my ($self, $w, $h) = @_; |
500 | |
515 | |
501 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
502 | |
|
|
503 | $self->child->size_allocate (0, 0, $w, $h); |
516 | $self->child->configure (0, 0, $w, $h); |
504 | |
517 | |
505 | $self->render_chld; |
518 | $self->render_chld; |
506 | } |
519 | } |
507 | |
520 | |
508 | sub _draw { |
521 | sub _draw { |
… | |
… | |
539 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
552 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
540 | |
553 | |
541 | @$self{qw(child_w child_h)} |
554 | @$self{qw(child_w child_h)} |
542 | } |
555 | } |
543 | |
556 | |
544 | sub size_allocate { |
|
|
545 | my ($self, $x, $y, $w, $h) = @_; |
|
|
546 | |
|
|
547 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
548 | } |
|
|
549 | |
|
|
550 | sub _draw { |
557 | sub _draw { |
551 | my ($self) = @_; |
558 | my ($self) = @_; |
552 | |
559 | |
553 | $self->{children}[1]->draw; |
560 | $self->{children}[1]->draw; |
554 | } |
561 | } |
… | |
… | |
573 | } |
580 | } |
574 | |
581 | |
575 | sub size_allocate { |
582 | sub size_allocate { |
576 | my ($self, $x, $y, $w, $h) = @_; |
583 | my ($self, $x, $y, $w, $h) = @_; |
577 | |
584 | |
578 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
579 | |
|
|
580 | $self->child->size_allocate (2, 2, $w - 4, $h - 4); |
585 | $self->child->configure (2, 2, $w - 4, $h - 4); |
581 | } |
586 | } |
582 | |
587 | |
583 | sub _draw { |
588 | sub _draw { |
584 | my ($self) = @_; |
589 | my ($self) = @_; |
585 | |
590 | |
… | |
… | |
616 | # TODO: user_x, user_y, overwrite moveto? |
621 | # TODO: user_x, user_y, overwrite moveto? |
617 | |
622 | |
618 | $class->SUPER::new ( |
623 | $class->SUPER::new ( |
619 | bg => [1, 1, 1, 1], |
624 | bg => [1, 1, 1, 1], |
620 | border_bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
621 | border => int $::FONTSIZE * 0.8, |
626 | border => 0.8, |
622 | @_ |
627 | @_ |
623 | ) |
628 | ) |
624 | } |
629 | } |
625 | |
630 | |
|
|
631 | sub border { |
|
|
632 | int $_[0]{border} * $::FONTSIZE |
|
|
633 | } |
|
|
634 | |
626 | sub size_request { |
635 | sub size_request { |
627 | my ($self) = @_; |
636 | my ($self) = @_; |
628 | |
637 | |
629 | 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}; |
630 | |
639 | |
631 | my ($w, $h) = $self->SUPER::size_request; |
640 | my ($w, $h) = $self->SUPER::size_request; |
632 | |
641 | |
633 | ( |
642 | ( |
634 | $w + $self->{border} * 2, |
643 | $w + $self->border * 2, |
635 | $h + $self->{border} * 2, |
644 | $h + $self->border * 2, |
636 | ) |
645 | ) |
637 | } |
646 | } |
638 | |
647 | |
639 | sub size_allocate { |
648 | sub size_allocate { |
640 | my ($self, $x, $y, $w, $h) = @_; |
649 | my ($self, $w, $h) = @_; |
641 | |
650 | |
642 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
643 | |
|
|
644 | $h -= List::Util::max 0, $self->{border} * 2; |
651 | $h -= List::Util::max 0, $self->border * 2; |
645 | $w -= List::Util::max 0, $self->{border} * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
646 | |
653 | |
647 | $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
648 | } |
655 | } |
649 | |
656 | |
650 | sub button_down { |
657 | sub button_down { |
651 | my ($self, $ev, $x, $y) = @_; |
658 | my ($self, $ev, $x, $y) = @_; |
652 | |
659 | |
|
|
660 | my $border = $self->border; |
|
|
661 | |
653 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
662 | if ($x < $self->{w} && $x >= $self->{w} - $border |
654 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
663 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
655 | |
664 | |
656 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
665 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
657 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
666 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
658 | |
667 | |
659 | $self->{motion} = sub { |
668 | $self->{motion} = sub { |
… | |
… | |
661 | |
670 | |
662 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
671 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
663 | |
672 | |
664 | $self->{user_w} = $bw + $x - $ox; |
673 | $self->{user_w} = $bw + $x - $ox; |
665 | $self->{user_h} = $bh + $y - $oy; |
674 | $self->{user_h} = $bh + $y - $oy; |
666 | $self->update; |
675 | $self->check_size; |
667 | }; |
676 | }; |
668 | |
677 | |
669 | } elsif ($x >= 0 && $x < $self->{w} |
678 | } elsif ($x >= 0 && $x < $self->{w} |
670 | && $y >= 0 && $y < $self->{border}) { |
679 | && $y >= 0 && $y < $border) { |
671 | |
680 | |
672 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
681 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
673 | my ($bx, $by) = ($self->{x}, $self->{y}); |
682 | my ($bx, $by) = ($self->{x}, $self->{y}); |
674 | |
683 | |
675 | $self->{motion} = sub { |
684 | $self->{motion} = sub { |
… | |
… | |
704 | glEnable GL_BLEND; |
713 | glEnable GL_BLEND; |
705 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
714 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
706 | glEnable GL_TEXTURE_2D; |
715 | glEnable GL_TEXTURE_2D; |
707 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
716 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
708 | |
717 | |
|
|
718 | my $border = $self->border; |
|
|
719 | |
709 | glColor @{ $self->{border_bg} }; |
720 | glColor @{ $self->{border_bg} }; |
710 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
721 | $tex[1]->draw_quad (0, 0, $w, $border); |
711 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
722 | $tex[3]->draw_quad (0, $border, $border, $ch); |
712 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
723 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
713 | $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); |
724 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
714 | |
725 | |
715 | my $bg = $tex[0]; |
726 | my $bg = $tex[0]; |
716 | |
727 | |
717 | # TODO: repeat texture not scale |
728 | # TODO: repeat texture not scale |
718 | my $rep_x = $cw / $bg->{w}; |
729 | my $rep_x = $cw / $bg->{w}; |
… | |
… | |
721 | glColor @{ $self->{bg} }; |
732 | glColor @{ $self->{bg} }; |
722 | |
733 | |
723 | $bg->{s} = $rep_x; |
734 | $bg->{s} = $rep_x; |
724 | $bg->{t} = $rep_y; |
735 | $bg->{t} = $rep_y; |
725 | $bg->{wrap_mode} = 1; |
736 | $bg->{wrap_mode} = 1; |
726 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
727 | |
738 | |
728 | glDisable GL_TEXTURE_2D; |
739 | glDisable GL_TEXTURE_2D; |
729 | glDisable GL_BLEND; |
740 | glDisable GL_BLEND; |
730 | |
741 | |
731 | $self->child->draw; |
742 | $self->child->draw; |
… | |
… | |
754 | my ($self, $x, $y, $child) = @_; |
765 | my ($self, $x, $y, $child) = @_; |
755 | |
766 | |
756 | $child->set_parent ($self); |
767 | $child->set_parent ($self); |
757 | $self->{children}[$y][$x] = $child; |
768 | $self->{children}[$y][$x] = $child; |
758 | |
769 | |
759 | $self->{w} = $self->{h} = -1; |
|
|
760 | |
|
|
761 | $child->check_size; |
770 | $child->check_size; |
762 | } |
771 | } |
763 | |
772 | |
764 | # 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? |
765 | sub clear { |
774 | sub clear { |
… | |
… | |
801 | (sum @$hs), |
810 | (sum @$hs), |
802 | ) |
811 | ) |
803 | } |
812 | } |
804 | |
813 | |
805 | sub size_allocate { |
814 | sub size_allocate { |
806 | my ($self, $x, $y, $w, $h) = @_; |
815 | my ($self, $w, $h) = @_; |
807 | |
|
|
808 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
809 | |
816 | |
810 | my ($ws, $hs) = $self->get_wh; |
817 | my ($ws, $hs) = $self->get_wh; |
811 | |
818 | |
812 | my $req_w = sum @$ws; |
819 | my $req_w = sum @$ws; |
813 | my $req_h = sum @$hs; |
820 | my $req_h = sum @$hs; |
… | |
… | |
835 | |
842 | |
836 | for my $c (0 .. $#$row) { |
843 | for my $c (0 .. $#$row) { |
837 | my $col_w = $ws->[$c]; |
844 | my $col_w = $ws->[$c]; |
838 | |
845 | |
839 | if (my $widget = $row->[$c]) { |
846 | if (my $widget = $row->[$c]) { |
840 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
847 | $widget->configure ($x, $y, $col_w, $row_h); |
841 | } |
848 | } |
842 | |
849 | |
843 | $x += $col_w; |
850 | $x += $col_w; |
844 | } |
851 | } |
845 | |
852 | |
… | |
… | |
890 | (List::Util::max map $_->[1], @alloc), |
897 | (List::Util::max map $_->[1], @alloc), |
891 | ) |
898 | ) |
892 | } |
899 | } |
893 | |
900 | |
894 | sub size_allocate { |
901 | sub size_allocate { |
895 | my ($self, $x, $y, $w, $h) = @_; |
902 | my ($self, $w, $h) = @_; |
896 | |
|
|
897 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
898 | |
903 | |
899 | ($h, $w) = ($w, $h); |
904 | ($h, $w) = ($w, $h); |
900 | |
905 | |
901 | my $children = $self->{children}; |
906 | my $children = $self->{children}; |
902 | |
907 | |
… | |
… | |
924 | |
929 | |
925 | my $y = 0; |
930 | my $y = 0; |
926 | for (0 .. $#$children) { |
931 | for (0 .. $#$children) { |
927 | my $child = $children->[$_]; |
932 | my $child = $children->[$_]; |
928 | my $h = $h[$_]; |
933 | my $h = $h[$_]; |
929 | $child->size_allocate ($y, 0, $h, $w); |
934 | $child->configure ($y, 0, $h, $w); |
930 | |
935 | |
931 | $y += $h; |
936 | $y += $h; |
932 | } |
937 | } |
933 | |
938 | |
934 | 1 |
939 | 1 |
… | |
… | |
952 | (List::Util::sum map $_->[1], @alloc), |
957 | (List::Util::sum map $_->[1], @alloc), |
953 | ) |
958 | ) |
954 | } |
959 | } |
955 | |
960 | |
956 | sub size_allocate { |
961 | sub size_allocate { |
957 | my ($self, $x, $y, $w, $h) = @_; |
962 | my ($self, $w, $h) = @_; |
958 | |
|
|
959 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
960 | |
963 | |
961 | my $children = $self->{children}; |
964 | my $children = $self->{children}; |
962 | |
965 | |
963 | my @h = map +($_->size_request)[1], @$children; |
966 | my @h = map +($_->size_request)[1], @$children; |
964 | |
967 | |
… | |
… | |
982 | |
985 | |
983 | my $y = 0; |
986 | my $y = 0; |
984 | for (0 .. $#$children) { |
987 | for (0 .. $#$children) { |
985 | my $child = $children->[$_]; |
988 | my $child = $children->[$_]; |
986 | my $h = $h[$_]; |
989 | my $h = $h[$_]; |
987 | $child->size_allocate (0, $y, $w, $h); |
990 | $child->configure (0, $y, $w, $h); |
988 | |
991 | |
989 | $y += $h; |
992 | $y += $h; |
990 | } |
993 | } |
991 | |
994 | |
992 | 1 |
995 | 1 |
… | |
… | |
1003 | sub new { |
1006 | sub new { |
1004 | my ($class, %arg) = @_; |
1007 | my ($class, %arg) = @_; |
1005 | |
1008 | |
1006 | my $self = $class->SUPER::new ( |
1009 | my $self = $class->SUPER::new ( |
1007 | fg => [1, 1, 1], |
1010 | fg => [1, 1, 1], |
1008 | fontsize => $::FONTSIZE, |
1011 | fontsize => 1, |
1009 | text => "", |
1012 | text => "", |
1010 | align => -1, |
1013 | align => -1, |
1011 | valign => -1, |
1014 | valign => -1, |
1012 | padding => 2, |
1015 | padding => 2, |
1013 | layout => new CFClient::Layout, |
1016 | layout => new CFClient::Layout, |
… | |
… | |
1052 | |
1055 | |
1053 | sub size_request { |
1056 | sub size_request { |
1054 | my ($self) = @_; |
1057 | my ($self) = @_; |
1055 | |
1058 | |
1056 | $self->{layout}->set_width; |
1059 | $self->{layout}->set_width; |
1057 | $self->{layout}->set_height ($self->{fontsize}); |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1058 | |
1061 | |
1059 | my ($w, $h) = $self->{layout}->size; |
1062 | my ($w, $h) = $self->{layout}->size; |
1060 | |
1063 | |
1061 | ( |
1064 | ( |
1062 | $w + $self->{padding} * 2, |
1065 | $w + $self->{padding} * 2, |
1063 | $h + $self->{padding} * 2, |
1066 | $h + $self->{padding} * 2, |
1064 | ) |
1067 | ) |
1065 | } |
1068 | } |
1066 | |
1069 | |
1067 | sub size_allocate { |
1070 | sub size_allocate { |
1068 | my ($self, $x, $y, $w, $h) = @_; |
1071 | my ($self, $w, $h) = @_; |
1069 | |
|
|
1070 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1071 | |
1072 | |
1072 | delete $self->{texture}; |
1073 | delete $self->{texture}; |
1073 | } |
|
|
1074 | |
|
|
1075 | sub update { |
|
|
1076 | my ($self) = @_; |
|
|
1077 | |
|
|
1078 | delete $self->{texture}; |
|
|
1079 | $self->SUPER::update; |
|
|
1080 | } |
1074 | } |
1081 | |
1075 | |
1082 | sub _draw { |
1076 | sub _draw { |
1083 | my ($self) = @_; |
1077 | my ($self) = @_; |
1084 | |
1078 | |
1085 | my $tex = $self->{texture} ||= do { |
1079 | my $tex = $self->{texture} ||= do { |
1086 | $self->{layout}->set_width ($self->{w}); |
1080 | $self->{layout}->set_width ($self->{w}); |
1087 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); |
1081 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1088 | new_from_layout CFClient::Texture $self->{layout} |
1082 | new_from_layout CFClient::Texture $self->{layout} |
1089 | }; |
1083 | }; |
1090 | |
1084 | |
1091 | glEnable GL_BLEND; |
1085 | glEnable GL_BLEND; |
1092 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1086 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
1117 | |
1111 | |
1118 | package CFClient::UI::EntryBase; |
1112 | package CFClient::UI::EntryBase; |
1119 | |
1113 | |
1120 | our @ISA = CFClient::UI::Label::; |
1114 | our @ISA = CFClient::UI::Label::; |
1121 | |
1115 | |
1122 | use SDL; |
|
|
1123 | use SDL::OpenGL; |
1116 | use SDL::OpenGL; |
1124 | |
1117 | |
1125 | sub new { |
1118 | sub new { |
1126 | my $class = shift; |
1119 | my $class = shift; |
1127 | |
1120 | |
… | |
… | |
1142 | |
1135 | |
1143 | delete $self->{cur_h}; |
1136 | delete $self->{cur_h}; |
1144 | |
1137 | |
1145 | return if $self->{text} eq $text; |
1138 | return if $self->{text} eq $text; |
1146 | |
1139 | |
|
|
1140 | delete $self->{texture}; |
|
|
1141 | |
1147 | $self->{last_activity} = $::NOW; |
1142 | $self->{last_activity} = $::NOW; |
1148 | $self->{text} = $text; |
1143 | $self->{text} = $text; |
1149 | |
1144 | |
1150 | $text =~ s/./*/g if $self->{hidden}; |
1145 | $text =~ s/./*/g if $self->{hidden}; |
1151 | $self->{layout}->set_text ("$text "); |
1146 | $self->{layout}->set_text ("$text "); |
… | |
… | |
1164 | |
1159 | |
1165 | ($w + 1, $h) # add 1 for cursor |
1160 | ($w + 1, $h) # add 1 for cursor |
1166 | } |
1161 | } |
1167 | |
1162 | |
1168 | sub size_allocate { |
1163 | sub size_allocate { |
1169 | my ($self, $x, $y, $w, $h) = @_; |
1164 | my ($self, $w, $h) = @_; |
1170 | |
|
|
1171 | $self->SUPER::size_allocate ($x, $y, $w, $h) or return; |
|
|
1172 | |
1165 | |
1173 | $self->_set_text ($self->{text}); |
1166 | $self->_set_text ($self->{text}); |
1174 | } |
1167 | } |
1175 | |
1168 | |
1176 | sub set_text { |
1169 | sub set_text { |
… | |
… | |
1182 | } |
1175 | } |
1183 | |
1176 | |
1184 | sub key_down { |
1177 | sub key_down { |
1185 | my ($self, $ev) = @_; |
1178 | my ($self, $ev) = @_; |
1186 | |
1179 | |
1187 | my $mod = $ev->key_mod; |
1180 | my $mod = $ev->{mod}; |
1188 | my $sym = $ev->key_sym; |
1181 | my $sym = $ev->{sym}; |
1189 | |
|
|
1190 | my $uni = $ev->key_unicode; |
1182 | my $uni = $ev->{unicode}; |
1191 | |
1183 | |
1192 | my $text = $self->get_text; |
1184 | my $text = $self->get_text; |
1193 | |
1185 | |
1194 | if ($sym == SDLK_BACKSPACE) { |
1186 | if ($sym == 8) { |
1195 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1187 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1196 | } elsif ($sym == SDLK_DELETE) { |
1188 | } elsif ($sym == 127) { |
1197 | substr $text, $self->{cursor}, 1, ""; |
1189 | substr $text, $self->{cursor}, 1, ""; |
1198 | } elsif ($sym == SDLK_LEFT) { |
1190 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1199 | --$self->{cursor} if $self->{cursor}; |
1191 | --$self->{cursor} if $self->{cursor}; |
1200 | } elsif ($sym == SDLK_RIGHT) { |
1192 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1201 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1193 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1202 | } elsif ($sym == SDLK_HOME) { |
1194 | } elsif ($sym == CFClient::SDLK_HOME) { |
1203 | $self->{cursor} = 0; |
1195 | $self->{cursor} = 0; |
1204 | } elsif ($sym == SDLK_END) { |
1196 | } elsif ($sym == CFClient::SDLK_END) { |
1205 | $self->{cursor} = length $text; |
1197 | $self->{cursor} = length $text; |
1206 | } elsif ($sym == SDLK_ESCAPE) { |
1198 | } elsif ($sym == 27) { |
1207 | $self->emit ('escape'); |
1199 | $self->emit ('escape'); |
1208 | } elsif ($uni) { |
1200 | } elsif ($uni) { |
1209 | substr $text, $self->{cursor}++, 0, chr $uni; |
1201 | substr $text, $self->{cursor}++, 0, chr $uni; |
1210 | } |
1202 | } |
1211 | |
1203 | |
… | |
… | |
1286 | |
1278 | |
1287 | package CFClient::UI::Entry; |
1279 | package CFClient::UI::Entry; |
1288 | |
1280 | |
1289 | our @ISA = CFClient::UI::EntryBase::; |
1281 | our @ISA = CFClient::UI::EntryBase::; |
1290 | |
1282 | |
1291 | use SDL; |
|
|
1292 | use SDL::OpenGL; |
1283 | use SDL::OpenGL; |
1293 | |
1284 | |
1294 | sub key_down { |
1285 | sub key_down { |
1295 | my ($self, $ev) = @_; |
1286 | my ($self, $ev) = @_; |
1296 | |
1287 | |
1297 | my $sym = $ev->key_sym; |
1288 | my $sym = $ev->{sym}; |
1298 | |
1289 | |
1299 | if ($sym == SDLK_RETURN) { |
1290 | if ($sym == 13) { |
1300 | $self->emit (activate => $self->get_text); |
1291 | $self->emit (activate => $self->get_text); |
1301 | $self->update; |
1292 | $self->update; |
1302 | |
1293 | |
1303 | } else { |
1294 | } else { |
1304 | $self->SUPER::key_down ($ev); |
1295 | $self->SUPER::key_down ($ev); |
… | |
… | |
1310 | |
1301 | |
1311 | package CFClient::UI::Button; |
1302 | package CFClient::UI::Button; |
1312 | |
1303 | |
1313 | our @ISA = CFClient::UI::Label::; |
1304 | our @ISA = CFClient::UI::Label::; |
1314 | |
1305 | |
1315 | use SDL; |
|
|
1316 | use SDL::OpenGL; |
1306 | use SDL::OpenGL; |
1317 | |
1307 | |
1318 | my @tex = |
1308 | my @tex = |
1319 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1309 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1320 | qw(b1_button_active.png); |
1310 | qw(b1_button_active.png); |
… | |
… | |
1374 | |
1364 | |
1375 | my @tex = |
1365 | my @tex = |
1376 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1366 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1377 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1367 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1378 | |
1368 | |
1379 | use SDL; |
|
|
1380 | use SDL::OpenGL; |
1369 | use SDL::OpenGL; |
1381 | |
1370 | |
1382 | sub new { |
1371 | sub new { |
1383 | my $class = shift; |
1372 | my $class = shift; |
1384 | |
1373 | |
… | |
… | |
1394 | |
1383 | |
1395 | sub size_request { |
1384 | sub size_request { |
1396 | my ($self) = @_; |
1385 | my ($self) = @_; |
1397 | |
1386 | |
1398 | ($self->{padding} * 2 + 6) x 2 |
1387 | ($self->{padding} * 2 + 6) x 2 |
1399 | } |
|
|
1400 | |
|
|
1401 | sub size_allocate { |
|
|
1402 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1403 | |
|
|
1404 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1405 | } |
1388 | } |
1406 | |
1389 | |
1407 | sub button_down { |
1390 | sub button_down { |
1408 | my ($self, $ev, $x, $y) = @_; |
1391 | my ($self, $ev, $x, $y) = @_; |
1409 | |
1392 | |
… | |
… | |
1520 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1503 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1521 | my $h2 = $ycut * $self->{h}; |
1504 | my $h2 = $ycut * $self->{h}; |
1522 | |
1505 | |
1523 | my $yp = 0; |
1506 | my $yp = 0; |
1524 | |
1507 | |
1525 | glBindTexture (GL_TEXTURE_2D, $t1->{name}); |
1508 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1526 | glBegin (GL_QUADS); |
1509 | glBegin GL_QUADS; |
1527 | glTexCoord (0, 0); glVertex (0 , $yp); |
1510 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1528 | glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1); |
1511 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1529 | glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1); |
1512 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1530 | glTexCoord (1, 0); glVertex (0 + $w, $yp); |
1513 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1531 | glEnd (); |
1514 | glEnd; |
1532 | |
1515 | |
1533 | $yp += $h1; |
1516 | $yp += $h1; |
1534 | |
1517 | |
1535 | glBindTexture (GL_TEXTURE_2D, $t2->{name}); |
1518 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1536 | glBegin (GL_QUADS); |
1519 | glBegin GL_QUADS; |
1537 | glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp); |
1520 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1538 | glTexCoord (0, 1); glVertex (0 , $yp + $h2); |
1521 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1539 | glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2); |
1522 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
1540 | glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp); |
1523 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1541 | glEnd (); |
1524 | glEnd; |
1542 | |
1525 | |
1543 | glDisable GL_BLEND; |
1526 | glDisable GL_BLEND; |
1544 | glDisable GL_TEXTURE_2D; |
1527 | glDisable GL_TEXTURE_2D; |
1545 | } |
1528 | } |
1546 | |
1529 | |
… | |
… | |
1568 | # TODO: calculations are off |
1551 | # TODO: calculations are off |
1569 | my $self = $class->SUPER::new ( |
1552 | my $self = $class->SUPER::new ( |
1570 | fg => [1, 1, 1], |
1553 | fg => [1, 1, 1], |
1571 | active_fg => [0, 0, 0], |
1554 | active_fg => [0, 0, 0], |
1572 | range => [0, 0, 100, 10], |
1555 | range => [0, 0, 100, 10], |
1573 | req_w => 40, |
1556 | req_w => 20, |
1574 | req_h => 13, |
1557 | req_h => 20, |
1575 | vertical => 0, |
1558 | vertical => 0, |
1576 | can_hover => 1, |
1559 | can_hover => 1, |
1577 | inner_pad => 5, |
1560 | inner_pad => 5, |
1578 | @_ |
1561 | @_ |
1579 | ); |
1562 | ); |
… | |
… | |
1689 | |
1672 | |
1690 | sub new { |
1673 | sub new { |
1691 | my $class = shift; |
1674 | my $class = shift; |
1692 | |
1675 | |
1693 | my $self = $class->SUPER::new ( |
1676 | my $self = $class->SUPER::new ( |
1694 | req_w => $::WIDTH / 6, |
|
|
1695 | req_h => $::HEIGHT / 6, |
|
|
1696 | fontsize => $::FONTSIZE, |
1677 | fontsize => 1, |
1697 | @_, |
1678 | @_, |
1698 | |
1679 | |
1699 | layout => (new CFClient::Layout), |
1680 | layout => (new CFClient::Layout), |
1700 | par => [], |
1681 | par => [], |
1701 | height => 0, |
1682 | height => 0, |
… | |
… | |
1722 | sub text_height { |
1703 | sub text_height { |
1723 | my ($self, $text) = @_; |
1704 | my ($self, $text) = @_; |
1724 | |
1705 | |
1725 | my $layout = $self->{layout}; |
1706 | my $layout = $self->{layout}; |
1726 | |
1707 | |
1727 | $layout->set_height ($self->{fontsize}); |
1708 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
1728 | $layout->set_width ($self->{w}); |
1709 | $layout->set_width ($self->{w}); |
1729 | $layout->set_text ($text); |
1710 | $layout->set_text ($text); |
1730 | |
1711 | |
1731 | ($layout->size)[1] |
1712 | ($layout->size)[1] |
1732 | } |
1713 | } |
… | |
… | |
1736 | |
1717 | |
1737 | $self->{need_reflow}++; |
1718 | $self->{need_reflow}++; |
1738 | $self->update; |
1719 | $self->update; |
1739 | } |
1720 | } |
1740 | |
1721 | |
1741 | sub size_request { |
|
|
1742 | my ($self) = @_; |
|
|
1743 | |
|
|
1744 | ($self->{req_w}, $self->{req_h}) |
|
|
1745 | } |
|
|
1746 | |
|
|
1747 | sub size_allocate { |
1722 | sub size_allocate { |
1748 | my ($self, $x, $y, $w, $h) = @_; |
1723 | my ($self, $w, $h) = @_; |
1749 | |
1724 | |
1750 | $self->SUPER::size_allocate ($x, $y, $w, $h) or return; |
1725 | $self->SUPER::size_allocate ($w, $h); |
1751 | |
1726 | |
1752 | $self->{layout}->set_height ($self->{fontsize}); |
1727 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1753 | $self->{layout}->set_width ($self->{w}); |
1728 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1754 | |
1729 | |
1755 | $self->reflow; |
1730 | $self->reflow; |
1756 | $self->update; |
|
|
1757 | } |
1731 | } |
1758 | |
1732 | |
1759 | sub add_paragraph { |
1733 | sub add_paragraph { |
1760 | my ($self, $color, $text) = @_; |
1734 | my ($self, $color, $text) = @_; |
1761 | |
1735 | |
… | |
… | |
1842 | glDisable GL_TEXTURE_2D; |
1816 | glDisable GL_TEXTURE_2D; |
1843 | } |
1817 | } |
1844 | |
1818 | |
1845 | $self->{children}[1]->draw; |
1819 | $self->{children}[1]->draw; |
1846 | |
1820 | |
1847 | } |
|
|
1848 | |
|
|
1849 | ############################################################################# |
|
|
1850 | |
|
|
1851 | package CFClient::UI::MapWidget; |
|
|
1852 | |
|
|
1853 | use strict; |
|
|
1854 | |
|
|
1855 | use List::Util qw(min max); |
|
|
1856 | |
|
|
1857 | use SDL; |
|
|
1858 | use SDL::OpenGL; |
|
|
1859 | |
|
|
1860 | our @ISA = CFClient::UI::Base::; |
|
|
1861 | |
|
|
1862 | sub new { |
|
|
1863 | my $class = shift; |
|
|
1864 | |
|
|
1865 | $class->SUPER::new ( |
|
|
1866 | z => -1, |
|
|
1867 | can_focus => 1, |
|
|
1868 | list => (glGenLists 1), |
|
|
1869 | @_ |
|
|
1870 | ) |
|
|
1871 | } |
|
|
1872 | |
|
|
1873 | sub key_down { |
|
|
1874 | print "MAPKEYDOWN\n"; |
|
|
1875 | } |
|
|
1876 | |
|
|
1877 | sub key_up { |
|
|
1878 | } |
|
|
1879 | |
|
|
1880 | sub button_down { |
|
|
1881 | my ($self, $ev, $x, $y) = @_; |
|
|
1882 | |
|
|
1883 | $self->focus_in; |
|
|
1884 | |
|
|
1885 | if ($ev->button == 2) { |
|
|
1886 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1887 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1888 | |
|
|
1889 | $self->{motion} = sub { |
|
|
1890 | my ($ev, $x, $y) = @_; |
|
|
1891 | |
|
|
1892 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1893 | |
|
|
1894 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1895 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1896 | |
|
|
1897 | $self->update; |
|
|
1898 | }; |
|
|
1899 | } |
|
|
1900 | } |
|
|
1901 | |
|
|
1902 | sub button_up { |
|
|
1903 | my ($self, $ev, $x, $y) = @_; |
|
|
1904 | |
|
|
1905 | delete $self->{motion}; |
|
|
1906 | } |
|
|
1907 | |
|
|
1908 | sub mouse_motion { |
|
|
1909 | my ($self, $ev, $x, $y) = @_; |
|
|
1910 | |
|
|
1911 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1912 | } |
|
|
1913 | |
|
|
1914 | sub size_request { |
|
|
1915 | ( |
|
|
1916 | 1 + 32 * int $::WIDTH / 32, |
|
|
1917 | 1 + 32 * int $::HEIGHT / 32, |
|
|
1918 | ) |
|
|
1919 | } |
|
|
1920 | |
|
|
1921 | sub update { |
|
|
1922 | my ($self) = @_; |
|
|
1923 | |
|
|
1924 | $self->{need_update} = 1; |
|
|
1925 | $self->SUPER::update; |
|
|
1926 | } |
|
|
1927 | |
|
|
1928 | sub draw { |
|
|
1929 | my ($self) = @_; |
|
|
1930 | |
|
|
1931 | if (delete $self->{need_update}) { |
|
|
1932 | glNewList $self->{list}, GL_COMPILE; |
|
|
1933 | |
|
|
1934 | if ($::MAP) { |
|
|
1935 | my $sw = int $::WIDTH / 32; |
|
|
1936 | my $sh = int $::HEIGHT / 32; |
|
|
1937 | |
|
|
1938 | my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
1939 | my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
1940 | |
|
|
1941 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
|
|
1942 | |
|
|
1943 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
|
|
1944 | |
|
|
1945 | if ($::CFG->{fow_enable}) { |
|
|
1946 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1947 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1948 | glConvolutionFilter2D |
|
|
1949 | GL_CONVOLUTION_2D, |
|
|
1950 | GL_ALPHA, |
|
|
1951 | 3, 3, |
|
|
1952 | GL_ALPHA, GL_FLOAT, |
|
|
1953 | pack "f*", |
|
|
1954 | 0.1, 0.1, 0.1, |
|
|
1955 | 0.1, 0.2, 0.1, |
|
|
1956 | 0.1, 0.1, 0.1, |
|
|
1957 | ; |
|
|
1958 | glEnable GL_CONVOLUTION_2D; |
|
|
1959 | } |
|
|
1960 | |
|
|
1961 | $self->{fow_texture} = new CFClient::Texture |
|
|
1962 | w => $w, |
|
|
1963 | h => $h, |
|
|
1964 | data => $data, |
|
|
1965 | internalformat => GL_ALPHA, |
|
|
1966 | format => GL_ALPHA; |
|
|
1967 | |
|
|
1968 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1969 | |
|
|
1970 | glEnable GL_BLEND; |
|
|
1971 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1972 | glEnable GL_TEXTURE_2D; |
|
|
1973 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1974 | |
|
|
1975 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1976 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1977 | |
|
|
1978 | glDisable GL_TEXTURE_2D; |
|
|
1979 | glDisable GL_BLEND; |
|
|
1980 | } |
|
|
1981 | |
|
|
1982 | # HACK BEGIN |
|
|
1983 | { |
|
|
1984 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
1985 | my ($w, $h) = (250, 250); |
|
|
1986 | |
|
|
1987 | glEnable GL_BLEND; |
|
|
1988 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1989 | glEnable GL_TEXTURE_2D; |
|
|
1990 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1991 | |
|
|
1992 | $self->{mapmap_texture} = |
|
|
1993 | new CFClient::Texture |
|
|
1994 | w => $w, |
|
|
1995 | h => $h, |
|
|
1996 | data => $::MAP->mapmap ($w, $h), |
|
|
1997 | type => GL_UNSIGNED_INT_8_8_8_8_REV; |
|
|
1998 | |
|
|
1999 | $self->{mapmap_texture}->draw_quad (100, 100); |
|
|
2000 | |
|
|
2001 | glDisable GL_TEXTURE_2D; |
|
|
2002 | glDisable GL_BLEND; |
|
|
2003 | } |
|
|
2004 | # HACK END |
|
|
2005 | } |
|
|
2006 | |
|
|
2007 | glEndList; |
|
|
2008 | } |
|
|
2009 | |
|
|
2010 | glPushMatrix; |
|
|
2011 | glCallList $self->{list}; |
|
|
2012 | glPopMatrix; |
|
|
2013 | |
|
|
2014 | if ($FOCUS != $self) { |
|
|
2015 | glColor 64/255, 64/255, 64/255; |
|
|
2016 | glLogicOp GL_AND; |
|
|
2017 | glEnable GL_COLOR_LOGIC_OP; |
|
|
2018 | glBegin GL_QUADS; |
|
|
2019 | glVertex 0, 0; |
|
|
2020 | glVertex 0, $::HEIGHT; |
|
|
2021 | glVertex $::WIDTH, $::HEIGHT; |
|
|
2022 | glVertex $::WIDTH, 0; |
|
|
2023 | glEnd; |
|
|
2024 | glDisable GL_COLOR_LOGIC_OP; |
|
|
2025 | } |
|
|
2026 | } |
|
|
2027 | |
|
|
2028 | my %DIR = ( |
|
|
2029 | SDLK_KP8, [1, "north"], |
|
|
2030 | SDLK_KP9, [2, "northeast"], |
|
|
2031 | SDLK_KP6, [3, "east"], |
|
|
2032 | SDLK_KP3, [4, "southeast"], |
|
|
2033 | SDLK_KP2, [5, "south"], |
|
|
2034 | SDLK_KP1, [6, "southwest"], |
|
|
2035 | SDLK_KP4, [7, "west"], |
|
|
2036 | SDLK_KP7, [8, "northwest"], |
|
|
2037 | |
|
|
2038 | SDLK_UP, [1, "north"], |
|
|
2039 | SDLK_RIGHT, [3, "east"], |
|
|
2040 | SDLK_DOWN, [5, "south"], |
|
|
2041 | SDLK_LEFT, [7, "west"], |
|
|
2042 | ); |
|
|
2043 | |
|
|
2044 | sub key_down { |
|
|
2045 | my ($self, $ev) = @_; |
|
|
2046 | |
|
|
2047 | my $mod = $ev->key_mod; |
|
|
2048 | my $sym = $ev->key_sym; |
|
|
2049 | |
|
|
2050 | if ($sym == SDLK_KP5) { |
|
|
2051 | $::CONN->user_send ("stay fire"); |
|
|
2052 | } elsif ($sym == SDLK_a) { |
|
|
2053 | $::CONN->user_send ("apply"); |
|
|
2054 | } elsif ($sym == SDLK_QUOTE) { |
|
|
2055 | $self->emit ('activate_console'); |
|
|
2056 | } elsif ($sym == SDLK_SLASH) { |
|
|
2057 | $self->emit ('activate_console' => '/'); |
|
|
2058 | } elsif (exists $DIR{$sym}) { |
|
|
2059 | if ($mod & KMOD_SHIFT) { |
|
|
2060 | $self->{shft}++; |
|
|
2061 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
2062 | } elsif ($mod & KMOD_CTRL) { |
|
|
2063 | $self->{ctrl}++; |
|
|
2064 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
2065 | } else { |
|
|
2066 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
2067 | } |
|
|
2068 | } |
|
|
2069 | } |
|
|
2070 | |
|
|
2071 | sub key_up { |
|
|
2072 | my ($self, $ev) = @_; |
|
|
2073 | |
|
|
2074 | my $mod = $ev->key_mod; |
|
|
2075 | my $sym = $ev->key_sym; |
|
|
2076 | |
|
|
2077 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
|
|
2078 | $::CONN->user_send ("fire_stop"); |
|
|
2079 | } |
|
|
2080 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
2081 | $::CONN->user_send ("run_stop"); |
|
|
2082 | } |
|
|
2083 | } |
1821 | } |
2084 | |
1822 | |
2085 | ############################################################################# |
1823 | ############################################################################# |
2086 | |
1824 | |
2087 | package CFClient::UI::Animator; |
1825 | package CFClient::UI::Animator; |
… | |
… | |
2172 | use SDL::OpenGL; |
1910 | use SDL::OpenGL; |
2173 | |
1911 | |
2174 | sub check_size { |
1912 | sub check_size { |
2175 | my ($self) = @_; |
1913 | my ($self) = @_; |
2176 | |
1914 | |
2177 | $self->size_allocate (0, 0, $::WITH, $::HEIGHT); |
1915 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2178 | } |
1916 | } |
2179 | |
1917 | |
2180 | sub size_request { |
1918 | sub size_request { |
2181 | ($::WIDTH, $::HEIGHT) |
1919 | ($::WIDTH, $::HEIGHT) |
2182 | } |
1920 | } |
2183 | |
1921 | |
2184 | sub size_allocate { |
1922 | sub configure { |
2185 | my ($self, $x, $y, $w, $h) = @_; |
1923 | my ($self, $x, $y, $w, $h) = @_; |
2186 | |
1924 | |
2187 | $self->_size_allocate ($x, $y, $w, $h); |
1925 | $self->SUPER::configure ($x, $y, $w, $h); |
2188 | |
1926 | |
2189 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
1927 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
2190 | for @{$self->{children}}; |
1928 | for @{$self->{children}}; |
2191 | } |
1929 | } |
2192 | |
1930 | |
2193 | sub _topleft { |
1931 | sub _topleft { |
2194 | my ($self, $x, $y) = @_; |
1932 | my ($self, $x, $y) = @_; |
… | |
… | |
2202 | $self->check_size; |
1940 | $self->check_size; |
2203 | ::refresh (); |
1941 | ::refresh (); |
2204 | } |
1942 | } |
2205 | |
1943 | |
2206 | sub add { |
1944 | sub add { |
2207 | my ($self, $widget) = @_; |
1945 | my ($self, $child) = @_; |
2208 | |
1946 | |
2209 | $self->SUPER::add ($widget); |
1947 | $self->SUPER::add ($child); |
2210 | |
|
|
2211 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
|
|
2212 | } |
1948 | } |
2213 | |
1949 | |
2214 | sub on_refresh { |
1950 | sub on_refresh { |
2215 | my ($self, $id, $cb) = @_; |
1951 | my ($self, $id, $cb) = @_; |
2216 | |
1952 | |