… | |
… | |
11 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
11 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | |
12 | |
13 | our $ROOT; |
13 | our $ROOT; |
14 | our $TOOLTIP; |
14 | our $TOOLTIP; |
15 | our $BUTTON_STATE; |
15 | our $BUTTON_STATE; |
|
|
16 | |
|
|
17 | our %WIDGET; # all widgets, weak-referenced |
16 | |
18 | |
17 | sub check_tooltip { |
19 | sub 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. |
|
|
142 | sub 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 | |
168 | sub destroy { |
191 | sub destroy { |
169 | my ($self) = @_; |
192 | my ($self) = @_; |
… | |
… | |
242 | |
265 | |
243 | sub size_allocate { |
266 | sub size_allocate { |
244 | # nothing to be done |
267 | # nothing to be done |
245 | } |
268 | } |
246 | |
269 | |
247 | sub children { |
|
|
248 | } |
|
|
249 | |
|
|
250 | # call when resolution changes etc. |
|
|
251 | sub reconfigure { |
270 | sub 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 | |
|
|
277 | sub children { |
259 | } |
278 | } |
260 | |
279 | |
261 | sub set_max_size { |
280 | sub 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 | |
365 | sub _draw { |
384 | sub _draw { |
366 | my ($self) = @_; |
385 | my ($self) = @_; |
… | |
… | |
417 | } |
436 | } |
418 | |
437 | |
419 | sub DESTROY { |
438 | sub 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; |
… | |
… | |
1449 | sub set_text { |
1470 | sub 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 | |
1458 | sub get_text { |
1479 | sub get_text { |
1459 | $_[0]{text} |
1480 | $_[0]{text} |
1460 | } |
1481 | } |
… | |
… | |
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 | |
1507 | sub focus_in { |
1529 | sub 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 | |
1991 | sub new { |
2013 | sub 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 | |
|
|
2039 | sub 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 | |
2014 | sub size_request { |
2062 | sub size_request { |
2015 | my ($self) = @_; |
2063 | my ($self) = @_; |
2016 | |
2064 | |
… | |
… | |
2029 | |
2077 | |
2030 | sub mouse_motion { |
2078 | sub 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 | |
|
|
2092 | sub 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 |
|
|
2055 | sub _calc_inner_pad_px { |
|
|
2056 | my ($self, $w) = @_; |
|
|
2057 | ($w / 100) * $self->{inner_pad} # % to pixels |
|
|
2058 | } |
2117 | } |
2059 | |
2118 | |
2060 | sub _draw { |
2119 | sub _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 |
… | |
… | |
2668 | ? "<b>$item->{count} ×</b> $item->{text}" |
2721 | ? "<b>$item->{count} ×</b> $item->{text}" |
2669 | : $item->{text}; |
2722 | : $item->{text}; |
2670 | |
2723 | |
2671 | for ($short) { |
2724 | for ($short) { |
2672 | s/^\s+//; |
2725 | s/^\s+//; |
2673 | s/\012.*/…/s; |
2726 | s/\s+/ /g; |
2674 | my $len = int 40 / $item->{fontsize}; |
2727 | my $len = int 40 / $item->{fontsize}; |
2675 | substr $_, $len, length, "…" if $len < length; |
2728 | substr $_, $len, length, "…" if $len < length; |
2676 | } |
2729 | } |
2677 | |
2730 | |
2678 | new CFClient::UI::Label |
2731 | new CFClient::UI::Label |
2679 | markup => $short, |
2732 | markup => $short, |
2680 | tooltip => $item->{tooltip}, |
2733 | tooltip => $item->{tooltip}, |
2681 | tooltip_font => $::FONT_PROP, |
2734 | tooltip_font => $::FONT_PROP, |
2682 | tooltip_width => 0.67, |
2735 | tooltip_width => 0.67, |
2683 | fontsize => $item->{fontsize}, |
2736 | fontsize => $item->{fontsize}, |
2684 | color => $item->{color}, |
2737 | fg => $item->{fg}, |
2685 | can_events => 1, |
2738 | can_events => 1, |
2686 | can_hover => 1 |
2739 | can_hover => 1 |
2687 | }; |
2740 | }; |
2688 | } |
2741 | } |
2689 | |
2742 | |
… | |
… | |
2716 | id => ++$self->{id}, |
2769 | id => ++$self->{id}, |
2717 | text => $text, |
2770 | text => $text, |
2718 | timeout => $timeout, |
2771 | timeout => $timeout, |
2719 | tooltip => $text, |
2772 | tooltip => $text, |
2720 | fontsize => 0.8, |
2773 | fontsize => 0.8, |
2721 | color => [0.8, 0.8, 0.8, 0.8], |
2774 | fg => [0.8, 0.8, 0.8, 0.8], |
2722 | pri => 0, |
2775 | pri => 0, |
2723 | count => 1, |
2776 | count => 1, |
2724 | %arg, |
2777 | %arg, |
2725 | }; |
2778 | }; |
2726 | } |
2779 | } |
… | |
… | |
2765 | } |
2818 | } |
2766 | |
2819 | |
2767 | sub size_allocate { |
2820 | sub size_allocate { |
2768 | my ($self, $w, $h) = @_; |
2821 | my ($self, $w, $h) = @_; |
2769 | |
2822 | |
2770 | my $old_w = $self->{old_w}; |
2823 | my $old_w = $self->{old_w}; $self->{old_w} = $w; |
2771 | my $old_h = $self->{old_h}; |
2824 | my $old_h = $self->{old_h}; $self->{old_h} = $h; |
2772 | |
2825 | |
2773 | if ($old_w && $old_h) { |
2826 | CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h |
2774 | for my $child ($self->children) { |
2827 | if $old_w && $old_h && ($old_w != $w || $old_h != $h); |
2775 | $child->{x} = int 0.5 + $child->{x} * $w / $old_w; |
|
|
2776 | $child->{w} = int 0.5 + $child->{w} * $w / $old_w; |
|
|
2777 | $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; |
|
|
2778 | $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; |
|
|
2779 | $child->{y} = int 0.5 + $child->{y} * $h / $old_h; |
|
|
2780 | $child->{h} = int 0.5 + $child->{h} * $h / $old_h; |
|
|
2781 | $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; |
|
|
2782 | $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; |
|
|
2783 | } |
|
|
2784 | } |
|
|
2785 | |
2828 | |
2786 | for my $child ($self->children) { |
2829 | for my $child ($self->children) { |
2787 | 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)}; |
2788 | |
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 | |
2789 | $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; |
2790 | $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 | |
2791 | $child->configure ($X, $Y, $W, $H); |
2841 | $child->configure ($X, $Y, $W, $H); |
2792 | } |
2842 | } |
2793 | |
|
|
2794 | $self->{old_w} = $w; |
|
|
2795 | $self->{old_h} = $h; |
|
|
2796 | } |
2843 | } |
2797 | |
2844 | |
2798 | sub coord2local { |
2845 | sub coord2local { |
2799 | my ($self, $x, $y) = @_; |
2846 | my ($self, $x, $y) = @_; |
2800 | |
2847 | |
… | |
… | |
2813 | $self->check_size; |
2860 | $self->check_size; |
2814 | $::WANT_REFRESH++; |
2861 | $::WANT_REFRESH++; |
2815 | } |
2862 | } |
2816 | |
2863 | |
2817 | sub add { |
2864 | sub add { |
2818 | my ($self, $child) = @_; |
2865 | my ($self, @children) = @_; |
2819 | |
2866 | |
|
|
2867 | for my $child (@children) { |
|
|
2868 | $child->{toplevel} = 1; |
|
|
2869 | |
2820 | # integerise window positions |
2870 | # integerise window positions |
2821 | $child->{x} = int $child->{x}; |
2871 | $child->{x} = int $child->{x}; |
2822 | $child->{y} = int $child->{y}; |
2872 | $child->{y} = int $child->{y}; |
|
|
2873 | } |
2823 | |
2874 | |
2824 | $self->SUPER::add ($child); |
2875 | $self->SUPER::add (@children); |
2825 | } |
2876 | } |
2826 | |
2877 | |
2827 | sub on_refresh { |
2878 | sub on_refresh { |
2828 | my ($self, $id, $cb) = @_; |
2879 | my ($self, $id, $cb) = @_; |
2829 | |
2880 | |