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.202 by root, Sun May 14 20:51:19 2006 UTC vs.
Revision 1.210 by root, Wed May 17 10:14:52 2006 UTC

31 $TOOLTIP->set_tooltip_from ($widget); 31 $TOOLTIP->set_tooltip_from ($widget);
32 $TOOLTIP->show; 32 $TOOLTIP->show;
33 33
34 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 34 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
35 35
36 if ($x + $TOOLTIP->{w} > $::WIDTH) {
37 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); 36 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0)
38 } 37 if $x + $TOOLTIP->{w} > $::WIDTH;
39 38
40 $TOOLTIP->move ($x, $y); 39 $TOOLTIP->move ($x, $y);
41 $TOOLTIP->check_size; 40 $TOOLTIP->check_size;
42 $TOOLTIP->update; 41 $TOOLTIP->update;
43 } 42 }
199sub show { 198sub show {
200 my ($self) = @_; 199 my ($self) = @_;
201 200
202 return if $self->{parent}; 201 return if $self->{parent};
203 202
204 $self->{toplevel} = 1;
205 $CFClient::UI::ROOT->add ($self); 203 $CFClient::UI::ROOT->add ($self);
206} 204}
207 205
208sub hide { 206sub hide {
209 my ($self) = @_; 207 my ($self) = @_;
282sub set_max_size { 280sub set_max_size {
283 my ($self, $w, $h) = @_; 281 my ($self, $w, $h) = @_;
284 282
285 delete $self->{max_w}; $self->{max_w} = $w if $w; 283 delete $self->{max_w}; $self->{max_w} = $w if $w;
286 delete $self->{max_h}; $self->{max_h} = $h if $h; 284 delete $self->{max_h}; $self->{max_h} = $h if $h;
285}
286
287sub set_tooltip {
288 my ($self, $tooltip) = @_;
289
290 $self->{tooltip} = $tooltip;
291
292 if ($CFClient::UI::TOOLTIP->{owner} == $self) {
293 delete $CFClient::UI::TOOLTIP->{owner};
294 CFClient::UI::check_tooltip;
295 }
287} 296}
288 297
289# translate global coordinates to local coordinate system 298# translate global coordinates to local coordinate system
290sub coord2local { 299sub coord2local {
291 my ($self, $x, $y) = @_; 300 my ($self, $x, $y) = @_;
377 glVertex $self->{w}, 0; 386 glVertex $self->{w}, 0;
378 glVertex $self->{w}, $self->{h}; 387 glVertex $self->{w}, $self->{h};
379 glVertex 0 , $self->{h}; 388 glVertex 0 , $self->{h};
380 glEnd; 389 glEnd;
381 glPopMatrix; 390 glPopMatrix;
382 CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 391 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
383 } 392 }
384} 393}
385 394
386sub _draw { 395sub _draw {
387 my ($self) = @_; 396 my ($self) = @_;
457 my $class = shift; 466 my $class = shift;
458 467
459 # range [value, low, high, page] 468 # range [value, low, high, page]
460 469
461 $class->SUPER::new ( 470 $class->SUPER::new (
462 bg => [0, 0, 0, 0.2], 471 #bg => [0, 0, 0, 0.2],
463 active_bg => [1, 1, 1, 0.5], 472 #active_bg => [1, 1, 1, 0.5],
464 @_ 473 @_
465 ) 474 )
466} 475}
467 476
468sub _draw { 477sub _draw {
469 my ($self) = @_; 478 my ($self) = @_;
470 479
480 my $color = $FOCUS == $self && $self->{active_bg}
481 ? $self->{active_bg}
482 : $self->{bg};
483
484 if ($color && (@$color < 4 || $color->[3])) {
471 my ($w, $h) = @$self{qw(w h)}; 485 my ($w, $h) = @$self{qw(w h)};
472 486
473 glEnable GL_BLEND; 487 glEnable GL_BLEND;
474 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 488 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
475 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; 489 glColor @$color;
476 490
477 glBegin GL_QUADS; 491 glBegin GL_QUADS;
478 glVertex 0 , 0; 492 glVertex 0 , 0;
479 glVertex 0 , $h; 493 glVertex 0 , $h;
480 glVertex $w, $h; 494 glVertex $w, $h;
481 glVertex $w, 0; 495 glVertex $w, 0;
482 glEnd; 496 glEnd;
483 497
484 glDisable GL_BLEND; 498 glDisable GL_BLEND;
499 }
485} 500}
486 501
487############################################################################# 502#############################################################################
488 503
489package CFClient::UI::Empty; 504package CFClient::UI::Empty;
897 my ($self, $w, $h) = @_; 912 my ($self, $w, $h) = @_;
898 913
899 $h -= List::Util::max 0, $self->border * 2; 914 $h -= List::Util::max 0, $self->border * 2;
900 $w -= List::Util::max 0, $self->border * 2; 915 $w -= List::Util::max 0, $self->border * 2;
901 916
902 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) 917 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
903 if $self->{title}; 918 if $self->{title};
904 919
905 $self->child->configure ($self->border, $self->border, $w, $h); 920 $self->child->configure ($self->border, $self->border, $w, $h);
906} 921}
907 922
1268 1283
1269############################################################################# 1284#############################################################################
1270 1285
1271package CFClient::UI::Label; 1286package CFClient::UI::Label;
1272 1287
1273our @ISA = CFClient::UI::Base::; 1288our @ISA = CFClient::UI::DrawBG::;
1274 1289
1275use CFClient::OpenGL; 1290use CFClient::OpenGL;
1276 1291
1277sub new { 1292sub new {
1278 my ($class, %arg) = @_; 1293 my ($class, %arg) = @_;
1279 1294
1280 my $self = $class->SUPER::new ( 1295 my $self = $class->SUPER::new (
1281 fg => [1, 1, 1], 1296 fg => [1, 1, 1],
1297 #bg => none
1298 #active_bg => none
1282 #font => default_font 1299 #font => default_font
1283 #text => initial text 1300 #text => initial text
1284 #markup => initial narkup 1301 #markup => initial narkup
1285 layout => (new CFClient::Layout), 1302 layout => (new CFClient::Layout),
1286 fontsize => 1, 1303 fontsize => 1,
1304 } 1321 }
1305 1322
1306 $self 1323 $self
1307} 1324}
1308 1325
1309sub escape { 1326sub escape($) {
1310 local $_ = $_[1]; 1327 local $_ = $_[0];
1311 1328
1312 s/&/&amp;/g; 1329 s/&/&amp;/g;
1313 s/>/&gt;/g; 1330 s/>/&gt;/g;
1314 s/</&lt;/g; 1331 s/</&lt;/g;
1315 1332
1316 $_[1] 1333 $_
1317} 1334}
1318 1335
1319sub update { 1336sub update {
1320 my ($self) = @_; 1337 my ($self) = @_;
1321 1338
1392 $self->check_size; 1409 $self->check_size;
1393} 1410}
1394 1411
1395sub _draw { 1412sub _draw {
1396 my ($self) = @_; 1413 my ($self) = @_;
1414
1415 $self->SUPER::_draw; # draw background, if applicable
1397 1416
1398 my $tex = $self->{texture} ||= do { 1417 my $tex = $self->{texture} ||= do {
1399 $self->{layout}->set_foreground (@{$self->{fg}}); 1418 $self->{layout}->set_foreground (@{$self->{fg}});
1400 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1419 $self->{layout}->set_font ($self->{font}) if $self->{font};
1401 $self->{layout}->set_width ($self->{w}); 1420 $self->{layout}->set_width ($self->{w});
1402 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1421 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1403 1422
1404 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1423 my $tex = new_from_layout CFClient::Texture $self->{layout};
1405 1424
1406 $self->{ox} = int $self->{align} < 0 ? $self->{padding} 1425 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1407 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1426 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1408 : ($self->{w} - $tex->{w}) * 0.5; 1427 : ($self->{w} - $tex->{w}) * 0.5);
1409 1428
1410 $self->{oy} = int $self->{valign} < 0 ? $self->{padding} 1429 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding}
1411 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1430 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1412 : ($self->{h} - $tex->{h}) * 0.5; 1431 : ($self->{h} - $tex->{h}) * 0.5);
1413 1432
1414 $tex 1433 $tex
1415 }; 1434 };
1416 1435
1417 glEnable GL_TEXTURE_2D; 1436 glEnable GL_TEXTURE_2D;
1472sub set_text { 1491sub set_text {
1473 my ($self, $text) = @_; 1492 my ($self, $text) = @_;
1474 1493
1475 $self->{cursor} = length $text; 1494 $self->{cursor} = length $text;
1476 $self->_set_text ($text); 1495 $self->_set_text ($text);
1496 $self->update;
1477 $self->check_size; 1497 $self->check_size;
1478 $self->update;
1479} 1498}
1480 1499
1481sub get_text { 1500sub get_text {
1482 $_[0]{text} 1501 $_[0]{text}
1483} 1502}
1523 substr $text, $self->{cursor}++, 0, chr $uni; 1542 substr $text, $self->{cursor}++, 0, chr $uni;
1524 } 1543 }
1525 1544
1526 $self->_set_text ($text); 1545 $self->_set_text ($text);
1527 $self->update; 1546 $self->update;
1547 $self->check_size;
1528} 1548}
1529 1549
1530sub focus_in { 1550sub focus_in {
1531 my ($self) = @_; 1551 my ($self) = @_;
1532 1552
1661 my $class = shift; 1681 my $class = shift;
1662 1682
1663 $class->SUPER::new ( 1683 $class->SUPER::new (
1664 padding => 4, 1684 padding => 4,
1665 fg => [1, 1, 1], 1685 fg => [1, 1, 1],
1666 bg => [1, 1, 1, 0.2],
1667 active_fg => [0, 0, 1], 1686 active_fg => [0, 0, 1],
1668 can_hover => 1, 1687 can_hover => 1,
1669 align => 0, 1688 align => 0,
1670 valign => 0, 1689 valign => 0,
1671 can_events => 1, 1690 can_events => 1,
1719 1738
1720 $class->SUPER::new ( 1739 $class->SUPER::new (
1721 padding => 2, 1740 padding => 2,
1722 fg => [1, 1, 1], 1741 fg => [1, 1, 1],
1723 active_fg => [1, 1, 0], 1742 active_fg => [1, 1, 0],
1743 bg => [0, 0, 0, 0.2],
1744 active_bg => [1, 1, 1, 0.5],
1724 state => 0, 1745 state => 0,
1725 can_hover => 1, 1746 can_hover => 1,
1726 @_ 1747 @_
1727 ) 1748 )
1728} 1749}
2012 qw(s1_slider.png s1_slider_bg.png); 2033 qw(s1_slider.png s1_slider_bg.png);
2013 2034
2014sub new { 2035sub new {
2015 my $class = shift; 2036 my $class = shift;
2016 2037
2017 # range [value, low, high, page] 2038 # range [value, low, high, page, unit]
2018 2039
2019 # TODO: 0-width page 2040 # TODO: 0-width page
2020 # TODO: req_w/h are wrong with vertical 2041 # TODO: req_w/h are wrong with vertical
2021 # TODO: calculations are off 2042 # TODO: calculations are off
2022 my $self = $class->SUPER::new ( 2043 my $self = $class->SUPER::new (
2023 fg => [1, 1, 1], 2044 fg => [1, 1, 1],
2024 active_fg => [0, 0, 0], 2045 active_fg => [0, 0, 0],
2046 bg => [0, 0, 0, 0.2],
2047 active_bg => [1, 1, 1, 0.5],
2025 range => [0, 0, 100, 10], 2048 range => [0, 0, 100, 10],
2026 req_w => $::WIDTH / 80, 2049 req_w => $::WIDTH / 80,
2027 req_h => $::WIDTH / 80, 2050 req_h => $::WIDTH / 80,
2028 vertical => 0, 2051 vertical => 0,
2029 can_hover => 1, 2052 can_hover => 1,
2030 inner_pad => 5, 2053 inner_pad => .05,
2031 @_ 2054 @_
2032 ); 2055 );
2033 2056
2057 $self->set_value ($self->{range}[0]);
2058 $self->update;
2059
2034 $self 2060 $self
2061}
2062
2063sub set_value {
2064 my ($self, $value) = @_;
2065
2066 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
2067
2068 $hi = $lo + 1 if $hi <= $lo;
2069
2070 $value = $lo if $value < $lo;
2071 $value = $hi if $value > $hi;
2072
2073 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
2074 if $unit;
2075
2076 $page = $hi - $lo if $page > $hi - $lo;
2077
2078 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
2079
2080 if ($value != $old_value) {
2081 $self->emit (changed => $value);
2082 $self->update;
2083 }
2035} 2084}
2036 2085
2037sub size_request { 2086sub size_request {
2038 my ($self) = @_; 2087 my ($self) = @_;
2039 2088
2052 2101
2053sub mouse_motion { 2102sub mouse_motion {
2054 my ($self, $ev, $x, $y) = @_; 2103 my ($self, $ev, $x, $y) = @_;
2055 2104
2056 if ($GRAB == $self) { 2105 if ($GRAB == $self) {
2106 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
2107
2108 my (undef, $lo, $hi, $page) = @{$self->{range}};
2109
2110 $x = $x / ($w * (1 - 2 * $self->{inner_pad})) - $self->{inner_pad};
2111
2112 $self->set_value ($x * ($hi - $lo) + $lo);
2113 }
2114}
2115
2116sub update {
2117 my ($self) = @_;
2118
2119 $CFClient::UI::ROOT->on_post_alloc ($self => sub {
2120 $self->set_value ($self->{range}[0]);
2121
2057 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2122 my ($value, $lo, $hi, $page) = @{$self->{range}};
2058 2123
2059 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 2124 my $inner_w = 1 - 2 * $self->{inner_pad};
2060 2125
2061 my $inner_pad_px = $self->_calc_inner_pad_px ($w); 2126 $self->{scale} = ($inner_w / ($hi - $lo)) || 1;
2062 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
2063 2127
2064 $x -= $inner_pad_px; # substract the padding 2128 $page = $self->{scale} * $page || 10 / ($self->{w} || 1);
2065 $x = $x * ($hi - $lo) / $inner_w + $lo; 2129 $value = $self->{scale} * ($value - $lo);
2066 $x = $lo if $x < $lo;
2067 $x = $hi - $page if $x > $hi - $page;
2068 $self->{range}[0] = $x;
2069 2130
2070 $self->emit (changed => $x); 2131 $value = $self->{inner_pad} + ($value - $page * 0.5);
2071 $self->update; 2132
2133 $value = 0 if $value < 0;
2134 $page = 1 - $value if $value + $page > 1;
2135
2136 $self->{knob_x} = $value;
2137 $self->{knob_w} = $page;
2072 } 2138 });
2073}
2074 2139
2075# the inner_* stuff is for generating a padding for the slider handle, 2140 $self->SUPER::update;
2076# so that the handle doesn't leave the texture. This calculation isn't 100%
2077# correct propably, but it does the job for now
2078sub _calc_inner_pad_px {
2079 my ($self, $w) = @_;
2080 ($w / 100) * $self->{inner_pad} # % to pixels
2081} 2141}
2082 2142
2083sub _draw { 2143sub _draw {
2084 my ($self) = @_; 2144 my ($self) = @_;
2085 2145
2086 $self->SUPER::_draw (); 2146 $self->SUPER::_draw ();
2087 2147
2088 my ($w, $h) = @$self{qw(w h)}; 2148 glScale $self->{w}, $self->{h};
2089 2149
2090 if ($self->{vertical}) { 2150 if ($self->{vertical}) {
2091 # draw a vertical slider like a rotated horizontal slider 2151 # draw a vertical slider like a rotated horizontal slider
2092 2152
2093 glRotate 90, 0, 0, 1; 2153 glRotate 90, 0, 0, 1;
2094 glTranslate 0, -$self->{w}, 0; 2154 glTranslate 0, 1, 0;
2095
2096 ($w, $h) = ($h, $w);
2097 } 2155 }
2098 2156
2099 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2157 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2100 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2158 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2101 2159
2102 my ($value, $lo, $hi, $page) = @{$self->{range}};
2103
2104 $hi = $value + 1 if $lo == $hi;
2105
2106 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
2107 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
2108
2109 $page = int $page * $inner_w / ($hi - $lo);
2110 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
2111
2112 $w -= $page;
2113 $page &= ~1;
2114 glTranslate $page * 0.5, 0, 0;
2115 $page ||= 2;
2116
2117 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
2118 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
2119
2120 glEnable GL_TEXTURE_2D; 2160 glEnable GL_TEXTURE_2D;
2121 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2161 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2122 2162
2123 # draw background 2163 # draw background
2124 $tex[1]->draw_quad_alpha (0, 0, $w, $h); 2164 $tex[1]->draw_quad_alpha (0, 0, 1, 1);
2125 2165
2126 # draw handle 2166 # draw handle
2127 $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); 2167 $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1);
2128 2168
2129 glDisable GL_TEXTURE_2D; 2169 glDisable GL_TEXTURE_2D;
2130} 2170}
2131 2171
2132############################################################################# 2172#############################################################################
2489 2529
2490 my $desc = $item->{nrof} < 2 2530 my $desc = $item->{nrof} < 2
2491 ? $item->{name} 2531 ? $item->{name}
2492 : "$item->{nrof} $item->{name_pl}"; 2532 : "$item->{nrof} $item->{name_pl}";
2493 2533
2534 $item->{flags} & Crossfire::Protocol::F_OPEN
2535 and $desc .= " (open)";
2536 $item->{flags} & Crossfire::Protocol::F_APPLIED
2537 and $desc .= " (applied)";
2538 $item->{flags} & Crossfire::Protocol::F_UNPAID
2539 and $desc .= " (unpaid)";
2540 $item->{flags} & Crossfire::Protocol::F_MAGIC
2541 and $desc .= " (magic)";
2542 $item->{flags} & Crossfire::Protocol::F_CURSED
2543 and $desc .= " (cursed)";
2544 $item->{flags} & Crossfire::Protocol::F_DAMNED
2545 and $desc .= " (damned)";
2546 $item->{flags} & Crossfire::Protocol::F_LOCKED
2547 and $desc .= " *";
2494 2548
2495 my $self = $class->SUPER::new ( 2549 my $self = $class->SUPER::new (
2496 can_hover => 1, 2550 can_hover => 1,
2497 can_events => 1, 2551 can_events => 1,
2498 tooltip => (CFClient::UI::Label->escape ($desc) 2552 tooltip => ((CFClient::UI::Label::escape $desc)
2499 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2553 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2500 connect_button_down => sub { 2554 connect_button_down => sub {
2501 my ($self, $ev, $x, $y) = @_; 2555 my ($self, $ev, $x, $y) = @_;
2502 2556
2503 # todo: maybe put examine on 1? but should just be a tooltip :( 2557 # todo: maybe put examine on 1? but should just be a tooltip :(
2504 if ($ev->{button} == 1) { 2558 if ($ev->{button} == 1) {
2505 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); 2559 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0");
2506 } elsif ($ev->{button} == 2) { 2560 } elsif ($ev->{button} == 2) {
2507 $::CONN->send ("apply $item->{tag}"); 2561 $::CONN->send ("apply $item->{tag}");
2508 } elsif ($ev->{button} == 3) { 2562 } elsif ($ev->{button} == 3) {
2509 CFClient::UI::Menu->new ( 2563 my @menu_items = (
2510 items => [
2511 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2564 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2565 ["mark", sub { $::CONN->send ("mark $item->{tag}") }],
2566 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2567 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2512 [ 2568 [
2513 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", 2569 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2514 sub { $::CONN->send ("lock $item->{tag}") }, 2570 sub { $::CONN->send ("lock ". () ."$item->{tag}") },
2515 ],
2516 ["mark", sub { $::CONN->send ("mark $item->{tag}") }],
2517 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2518 ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }],
2519 ], 2571 ],
2520 )->popup ($ev); 2572 );
2573
2574 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2521 } 2575 }
2522 2576
2523 1 2577 1
2524 }, 2578 },
2525 %args 2579 %args
2664 2718
2665package CFClient::UI::Statusbox; 2719package CFClient::UI::Statusbox;
2666 2720
2667our @ISA = CFClient::UI::VBox::; 2721our @ISA = CFClient::UI::VBox::;
2668 2722
2723sub new {
2724 my $class = shift;
2725
2726 $class->SUPER::new (
2727 fontsize => 0.8,
2728 @_,
2729 )
2730}
2731
2669sub reorder { 2732sub reorder {
2670 my ($self) = @_; 2733 my ($self) = @_;
2671 my $NOW = time; 2734 my $NOW = time;
2672 2735
2673 while (my ($k, $v) = each %{ $self->{item} }) { 2736 while (my ($k, $v) = each %{ $self->{item} }) {
2689 # TODO: doesn't handle markup well (read as: at all) 2752 # TODO: doesn't handle markup well (read as: at all)
2690 my $short = $item->{count} > 1 2753 my $short = $item->{count} > 1
2691 ? "<b>$item->{count} ×</b> $item->{text}" 2754 ? "<b>$item->{count} ×</b> $item->{text}"
2692 : $item->{text}; 2755 : $item->{text};
2693 2756
2757 my $fontsize = $item->{fontsize} || $self->{fontsize};
2758
2694 for ($short) { 2759 for ($short) {
2695 s/^\s+//; 2760 s/^\s+//;
2696 s/\012.*/…/s; 2761 s/\s+/ /g;
2697 my $len = int 40 / $item->{fontsize}; 2762 my $len = int 40 / $fontsize;
2698 substr $_, $len, length, "…" if $len < length; 2763 substr $_, $len, length, "…" if $len < length;
2699 } 2764 }
2700 2765
2701 new CFClient::UI::Label 2766 new CFClient::UI::Label
2702 markup => $short, 2767 markup => $short,
2703 tooltip => $item->{tooltip}, 2768 tooltip => $item->{tooltip},
2704 tooltip_font => $::FONT_PROP, 2769 tooltip_font => $::FONT_PROP,
2705 tooltip_width => 0.67, 2770 tooltip_width => 0.67,
2706 fontsize => $item->{fontsize}, 2771 fontsize => $fontsize,
2707 color => $item->{color}, 2772 fg => $item->{fg},
2708 can_events => 1, 2773 can_events => 1,
2709 can_hover => 1 2774 can_hover => 1
2710 }; 2775 };
2711 } 2776 }
2712 2777
2738 $self->{item}{$group} = { 2803 $self->{item}{$group} = {
2739 id => ++$self->{id}, 2804 id => ++$self->{id},
2740 text => $text, 2805 text => $text,
2741 timeout => $timeout, 2806 timeout => $timeout,
2742 tooltip => $text, 2807 tooltip => $text,
2743 fontsize => 0.8,
2744 color => [0.8, 0.8, 0.8, 0.8], 2808 fg => [0.8, 0.8, 0.8, 0.8],
2745 pri => 0, 2809 pri => 0,
2746 count => 1, 2810 count => 1,
2747 %arg, 2811 %arg,
2748 }; 2812 };
2749 } 2813 }
2797 if $old_w && $old_h && ($old_w != $w || $old_h != $h); 2861 if $old_w && $old_h && ($old_w != $w || $old_h != $h);
2798 2862
2799 for my $child ($self->children) { 2863 for my $child ($self->children) {
2800 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 2864 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2801 2865
2866 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1
2867 if exists $child->{req_x};
2868
2869 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1
2870 if exists $child->{req_y};
2871
2802 $X = List::Util::max 0, List::Util::min $w - $W, $X; 2872 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5;
2803 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 2873 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5;
2874
2804 $child->configure ($X, $Y, $W, $H); 2875 $child->configure ($X, $Y, $W, $H);
2805 } 2876 }
2806} 2877}
2807 2878
2808sub coord2local { 2879sub coord2local {
2823 $self->check_size; 2894 $self->check_size;
2824 $::WANT_REFRESH++; 2895 $::WANT_REFRESH++;
2825} 2896}
2826 2897
2827sub add { 2898sub add {
2828 my ($self, $child) = @_; 2899 my ($self, @children) = @_;
2829 2900
2901 for my $child (@children) {
2902 $child->{toplevel} = 1;
2903
2830 # integerise window positions 2904 # integerise window positions
2831 $child->{x} = int $child->{x}; 2905 $child->{x} = int $child->{x};
2832 $child->{y} = int $child->{y}; 2906 $child->{y} = int $child->{y};
2907 }
2833 2908
2834 $self->SUPER::add ($child); 2909 $self->SUPER::add (@children);
2835} 2910}
2836 2911
2837sub on_refresh { 2912sub on_refresh {
2838 my ($self, $id, $cb) = @_; 2913 my ($self, $id, $cb) = @_;
2839 2914

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines