… | |
… | |
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 | } |
… | |
… | |
283 | |
282 | |
284 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
283 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
285 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
284 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
286 | } |
285 | } |
287 | |
286 | |
|
|
287 | sub 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 | } |
|
|
296 | } |
|
|
297 | |
288 | # translate global coordinates to local coordinate system |
298 | # translate global coordinates to local coordinate system |
289 | sub coord2local { |
299 | sub coord2local { |
290 | my ($self, $x, $y) = @_; |
300 | my ($self, $x, $y) = @_; |
291 | |
301 | |
292 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
302 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
… | |
… | |
376 | glVertex $self->{w}, 0; |
386 | glVertex $self->{w}, 0; |
377 | glVertex $self->{w}, $self->{h}; |
387 | glVertex $self->{w}, $self->{h}; |
378 | glVertex 0 , $self->{h}; |
388 | glVertex 0 , $self->{h}; |
379 | glEnd; |
389 | glEnd; |
380 | glPopMatrix; |
390 | glPopMatrix; |
381 | 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; |
382 | } |
392 | } |
383 | } |
393 | } |
384 | |
394 | |
385 | sub _draw { |
395 | sub _draw { |
386 | my ($self) = @_; |
396 | my ($self) = @_; |
… | |
… | |
456 | my $class = shift; |
466 | my $class = shift; |
457 | |
467 | |
458 | # range [value, low, high, page] |
468 | # range [value, low, high, page] |
459 | |
469 | |
460 | $class->SUPER::new ( |
470 | $class->SUPER::new ( |
461 | bg => [0, 0, 0, 0.2], |
471 | #bg => [0, 0, 0, 0.2], |
462 | active_bg => [1, 1, 1, 0.5], |
472 | #active_bg => [1, 1, 1, 0.5], |
463 | @_ |
473 | @_ |
464 | ) |
474 | ) |
465 | } |
475 | } |
466 | |
476 | |
467 | sub _draw { |
477 | sub _draw { |
468 | my ($self) = @_; |
478 | my ($self) = @_; |
469 | |
479 | |
|
|
480 | my $color = $FOCUS == $self && $self->{active_bg} |
|
|
481 | ? $self->{active_bg} |
|
|
482 | : $self->{bg}; |
|
|
483 | |
|
|
484 | if ($color && (@$color < 4 || $color->[3])) { |
470 | my ($w, $h) = @$self{qw(w h)}; |
485 | my ($w, $h) = @$self{qw(w h)}; |
471 | |
486 | |
472 | glEnable GL_BLEND; |
487 | glEnable GL_BLEND; |
473 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
488 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
474 | glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; |
489 | glColor @$color; |
475 | |
490 | |
476 | glBegin GL_QUADS; |
491 | glBegin GL_QUADS; |
477 | glVertex 0 , 0; |
492 | glVertex 0 , 0; |
478 | glVertex 0 , $h; |
493 | glVertex 0 , $h; |
479 | glVertex $w, $h; |
494 | glVertex $w, $h; |
480 | glVertex $w, 0; |
495 | glVertex $w, 0; |
481 | glEnd; |
496 | glEnd; |
482 | |
497 | |
483 | glDisable GL_BLEND; |
498 | glDisable GL_BLEND; |
|
|
499 | } |
484 | } |
500 | } |
485 | |
501 | |
486 | ############################################################################# |
502 | ############################################################################# |
487 | |
503 | |
488 | package CFClient::UI::Empty; |
504 | package CFClient::UI::Empty; |
… | |
… | |
896 | my ($self, $w, $h) = @_; |
912 | my ($self, $w, $h) = @_; |
897 | |
913 | |
898 | $h -= List::Util::max 0, $self->border * 2; |
914 | $h -= List::Util::max 0, $self->border * 2; |
899 | $w -= List::Util::max 0, $self->border * 2; |
915 | $w -= List::Util::max 0, $self->border * 2; |
900 | |
916 | |
901 | $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) |
902 | if $self->{title}; |
918 | if $self->{title}; |
903 | |
919 | |
904 | $self->child->configure ($self->border, $self->border, $w, $h); |
920 | $self->child->configure ($self->border, $self->border, $w, $h); |
905 | } |
921 | } |
906 | |
922 | |
… | |
… | |
1267 | |
1283 | |
1268 | ############################################################################# |
1284 | ############################################################################# |
1269 | |
1285 | |
1270 | package CFClient::UI::Label; |
1286 | package CFClient::UI::Label; |
1271 | |
1287 | |
1272 | our @ISA = CFClient::UI::Base::; |
1288 | our @ISA = CFClient::UI::DrawBG::; |
1273 | |
1289 | |
1274 | use CFClient::OpenGL; |
1290 | use CFClient::OpenGL; |
1275 | |
1291 | |
1276 | sub new { |
1292 | sub new { |
1277 | my ($class, %arg) = @_; |
1293 | my ($class, %arg) = @_; |
1278 | |
1294 | |
1279 | my $self = $class->SUPER::new ( |
1295 | my $self = $class->SUPER::new ( |
1280 | fg => [1, 1, 1], |
1296 | fg => [1, 1, 1], |
|
|
1297 | #bg => none |
|
|
1298 | #active_bg => none |
1281 | #font => default_font |
1299 | #font => default_font |
1282 | #text => initial text |
1300 | #text => initial text |
1283 | #markup => initial narkup |
1301 | #markup => initial narkup |
1284 | layout => (new CFClient::Layout), |
1302 | layout => (new CFClient::Layout), |
1285 | fontsize => 1, |
1303 | fontsize => 1, |
… | |
… | |
1303 | } |
1321 | } |
1304 | |
1322 | |
1305 | $self |
1323 | $self |
1306 | } |
1324 | } |
1307 | |
1325 | |
1308 | sub escape { |
1326 | sub escape($) { |
1309 | local $_ = $_[1]; |
1327 | local $_ = $_[0]; |
1310 | |
1328 | |
1311 | s/&/&/g; |
1329 | s/&/&/g; |
1312 | s/>/>/g; |
1330 | s/>/>/g; |
1313 | s/</</g; |
1331 | s/</</g; |
1314 | |
1332 | |
1315 | $_[1] |
1333 | $_ |
1316 | } |
1334 | } |
1317 | |
1335 | |
1318 | sub update { |
1336 | sub update { |
1319 | my ($self) = @_; |
1337 | my ($self) = @_; |
1320 | |
1338 | |
… | |
… | |
1391 | $self->check_size; |
1409 | $self->check_size; |
1392 | } |
1410 | } |
1393 | |
1411 | |
1394 | sub _draw { |
1412 | sub _draw { |
1395 | my ($self) = @_; |
1413 | my ($self) = @_; |
|
|
1414 | |
|
|
1415 | $self->SUPER::_draw; # draw background, if applicable |
1396 | |
1416 | |
1397 | my $tex = $self->{texture} ||= do { |
1417 | my $tex = $self->{texture} ||= do { |
1398 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1418 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1399 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1419 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1400 | $self->{layout}->set_width ($self->{w}); |
1420 | $self->{layout}->set_width ($self->{w}); |
1401 | $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); |
1402 | |
1422 | |
1403 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1423 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1404 | |
1424 | |
1405 | $self->{ox} = int $self->{align} < 0 ? $self->{padding} |
1425 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding} |
1406 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1426 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1407 | : ($self->{w} - $tex->{w}) * 0.5; |
1427 | : ($self->{w} - $tex->{w}) * 0.5); |
1408 | |
1428 | |
1409 | $self->{oy} = int $self->{valign} < 0 ? $self->{padding} |
1429 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding} |
1410 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1430 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1411 | : ($self->{h} - $tex->{h}) * 0.5; |
1431 | : ($self->{h} - $tex->{h}) * 0.5); |
1412 | |
1432 | |
1413 | $tex |
1433 | $tex |
1414 | }; |
1434 | }; |
1415 | |
1435 | |
1416 | glEnable GL_TEXTURE_2D; |
1436 | glEnable GL_TEXTURE_2D; |
… | |
… | |
1471 | sub set_text { |
1491 | sub set_text { |
1472 | my ($self, $text) = @_; |
1492 | my ($self, $text) = @_; |
1473 | |
1493 | |
1474 | $self->{cursor} = length $text; |
1494 | $self->{cursor} = length $text; |
1475 | $self->_set_text ($text); |
1495 | $self->_set_text ($text); |
|
|
1496 | $self->update; |
1476 | $self->check_size; |
1497 | $self->check_size; |
1477 | $self->update; |
|
|
1478 | } |
1498 | } |
1479 | |
1499 | |
1480 | sub get_text { |
1500 | sub get_text { |
1481 | $_[0]{text} |
1501 | $_[0]{text} |
1482 | } |
1502 | } |
… | |
… | |
1522 | substr $text, $self->{cursor}++, 0, chr $uni; |
1542 | substr $text, $self->{cursor}++, 0, chr $uni; |
1523 | } |
1543 | } |
1524 | |
1544 | |
1525 | $self->_set_text ($text); |
1545 | $self->_set_text ($text); |
1526 | $self->update; |
1546 | $self->update; |
|
|
1547 | $self->check_size; |
1527 | } |
1548 | } |
1528 | |
1549 | |
1529 | sub focus_in { |
1550 | sub focus_in { |
1530 | my ($self) = @_; |
1551 | my ($self) = @_; |
1531 | |
1552 | |
… | |
… | |
1660 | my $class = shift; |
1681 | my $class = shift; |
1661 | |
1682 | |
1662 | $class->SUPER::new ( |
1683 | $class->SUPER::new ( |
1663 | padding => 4, |
1684 | padding => 4, |
1664 | fg => [1, 1, 1], |
1685 | fg => [1, 1, 1], |
1665 | bg => [1, 1, 1, 0.2], |
|
|
1666 | active_fg => [0, 0, 1], |
1686 | active_fg => [0, 0, 1], |
1667 | can_hover => 1, |
1687 | can_hover => 1, |
1668 | align => 0, |
1688 | align => 0, |
1669 | valign => 0, |
1689 | valign => 0, |
1670 | can_events => 1, |
1690 | can_events => 1, |
… | |
… | |
1718 | |
1738 | |
1719 | $class->SUPER::new ( |
1739 | $class->SUPER::new ( |
1720 | padding => 2, |
1740 | padding => 2, |
1721 | fg => [1, 1, 1], |
1741 | fg => [1, 1, 1], |
1722 | 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], |
1723 | state => 0, |
1745 | state => 0, |
1724 | can_hover => 1, |
1746 | can_hover => 1, |
1725 | @_ |
1747 | @_ |
1726 | ) |
1748 | ) |
1727 | } |
1749 | } |
… | |
… | |
2011 | qw(s1_slider.png s1_slider_bg.png); |
2033 | qw(s1_slider.png s1_slider_bg.png); |
2012 | |
2034 | |
2013 | sub new { |
2035 | sub new { |
2014 | my $class = shift; |
2036 | my $class = shift; |
2015 | |
2037 | |
2016 | # range [value, low, high, page] |
2038 | # range [value, low, high, page, unit] |
2017 | |
2039 | |
2018 | # TODO: 0-width page |
2040 | # TODO: 0-width page |
2019 | # TODO: req_w/h are wrong with vertical |
2041 | # TODO: req_w/h are wrong with vertical |
2020 | # TODO: calculations are off |
2042 | # TODO: calculations are off |
2021 | my $self = $class->SUPER::new ( |
2043 | my $self = $class->SUPER::new ( |
2022 | fg => [1, 1, 1], |
2044 | fg => [1, 1, 1], |
2023 | 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], |
2024 | range => [0, 0, 100, 10], |
2048 | range => [0, 0, 100, 10], |
2025 | req_w => $::WIDTH / 80, |
2049 | req_w => $::WIDTH / 80, |
2026 | req_h => $::WIDTH / 80, |
2050 | req_h => $::WIDTH / 80, |
2027 | vertical => 0, |
2051 | vertical => 0, |
2028 | can_hover => 1, |
2052 | can_hover => 1, |
2029 | inner_pad => 5, |
2053 | inner_pad => .05, |
2030 | @_ |
2054 | @_ |
2031 | ); |
2055 | ); |
2032 | |
2056 | |
|
|
2057 | $self->set_value ($self->{range}[0]); |
|
|
2058 | $self->update; |
|
|
2059 | |
2033 | $self |
2060 | $self |
|
|
2061 | } |
|
|
2062 | |
|
|
2063 | sub 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 | } |
2034 | } |
2084 | } |
2035 | |
2085 | |
2036 | sub size_request { |
2086 | sub size_request { |
2037 | my ($self) = @_; |
2087 | my ($self) = @_; |
2038 | |
2088 | |
… | |
… | |
2051 | |
2101 | |
2052 | sub mouse_motion { |
2102 | sub mouse_motion { |
2053 | my ($self, $ev, $x, $y) = @_; |
2103 | my ($self, $ev, $x, $y) = @_; |
2054 | |
2104 | |
2055 | 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 | |
|
|
2116 | sub update { |
|
|
2117 | my ($self) = @_; |
|
|
2118 | |
|
|
2119 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
|
|
2120 | $self->set_value ($self->{range}[0]); |
|
|
2121 | |
2056 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2122 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2057 | |
2123 | |
2058 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
2124 | my $inner_w = 1 - 2 * $self->{inner_pad}; |
2059 | |
2125 | |
2060 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
2126 | $self->{scale} = ($inner_w / ($hi - $lo)) || 1; |
2061 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
|
|
2062 | |
2127 | |
2063 | $x -= $inner_pad_px; # substract the padding |
2128 | $page = $self->{scale} * $page || 10 / ($self->{w} || 1); |
2064 | $x = $x * ($hi - $lo) / $inner_w + $lo; |
2129 | $value = $self->{scale} * ($value - $lo); |
2065 | $x = $lo if $x < $lo; |
|
|
2066 | $x = $hi - $page if $x > $hi - $page; |
|
|
2067 | $self->{range}[0] = $x; |
|
|
2068 | |
2130 | |
2069 | $self->emit (changed => $x); |
2131 | $value = $self->{inner_pad} + ($value - $page * 0.5); |
2070 | $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; |
2071 | } |
2138 | }); |
2072 | } |
|
|
2073 | |
2139 | |
2074 | # the inner_* stuff is for generating a padding for the slider handle, |
2140 | $self->SUPER::update; |
2075 | # so that the handle doesn't leave the texture. This calculation isn't 100% |
|
|
2076 | # correct propably, but it does the job for now |
|
|
2077 | sub _calc_inner_pad_px { |
|
|
2078 | my ($self, $w) = @_; |
|
|
2079 | ($w / 100) * $self->{inner_pad} # % to pixels |
|
|
2080 | } |
2141 | } |
2081 | |
2142 | |
2082 | sub _draw { |
2143 | sub _draw { |
2083 | my ($self) = @_; |
2144 | my ($self) = @_; |
2084 | |
2145 | |
2085 | $self->SUPER::_draw (); |
2146 | $self->SUPER::_draw (); |
2086 | |
2147 | |
2087 | my ($w, $h) = @$self{qw(w h)}; |
2148 | glScale $self->{w}, $self->{h}; |
2088 | |
2149 | |
2089 | if ($self->{vertical}) { |
2150 | if ($self->{vertical}) { |
2090 | # draw a vertical slider like a rotated horizontal slider |
2151 | # draw a vertical slider like a rotated horizontal slider |
2091 | |
2152 | |
2092 | glRotate 90, 0, 0, 1; |
2153 | glRotate 90, 0, 0, 1; |
2093 | glTranslate 0, -$self->{w}, 0; |
2154 | glTranslate 0, 1, 0; |
2094 | |
|
|
2095 | ($w, $h) = ($h, $w); |
|
|
2096 | } |
2155 | } |
2097 | |
2156 | |
2098 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2157 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2099 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2158 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2100 | |
2159 | |
2101 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
|
|
2102 | |
|
|
2103 | $hi = $value + 1 if $lo == $hi; |
|
|
2104 | |
|
|
2105 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
|
|
2106 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
|
|
2107 | |
|
|
2108 | $page = int $page * $inner_w / ($hi - $lo); |
|
|
2109 | $value = int +($value - $lo) * $inner_w / ($hi - $lo); |
|
|
2110 | |
|
|
2111 | $w -= $page; |
|
|
2112 | $page &= ~1; |
|
|
2113 | glTranslate $page * 0.5, 0, 0; |
|
|
2114 | $page ||= 2; |
|
|
2115 | |
|
|
2116 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
|
|
2117 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
|
|
2118 | |
|
|
2119 | glEnable GL_TEXTURE_2D; |
2160 | glEnable GL_TEXTURE_2D; |
2120 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2161 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2121 | |
2162 | |
2122 | # draw background |
2163 | # draw background |
2123 | $tex[1]->draw_quad_alpha (0, 0, $w, $h); |
2164 | $tex[1]->draw_quad_alpha (0, 0, 1, 1); |
2124 | |
2165 | |
2125 | # draw handle |
2166 | # draw handle |
2126 | $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); |
2127 | |
2168 | |
2128 | glDisable GL_TEXTURE_2D; |
2169 | glDisable GL_TEXTURE_2D; |
2129 | } |
2170 | } |
2130 | |
2171 | |
2131 | ############################################################################# |
2172 | ############################################################################# |
… | |
… | |
2488 | |
2529 | |
2489 | my $desc = $item->{nrof} < 2 |
2530 | my $desc = $item->{nrof} < 2 |
2490 | ? $item->{name} |
2531 | ? $item->{name} |
2491 | : "$item->{nrof} $item->{name_pl}"; |
2532 | : "$item->{nrof} $item->{name_pl}"; |
2492 | |
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 .= " *"; |
2493 | |
2548 | |
2494 | my $self = $class->SUPER::new ( |
2549 | my $self = $class->SUPER::new ( |
2495 | can_hover => 1, |
2550 | can_hover => 1, |
2496 | can_events => 1, |
2551 | can_events => 1, |
2497 | tooltip => (CFClient::UI::Label->escape ($desc) |
2552 | tooltip => ((CFClient::UI::Label::escape $desc) |
2498 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2553 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2499 | connect_button_down => sub { |
2554 | connect_button_down => sub { |
2500 | my ($self, $ev, $x, $y) = @_; |
2555 | my ($self, $ev, $x, $y) = @_; |
2501 | |
2556 | |
2502 | # 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 :( |
2503 | if ($ev->{button} == 1) { |
2558 | if ($ev->{button} == 1) { |
2504 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
2559 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
2505 | } elsif ($ev->{button} == 2) { |
2560 | } elsif ($ev->{button} == 2) { |
2506 | $::CONN->send ("apply $item->{tag}"); |
2561 | $::CONN->send ("apply $item->{tag}"); |
2507 | } elsif ($ev->{button} == 3) { |
2562 | } elsif ($ev->{button} == 3) { |
2508 | CFClient::UI::Menu->new ( |
2563 | my @menu_items = ( |
2509 | items => [ |
|
|
2510 | ["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") }], |
2511 | [ |
2568 | [ |
2512 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
2569 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
2513 | sub { $::CONN->send ("lock $item->{tag}") }, |
2570 | sub { $::CONN->send ("lock ". () ."$item->{tag}") }, |
2514 | ], |
|
|
2515 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
|
|
2516 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2517 | ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], |
|
|
2518 | ], |
2571 | ], |
2519 | )->popup ($ev); |
2572 | ); |
|
|
2573 | |
|
|
2574 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2520 | } |
2575 | } |
2521 | |
2576 | |
2522 | 1 |
2577 | 1 |
2523 | }, |
2578 | }, |
2524 | %args |
2579 | %args |
… | |
… | |
2690 | ? "<b>$item->{count} ×</b> $item->{text}" |
2745 | ? "<b>$item->{count} ×</b> $item->{text}" |
2691 | : $item->{text}; |
2746 | : $item->{text}; |
2692 | |
2747 | |
2693 | for ($short) { |
2748 | for ($short) { |
2694 | s/^\s+//; |
2749 | s/^\s+//; |
2695 | s/\012.*/…/s; |
2750 | s/\s+/ /g; |
2696 | my $len = int 40 / $item->{fontsize}; |
2751 | my $len = int 40 / $item->{fontsize}; |
2697 | substr $_, $len, length, "…" if $len < length; |
2752 | substr $_, $len, length, "…" if $len < length; |
2698 | } |
2753 | } |
2699 | |
2754 | |
2700 | new CFClient::UI::Label |
2755 | new CFClient::UI::Label |
2701 | markup => $short, |
2756 | markup => $short, |
2702 | tooltip => $item->{tooltip}, |
2757 | tooltip => $item->{tooltip}, |
2703 | tooltip_font => $::FONT_PROP, |
2758 | tooltip_font => $::FONT_PROP, |
2704 | tooltip_width => 0.67, |
2759 | tooltip_width => 0.67, |
2705 | fontsize => $item->{fontsize}, |
2760 | fontsize => $item->{fontsize}, |
2706 | color => $item->{color}, |
2761 | fg => $item->{fg}, |
2707 | can_events => 1, |
2762 | can_events => 1, |
2708 | can_hover => 1 |
2763 | can_hover => 1 |
2709 | }; |
2764 | }; |
2710 | } |
2765 | } |
2711 | |
2766 | |
… | |
… | |
2738 | id => ++$self->{id}, |
2793 | id => ++$self->{id}, |
2739 | text => $text, |
2794 | text => $text, |
2740 | timeout => $timeout, |
2795 | timeout => $timeout, |
2741 | tooltip => $text, |
2796 | tooltip => $text, |
2742 | fontsize => 0.8, |
2797 | fontsize => 0.8, |
2743 | color => [0.8, 0.8, 0.8, 0.8], |
2798 | fg => [0.8, 0.8, 0.8, 0.8], |
2744 | pri => 0, |
2799 | pri => 0, |
2745 | count => 1, |
2800 | count => 1, |
2746 | %arg, |
2801 | %arg, |
2747 | }; |
2802 | }; |
2748 | } |
2803 | } |
… | |
… | |
2796 | if $old_w && $old_h && ($old_w != $w || $old_h != $h); |
2851 | if $old_w && $old_h && ($old_w != $w || $old_h != $h); |
2797 | |
2852 | |
2798 | for my $child ($self->children) { |
2853 | for my $child ($self->children) { |
2799 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2854 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2800 | |
2855 | |
|
|
2856 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
|
|
2857 | if exists $child->{req_x}; |
|
|
2858 | |
|
|
2859 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
|
|
2860 | if exists $child->{req_y}; |
|
|
2861 | |
2801 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2862 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
2802 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2863 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
|
|
2864 | |
2803 | $child->configure ($X, $Y, $W, $H); |
2865 | $child->configure ($X, $Y, $W, $H); |
2804 | } |
2866 | } |
2805 | } |
2867 | } |
2806 | |
2868 | |
2807 | sub coord2local { |
2869 | sub coord2local { |