… | |
… | |
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) = @_; |
117 | |
131 | |
118 | $self->{x} = int $x; |
132 | $self->{x} = int $x; |
119 | $self->{y} = int $y; |
133 | $self->{y} = int $y; |
… | |
… | |
141 | |
155 | |
142 | $self->{w} = $w; |
156 | $self->{w} = $w; |
143 | $self->{h} = $h; |
157 | $self->{h} = $h; |
144 | |
158 | |
145 | $self->size_allocate ($w, $h); |
159 | $self->size_allocate ($w, $h); |
|
|
160 | $self->update; |
146 | } |
161 | } |
147 | |
162 | |
148 | sub size_allocate { |
163 | sub size_allocate { |
149 | # nothing to be done |
164 | # nothing to be done |
150 | } |
165 | } |
… | |
… | |
272 | $self->{req_w} = $w; |
287 | $self->{req_w} = $w; |
273 | $self->{req_h} = $h; |
288 | $self->{req_h} = $h; |
274 | |
289 | |
275 | $self->{parent}->check_size |
290 | $self->{parent}->check_size |
276 | if $self->{parent}; |
291 | if $self->{parent}; |
277 | |
|
|
278 | $self->size_allocate ($w, $h); |
|
|
279 | $self->update; |
|
|
280 | } |
292 | } |
281 | } |
293 | } |
282 | |
294 | |
283 | sub update { |
295 | sub update { |
284 | my ($self) = @_; |
296 | my ($self) = @_; |
… | |
… | |
386 | $self->{children} = [ |
398 | $self->{children} = [ |
387 | sort { $a->{z} <=> $b->{z} } |
399 | sort { $a->{z} <=> $b->{z} } |
388 | @{$self->{children}}, $child |
400 | @{$self->{children}}, $child |
389 | ]; |
401 | ]; |
390 | |
402 | |
391 | $self->{w} = $self->{h} = -1; |
|
|
392 | |
|
|
393 | $child->check_size; |
403 | $child->check_size; |
394 | } |
404 | } |
395 | |
405 | |
396 | sub remove { |
406 | sub remove { |
397 | my ($self, $widget) = @_; |
407 | my ($self, $child) = @_; |
398 | |
408 | |
|
|
409 | delete $child->{parent}; |
|
|
410 | |
399 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
411 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
400 | |
412 | |
401 | $self->check_size; |
413 | $self->check_size; |
402 | } |
414 | } |
403 | |
415 | |
404 | sub find_widget { |
416 | sub find_widget { |
… | |
… | |
436 | |
448 | |
437 | $class->SUPER::new (children => [$child], %arg) |
449 | $class->SUPER::new (children => [$child], %arg) |
438 | } |
450 | } |
439 | |
451 | |
440 | sub add { |
452 | sub add { |
441 | my ($self, $widget) = @_; |
453 | my ($self, $child) = @_; |
442 | |
454 | |
443 | $self->{children} = []; |
455 | $self->{children} = []; |
444 | |
456 | |
445 | $self->SUPER::add ($widget); |
457 | $self->SUPER::add ($child); |
446 | } |
458 | } |
447 | |
459 | |
448 | sub remove { |
460 | sub remove { |
449 | my ($self, $widget) = @_; |
461 | my ($self, $widget) = @_; |
450 | |
462 | |
… | |
… | |
609 | # TODO: user_x, user_y, overwrite moveto? |
621 | # TODO: user_x, user_y, overwrite moveto? |
610 | |
622 | |
611 | $class->SUPER::new ( |
623 | $class->SUPER::new ( |
612 | bg => [1, 1, 1, 1], |
624 | bg => [1, 1, 1, 1], |
613 | border_bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
614 | border => int $::FONTSIZE * 0.8, |
626 | border => 0.8, |
615 | @_ |
627 | @_ |
616 | ) |
628 | ) |
617 | } |
629 | } |
618 | |
630 | |
|
|
631 | sub border { |
|
|
632 | int $_[0]{border} * $::FONTSIZE |
|
|
633 | } |
|
|
634 | |
619 | sub size_request { |
635 | sub size_request { |
620 | my ($self) = @_; |
636 | my ($self) = @_; |
621 | |
637 | |
622 | 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}; |
623 | |
639 | |
624 | my ($w, $h) = $self->SUPER::size_request; |
640 | my ($w, $h) = $self->SUPER::size_request; |
625 | |
641 | |
626 | ( |
642 | ( |
627 | $w + $self->{border} * 2, |
643 | $w + $self->border * 2, |
628 | $h + $self->{border} * 2, |
644 | $h + $self->border * 2, |
629 | ) |
645 | ) |
630 | } |
646 | } |
631 | |
647 | |
632 | sub size_allocate { |
648 | sub size_allocate { |
633 | my ($self, $w, $h) = @_; |
649 | my ($self, $w, $h) = @_; |
634 | |
650 | |
635 | $h -= List::Util::max 0, $self->{border} * 2; |
651 | $h -= List::Util::max 0, $self->border * 2; |
636 | $w -= List::Util::max 0, $self->{border} * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
637 | |
653 | |
638 | $self->child->configure ($self->{border}, $self->{border}, $w, $h); |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
639 | } |
655 | } |
640 | |
656 | |
641 | sub button_down { |
657 | sub button_down { |
642 | my ($self, $ev, $x, $y) = @_; |
658 | my ($self, $ev, $x, $y) = @_; |
643 | |
659 | |
|
|
660 | my $border = $self->border; |
|
|
661 | |
644 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
662 | if ($x < $self->{w} && $x >= $self->{w} - $border |
645 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
663 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
646 | |
664 | |
647 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
665 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
648 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
666 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
649 | |
667 | |
650 | $self->{motion} = sub { |
668 | $self->{motion} = sub { |
… | |
… | |
656 | $self->{user_h} = $bh + $y - $oy; |
674 | $self->{user_h} = $bh + $y - $oy; |
657 | $self->check_size; |
675 | $self->check_size; |
658 | }; |
676 | }; |
659 | |
677 | |
660 | } elsif ($x >= 0 && $x < $self->{w} |
678 | } elsif ($x >= 0 && $x < $self->{w} |
661 | && $y >= 0 && $y < $self->{border}) { |
679 | && $y >= 0 && $y < $border) { |
662 | |
680 | |
663 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
681 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
664 | my ($bx, $by) = ($self->{x}, $self->{y}); |
682 | my ($bx, $by) = ($self->{x}, $self->{y}); |
665 | |
683 | |
666 | $self->{motion} = sub { |
684 | $self->{motion} = sub { |
… | |
… | |
695 | glEnable GL_BLEND; |
713 | glEnable GL_BLEND; |
696 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
714 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
697 | glEnable GL_TEXTURE_2D; |
715 | glEnable GL_TEXTURE_2D; |
698 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
716 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
699 | |
717 | |
|
|
718 | my $border = $self->border; |
|
|
719 | |
700 | glColor @{ $self->{border_bg} }; |
720 | glColor @{ $self->{border_bg} }; |
701 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
721 | $tex[1]->draw_quad (0, 0, $w, $border); |
702 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
722 | $tex[3]->draw_quad (0, $border, $border, $ch); |
703 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
723 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
704 | $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); |
724 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
705 | |
725 | |
706 | my $bg = $tex[0]; |
726 | my $bg = $tex[0]; |
707 | |
727 | |
708 | # TODO: repeat texture not scale |
728 | # TODO: repeat texture not scale |
709 | my $rep_x = $cw / $bg->{w}; |
729 | my $rep_x = $cw / $bg->{w}; |
… | |
… | |
712 | glColor @{ $self->{bg} }; |
732 | glColor @{ $self->{bg} }; |
713 | |
733 | |
714 | $bg->{s} = $rep_x; |
734 | $bg->{s} = $rep_x; |
715 | $bg->{t} = $rep_y; |
735 | $bg->{t} = $rep_y; |
716 | $bg->{wrap_mode} = 1; |
736 | $bg->{wrap_mode} = 1; |
717 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
718 | |
738 | |
719 | glDisable GL_TEXTURE_2D; |
739 | glDisable GL_TEXTURE_2D; |
720 | glDisable GL_BLEND; |
740 | glDisable GL_BLEND; |
721 | |
741 | |
722 | $self->child->draw; |
742 | $self->child->draw; |
… | |
… | |
744 | sub add { |
764 | sub add { |
745 | my ($self, $x, $y, $child) = @_; |
765 | my ($self, $x, $y, $child) = @_; |
746 | |
766 | |
747 | $child->set_parent ($self); |
767 | $child->set_parent ($self); |
748 | $self->{children}[$y][$x] = $child; |
768 | $self->{children}[$y][$x] = $child; |
749 | |
|
|
750 | $self->{w} = $self->{h} = -1; |
|
|
751 | |
769 | |
752 | $child->check_size; |
770 | $child->check_size; |
753 | } |
771 | } |
754 | |
772 | |
755 | # 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? |
… | |
… | |
988 | sub new { |
1006 | sub new { |
989 | my ($class, %arg) = @_; |
1007 | my ($class, %arg) = @_; |
990 | |
1008 | |
991 | my $self = $class->SUPER::new ( |
1009 | my $self = $class->SUPER::new ( |
992 | fg => [1, 1, 1], |
1010 | fg => [1, 1, 1], |
993 | fontsize => $::FONTSIZE, |
1011 | fontsize => 1, |
994 | text => "", |
1012 | text => "", |
995 | align => -1, |
1013 | align => -1, |
996 | valign => -1, |
1014 | valign => -1, |
997 | padding => 2, |
1015 | padding => 2, |
998 | layout => new CFClient::Layout, |
1016 | layout => new CFClient::Layout, |
… | |
… | |
1037 | |
1055 | |
1038 | sub size_request { |
1056 | sub size_request { |
1039 | my ($self) = @_; |
1057 | my ($self) = @_; |
1040 | |
1058 | |
1041 | $self->{layout}->set_width; |
1059 | $self->{layout}->set_width; |
1042 | $self->{layout}->set_height ($self->{fontsize}); |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1043 | |
1061 | |
1044 | my ($w, $h) = $self->{layout}->size; |
1062 | my ($w, $h) = $self->{layout}->size; |
1045 | |
1063 | |
1046 | ( |
1064 | ( |
1047 | $w + $self->{padding} * 2, |
1065 | $w + $self->{padding} * 2, |
… | |
… | |
1053 | my ($self, $w, $h) = @_; |
1071 | my ($self, $w, $h) = @_; |
1054 | |
1072 | |
1055 | delete $self->{texture}; |
1073 | delete $self->{texture}; |
1056 | } |
1074 | } |
1057 | |
1075 | |
1058 | sub update { |
|
|
1059 | my ($self) = @_; |
|
|
1060 | |
|
|
1061 | delete $self->{texture}; |
|
|
1062 | $self->SUPER::update; |
|
|
1063 | } |
|
|
1064 | |
|
|
1065 | sub _draw { |
1076 | sub _draw { |
1066 | my ($self) = @_; |
1077 | my ($self) = @_; |
1067 | |
1078 | |
1068 | my $tex = $self->{texture} ||= do { |
1079 | my $tex = $self->{texture} ||= do { |
1069 | $self->{layout}->set_width ($self->{w}); |
1080 | $self->{layout}->set_width ($self->{w}); |
1070 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); |
1081 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1071 | new_from_layout CFClient::Texture $self->{layout} |
1082 | new_from_layout CFClient::Texture $self->{layout} |
1072 | }; |
1083 | }; |
1073 | |
1084 | |
1074 | glEnable GL_BLEND; |
1085 | glEnable GL_BLEND; |
1075 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1086 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
1100 | |
1111 | |
1101 | package CFClient::UI::EntryBase; |
1112 | package CFClient::UI::EntryBase; |
1102 | |
1113 | |
1103 | our @ISA = CFClient::UI::Label::; |
1114 | our @ISA = CFClient::UI::Label::; |
1104 | |
1115 | |
1105 | use SDL; |
|
|
1106 | use SDL::OpenGL; |
1116 | use SDL::OpenGL; |
1107 | |
1117 | |
1108 | sub new { |
1118 | sub new { |
1109 | my $class = shift; |
1119 | my $class = shift; |
1110 | |
1120 | |
… | |
… | |
1125 | |
1135 | |
1126 | delete $self->{cur_h}; |
1136 | delete $self->{cur_h}; |
1127 | |
1137 | |
1128 | return if $self->{text} eq $text; |
1138 | return if $self->{text} eq $text; |
1129 | |
1139 | |
|
|
1140 | delete $self->{texture}; |
|
|
1141 | |
1130 | $self->{last_activity} = $::NOW; |
1142 | $self->{last_activity} = $::NOW; |
1131 | $self->{text} = $text; |
1143 | $self->{text} = $text; |
1132 | |
1144 | |
1133 | $text =~ s/./*/g if $self->{hidden}; |
1145 | $text =~ s/./*/g if $self->{hidden}; |
1134 | $self->{layout}->set_text ("$text "); |
1146 | $self->{layout}->set_text ("$text "); |
… | |
… | |
1163 | } |
1175 | } |
1164 | |
1176 | |
1165 | sub key_down { |
1177 | sub key_down { |
1166 | my ($self, $ev) = @_; |
1178 | my ($self, $ev) = @_; |
1167 | |
1179 | |
1168 | my $mod = $ev->key_mod; |
1180 | my $mod = $ev->{mod}; |
1169 | my $sym = $ev->key_sym; |
1181 | my $sym = $ev->{sym}; |
1170 | |
|
|
1171 | my $uni = $ev->key_unicode; |
1182 | my $uni = $ev->{unicode}; |
1172 | |
1183 | |
1173 | my $text = $self->get_text; |
1184 | my $text = $self->get_text; |
1174 | |
1185 | |
1175 | if ($sym == SDLK_BACKSPACE) { |
1186 | if ($sym == 8) { |
1176 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1187 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1177 | } elsif ($sym == SDLK_DELETE) { |
1188 | } elsif ($sym == 127) { |
1178 | substr $text, $self->{cursor}, 1, ""; |
1189 | substr $text, $self->{cursor}, 1, ""; |
1179 | } elsif ($sym == SDLK_LEFT) { |
1190 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1180 | --$self->{cursor} if $self->{cursor}; |
1191 | --$self->{cursor} if $self->{cursor}; |
1181 | } elsif ($sym == SDLK_RIGHT) { |
1192 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1182 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1193 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1183 | } elsif ($sym == SDLK_HOME) { |
1194 | } elsif ($sym == CFClient::SDLK_HOME) { |
1184 | $self->{cursor} = 0; |
1195 | $self->{cursor} = 0; |
1185 | } elsif ($sym == SDLK_END) { |
1196 | } elsif ($sym == CFClient::SDLK_END) { |
1186 | $self->{cursor} = length $text; |
1197 | $self->{cursor} = length $text; |
1187 | } elsif ($sym == SDLK_ESCAPE) { |
1198 | } elsif ($sym == 27) { |
1188 | $self->emit ('escape'); |
1199 | $self->emit ('escape'); |
1189 | } elsif ($uni) { |
1200 | } elsif ($uni) { |
1190 | substr $text, $self->{cursor}++, 0, chr $uni; |
1201 | substr $text, $self->{cursor}++, 0, chr $uni; |
1191 | } |
1202 | } |
1192 | |
1203 | |
… | |
… | |
1267 | |
1278 | |
1268 | package CFClient::UI::Entry; |
1279 | package CFClient::UI::Entry; |
1269 | |
1280 | |
1270 | our @ISA = CFClient::UI::EntryBase::; |
1281 | our @ISA = CFClient::UI::EntryBase::; |
1271 | |
1282 | |
1272 | use SDL; |
|
|
1273 | use SDL::OpenGL; |
1283 | use SDL::OpenGL; |
1274 | |
1284 | |
1275 | sub key_down { |
1285 | sub key_down { |
1276 | my ($self, $ev) = @_; |
1286 | my ($self, $ev) = @_; |
1277 | |
1287 | |
1278 | my $sym = $ev->key_sym; |
1288 | my $sym = $ev->{sym}; |
1279 | |
1289 | |
1280 | if ($sym == SDLK_RETURN) { |
1290 | if ($sym == 13) { |
1281 | $self->emit (activate => $self->get_text); |
1291 | $self->emit (activate => $self->get_text); |
1282 | $self->update; |
1292 | $self->update; |
1283 | |
1293 | |
1284 | } else { |
1294 | } else { |
1285 | $self->SUPER::key_down ($ev); |
1295 | $self->SUPER::key_down ($ev); |
… | |
… | |
1291 | |
1301 | |
1292 | package CFClient::UI::Button; |
1302 | package CFClient::UI::Button; |
1293 | |
1303 | |
1294 | our @ISA = CFClient::UI::Label::; |
1304 | our @ISA = CFClient::UI::Label::; |
1295 | |
1305 | |
1296 | use SDL; |
|
|
1297 | use SDL::OpenGL; |
1306 | use SDL::OpenGL; |
1298 | |
1307 | |
1299 | my @tex = |
1308 | my @tex = |
1300 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1309 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1301 | qw(b1_button_active.png); |
1310 | qw(b1_button_active.png); |
… | |
… | |
1355 | |
1364 | |
1356 | my @tex = |
1365 | my @tex = |
1357 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1366 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1358 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1367 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1359 | |
1368 | |
1360 | use SDL; |
|
|
1361 | use SDL::OpenGL; |
1369 | use SDL::OpenGL; |
1362 | |
1370 | |
1363 | sub new { |
1371 | sub new { |
1364 | my $class = shift; |
1372 | my $class = shift; |
1365 | |
1373 | |
… | |
… | |
1543 | # TODO: calculations are off |
1551 | # TODO: calculations are off |
1544 | my $self = $class->SUPER::new ( |
1552 | my $self = $class->SUPER::new ( |
1545 | fg => [1, 1, 1], |
1553 | fg => [1, 1, 1], |
1546 | active_fg => [0, 0, 0], |
1554 | active_fg => [0, 0, 0], |
1547 | range => [0, 0, 100, 10], |
1555 | range => [0, 0, 100, 10], |
1548 | req_w => 40, |
1556 | req_w => 20, |
1549 | req_h => 13, |
1557 | req_h => 20, |
1550 | vertical => 0, |
1558 | vertical => 0, |
1551 | can_hover => 1, |
1559 | can_hover => 1, |
1552 | inner_pad => 5, |
1560 | inner_pad => 5, |
1553 | @_ |
1561 | @_ |
1554 | ); |
1562 | ); |
… | |
… | |
1664 | |
1672 | |
1665 | sub new { |
1673 | sub new { |
1666 | my $class = shift; |
1674 | my $class = shift; |
1667 | |
1675 | |
1668 | my $self = $class->SUPER::new ( |
1676 | my $self = $class->SUPER::new ( |
1669 | req_w => $::WIDTH / 6, |
|
|
1670 | req_h => $::HEIGHT / 6, |
|
|
1671 | fontsize => $::FONTSIZE, |
1677 | fontsize => 1, |
1672 | @_, |
1678 | @_, |
1673 | |
1679 | |
1674 | layout => (new CFClient::Layout), |
1680 | layout => (new CFClient::Layout), |
1675 | par => [], |
1681 | par => [], |
1676 | height => 0, |
1682 | height => 0, |
… | |
… | |
1697 | sub text_height { |
1703 | sub text_height { |
1698 | my ($self, $text) = @_; |
1704 | my ($self, $text) = @_; |
1699 | |
1705 | |
1700 | my $layout = $self->{layout}; |
1706 | my $layout = $self->{layout}; |
1701 | |
1707 | |
1702 | $layout->set_height ($self->{fontsize}); |
1708 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
1703 | $layout->set_width ($self->{w}); |
1709 | $layout->set_width ($self->{w}); |
1704 | $layout->set_text ($text); |
1710 | $layout->set_text ($text); |
1705 | |
1711 | |
1706 | ($layout->size)[1] |
1712 | ($layout->size)[1] |
1707 | } |
1713 | } |
… | |
… | |
1711 | |
1717 | |
1712 | $self->{need_reflow}++; |
1718 | $self->{need_reflow}++; |
1713 | $self->update; |
1719 | $self->update; |
1714 | } |
1720 | } |
1715 | |
1721 | |
1716 | sub size_request { |
|
|
1717 | my ($self) = @_; |
|
|
1718 | |
|
|
1719 | ($self->{req_w}, $self->{req_h}) |
|
|
1720 | } |
|
|
1721 | |
|
|
1722 | sub size_allocate { |
1722 | sub size_allocate { |
1723 | my ($self, $w, $h) = @_; |
1723 | my ($self, $w, $h) = @_; |
1724 | |
1724 | |
|
|
1725 | $self->SUPER::size_allocate ($w, $h); |
|
|
1726 | |
1725 | $self->{layout}->set_height ($self->{fontsize}); |
1727 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1726 | $self->{layout}->set_width ($self->{w}); |
1728 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1727 | |
1729 | |
1728 | $self->reflow; |
1730 | $self->reflow; |
1729 | $self->update; |
|
|
1730 | } |
1731 | } |
1731 | |
1732 | |
1732 | sub add_paragraph { |
1733 | sub add_paragraph { |
1733 | my ($self, $color, $text) = @_; |
1734 | my ($self, $color, $text) = @_; |
1734 | |
1735 | |
… | |
… | |
1815 | glDisable GL_TEXTURE_2D; |
1816 | glDisable GL_TEXTURE_2D; |
1816 | } |
1817 | } |
1817 | |
1818 | |
1818 | $self->{children}[1]->draw; |
1819 | $self->{children}[1]->draw; |
1819 | |
1820 | |
1820 | } |
|
|
1821 | |
|
|
1822 | ############################################################################# |
|
|
1823 | |
|
|
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 | } |
1821 | } |
2057 | |
1822 | |
2058 | ############################################################################# |
1823 | ############################################################################# |
2059 | |
1824 | |
2060 | package CFClient::UI::Animator; |
1825 | package CFClient::UI::Animator; |