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.197 by root, Fri May 12 01:47:04 2006 UTC vs.
Revision 1.206 by root, Mon May 15 17:45:29 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
270sub reconfigure {
271 my ($self) = @_;
272
273 $self->check_size (1);
274 $self->update;
275}
276
247sub children { 277sub children {
248}
249
250# call when resolution changes etc.
251sub reconfigure {
252 my ($self) = @_;
253
254 $_->reconfigure
255 for $self->children;
256
257 $self->check_size;
258 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $self->{w}, $self->{h}];
259 $self->update;
260} 278}
261 279
262sub set_max_size { 280sub set_max_size {
263 my ($self, $w, $h) = @_; 281 my ($self, $w, $h) = @_;
264 282
357 glVertex $self->{w}, 0; 375 glVertex $self->{w}, 0;
358 glVertex $self->{w}, $self->{h}; 376 glVertex $self->{w}, $self->{h};
359 glVertex 0 , $self->{h}; 377 glVertex 0 , $self->{h};
360 glEnd; 378 glEnd;
361 glPopMatrix; 379 glPopMatrix;
362 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;
363 } 381 }
364} 382}
365 383
366sub _draw { 384sub _draw {
367 my ($self) = @_; 385 my ($self) = @_;
384sub set_parent { 402sub set_parent {
385 my ($self, $parent) = @_; 403 my ($self, $parent) = @_;
386 404
387 Scalar::Util::weaken ($self->{parent} = $parent); 405 Scalar::Util::weaken ($self->{parent} = $parent);
388 406
407 # TODO: req_w _does_change after ->reconfigure
389 $self->check_size 408 $self->check_size
390 unless exists $self->{req_w}; 409 unless exists $self->{req_w};
391} 410}
392 411
393sub check_size { 412sub check_size {
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
628} 648}
629 649
630sub update { 650sub update {
631 my ($self) = @_; 651 my ($self) = @_;
632 652
633 $ROOT->on_refresh ($self => sub { $self->render_child }); 653 $ROOT->on_post_alloc ($self => sub { $self->render_child });
634 $self->SUPER::update; 654 $self->SUPER::update;
635} 655}
636 656
637sub size_allocate { 657sub size_allocate {
638 my ($self, $w, $h) = @_; 658 my ($self, $w, $h) = @_;
776 $self->add ($self->{slider}); 796 $self->add ($self->{slider});
777 797
778 $self 798 $self
779} 799}
780 800
781#TODO# update range on size_allocate depeneing on child 801#TODO# update range on size_allocate depending on child
782# update viewport offset on scroll 802# update viewport offset on scroll
783 803
784############################################################################# 804#############################################################################
785 805
786package CFClient::UI::Frame; 806package CFClient::UI::Frame;
787 807
788our @ISA = CFClient::UI::Bin::; 808our @ISA = CFClient::UI::Bin::;
789 809
790use CFClient::OpenGL; 810use CFClient::OpenGL;
811
812sub new {
813 my $class = shift;
814
815 $class->SUPER::new (
816 bg => undef,
817 @_,
818 )
819}
820
821sub _draw {
822 my ($self) = @_;
823
824 if ($self->{bg}) {
825 my ($w, $h) = @$self{qw(w h)};
826
827 glEnable GL_BLEND;
828 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
829 glColor @{ $self->{bg} };
830
831 glBegin GL_QUADS;
832 glVertex 0 , 0;
833 glVertex 0 , $h;
834 glVertex $w, $h;
835 glVertex $w, 0;
836 glEnd;
837
838 glDisable GL_BLEND;
839 }
840
841 $self->SUPER::_draw;
842}
791 843
792############################################################################# 844#############################################################################
793 845
794package CFClient::UI::FancyFrame; 846package CFClient::UI::FancyFrame;
795 847
808 860
809 my $self = $class->SUPER::new ( 861 my $self = $class->SUPER::new (
810 bg => [1, 1, 1, 1], 862 bg => [1, 1, 1, 1],
811 border_bg => [1, 1, 1, 1], 863 border_bg => [1, 1, 1, 1],
812 border => 0.6, 864 border => 0.6,
865 toplevel => 1,
813 can_events => 1, 866 can_events => 1,
814 @_ 867 @_
815 ); 868 );
816 869
817 $self->{title} &&= new CFClient::UI::Label 870 $self->{title} &&= new CFClient::UI::Label
1448 my $sym = $ev->{sym}; 1501 my $sym = $ev->{sym};
1449 my $uni = $ev->{unicode}; 1502 my $uni = $ev->{unicode};
1450 1503
1451 my $text = $self->get_text; 1504 my $text = $self->get_text;
1452 1505
1453 if ($sym == 8) { 1506 if ($uni == 8) {
1454 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1507 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1455 } elsif ($sym == 127) { 1508 } elsif ($uni == 127) {
1456 substr $text, $self->{cursor}, 1, ""; 1509 substr $text, $self->{cursor}, 1, "";
1457 } elsif ($sym == CFClient::SDLK_LEFT) { 1510 } elsif ($sym == CFClient::SDLK_LEFT) {
1458 --$self->{cursor} if $self->{cursor}; 1511 --$self->{cursor} if $self->{cursor};
1459 } elsif ($sym == CFClient::SDLK_RIGHT) { 1512 } elsif ($sym == CFClient::SDLK_RIGHT) {
1460 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1513 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1461 } elsif ($sym == CFClient::SDLK_HOME) { 1514 } elsif ($sym == CFClient::SDLK_HOME) {
1462 $self->{cursor} = 0; 1515 $self->{cursor} = 0;
1463 } elsif ($sym == CFClient::SDLK_END) { 1516 } elsif ($sym == CFClient::SDLK_END) {
1464 $self->{cursor} = length $text; 1517 $self->{cursor} = length $text;
1465 } elsif ($sym == 27) { 1518 } elsif ($uni == 27) {
1466 $self->emit ('escape'); 1519 $self->emit ('escape');
1467 } elsif ($uni) { 1520 } elsif ($uni) {
1468 substr $text, $self->{cursor}++, 0, chr $uni; 1521 substr $text, $self->{cursor}++, 0, chr $uni;
1469 } 1522 }
1470 1523
1957 qw(s1_slider.png s1_slider_bg.png); 2010 qw(s1_slider.png s1_slider_bg.png);
1958 2011
1959sub new { 2012sub new {
1960 my $class = shift; 2013 my $class = shift;
1961 2014
1962 # range [value, low, high, page] 2015 # range [value, low, high, page, unit]
1963 2016
1964 # TODO: 0-width page 2017 # TODO: 0-width page
1965 # TODO: req_w/h are wrong with vertical 2018 # TODO: req_w/h are wrong with vertical
1966 # TODO: calculations are off 2019 # TODO: calculations are off
1967 my $self = $class->SUPER::new ( 2020 my $self = $class->SUPER::new (
1970 range => [0, 0, 100, 10], 2023 range => [0, 0, 100, 10],
1971 req_w => $::WIDTH / 80, 2024 req_w => $::WIDTH / 80,
1972 req_h => $::WIDTH / 80, 2025 req_h => $::WIDTH / 80,
1973 vertical => 0, 2026 vertical => 0,
1974 can_hover => 1, 2027 can_hover => 1,
1975 inner_pad => 5, 2028 inner_pad => .05,
1976 @_ 2029 @_
1977 ); 2030 );
1978 2031
2032 $self->set_value ($self->{range}[0]);
2033 $self->update;
2034
1979 $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 }
1980} 2059}
1981 2060
1982sub size_request { 2061sub size_request {
1983 my ($self) = @_; 2062 my ($self) = @_;
1984 2063
1997 2076
1998sub mouse_motion { 2077sub mouse_motion {
1999 my ($self, $ev, $x, $y) = @_; 2078 my ($self, $ev, $x, $y) = @_;
2000 2079
2001 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
2002 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2097 my ($value, $lo, $hi, $page) = @{$self->{range}};
2003 2098
2004 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 2099 my $inner_w = 1 - 2 * $self->{inner_pad};
2005 2100
2006 my $inner_pad_px = $self->_calc_inner_pad_px ($w); 2101 $self->{scale} = ($inner_w / ($hi - $lo)) || 1;
2007 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
2008 2102
2009 $x -= $inner_pad_px; # substract the padding 2103 $page = $self->{scale} * $page || 10 / ($self->{w} || 1);
2010 $x = $x * ($hi - $lo) / $inner_w + $lo; 2104 $value = $self->{scale} * ($value - $lo);
2011 $x = $lo if $x < $lo;
2012 $x = $hi - $page if $x > $hi - $page;
2013 $self->{range}[0] = $x;
2014 2105
2015 $self->emit (changed => $x); 2106 $value = $self->{inner_pad} + ($value - $page * 0.5);
2016 $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;
2017 } 2113 });
2018}
2019 2114
2020# the inner_* stuff is for generating a padding for the slider handle, 2115 $self->SUPER::update;
2021# so that the handle doesn't leave the texture. This calculation isn't 100%
2022# correct propably, but it does the job for now
2023sub _calc_inner_pad_px {
2024 my ($self, $w) = @_;
2025 ($w / 100) * $self->{inner_pad} # % to pixels
2026} 2116}
2027 2117
2028sub _draw { 2118sub _draw {
2029 my ($self) = @_; 2119 my ($self) = @_;
2030 2120
2031 $self->SUPER::_draw (); 2121 $self->SUPER::_draw ();
2032 2122
2033 my ($w, $h) = @$self{qw(w h)}; 2123 glScale $self->{w}, $self->{h};
2034 2124
2035 if ($self->{vertical}) { 2125 if ($self->{vertical}) {
2036 # draw a vertical slider like a rotated horizontal slider 2126 # draw a vertical slider like a rotated horizontal slider
2037 2127
2038 glRotate 90, 0, 0, 1; 2128 glRotate 90, 0, 0, 1;
2039 glTranslate 0, -$self->{w}, 0; 2129 glTranslate 0, 1, 0;
2040
2041 ($w, $h) = ($h, $w);
2042 } 2130 }
2043 2131
2044 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2132 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2045 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2133 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2046 2134
2047 my ($value, $lo, $hi, $page) = @{$self->{range}};
2048
2049 $hi = $value + 1 if $lo == $hi;
2050
2051 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
2052 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
2053
2054 $page = int $page * $inner_w / ($hi - $lo);
2055 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
2056
2057 $w -= $page;
2058 $page &= ~1;
2059 glTranslate $page * 0.5, 0, 0;
2060 $page ||= 2;
2061
2062 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
2063 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
2064
2065 glEnable GL_TEXTURE_2D; 2135 glEnable GL_TEXTURE_2D;
2066 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2136 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2067 2137
2068 # draw background 2138 # draw background
2069 $tex[1]->draw_quad_alpha (0, 0, $w, $h); 2139 $tex[1]->draw_quad_alpha (0, 0, 1, 1);
2070 2140
2071 # draw handle 2141 # draw handle
2072 $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);
2073 2143
2074 glDisable GL_TEXTURE_2D; 2144 glDisable GL_TEXTURE_2D;
2075} 2145}
2076 2146
2077############################################################################# 2147#############################################################################
2165 2235
2166 return unless $self->{h} > 0; 2236 return unless $self->{h} > 0;
2167 2237
2168 delete $self->{texture}; 2238 delete $self->{texture};
2169 2239
2170 $ROOT->on_refresh ($self, sub { 2240 $ROOT->on_post_alloc ($self, sub {
2171 if (delete $self->{need_reflow}) { 2241 if (delete $self->{need_reflow}) {
2172 my $height = 0; 2242 my $height = 0;
2173 2243
2174 $height += $_->[0] = $self->text_height ($_->[2]) 2244 $height += $_->[0] = $self->text_height ($_->[2])
2175 for @{$self->{par}}; 2245 for @{$self->{par}};
2506 my ($self, $items) = @_; 2576 my ($self, $items) = @_;
2507 2577
2508 $self->{scrolled}->clear; 2578 $self->{scrolled}->clear;
2509 return unless $items; 2579 return unless $items;
2510 2580
2511 my @items = sort { $a->{type} <=> $b->{type} } @$items; 2581 my @items = sort {
2582 ($a->{type} <=> $b->{type})
2583 or ($a->{name} cmp $b->{name})
2584 } @$items;
2512 2585
2513 $self->{real_items} = \@items; 2586 $self->{real_items} = \@items;
2514 2587
2515 for my $item (@items) { 2588 for my $item (@items) {
2516 my $desc = $item->{nrof} < 2 2589 my $desc = $item->{nrof} < 2
2517 ? $item->{name} 2590 ? $item->{name}
2518 : "$item->{nrof} $item->{name_pl}"; 2591 : "$item->{nrof} $item->{name_pl}";
2519 2592
2520 $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item); 2593 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2521 } 2594 }
2595
2596 $self->{scrolled}->add (@items);
2522 2597
2523# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2598# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2524} 2599}
2525 2600
2526sub size_request { 2601sub size_request {
2631 ? "<b>$item->{count} ×</b> $item->{text}" 2706 ? "<b>$item->{count} ×</b> $item->{text}"
2632 : $item->{text}; 2707 : $item->{text};
2633 2708
2634 for ($short) { 2709 for ($short) {
2635 s/^\s+//; 2710 s/^\s+//;
2636 s/\012.*/…/s; 2711 s/\s+/ /g;
2637 my $len = int 30 / $item->{fontsize}; 2712 my $len = int 40 / $item->{fontsize};
2638 substr $_, $len, length, "…" if $len < length; 2713 substr $_, $len, length, "…" if $len < length;
2639 } 2714 }
2640 2715
2641 new CFClient::UI::Label 2716 new CFClient::UI::Label
2642 markup => $short, 2717 markup => $short,
2643 tooltip => $item->{tooltip}, 2718 tooltip => $item->{tooltip},
2644 tooltip_font => $::FONT_PROP, 2719 tooltip_font => $::FONT_PROP,
2645 tooltip_width => 0.67, 2720 tooltip_width => 0.67,
2646 fontsize => $item->{fontsize}, 2721 fontsize => $item->{fontsize},
2647 color => $item->{color}, 2722 fg => $item->{fg},
2648 can_events => 1, 2723 can_events => 1,
2649 can_hover => 1 2724 can_hover => 1
2650 }; 2725 };
2651 } 2726 }
2652 2727
2654 $self->SUPER::add (reverse @widgets); 2729 $self->SUPER::add (reverse @widgets);
2655} 2730}
2656 2731
2657sub add { 2732sub add {
2658 my ($self, $text, %arg) = @_; 2733 my ($self, $text, %arg) = @_;
2734
2735 $text =~ s/^\s+//;
2736 $text =~ s/\s+$//;
2659 2737
2660 my $timeout = time + ((delete $arg{timeout}) || 60); 2738 my $timeout = time + ((delete $arg{timeout}) || 60);
2661 2739
2662 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 2740 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2663 2741
2666 $item->{count}++; 2744 $item->{count}++;
2667 } else { 2745 } else {
2668 $item->{count} = 1; 2746 $item->{count} = 1;
2669 $item->{text} = $item->{tooltip} = $text; 2747 $item->{text} = $item->{tooltip} = $text;
2670 } 2748 }
2749 $item->{id} = ++$self->{id};
2671 $item->{timeout} = $timeout; 2750 $item->{timeout} = $timeout;
2672 delete $item->{label}; 2751 delete $item->{label};
2673 } else { 2752 } else {
2674 $self->{item}{$group} = { 2753 $self->{item}{$group} = {
2675 id => ++$self->{id}, 2754 id => ++$self->{id},
2676 text => $text, 2755 text => $text,
2677 timeout => $timeout, 2756 timeout => $timeout,
2678 tooltip => $text, 2757 tooltip => $text,
2679 fontsize => 0.8, 2758 fontsize => 0.8,
2680 color => [0.8, 0.8, 0.8, 0.8], 2759 fg => [0.8, 0.8, 0.8, 0.8],
2681 pri => 0, 2760 pri => 0,
2682 count => 1, 2761 count => 1,
2683 %arg, 2762 %arg,
2684 }; 2763 };
2685 } 2764 }
2724} 2803}
2725 2804
2726sub size_allocate { 2805sub size_allocate {
2727 my ($self, $w, $h) = @_; 2806 my ($self, $w, $h) = @_;
2728 2807
2729 my $old_w = $self->{old_w}; 2808 my $old_w = $self->{old_w}; $self->{old_w} = $w;
2730 my $old_h = $self->{old_h}; 2809 my $old_h = $self->{old_h}; $self->{old_h} = $h;
2731 2810
2732 if ($old_w && $old_h) { 2811 CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h
2733 for my $child ($self->children) { 2812 if $old_w && $old_h && ($old_w != $w || $old_h != $h);
2734 $child->{x} = int 0.5 + $child->{x} * $w / $old_w;
2735 $child->{w} = int 0.5 + $child->{w} * $w / $old_w;
2736 $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w};
2737 $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w};
2738 $child->{y} = int 0.5 + $child->{y} * $h / $old_h;
2739 $child->{h} = int 0.5 + $child->{h} * $h / $old_h;
2740 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h};
2741 $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h};
2742 }
2743 }
2744 2813
2745 for my $child ($self->children) { 2814 for my $child ($self->children) {
2746 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 2815 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2747 2816
2817 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1
2818 if exists $child->{req_x};
2819
2820 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1
2821 if exists $child->{req_y};
2822
2748 $X = List::Util::max 0, List::Util::min $w - $W, $X; 2823 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5;
2749 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 2824 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5;
2825
2750 $child->configure ($X, $Y, $W, $H); 2826 $child->configure ($X, $Y, $W, $H);
2751 } 2827 }
2752
2753 $self->{old_w} = $w;
2754 $self->{old_h} = $h;
2755} 2828}
2756 2829
2757sub coord2local { 2830sub coord2local {
2758 my ($self, $x, $y) = @_; 2831 my ($self, $x, $y) = @_;
2759 2832
2772 $self->check_size; 2845 $self->check_size;
2773 $::WANT_REFRESH++; 2846 $::WANT_REFRESH++;
2774} 2847}
2775 2848
2776sub add { 2849sub add {
2777 my ($self, $child) = @_; 2850 my ($self, @children) = @_;
2778 2851
2852 for my $child (@children) {
2853 $child->{toplevel} = 1;
2854
2779 # integerise window positions 2855 # integerise window positions
2780 $child->{x} = int $child->{x}; 2856 $child->{x} = int $child->{x};
2781 $child->{y} = int $child->{y}; 2857 $child->{y} = int $child->{y};
2858 }
2782 2859
2783 $self->SUPER::add ($child); 2860 $self->SUPER::add (@children);
2784} 2861}
2785 2862
2786sub on_refresh { 2863sub on_refresh {
2787 my ($self, $id, $cb) = @_; 2864 my ($self, $id, $cb) = @_;
2788 2865
2789 $self->{refresh_hook}{$id} = $cb; 2866 $self->{refresh_hook}{$id} = $cb;
2790} 2867}
2791 2868
2869sub on_post_alloc {
2870 my ($self, $id, $cb) = @_;
2871
2872 $self->{post_alloc_hook}{$id} = $cb;
2873}
2874
2792sub draw { 2875sub draw {
2793 my ($self) = @_; 2876 my ($self) = @_;
2877
2878 while ($self->{refresh_hook}) {
2879 $_->()
2880 for values %{delete $self->{refresh_hook}};
2881 }
2794 2882
2795 if ($self->{check_size}) { 2883 if ($self->{check_size}) {
2796 my @queue = ([], []); 2884 my @queue = ([], []);
2797 2885
2798 for (;;) { 2886 for (;;) {
2835 $widget->size_allocate ($w, $h); 2923 $widget->size_allocate ($w, $h);
2836 $widget->emit (size_allocate => $w, $h); 2924 $widget->emit (size_allocate => $w, $h);
2837 } 2925 }
2838 } 2926 }
2839 2927
2840 while ($self->{refresh_hook}) { 2928 while ($self->{post_alloc_hook}) {
2841 $_->() 2929 $_->()
2842 for values %{delete $self->{refresh_hook}}; 2930 for values %{delete $self->{post_alloc_hook}};
2843 } 2931 }
2844 2932
2845 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2933 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2846 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2934 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2847 glClear GL_COLOR_BUFFER_BIT; 2935 glClear GL_COLOR_BUFFER_BIT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines