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.208 by root, Mon May 15 22:52:17 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
874 my ($self, $w, $h) = @_; 895 my ($self, $w, $h) = @_;
875 896
876 $h -= List::Util::max 0, $self->border * 2; 897 $h -= List::Util::max 0, $self->border * 2;
877 $w -= List::Util::max 0, $self->border * 2; 898 $w -= List::Util::max 0, $self->border * 2;
878 899
879 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) 900 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
880 if $self->{title}; 901 if $self->{title};
881 902
882 $self->child->configure ($self->border, $self->border, $w, $h); 903 $self->child->configure ($self->border, $self->border, $w, $h);
883} 904}
884 905
1378 $self->{layout}->set_width ($self->{w}); 1399 $self->{layout}->set_width ($self->{w});
1379 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1400 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1380 1401
1381 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1402 my $tex = new_from_layout CFClient::Texture $self->{layout};
1382 1403
1383 $self->{ox} = int $self->{align} < 0 ? $self->{padding} 1404 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1384 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1405 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1385 : ($self->{w} - $tex->{w}) * 0.5; 1406 : ($self->{w} - $tex->{w}) * 0.5);
1386 1407
1387 $self->{oy} = int $self->{valign} < 0 ? $self->{padding} 1408 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding}
1388 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1409 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1389 : ($self->{h} - $tex->{h}) * 0.5; 1410 : ($self->{h} - $tex->{h}) * 0.5);
1390 1411
1391 $tex 1412 $tex
1392 }; 1413 };
1393 1414
1394 glEnable GL_TEXTURE_2D; 1415 glEnable GL_TEXTURE_2D;
1449sub set_text { 1470sub set_text {
1450 my ($self, $text) = @_; 1471 my ($self, $text) = @_;
1451 1472
1452 $self->{cursor} = length $text; 1473 $self->{cursor} = length $text;
1453 $self->_set_text ($text); 1474 $self->_set_text ($text);
1475 $self->update;
1454 $self->check_size; 1476 $self->check_size;
1455 $self->update;
1456} 1477}
1457 1478
1458sub get_text { 1479sub get_text {
1459 $_[0]{text} 1480 $_[0]{text}
1460} 1481}
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
1503 $self->_set_text ($text); 1524 $self->_set_text ($text);
1504 $self->update; 1525 $self->update;
1526 $self->check_size;
1505} 1527}
1506 1528
1507sub focus_in { 1529sub focus_in {
1508 my ($self) = @_; 1530 my ($self) = @_;
1509 1531
1989 qw(s1_slider.png s1_slider_bg.png); 2011 qw(s1_slider.png s1_slider_bg.png);
1990 2012
1991sub new { 2013sub new {
1992 my $class = shift; 2014 my $class = shift;
1993 2015
1994 # range [value, low, high, page] 2016 # range [value, low, high, page, unit]
1995 2017
1996 # TODO: 0-width page 2018 # TODO: 0-width page
1997 # TODO: req_w/h are wrong with vertical 2019 # TODO: req_w/h are wrong with vertical
1998 # TODO: calculations are off 2020 # TODO: calculations are off
1999 my $self = $class->SUPER::new ( 2021 my $self = $class->SUPER::new (
2002 range => [0, 0, 100, 10], 2024 range => [0, 0, 100, 10],
2003 req_w => $::WIDTH / 80, 2025 req_w => $::WIDTH / 80,
2004 req_h => $::WIDTH / 80, 2026 req_h => $::WIDTH / 80,
2005 vertical => 0, 2027 vertical => 0,
2006 can_hover => 1, 2028 can_hover => 1,
2007 inner_pad => 5, 2029 inner_pad => .05,
2008 @_ 2030 @_
2009 ); 2031 );
2010 2032
2033 $self->set_value ($self->{range}[0]);
2034 $self->update;
2035
2011 $self 2036 $self
2037}
2038
2039sub set_value {
2040 my ($self, $value) = @_;
2041
2042 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
2043
2044 $hi = $lo + 1 if $hi <= $lo;
2045
2046 $value = $lo if $value < $lo;
2047 $value = $hi if $value > $hi;
2048
2049 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
2050 if $unit;
2051
2052 $page = $hi - $lo if $page > $hi - $lo;
2053
2054 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
2055
2056 if ($value != $old_value) {
2057 $self->emit (changed => $value);
2058 $self->update;
2059 }
2012} 2060}
2013 2061
2014sub size_request { 2062sub size_request {
2015 my ($self) = @_; 2063 my ($self) = @_;
2016 2064
2029 2077
2030sub mouse_motion { 2078sub mouse_motion {
2031 my ($self, $ev, $x, $y) = @_; 2079 my ($self, $ev, $x, $y) = @_;
2032 2080
2033 if ($GRAB == $self) { 2081 if ($GRAB == $self) {
2082 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
2083
2084 my (undef, $lo, $hi, $page) = @{$self->{range}};
2085
2086 $x = $x / ($w * (1 - 2 * $self->{inner_pad})) - $self->{inner_pad};
2087
2088 $self->set_value ($x * ($hi - $lo) + $lo);
2089 }
2090}
2091
2092sub update {
2093 my ($self) = @_;
2094
2095 $CFClient::UI::ROOT->on_post_alloc ($self => sub {
2096 $self->set_value ($self->{range}[0]);
2097
2034 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2098 my ($value, $lo, $hi, $page) = @{$self->{range}};
2035 2099
2036 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 2100 my $inner_w = 1 - 2 * $self->{inner_pad};
2037 2101
2038 my $inner_pad_px = $self->_calc_inner_pad_px ($w); 2102 $self->{scale} = ($inner_w / ($hi - $lo)) || 1;
2039 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
2040 2103
2041 $x -= $inner_pad_px; # substract the padding 2104 $page = $self->{scale} * $page || 10 / ($self->{w} || 1);
2042 $x = $x * ($hi - $lo) / $inner_w + $lo; 2105 $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 2106
2047 $self->emit (changed => $x); 2107 $value = $self->{inner_pad} + ($value - $page * 0.5);
2048 $self->update; 2108
2109 $value = 0 if $value < 0;
2110 $page = 1 - $value if $value + $page > 1;
2111
2112 $self->{knob_x} = $value;
2113 $self->{knob_w} = $page;
2049 } 2114 });
2050}
2051 2115
2052# the inner_* stuff is for generating a padding for the slider handle, 2116 $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} 2117}
2059 2118
2060sub _draw { 2119sub _draw {
2061 my ($self) = @_; 2120 my ($self) = @_;
2062 2121
2063 $self->SUPER::_draw (); 2122 $self->SUPER::_draw ();
2064 2123
2065 my ($w, $h) = @$self{qw(w h)}; 2124 glScale $self->{w}, $self->{h};
2066 2125
2067 if ($self->{vertical}) { 2126 if ($self->{vertical}) {
2068 # draw a vertical slider like a rotated horizontal slider 2127 # draw a vertical slider like a rotated horizontal slider
2069 2128
2070 glRotate 90, 0, 0, 1; 2129 glRotate 90, 0, 0, 1;
2071 glTranslate 0, -$self->{w}, 0; 2130 glTranslate 0, 1, 0;
2072
2073 ($w, $h) = ($h, $w);
2074 } 2131 }
2075 2132
2076 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2133 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2077 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2134 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2078 2135
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; 2136 glEnable GL_TEXTURE_2D;
2098 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2137 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2099 2138
2100 # draw background 2139 # draw background
2101 $tex[1]->draw_quad_alpha (0, 0, $w, $h); 2140 $tex[1]->draw_quad_alpha (0, 0, 1, 1);
2102 2141
2103 # draw handle 2142 # draw handle
2104 $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); 2143 $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1);
2105 2144
2106 glDisable GL_TEXTURE_2D; 2145 glDisable GL_TEXTURE_2D;
2107} 2146}
2108 2147
2109############################################################################# 2148#############################################################################
2466 2505
2467 my $desc = $item->{nrof} < 2 2506 my $desc = $item->{nrof} < 2
2468 ? $item->{name} 2507 ? $item->{name}
2469 : "$item->{nrof} $item->{name_pl}"; 2508 : "$item->{nrof} $item->{name_pl}";
2470 2509
2510 $item->{flags} & Crossfire::Protocol::F_OPEN
2511 and $desc .= " (open)";
2512 $item->{flags} & Crossfire::Protocol::F_APPLIED
2513 and $desc .= " (applied)";
2514 $item->{flags} & Crossfire::Protocol::F_UNPAID
2515 and $desc .= " (unpaid)";
2516 $item->{flags} & Crossfire::Protocol::F_MAGIC
2517 and $desc .= " (magic)";
2518 $item->{flags} & Crossfire::Protocol::F_CURSED
2519 and $desc .= " (cursed)";
2520 $item->{flags} & Crossfire::Protocol::F_DAMNED
2521 and $desc .= " (damned)";
2522 $item->{flags} & Crossfire::Protocol::F_LOCKED
2523 and $desc .= " *";
2471 2524
2472 my $self = $class->SUPER::new ( 2525 my $self = $class->SUPER::new (
2473 can_hover => 1, 2526 can_hover => 1,
2474 can_events => 1, 2527 can_events => 1,
2475 tooltip => (CFClient::UI::Label->escape ($desc) 2528 tooltip => (CFClient::UI::Label->escape ($desc)
2481 if ($ev->{button} == 1) { 2534 if ($ev->{button} == 1) {
2482 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); 2535 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0");
2483 } elsif ($ev->{button} == 2) { 2536 } elsif ($ev->{button} == 2) {
2484 $::CONN->send ("apply $item->{tag}"); 2537 $::CONN->send ("apply $item->{tag}");
2485 } elsif ($ev->{button} == 3) { 2538 } elsif ($ev->{button} == 3) {
2486 CFClient::UI::Menu->new ( 2539 my @menu_items = (
2487 items => [
2488 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2540 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2541 ["mark", sub { $::CONN->send ("mark $item->{tag}") }],
2542 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2543 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2489 [ 2544 [
2490 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", 2545 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2491 sub { $::CONN->send ("lock $item->{tag}") }, 2546 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 ], 2547 ],
2497 )->popup ($ev); 2548 );
2549
2550 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2498 } 2551 }
2499 2552
2500 1 2553 1
2501 }, 2554 },
2502 %args 2555 %args
2538 my ($self, $items) = @_; 2591 my ($self, $items) = @_;
2539 2592
2540 $self->{scrolled}->clear; 2593 $self->{scrolled}->clear;
2541 return unless $items; 2594 return unless $items;
2542 2595
2543 my @items = sort { $a->{type} <=> $b->{type} } @$items; 2596 my @items = sort {
2597 ($a->{type} <=> $b->{type})
2598 or ($a->{name} cmp $b->{name})
2599 } @$items;
2544 2600
2545 $self->{real_items} = \@items; 2601 $self->{real_items} = \@items;
2546 2602
2547 for my $item (@items) { 2603 for my $item (@items) {
2548 my $desc = $item->{nrof} < 2 2604 my $desc = $item->{nrof} < 2
2549 ? $item->{name} 2605 ? $item->{name}
2550 : "$item->{nrof} $item->{name_pl}"; 2606 : "$item->{nrof} $item->{name_pl}";
2551 2607
2552 $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item); 2608 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2553 } 2609 }
2610
2611 $self->{scrolled}->add (@items);
2554 2612
2555# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2613# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2556} 2614}
2557 2615
2558sub size_request { 2616sub size_request {
2663 ? "<b>$item->{count} ×</b> $item->{text}" 2721 ? "<b>$item->{count} ×</b> $item->{text}"
2664 : $item->{text}; 2722 : $item->{text};
2665 2723
2666 for ($short) { 2724 for ($short) {
2667 s/^\s+//; 2725 s/^\s+//;
2668 s/\012.*/…/s; 2726 s/\s+/ /g;
2669 my $len = int 40 / $item->{fontsize}; 2727 my $len = int 40 / $item->{fontsize};
2670 substr $_, $len, length, "…" if $len < length; 2728 substr $_, $len, length, "…" if $len < length;
2671 } 2729 }
2672 2730
2673 new CFClient::UI::Label 2731 new CFClient::UI::Label
2674 markup => $short, 2732 markup => $short,
2675 tooltip => $item->{tooltip}, 2733 tooltip => $item->{tooltip},
2676 tooltip_font => $::FONT_PROP, 2734 tooltip_font => $::FONT_PROP,
2677 tooltip_width => 0.67, 2735 tooltip_width => 0.67,
2678 fontsize => $item->{fontsize}, 2736 fontsize => $item->{fontsize},
2679 color => $item->{color}, 2737 fg => $item->{fg},
2680 can_events => 1, 2738 can_events => 1,
2681 can_hover => 1 2739 can_hover => 1
2682 }; 2740 };
2683 } 2741 }
2684 2742
2711 id => ++$self->{id}, 2769 id => ++$self->{id},
2712 text => $text, 2770 text => $text,
2713 timeout => $timeout, 2771 timeout => $timeout,
2714 tooltip => $text, 2772 tooltip => $text,
2715 fontsize => 0.8, 2773 fontsize => 0.8,
2716 color => [0.8, 0.8, 0.8, 0.8], 2774 fg => [0.8, 0.8, 0.8, 0.8],
2717 pri => 0, 2775 pri => 0,
2718 count => 1, 2776 count => 1,
2719 %arg, 2777 %arg,
2720 }; 2778 };
2721 } 2779 }
2760} 2818}
2761 2819
2762sub size_allocate { 2820sub size_allocate {
2763 my ($self, $w, $h) = @_; 2821 my ($self, $w, $h) = @_;
2764 2822
2765 my $old_w = $self->{old_w}; 2823 my $old_w = $self->{old_w}; $self->{old_w} = $w;
2766 my $old_h = $self->{old_h}; 2824 my $old_h = $self->{old_h}; $self->{old_h} = $h;
2767 2825
2768 if ($old_w && $old_h) { 2826 CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h
2769 for my $child ($self->children) { 2827 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 2828
2781 for my $child ($self->children) { 2829 for my $child ($self->children) {
2782 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 2830 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2783 2831
2832 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1
2833 if exists $child->{req_x};
2834
2835 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1
2836 if exists $child->{req_y};
2837
2784 $X = List::Util::max 0, List::Util::min $w - $W, $X; 2838 $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; 2839 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5;
2840
2786 $child->configure ($X, $Y, $W, $H); 2841 $child->configure ($X, $Y, $W, $H);
2787 } 2842 }
2788
2789 $self->{old_w} = $w;
2790 $self->{old_h} = $h;
2791} 2843}
2792 2844
2793sub coord2local { 2845sub coord2local {
2794 my ($self, $x, $y) = @_; 2846 my ($self, $x, $y) = @_;
2795 2847
2808 $self->check_size; 2860 $self->check_size;
2809 $::WANT_REFRESH++; 2861 $::WANT_REFRESH++;
2810} 2862}
2811 2863
2812sub add { 2864sub add {
2813 my ($self, $child) = @_; 2865 my ($self, @children) = @_;
2814 2866
2867 for my $child (@children) {
2868 $child->{toplevel} = 1;
2869
2815 # integerise window positions 2870 # integerise window positions
2816 $child->{x} = int $child->{x}; 2871 $child->{x} = int $child->{x};
2817 $child->{y} = int $child->{y}; 2872 $child->{y} = int $child->{y};
2873 }
2818 2874
2819 $self->SUPER::add ($child); 2875 $self->SUPER::add (@children);
2820} 2876}
2821 2877
2822sub on_refresh { 2878sub on_refresh {
2823 my ($self, $id, $cb) = @_; 2879 my ($self, $id, $cb) = @_;
2824 2880

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines