… | |
… | |
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) = @_; |
117 | |
131 | |
118 | $self->{x} = int $x; |
132 | $self->{x} = int $x; |
119 | $self->{y} = int $y; |
133 | $self->{y} = int $y; |
… | |
… | |
135 | my ($self, $x, $y, $w, $h) = @_; |
149 | my ($self, $x, $y, $w, $h) = @_; |
136 | |
150 | |
137 | $self->{x} = $x; |
151 | $self->{x} = $x; |
138 | $self->{y} = $y; |
152 | $self->{y} = $y; |
139 | |
153 | |
|
|
154 | if ($self->{aspect}) { |
|
|
155 | $w = List::Util::min $w, int $h * $self->{aspect}; |
|
|
156 | $h = List::Util::min $h, int $w / $self->{aspect}; |
|
|
157 | } |
|
|
158 | |
140 | return unless $self->{w} != $w || $self->{h} != $h; |
159 | return unless $self->{w} != $w || $self->{h} != $h; |
141 | |
160 | |
142 | $self->{w} = $w; |
161 | $self->{w} = $w; |
143 | $self->{h} = $h; |
162 | $self->{h} = $h; |
144 | |
163 | |
145 | $self->size_allocate ($w, $h); |
164 | $self->size_allocate ($w, $h); |
|
|
165 | $self->update; |
146 | } |
166 | } |
147 | |
167 | |
148 | sub size_allocate { |
168 | sub size_allocate { |
149 | # nothing to be done |
169 | # nothing to be done |
150 | } |
170 | } |
… | |
… | |
272 | $self->{req_w} = $w; |
292 | $self->{req_w} = $w; |
273 | $self->{req_h} = $h; |
293 | $self->{req_h} = $h; |
274 | |
294 | |
275 | $self->{parent}->check_size |
295 | $self->{parent}->check_size |
276 | if $self->{parent}; |
296 | if $self->{parent}; |
277 | |
|
|
278 | $self->size_allocate ($w, $h); |
|
|
279 | $self->update; |
|
|
280 | } |
297 | } |
281 | } |
298 | } |
282 | |
299 | |
283 | sub update { |
300 | sub update { |
284 | my ($self) = @_; |
301 | my ($self) = @_; |
… | |
… | |
312 | package CFClient::UI::DrawBG; |
329 | package CFClient::UI::DrawBG; |
313 | |
330 | |
314 | our @ISA = CFClient::UI::Base::; |
331 | our @ISA = CFClient::UI::Base::; |
315 | |
332 | |
316 | use strict; |
333 | use strict; |
317 | use SDL::OpenGL; |
334 | use CFClient::OpenGL; |
318 | |
335 | |
319 | sub new { |
336 | sub new { |
320 | my $class = shift; |
337 | my $class = shift; |
321 | |
338 | |
322 | # range [value, low, high, page] |
339 | # range [value, low, high, page] |
… | |
… | |
386 | $self->{children} = [ |
403 | $self->{children} = [ |
387 | sort { $a->{z} <=> $b->{z} } |
404 | sort { $a->{z} <=> $b->{z} } |
388 | @{$self->{children}}, $child |
405 | @{$self->{children}}, $child |
389 | ]; |
406 | ]; |
390 | |
407 | |
391 | $self->{w} = $self->{h} = -1; |
|
|
392 | |
|
|
393 | $child->check_size; |
408 | $child->check_size; |
394 | } |
409 | } |
395 | |
410 | |
396 | sub remove { |
411 | sub remove { |
397 | my ($self, $widget) = @_; |
412 | my ($self, $child) = @_; |
398 | |
413 | |
|
|
414 | delete $child->{parent}; |
|
|
415 | |
399 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
416 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
400 | |
417 | |
401 | $self->check_size; |
418 | $self->check_size; |
402 | } |
419 | } |
403 | |
420 | |
404 | sub find_widget { |
421 | sub find_widget { |
… | |
… | |
436 | |
453 | |
437 | $class->SUPER::new (children => [$child], %arg) |
454 | $class->SUPER::new (children => [$child], %arg) |
438 | } |
455 | } |
439 | |
456 | |
440 | sub add { |
457 | sub add { |
441 | my ($self, $widget) = @_; |
458 | my ($self, $child) = @_; |
442 | |
459 | |
443 | $self->{children} = []; |
460 | $self->{children} = []; |
444 | |
461 | |
445 | $self->SUPER::add ($widget); |
462 | $self->SUPER::add ($child); |
446 | } |
463 | } |
447 | |
464 | |
448 | sub remove { |
465 | sub remove { |
449 | my ($self, $widget) = @_; |
466 | my ($self, $widget) = @_; |
450 | |
467 | |
… | |
… | |
470 | |
487 | |
471 | package CFClient::UI::Window; |
488 | package CFClient::UI::Window; |
472 | |
489 | |
473 | our @ISA = CFClient::UI::Bin::; |
490 | our @ISA = CFClient::UI::Bin::; |
474 | |
491 | |
475 | use SDL::OpenGL; |
492 | use CFClient::OpenGL; |
476 | |
493 | |
477 | sub new { |
494 | sub new { |
478 | my ($class, %arg) = @_; |
495 | my ($class, %arg) = @_; |
479 | |
496 | |
480 | my $self = $class->SUPER::new (%arg); |
497 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
553 | |
570 | |
554 | package CFClient::UI::Frame; |
571 | package CFClient::UI::Frame; |
555 | |
572 | |
556 | our @ISA = CFClient::UI::Bin::; |
573 | our @ISA = CFClient::UI::Bin::; |
557 | |
574 | |
558 | use SDL::OpenGL; |
575 | use CFClient::OpenGL; |
559 | |
576 | |
560 | sub size_request { |
577 | sub size_request { |
561 | my ($self) = @_; |
578 | my ($self) = @_; |
562 | my $chld = $self->child |
579 | my $chld = $self->child |
563 | or return (0, 0); |
580 | or return (0, 0); |
… | |
… | |
595 | |
612 | |
596 | package CFClient::UI::FancyFrame; |
613 | package CFClient::UI::FancyFrame; |
597 | |
614 | |
598 | our @ISA = CFClient::UI::Bin::; |
615 | our @ISA = CFClient::UI::Bin::; |
599 | |
616 | |
600 | use SDL::OpenGL; |
617 | use CFClient::OpenGL; |
601 | |
618 | |
602 | my @tex = |
619 | my @tex = |
603 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
620 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
604 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
621 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
605 | |
622 | |
… | |
… | |
609 | # TODO: user_x, user_y, overwrite moveto? |
626 | # TODO: user_x, user_y, overwrite moveto? |
610 | |
627 | |
611 | $class->SUPER::new ( |
628 | $class->SUPER::new ( |
612 | bg => [1, 1, 1, 1], |
629 | bg => [1, 1, 1, 1], |
613 | border_bg => [1, 1, 1, 1], |
630 | border_bg => [1, 1, 1, 1], |
614 | border => int $::FONTSIZE * 0.8, |
631 | border => 0.8, |
615 | @_ |
632 | @_ |
616 | ) |
633 | ) |
617 | } |
634 | } |
618 | |
635 | |
|
|
636 | sub border { |
|
|
637 | int $_[0]{border} * $::FONTSIZE |
|
|
638 | } |
|
|
639 | |
619 | sub size_request { |
640 | sub size_request { |
620 | my ($self) = @_; |
641 | my ($self) = @_; |
621 | |
642 | |
622 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
643 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
623 | |
644 | |
624 | my ($w, $h) = $self->SUPER::size_request; |
645 | my ($w, $h) = $self->SUPER::size_request; |
625 | |
646 | |
626 | ( |
647 | ( |
627 | $w + $self->{border} * 2, |
648 | $w + $self->border * 2, |
628 | $h + $self->{border} * 2, |
649 | $h + $self->border * 2, |
629 | ) |
650 | ) |
630 | } |
651 | } |
631 | |
652 | |
632 | sub size_allocate { |
653 | sub size_allocate { |
633 | my ($self, $w, $h) = @_; |
654 | my ($self, $w, $h) = @_; |
634 | |
655 | |
635 | $h -= List::Util::max 0, $self->{border} * 2; |
656 | $h -= List::Util::max 0, $self->border * 2; |
636 | $w -= List::Util::max 0, $self->{border} * 2; |
657 | $w -= List::Util::max 0, $self->border * 2; |
637 | |
658 | |
638 | $self->child->configure ($self->{border}, $self->{border}, $w, $h); |
659 | $self->child->configure ($self->border, $self->border, $w, $h); |
639 | } |
660 | } |
640 | |
661 | |
641 | sub button_down { |
662 | sub button_down { |
642 | my ($self, $ev, $x, $y) = @_; |
663 | my ($self, $ev, $x, $y) = @_; |
643 | |
664 | |
|
|
665 | my $border = $self->border; |
|
|
666 | |
644 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
667 | if ($x < $self->{w} && $x >= $self->{w} - $border |
645 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
668 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
646 | |
669 | |
647 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
670 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
648 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
671 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
649 | |
672 | |
650 | $self->{motion} = sub { |
673 | $self->{motion} = sub { |
651 | my ($ev, $x, $y) = @_; |
674 | my ($ev, $x, $y) = @_; |
652 | |
675 | |
653 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
676 | ($x, $y) = ($ev->{x}, $ev->{y}); |
654 | |
677 | |
655 | $self->{user_w} = $bw + $x - $ox; |
678 | $self->{user_w} = $bw + $x - $ox; |
656 | $self->{user_h} = $bh + $y - $oy; |
679 | $self->{user_h} = $bh + $y - $oy; |
657 | $self->check_size; |
680 | $self->check_size; |
658 | }; |
681 | }; |
659 | |
682 | |
660 | } elsif ($x >= 0 && $x < $self->{w} |
683 | } elsif ($x >= 0 && $x < $self->{w} |
661 | && $y >= 0 && $y < $self->{border}) { |
684 | && $y >= 0 && $y < $border) { |
662 | |
685 | |
663 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
686 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
664 | my ($bx, $by) = ($self->{x}, $self->{y}); |
687 | my ($bx, $by) = ($self->{x}, $self->{y}); |
665 | |
688 | |
666 | $self->{motion} = sub { |
689 | $self->{motion} = sub { |
667 | my ($ev, $x, $y) = @_; |
690 | my ($ev, $x, $y) = @_; |
668 | |
691 | |
669 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
692 | ($x, $y) = ($ev->{x}, $ev->{y}); |
670 | |
693 | |
671 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
694 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
672 | $self->update; |
695 | $self->update; |
673 | }; |
696 | }; |
674 | } |
697 | } |
… | |
… | |
695 | glEnable GL_BLEND; |
718 | glEnable GL_BLEND; |
696 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
719 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
697 | glEnable GL_TEXTURE_2D; |
720 | glEnable GL_TEXTURE_2D; |
698 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
721 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
699 | |
722 | |
|
|
723 | my $border = $self->border; |
|
|
724 | |
700 | glColor @{ $self->{border_bg} }; |
725 | glColor @{ $self->{border_bg} }; |
701 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
726 | $tex[1]->draw_quad (0, 0, $w, $border); |
702 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
727 | $tex[3]->draw_quad (0, $border, $border, $ch); |
703 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
728 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
704 | $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); |
729 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
705 | |
730 | |
706 | my $bg = $tex[0]; |
731 | my $bg = $tex[0]; |
707 | |
732 | |
708 | # TODO: repeat texture not scale |
733 | # TODO: repeat texture not scale |
709 | my $rep_x = $cw / $bg->{w}; |
734 | my $rep_x = $cw / $bg->{w}; |
… | |
… | |
712 | glColor @{ $self->{bg} }; |
737 | glColor @{ $self->{bg} }; |
713 | |
738 | |
714 | $bg->{s} = $rep_x; |
739 | $bg->{s} = $rep_x; |
715 | $bg->{t} = $rep_y; |
740 | $bg->{t} = $rep_y; |
716 | $bg->{wrap_mode} = 1; |
741 | $bg->{wrap_mode} = 1; |
717 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
742 | $bg->draw_quad ($border, $border, $cw, $ch); |
718 | |
743 | |
719 | glDisable GL_TEXTURE_2D; |
744 | glDisable GL_TEXTURE_2D; |
720 | glDisable GL_BLEND; |
745 | glDisable GL_BLEND; |
721 | |
746 | |
722 | $self->child->draw; |
747 | $self->child->draw; |
… | |
… | |
728 | |
753 | |
729 | our @ISA = CFClient::UI::Base::; |
754 | our @ISA = CFClient::UI::Base::; |
730 | |
755 | |
731 | use List::Util qw(max sum); |
756 | use List::Util qw(max sum); |
732 | |
757 | |
733 | use SDL::OpenGL; |
758 | use CFClient::OpenGL; |
734 | |
759 | |
735 | sub new { |
760 | sub new { |
736 | my $class = shift; |
761 | my $class = shift; |
737 | |
762 | |
738 | $class->SUPER::new ( |
763 | $class->SUPER::new ( |
… | |
… | |
744 | sub add { |
769 | sub add { |
745 | my ($self, $x, $y, $child) = @_; |
770 | my ($self, $x, $y, $child) = @_; |
746 | |
771 | |
747 | $child->set_parent ($self); |
772 | $child->set_parent ($self); |
748 | $self->{children}[$y][$x] = $child; |
773 | $self->{children}[$y][$x] = $child; |
749 | |
|
|
750 | $self->{w} = $self->{h} = -1; |
|
|
751 | |
774 | |
752 | $child->check_size; |
775 | $child->check_size; |
753 | } |
776 | } |
754 | |
777 | |
755 | # TODO: move to container class maybe? send childs a signal on removal? |
778 | # TODO: move to container class maybe? send childs a signal on removal? |
… | |
… | |
981 | |
1004 | |
982 | package CFClient::UI::Label; |
1005 | package CFClient::UI::Label; |
983 | |
1006 | |
984 | our @ISA = CFClient::UI::Base::; |
1007 | our @ISA = CFClient::UI::Base::; |
985 | |
1008 | |
986 | use SDL::OpenGL; |
1009 | use CFClient::OpenGL; |
987 | |
1010 | |
988 | sub new { |
1011 | sub new { |
989 | my ($class, %arg) = @_; |
1012 | my ($class, %arg) = @_; |
990 | |
1013 | |
991 | my $self = $class->SUPER::new ( |
1014 | my $self = $class->SUPER::new ( |
992 | fg => [1, 1, 1], |
1015 | fg => [1, 1, 1], |
993 | fontsize => $::FONTSIZE, |
1016 | fontsize => 1, |
994 | text => "", |
1017 | text => "", |
995 | align => -1, |
1018 | align => -1, |
996 | valign => -1, |
1019 | valign => -1, |
997 | padding => 2, |
1020 | padding => 2, |
998 | layout => new CFClient::Layout, |
1021 | layout => new CFClient::Layout, |
… | |
… | |
1037 | |
1060 | |
1038 | sub size_request { |
1061 | sub size_request { |
1039 | my ($self) = @_; |
1062 | my ($self) = @_; |
1040 | |
1063 | |
1041 | $self->{layout}->set_width; |
1064 | $self->{layout}->set_width; |
1042 | $self->{layout}->set_height ($self->{fontsize}); |
1065 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1043 | |
1066 | |
1044 | my ($w, $h) = $self->{layout}->size; |
1067 | my ($w, $h) = $self->{layout}->size; |
1045 | |
1068 | |
1046 | ( |
1069 | ( |
1047 | $w + $self->{padding} * 2, |
1070 | $w + $self->{padding} * 2, |
… | |
… | |
1053 | my ($self, $w, $h) = @_; |
1076 | my ($self, $w, $h) = @_; |
1054 | |
1077 | |
1055 | delete $self->{texture}; |
1078 | delete $self->{texture}; |
1056 | } |
1079 | } |
1057 | |
1080 | |
1058 | sub update { |
|
|
1059 | my ($self) = @_; |
|
|
1060 | |
|
|
1061 | delete $self->{texture}; |
|
|
1062 | $self->SUPER::update; |
|
|
1063 | } |
|
|
1064 | |
|
|
1065 | sub _draw { |
1081 | sub _draw { |
1066 | my ($self) = @_; |
1082 | my ($self) = @_; |
1067 | |
1083 | |
1068 | my $tex = $self->{texture} ||= do { |
1084 | my $tex = $self->{texture} ||= do { |
1069 | $self->{layout}->set_width ($self->{w}); |
1085 | $self->{layout}->set_width ($self->{w}); |
1070 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); |
1086 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1071 | new_from_layout CFClient::Texture $self->{layout} |
1087 | new_from_layout CFClient::Texture $self->{layout} |
1072 | }; |
1088 | }; |
1073 | |
1089 | |
1074 | glEnable GL_BLEND; |
1090 | glEnable GL_BLEND; |
1075 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1091 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
1100 | |
1116 | |
1101 | package CFClient::UI::EntryBase; |
1117 | package CFClient::UI::EntryBase; |
1102 | |
1118 | |
1103 | our @ISA = CFClient::UI::Label::; |
1119 | our @ISA = CFClient::UI::Label::; |
1104 | |
1120 | |
1105 | use SDL; |
1121 | use CFClient::OpenGL; |
1106 | use SDL::OpenGL; |
|
|
1107 | |
1122 | |
1108 | sub new { |
1123 | sub new { |
1109 | my $class = shift; |
1124 | my $class = shift; |
1110 | |
1125 | |
1111 | $class->SUPER::new ( |
1126 | $class->SUPER::new ( |
… | |
… | |
1125 | |
1140 | |
1126 | delete $self->{cur_h}; |
1141 | delete $self->{cur_h}; |
1127 | |
1142 | |
1128 | return if $self->{text} eq $text; |
1143 | return if $self->{text} eq $text; |
1129 | |
1144 | |
|
|
1145 | delete $self->{texture}; |
|
|
1146 | |
1130 | $self->{last_activity} = $::NOW; |
1147 | $self->{last_activity} = $::NOW; |
1131 | $self->{text} = $text; |
1148 | $self->{text} = $text; |
1132 | |
1149 | |
1133 | $text =~ s/./*/g if $self->{hidden}; |
1150 | $text =~ s/./*/g if $self->{hidden}; |
1134 | $self->{layout}->set_text ("$text "); |
1151 | $self->{layout}->set_text ("$text "); |
… | |
… | |
1163 | } |
1180 | } |
1164 | |
1181 | |
1165 | sub key_down { |
1182 | sub key_down { |
1166 | my ($self, $ev) = @_; |
1183 | my ($self, $ev) = @_; |
1167 | |
1184 | |
1168 | my $mod = $ev->key_mod; |
1185 | my $mod = $ev->{mod}; |
1169 | my $sym = $ev->key_sym; |
1186 | my $sym = $ev->{sym}; |
1170 | |
|
|
1171 | my $uni = $ev->key_unicode; |
1187 | my $uni = $ev->{unicode}; |
1172 | |
1188 | |
1173 | my $text = $self->get_text; |
1189 | my $text = $self->get_text; |
1174 | |
1190 | |
1175 | if ($sym == SDLK_BACKSPACE) { |
1191 | if ($sym == 8) { |
1176 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1192 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1177 | } elsif ($sym == SDLK_DELETE) { |
1193 | } elsif ($sym == 127) { |
1178 | substr $text, $self->{cursor}, 1, ""; |
1194 | substr $text, $self->{cursor}, 1, ""; |
1179 | } elsif ($sym == SDLK_LEFT) { |
1195 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1180 | --$self->{cursor} if $self->{cursor}; |
1196 | --$self->{cursor} if $self->{cursor}; |
1181 | } elsif ($sym == SDLK_RIGHT) { |
1197 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1182 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1198 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1183 | } elsif ($sym == SDLK_HOME) { |
1199 | } elsif ($sym == CFClient::SDLK_HOME) { |
1184 | $self->{cursor} = 0; |
1200 | $self->{cursor} = 0; |
1185 | } elsif ($sym == SDLK_END) { |
1201 | } elsif ($sym == CFClient::SDLK_END) { |
1186 | $self->{cursor} = length $text; |
1202 | $self->{cursor} = length $text; |
1187 | } elsif ($sym == SDLK_ESCAPE) { |
1203 | } elsif ($sym == 27) { |
1188 | $self->emit ('escape'); |
1204 | $self->emit ('escape'); |
1189 | } elsif ($uni) { |
1205 | } elsif ($uni) { |
1190 | substr $text, $self->{cursor}++, 0, chr $uni; |
1206 | substr $text, $self->{cursor}++, 0, chr $uni; |
1191 | } |
1207 | } |
1192 | |
1208 | |
… | |
… | |
1267 | |
1283 | |
1268 | package CFClient::UI::Entry; |
1284 | package CFClient::UI::Entry; |
1269 | |
1285 | |
1270 | our @ISA = CFClient::UI::EntryBase::; |
1286 | our @ISA = CFClient::UI::EntryBase::; |
1271 | |
1287 | |
1272 | use SDL; |
1288 | use CFClient::OpenGL; |
1273 | use SDL::OpenGL; |
|
|
1274 | |
1289 | |
1275 | sub key_down { |
1290 | sub key_down { |
1276 | my ($self, $ev) = @_; |
1291 | my ($self, $ev) = @_; |
1277 | |
1292 | |
1278 | my $sym = $ev->key_sym; |
1293 | my $sym = $ev->{sym}; |
1279 | |
1294 | |
1280 | if ($sym == SDLK_RETURN) { |
1295 | if ($sym == 13) { |
1281 | $self->emit (activate => $self->get_text); |
1296 | $self->emit (activate => $self->get_text); |
1282 | $self->update; |
1297 | $self->update; |
1283 | |
1298 | |
1284 | } else { |
1299 | } else { |
1285 | $self->SUPER::key_down ($ev); |
1300 | $self->SUPER::key_down ($ev); |
… | |
… | |
1291 | |
1306 | |
1292 | package CFClient::UI::Button; |
1307 | package CFClient::UI::Button; |
1293 | |
1308 | |
1294 | our @ISA = CFClient::UI::Label::; |
1309 | our @ISA = CFClient::UI::Label::; |
1295 | |
1310 | |
1296 | use SDL; |
1311 | use CFClient::OpenGL; |
1297 | use SDL::OpenGL; |
|
|
1298 | |
1312 | |
1299 | my @tex = |
1313 | my @tex = |
1300 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1314 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1301 | qw(b1_button_active.png); |
1315 | qw(b1_button_active.png); |
1302 | |
1316 | |
… | |
… | |
1355 | |
1369 | |
1356 | my @tex = |
1370 | my @tex = |
1357 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1371 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1358 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1372 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1359 | |
1373 | |
1360 | use SDL; |
1374 | use CFClient::OpenGL; |
1361 | use SDL::OpenGL; |
|
|
1362 | |
1375 | |
1363 | sub new { |
1376 | sub new { |
1364 | my $class = shift; |
1377 | my $class = shift; |
1365 | |
1378 | |
1366 | $class->SUPER::new ( |
1379 | $class->SUPER::new ( |
… | |
… | |
1416 | |
1429 | |
1417 | package CFClient::UI::VGauge; |
1430 | package CFClient::UI::VGauge; |
1418 | |
1431 | |
1419 | our @ISA = CFClient::UI::Base::; |
1432 | our @ISA = CFClient::UI::Base::; |
1420 | |
1433 | |
1421 | use SDL::OpenGL; |
1434 | use CFClient::OpenGL; |
1422 | |
1435 | |
1423 | my %tex = ( |
1436 | my %tex = ( |
1424 | food => [ |
1437 | food => [ |
1425 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1438 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1426 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
1439 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
… | |
… | |
1441 | |
1454 | |
1442 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1455 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1443 | sub new { |
1456 | sub new { |
1444 | my $class = shift; |
1457 | my $class = shift; |
1445 | |
1458 | |
1446 | my $self = $class->SUPER::new (gauge => 'food', @_); |
1459 | my $self = $class->SUPER::new ( |
|
|
1460 | gauge => 'food', |
|
|
1461 | @_ |
|
|
1462 | ); |
|
|
1463 | |
|
|
1464 | $self->{aspect} = $tex{$self->{gauge}}[0]{w} / $tex{$self->{gauge}}[0]{h}; |
1447 | |
1465 | |
1448 | $self |
1466 | $self |
1449 | } |
1467 | } |
1450 | |
1468 | |
1451 | sub size_request { |
1469 | sub size_request { |
… | |
… | |
1523 | |
1541 | |
1524 | package CFClient::UI::Slider; |
1542 | package CFClient::UI::Slider; |
1525 | |
1543 | |
1526 | use strict; |
1544 | use strict; |
1527 | |
1545 | |
1528 | use SDL::OpenGL; |
1546 | use CFClient::OpenGL; |
1529 | |
1547 | |
1530 | our @ISA = CFClient::UI::DrawBG::; |
1548 | our @ISA = CFClient::UI::DrawBG::; |
1531 | |
1549 | |
1532 | my @tex = |
1550 | my @tex = |
1533 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1551 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1543 | # TODO: calculations are off |
1561 | # TODO: calculations are off |
1544 | my $self = $class->SUPER::new ( |
1562 | my $self = $class->SUPER::new ( |
1545 | fg => [1, 1, 1], |
1563 | fg => [1, 1, 1], |
1546 | active_fg => [0, 0, 0], |
1564 | active_fg => [0, 0, 0], |
1547 | range => [0, 0, 100, 10], |
1565 | range => [0, 0, 100, 10], |
1548 | req_w => 40, |
1566 | req_w => 20, |
1549 | req_h => 13, |
1567 | req_h => 20, |
1550 | vertical => 0, |
1568 | vertical => 0, |
1551 | can_hover => 1, |
1569 | can_hover => 1, |
1552 | inner_pad => 5, |
1570 | inner_pad => 5, |
1553 | @_ |
1571 | @_ |
1554 | ); |
1572 | ); |
… | |
… | |
1658 | |
1676 | |
1659 | package CFClient::UI::TextView; |
1677 | package CFClient::UI::TextView; |
1660 | |
1678 | |
1661 | our @ISA = CFClient::UI::HBox::; |
1679 | our @ISA = CFClient::UI::HBox::; |
1662 | |
1680 | |
1663 | use SDL::OpenGL; |
1681 | use CFClient::OpenGL; |
1664 | |
1682 | |
1665 | sub new { |
1683 | sub new { |
1666 | my $class = shift; |
1684 | my $class = shift; |
1667 | |
1685 | |
1668 | my $self = $class->SUPER::new ( |
1686 | my $self = $class->SUPER::new ( |
1669 | req_w => $::WIDTH / 6, |
|
|
1670 | req_h => $::HEIGHT / 6, |
|
|
1671 | fontsize => $::FONTSIZE, |
1687 | fontsize => 1, |
1672 | @_, |
1688 | @_, |
1673 | |
1689 | |
1674 | layout => (new CFClient::Layout), |
1690 | layout => (new CFClient::Layout), |
1675 | par => [], |
1691 | par => [], |
1676 | height => 0, |
1692 | height => 0, |
… | |
… | |
1697 | sub text_height { |
1713 | sub text_height { |
1698 | my ($self, $text) = @_; |
1714 | my ($self, $text) = @_; |
1699 | |
1715 | |
1700 | my $layout = $self->{layout}; |
1716 | my $layout = $self->{layout}; |
1701 | |
1717 | |
1702 | $layout->set_height ($self->{fontsize}); |
1718 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
1703 | $layout->set_width ($self->{w}); |
1719 | $layout->set_width ($self->{w}); |
1704 | $layout->set_text ($text); |
1720 | $layout->set_text ($text); |
1705 | |
1721 | |
1706 | ($layout->size)[1] |
1722 | ($layout->size)[1] |
1707 | } |
1723 | } |
… | |
… | |
1711 | |
1727 | |
1712 | $self->{need_reflow}++; |
1728 | $self->{need_reflow}++; |
1713 | $self->update; |
1729 | $self->update; |
1714 | } |
1730 | } |
1715 | |
1731 | |
1716 | sub size_request { |
|
|
1717 | my ($self) = @_; |
|
|
1718 | |
|
|
1719 | ($self->{req_w}, $self->{req_h}) |
|
|
1720 | } |
|
|
1721 | |
|
|
1722 | sub size_allocate { |
1732 | sub size_allocate { |
1723 | my ($self, $w, $h) = @_; |
1733 | my ($self, $w, $h) = @_; |
1724 | |
1734 | |
|
|
1735 | $self->SUPER::size_allocate ($w, $h); |
|
|
1736 | |
1725 | $self->{layout}->set_height ($self->{fontsize}); |
1737 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1726 | $self->{layout}->set_width ($self->{w}); |
1738 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1727 | |
1739 | |
1728 | $self->reflow; |
1740 | $self->reflow; |
1729 | $self->update; |
|
|
1730 | } |
1741 | } |
1731 | |
1742 | |
1732 | sub add_paragraph { |
1743 | sub add_paragraph { |
1733 | my ($self, $color, $text) = @_; |
1744 | my ($self, $color, $text) = @_; |
1734 | |
1745 | |
… | |
… | |
1819 | |
1830 | |
1820 | } |
1831 | } |
1821 | |
1832 | |
1822 | ############################################################################# |
1833 | ############################################################################# |
1823 | |
1834 | |
1824 | package CFClient::UI::MapWidget; |
|
|
1825 | |
|
|
1826 | use strict; |
|
|
1827 | |
|
|
1828 | use List::Util qw(min max); |
|
|
1829 | |
|
|
1830 | use SDL; |
|
|
1831 | use SDL::OpenGL; |
|
|
1832 | |
|
|
1833 | our @ISA = CFClient::UI::Base::; |
|
|
1834 | |
|
|
1835 | sub new { |
|
|
1836 | my $class = shift; |
|
|
1837 | |
|
|
1838 | $class->SUPER::new ( |
|
|
1839 | z => -1, |
|
|
1840 | can_focus => 1, |
|
|
1841 | list => (glGenLists 1), |
|
|
1842 | @_ |
|
|
1843 | ) |
|
|
1844 | } |
|
|
1845 | |
|
|
1846 | sub key_down { |
|
|
1847 | print "MAPKEYDOWN\n"; |
|
|
1848 | } |
|
|
1849 | |
|
|
1850 | sub key_up { |
|
|
1851 | } |
|
|
1852 | |
|
|
1853 | sub button_down { |
|
|
1854 | my ($self, $ev, $x, $y) = @_; |
|
|
1855 | |
|
|
1856 | $self->focus_in; |
|
|
1857 | |
|
|
1858 | if ($ev->button == 2) { |
|
|
1859 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1860 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1861 | |
|
|
1862 | $self->{motion} = sub { |
|
|
1863 | my ($ev, $x, $y) = @_; |
|
|
1864 | |
|
|
1865 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1866 | |
|
|
1867 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1868 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1869 | |
|
|
1870 | $self->update; |
|
|
1871 | }; |
|
|
1872 | } |
|
|
1873 | } |
|
|
1874 | |
|
|
1875 | sub button_up { |
|
|
1876 | my ($self, $ev, $x, $y) = @_; |
|
|
1877 | |
|
|
1878 | delete $self->{motion}; |
|
|
1879 | } |
|
|
1880 | |
|
|
1881 | sub mouse_motion { |
|
|
1882 | my ($self, $ev, $x, $y) = @_; |
|
|
1883 | |
|
|
1884 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1885 | } |
|
|
1886 | |
|
|
1887 | sub size_request { |
|
|
1888 | ( |
|
|
1889 | 1 + 32 * int $::WIDTH / 32, |
|
|
1890 | 1 + 32 * int $::HEIGHT / 32, |
|
|
1891 | ) |
|
|
1892 | } |
|
|
1893 | |
|
|
1894 | sub update { |
|
|
1895 | my ($self) = @_; |
|
|
1896 | |
|
|
1897 | $self->{need_update} = 1; |
|
|
1898 | $self->SUPER::update; |
|
|
1899 | } |
|
|
1900 | |
|
|
1901 | sub draw { |
|
|
1902 | my ($self) = @_; |
|
|
1903 | |
|
|
1904 | if (delete $self->{need_update}) { |
|
|
1905 | glNewList $self->{list}, GL_COMPILE; |
|
|
1906 | |
|
|
1907 | if ($::MAP) { |
|
|
1908 | my $sw = int $::WIDTH / 32; |
|
|
1909 | my $sh = int $::HEIGHT / 32; |
|
|
1910 | |
|
|
1911 | my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
1912 | my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
1913 | |
|
|
1914 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
|
|
1915 | |
|
|
1916 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
|
|
1917 | |
|
|
1918 | if ($::CFG->{fow_enable}) { |
|
|
1919 | if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
1920 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
1921 | glConvolutionFilter2D ( |
|
|
1922 | GL_CONVOLUTION_2D, |
|
|
1923 | GL_ALPHA, |
|
|
1924 | 3, 3, |
|
|
1925 | GL_ALPHA, GL_FLOAT, |
|
|
1926 | pack "f*", |
|
|
1927 | 0.1, 0.1, 0.1, |
|
|
1928 | 0.1, 0.2, 0.1, |
|
|
1929 | 0.1, 0.1, 0.1, |
|
|
1930 | ); |
|
|
1931 | glEnable GL_CONVOLUTION_2D; |
|
|
1932 | } |
|
|
1933 | |
|
|
1934 | $self->{fow_texture} = new CFClient::Texture |
|
|
1935 | w => $w, |
|
|
1936 | h => $h, |
|
|
1937 | data => $data, |
|
|
1938 | internalformat => GL_ALPHA, |
|
|
1939 | format => GL_ALPHA; |
|
|
1940 | |
|
|
1941 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1942 | |
|
|
1943 | glEnable GL_BLEND; |
|
|
1944 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1945 | glEnable GL_TEXTURE_2D; |
|
|
1946 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1947 | |
|
|
1948 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1949 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1950 | |
|
|
1951 | glDisable GL_TEXTURE_2D; |
|
|
1952 | glDisable GL_BLEND; |
|
|
1953 | } |
|
|
1954 | |
|
|
1955 | # HACK BEGIN |
|
|
1956 | { |
|
|
1957 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
1958 | my ($w, $h) = (250, 250); |
|
|
1959 | |
|
|
1960 | glEnable GL_BLEND; |
|
|
1961 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1962 | glEnable GL_TEXTURE_2D; |
|
|
1963 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1964 | |
|
|
1965 | $self->{mapmap_texture} = |
|
|
1966 | new CFClient::Texture |
|
|
1967 | w => $w, |
|
|
1968 | h => $h, |
|
|
1969 | data => $::MAP->mapmap ($w, $h), |
|
|
1970 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
|
|
1971 | |
|
|
1972 | $self->{mapmap_texture}->draw_quad (100, 100); |
|
|
1973 | |
|
|
1974 | glDisable GL_TEXTURE_2D; |
|
|
1975 | glDisable GL_BLEND; |
|
|
1976 | } |
|
|
1977 | # HACK END |
|
|
1978 | } |
|
|
1979 | |
|
|
1980 | glEndList; |
|
|
1981 | } |
|
|
1982 | |
|
|
1983 | glPushMatrix; |
|
|
1984 | glCallList $self->{list}; |
|
|
1985 | glPopMatrix; |
|
|
1986 | |
|
|
1987 | if ($FOCUS != $self) { |
|
|
1988 | glColor 64/255, 64/255, 64/255; |
|
|
1989 | glLogicOp GL_AND; |
|
|
1990 | glEnable GL_COLOR_LOGIC_OP; |
|
|
1991 | glBegin GL_QUADS; |
|
|
1992 | glVertex 0, 0; |
|
|
1993 | glVertex 0, $::HEIGHT; |
|
|
1994 | glVertex $::WIDTH, $::HEIGHT; |
|
|
1995 | glVertex $::WIDTH, 0; |
|
|
1996 | glEnd; |
|
|
1997 | glDisable GL_COLOR_LOGIC_OP; |
|
|
1998 | } |
|
|
1999 | } |
|
|
2000 | |
|
|
2001 | my %DIR = ( |
|
|
2002 | SDLK_KP8, [1, "north"], |
|
|
2003 | SDLK_KP9, [2, "northeast"], |
|
|
2004 | SDLK_KP6, [3, "east"], |
|
|
2005 | SDLK_KP3, [4, "southeast"], |
|
|
2006 | SDLK_KP2, [5, "south"], |
|
|
2007 | SDLK_KP1, [6, "southwest"], |
|
|
2008 | SDLK_KP4, [7, "west"], |
|
|
2009 | SDLK_KP7, [8, "northwest"], |
|
|
2010 | |
|
|
2011 | SDLK_UP, [1, "north"], |
|
|
2012 | SDLK_RIGHT, [3, "east"], |
|
|
2013 | SDLK_DOWN, [5, "south"], |
|
|
2014 | SDLK_LEFT, [7, "west"], |
|
|
2015 | ); |
|
|
2016 | |
|
|
2017 | sub key_down { |
|
|
2018 | my ($self, $ev) = @_; |
|
|
2019 | |
|
|
2020 | my $mod = $ev->key_mod; |
|
|
2021 | my $sym = $ev->key_sym; |
|
|
2022 | |
|
|
2023 | if ($sym == SDLK_KP5) { |
|
|
2024 | $::CONN->user_send ("stay fire"); |
|
|
2025 | } elsif ($sym == SDLK_a) { |
|
|
2026 | $::CONN->user_send ("apply"); |
|
|
2027 | } elsif ($sym == SDLK_QUOTE) { |
|
|
2028 | $self->emit ('activate_console'); |
|
|
2029 | } elsif ($sym == SDLK_SLASH) { |
|
|
2030 | $self->emit ('activate_console' => '/'); |
|
|
2031 | } elsif (exists $DIR{$sym}) { |
|
|
2032 | if ($mod & KMOD_SHIFT) { |
|
|
2033 | $self->{shft}++; |
|
|
2034 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
2035 | } elsif ($mod & KMOD_CTRL) { |
|
|
2036 | $self->{ctrl}++; |
|
|
2037 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
2038 | } else { |
|
|
2039 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
2040 | } |
|
|
2041 | } |
|
|
2042 | } |
|
|
2043 | |
|
|
2044 | sub key_up { |
|
|
2045 | my ($self, $ev) = @_; |
|
|
2046 | |
|
|
2047 | my $mod = $ev->key_mod; |
|
|
2048 | my $sym = $ev->key_sym; |
|
|
2049 | |
|
|
2050 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
|
|
2051 | $::CONN->user_send ("fire_stop"); |
|
|
2052 | } |
|
|
2053 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
2054 | $::CONN->user_send ("run_stop"); |
|
|
2055 | } |
|
|
2056 | } |
|
|
2057 | |
|
|
2058 | ############################################################################# |
|
|
2059 | |
|
|
2060 | package CFClient::UI::Animator; |
1835 | package CFClient::UI::Animator; |
2061 | |
1836 | |
2062 | use SDL::OpenGL; |
1837 | use CFClient::OpenGL; |
2063 | |
1838 | |
2064 | our @ISA = CFClient::UI::Bin::; |
1839 | our @ISA = CFClient::UI::Bin::; |
2065 | |
1840 | |
2066 | sub moveto { |
1841 | sub moveto { |
2067 | my ($self, $x, $y) = @_; |
1842 | my ($self, $x, $y) = @_; |
… | |
… | |
2140 | |
1915 | |
2141 | package CFClient::UI::Root; |
1916 | package CFClient::UI::Root; |
2142 | |
1917 | |
2143 | our @ISA = CFClient::UI::Container::; |
1918 | our @ISA = CFClient::UI::Container::; |
2144 | |
1919 | |
2145 | use SDL::OpenGL; |
1920 | use CFClient::OpenGL; |
2146 | |
1921 | |
2147 | sub check_size { |
1922 | sub check_size { |
2148 | my ($self) = @_; |
1923 | my ($self) = @_; |
2149 | |
1924 | |
2150 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
1925 | $self->configure (0, 0, $::WITH, $::HEIGHT); |