… | |
… | |
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 | } |
… | |
… | |
376 | glVertex $self->{w}, 0; |
375 | glVertex $self->{w}, 0; |
377 | glVertex $self->{w}, $self->{h}; |
376 | glVertex $self->{w}, $self->{h}; |
378 | glVertex 0 , $self->{h}; |
377 | glVertex 0 , $self->{h}; |
379 | glEnd; |
378 | glEnd; |
380 | glPopMatrix; |
379 | glPopMatrix; |
381 | 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; |
382 | } |
381 | } |
383 | } |
382 | } |
384 | |
383 | |
385 | sub _draw { |
384 | sub _draw { |
386 | my ($self) = @_; |
385 | my ($self) = @_; |
… | |
… | |
896 | my ($self, $w, $h) = @_; |
895 | my ($self, $w, $h) = @_; |
897 | |
896 | |
898 | $h -= List::Util::max 0, $self->border * 2; |
897 | $h -= List::Util::max 0, $self->border * 2; |
899 | $w -= List::Util::max 0, $self->border * 2; |
898 | $w -= List::Util::max 0, $self->border * 2; |
900 | |
899 | |
901 | $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) |
902 | if $self->{title}; |
901 | if $self->{title}; |
903 | |
902 | |
904 | $self->child->configure ($self->border, $self->border, $w, $h); |
903 | $self->child->configure ($self->border, $self->border, $w, $h); |
905 | } |
904 | } |
906 | |
905 | |
… | |
… | |
1400 | $self->{layout}->set_width ($self->{w}); |
1399 | $self->{layout}->set_width ($self->{w}); |
1401 | $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); |
1402 | |
1401 | |
1403 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1402 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1404 | |
1403 | |
1405 | $self->{ox} = int $self->{align} < 0 ? $self->{padding} |
1404 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding} |
1406 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1405 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1407 | : ($self->{w} - $tex->{w}) * 0.5; |
1406 | : ($self->{w} - $tex->{w}) * 0.5); |
1408 | |
1407 | |
1409 | $self->{oy} = int $self->{valign} < 0 ? $self->{padding} |
1408 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding} |
1410 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1409 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1411 | : ($self->{h} - $tex->{h}) * 0.5; |
1410 | : ($self->{h} - $tex->{h}) * 0.5); |
1412 | |
1411 | |
1413 | $tex |
1412 | $tex |
1414 | }; |
1413 | }; |
1415 | |
1414 | |
1416 | glEnable GL_TEXTURE_2D; |
1415 | glEnable GL_TEXTURE_2D; |
… | |
… | |
1471 | sub set_text { |
1470 | sub set_text { |
1472 | my ($self, $text) = @_; |
1471 | my ($self, $text) = @_; |
1473 | |
1472 | |
1474 | $self->{cursor} = length $text; |
1473 | $self->{cursor} = length $text; |
1475 | $self->_set_text ($text); |
1474 | $self->_set_text ($text); |
|
|
1475 | $self->update; |
1476 | $self->check_size; |
1476 | $self->check_size; |
1477 | $self->update; |
|
|
1478 | } |
1477 | } |
1479 | |
1478 | |
1480 | sub get_text { |
1479 | sub get_text { |
1481 | $_[0]{text} |
1480 | $_[0]{text} |
1482 | } |
1481 | } |
… | |
… | |
1522 | substr $text, $self->{cursor}++, 0, chr $uni; |
1521 | substr $text, $self->{cursor}++, 0, chr $uni; |
1523 | } |
1522 | } |
1524 | |
1523 | |
1525 | $self->_set_text ($text); |
1524 | $self->_set_text ($text); |
1526 | $self->update; |
1525 | $self->update; |
|
|
1526 | $self->check_size; |
1527 | } |
1527 | } |
1528 | |
1528 | |
1529 | sub focus_in { |
1529 | sub focus_in { |
1530 | my ($self) = @_; |
1530 | my ($self) = @_; |
1531 | |
1531 | |
… | |
… | |
2011 | qw(s1_slider.png s1_slider_bg.png); |
2011 | qw(s1_slider.png s1_slider_bg.png); |
2012 | |
2012 | |
2013 | sub new { |
2013 | sub new { |
2014 | my $class = shift; |
2014 | my $class = shift; |
2015 | |
2015 | |
2016 | # range [value, low, high, page] |
2016 | # range [value, low, high, page, unit] |
2017 | |
2017 | |
2018 | # TODO: 0-width page |
2018 | # TODO: 0-width page |
2019 | # TODO: req_w/h are wrong with vertical |
2019 | # TODO: req_w/h are wrong with vertical |
2020 | # TODO: calculations are off |
2020 | # TODO: calculations are off |
2021 | my $self = $class->SUPER::new ( |
2021 | my $self = $class->SUPER::new ( |
… | |
… | |
2024 | range => [0, 0, 100, 10], |
2024 | range => [0, 0, 100, 10], |
2025 | req_w => $::WIDTH / 80, |
2025 | req_w => $::WIDTH / 80, |
2026 | req_h => $::WIDTH / 80, |
2026 | req_h => $::WIDTH / 80, |
2027 | vertical => 0, |
2027 | vertical => 0, |
2028 | can_hover => 1, |
2028 | can_hover => 1, |
2029 | inner_pad => 5, |
2029 | inner_pad => .05, |
2030 | @_ |
2030 | @_ |
2031 | ); |
2031 | ); |
2032 | |
2032 | |
|
|
2033 | $self->set_value ($self->{range}[0]); |
|
|
2034 | $self->update; |
|
|
2035 | |
2033 | $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 | } |
2034 | } |
2060 | } |
2035 | |
2061 | |
2036 | sub size_request { |
2062 | sub size_request { |
2037 | my ($self) = @_; |
2063 | my ($self) = @_; |
2038 | |
2064 | |
… | |
… | |
2051 | |
2077 | |
2052 | sub mouse_motion { |
2078 | sub mouse_motion { |
2053 | my ($self, $ev, $x, $y) = @_; |
2079 | my ($self, $ev, $x, $y) = @_; |
2054 | |
2080 | |
2055 | 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 | |
2056 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2098 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2057 | |
2099 | |
2058 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
2100 | my $inner_w = 1 - 2 * $self->{inner_pad}; |
2059 | |
2101 | |
2060 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
2102 | $self->{scale} = ($inner_w / ($hi - $lo)) || 1; |
2061 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
|
|
2062 | |
2103 | |
2063 | $x -= $inner_pad_px; # substract the padding |
2104 | $page = $self->{scale} * $page || 10 / ($self->{w} || 1); |
2064 | $x = $x * ($hi - $lo) / $inner_w + $lo; |
2105 | $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 | |
2106 | |
2069 | $self->emit (changed => $x); |
2107 | $value = $self->{inner_pad} + ($value - $page * 0.5); |
2070 | $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; |
2071 | } |
2114 | }); |
2072 | } |
|
|
2073 | |
2115 | |
2074 | # the inner_* stuff is for generating a padding for the slider handle, |
2116 | $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 | } |
2117 | } |
2081 | |
2118 | |
2082 | sub _draw { |
2119 | sub _draw { |
2083 | my ($self) = @_; |
2120 | my ($self) = @_; |
2084 | |
2121 | |
2085 | $self->SUPER::_draw (); |
2122 | $self->SUPER::_draw (); |
2086 | |
2123 | |
2087 | my ($w, $h) = @$self{qw(w h)}; |
2124 | glScale $self->{w}, $self->{h}; |
2088 | |
2125 | |
2089 | if ($self->{vertical}) { |
2126 | if ($self->{vertical}) { |
2090 | # draw a vertical slider like a rotated horizontal slider |
2127 | # draw a vertical slider like a rotated horizontal slider |
2091 | |
2128 | |
2092 | glRotate 90, 0, 0, 1; |
2129 | glRotate 90, 0, 0, 1; |
2093 | glTranslate 0, -$self->{w}, 0; |
2130 | glTranslate 0, 1, 0; |
2094 | |
|
|
2095 | ($w, $h) = ($h, $w); |
|
|
2096 | } |
2131 | } |
2097 | |
2132 | |
2098 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2133 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2099 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2134 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2100 | |
2135 | |
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; |
2136 | glEnable GL_TEXTURE_2D; |
2120 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2137 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2121 | |
2138 | |
2122 | # draw background |
2139 | # draw background |
2123 | $tex[1]->draw_quad_alpha (0, 0, $w, $h); |
2140 | $tex[1]->draw_quad_alpha (0, 0, 1, 1); |
2124 | |
2141 | |
2125 | # draw handle |
2142 | # draw handle |
2126 | $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); |
2127 | |
2144 | |
2128 | glDisable GL_TEXTURE_2D; |
2145 | glDisable GL_TEXTURE_2D; |
2129 | } |
2146 | } |
2130 | |
2147 | |
2131 | ############################################################################# |
2148 | ############################################################################# |
… | |
… | |
2488 | |
2505 | |
2489 | my $desc = $item->{nrof} < 2 |
2506 | my $desc = $item->{nrof} < 2 |
2490 | ? $item->{name} |
2507 | ? $item->{name} |
2491 | : "$item->{nrof} $item->{name_pl}"; |
2508 | : "$item->{nrof} $item->{name_pl}"; |
2492 | |
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 .= " *"; |
2493 | |
2524 | |
2494 | my $self = $class->SUPER::new ( |
2525 | my $self = $class->SUPER::new ( |
2495 | can_hover => 1, |
2526 | can_hover => 1, |
2496 | can_events => 1, |
2527 | can_events => 1, |
2497 | tooltip => (CFClient::UI::Label->escape ($desc) |
2528 | tooltip => (CFClient::UI::Label->escape ($desc) |
… | |
… | |
2503 | if ($ev->{button} == 1) { |
2534 | if ($ev->{button} == 1) { |
2504 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
2535 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
2505 | } elsif ($ev->{button} == 2) { |
2536 | } elsif ($ev->{button} == 2) { |
2506 | $::CONN->send ("apply $item->{tag}"); |
2537 | $::CONN->send ("apply $item->{tag}"); |
2507 | } elsif ($ev->{button} == 3) { |
2538 | } elsif ($ev->{button} == 3) { |
2508 | CFClient::UI::Menu->new ( |
2539 | my @menu_items = ( |
2509 | items => [ |
|
|
2510 | ["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") }], |
2511 | [ |
2544 | [ |
2512 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
2545 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
2513 | sub { $::CONN->send ("lock $item->{tag}") }, |
2546 | 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 | ], |
2547 | ], |
2519 | )->popup ($ev); |
2548 | ); |
|
|
2549 | |
|
|
2550 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2520 | } |
2551 | } |
2521 | |
2552 | |
2522 | 1 |
2553 | 1 |
2523 | }, |
2554 | }, |
2524 | %args |
2555 | %args |
… | |
… | |
2690 | ? "<b>$item->{count} ×</b> $item->{text}" |
2721 | ? "<b>$item->{count} ×</b> $item->{text}" |
2691 | : $item->{text}; |
2722 | : $item->{text}; |
2692 | |
2723 | |
2693 | for ($short) { |
2724 | for ($short) { |
2694 | s/^\s+//; |
2725 | s/^\s+//; |
2695 | s/\012.*/…/s; |
2726 | s/\s+/ /g; |
2696 | my $len = int 40 / $item->{fontsize}; |
2727 | my $len = int 40 / $item->{fontsize}; |
2697 | substr $_, $len, length, "…" if $len < length; |
2728 | substr $_, $len, length, "…" if $len < length; |
2698 | } |
2729 | } |
2699 | |
2730 | |
2700 | new CFClient::UI::Label |
2731 | new CFClient::UI::Label |
2701 | markup => $short, |
2732 | markup => $short, |
2702 | tooltip => $item->{tooltip}, |
2733 | tooltip => $item->{tooltip}, |
2703 | tooltip_font => $::FONT_PROP, |
2734 | tooltip_font => $::FONT_PROP, |
2704 | tooltip_width => 0.67, |
2735 | tooltip_width => 0.67, |
2705 | fontsize => $item->{fontsize}, |
2736 | fontsize => $item->{fontsize}, |
2706 | color => $item->{color}, |
2737 | fg => $item->{fg}, |
2707 | can_events => 1, |
2738 | can_events => 1, |
2708 | can_hover => 1 |
2739 | can_hover => 1 |
2709 | }; |
2740 | }; |
2710 | } |
2741 | } |
2711 | |
2742 | |
… | |
… | |
2738 | id => ++$self->{id}, |
2769 | id => ++$self->{id}, |
2739 | text => $text, |
2770 | text => $text, |
2740 | timeout => $timeout, |
2771 | timeout => $timeout, |
2741 | tooltip => $text, |
2772 | tooltip => $text, |
2742 | fontsize => 0.8, |
2773 | fontsize => 0.8, |
2743 | color => [0.8, 0.8, 0.8, 0.8], |
2774 | fg => [0.8, 0.8, 0.8, 0.8], |
2744 | pri => 0, |
2775 | pri => 0, |
2745 | count => 1, |
2776 | count => 1, |
2746 | %arg, |
2777 | %arg, |
2747 | }; |
2778 | }; |
2748 | } |
2779 | } |
… | |
… | |
2796 | if $old_w && $old_h && ($old_w != $w || $old_h != $h); |
2827 | if $old_w && $old_h && ($old_w != $w || $old_h != $h); |
2797 | |
2828 | |
2798 | for my $child ($self->children) { |
2829 | for my $child ($self->children) { |
2799 | 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)}; |
2800 | |
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 | |
2801 | $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; |
2802 | $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 | |
2803 | $child->configure ($X, $Y, $W, $H); |
2841 | $child->configure ($X, $Y, $W, $H); |
2804 | } |
2842 | } |
2805 | } |
2843 | } |
2806 | |
2844 | |
2807 | sub coord2local { |
2845 | sub coord2local { |