… | |
… | |
260 | my ($self, $parent) = @_; |
260 | my ($self, $parent) = @_; |
261 | |
261 | |
262 | Scalar::Util::weaken ($self->{parent} = $parent); |
262 | Scalar::Util::weaken ($self->{parent} = $parent); |
263 | } |
263 | } |
264 | |
264 | |
|
|
265 | sub check_size { |
|
|
266 | my ($self) = @_; |
|
|
267 | |
|
|
268 | my ($w, $h) = $self->size_request; |
|
|
269 | |
|
|
270 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
|
|
271 | $self->{req_w} = $w; |
|
|
272 | $self->{req_h} = $h; |
|
|
273 | |
|
|
274 | $self->{parent}->check_size |
|
|
275 | if $self->{parent}; |
|
|
276 | } |
|
|
277 | } |
|
|
278 | |
265 | sub update { |
279 | sub update { |
266 | my ($self) = @_; |
280 | my ($self) = @_; |
267 | |
281 | |
268 | $self->{parent}->update |
282 | $self->{parent}->update |
269 | if $self->{parent}; |
283 | if $self->{parent}; |
… | |
… | |
376 | sub remove { |
390 | sub remove { |
377 | my ($self, $widget) = @_; |
391 | my ($self, $widget) = @_; |
378 | |
392 | |
379 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
393 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
380 | |
394 | |
381 | $self->size_allocate (0, 0, $self->{w}, $self->{h}); |
395 | $self->check_size; |
382 | } |
396 | } |
383 | |
397 | |
384 | sub find_widget { |
398 | sub find_widget { |
385 | my ($self, $x, $y) = @_; |
399 | my ($self, $x, $y) = @_; |
386 | |
400 | |
… | |
… | |
506 | $tex->draw_quad (0, 0, $w, $h); |
520 | $tex->draw_quad (0, 0, $w, $h); |
507 | |
521 | |
508 | glDisable GL_BLEND; |
522 | glDisable GL_BLEND; |
509 | glDisable GL_TEXTURE_2D; |
523 | glDisable GL_TEXTURE_2D; |
510 | } |
524 | } |
|
|
525 | |
|
|
526 | ############################################################################# |
|
|
527 | |
|
|
528 | package CFClient::UI::ViewPort; |
|
|
529 | |
|
|
530 | our @ISA = CFClient::UI::Window::; |
|
|
531 | |
|
|
532 | sub new { die } |
|
|
533 | |
|
|
534 | sub size_request { |
|
|
535 | my ($self) = @_; |
|
|
536 | |
|
|
537 | @$self{qw(child_w child_h)} = $self->child->size_request; |
|
|
538 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
|
|
539 | |
|
|
540 | @$self{qw(child_w child_h)} |
|
|
541 | } |
|
|
542 | |
|
|
543 | sub size_allocate { |
|
|
544 | my ($self, $x, $y, $w, $h) = @_; |
|
|
545 | |
|
|
546 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
547 | } |
|
|
548 | |
|
|
549 | sub _draw { |
|
|
550 | my ($self) = @_; |
|
|
551 | |
|
|
552 | $self->{children}[1]->draw; |
|
|
553 | } |
|
|
554 | |
511 | |
555 | |
512 | ############################################################################# |
556 | ############################################################################# |
513 | |
557 | |
514 | package CFClient::UI::Frame; |
558 | package CFClient::UI::Frame; |
515 | |
559 | |
… | |
… | |
846 | } |
890 | } |
847 | |
891 | |
848 | sub size_allocate { |
892 | sub size_allocate { |
849 | my ($self, $x, $y, $w, $h) = @_; |
893 | my ($self, $x, $y, $w, $h) = @_; |
850 | |
894 | |
851 | $self->_size_allocate ($x, $y, $w, $h); |
895 | $self->_size_allocate ($x, $y, $w, $h) or return; |
852 | |
896 | |
853 | ($h, $w) = ($w, $h); |
897 | ($h, $w) = ($w, $h); |
854 | |
898 | |
855 | my $children = $self->{children}; |
899 | my $children = $self->{children}; |
856 | |
900 | |
… | |
… | |
882 | my $h = $h[$_]; |
926 | my $h = $h[$_]; |
883 | $child->size_allocate ($y, 0, $h, $w); |
927 | $child->size_allocate ($y, 0, $h, $w); |
884 | |
928 | |
885 | $y += $h; |
929 | $y += $h; |
886 | } |
930 | } |
|
|
931 | |
|
|
932 | 1 |
887 | } |
933 | } |
888 | |
934 | |
889 | ############################################################################# |
935 | ############################################################################# |
890 | |
936 | |
891 | package CFClient::UI::VBox; |
937 | package CFClient::UI::VBox; |
… | |
… | |
906 | } |
952 | } |
907 | |
953 | |
908 | sub size_allocate { |
954 | sub size_allocate { |
909 | my ($self, $x, $y, $w, $h) = @_; |
955 | my ($self, $x, $y, $w, $h) = @_; |
910 | |
956 | |
911 | $self->_size_allocate ($x, $y, $w, $h); |
957 | $self->_size_allocate ($x, $y, $w, $h) or return; |
912 | |
958 | |
913 | my $children = $self->{children}; |
959 | my $children = $self->{children}; |
914 | |
960 | |
915 | my @h = map +($_->size_request)[1], @$children; |
961 | my @h = map +($_->size_request)[1], @$children; |
916 | |
962 | |
… | |
… | |
938 | my $h = $h[$_]; |
984 | my $h = $h[$_]; |
939 | $child->size_allocate (0, $y, $w, $h); |
985 | $child->size_allocate (0, $y, $w, $h); |
940 | |
986 | |
941 | $y += $h; |
987 | $y += $h; |
942 | } |
988 | } |
|
|
989 | |
|
|
990 | 1 |
943 | } |
991 | } |
944 | |
992 | |
945 | ############################################################################# |
993 | ############################################################################# |
946 | |
994 | |
947 | package CFClient::UI::Label; |
995 | package CFClient::UI::Label; |
… | |
… | |
1116 | } |
1164 | } |
1117 | |
1165 | |
1118 | sub size_allocate { |
1166 | sub size_allocate { |
1119 | my ($self, $x, $y, $w, $h) = @_; |
1167 | my ($self, $x, $y, $w, $h) = @_; |
1120 | |
1168 | |
1121 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
1169 | $self->SUPER::size_allocate ($x, $y, $w, $h) or return; |
1122 | |
1170 | |
1123 | $self->_set_text ($self->{text}); |
1171 | $self->_set_text ($self->{text}); |
1124 | } |
1172 | } |
1125 | |
1173 | |
1126 | sub set_text { |
1174 | sub set_text { |
… | |
… | |
1347 | } |
1395 | } |
1348 | |
1396 | |
1349 | sub size_allocate { |
1397 | sub size_allocate { |
1350 | my ($self, $x, $y, $w, $h) = @_; |
1398 | my ($self, $x, $y, $w, $h) = @_; |
1351 | |
1399 | |
1352 | $self->_size_allocate ($x, $y, $w, $h); |
1400 | $self->_size_allocate ($x, $y, $w, $h) or return; |
1353 | } |
1401 | } |
1354 | |
1402 | |
1355 | sub button_down { |
1403 | sub button_down { |
1356 | my ($self, $ev, $x, $y) = @_; |
1404 | my ($self, $ev, $x, $y) = @_; |
1357 | |
1405 | |
… | |
… | |
1690 | } |
1738 | } |
1691 | |
1739 | |
1692 | sub size_allocate { |
1740 | sub size_allocate { |
1693 | my ($self, $x, $y, $w, $h) = @_; |
1741 | my ($self, $x, $y, $w, $h) = @_; |
1694 | |
1742 | |
1695 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
1743 | $self->SUPER::size_allocate ($x, $y, $w, $h) or return; |
1696 | |
1744 | |
1697 | $self->{layout}->set_height ($self->{fontsize}); |
1745 | $self->{layout}->set_height ($self->{fontsize}); |
1698 | $self->{layout}->set_width ($self->{w}); |
1746 | $self->{layout}->set_width ($self->{w}); |
1699 | |
1747 | |
1700 | $self->reflow; |
1748 | $self->reflow; |
|
|
1749 | $self->update; |
1701 | } |
1750 | } |
1702 | |
1751 | |
1703 | sub add_paragraph { |
1752 | sub add_paragraph { |
1704 | my ($self, $color, $text) = @_; |
1753 | my ($self, $color, $text) = @_; |
1705 | |
1754 | |
… | |
… | |
2113 | |
2162 | |
2114 | our @ISA = CFClient::UI::Container::; |
2163 | our @ISA = CFClient::UI::Container::; |
2115 | |
2164 | |
2116 | use SDL::OpenGL; |
2165 | use SDL::OpenGL; |
2117 | |
2166 | |
|
|
2167 | sub check_size { |
|
|
2168 | my ($self) = @_; |
|
|
2169 | |
|
|
2170 | $self->size_allocate (0, 0, $::WITH, $::HEIGHT); |
|
|
2171 | } |
|
|
2172 | |
2118 | sub size_request { |
2173 | sub size_request { |
2119 | ($::WIDTH, $::HEIGHT) |
2174 | ($::WIDTH, $::HEIGHT) |
2120 | } |
2175 | } |
2121 | |
2176 | |
2122 | sub size_allocate { |
2177 | sub size_allocate { |
… | |
… | |
2135 | } |
2190 | } |
2136 | |
2191 | |
2137 | sub update { |
2192 | sub update { |
2138 | my ($self) = @_; |
2193 | my ($self) = @_; |
2139 | |
2194 | |
2140 | $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); |
2195 | $self->check_size; |
2141 | ::refresh (); |
2196 | ::refresh (); |
2142 | } |
2197 | } |
2143 | |
2198 | |
2144 | sub add { |
2199 | sub add { |
2145 | my ($self, $widget) = @_; |
2200 | my ($self, $widget) = @_; |