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.199 by root, Fri May 12 15:45:42 2006 UTC vs.
Revision 1.207 by elmex, Mon May 15 18:23:33 2006 UTC

11our ($FOCUS, $HOVER, $GRAB); # various widgets 11our ($FOCUS, $HOVER, $GRAB); # various widgets
12 12
13our $ROOT; 13our $ROOT;
14our $TOOLTIP; 14our $TOOLTIP;
15our $BUTTON_STATE; 15our $BUTTON_STATE;
16
17our %WIDGET; # all widgets, weak-referenced
16 18
17sub check_tooltip { 19sub check_tooltip {
18 if (!$GRAB) { 20 if (!$GRAB) {
19 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 21 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
20 if (length $widget->{tooltip}) { 22 if (length $widget->{tooltip}) {
29 $TOOLTIP->set_tooltip_from ($widget); 31 $TOOLTIP->set_tooltip_from ($widget);
30 $TOOLTIP->show; 32 $TOOLTIP->show;
31 33
32 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 34 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
33 35
34 if ($x + $TOOLTIP->{w} > $::WIDTH) {
35 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); 36 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0)
36 } 37 if $x + $TOOLTIP->{w} > $::WIDTH;
37 38
38 $TOOLTIP->move ($x, $y); 39 $TOOLTIP->move ($x, $y);
39 $TOOLTIP->check_size; 40 $TOOLTIP->check_size;
40 $TOOLTIP->update; 41 $TOOLTIP->update;
41 } 42 }
132 133
133 for (@$vals) { 134 for (@$vals) {
134 my $i = int $_ + $rem; 135 my $i = int $_ + $rem;
135 $rem += $_ - $i; 136 $rem += $_ - $i;
136 $_ = $i; 137 $_ = $i;
138 }
139}
140
141# call when resolution changes etc.
142sub rescale_widgets {
143 my ($sx, $sy) = @_;
144
145 for my $widget (values %WIDGET) {
146 if ($widget->{toplevel}) {
147 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x};
148 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
149 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w};
150 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
151 $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y};
152 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
153 $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h};
154 $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h};
155 }
156
157 $widget->reconfigure;
137 } 158 }
138} 159}
139 160
140############################################################################# 161#############################################################################
141 162
160 if (/^connect_(.*)$/) { 181 if (/^connect_(.*)$/) {
161 $self->connect ($1 => delete $self->{$_}); 182 $self->connect ($1 => delete $self->{$_});
162 } 183 }
163 } 184 }
164 185
186 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self);
187
165 $self 188 $self
166} 189}
167 190
168sub destroy { 191sub destroy {
169 my ($self) = @_; 192 my ($self) = @_;
242 265
243sub size_allocate { 266sub size_allocate {
244 # nothing to be done 267 # nothing to be done
245} 268}
246 269
247sub children {
248}
249
250# call when resolution changes etc.
251sub reconfigure { 270sub reconfigure {
252 my ($self) = @_; 271 my ($self) = @_;
253
254 $_->reconfigure
255 for $self->children;
256 272
257 $self->check_size (1); 273 $self->check_size (1);
258 $self->update; 274 $self->update;
275}
276
277sub children {
259} 278}
260 279
261sub set_max_size { 280sub set_max_size {
262 my ($self, $w, $h) = @_; 281 my ($self, $w, $h) = @_;
263 282
356 glVertex $self->{w}, 0; 375 glVertex $self->{w}, 0;
357 glVertex $self->{w}, $self->{h}; 376 glVertex $self->{w}, $self->{h};
358 glVertex 0 , $self->{h}; 377 glVertex 0 , $self->{h};
359 glEnd; 378 glEnd;
360 glPopMatrix; 379 glPopMatrix;
361 CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 380 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
362 } 381 }
363} 382}
364 383
365sub _draw { 384sub _draw {
366 my ($self) = @_; 385 my ($self) = @_;
417} 436}
418 437
419sub DESTROY { 438sub DESTROY {
420 my ($self) = @_; 439 my ($self) = @_;
421 440
441 delete $WIDGET{$self+0};
422 #$self->deactivate; 442 #$self->deactivate;
423} 443}
424 444
425############################################################################# 445#############################################################################
426 446
840 860
841 my $self = $class->SUPER::new ( 861 my $self = $class->SUPER::new (
842 bg => [1, 1, 1, 1], 862 bg => [1, 1, 1, 1],
843 border_bg => [1, 1, 1, 1], 863 border_bg => [1, 1, 1, 1],
844 border => 0.6, 864 border => 0.6,
865 toplevel => 1,
845 can_events => 1, 866 can_events => 1,
846 @_ 867 @_
847 ); 868 );
848 869
849 $self->{title} &&= new CFClient::UI::Label 870 $self->{title} &&= new CFClient::UI::Label
1480 my $sym = $ev->{sym}; 1501 my $sym = $ev->{sym};
1481 my $uni = $ev->{unicode}; 1502 my $uni = $ev->{unicode};
1482 1503
1483 my $text = $self->get_text; 1504 my $text = $self->get_text;
1484 1505
1485 if ($sym == 8) { 1506 if ($uni == 8) {
1486 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1507 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1487 } elsif ($sym == 127) { 1508 } elsif ($uni == 127) {
1488 substr $text, $self->{cursor}, 1, ""; 1509 substr $text, $self->{cursor}, 1, "";
1489 } elsif ($sym == CFClient::SDLK_LEFT) { 1510 } elsif ($sym == CFClient::SDLK_LEFT) {
1490 --$self->{cursor} if $self->{cursor}; 1511 --$self->{cursor} if $self->{cursor};
1491 } elsif ($sym == CFClient::SDLK_RIGHT) { 1512 } elsif ($sym == CFClient::SDLK_RIGHT) {
1492 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1513 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1493 } elsif ($sym == CFClient::SDLK_HOME) { 1514 } elsif ($sym == CFClient::SDLK_HOME) {
1494 $self->{cursor} = 0; 1515 $self->{cursor} = 0;
1495 } elsif ($sym == CFClient::SDLK_END) { 1516 } elsif ($sym == CFClient::SDLK_END) {
1496 $self->{cursor} = length $text; 1517 $self->{cursor} = length $text;
1497 } elsif ($sym == 27) { 1518 } elsif ($uni == 27) {
1498 $self->emit ('escape'); 1519 $self->emit ('escape');
1499 } elsif ($uni) { 1520 } elsif ($uni) {
1500 substr $text, $self->{cursor}++, 0, chr $uni; 1521 substr $text, $self->{cursor}++, 0, chr $uni;
1501 } 1522 }
1502 1523
1989 qw(s1_slider.png s1_slider_bg.png); 2010 qw(s1_slider.png s1_slider_bg.png);
1990 2011
1991sub new { 2012sub new {
1992 my $class = shift; 2013 my $class = shift;
1993 2014
1994 # range [value, low, high, page] 2015 # range [value, low, high, page, unit]
1995 2016
1996 # TODO: 0-width page 2017 # TODO: 0-width page
1997 # TODO: req_w/h are wrong with vertical 2018 # TODO: req_w/h are wrong with vertical
1998 # TODO: calculations are off 2019 # TODO: calculations are off
1999 my $self = $class->SUPER::new ( 2020 my $self = $class->SUPER::new (
2002 range => [0, 0, 100, 10], 2023 range => [0, 0, 100, 10],
2003 req_w => $::WIDTH / 80, 2024 req_w => $::WIDTH / 80,
2004 req_h => $::WIDTH / 80, 2025 req_h => $::WIDTH / 80,
2005 vertical => 0, 2026 vertical => 0,
2006 can_hover => 1, 2027 can_hover => 1,
2007 inner_pad => 5, 2028 inner_pad => .05,
2008 @_ 2029 @_
2009 ); 2030 );
2010 2031
2032 $self->set_value ($self->{range}[0]);
2033 $self->update;
2034
2011 $self 2035 $self
2036}
2037
2038sub set_value {
2039 my ($self, $value) = @_;
2040
2041 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
2042
2043 $hi = $lo + 1 if $hi <= $lo;
2044
2045 $value = $lo if $value < $lo;
2046 $value = $hi if $value > $hi;
2047
2048 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
2049 if $unit;
2050
2051 $page = $hi - $lo if $page > $hi - $lo;
2052
2053 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
2054
2055 if ($value != $old_value) {
2056 $self->emit (changed => $value);
2057 $self->update;
2058 }
2012} 2059}
2013 2060
2014sub size_request { 2061sub size_request {
2015 my ($self) = @_; 2062 my ($self) = @_;
2016 2063
2029 2076
2030sub mouse_motion { 2077sub mouse_motion {
2031 my ($self, $ev, $x, $y) = @_; 2078 my ($self, $ev, $x, $y) = @_;
2032 2079
2033 if ($GRAB == $self) { 2080 if ($GRAB == $self) {
2081 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
2082
2083 my (undef, $lo, $hi, $page) = @{$self->{range}};
2084
2085 $x = $x / ($w * (1 - 2 * $self->{inner_pad})) - $self->{inner_pad};
2086
2087 $self->set_value ($x * ($hi - $lo) + $lo);
2088 }
2089}
2090
2091sub update {
2092 my ($self) = @_;
2093
2094 $CFClient::UI::ROOT->on_post_alloc ($self => sub {
2095 $self->set_value ($self->{range}[0]);
2096
2034 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2097 my ($value, $lo, $hi, $page) = @{$self->{range}};
2035 2098
2036 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 2099 my $inner_w = 1 - 2 * $self->{inner_pad};
2037 2100
2038 my $inner_pad_px = $self->_calc_inner_pad_px ($w); 2101 $self->{scale} = ($inner_w / ($hi - $lo)) || 1;
2039 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
2040 2102
2041 $x -= $inner_pad_px; # substract the padding 2103 $page = $self->{scale} * $page || 10 / ($self->{w} || 1);
2042 $x = $x * ($hi - $lo) / $inner_w + $lo; 2104 $value = $self->{scale} * ($value - $lo);
2043 $x = $lo if $x < $lo;
2044 $x = $hi - $page if $x > $hi - $page;
2045 $self->{range}[0] = $x;
2046 2105
2047 $self->emit (changed => $x); 2106 $value = $self->{inner_pad} + ($value - $page * 0.5);
2048 $self->update; 2107
2108 $value = 0 if $value < 0;
2109 $page = 1 - $value if $value + $page > 1;
2110
2111 $self->{knob_x} = $value;
2112 $self->{knob_w} = $page;
2049 } 2113 });
2050}
2051 2114
2052# the inner_* stuff is for generating a padding for the slider handle, 2115 $self->SUPER::update;
2053# so that the handle doesn't leave the texture. This calculation isn't 100%
2054# correct propably, but it does the job for now
2055sub _calc_inner_pad_px {
2056 my ($self, $w) = @_;
2057 ($w / 100) * $self->{inner_pad} # % to pixels
2058} 2116}
2059 2117
2060sub _draw { 2118sub _draw {
2061 my ($self) = @_; 2119 my ($self) = @_;
2062 2120
2063 $self->SUPER::_draw (); 2121 $self->SUPER::_draw ();
2064 2122
2065 my ($w, $h) = @$self{qw(w h)}; 2123 glScale $self->{w}, $self->{h};
2066 2124
2067 if ($self->{vertical}) { 2125 if ($self->{vertical}) {
2068 # draw a vertical slider like a rotated horizontal slider 2126 # draw a vertical slider like a rotated horizontal slider
2069 2127
2070 glRotate 90, 0, 0, 1; 2128 glRotate 90, 0, 0, 1;
2071 glTranslate 0, -$self->{w}, 0; 2129 glTranslate 0, 1, 0;
2072
2073 ($w, $h) = ($h, $w);
2074 } 2130 }
2075 2131
2076 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2132 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2077 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2133 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2078 2134
2079 my ($value, $lo, $hi, $page) = @{$self->{range}};
2080
2081 $hi = $value + 1 if $lo == $hi;
2082
2083 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
2084 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
2085
2086 $page = int $page * $inner_w / ($hi - $lo);
2087 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
2088
2089 $w -= $page;
2090 $page &= ~1;
2091 glTranslate $page * 0.5, 0, 0;
2092 $page ||= 2;
2093
2094 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
2095 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
2096
2097 glEnable GL_TEXTURE_2D; 2135 glEnable GL_TEXTURE_2D;
2098 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2136 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2099 2137
2100 # draw background 2138 # draw background
2101 $tex[1]->draw_quad_alpha (0, 0, $w, $h); 2139 $tex[1]->draw_quad_alpha (0, 0, 1, 1);
2102 2140
2103 # draw handle 2141 # draw handle
2104 $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); 2142 $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1);
2105 2143
2106 glDisable GL_TEXTURE_2D; 2144 glDisable GL_TEXTURE_2D;
2107} 2145}
2108 2146
2109############################################################################# 2147#############################################################################
2466 2504
2467 my $desc = $item->{nrof} < 2 2505 my $desc = $item->{nrof} < 2
2468 ? $item->{name} 2506 ? $item->{name}
2469 : "$item->{nrof} $item->{name_pl}"; 2507 : "$item->{nrof} $item->{name_pl}";
2470 2508
2509 $item->{flags} & Crossfire::Protocol::F_OPEN
2510 and $desc .= " (open)";
2511 $item->{flags} & Crossfire::Protocol::F_APPLIED
2512 and $desc .= " (applied)";
2513 $item->{flags} & Crossfire::Protocol::F_UNPAID
2514 and $desc .= " (unpaid)";
2515 $item->{flags} & Crossfire::Protocol::F_MAGIC
2516 and $desc .= " (magic)";
2517 $item->{flags} & Crossfire::Protocol::F_CURSED
2518 and $desc .= " (cursed)";
2519 $item->{flags} & Crossfire::Protocol::F_DAMNED
2520 and $desc .= " (damned)";
2521 $item->{flags} & Crossfire::Protocol::F_LOCKED
2522 and $desc .= " *";
2471 2523
2472 my $self = $class->SUPER::new ( 2524 my $self = $class->SUPER::new (
2473 can_hover => 1, 2525 can_hover => 1,
2474 can_events => 1, 2526 can_events => 1,
2475 tooltip => (CFClient::UI::Label->escape ($desc) 2527 tooltip => (CFClient::UI::Label->escape ($desc)
2481 if ($ev->{button} == 1) { 2533 if ($ev->{button} == 1) {
2482 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); 2534 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0");
2483 } elsif ($ev->{button} == 2) { 2535 } elsif ($ev->{button} == 2) {
2484 $::CONN->send ("apply $item->{tag}"); 2536 $::CONN->send ("apply $item->{tag}");
2485 } elsif ($ev->{button} == 3) { 2537 } elsif ($ev->{button} == 3) {
2486 CFClient::UI::Menu->new ( 2538 my @menu_items = (
2487 items => [
2488 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2539 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2540 ["mark", sub { $::CONN->send ("mark $item->{tag}") }],
2541 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2542 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2489 [ 2543 [
2490 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", 2544 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2491 sub { $::CONN->send ("lock $item->{tag}") }, 2545 sub { $::CONN->send ("lock ". () ."$item->{tag}") },
2492 ],
2493 ["mark", sub { $::CONN->send ("mark $item->{tag}") }],
2494 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2495 ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }],
2496 ], 2546 ],
2497 )->popup ($ev); 2547 );
2548
2549 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2498 } 2550 }
2499 2551
2500 1 2552 1
2501 }, 2553 },
2502 %args 2554 %args
2538 my ($self, $items) = @_; 2590 my ($self, $items) = @_;
2539 2591
2540 $self->{scrolled}->clear; 2592 $self->{scrolled}->clear;
2541 return unless $items; 2593 return unless $items;
2542 2594
2543 my @items = sort { $a->{type} <=> $b->{type} } @$items; 2595 my @items = sort {
2596 ($a->{type} <=> $b->{type})
2597 or ($a->{name} cmp $b->{name})
2598 } @$items;
2544 2599
2545 $self->{real_items} = \@items; 2600 $self->{real_items} = \@items;
2546 2601
2547 for my $item (@items) { 2602 for my $item (@items) {
2548 my $desc = $item->{nrof} < 2 2603 my $desc = $item->{nrof} < 2
2549 ? $item->{name} 2604 ? $item->{name}
2550 : "$item->{nrof} $item->{name_pl}"; 2605 : "$item->{nrof} $item->{name_pl}";
2551 2606
2552 $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item); 2607 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2553 } 2608 }
2609
2610 $self->{scrolled}->add (@items);
2554 2611
2555# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2612# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2556} 2613}
2557 2614
2558sub size_request { 2615sub size_request {
2663 ? "<b>$item->{count} ×</b> $item->{text}" 2720 ? "<b>$item->{count} ×</b> $item->{text}"
2664 : $item->{text}; 2721 : $item->{text};
2665 2722
2666 for ($short) { 2723 for ($short) {
2667 s/^\s+//; 2724 s/^\s+//;
2668 s/\012.*/…/s; 2725 s/\s+/ /g;
2669 my $len = int 40 / $item->{fontsize}; 2726 my $len = int 40 / $item->{fontsize};
2670 substr $_, $len, length, "…" if $len < length; 2727 substr $_, $len, length, "…" if $len < length;
2671 } 2728 }
2672 2729
2673 new CFClient::UI::Label 2730 new CFClient::UI::Label
2674 markup => $short, 2731 markup => $short,
2675 tooltip => $item->{tooltip}, 2732 tooltip => $item->{tooltip},
2676 tooltip_font => $::FONT_PROP, 2733 tooltip_font => $::FONT_PROP,
2677 tooltip_width => 0.67, 2734 tooltip_width => 0.67,
2678 fontsize => $item->{fontsize}, 2735 fontsize => $item->{fontsize},
2679 color => $item->{color}, 2736 fg => $item->{fg},
2680 can_events => 1, 2737 can_events => 1,
2681 can_hover => 1 2738 can_hover => 1
2682 }; 2739 };
2683 } 2740 }
2684 2741
2711 id => ++$self->{id}, 2768 id => ++$self->{id},
2712 text => $text, 2769 text => $text,
2713 timeout => $timeout, 2770 timeout => $timeout,
2714 tooltip => $text, 2771 tooltip => $text,
2715 fontsize => 0.8, 2772 fontsize => 0.8,
2716 color => [0.8, 0.8, 0.8, 0.8], 2773 fg => [0.8, 0.8, 0.8, 0.8],
2717 pri => 0, 2774 pri => 0,
2718 count => 1, 2775 count => 1,
2719 %arg, 2776 %arg,
2720 }; 2777 };
2721 } 2778 }
2760} 2817}
2761 2818
2762sub size_allocate { 2819sub size_allocate {
2763 my ($self, $w, $h) = @_; 2820 my ($self, $w, $h) = @_;
2764 2821
2765 my $old_w = $self->{old_w}; 2822 my $old_w = $self->{old_w}; $self->{old_w} = $w;
2766 my $old_h = $self->{old_h}; 2823 my $old_h = $self->{old_h}; $self->{old_h} = $h;
2767 2824
2768 if ($old_w && $old_h) { 2825 CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h
2769 for my $child ($self->children) { 2826 if $old_w && $old_h && ($old_w != $w || $old_h != $h);
2770 $child->{x} = int 0.5 + $child->{x} * $w / $old_w;
2771 $child->{w} = int 0.5 + $child->{w} * $w / $old_w;
2772 $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w};
2773 $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w};
2774 $child->{y} = int 0.5 + $child->{y} * $h / $old_h;
2775 $child->{h} = int 0.5 + $child->{h} * $h / $old_h;
2776 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h};
2777 $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h};
2778 }
2779 }
2780 2827
2781 for my $child ($self->children) { 2828 for my $child ($self->children) {
2782 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 2829 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2783 2830
2831 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1
2832 if exists $child->{req_x};
2833
2834 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1
2835 if exists $child->{req_y};
2836
2784 $X = List::Util::max 0, List::Util::min $w - $W, $X; 2837 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5;
2785 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 2838 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5;
2839
2786 $child->configure ($X, $Y, $W, $H); 2840 $child->configure ($X, $Y, $W, $H);
2787 } 2841 }
2788
2789 $self->{old_w} = $w;
2790 $self->{old_h} = $h;
2791} 2842}
2792 2843
2793sub coord2local { 2844sub coord2local {
2794 my ($self, $x, $y) = @_; 2845 my ($self, $x, $y) = @_;
2795 2846
2808 $self->check_size; 2859 $self->check_size;
2809 $::WANT_REFRESH++; 2860 $::WANT_REFRESH++;
2810} 2861}
2811 2862
2812sub add { 2863sub add {
2813 my ($self, $child) = @_; 2864 my ($self, @children) = @_;
2814 2865
2866 for my $child (@children) {
2867 $child->{toplevel} = 1;
2868
2815 # integerise window positions 2869 # integerise window positions
2816 $child->{x} = int $child->{x}; 2870 $child->{x} = int $child->{x};
2817 $child->{y} = int $child->{y}; 2871 $child->{y} = int $child->{y};
2872 }
2818 2873
2819 $self->SUPER::add ($child); 2874 $self->SUPER::add (@children);
2820} 2875}
2821 2876
2822sub on_refresh { 2877sub on_refresh {
2823 my ($self, $id, $cb) = @_; 2878 my ($self, $id, $cb) = @_;
2824 2879

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines