… | |
… | |
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 { |
… | |
… | |
146 | } |
146 | } |
147 | |
147 | |
148 | sub configure { |
148 | sub configure { |
149 | my ($self, $x, $y, $w, $h) = @_; |
149 | my ($self, $x, $y, $w, $h) = @_; |
150 | |
150 | |
|
|
151 | if ($self->{aspect}) { |
|
|
152 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
|
|
153 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
|
|
154 | |
|
|
155 | # use alignment to adjust x, y |
|
|
156 | |
|
|
157 | $x += ($w - $w2) * 0.5; |
|
|
158 | $y += ($h - $h2) * 0.5; |
|
|
159 | |
|
|
160 | ($w, $h) = ($w2, $h2); |
|
|
161 | } |
|
|
162 | |
|
|
163 | if ($self->{x} != $x || $self->{y} != $y) { |
151 | $self->{x} = $x; |
164 | $self->{x} = $x; |
152 | $self->{y} = $y; |
165 | $self->{y} = $y; |
|
|
166 | $self->update; |
|
|
167 | } |
153 | |
168 | |
154 | return unless $self->{w} != $w || $self->{h} != $h; |
169 | if ($self->{w} != $w || $self->{h} != $h) { |
155 | |
|
|
156 | $self->{w} = $w; |
170 | $self->{w} = $w; |
157 | $self->{h} = $h; |
171 | $self->{h} = $h; |
158 | |
172 | |
159 | $self->size_allocate ($w, $h); |
173 | $self->size_allocate ($w, $h); |
160 | $self->update; |
174 | $self->update; |
|
|
175 | } |
161 | } |
176 | } |
162 | |
177 | |
163 | sub size_allocate { |
178 | sub size_allocate { |
164 | # nothing to be done |
179 | # nothing to be done |
165 | } |
180 | } |
… | |
… | |
324 | package CFClient::UI::DrawBG; |
339 | package CFClient::UI::DrawBG; |
325 | |
340 | |
326 | our @ISA = CFClient::UI::Base::; |
341 | our @ISA = CFClient::UI::Base::; |
327 | |
342 | |
328 | use strict; |
343 | use strict; |
329 | use SDL::OpenGL; |
344 | use CFClient::OpenGL; |
330 | |
345 | |
331 | sub new { |
346 | sub new { |
332 | my $class = shift; |
347 | my $class = shift; |
333 | |
348 | |
334 | # range [value, low, high, page] |
349 | # range [value, low, high, page] |
… | |
… | |
482 | |
497 | |
483 | package CFClient::UI::Window; |
498 | package CFClient::UI::Window; |
484 | |
499 | |
485 | our @ISA = CFClient::UI::Bin::; |
500 | our @ISA = CFClient::UI::Bin::; |
486 | |
501 | |
487 | use SDL::OpenGL; |
502 | use CFClient::OpenGL; |
488 | |
503 | |
489 | sub new { |
504 | sub new { |
490 | my ($class, %arg) = @_; |
505 | my ($class, %arg) = @_; |
491 | |
506 | |
492 | my $self = $class->SUPER::new (%arg); |
507 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
565 | |
580 | |
566 | package CFClient::UI::Frame; |
581 | package CFClient::UI::Frame; |
567 | |
582 | |
568 | our @ISA = CFClient::UI::Bin::; |
583 | our @ISA = CFClient::UI::Bin::; |
569 | |
584 | |
570 | use SDL::OpenGL; |
585 | use CFClient::OpenGL; |
571 | |
586 | |
572 | sub size_request { |
587 | sub size_request { |
573 | my ($self) = @_; |
588 | my ($self) = @_; |
574 | my $chld = $self->child |
589 | my $chld = $self->child |
575 | or return (0, 0); |
590 | or return (0, 0); |
… | |
… | |
607 | |
622 | |
608 | package CFClient::UI::FancyFrame; |
623 | package CFClient::UI::FancyFrame; |
609 | |
624 | |
610 | our @ISA = CFClient::UI::Bin::; |
625 | our @ISA = CFClient::UI::Bin::; |
611 | |
626 | |
612 | use SDL::OpenGL; |
627 | use CFClient::OpenGL; |
613 | |
628 | |
614 | my @tex = |
629 | my @tex = |
615 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
630 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
616 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
631 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
617 | |
632 | |
618 | sub new { |
633 | sub new { |
619 | my $class = shift; |
634 | my $class = shift; |
620 | |
635 | |
621 | # TODO: user_x, user_y, overwrite moveto? |
636 | # TODO: user_x, user_y, overwrite moveto? |
622 | |
637 | |
623 | $class->SUPER::new ( |
638 | my $self = $class->SUPER::new ( |
624 | bg => [1, 1, 1, 1], |
639 | bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
640 | border_bg => [1, 1, 1, 1], |
626 | border => 0.8, |
641 | border => 0.8, |
627 | @_ |
642 | @_ |
628 | ) |
643 | ); |
|
|
644 | |
|
|
645 | $self->{title} &&= new CFClient::UI::Label |
|
|
646 | align => 0, |
|
|
647 | valign => 1, |
|
|
648 | text => $self->{title}, |
|
|
649 | fontsize => 1; |
|
|
650 | |
|
|
651 | $self |
629 | } |
652 | } |
630 | |
653 | |
631 | sub border { |
654 | sub border { |
632 | int $_[0]{border} * $::FONTSIZE |
655 | int $_[0]{border} * $::FONTSIZE |
633 | } |
656 | } |
… | |
… | |
649 | my ($self, $w, $h) = @_; |
672 | my ($self, $w, $h) = @_; |
650 | |
673 | |
651 | $h -= List::Util::max 0, $self->border * 2; |
674 | $h -= List::Util::max 0, $self->border * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
675 | $w -= List::Util::max 0, $self->border * 2; |
653 | |
676 | |
|
|
677 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
678 | if $self->{title}; |
|
|
679 | |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
680 | $self->child->configure ($self->border, $self->border, $w, $h); |
655 | } |
681 | } |
656 | |
682 | |
657 | sub button_down { |
683 | sub button_down { |
658 | my ($self, $ev, $x, $y) = @_; |
684 | my ($self, $ev, $x, $y) = @_; |
… | |
… | |
660 | my $border = $self->border; |
686 | my $border = $self->border; |
661 | |
687 | |
662 | if ($x < $self->{w} && $x >= $self->{w} - $border |
688 | if ($x < $self->{w} && $x >= $self->{w} - $border |
663 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
689 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
664 | |
690 | |
665 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
691 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
666 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
692 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
667 | |
693 | |
668 | $self->{motion} = sub { |
694 | $self->{motion} = sub { |
669 | my ($ev, $x, $y) = @_; |
695 | my ($ev, $x, $y) = @_; |
670 | |
696 | |
671 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
697 | ($x, $y) = ($ev->{x}, $ev->{y}); |
672 | |
698 | |
673 | $self->{user_w} = $bw + $x - $ox; |
699 | $self->{user_w} = $bw + $x - $ox; |
674 | $self->{user_h} = $bh + $y - $oy; |
700 | $self->{user_h} = $bh + $y - $oy; |
675 | $self->check_size; |
701 | $self->check_size; |
676 | }; |
702 | }; |
677 | |
703 | |
678 | } elsif ($x >= 0 && $x < $self->{w} |
704 | } elsif ($x >= 0 && $x < $self->{w} |
679 | && $y >= 0 && $y < $border) { |
705 | && $y >= 0 && $y < $border) { |
680 | |
706 | |
681 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
707 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
682 | my ($bx, $by) = ($self->{x}, $self->{y}); |
708 | my ($bx, $by) = ($self->{x}, $self->{y}); |
683 | |
709 | |
684 | $self->{motion} = sub { |
710 | $self->{motion} = sub { |
685 | my ($ev, $x, $y) = @_; |
711 | my ($ev, $x, $y) = @_; |
686 | |
712 | |
687 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
713 | ($x, $y) = ($ev->{x}, $ev->{y}); |
688 | |
714 | |
689 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
715 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
690 | $self->update; |
716 | $self->update; |
691 | }; |
717 | }; |
692 | } |
718 | } |
… | |
… | |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
763 | $bg->draw_quad ($border, $border, $cw, $ch); |
738 | |
764 | |
739 | glDisable GL_TEXTURE_2D; |
765 | glDisable GL_TEXTURE_2D; |
740 | glDisable GL_BLEND; |
766 | glDisable GL_BLEND; |
741 | |
767 | |
|
|
768 | $self->{title}->draw if $self->{title}; |
742 | $self->child->draw; |
769 | $self->child->draw; |
743 | } |
770 | } |
744 | |
771 | |
745 | ############################################################################# |
772 | ############################################################################# |
746 | |
773 | |
… | |
… | |
748 | |
775 | |
749 | our @ISA = CFClient::UI::Base::; |
776 | our @ISA = CFClient::UI::Base::; |
750 | |
777 | |
751 | use List::Util qw(max sum); |
778 | use List::Util qw(max sum); |
752 | |
779 | |
753 | use SDL::OpenGL; |
780 | use CFClient::OpenGL; |
754 | |
781 | |
755 | sub new { |
782 | sub new { |
756 | my $class = shift; |
783 | my $class = shift; |
757 | |
784 | |
758 | $class->SUPER::new ( |
785 | $class->SUPER::new ( |
… | |
… | |
999 | |
1026 | |
1000 | package CFClient::UI::Label; |
1027 | package CFClient::UI::Label; |
1001 | |
1028 | |
1002 | our @ISA = CFClient::UI::Base::; |
1029 | our @ISA = CFClient::UI::Base::; |
1003 | |
1030 | |
1004 | use SDL::OpenGL; |
1031 | use CFClient::OpenGL; |
1005 | |
1032 | |
1006 | sub new { |
1033 | sub new { |
1007 | my ($class, %arg) = @_; |
1034 | my ($class, %arg) = @_; |
1008 | |
1035 | |
1009 | my $self = $class->SUPER::new ( |
1036 | my $self = $class->SUPER::new ( |
… | |
… | |
1015 | padding => 2, |
1042 | padding => 2, |
1016 | layout => new CFClient::Layout, |
1043 | layout => new CFClient::Layout, |
1017 | %arg |
1044 | %arg |
1018 | ); |
1045 | ); |
1019 | |
1046 | |
1020 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
1047 | if (exists $self->{template}) { |
|
|
1048 | my $layout = new CFClient::Layout; |
|
|
1049 | $layout->set_text (delete $self->{template}); |
|
|
1050 | $self->{template} = $layout; |
|
|
1051 | } |
1021 | |
1052 | |
1022 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1053 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1023 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1054 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1024 | |
1055 | |
1025 | $self |
1056 | $self |
… | |
… | |
1058 | |
1089 | |
1059 | $self->{layout}->set_width; |
1090 | $self->{layout}->set_width; |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1091 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1061 | |
1092 | |
1062 | my ($w, $h) = $self->{layout}->size; |
1093 | my ($w, $h) = $self->{layout}->size; |
|
|
1094 | |
|
|
1095 | if (exists $self->{template}) { |
|
|
1096 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1097 | |
|
|
1098 | my ($w2, $h2) = $self->{template}->size; |
|
|
1099 | |
|
|
1100 | $w = List::Util::max $w, $w2; |
|
|
1101 | $h = List::Util::max $h, $h2; |
|
|
1102 | } |
1063 | |
1103 | |
1064 | ( |
1104 | ( |
1065 | $w + $self->{padding} * 2, |
1105 | $w + $self->{padding} * 2, |
1066 | $h + $self->{padding} * 2, |
1106 | $h + $self->{padding} * 2, |
1067 | ) |
1107 | ) |
… | |
… | |
1069 | |
1109 | |
1070 | sub size_allocate { |
1110 | sub size_allocate { |
1071 | my ($self, $w, $h) = @_; |
1111 | my ($self, $w, $h) = @_; |
1072 | |
1112 | |
1073 | delete $self->{texture}; |
1113 | delete $self->{texture}; |
|
|
1114 | } |
|
|
1115 | |
|
|
1116 | sub set_fontsize { |
|
|
1117 | my ($self, $fontsize) = @_; |
|
|
1118 | |
|
|
1119 | $self->{fontsize} = $fontsize; |
|
|
1120 | $self->update; |
1074 | } |
1121 | } |
1075 | |
1122 | |
1076 | sub _draw { |
1123 | sub _draw { |
1077 | my ($self) = @_; |
1124 | my ($self) = @_; |
1078 | |
1125 | |
… | |
… | |
1111 | |
1158 | |
1112 | package CFClient::UI::EntryBase; |
1159 | package CFClient::UI::EntryBase; |
1113 | |
1160 | |
1114 | our @ISA = CFClient::UI::Label::; |
1161 | our @ISA = CFClient::UI::Label::; |
1115 | |
1162 | |
1116 | use SDL; |
1163 | use CFClient::OpenGL; |
1117 | use SDL::OpenGL; |
|
|
1118 | |
1164 | |
1119 | sub new { |
1165 | sub new { |
1120 | my $class = shift; |
1166 | my $class = shift; |
1121 | |
1167 | |
1122 | $class->SUPER::new ( |
1168 | $class->SUPER::new ( |
… | |
… | |
1176 | } |
1222 | } |
1177 | |
1223 | |
1178 | sub key_down { |
1224 | sub key_down { |
1179 | my ($self, $ev) = @_; |
1225 | my ($self, $ev) = @_; |
1180 | |
1226 | |
1181 | my $mod = $ev->key_mod; |
1227 | my $mod = $ev->{mod}; |
1182 | my $sym = $ev->key_sym; |
1228 | my $sym = $ev->{sym}; |
1183 | |
|
|
1184 | my $uni = $ev->key_unicode; |
1229 | my $uni = $ev->{unicode}; |
1185 | |
1230 | |
1186 | my $text = $self->get_text; |
1231 | my $text = $self->get_text; |
1187 | |
1232 | |
1188 | if ($sym == SDLK_BACKSPACE) { |
1233 | if ($sym == 8) { |
1189 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1234 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1190 | } elsif ($sym == SDLK_DELETE) { |
1235 | } elsif ($sym == 127) { |
1191 | substr $text, $self->{cursor}, 1, ""; |
1236 | substr $text, $self->{cursor}, 1, ""; |
1192 | } elsif ($sym == SDLK_LEFT) { |
1237 | } elsif ($sym == CFClient::SDLK_LEFT) { |
1193 | --$self->{cursor} if $self->{cursor}; |
1238 | --$self->{cursor} if $self->{cursor}; |
1194 | } elsif ($sym == SDLK_RIGHT) { |
1239 | } elsif ($sym == CFClient::SDLK_RIGHT) { |
1195 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1240 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1196 | } elsif ($sym == SDLK_HOME) { |
1241 | } elsif ($sym == CFClient::SDLK_HOME) { |
1197 | $self->{cursor} = 0; |
1242 | $self->{cursor} = 0; |
1198 | } elsif ($sym == SDLK_END) { |
1243 | } elsif ($sym == CFClient::SDLK_END) { |
1199 | $self->{cursor} = length $text; |
1244 | $self->{cursor} = length $text; |
1200 | } elsif ($sym == SDLK_ESCAPE) { |
1245 | } elsif ($sym == 27) { |
1201 | $self->emit ('escape'); |
1246 | $self->emit ('escape'); |
1202 | } elsif ($uni) { |
1247 | } elsif ($uni) { |
1203 | substr $text, $self->{cursor}++, 0, chr $uni; |
1248 | substr $text, $self->{cursor}++, 0, chr $uni; |
1204 | } |
1249 | } |
1205 | |
1250 | |
… | |
… | |
1280 | |
1325 | |
1281 | package CFClient::UI::Entry; |
1326 | package CFClient::UI::Entry; |
1282 | |
1327 | |
1283 | our @ISA = CFClient::UI::EntryBase::; |
1328 | our @ISA = CFClient::UI::EntryBase::; |
1284 | |
1329 | |
1285 | use SDL; |
1330 | use CFClient::OpenGL; |
1286 | use SDL::OpenGL; |
|
|
1287 | |
1331 | |
1288 | sub key_down { |
1332 | sub key_down { |
1289 | my ($self, $ev) = @_; |
1333 | my ($self, $ev) = @_; |
1290 | |
1334 | |
1291 | my $sym = $ev->key_sym; |
1335 | my $sym = $ev->{sym}; |
1292 | |
1336 | |
1293 | if ($sym == SDLK_RETURN) { |
1337 | if ($sym == 13) { |
1294 | $self->emit (activate => $self->get_text); |
1338 | $self->emit (activate => $self->get_text); |
1295 | $self->update; |
1339 | $self->update; |
1296 | |
1340 | |
1297 | } else { |
1341 | } else { |
1298 | $self->SUPER::key_down ($ev); |
1342 | $self->SUPER::key_down ($ev); |
… | |
… | |
1304 | |
1348 | |
1305 | package CFClient::UI::Button; |
1349 | package CFClient::UI::Button; |
1306 | |
1350 | |
1307 | our @ISA = CFClient::UI::Label::; |
1351 | our @ISA = CFClient::UI::Label::; |
1308 | |
1352 | |
1309 | use SDL; |
1353 | use CFClient::OpenGL; |
1310 | use SDL::OpenGL; |
|
|
1311 | |
1354 | |
1312 | my @tex = |
1355 | my @tex = |
1313 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1356 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1314 | qw(b1_button_active.png); |
1357 | qw(b1_button_active.png); |
1315 | |
1358 | |
1316 | sub new { |
1359 | sub new { |
1317 | my $class = shift; |
1360 | my $class = shift; |
1318 | |
1361 | |
… | |
… | |
1365 | package CFClient::UI::CheckBox; |
1408 | package CFClient::UI::CheckBox; |
1366 | |
1409 | |
1367 | our @ISA = CFClient::UI::DrawBG::; |
1410 | our @ISA = CFClient::UI::DrawBG::; |
1368 | |
1411 | |
1369 | my @tex = |
1412 | my @tex = |
1370 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1413 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1371 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1414 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1372 | |
1415 | |
1373 | use SDL; |
1416 | use CFClient::OpenGL; |
1374 | use SDL::OpenGL; |
|
|
1375 | |
1417 | |
1376 | sub new { |
1418 | sub new { |
1377 | my $class = shift; |
1419 | my $class = shift; |
1378 | |
1420 | |
1379 | $class->SUPER::new ( |
1421 | $class->SUPER::new ( |
… | |
… | |
1425 | glDisable GL_BLEND; |
1467 | glDisable GL_BLEND; |
1426 | } |
1468 | } |
1427 | |
1469 | |
1428 | ############################################################################# |
1470 | ############################################################################# |
1429 | |
1471 | |
1430 | package CFClient::UI::VGauge; |
1472 | package CFClient::UI::Image; |
1431 | |
1473 | |
1432 | our @ISA = CFClient::UI::Base::; |
1474 | our @ISA = CFClient::UI::Base::; |
1433 | |
1475 | |
1434 | use SDL::OpenGL; |
1476 | use CFClient::OpenGL; |
|
|
1477 | use Carp qw/confess/; |
1435 | |
1478 | |
1436 | my %tex = ( |
1479 | our %loaded_images; |
1437 | food => [ |
|
|
1438 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1439 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1440 | ], |
|
|
1441 | grace => [ |
|
|
1442 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1443 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1444 | ], |
|
|
1445 | hp => [ |
|
|
1446 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1447 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1448 | ], |
|
|
1449 | mana => [ |
|
|
1450 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1451 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1452 | ], |
|
|
1453 | ); |
|
|
1454 | |
1480 | |
1455 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1456 | sub new { |
1481 | sub new { |
1457 | my $class = shift; |
1482 | my $class = shift; |
1458 | |
1483 | |
1459 | my $self = $class->SUPER::new (gauge => 'food', @_); |
1484 | my $self = $class->SUPER::new (@_); |
|
|
1485 | |
|
|
1486 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
|
|
1487 | |
|
|
1488 | $loaded_images{$self->{image}} ||= |
|
|
1489 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
|
|
1490 | |
|
|
1491 | my $tex = $self->{tex} = $loaded_images{$self->{image}}; |
|
|
1492 | |
|
|
1493 | $self->{aspect} = $tex->{w} / $tex->{h}; |
1460 | |
1494 | |
1461 | $self |
1495 | $self |
1462 | } |
1496 | } |
1463 | |
1497 | |
1464 | sub size_request { |
1498 | sub size_request { |
1465 | my ($self) = @_; |
1499 | my ($self) = @_; |
1466 | |
1500 | |
1467 | my $tex = $tex{$self->{gauge}}[0]; |
1501 | ($self->{tex}->{w}, $self->{tex}->{h}) |
1468 | |
|
|
1469 | @$tex{qw(w h)} |
|
|
1470 | } |
|
|
1471 | |
|
|
1472 | sub set_max { |
|
|
1473 | my ($self, $max) = @_; |
|
|
1474 | |
|
|
1475 | $self->{max_val} = $max; |
|
|
1476 | } |
|
|
1477 | |
|
|
1478 | sub set_value { |
|
|
1479 | my ($self, $val, $max) = @_; |
|
|
1480 | |
|
|
1481 | $self->set_max ($max) |
|
|
1482 | if defined $max; |
|
|
1483 | |
|
|
1484 | $max = $self->{max_val}; |
|
|
1485 | $self->{val} = $val; |
|
|
1486 | |
|
|
1487 | $self->update; |
|
|
1488 | } |
1502 | } |
1489 | |
1503 | |
1490 | sub _draw { |
1504 | sub _draw { |
1491 | my ($self) = @_; |
1505 | my ($self) = @_; |
1492 | |
1506 | |
1493 | my $tex = $tex{$self->{gauge}}; |
1507 | my $tex = $self->{tex}; |
1494 | |
1508 | |
1495 | my ($w, $h) = ($self->{w}, $self->{h}); |
1509 | my ($w, $h) = ($self->{w}, $self->{h}); |
1496 | |
1510 | |
1497 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1511 | if ($self->{rot90}) { |
1498 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1512 | glRotate 90, 0, 0, 1; |
|
|
1513 | glTranslate 0, -$self->{w}, 0; |
1499 | |
1514 | |
1500 | my $t1 = $tex->[0]; |
1515 | ($w, $h) = ($h, $w); |
1501 | my $t2 = $tex->[1]; |
1516 | } |
1502 | |
1517 | |
1503 | glEnable GL_BLEND; |
1518 | glEnable GL_BLEND; |
1504 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1519 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1505 | glEnable GL_TEXTURE_2D; |
1520 | glEnable GL_TEXTURE_2D; |
1506 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1521 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1507 | |
1522 | |
|
|
1523 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1524 | |
|
|
1525 | glDisable GL_BLEND; |
|
|
1526 | glDisable GL_TEXTURE_2D; |
|
|
1527 | } |
|
|
1528 | |
|
|
1529 | ############################################################################# |
|
|
1530 | |
|
|
1531 | package CFClient::UI::VGauge; |
|
|
1532 | |
|
|
1533 | our @ISA = CFClient::UI::Base::; |
|
|
1534 | |
|
|
1535 | use CFClient::OpenGL; |
|
|
1536 | |
|
|
1537 | my %tex = ( |
|
|
1538 | food => [ |
|
|
1539 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1540 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1541 | ], |
|
|
1542 | grace => [ |
|
|
1543 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1544 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1545 | ], |
|
|
1546 | hp => [ |
|
|
1547 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1548 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1549 | ], |
|
|
1550 | mana => [ |
|
|
1551 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1552 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1553 | ], |
|
|
1554 | ); |
|
|
1555 | |
|
|
1556 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1557 | sub new { |
|
|
1558 | my $class = shift; |
|
|
1559 | |
|
|
1560 | my $self = $class->SUPER::new ( |
|
|
1561 | type => 'food', |
|
|
1562 | @_ |
|
|
1563 | ); |
|
|
1564 | |
|
|
1565 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
|
|
1566 | |
|
|
1567 | $self |
|
|
1568 | } |
|
|
1569 | |
|
|
1570 | sub size_request { |
|
|
1571 | my ($self) = @_; |
|
|
1572 | |
|
|
1573 | #my $tex = $tex{$self->{type}}[0]; |
|
|
1574 | #@$tex{qw(w h)} |
|
|
1575 | (0, 0) |
|
|
1576 | } |
|
|
1577 | |
|
|
1578 | sub set_max { |
|
|
1579 | my ($self, $max) = @_; |
|
|
1580 | |
|
|
1581 | $self->{max_val} = $max; |
|
|
1582 | } |
|
|
1583 | |
|
|
1584 | sub set_value { |
|
|
1585 | my ($self, $val, $max) = @_; |
|
|
1586 | |
|
|
1587 | $self->set_max ($max) |
|
|
1588 | if defined $max; |
|
|
1589 | |
|
|
1590 | $max = $self->{max_val}; |
|
|
1591 | $self->{val} = $val; |
|
|
1592 | |
|
|
1593 | $self->update; |
|
|
1594 | } |
|
|
1595 | |
|
|
1596 | sub _draw { |
|
|
1597 | my ($self) = @_; |
|
|
1598 | |
|
|
1599 | my $tex = $tex{$self->{type}}; |
|
|
1600 | |
|
|
1601 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1602 | |
|
|
1603 | if ($self->{vertical}) { |
|
|
1604 | glRotate 90, 0, 0, 1; |
|
|
1605 | glTranslate 0, -$self->{w}, 0; |
|
|
1606 | |
|
|
1607 | ($w, $h) = ($h, $w); |
|
|
1608 | } |
|
|
1609 | |
|
|
1610 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1611 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1612 | |
|
|
1613 | my $t1 = $tex->[0]; |
|
|
1614 | my $t2 = $tex->[1]; |
|
|
1615 | |
|
|
1616 | glEnable GL_BLEND; |
|
|
1617 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1618 | glEnable GL_TEXTURE_2D; |
|
|
1619 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1620 | |
1508 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1621 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1509 | my $h2 = $ycut * $self->{h}; |
1622 | my $h2 = $ycut * $self->{h}; |
1510 | |
1623 | |
1511 | my $yp = 0; |
|
|
1512 | |
|
|
1513 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1624 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1514 | glBegin GL_QUADS; |
1625 | glBegin GL_QUADS; |
1515 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1626 | glTexCoord 0 , 0; glVertex 0 , 0; |
1516 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1627 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1517 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1628 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1518 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1629 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1519 | glEnd; |
1630 | glEnd; |
1520 | |
|
|
1521 | $yp += $h1; |
|
|
1522 | |
1631 | |
1523 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1632 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1524 | glBegin GL_QUADS; |
1633 | glBegin GL_QUADS; |
1525 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1634 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1526 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1635 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1527 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
1636 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1528 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1637 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1529 | glEnd; |
1638 | glEnd; |
1530 | |
1639 | |
1531 | glDisable GL_BLEND; |
1640 | glDisable GL_BLEND; |
1532 | glDisable GL_TEXTURE_2D; |
1641 | glDisable GL_TEXTURE_2D; |
1533 | } |
1642 | } |
1534 | |
1643 | |
1535 | ############################################################################# |
1644 | ############################################################################# |
1536 | |
1645 | |
|
|
1646 | package CFClient::UI::Gauge; |
|
|
1647 | |
|
|
1648 | our @ISA = CFClient::UI::VBox::; |
|
|
1649 | |
|
|
1650 | sub new { |
|
|
1651 | my ($class, %arg) = shift; |
|
|
1652 | |
|
|
1653 | my $self = $class->SUPER::new ( |
|
|
1654 | @_, |
|
|
1655 | ); |
|
|
1656 | |
|
|
1657 | $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1658 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
|
|
1659 | $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1660 | |
|
|
1661 | $self |
|
|
1662 | } |
|
|
1663 | |
|
|
1664 | sub set_fontsize { |
|
|
1665 | my ($self, $fsize) = @_; |
|
|
1666 | |
|
|
1667 | $self->{value}->set_fontsize ($fsize); |
|
|
1668 | $self->{max} ->set_fontsize ($fsize); |
|
|
1669 | $self->update; |
|
|
1670 | } |
|
|
1671 | |
|
|
1672 | sub set_value { |
|
|
1673 | my ($self, $val, $max) = @_; |
|
|
1674 | |
|
|
1675 | $self->set_max ($max) |
|
|
1676 | if defined $max; |
|
|
1677 | |
|
|
1678 | $self->{gauge}->set_value ($val, $max); |
|
|
1679 | $self->{value}->set_text ($val); |
|
|
1680 | } |
|
|
1681 | |
|
|
1682 | sub set_max { |
|
|
1683 | my ($self, $max) = @_; |
|
|
1684 | |
|
|
1685 | $self->{gauge}->set_max ($max); |
|
|
1686 | $self->{max}->set_text ($max); |
|
|
1687 | } |
|
|
1688 | |
|
|
1689 | ############################################################################# |
|
|
1690 | |
1537 | package CFClient::UI::Slider; |
1691 | package CFClient::UI::Slider; |
1538 | |
1692 | |
1539 | use strict; |
1693 | use strict; |
1540 | |
1694 | |
1541 | use SDL::OpenGL; |
1695 | use CFClient::OpenGL; |
1542 | |
1696 | |
1543 | our @ISA = CFClient::UI::DrawBG::; |
1697 | our @ISA = CFClient::UI::DrawBG::; |
1544 | |
1698 | |
1545 | my @tex = |
1699 | my @tex = |
1546 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1700 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1671 | |
1825 | |
1672 | package CFClient::UI::TextView; |
1826 | package CFClient::UI::TextView; |
1673 | |
1827 | |
1674 | our @ISA = CFClient::UI::HBox::; |
1828 | our @ISA = CFClient::UI::HBox::; |
1675 | |
1829 | |
1676 | use SDL::OpenGL; |
1830 | use CFClient::OpenGL; |
1677 | |
1831 | |
1678 | sub new { |
1832 | sub new { |
1679 | my $class = shift; |
1833 | my $class = shift; |
1680 | |
1834 | |
1681 | my $self = $class->SUPER::new ( |
1835 | my $self = $class->SUPER::new ( |
… | |
… | |
1825 | |
1979 | |
1826 | } |
1980 | } |
1827 | |
1981 | |
1828 | ############################################################################# |
1982 | ############################################################################# |
1829 | |
1983 | |
1830 | package CFClient::UI::MapWidget; |
|
|
1831 | |
|
|
1832 | use strict; |
|
|
1833 | |
|
|
1834 | use List::Util qw(min max); |
|
|
1835 | |
|
|
1836 | use SDL; |
|
|
1837 | use SDL::OpenGL; |
|
|
1838 | |
|
|
1839 | our @ISA = CFClient::UI::Base::; |
|
|
1840 | |
|
|
1841 | sub new { |
|
|
1842 | my $class = shift; |
|
|
1843 | |
|
|
1844 | $class->SUPER::new ( |
|
|
1845 | z => -1, |
|
|
1846 | can_focus => 1, |
|
|
1847 | list => (glGenLists 1), |
|
|
1848 | @_ |
|
|
1849 | ) |
|
|
1850 | } |
|
|
1851 | |
|
|
1852 | sub key_down { |
|
|
1853 | print "MAPKEYDOWN\n"; |
|
|
1854 | } |
|
|
1855 | |
|
|
1856 | sub key_up { |
|
|
1857 | } |
|
|
1858 | |
|
|
1859 | sub button_down { |
|
|
1860 | my ($self, $ev, $x, $y) = @_; |
|
|
1861 | |
|
|
1862 | $self->focus_in; |
|
|
1863 | |
|
|
1864 | if ($ev->button == 2) { |
|
|
1865 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1866 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1867 | |
|
|
1868 | $self->{motion} = sub { |
|
|
1869 | my ($ev, $x, $y) = @_; |
|
|
1870 | |
|
|
1871 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1872 | |
|
|
1873 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1874 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1875 | |
|
|
1876 | $self->update; |
|
|
1877 | }; |
|
|
1878 | } |
|
|
1879 | } |
|
|
1880 | |
|
|
1881 | sub button_up { |
|
|
1882 | my ($self, $ev, $x, $y) = @_; |
|
|
1883 | |
|
|
1884 | delete $self->{motion}; |
|
|
1885 | } |
|
|
1886 | |
|
|
1887 | sub mouse_motion { |
|
|
1888 | my ($self, $ev, $x, $y) = @_; |
|
|
1889 | |
|
|
1890 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1891 | } |
|
|
1892 | |
|
|
1893 | sub size_request { |
|
|
1894 | ( |
|
|
1895 | 1 + 32 * int $::WIDTH / 32, |
|
|
1896 | 1 + 32 * int $::HEIGHT / 32, |
|
|
1897 | ) |
|
|
1898 | } |
|
|
1899 | |
|
|
1900 | sub update { |
|
|
1901 | my ($self) = @_; |
|
|
1902 | |
|
|
1903 | $self->{need_update} = 1; |
|
|
1904 | $self->SUPER::update; |
|
|
1905 | } |
|
|
1906 | |
|
|
1907 | sub draw { |
|
|
1908 | my ($self) = @_; |
|
|
1909 | |
|
|
1910 | if (delete $self->{need_update}) { |
|
|
1911 | glNewList $self->{list}, GL_COMPILE; |
|
|
1912 | |
|
|
1913 | if ($::MAP) { |
|
|
1914 | my $sw = int $::WIDTH / 32; |
|
|
1915 | my $sh = int $::HEIGHT / 32; |
|
|
1916 | |
|
|
1917 | my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
1918 | my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
1919 | |
|
|
1920 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
|
|
1921 | |
|
|
1922 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
|
|
1923 | |
|
|
1924 | if ($::CFG->{fow_enable}) { |
|
|
1925 | if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
1926 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
1927 | glConvolutionFilter2D ( |
|
|
1928 | GL_CONVOLUTION_2D, |
|
|
1929 | GL_ALPHA, |
|
|
1930 | 3, 3, |
|
|
1931 | GL_ALPHA, GL_FLOAT, |
|
|
1932 | pack "f*", |
|
|
1933 | 0.1, 0.1, 0.1, |
|
|
1934 | 0.1, 0.2, 0.1, |
|
|
1935 | 0.1, 0.1, 0.1, |
|
|
1936 | ); |
|
|
1937 | glEnable GL_CONVOLUTION_2D; |
|
|
1938 | } |
|
|
1939 | |
|
|
1940 | $self->{fow_texture} = new CFClient::Texture |
|
|
1941 | w => $w, |
|
|
1942 | h => $h, |
|
|
1943 | data => $data, |
|
|
1944 | internalformat => GL_ALPHA, |
|
|
1945 | format => GL_ALPHA; |
|
|
1946 | |
|
|
1947 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1948 | |
|
|
1949 | glEnable GL_BLEND; |
|
|
1950 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1951 | glEnable GL_TEXTURE_2D; |
|
|
1952 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1953 | |
|
|
1954 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1955 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1956 | |
|
|
1957 | glDisable GL_TEXTURE_2D; |
|
|
1958 | glDisable GL_BLEND; |
|
|
1959 | } |
|
|
1960 | |
|
|
1961 | # HACK BEGIN |
|
|
1962 | { |
|
|
1963 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
1964 | my ($w, $h) = (250, 250); |
|
|
1965 | |
|
|
1966 | glEnable GL_BLEND; |
|
|
1967 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1968 | glEnable GL_TEXTURE_2D; |
|
|
1969 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1970 | |
|
|
1971 | $self->{mapmap_texture} = |
|
|
1972 | new CFClient::Texture |
|
|
1973 | w => $w, |
|
|
1974 | h => $h, |
|
|
1975 | data => $::MAP->mapmap ($w, $h), |
|
|
1976 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
|
|
1977 | |
|
|
1978 | $self->{mapmap_texture}->draw_quad (100, 100); |
|
|
1979 | |
|
|
1980 | glDisable GL_TEXTURE_2D; |
|
|
1981 | glDisable GL_BLEND; |
|
|
1982 | } |
|
|
1983 | # HACK END |
|
|
1984 | } |
|
|
1985 | |
|
|
1986 | glEndList; |
|
|
1987 | } |
|
|
1988 | |
|
|
1989 | glPushMatrix; |
|
|
1990 | glCallList $self->{list}; |
|
|
1991 | glPopMatrix; |
|
|
1992 | |
|
|
1993 | if ($FOCUS != $self) { |
|
|
1994 | glColor 64/255, 64/255, 64/255; |
|
|
1995 | glLogicOp GL_AND; |
|
|
1996 | glEnable GL_COLOR_LOGIC_OP; |
|
|
1997 | glBegin GL_QUADS; |
|
|
1998 | glVertex 0, 0; |
|
|
1999 | glVertex 0, $::HEIGHT; |
|
|
2000 | glVertex $::WIDTH, $::HEIGHT; |
|
|
2001 | glVertex $::WIDTH, 0; |
|
|
2002 | glEnd; |
|
|
2003 | glDisable GL_COLOR_LOGIC_OP; |
|
|
2004 | } |
|
|
2005 | } |
|
|
2006 | |
|
|
2007 | my %DIR = ( |
|
|
2008 | SDLK_KP8, [1, "north"], |
|
|
2009 | SDLK_KP9, [2, "northeast"], |
|
|
2010 | SDLK_KP6, [3, "east"], |
|
|
2011 | SDLK_KP3, [4, "southeast"], |
|
|
2012 | SDLK_KP2, [5, "south"], |
|
|
2013 | SDLK_KP1, [6, "southwest"], |
|
|
2014 | SDLK_KP4, [7, "west"], |
|
|
2015 | SDLK_KP7, [8, "northwest"], |
|
|
2016 | |
|
|
2017 | SDLK_UP, [1, "north"], |
|
|
2018 | SDLK_RIGHT, [3, "east"], |
|
|
2019 | SDLK_DOWN, [5, "south"], |
|
|
2020 | SDLK_LEFT, [7, "west"], |
|
|
2021 | ); |
|
|
2022 | |
|
|
2023 | sub key_down { |
|
|
2024 | my ($self, $ev) = @_; |
|
|
2025 | |
|
|
2026 | my $mod = $ev->key_mod; |
|
|
2027 | my $sym = $ev->key_sym; |
|
|
2028 | |
|
|
2029 | if ($sym == SDLK_KP5) { |
|
|
2030 | $::CONN->user_send ("stay fire"); |
|
|
2031 | } elsif ($sym == SDLK_a) { |
|
|
2032 | $::CONN->user_send ("apply"); |
|
|
2033 | } elsif ($sym == SDLK_QUOTE) { |
|
|
2034 | $self->emit ('activate_console'); |
|
|
2035 | } elsif ($sym == SDLK_SLASH) { |
|
|
2036 | $self->emit ('activate_console' => '/'); |
|
|
2037 | } elsif (exists $DIR{$sym}) { |
|
|
2038 | if ($mod & KMOD_SHIFT) { |
|
|
2039 | $self->{shft}++; |
|
|
2040 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
2041 | } elsif ($mod & KMOD_CTRL) { |
|
|
2042 | $self->{ctrl}++; |
|
|
2043 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
2044 | } else { |
|
|
2045 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
2046 | } |
|
|
2047 | } |
|
|
2048 | } |
|
|
2049 | |
|
|
2050 | sub key_up { |
|
|
2051 | my ($self, $ev) = @_; |
|
|
2052 | |
|
|
2053 | my $mod = $ev->key_mod; |
|
|
2054 | my $sym = $ev->key_sym; |
|
|
2055 | |
|
|
2056 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
|
|
2057 | $::CONN->user_send ("fire_stop"); |
|
|
2058 | } |
|
|
2059 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
2060 | $::CONN->user_send ("run_stop"); |
|
|
2061 | } |
|
|
2062 | } |
|
|
2063 | |
|
|
2064 | ############################################################################# |
|
|
2065 | |
|
|
2066 | package CFClient::UI::Animator; |
1984 | package CFClient::UI::Animator; |
2067 | |
1985 | |
2068 | use SDL::OpenGL; |
1986 | use CFClient::OpenGL; |
2069 | |
1987 | |
2070 | our @ISA = CFClient::UI::Bin::; |
1988 | our @ISA = CFClient::UI::Bin::; |
2071 | |
1989 | |
2072 | sub moveto { |
1990 | sub moveto { |
2073 | my ($self, $x, $y) = @_; |
1991 | my ($self, $x, $y) = @_; |
… | |
… | |
2146 | |
2064 | |
2147 | package CFClient::UI::Root; |
2065 | package CFClient::UI::Root; |
2148 | |
2066 | |
2149 | our @ISA = CFClient::UI::Container::; |
2067 | our @ISA = CFClient::UI::Container::; |
2150 | |
2068 | |
2151 | use SDL::OpenGL; |
2069 | use CFClient::OpenGL; |
2152 | |
2070 | |
2153 | sub check_size { |
2071 | sub check_size { |
2154 | my ($self) = @_; |
2072 | my ($self) = @_; |
2155 | |
2073 | |
2156 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2074 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
… | |
… | |
2182 | ::refresh (); |
2100 | ::refresh (); |
2183 | } |
2101 | } |
2184 | |
2102 | |
2185 | sub add { |
2103 | sub add { |
2186 | my ($self, $child) = @_; |
2104 | my ($self, $child) = @_; |
|
|
2105 | |
|
|
2106 | # integerize window positions |
|
|
2107 | $child->{x} = int $child->{x}; |
|
|
2108 | $child->{y} = int $child->{y}; |
2187 | |
2109 | |
2188 | $self->SUPER::add ($child); |
2110 | $self->SUPER::add ($child); |
2189 | } |
2111 | } |
2190 | |
2112 | |
2191 | sub on_refresh { |
2113 | sub on_refresh { |