ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.174 by root, Tue Apr 25 11:18:49 2006 UTC vs.
Revision 1.187 by root, Mon May 8 20:40:31 2006 UTC

237 $self->{w} = $w; 237 $self->{w} = $w;
238 $self->{h} = $h; 238 $self->{h} = $h;
239 239
240 $self->size_allocate ($w, $h); 240 $self->size_allocate ($w, $h);
241 $self->update; 241 $self->update;
242 $self->emit (size_allocate => $w, $h);
242 } 243 }
243} 244}
244 245
245sub size_allocate { 246sub size_allocate {
246 # nothing to be done 247 # nothing to be done
247} 248}
248 249
249sub children { 250sub children {
250} 251}
251 252
252# call when resoltuion changes etc. 253# call when resolution changes etc.
253sub reconfigure { 254sub reconfigure {
254 my ($self) = @_; 255 my ($self) = @_;
255 256
256 $_->reconfigure 257 $_->reconfigure
257 for $self->children; 258 for $self->children;
258 259
259 $_->check_size; 260 $self->check_size;
261 $self->size_allocate ($self->{w}, $self->{h});
262 $self->update;
260} 263}
261 264
262sub set_max_size { 265sub set_max_size {
263 my ($self, $w, $h) = @_; 266 my ($self, $w, $h) = @_;
264 267
539 sort { $a->{z} <=> $b->{z} } 542 sort { $a->{z} <=> $b->{z} }
540 @{$self->{children}}, $child 543 @{$self->{children}}, $child
541 ]; 544 ];
542 545
543 $child->check_size; 546 $child->check_size;
547 $self->update;
544} 548}
545 549
546sub children { 550sub children {
547 @{ $_[0]{children} } 551 @{ $_[0]{children} }
548} 552}
567 571
568 for (@$children) { 572 for (@$children) {
569 delete $_->{parent}; 573 delete $_->{parent};
570 $_->hide; 574 $_->hide;
571 } 575 }
576
577 $self->check_size;
578 $self->update;
572} 579}
573 580
574sub find_widget { 581sub find_widget {
575 my ($self, $x, $y) = @_; 582 my ($self, $x, $y) = @_;
576 583
662 669
663 $self->SUPER::size_allocate ($w, $h); 670 $self->SUPER::size_allocate ($w, $h);
664 $self->update; 671 $self->update;
665} 672}
666 673
674sub _render {
675 $_[0]{children}[0]->draw;
676}
677
667sub render_child { 678sub render_child {
668 my ($self) = @_; 679 my ($self) = @_;
669 680
670 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 681 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
671 glClearColor 0, 0, 0, 0; 682 glClearColor 0, 0, 0, 0;
672 glClear GL_COLOR_BUFFER_BIT; 683 glClear GL_COLOR_BUFFER_BIT;
673 $self->child->draw; 684
685 $self->_render;
686# glColorMask 1, 1, 1, 0;
687# glEnable GL_BLEND;
688# glBlendFunc GL_SRC_ALPHA, GL_ZERO;
689# glRasterPos 0, 0;
690# glCopyPixels 0, 0, $self->{w}, $self->{h};
691# glDisable GL_BLEND;
692# glColorMask 1, 1, 1, 1;
674 }; 693 };
675} 694}
676 695
677sub _draw { 696sub _draw {
678 my ($self) = @_; 697 my ($self) = @_;
698 717
699package CFClient::UI::ViewPort; 718package CFClient::UI::ViewPort;
700 719
701our @ISA = CFClient::UI::Window::; 720our @ISA = CFClient::UI::Window::;
702 721
703sub new { die }
704
705sub size_request { 722sub size_request {
706 my ($self) = @_; 723 my ($self) = @_;
707 724
708 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; 725 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
709 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); 726 $self->child->configure (0, 0, @$self{qw(child_w child_h)});
710 727
711 @$self{qw(child_w child_h)} 728 @$self{qw(child_w child_h)}
712} 729}
713 730
714sub _draw { 731sub size_allocate {
715 my ($self) = @_; 732 my ($self, $w, $h) = @_;
716 733
717 $self->{children}[1]->draw; 734 $self->update;
718} 735}
719 736
737sub set_offset {
738 my ($self, $x, $y) = @_;
739
740 $self->{view_x} = int $x;
741 $self->{view_y} = int $y;
742
743 $self->update;
744}
745
746# hmm, this does not work for topleft of $self... but we should not aks for that
747sub _topleft {
748 my ($self, $x, $y) = @_;
749
750 $self->SUPER::_topleft ($x - $self->{view_x}, $y - $self->{view_y})
751}
752
753sub find_widget {
754 my ($self, $x, $y) = @_;
755
756 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
757 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
758 ) {
759 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
760 } else {
761 $self->CFClient::UI::Base::find_widget ($x, $y)
762 }
763}
764
765sub _render {
766 my ($self) = @_;
767
768 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
769
770 $self->SUPER::_render;
771}
772
773#############################################################################
774
775package CFClient::UI::ScrolledWindow;
776
777our @ISA = CFClient::UI::HBox::;
778
779sub new {
780 my $class = shift;
781
782 my $self;
783
784 my $slider = new CFClient::UI::Slider
785 vertical => 1,
786 range => [0, 0, 1, 0.01], # HACK fix
787 connect_changed => sub {
788 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h}));
789 },
790 ;
791
792 $self = $class->SUPER::new (
793 vp => (new CFClient::UI::ViewPort),
794 slider => $slider,
795 @_,
796 );
797
798 $self->{vp}->add ($self->{scrolled});
799 $self->add ($self->{vp});
800 $self->add ($self->{slider});
801
802 $self
803}
804
805#TODO# update range on size_allocate depeneing on child
806# update viewport offset on scroll
720 807
721############################################################################# 808#############################################################################
722 809
723package CFClient::UI::Frame; 810package CFClient::UI::Frame;
724 811
781 # TODO: user_x, user_y, overwrite moveto? 868 # TODO: user_x, user_y, overwrite moveto?
782 869
783 my $self = $class->SUPER::new ( 870 my $self = $class->SUPER::new (
784 bg => [1, 1, 1, 1], 871 bg => [1, 1, 1, 1],
785 border_bg => [1, 1, 1, 1], 872 border_bg => [1, 1, 1, 1],
786 border => 0.8, 873 border => 0.6,
787 can_events => 1, 874 can_events => 1,
788 @_ 875 @_
789 ); 876 );
790 877
791 $self->{title} &&= new CFClient::UI::Label 878 $self->{title} &&= new CFClient::UI::Label
792 align => 0, 879 align => 0,
793 valign => 1, 880 valign => 1,
794 text => $self->{title}, 881 text => $self->{title},
795 fontsize => 1; 882 fontsize => $self->{border};
796 883
797 $self 884 $self
798} 885}
799 886
800sub border { 887sub border {
825} 912}
826 913
827sub button_down { 914sub button_down {
828 my ($self, $ev, $x, $y) = @_; 915 my ($self, $ev, $x, $y) = @_;
829 916
917 my ($w, $h) = @$self{qw(w h)};
830 my $border = $self->border; 918 my $border = $self->border;
831 919
832 if ($x < $self->{w} && $x >= $self->{w} - $border 920 my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w);
833 && $y < $self->{h} && $y >= $self->{h} - $border) { 921 my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h);
834 922
923 if ($lr & $td) {
924 my ($wx, $wy) = ($self->{x}, $self->{y});
835 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 925 my ($ox, $oy) = ($ev->{x}, $ev->{y});
836 my ($bw, $bh) = ($self->{w}, $self->{h}); 926 my ($bw, $bh) = ($self->{w}, $self->{h});
837 927
928 my $mx = $x < $border;
929 my $my = $y < $border;
930
838 $self->{motion} = sub { 931 $self->{motion} = sub {
839 my ($ev, $x, $y) = @_; 932 my ($ev, $x, $y) = @_;
840 933
841 ($x, $y) = ($ev->{x}, $ev->{y}); 934 my $dx = $ev->{x} - $ox;
935 my $dy = $ev->{y} - $oy;
842 936
843 $self->{user_w} = $bw + $x - $ox; 937 $self->{user_w} = $bw + $dx * ($mx ? -1 : 1);
844 $self->{user_h} = $bh + $y - $oy; 938 $self->{user_h} = $bh + $dy * ($my ? -1 : 1);
939 $self->move ($wx + $dx * $mx, $wy + $dy * $my);
845 $self->check_size; 940 $self->check_size;
846 }; 941 };
847 942
848 } elsif ($x >= 0 && $x < $self->{w} 943 } elsif ($lr ^ $td) {
849 && $y >= 0 && $y < $border) {
850
851 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 944 my ($ox, $oy) = ($ev->{x}, $ev->{y});
852 my ($bx, $by) = ($self->{x}, $self->{y}); 945 my ($bx, $by) = ($self->{x}, $self->{y});
853 946
854 $self->{motion} = sub { 947 $self->{motion} = sub {
855 my ($ev, $x, $y) = @_; 948 my ($ev, $x, $y) = @_;
891 $tex[1]->draw_quad (0, 0, $w, $border); 984 $tex[1]->draw_quad (0, 0, $w, $border);
892 $tex[3]->draw_quad (0, $border, $border, $ch); 985 $tex[3]->draw_quad (0, $border, $border, $ch);
893 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 986 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
894 $tex[4]->draw_quad (0, $h - $border, $w, $border); 987 $tex[4]->draw_quad (0, $h - $border, $w, $border);
895 988
989 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
896 my $bg = $tex[0]; 990 my $bg = $tex[0];
897 991
898 # TODO: repeat texture not scale 992 # TODO: repeat texture not scale
899 my $rep_x = $cw / $bg->{w}; 993 my $rep_x = $cw / $bg->{w};
900 my $rep_y = $ch / $bg->{h}; 994 my $rep_y = $ch / $bg->{h};
901 995
902 glColor @{ $self->{bg} }; 996 glColor @{ $self->{bg} };
903 997
904 $bg->{s} = $rep_x; 998 $bg->{s} = $rep_x;
905 $bg->{t} = $rep_y; 999 $bg->{t} = $rep_y;
906 $bg->{wrap_mode} = 1; 1000 $bg->{wrap_mode} = 1;
907 $bg->draw_quad ($border, $border, $cw, $ch); 1001 $bg->draw_quad ($border, $border, $cw, $ch);
908 1002
909 glDisable GL_TEXTURE_2D; 1003 glDisable GL_TEXTURE_2D;
910 glDisable GL_BLEND; 1004 glDisable GL_BLEND;
1005 }
911 1006
912 $self->{title}->draw if $self->{title}; 1007 $self->{title}->draw if $self->{title};
1008
913 $self->child->draw; 1009 $self->child->draw;
914} 1010}
915 1011
916############################################################################# 1012#############################################################################
917 1013
1228 1324
1229 delete $self->{texture}; 1325 delete $self->{texture};
1230 $self->SUPER::update; 1326 $self->SUPER::update;
1231} 1327}
1232 1328
1233sub reconfigure {
1234 my ($self) = @_;
1235
1236 delete $self->{texture};
1237}
1238
1239sub set_text { 1329sub set_text {
1240 my ($self, $text) = @_; 1330 my ($self, $text) = @_;
1241 1331
1242 return if $self->{text} eq "T$text"; 1332 return if $self->{text} eq "T$text";
1243 $self->{text} = "T$text"; 1333 $self->{text} = "T$text";
1296sub set_fontsize { 1386sub set_fontsize {
1297 my ($self, $fontsize) = @_; 1387 my ($self, $fontsize) = @_;
1298 1388
1299 $self->{fontsize} = $fontsize; 1389 $self->{fontsize} = $fontsize;
1300 delete $self->{texture}; 1390 delete $self->{texture};
1391
1392 $self->update;
1301 $self->check_size; 1393 $self->check_size;
1302 $self->update;
1303} 1394}
1304 1395
1305sub _draw { 1396sub _draw {
1306 my ($self) = @_; 1397 my ($self) = @_;
1307 1398
1941 # TODO: calculations are off 2032 # TODO: calculations are off
1942 my $self = $class->SUPER::new ( 2033 my $self = $class->SUPER::new (
1943 fg => [1, 1, 1], 2034 fg => [1, 1, 1],
1944 active_fg => [0, 0, 0], 2035 active_fg => [0, 0, 0],
1945 range => [0, 0, 100, 10], 2036 range => [0, 0, 100, 10],
1946 req_w => 20, 2037 req_w => $::WIDTH / 80,
1947 req_h => 20, 2038 req_h => $::WIDTH / 80,
1948 vertical => 0, 2039 vertical => 0,
1949 can_hover => 1, 2040 can_hover => 1,
1950 inner_pad => 5, 2041 inner_pad => 5,
1951 @_ 2042 @_
1952 ); 2043 );
2076 (new CFClient::UI::Empty expand => 1), 2167 (new CFClient::UI::Empty expand => 1),
2077 (new CFClient::UI::Slider vertical => 1), 2168 (new CFClient::UI::Slider vertical => 1),
2078 ], 2169 ],
2079 ); 2170 );
2080 2171
2081 $self->{children}[1]->connect (changed => sub { 2172 $self->{children}[1]->connect (changed => sub { $self->update });
2082 $self->update;
2083 });
2084 2173
2085 $self 2174 $self
2086} 2175}
2087 2176
2088sub set_fontsize { 2177sub set_fontsize {
2096 my ($self, $text) = @_; 2185 my ($self, $text) = @_;
2097 2186
2098 my $layout = $self->{layout}; 2187 my $layout = $self->{layout};
2099 2188
2100 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2189 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2101 $layout->set_width ($self->{w}); 2190 $layout->set_width ($self->{children}[0]{w});
2102 $layout->set_text ($text); 2191 $layout->set_text ($text);
2103 2192
2104 ($layout->size)[1] 2193 ($layout->size)[1]
2105} 2194}
2106 2195
2159 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2248 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2160 2249
2161 delete $self->{texture}; 2250 delete $self->{texture};
2162 } 2251 }
2163 2252
2164 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 2253 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2165 glClearColor 0, 0, 0, 1; 2254 glClearColor 0, 0, 0, 0;
2166 glClear GL_COLOR_BUFFER_BIT; 2255 glClear GL_COLOR_BUFFER_BIT;
2167 2256
2168 glEnable GL_BLEND; 2257 glEnable GL_BLEND;
2169 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2258 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2170 glEnable GL_TEXTURE_2D; 2259 glEnable GL_TEXTURE_2D;
2202} 2291}
2203 2292
2204sub _draw { 2293sub _draw {
2205 my ($self) = @_; 2294 my ($self) = @_;
2206 2295
2207 if ($self->{texture}) { 2296 glEnable GL_BLEND;
2297 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2208 glEnable GL_TEXTURE_2D; 2298 glEnable GL_TEXTURE_2D;
2209 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2299 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2210 glColor 1, 1, 1, 1; 2300 glColor 1, 1, 1, 1;
2211 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2301 $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2212 glDisable GL_TEXTURE_2D; 2302 glDisable GL_TEXTURE_2D;
2213 } 2303 glDisable GL_BLEND;
2214 2304
2215 $self->{children}[1]->draw; 2305 $self->{children}[1]->draw;
2216 2306
2217} 2307}
2218 2308
2387 2477
2388sub size_request { 2478sub size_request {
2389 (32, 8) 2479 (32, 8)
2390} 2480}
2391 2481
2392sub draw { 2482sub _draw {
2393 my ($self) = @_; 2483 my ($self) = @_;
2394 2484
2485 return unless $::CONN;#d# manage and cache textures differently
2395 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2486 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2396 2487
2488 # TODO animation
2397 if ($tex) { 2489 if ($tex) {
2398 glEnable GL_BLEND; 2490 glEnable GL_BLEND;
2399 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2491 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2400 glEnable GL_TEXTURE_2D; 2492 glEnable GL_TEXTURE_2D;
2401 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2493 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2406 } 2498 }
2407} 2499}
2408 2500
2409############################################################################# 2501#############################################################################
2410 2502
2503package CFClient::UI::InventoryItem;
2504
2505our @ISA = CFClient::UI::HBox::;
2506
2507sub new {
2508 my $class = shift;
2509
2510 my %args = @_;
2511
2512 my $item = $args{item};
2513
2514 my $desc = $item->{nrof} < 2
2515 ? $item->{name}
2516 : "$item->{nrof} $item->{name_pl}";
2517
2518
2519 my $self = $class->SUPER::new (
2520 can_hover => 1,
2521 can_events => 1,
2522 tooltip => (CFClient::UI::Label->escape ($desc)
2523 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2524 connect_button_down => sub {
2525 my ($self, $ev, $x, $y) = @_;
2526
2527 # todo: maybe put examine on 1? but should just be a tooltip :(
2528 if ($ev->{button} == 1) {
2529 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0");
2530 } elsif ($ev->{button} == 2) {
2531 $::CONN->send ("apply $item->{tag}");
2532 } elsif ($ev->{button} == 3) {
2533 CFClient::UI::Menu->new (
2534 items => [
2535 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2536 [
2537 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2538 sub { $::CONN->send ("lock $item->{tag}") },
2539 ],
2540 ["mark", sub { $::CONN->send ("mark $item->{tag}") }],
2541 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2542 ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }],
2543 ],
2544 )->popup ($ev);
2545 }
2546
2547 1
2548 },
2549 %args
2550 );
2551 $self->add(new CFClient::UI::Face
2552 can_events => 0,
2553 face => $item->{face},
2554 anim => $item->{anim},
2555 animspeed => $item->{animspeed});
2556 $self->add(new CFClient::UI::Label
2557 can_events => 0,
2558 text => $desc);
2559
2560 $self
2561}
2562
2563#############################################################################
2564
2565package CFClient::UI::Inventory;
2566
2567our @ISA = CFClient::UI::ScrolledWindow::;
2568
2569sub new {
2570 my $class = shift;
2571
2572 my $self = $class->SUPER::new (
2573 scrolled => (new CFClient::UI::VBox),
2574 @_,
2575 );
2576
2577 $self
2578}
2579
2580sub set_items {
2581 my ($self, $items) = @_;
2582
2583 $self->{scrolled}->clear;
2584 return unless $items;
2585
2586 my @items = sort { $a->{type} <=> $b->{type} } @$items;
2587
2588 $self->{real_items} = \@items;
2589
2590 for my $item (@items) {
2591 my $desc = $item->{nrof} < 2
2592 ? $item->{name}
2593 : "$item->{nrof} $item->{name_pl}";
2594
2595 $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item);
2596 }
2597
2598# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2599}
2600
2601sub size_request {
2602 my ($self) = @_;
2603 ($self->{req_w}, $self->{req_h});
2604}
2605
2606#############################################################################
2607
2608package CFClient::UI::Menu;
2609
2610our @ISA = CFClient::UI::FancyFrame::;
2611
2612use CFClient::OpenGL;
2613
2614sub new {
2615 my $class = shift;
2616
2617 my $self = $class->SUPER::new (
2618 items => [],
2619 z => 100,
2620 @_,
2621 );
2622
2623 $self->add ($self->{vbox} = new CFClient::UI::VBox);
2624
2625 for my $item (@{ $self->{items} }) {
2626 my ($widget, $cb) = @$item;
2627
2628 # handle various types of items, only text for now
2629 if (!ref $widget) {
2630 $widget = new CFClient::UI::Label
2631 can_hover => 1,
2632 can_events => 1,
2633 text => $widget;
2634 }
2635
2636 $self->{item}{$widget} = $item;
2637
2638 $self->{vbox}->add ($widget);
2639 }
2640
2641 $self
2642}
2643
2644# popup given the event (must be a mouse button down event currently)
2645sub popup {
2646 my ($self, $ev) = @_;
2647
2648 $self->emit ("popdown");
2649
2650 # maybe save $GRAB? must be careful about events...
2651 $GRAB = $self;
2652 $self->{button} = $ev->{button};
2653
2654 $self->show;
2655 $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5);
2656}
2657
2658sub mouse_motion {
2659 my ($self, $ev, $x, $y) = @_;
2660
2661 # TODO: should use vbox->find_widget or so
2662 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2663 $self->{hover} = $self->{item}{$HOVER};
2664}
2665
2666sub button_up {
2667 my ($self, $ev, $x, $y) = @_;
2668
2669 if ($ev->{button} == $self->{button}) {
2670 undef $GRAB;
2671 $self->hide;
2672
2673 $self->emit ("popdown");
2674 $self->{hover}[1]->() if $self->{hover};
2675 }
2676}
2677
2678#############################################################################
2679
2411package CFClient::UI::Root; 2680package CFClient::UI::Root;
2412 2681
2413our @ISA = CFClient::UI::Container::; 2682our @ISA = CFClient::UI::Container::;
2414 2683
2415use CFClient::OpenGL; 2684use CFClient::OpenGL;
2416 2685
2417sub check_size { 2686sub check_size {
2418 my ($self) = @_; 2687 my ($self) = @_;
2419 2688
2420 $self->configure (0, 0, $::WIDTH, $::HEIGHT); 2689 $self->configure (0, 0, $self->{w}, $self->{h});
2421} 2690}
2422 2691
2423sub size_request { 2692sub size_request {
2424 ($::WIDTH, $::HEIGHT) 2693 my ($self) = @_;
2694
2695 ($self->{w}, $self->{h})
2696}
2697
2698sub size_allocate {
2699 my ($self, $w, $h) = @_;
2700
2701 my $old_w = $self->{old_w};
2702 my $old_h = $self->{old_h};
2703
2704 if ($old_w && $old_h) {
2705 for my $child ($self->children) {
2706 $child->{x} = int 0.5 + $child->{x} * $w / $old_w;
2707 $child->{w} = int 0.5 + $child->{w} * $w / $old_w;
2708 $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w};
2709 $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w};
2710 $child->{y} = int 0.5 + $child->{y} * $h / $old_h;
2711 $child->{h} = int 0.5 + $child->{h} * $h / $old_h;
2712 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h};
2713 $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h};
2714 }
2715 }
2716
2717 $self->{old_w} = $w;
2718 $self->{old_h} = $h;
2425} 2719}
2426 2720
2427sub configure { 2721sub configure {
2428 my ($self, $x, $y, $w, $h) = @_; 2722 my ($self, $x, $y, $w, $h) = @_;
2429 2723
2430 $self->SUPER::configure ($x, $y, $w, $h); 2724 $self->SUPER::configure ($x, $y, $w, $h);
2431 2725
2432 for my $child (@{$self->{children}}) { 2726 for my $child ($self->children) {
2433 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 2727 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2434 2728
2435 $X = List::Util::max 0, List::Util::min $w - $W, $X; 2729 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2436 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 2730 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2437 $child->configure ($X, $Y, $W,$H); 2731 $child->configure ($X, $Y, $W, $H);
2438 } 2732 }
2439} 2733}
2440 2734
2441sub _topleft { 2735sub _topleft {
2442 my ($self, $x, $y) = @_; 2736 my ($self, $x, $y) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines