… | |
… | |
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 { |
… | |
… | |
140 | 0 |
140 | 0 |
141 | } |
141 | } |
142 | |
142 | |
143 | sub size_request { |
143 | sub size_request { |
144 | require Carp; |
144 | require Carp; |
145 | Carp::confess "size_request is abtract"; |
145 | Carp::confess "size_request is abstract"; |
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 += int +($w - $w2) * 0.5; |
|
|
158 | $y += int +($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->check_size; |
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::OpenGL; |
1163 | use CFClient::OpenGL; |
1117 | |
1164 | |
1118 | sub new { |
1165 | sub new { |
1119 | my $class = shift; |
1166 | my $class = shift; |
1120 | |
1167 | |
1121 | $class->SUPER::new ( |
1168 | $class->SUPER::new ( |
… | |
… | |
1175 | } |
1222 | } |
1176 | |
1223 | |
1177 | sub key_down { |
1224 | sub key_down { |
1178 | my ($self, $ev) = @_; |
1225 | my ($self, $ev) = @_; |
1179 | |
1226 | |
1180 | my $mod = $ev->key_mod; |
1227 | my $mod = $ev->{mod}; |
1181 | my $sym = $ev->key_sym; |
1228 | my $sym = $ev->{sym}; |
1182 | |
|
|
1183 | my $uni = $ev->key_unicode; |
1229 | my $uni = $ev->{unicode}; |
1184 | |
1230 | |
1185 | my $text = $self->get_text; |
1231 | my $text = $self->get_text; |
1186 | |
1232 | |
1187 | if ($sym == 8) { |
1233 | if ($sym == 8) { |
1188 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1234 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
… | |
… | |
1279 | |
1325 | |
1280 | package CFClient::UI::Entry; |
1326 | package CFClient::UI::Entry; |
1281 | |
1327 | |
1282 | our @ISA = CFClient::UI::EntryBase::; |
1328 | our @ISA = CFClient::UI::EntryBase::; |
1283 | |
1329 | |
1284 | use SDL::OpenGL; |
1330 | use CFClient::OpenGL; |
1285 | |
1331 | |
1286 | sub key_down { |
1332 | sub key_down { |
1287 | my ($self, $ev) = @_; |
1333 | my ($self, $ev) = @_; |
1288 | |
1334 | |
1289 | my $sym = $ev->key_sym; |
1335 | my $sym = $ev->{sym}; |
1290 | |
1336 | |
1291 | if ($sym == 13) { |
1337 | if ($sym == 13) { |
1292 | $self->emit (activate => $self->get_text); |
1338 | $self->emit (activate => $self->get_text); |
1293 | $self->update; |
1339 | $self->update; |
1294 | |
1340 | |
… | |
… | |
1302 | |
1348 | |
1303 | package CFClient::UI::Button; |
1349 | package CFClient::UI::Button; |
1304 | |
1350 | |
1305 | our @ISA = CFClient::UI::Label::; |
1351 | our @ISA = CFClient::UI::Label::; |
1306 | |
1352 | |
1307 | use SDL::OpenGL; |
1353 | use CFClient::OpenGL; |
1308 | |
1354 | |
1309 | my @tex = |
1355 | my @tex = |
1310 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1356 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1311 | qw(b1_button_active.png); |
1357 | qw(b1_button_active.png); |
1312 | |
1358 | |
1313 | sub new { |
1359 | sub new { |
1314 | my $class = shift; |
1360 | my $class = shift; |
1315 | |
1361 | |
… | |
… | |
1362 | package CFClient::UI::CheckBox; |
1408 | package CFClient::UI::CheckBox; |
1363 | |
1409 | |
1364 | our @ISA = CFClient::UI::DrawBG::; |
1410 | our @ISA = CFClient::UI::DrawBG::; |
1365 | |
1411 | |
1366 | my @tex = |
1412 | my @tex = |
1367 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1413 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1368 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1414 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1369 | |
1415 | |
1370 | use SDL::OpenGL; |
1416 | use CFClient::OpenGL; |
1371 | |
1417 | |
1372 | sub new { |
1418 | sub new { |
1373 | my $class = shift; |
1419 | my $class = shift; |
1374 | |
1420 | |
1375 | $class->SUPER::new ( |
1421 | $class->SUPER::new ( |
… | |
… | |
1421 | glDisable GL_BLEND; |
1467 | glDisable GL_BLEND; |
1422 | } |
1468 | } |
1423 | |
1469 | |
1424 | ############################################################################# |
1470 | ############################################################################# |
1425 | |
1471 | |
1426 | package CFClient::UI::VGauge; |
1472 | package CFClient::UI::Image; |
1427 | |
1473 | |
1428 | our @ISA = CFClient::UI::Base::; |
1474 | our @ISA = CFClient::UI::Base::; |
1429 | |
1475 | |
1430 | use SDL::OpenGL; |
1476 | use CFClient::OpenGL; |
|
|
1477 | use Carp qw/confess/; |
1431 | |
1478 | |
1432 | my %tex = ( |
1479 | our %loaded_images; |
1433 | food => [ |
|
|
1434 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1435 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1436 | ], |
|
|
1437 | grace => [ |
|
|
1438 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1439 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1440 | ], |
|
|
1441 | hp => [ |
|
|
1442 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1443 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1444 | ], |
|
|
1445 | mana => [ |
|
|
1446 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1447 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1448 | ], |
|
|
1449 | ); |
|
|
1450 | |
1480 | |
1451 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1452 | sub new { |
1481 | sub new { |
1453 | my $class = shift; |
1482 | my $class = shift; |
1454 | |
1483 | |
1455 | 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 | Scalar::Util::weaken $loaded_images{$self->{image}}; |
|
|
1494 | |
|
|
1495 | $self->{aspect} = $tex->{w} / $tex->{h}; |
1456 | |
1496 | |
1457 | $self |
1497 | $self |
1458 | } |
1498 | } |
1459 | |
1499 | |
1460 | sub size_request { |
1500 | sub size_request { |
1461 | my ($self) = @_; |
1501 | my ($self) = @_; |
1462 | |
1502 | |
1463 | my $tex = $tex{$self->{gauge}}[0]; |
1503 | ($self->{tex}->{w}, $self->{tex}->{h}) |
1464 | |
|
|
1465 | @$tex{qw(w h)} |
|
|
1466 | } |
|
|
1467 | |
|
|
1468 | sub set_max { |
|
|
1469 | my ($self, $max) = @_; |
|
|
1470 | |
|
|
1471 | $self->{max_val} = $max; |
|
|
1472 | } |
|
|
1473 | |
|
|
1474 | sub set_value { |
|
|
1475 | my ($self, $val, $max) = @_; |
|
|
1476 | |
|
|
1477 | $self->set_max ($max) |
|
|
1478 | if defined $max; |
|
|
1479 | |
|
|
1480 | $max = $self->{max_val}; |
|
|
1481 | $self->{val} = $val; |
|
|
1482 | |
|
|
1483 | $self->update; |
|
|
1484 | } |
1504 | } |
1485 | |
1505 | |
1486 | sub _draw { |
1506 | sub _draw { |
1487 | my ($self) = @_; |
1507 | my ($self) = @_; |
1488 | |
1508 | |
1489 | my $tex = $tex{$self->{gauge}}; |
1509 | my $tex = $self->{tex}; |
1490 | |
1510 | |
1491 | my ($w, $h) = ($self->{w}, $self->{h}); |
1511 | my ($w, $h) = ($self->{w}, $self->{h}); |
1492 | |
1512 | |
1493 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1513 | if ($self->{rot90}) { |
1494 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1514 | glRotate 90, 0, 0, 1; |
|
|
1515 | glTranslate 0, -$self->{w}, 0; |
1495 | |
1516 | |
1496 | my $t1 = $tex->[0]; |
1517 | ($w, $h) = ($h, $w); |
1497 | my $t2 = $tex->[1]; |
1518 | } |
1498 | |
1519 | |
1499 | glEnable GL_BLEND; |
1520 | glEnable GL_BLEND; |
1500 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1521 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1501 | glEnable GL_TEXTURE_2D; |
1522 | glEnable GL_TEXTURE_2D; |
1502 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1523 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1503 | |
1524 | |
|
|
1525 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1526 | |
|
|
1527 | glDisable GL_BLEND; |
|
|
1528 | glDisable GL_TEXTURE_2D; |
|
|
1529 | } |
|
|
1530 | |
|
|
1531 | ############################################################################# |
|
|
1532 | |
|
|
1533 | package CFClient::UI::VGauge; |
|
|
1534 | |
|
|
1535 | our @ISA = CFClient::UI::Base::; |
|
|
1536 | |
|
|
1537 | use CFClient::OpenGL; |
|
|
1538 | |
|
|
1539 | my %tex = ( |
|
|
1540 | food => [ |
|
|
1541 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1542 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1543 | ], |
|
|
1544 | grace => [ |
|
|
1545 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1546 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1547 | ], |
|
|
1548 | hp => [ |
|
|
1549 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1550 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1551 | ], |
|
|
1552 | mana => [ |
|
|
1553 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1554 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1555 | ], |
|
|
1556 | ); |
|
|
1557 | |
|
|
1558 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1559 | sub new { |
|
|
1560 | my $class = shift; |
|
|
1561 | |
|
|
1562 | my $self = $class->SUPER::new ( |
|
|
1563 | type => 'food', |
|
|
1564 | @_ |
|
|
1565 | ); |
|
|
1566 | |
|
|
1567 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
|
|
1568 | |
|
|
1569 | $self |
|
|
1570 | } |
|
|
1571 | |
|
|
1572 | sub size_request { |
|
|
1573 | my ($self) = @_; |
|
|
1574 | |
|
|
1575 | #my $tex = $tex{$self->{type}}[0]; |
|
|
1576 | #@$tex{qw(w h)} |
|
|
1577 | (0, 0) |
|
|
1578 | } |
|
|
1579 | |
|
|
1580 | sub set_max { |
|
|
1581 | my ($self, $max) = @_; |
|
|
1582 | |
|
|
1583 | $self->{max_val} = $max; |
|
|
1584 | } |
|
|
1585 | |
|
|
1586 | sub set_value { |
|
|
1587 | my ($self, $val, $max) = @_; |
|
|
1588 | |
|
|
1589 | $self->set_max ($max) |
|
|
1590 | if defined $max; |
|
|
1591 | |
|
|
1592 | $max = $self->{max_val}; |
|
|
1593 | $self->{val} = $val; |
|
|
1594 | |
|
|
1595 | $self->update; |
|
|
1596 | } |
|
|
1597 | |
|
|
1598 | sub _draw { |
|
|
1599 | my ($self) = @_; |
|
|
1600 | |
|
|
1601 | my $tex = $tex{$self->{type}}; |
|
|
1602 | |
|
|
1603 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1604 | |
|
|
1605 | if ($self->{vertical}) { |
|
|
1606 | glRotate 90, 0, 0, 1; |
|
|
1607 | glTranslate 0, -$self->{w}, 0; |
|
|
1608 | |
|
|
1609 | ($w, $h) = ($h, $w); |
|
|
1610 | } |
|
|
1611 | |
|
|
1612 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1613 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1614 | |
|
|
1615 | my $t1 = $tex->[0]; |
|
|
1616 | my $t2 = $tex->[1]; |
|
|
1617 | |
|
|
1618 | glEnable GL_BLEND; |
|
|
1619 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1620 | glEnable GL_TEXTURE_2D; |
|
|
1621 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1622 | |
1504 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1623 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1505 | my $h2 = $ycut * $self->{h}; |
1624 | my $h2 = $ycut * $self->{h}; |
1506 | |
1625 | |
1507 | my $yp = 0; |
|
|
1508 | |
|
|
1509 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1626 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1510 | glBegin GL_QUADS; |
1627 | glBegin GL_QUADS; |
1511 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1628 | glTexCoord 0 , 0; glVertex 0 , 0; |
1512 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1629 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1513 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1630 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1514 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1631 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1515 | glEnd; |
1632 | glEnd; |
1516 | |
|
|
1517 | $yp += $h1; |
|
|
1518 | |
1633 | |
1519 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1634 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1520 | glBegin GL_QUADS; |
1635 | glBegin GL_QUADS; |
1521 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1636 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1522 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1637 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1523 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
1638 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1524 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1639 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1525 | glEnd; |
1640 | glEnd; |
1526 | |
1641 | |
1527 | glDisable GL_BLEND; |
1642 | glDisable GL_BLEND; |
1528 | glDisable GL_TEXTURE_2D; |
1643 | glDisable GL_TEXTURE_2D; |
1529 | } |
1644 | } |
1530 | |
1645 | |
1531 | ############################################################################# |
1646 | ############################################################################# |
1532 | |
1647 | |
|
|
1648 | package CFClient::UI::Gauge; |
|
|
1649 | |
|
|
1650 | our @ISA = CFClient::UI::VBox::; |
|
|
1651 | |
|
|
1652 | sub new { |
|
|
1653 | my ($class, %arg) = shift; |
|
|
1654 | |
|
|
1655 | my $self = $class->SUPER::new ( |
|
|
1656 | @_, |
|
|
1657 | ); |
|
|
1658 | |
|
|
1659 | $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1660 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
|
|
1661 | $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1662 | |
|
|
1663 | $self |
|
|
1664 | } |
|
|
1665 | |
|
|
1666 | sub set_fontsize { |
|
|
1667 | my ($self, $fsize) = @_; |
|
|
1668 | |
|
|
1669 | $self->{value}->set_fontsize ($fsize); |
|
|
1670 | $self->{max} ->set_fontsize ($fsize); |
|
|
1671 | } |
|
|
1672 | |
|
|
1673 | sub set_value { |
|
|
1674 | my ($self, $val, $max) = @_; |
|
|
1675 | |
|
|
1676 | $self->set_max ($max) |
|
|
1677 | if defined $max; |
|
|
1678 | |
|
|
1679 | $self->{gauge}->set_value ($val, $max); |
|
|
1680 | $self->{value}->set_text ($val); |
|
|
1681 | } |
|
|
1682 | |
|
|
1683 | sub set_max { |
|
|
1684 | my ($self, $max) = @_; |
|
|
1685 | |
|
|
1686 | $self->{gauge}->set_max ($max); |
|
|
1687 | $self->{max}->set_text ($max); |
|
|
1688 | } |
|
|
1689 | |
|
|
1690 | ############################################################################# |
|
|
1691 | |
1533 | package CFClient::UI::Slider; |
1692 | package CFClient::UI::Slider; |
1534 | |
1693 | |
1535 | use strict; |
1694 | use strict; |
1536 | |
1695 | |
1537 | use SDL::OpenGL; |
1696 | use CFClient::OpenGL; |
1538 | |
1697 | |
1539 | our @ISA = CFClient::UI::DrawBG::; |
1698 | our @ISA = CFClient::UI::DrawBG::; |
1540 | |
1699 | |
1541 | my @tex = |
1700 | my @tex = |
1542 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1701 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1667 | |
1826 | |
1668 | package CFClient::UI::TextView; |
1827 | package CFClient::UI::TextView; |
1669 | |
1828 | |
1670 | our @ISA = CFClient::UI::HBox::; |
1829 | our @ISA = CFClient::UI::HBox::; |
1671 | |
1830 | |
1672 | use SDL::OpenGL; |
1831 | use CFClient::OpenGL; |
1673 | |
1832 | |
1674 | sub new { |
1833 | sub new { |
1675 | my $class = shift; |
1834 | my $class = shift; |
1676 | |
1835 | |
1677 | my $self = $class->SUPER::new ( |
1836 | my $self = $class->SUPER::new ( |
… | |
… | |
1823 | |
1982 | |
1824 | ############################################################################# |
1983 | ############################################################################# |
1825 | |
1984 | |
1826 | package CFClient::UI::Animator; |
1985 | package CFClient::UI::Animator; |
1827 | |
1986 | |
1828 | use SDL::OpenGL; |
1987 | use CFClient::OpenGL; |
1829 | |
1988 | |
1830 | our @ISA = CFClient::UI::Bin::; |
1989 | our @ISA = CFClient::UI::Bin::; |
1831 | |
1990 | |
1832 | sub moveto { |
1991 | sub moveto { |
1833 | my ($self, $x, $y) = @_; |
1992 | my ($self, $x, $y) = @_; |
… | |
… | |
1906 | |
2065 | |
1907 | package CFClient::UI::Root; |
2066 | package CFClient::UI::Root; |
1908 | |
2067 | |
1909 | our @ISA = CFClient::UI::Container::; |
2068 | our @ISA = CFClient::UI::Container::; |
1910 | |
2069 | |
1911 | use SDL::OpenGL; |
2070 | use CFClient::OpenGL; |
1912 | |
2071 | |
1913 | sub check_size { |
2072 | sub check_size { |
1914 | my ($self) = @_; |
2073 | my ($self) = @_; |
1915 | |
2074 | |
1916 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2075 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
… | |
… | |
1942 | ::refresh (); |
2101 | ::refresh (); |
1943 | } |
2102 | } |
1944 | |
2103 | |
1945 | sub add { |
2104 | sub add { |
1946 | my ($self, $child) = @_; |
2105 | my ($self, $child) = @_; |
|
|
2106 | |
|
|
2107 | # integerize window positions |
|
|
2108 | $child->{x} = int $child->{x}; |
|
|
2109 | $child->{y} = int $child->{y}; |
1947 | |
2110 | |
1948 | $self->SUPER::add ($child); |
2111 | $self->SUPER::add ($child); |
1949 | } |
2112 | } |
1950 | |
2113 | |
1951 | sub on_refresh { |
2114 | sub on_refresh { |