… | |
… | |
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 | } |
… | |
… | |
279 | } |
294 | } |
280 | |
295 | |
281 | sub check_size { |
296 | sub check_size { |
282 | my ($self) = @_; |
297 | my ($self) = @_; |
283 | |
298 | |
|
|
299 | return unless $self->{parent}; |
|
|
300 | |
284 | my ($w, $h) = $self->size_request; |
301 | my ($w, $h) = $self->size_request; |
285 | |
302 | |
286 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
303 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
287 | $self->{req_w} = $w; |
304 | $self->{req_w} = $w; |
288 | $self->{req_h} = $h; |
305 | $self->{req_h} = $h; |
289 | |
306 | |
290 | $self->{parent}->check_size |
307 | $self->{parent}->check_size; |
291 | if $self->{parent}; |
|
|
292 | } |
308 | } |
293 | } |
309 | } |
294 | |
310 | |
295 | sub update { |
311 | sub update { |
296 | my ($self) = @_; |
312 | my ($self) = @_; |
… | |
… | |
546 | sub new { die } |
562 | sub new { die } |
547 | |
563 | |
548 | sub size_request { |
564 | sub size_request { |
549 | my ($self) = @_; |
565 | my ($self) = @_; |
550 | |
566 | |
551 | @$self{qw(child_w child_h)} = $self->child->size_request; |
567 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
552 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
568 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
553 | |
569 | |
554 | @$self{qw(child_w child_h)} |
570 | @$self{qw(child_w child_h)} |
555 | } |
571 | } |
556 | |
572 | |
… | |
… | |
566 | package CFClient::UI::Frame; |
582 | package CFClient::UI::Frame; |
567 | |
583 | |
568 | our @ISA = CFClient::UI::Bin::; |
584 | our @ISA = CFClient::UI::Bin::; |
569 | |
585 | |
570 | use CFClient::OpenGL; |
586 | use CFClient::OpenGL; |
571 | |
|
|
572 | sub size_request { |
|
|
573 | my ($self) = @_; |
|
|
574 | my $chld = $self->child |
|
|
575 | or return (0, 0); |
|
|
576 | |
|
|
577 | $chld->move (2, 2); |
|
|
578 | |
|
|
579 | map { $_ + 4 } $chld->size_request; |
|
|
580 | } |
|
|
581 | |
|
|
582 | sub size_allocate { |
|
|
583 | my ($self, $x, $y, $w, $h) = @_; |
|
|
584 | |
|
|
585 | $self->child->configure (2, 2, $w - 4, $h - 4); |
|
|
586 | } |
|
|
587 | |
|
|
588 | sub _draw { |
|
|
589 | my ($self) = @_; |
|
|
590 | |
|
|
591 | my $chld = $self->child; |
|
|
592 | |
|
|
593 | my ($w, $h) = $chld->size_request; |
|
|
594 | |
|
|
595 | glBegin GL_QUADS; |
|
|
596 | glColor 0, 0, 0; |
|
|
597 | glVertex 0 , 0; |
|
|
598 | glVertex 0 , $h + 4; |
|
|
599 | glVertex $w + 4 , $h + 4; |
|
|
600 | glVertex $w + 4 , 0; |
|
|
601 | glEnd; |
|
|
602 | |
|
|
603 | $chld->draw; |
|
|
604 | } |
|
|
605 | |
|
|
606 | ############################################################################# |
|
|
607 | |
|
|
608 | package CFClient::UI::FancyFrame; |
|
|
609 | |
|
|
610 | our @ISA = CFClient::UI::Bin::; |
|
|
611 | |
|
|
612 | use CFClient::OpenGL; |
|
|
613 | |
|
|
614 | my @tex = |
|
|
615 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
616 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
617 | |
587 | |
618 | sub new { |
588 | sub new { |
619 | my $class = shift; |
589 | my $class = shift; |
620 | |
590 | |
621 | # TODO: user_x, user_y, overwrite moveto? |
|
|
622 | |
|
|
623 | $class->SUPER::new ( |
591 | my $self = $class->SUPER::new ( |
624 | bg => [1, 1, 1, 1], |
592 | bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
593 | border_bg => [1, 1, 1, 1], |
626 | border => 0.8, |
594 | border => 0.8, |
627 | @_ |
595 | @_ |
628 | ) |
596 | ); |
|
|
597 | |
|
|
598 | $self |
|
|
599 | } |
|
|
600 | |
|
|
601 | sub set_size { |
|
|
602 | my ($self, $w, $h) = @_; |
|
|
603 | $self->{req_w} = $w; |
|
|
604 | $self->{req_h} = $h; |
|
|
605 | $self->check_size; |
|
|
606 | } |
|
|
607 | |
|
|
608 | sub size_request { |
|
|
609 | my ($self) = @_; |
|
|
610 | ($self->{req_w}, $self->{req_h}) |
|
|
611 | } |
|
|
612 | |
|
|
613 | sub size_allocate { |
|
|
614 | my ($self, $w, $h) = @_; |
|
|
615 | $self->{w} = $w; |
|
|
616 | $self->{h} = $h; |
|
|
617 | $self->child->configure (0, 0, $w, $h); |
|
|
618 | } |
|
|
619 | |
|
|
620 | sub _draw { |
|
|
621 | my ($self) = @_; |
|
|
622 | |
|
|
623 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
624 | |
|
|
625 | glEnable GL_BLEND; |
|
|
626 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
627 | glEnable GL_TEXTURE_2D; |
|
|
628 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
629 | |
|
|
630 | # glBegin GL_QUADS; |
|
|
631 | # glColor 0, 0, 0, 0; |
|
|
632 | # glVertex 0 , 0; |
|
|
633 | # glVertex 0 , $h; |
|
|
634 | # glVertex $w, $h; |
|
|
635 | # glVertex $w, 0; |
|
|
636 | # glEnd; |
|
|
637 | |
|
|
638 | |
|
|
639 | $self->child->draw; |
|
|
640 | glDisable GL_BLEND; |
|
|
641 | glDisable GL_TEXTURE_2D; |
|
|
642 | } |
|
|
643 | |
|
|
644 | ############################################################################# |
|
|
645 | |
|
|
646 | package CFClient::UI::FancyFrame; |
|
|
647 | |
|
|
648 | our @ISA = CFClient::UI::Bin::; |
|
|
649 | |
|
|
650 | use CFClient::OpenGL; |
|
|
651 | |
|
|
652 | my @tex = |
|
|
653 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
654 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
655 | |
|
|
656 | sub new { |
|
|
657 | my $class = shift; |
|
|
658 | |
|
|
659 | # TODO: user_x, user_y, overwrite moveto? |
|
|
660 | |
|
|
661 | my $self = $class->SUPER::new ( |
|
|
662 | bg => [1, 1, 1, 1], |
|
|
663 | border_bg => [1, 1, 1, 1], |
|
|
664 | border => 0.8, |
|
|
665 | @_ |
|
|
666 | ); |
|
|
667 | |
|
|
668 | $self->{title} &&= new CFClient::UI::Label |
|
|
669 | align => 0, |
|
|
670 | valign => 1, |
|
|
671 | text => $self->{title}, |
|
|
672 | fontsize => 1; |
|
|
673 | |
|
|
674 | $self |
629 | } |
675 | } |
630 | |
676 | |
631 | sub border { |
677 | sub border { |
632 | int $_[0]{border} * $::FONTSIZE |
678 | int $_[0]{border} * $::FONTSIZE |
633 | } |
679 | } |
… | |
… | |
648 | sub size_allocate { |
694 | sub size_allocate { |
649 | my ($self, $w, $h) = @_; |
695 | my ($self, $w, $h) = @_; |
650 | |
696 | |
651 | $h -= List::Util::max 0, $self->border * 2; |
697 | $h -= List::Util::max 0, $self->border * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
698 | $w -= List::Util::max 0, $self->border * 2; |
|
|
699 | |
|
|
700 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
701 | if $self->{title}; |
653 | |
702 | |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
703 | $self->child->configure ($self->border, $self->border, $w, $h); |
655 | } |
704 | } |
656 | |
705 | |
657 | sub button_down { |
706 | sub button_down { |
… | |
… | |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
786 | $bg->draw_quad ($border, $border, $cw, $ch); |
738 | |
787 | |
739 | glDisable GL_TEXTURE_2D; |
788 | glDisable GL_TEXTURE_2D; |
740 | glDisable GL_BLEND; |
789 | glDisable GL_BLEND; |
741 | |
790 | |
|
|
791 | $self->{title}->draw if $self->{title}; |
742 | $self->child->draw; |
792 | $self->child->draw; |
743 | } |
793 | } |
744 | |
794 | |
745 | ############################################################################# |
795 | ############################################################################# |
746 | |
796 | |
… | |
… | |
788 | or next; |
838 | or next; |
789 | |
839 | |
790 | for my $x (0 .. $#$row) { |
840 | for my $x (0 .. $#$row) { |
791 | my $widget = $row->[$x] |
841 | my $widget = $row->[$x] |
792 | or next; |
842 | or next; |
793 | my ($w, $h) = $widget->size_request; |
843 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
794 | |
844 | |
795 | $w[$x] = max $w[$x], $w; |
845 | $w[$x] = max $w[$x], $w; |
796 | $h[$y] = max $h[$y], $h; |
846 | $h[$y] = max $h[$y], $h; |
797 | } |
847 | } |
798 | } |
848 | } |
… | |
… | |
903 | |
953 | |
904 | ($h, $w) = ($w, $h); |
954 | ($h, $w) = ($w, $h); |
905 | |
955 | |
906 | my $children = $self->{children}; |
956 | my $children = $self->{children}; |
907 | |
957 | |
908 | my @h = map +($_->size_request)[0], @$children; |
958 | my @h = map $_->{req_w}, @$children; |
909 | |
959 | |
910 | my $req_h = List::Util::sum @h; |
960 | my $req_h = List::Util::sum @h; |
911 | |
961 | |
912 | if ($req_h > $h) { |
962 | if ($req_h > $h) { |
913 | # ah well, not enough space |
963 | # ah well, not enough space |
… | |
… | |
961 | sub size_allocate { |
1011 | sub size_allocate { |
962 | my ($self, $w, $h) = @_; |
1012 | my ($self, $w, $h) = @_; |
963 | |
1013 | |
964 | my $children = $self->{children}; |
1014 | my $children = $self->{children}; |
965 | |
1015 | |
966 | my @h = map +($_->size_request)[1], @$children; |
1016 | my @h = map $_->{req_h}, @$children; |
967 | |
1017 | |
968 | my $req_h = List::Util::sum @h; |
1018 | my $req_h = List::Util::sum @h; |
969 | |
1019 | |
970 | if ($req_h > $h) { |
1020 | if ($req_h > $h) { |
971 | # ah well, not enough space |
1021 | # ah well, not enough space |
… | |
… | |
1015 | padding => 2, |
1065 | padding => 2, |
1016 | layout => new CFClient::Layout, |
1066 | layout => new CFClient::Layout, |
1017 | %arg |
1067 | %arg |
1018 | ); |
1068 | ); |
1019 | |
1069 | |
1020 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
1070 | if (exists $self->{template}) { |
|
|
1071 | my $layout = new CFClient::Layout; |
|
|
1072 | $layout->set_text (delete $self->{template}); |
|
|
1073 | $self->{template} = $layout; |
|
|
1074 | } |
1021 | |
1075 | |
1022 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1076 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1023 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1077 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1024 | |
1078 | |
1025 | $self |
1079 | $self |
… | |
… | |
1039 | my ($self, $text) = @_; |
1093 | my ($self, $text) = @_; |
1040 | |
1094 | |
1041 | $self->{layout}->set_text ($text); |
1095 | $self->{layout}->set_text ($text); |
1042 | |
1096 | |
1043 | delete $self->{texture}; |
1097 | delete $self->{texture}; |
|
|
1098 | $self->check_size; |
1044 | $self->update; |
1099 | $self->update; |
1045 | } |
1100 | } |
1046 | |
1101 | |
1047 | sub set_markup { |
1102 | sub set_markup { |
1048 | my ($self, $markup) = @_; |
1103 | my ($self, $markup) = @_; |
1049 | |
1104 | |
1050 | $self->{layout}->set_markup ($markup); |
1105 | $self->{layout}->set_markup ($markup); |
1051 | |
1106 | |
1052 | delete $self->{texture}; |
1107 | delete $self->{texture}; |
|
|
1108 | $self->check_size; |
1053 | $self->update; |
1109 | $self->update; |
1054 | } |
1110 | } |
1055 | |
1111 | |
1056 | sub size_request { |
1112 | sub size_request { |
1057 | my ($self) = @_; |
1113 | my ($self) = @_; |
1058 | |
1114 | |
1059 | $self->{layout}->set_width; |
1115 | $self->{layout}->set_width; |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1116 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1061 | |
1117 | |
1062 | my ($w, $h) = $self->{layout}->size; |
1118 | my ($w, $h) = $self->{layout}->size; |
|
|
1119 | |
|
|
1120 | if (exists $self->{template}) { |
|
|
1121 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1122 | |
|
|
1123 | my ($w2, $h2) = $self->{template}->size; |
|
|
1124 | |
|
|
1125 | $w = List::Util::max $w, $w2; |
|
|
1126 | $h = List::Util::max $h, $h2; |
|
|
1127 | } |
1063 | |
1128 | |
1064 | ( |
1129 | ( |
1065 | $w + $self->{padding} * 2, |
1130 | $w + $self->{padding} * 2, |
1066 | $h + $self->{padding} * 2, |
1131 | $h + $self->{padding} * 2, |
1067 | ) |
1132 | ) |
… | |
… | |
1069 | |
1134 | |
1070 | sub size_allocate { |
1135 | sub size_allocate { |
1071 | my ($self, $w, $h) = @_; |
1136 | my ($self, $w, $h) = @_; |
1072 | |
1137 | |
1073 | delete $self->{texture}; |
1138 | delete $self->{texture}; |
|
|
1139 | } |
|
|
1140 | |
|
|
1141 | sub set_fontsize { |
|
|
1142 | my ($self, $fontsize) = @_; |
|
|
1143 | |
|
|
1144 | $self->{fontsize} = $fontsize; |
|
|
1145 | $self->check_size; |
1074 | } |
1146 | } |
1075 | |
1147 | |
1076 | sub _draw { |
1148 | sub _draw { |
1077 | my ($self) = @_; |
1149 | my ($self) = @_; |
1078 | |
1150 | |
… | |
… | |
1161 | } |
1233 | } |
1162 | |
1234 | |
1163 | sub size_allocate { |
1235 | sub size_allocate { |
1164 | my ($self, $w, $h) = @_; |
1236 | my ($self, $w, $h) = @_; |
1165 | |
1237 | |
1166 | $self->_set_text ($self->{text}); |
1238 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1167 | } |
1239 | } |
1168 | |
1240 | |
1169 | sub set_text { |
1241 | sub set_text { |
1170 | my ($self, $text) = @_; |
1242 | my ($self, $text) = @_; |
1171 | |
1243 | |
… | |
… | |
1304 | our @ISA = CFClient::UI::Label::; |
1376 | our @ISA = CFClient::UI::Label::; |
1305 | |
1377 | |
1306 | use CFClient::OpenGL; |
1378 | use CFClient::OpenGL; |
1307 | |
1379 | |
1308 | my @tex = |
1380 | my @tex = |
1309 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1381 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1310 | qw(b1_button_active.png); |
1382 | qw(b1_button_active.png); |
1311 | |
1383 | |
1312 | sub new { |
1384 | sub new { |
1313 | my $class = shift; |
1385 | my $class = shift; |
1314 | |
1386 | |
… | |
… | |
1361 | package CFClient::UI::CheckBox; |
1433 | package CFClient::UI::CheckBox; |
1362 | |
1434 | |
1363 | our @ISA = CFClient::UI::DrawBG::; |
1435 | our @ISA = CFClient::UI::DrawBG::; |
1364 | |
1436 | |
1365 | my @tex = |
1437 | my @tex = |
1366 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1438 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1367 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1439 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1368 | |
1440 | |
1369 | use CFClient::OpenGL; |
1441 | use CFClient::OpenGL; |
1370 | |
1442 | |
1371 | sub new { |
1443 | sub new { |
… | |
… | |
1420 | glDisable GL_BLEND; |
1492 | glDisable GL_BLEND; |
1421 | } |
1493 | } |
1422 | |
1494 | |
1423 | ############################################################################# |
1495 | ############################################################################# |
1424 | |
1496 | |
1425 | package CFClient::UI::VGauge; |
1497 | package CFClient::UI::Image; |
1426 | |
1498 | |
1427 | our @ISA = CFClient::UI::Base::; |
1499 | our @ISA = CFClient::UI::Base::; |
1428 | |
1500 | |
1429 | use CFClient::OpenGL; |
1501 | use CFClient::OpenGL; |
|
|
1502 | use Carp qw/confess/; |
1430 | |
1503 | |
1431 | my %tex = ( |
1504 | our %loaded_images; |
1432 | food => [ |
|
|
1433 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1434 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1435 | ], |
|
|
1436 | grace => [ |
|
|
1437 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1438 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1439 | ], |
|
|
1440 | hp => [ |
|
|
1441 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1442 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1443 | ], |
|
|
1444 | mana => [ |
|
|
1445 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1446 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1447 | ], |
|
|
1448 | ); |
|
|
1449 | |
1505 | |
1450 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1451 | sub new { |
1506 | sub new { |
1452 | my $class = shift; |
1507 | my $class = shift; |
1453 | |
1508 | |
1454 | my $self = $class->SUPER::new (gauge => 'food', @_); |
1509 | my $self = $class->SUPER::new (@_); |
|
|
1510 | |
|
|
1511 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
|
|
1512 | |
|
|
1513 | $loaded_images{$self->{image}} ||= |
|
|
1514 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
|
|
1515 | |
|
|
1516 | my $tex = $self->{tex} = $loaded_images{$self->{image}}; |
|
|
1517 | |
|
|
1518 | Scalar::Util::weaken $loaded_images{$self->{image}}; |
|
|
1519 | |
|
|
1520 | $self->{aspect} = $tex->{w} / $tex->{h}; |
1455 | |
1521 | |
1456 | $self |
1522 | $self |
1457 | } |
1523 | } |
1458 | |
1524 | |
1459 | sub size_request { |
1525 | sub size_request { |
1460 | my ($self) = @_; |
1526 | my ($self) = @_; |
1461 | |
1527 | |
1462 | my $tex = $tex{$self->{gauge}}[0]; |
1528 | ($self->{tex}->{w}, $self->{tex}->{h}) |
1463 | |
|
|
1464 | @$tex{qw(w h)} |
|
|
1465 | } |
|
|
1466 | |
|
|
1467 | sub set_max { |
|
|
1468 | my ($self, $max) = @_; |
|
|
1469 | |
|
|
1470 | $self->{max_val} = $max; |
|
|
1471 | } |
|
|
1472 | |
|
|
1473 | sub set_value { |
|
|
1474 | my ($self, $val, $max) = @_; |
|
|
1475 | |
|
|
1476 | $self->set_max ($max) |
|
|
1477 | if defined $max; |
|
|
1478 | |
|
|
1479 | $max = $self->{max_val}; |
|
|
1480 | $self->{val} = $val; |
|
|
1481 | |
|
|
1482 | $self->update; |
|
|
1483 | } |
1529 | } |
1484 | |
1530 | |
1485 | sub _draw { |
1531 | sub _draw { |
1486 | my ($self) = @_; |
1532 | my ($self) = @_; |
1487 | |
1533 | |
1488 | my $tex = $tex{$self->{gauge}}; |
1534 | my $tex = $self->{tex}; |
1489 | |
1535 | |
1490 | my ($w, $h) = ($self->{w}, $self->{h}); |
1536 | my ($w, $h) = ($self->{w}, $self->{h}); |
1491 | |
1537 | |
1492 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1538 | if ($self->{rot90}) { |
1493 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1539 | glRotate 90, 0, 0, 1; |
|
|
1540 | glTranslate 0, -$self->{w}, 0; |
1494 | |
1541 | |
1495 | my $t1 = $tex->[0]; |
1542 | ($w, $h) = ($h, $w); |
1496 | my $t2 = $tex->[1]; |
1543 | } |
1497 | |
1544 | |
1498 | glEnable GL_BLEND; |
1545 | glEnable GL_BLEND; |
1499 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1546 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1500 | glEnable GL_TEXTURE_2D; |
1547 | glEnable GL_TEXTURE_2D; |
1501 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1548 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1502 | |
1549 | |
|
|
1550 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1551 | |
|
|
1552 | glDisable GL_BLEND; |
|
|
1553 | glDisable GL_TEXTURE_2D; |
|
|
1554 | } |
|
|
1555 | |
|
|
1556 | ############################################################################# |
|
|
1557 | |
|
|
1558 | package CFClient::UI::VGauge; |
|
|
1559 | |
|
|
1560 | our @ISA = CFClient::UI::Base::; |
|
|
1561 | |
|
|
1562 | use CFClient::OpenGL; |
|
|
1563 | |
|
|
1564 | my %tex = ( |
|
|
1565 | food => [ |
|
|
1566 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1567 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1568 | ], |
|
|
1569 | grace => [ |
|
|
1570 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1571 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1572 | ], |
|
|
1573 | hp => [ |
|
|
1574 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1575 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1576 | ], |
|
|
1577 | mana => [ |
|
|
1578 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1579 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1580 | ], |
|
|
1581 | ); |
|
|
1582 | |
|
|
1583 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1584 | sub new { |
|
|
1585 | my $class = shift; |
|
|
1586 | |
|
|
1587 | my $self = $class->SUPER::new ( |
|
|
1588 | type => 'food', |
|
|
1589 | @_ |
|
|
1590 | ); |
|
|
1591 | |
|
|
1592 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
|
|
1593 | |
|
|
1594 | $self |
|
|
1595 | } |
|
|
1596 | |
|
|
1597 | sub size_request { |
|
|
1598 | my ($self) = @_; |
|
|
1599 | |
|
|
1600 | #my $tex = $tex{$self->{type}}[0]; |
|
|
1601 | #@$tex{qw(w h)} |
|
|
1602 | (0, 0) |
|
|
1603 | } |
|
|
1604 | |
|
|
1605 | sub set_max { |
|
|
1606 | my ($self, $max) = @_; |
|
|
1607 | |
|
|
1608 | $self->{max_val} = $max; |
|
|
1609 | } |
|
|
1610 | |
|
|
1611 | sub set_value { |
|
|
1612 | my ($self, $val, $max) = @_; |
|
|
1613 | |
|
|
1614 | $self->set_max ($max) |
|
|
1615 | if defined $max; |
|
|
1616 | |
|
|
1617 | $max = $self->{max_val}; |
|
|
1618 | $self->{val} = $val; |
|
|
1619 | |
|
|
1620 | $self->update; |
|
|
1621 | } |
|
|
1622 | |
|
|
1623 | sub _draw { |
|
|
1624 | my ($self) = @_; |
|
|
1625 | |
|
|
1626 | my $tex = $tex{$self->{type}}; |
|
|
1627 | |
|
|
1628 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1629 | |
|
|
1630 | if ($self->{vertical}) { |
|
|
1631 | glRotate 90, 0, 0, 1; |
|
|
1632 | glTranslate 0, -$self->{w}, 0; |
|
|
1633 | |
|
|
1634 | ($w, $h) = ($h, $w); |
|
|
1635 | } |
|
|
1636 | |
|
|
1637 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1638 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1639 | |
|
|
1640 | my $t1 = $tex->[0]; |
|
|
1641 | my $t2 = $tex->[1]; |
|
|
1642 | |
|
|
1643 | glEnable GL_BLEND; |
|
|
1644 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1645 | glEnable GL_TEXTURE_2D; |
|
|
1646 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1647 | |
1503 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1648 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1504 | my $h2 = $ycut * $self->{h}; |
1649 | my $h2 = $ycut * $self->{h}; |
1505 | |
1650 | |
1506 | my $yp = 0; |
|
|
1507 | |
|
|
1508 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1651 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1509 | glBegin GL_QUADS; |
1652 | glBegin GL_QUADS; |
1510 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1653 | glTexCoord 0 , 0; glVertex 0 , 0; |
1511 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1654 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1512 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1655 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1513 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1656 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1514 | glEnd; |
1657 | glEnd; |
1515 | |
|
|
1516 | $yp += $h1; |
|
|
1517 | |
1658 | |
1518 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1659 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1519 | glBegin GL_QUADS; |
1660 | glBegin GL_QUADS; |
1520 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1661 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1521 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1662 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1522 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
1663 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1523 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1664 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1524 | glEnd; |
1665 | glEnd; |
1525 | |
1666 | |
1526 | glDisable GL_BLEND; |
1667 | glDisable GL_BLEND; |
1527 | glDisable GL_TEXTURE_2D; |
1668 | glDisable GL_TEXTURE_2D; |
|
|
1669 | } |
|
|
1670 | |
|
|
1671 | ############################################################################# |
|
|
1672 | |
|
|
1673 | package CFClient::UI::Gauge; |
|
|
1674 | |
|
|
1675 | our @ISA = CFClient::UI::VBox::; |
|
|
1676 | |
|
|
1677 | sub new { |
|
|
1678 | my ($class, %arg) = shift; |
|
|
1679 | |
|
|
1680 | my $self = $class->SUPER::new ( |
|
|
1681 | @_, |
|
|
1682 | ); |
|
|
1683 | |
|
|
1684 | $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1685 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
|
|
1686 | $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1687 | |
|
|
1688 | $self |
|
|
1689 | } |
|
|
1690 | |
|
|
1691 | sub set_fontsize { |
|
|
1692 | my ($self, $fsize) = @_; |
|
|
1693 | |
|
|
1694 | $self->{value}->set_fontsize ($fsize); |
|
|
1695 | $self->{max} ->set_fontsize ($fsize); |
|
|
1696 | } |
|
|
1697 | |
|
|
1698 | sub set_value { |
|
|
1699 | my ($self, $val, $max) = @_; |
|
|
1700 | |
|
|
1701 | $self->set_max ($max) |
|
|
1702 | if defined $max; |
|
|
1703 | |
|
|
1704 | $self->{gauge}->set_value ($val, $max); |
|
|
1705 | $self->{value}->set_text ($val); |
|
|
1706 | } |
|
|
1707 | |
|
|
1708 | sub set_max { |
|
|
1709 | my ($self, $max) = @_; |
|
|
1710 | |
|
|
1711 | $self->{gauge}->set_max ($max); |
|
|
1712 | $self->{max}->set_text ($max); |
1528 | } |
1713 | } |
1529 | |
1714 | |
1530 | ############################################################################# |
1715 | ############################################################################# |
1531 | |
1716 | |
1532 | package CFClient::UI::Slider; |
1717 | package CFClient::UI::Slider; |
… | |
… | |
1910 | use CFClient::OpenGL; |
2095 | use CFClient::OpenGL; |
1911 | |
2096 | |
1912 | sub check_size { |
2097 | sub check_size { |
1913 | my ($self) = @_; |
2098 | my ($self) = @_; |
1914 | |
2099 | |
1915 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2100 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
1916 | } |
2101 | } |
1917 | |
2102 | |
1918 | sub size_request { |
2103 | sub size_request { |
1919 | ($::WIDTH, $::HEIGHT) |
2104 | ($::WIDTH, $::HEIGHT) |
1920 | } |
2105 | } |
… | |
… | |
1922 | sub configure { |
2107 | sub configure { |
1923 | my ($self, $x, $y, $w, $h) = @_; |
2108 | my ($self, $x, $y, $w, $h) = @_; |
1924 | |
2109 | |
1925 | $self->SUPER::configure ($x, $y, $w, $h); |
2110 | $self->SUPER::configure ($x, $y, $w, $h); |
1926 | |
2111 | |
1927 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
|
|
1928 | for @{$self->{children}}; |
2112 | for my $child (@{$self->{children}}) { |
|
|
2113 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
|
|
2114 | |
|
|
2115 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
|
|
2116 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
|
|
2117 | $child->configure ($X, $Y, $W,$H); |
|
|
2118 | } |
1929 | } |
2119 | } |
1930 | |
2120 | |
1931 | sub _topleft { |
2121 | sub _topleft { |
1932 | my ($self, $x, $y) = @_; |
2122 | my ($self, $x, $y) = @_; |
1933 | |
2123 | |
… | |
… | |
1941 | ::refresh (); |
2131 | ::refresh (); |
1942 | } |
2132 | } |
1943 | |
2133 | |
1944 | sub add { |
2134 | sub add { |
1945 | my ($self, $child) = @_; |
2135 | my ($self, $child) = @_; |
|
|
2136 | |
|
|
2137 | # integerize window positions |
|
|
2138 | $child->{x} = int $child->{x}; |
|
|
2139 | $child->{y} = int $child->{y}; |
1946 | |
2140 | |
1947 | $self->SUPER::add ($child); |
2141 | $self->SUPER::add ($child); |
1948 | } |
2142 | } |
1949 | |
2143 | |
1950 | sub on_refresh { |
2144 | sub on_refresh { |