… | |
… | |
112 | $self |
112 | $self |
113 | } |
113 | } |
114 | |
114 | |
115 | sub move { |
115 | sub move { |
116 | my ($self, $x, $y, $z) = @_; |
116 | my ($self, $x, $y, $z) = @_; |
|
|
117 | |
117 | $self->{x} = int $x; |
118 | $self->{x} = int $x; |
118 | $self->{y} = int $y; |
119 | $self->{y} = int $y; |
119 | $self->{z} = $z if defined $z; |
120 | $self->{z} = $z if defined $z; |
|
|
121 | |
|
|
122 | $self->update; |
120 | } |
123 | } |
121 | |
124 | |
122 | sub needs_redraw { |
125 | sub needs_redraw { |
123 | 0 |
126 | 0 |
124 | } |
127 | } |
… | |
… | |
126 | sub size_request { |
129 | sub size_request { |
127 | require Carp; |
130 | require Carp; |
128 | Carp::confess "size_request is abtract"; |
131 | Carp::confess "size_request is abtract"; |
129 | } |
132 | } |
130 | |
133 | |
131 | sub _size_allocate { |
134 | sub configure { |
132 | my ($self, $x, $y, $w, $h) = @_; |
135 | my ($self, $x, $y, $w, $h) = @_; |
133 | |
136 | |
134 | $self->{x} = $x; |
137 | $self->{x} = $x; |
135 | $self->{y} = $y; |
138 | $self->{y} = $y; |
136 | |
139 | |
137 | return unless $self->{w} != $w || $self->{h} != $h; |
140 | return unless $self->{w} != $w || $self->{h} != $h; |
138 | |
141 | |
139 | $self->{w} = $w; |
142 | $self->{w} = $w; |
140 | $self->{h} = $h; |
143 | $self->{h} = $h; |
141 | |
144 | |
142 | 1 |
145 | $self->size_allocate ($w, $h); |
143 | } |
146 | } |
144 | |
147 | |
145 | sub size_allocate { |
148 | sub size_allocate { |
146 | my ($self, $x, $y, $w, $h) = @_; |
149 | # nothing to be done |
147 | |
|
|
148 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
149 | } |
150 | } |
150 | |
151 | |
151 | # return top left coordinates |
152 | # return top left coordinates |
152 | sub _topleft { |
153 | sub _topleft { |
153 | my ($self, $x, $y) = @_; |
154 | my ($self, $x, $y) = @_; |
… | |
… | |
271 | $self->{req_w} = $w; |
272 | $self->{req_w} = $w; |
272 | $self->{req_h} = $h; |
273 | $self->{req_h} = $h; |
273 | |
274 | |
274 | $self->{parent}->check_size |
275 | $self->{parent}->check_size |
275 | if $self->{parent}; |
276 | if $self->{parent}; |
|
|
277 | |
|
|
278 | $self->size_allocate ($w, $h); |
|
|
279 | $self->update; |
276 | } |
280 | } |
277 | } |
281 | } |
278 | |
282 | |
279 | sub update { |
283 | sub update { |
280 | my ($self) = @_; |
284 | my ($self) = @_; |
… | |
… | |
454 | sub size_request { |
458 | sub size_request { |
455 | $_[0]{children}[0]->size_request |
459 | $_[0]{children}[0]->size_request |
456 | } |
460 | } |
457 | |
461 | |
458 | sub size_allocate { |
462 | sub size_allocate { |
459 | my ($self, $x, $y, $w, $h) = @_; |
463 | my ($self, $w, $h) = @_; |
460 | |
464 | |
461 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
462 | |
|
|
463 | $self->{children}[0]->size_allocate (0, 0, $w, $h); |
465 | $self->{children}[0]->configure (0, 0, $w, $h); |
464 | } |
466 | } |
465 | |
467 | |
466 | ############################################################################# |
468 | ############################################################################# |
467 | |
469 | |
468 | package CFClient::UI::Window; |
470 | package CFClient::UI::Window; |
… | |
… | |
494 | $self->child->draw; |
496 | $self->child->draw; |
495 | }; |
497 | }; |
496 | } |
498 | } |
497 | |
499 | |
498 | sub size_allocate { |
500 | sub size_allocate { |
499 | my ($self, $x, $y, $w, $h) = @_; |
501 | my ($self, $w, $h) = @_; |
500 | |
502 | |
501 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
502 | |
|
|
503 | $self->child->size_allocate (0, 0, $w, $h); |
503 | $self->child->configure (0, 0, $w, $h); |
504 | |
504 | |
505 | $self->render_chld; |
505 | $self->render_chld; |
506 | } |
506 | } |
507 | |
507 | |
508 | sub _draw { |
508 | sub _draw { |
… | |
… | |
539 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
539 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
540 | |
540 | |
541 | @$self{qw(child_w child_h)} |
541 | @$self{qw(child_w child_h)} |
542 | } |
542 | } |
543 | |
543 | |
544 | sub size_allocate { |
|
|
545 | my ($self, $x, $y, $w, $h) = @_; |
|
|
546 | |
|
|
547 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
548 | } |
|
|
549 | |
|
|
550 | sub _draw { |
544 | sub _draw { |
551 | my ($self) = @_; |
545 | my ($self) = @_; |
552 | |
546 | |
553 | $self->{children}[1]->draw; |
547 | $self->{children}[1]->draw; |
554 | } |
548 | } |
… | |
… | |
573 | } |
567 | } |
574 | |
568 | |
575 | sub size_allocate { |
569 | sub size_allocate { |
576 | my ($self, $x, $y, $w, $h) = @_; |
570 | my ($self, $x, $y, $w, $h) = @_; |
577 | |
571 | |
578 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
579 | |
|
|
580 | $self->child->size_allocate (2, 2, $w - 4, $h - 4); |
572 | $self->child->configure (2, 2, $w - 4, $h - 4); |
581 | } |
573 | } |
582 | |
574 | |
583 | sub _draw { |
575 | sub _draw { |
584 | my ($self) = @_; |
576 | my ($self) = @_; |
585 | |
577 | |
… | |
… | |
635 | $h + $self->{border} * 2, |
627 | $h + $self->{border} * 2, |
636 | ) |
628 | ) |
637 | } |
629 | } |
638 | |
630 | |
639 | sub size_allocate { |
631 | sub size_allocate { |
640 | my ($self, $x, $y, $w, $h) = @_; |
632 | my ($self, $w, $h) = @_; |
641 | |
|
|
642 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
643 | |
633 | |
644 | $h -= List::Util::max 0, $self->{border} * 2; |
634 | $h -= List::Util::max 0, $self->{border} * 2; |
645 | $w -= List::Util::max 0, $self->{border} * 2; |
635 | $w -= List::Util::max 0, $self->{border} * 2; |
646 | |
636 | |
647 | $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); |
637 | $self->child->configure ($self->{border}, $self->{border}, $w, $h); |
648 | } |
638 | } |
649 | |
639 | |
650 | sub button_down { |
640 | sub button_down { |
651 | my ($self, $ev, $x, $y) = @_; |
641 | my ($self, $ev, $x, $y) = @_; |
652 | |
642 | |
… | |
… | |
661 | |
651 | |
662 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
652 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
663 | |
653 | |
664 | $self->{user_w} = $bw + $x - $ox; |
654 | $self->{user_w} = $bw + $x - $ox; |
665 | $self->{user_h} = $bh + $y - $oy; |
655 | $self->{user_h} = $bh + $y - $oy; |
666 | $self->update; |
656 | $self->check_size; |
667 | }; |
657 | }; |
668 | |
658 | |
669 | } elsif ($x >= 0 && $x < $self->{w} |
659 | } elsif ($x >= 0 && $x < $self->{w} |
670 | && $y >= 0 && $y < $self->{border}) { |
660 | && $y >= 0 && $y < $self->{border}) { |
671 | |
661 | |
… | |
… | |
801 | (sum @$hs), |
791 | (sum @$hs), |
802 | ) |
792 | ) |
803 | } |
793 | } |
804 | |
794 | |
805 | sub size_allocate { |
795 | sub size_allocate { |
806 | my ($self, $x, $y, $w, $h) = @_; |
796 | my ($self, $w, $h) = @_; |
807 | |
|
|
808 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
809 | |
797 | |
810 | my ($ws, $hs) = $self->get_wh; |
798 | my ($ws, $hs) = $self->get_wh; |
811 | |
799 | |
812 | my $req_w = sum @$ws; |
800 | my $req_w = sum @$ws; |
813 | my $req_h = sum @$hs; |
801 | my $req_h = sum @$hs; |
… | |
… | |
835 | |
823 | |
836 | for my $c (0 .. $#$row) { |
824 | for my $c (0 .. $#$row) { |
837 | my $col_w = $ws->[$c]; |
825 | my $col_w = $ws->[$c]; |
838 | |
826 | |
839 | if (my $widget = $row->[$c]) { |
827 | if (my $widget = $row->[$c]) { |
840 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
828 | $widget->configure ($x, $y, $col_w, $row_h); |
841 | } |
829 | } |
842 | |
830 | |
843 | $x += $col_w; |
831 | $x += $col_w; |
844 | } |
832 | } |
845 | |
833 | |
… | |
… | |
890 | (List::Util::max map $_->[1], @alloc), |
878 | (List::Util::max map $_->[1], @alloc), |
891 | ) |
879 | ) |
892 | } |
880 | } |
893 | |
881 | |
894 | sub size_allocate { |
882 | sub size_allocate { |
895 | my ($self, $x, $y, $w, $h) = @_; |
883 | my ($self, $w, $h) = @_; |
896 | |
|
|
897 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
898 | |
884 | |
899 | ($h, $w) = ($w, $h); |
885 | ($h, $w) = ($w, $h); |
900 | |
886 | |
901 | my $children = $self->{children}; |
887 | my $children = $self->{children}; |
902 | |
888 | |
… | |
… | |
924 | |
910 | |
925 | my $y = 0; |
911 | my $y = 0; |
926 | for (0 .. $#$children) { |
912 | for (0 .. $#$children) { |
927 | my $child = $children->[$_]; |
913 | my $child = $children->[$_]; |
928 | my $h = $h[$_]; |
914 | my $h = $h[$_]; |
929 | $child->size_allocate ($y, 0, $h, $w); |
915 | $child->configure ($y, 0, $h, $w); |
930 | |
916 | |
931 | $y += $h; |
917 | $y += $h; |
932 | } |
918 | } |
933 | |
919 | |
934 | 1 |
920 | 1 |
… | |
… | |
952 | (List::Util::sum map $_->[1], @alloc), |
938 | (List::Util::sum map $_->[1], @alloc), |
953 | ) |
939 | ) |
954 | } |
940 | } |
955 | |
941 | |
956 | sub size_allocate { |
942 | sub size_allocate { |
957 | my ($self, $x, $y, $w, $h) = @_; |
943 | my ($self, $w, $h) = @_; |
958 | |
|
|
959 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
960 | |
944 | |
961 | my $children = $self->{children}; |
945 | my $children = $self->{children}; |
962 | |
946 | |
963 | my @h = map +($_->size_request)[1], @$children; |
947 | my @h = map +($_->size_request)[1], @$children; |
964 | |
948 | |
… | |
… | |
982 | |
966 | |
983 | my $y = 0; |
967 | my $y = 0; |
984 | for (0 .. $#$children) { |
968 | for (0 .. $#$children) { |
985 | my $child = $children->[$_]; |
969 | my $child = $children->[$_]; |
986 | my $h = $h[$_]; |
970 | my $h = $h[$_]; |
987 | $child->size_allocate (0, $y, $w, $h); |
971 | $child->configure (0, $y, $w, $h); |
988 | |
972 | |
989 | $y += $h; |
973 | $y += $h; |
990 | } |
974 | } |
991 | |
975 | |
992 | 1 |
976 | 1 |
… | |
… | |
1063 | $h + $self->{padding} * 2, |
1047 | $h + $self->{padding} * 2, |
1064 | ) |
1048 | ) |
1065 | } |
1049 | } |
1066 | |
1050 | |
1067 | sub size_allocate { |
1051 | sub size_allocate { |
1068 | my ($self, $x, $y, $w, $h) = @_; |
1052 | my ($self, $w, $h) = @_; |
1069 | |
|
|
1070 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1071 | |
1053 | |
1072 | delete $self->{texture}; |
1054 | delete $self->{texture}; |
1073 | } |
1055 | } |
1074 | |
1056 | |
1075 | sub update { |
1057 | sub update { |
… | |
… | |
1164 | |
1146 | |
1165 | ($w + 1, $h) # add 1 for cursor |
1147 | ($w + 1, $h) # add 1 for cursor |
1166 | } |
1148 | } |
1167 | |
1149 | |
1168 | sub size_allocate { |
1150 | sub size_allocate { |
1169 | my ($self, $x, $y, $w, $h) = @_; |
1151 | my ($self, $w, $h) = @_; |
1170 | |
|
|
1171 | $self->SUPER::size_allocate ($x, $y, $w, $h) or return; |
|
|
1172 | |
1152 | |
1173 | $self->_set_text ($self->{text}); |
1153 | $self->_set_text ($self->{text}); |
1174 | } |
1154 | } |
1175 | |
1155 | |
1176 | sub set_text { |
1156 | sub set_text { |
… | |
… | |
1394 | |
1374 | |
1395 | sub size_request { |
1375 | sub size_request { |
1396 | my ($self) = @_; |
1376 | my ($self) = @_; |
1397 | |
1377 | |
1398 | ($self->{padding} * 2 + 6) x 2 |
1378 | ($self->{padding} * 2 + 6) x 2 |
1399 | } |
|
|
1400 | |
|
|
1401 | sub size_allocate { |
|
|
1402 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1403 | |
|
|
1404 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
1405 | } |
1379 | } |
1406 | |
1380 | |
1407 | sub button_down { |
1381 | sub button_down { |
1408 | my ($self, $ev, $x, $y) = @_; |
1382 | my ($self, $ev, $x, $y) = @_; |
1409 | |
1383 | |
… | |
… | |
1743 | |
1717 | |
1744 | ($self->{req_w}, $self->{req_h}) |
1718 | ($self->{req_w}, $self->{req_h}) |
1745 | } |
1719 | } |
1746 | |
1720 | |
1747 | sub size_allocate { |
1721 | sub size_allocate { |
1748 | my ($self, $x, $y, $w, $h) = @_; |
1722 | my ($self, $w, $h) = @_; |
1749 | |
|
|
1750 | $self->SUPER::size_allocate ($x, $y, $w, $h) or return; |
|
|
1751 | |
1723 | |
1752 | $self->{layout}->set_height ($self->{fontsize}); |
1724 | $self->{layout}->set_height ($self->{fontsize}); |
1753 | $self->{layout}->set_width ($self->{w}); |
1725 | $self->{layout}->set_width ($self->{w}); |
1754 | |
1726 | |
1755 | $self->reflow; |
1727 | $self->reflow; |
… | |
… | |
2172 | use SDL::OpenGL; |
2144 | use SDL::OpenGL; |
2173 | |
2145 | |
2174 | sub check_size { |
2146 | sub check_size { |
2175 | my ($self) = @_; |
2147 | my ($self) = @_; |
2176 | |
2148 | |
2177 | $self->size_allocate (0, 0, $::WITH, $::HEIGHT); |
2149 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2178 | } |
2150 | } |
2179 | |
2151 | |
2180 | sub size_request { |
2152 | sub size_request { |
2181 | ($::WIDTH, $::HEIGHT) |
2153 | ($::WIDTH, $::HEIGHT) |
2182 | } |
2154 | } |
2183 | |
2155 | |
2184 | sub size_allocate { |
2156 | sub configure { |
2185 | my ($self, $x, $y, $w, $h) = @_; |
2157 | my ($self, $x, $y, $w, $h) = @_; |
2186 | |
2158 | |
2187 | $self->_size_allocate ($x, $y, $w, $h); |
2159 | $self->SUPER::configure ($x, $y, $w, $h); |
2188 | |
2160 | |
2189 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
2161 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
2190 | for @{$self->{children}}; |
2162 | for @{$self->{children}}; |
2191 | } |
2163 | } |
2192 | |
2164 | |
2193 | sub _topleft { |
2165 | sub _topleft { |
2194 | my ($self, $x, $y) = @_; |
2166 | my ($self, $x, $y) = @_; |
… | |
… | |
2202 | $self->check_size; |
2174 | $self->check_size; |
2203 | ::refresh (); |
2175 | ::refresh (); |
2204 | } |
2176 | } |
2205 | |
2177 | |
2206 | sub add { |
2178 | sub add { |
2207 | my ($self, $widget) = @_; |
2179 | my ($self, $child) = @_; |
2208 | |
2180 | |
2209 | $self->SUPER::add ($widget); |
2181 | $self->SUPER::add ($child); |
2210 | |
|
|
2211 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
|
|
2212 | } |
2182 | } |
2213 | |
2183 | |
2214 | sub on_refresh { |
2184 | sub on_refresh { |
2215 | my ($self, $id, $cb) = @_; |
2185 | my ($self, $id, $cb) = @_; |
2216 | |
2186 | |