… | |
… | |
367 | my ($self, $x, $y, $w, $h) = @_; |
367 | my ($self, $x, $y, $w, $h) = @_; |
368 | |
368 | |
369 | if ($self->{aspect}) { |
369 | if ($self->{aspect}) { |
370 | my ($ow, $oh) = ($w, $h); |
370 | my ($ow, $oh) = ($w, $h); |
371 | |
371 | |
372 | $w = List::Util::min $w, int $h * $self->{aspect}; |
372 | $w = List::Util::min $w, CFClient::ceil $h * $self->{aspect}; |
373 | $h = List::Util::min $h, int $w / $self->{aspect}; |
373 | $h = List::Util::min $h, CFClient::ceil $w / $self->{aspect}; |
374 | |
374 | |
375 | # use alignment to adjust x, y |
375 | # use alignment to adjust x, y |
376 | |
376 | |
377 | $x += int 0.5 * ($ow - $w); |
377 | $x += int 0.5 * ($ow - $w); |
378 | $y += int 0.5 * ($oh - $h); |
378 | $y += int 0.5 * ($oh - $h); |
… | |
… | |
429 | |
429 | |
430 | # translate global coordinates to local coordinate system |
430 | # translate global coordinates to local coordinate system |
431 | sub coord2local { |
431 | sub coord2local { |
432 | my ($self, $x, $y) = @_; |
432 | my ($self, $x, $y) = @_; |
433 | |
433 | |
|
|
434 | Carp::confess unless $self->{parent};#d# |
|
|
435 | |
434 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
436 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
435 | } |
437 | } |
436 | |
438 | |
437 | # translate local coordinates to global coordinate system |
439 | # translate local coordinates to global coordinate system |
438 | sub coord2global { |
440 | sub coord2global { |
439 | my ($self, $x, $y) = @_; |
441 | my ($self, $x, $y) = @_; |
|
|
442 | |
|
|
443 | Carp::confess unless $self->{parent};#d# |
440 | |
444 | |
441 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
445 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
442 | } |
446 | } |
443 | |
447 | |
444 | sub invoke_focus_in { |
448 | sub invoke_focus_in { |
… | |
… | |
492 | |
496 | |
493 | sub connect { |
497 | sub connect { |
494 | my ($self, $signal, $cb) = @_; |
498 | my ($self, $signal, $cb) = @_; |
495 | |
499 | |
496 | push @{ $self->{signal_cb}{$signal} }, $cb; |
500 | push @{ $self->{signal_cb}{$signal} }, $cb; |
|
|
501 | |
|
|
502 | defined wantarray and CFClient::guard { |
|
|
503 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
|
|
504 | @{ $self->{signal_cb}{$signal} }; |
|
|
505 | } |
497 | } |
506 | } |
|
|
507 | |
|
|
508 | my %has_coords = ( |
|
|
509 | button_down => 1, |
|
|
510 | button_up => 1, |
|
|
511 | mouse_motion => 1, |
|
|
512 | mouse_wheel => 1, |
|
|
513 | ); |
498 | |
514 | |
499 | sub emit { |
515 | sub emit { |
500 | my ($self, $signal, @args) = @_; |
516 | my ($self, $signal, @args) = @_; |
501 | |
517 | |
|
|
518 | # I do not really like this solution, but I dislike duplication |
|
|
519 | # and needlessly verbose code, too. |
502 | my @append |
520 | my @append |
503 | = ref $args[0] && $args[0]->isa ("CFClient::UI::Event") |
521 | = $has_coords{$signal} |
504 | ? $args[0]->xy ($self) |
522 | ? $args[0]->xy ($self) |
505 | : (); |
523 | : (); |
506 | |
524 | |
507 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
525 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
508 | |
526 | |
… | |
… | |
713 | if $children; |
731 | if $children; |
714 | |
732 | |
715 | $self |
733 | $self |
716 | } |
734 | } |
717 | |
735 | |
|
|
736 | sub realloc { |
|
|
737 | my ($self) = @_; |
|
|
738 | |
|
|
739 | $self->{force_realloc} = 1; |
|
|
740 | $self->{force_size_alloc} = 1; |
|
|
741 | $self->SUPER::realloc; |
|
|
742 | } |
|
|
743 | |
718 | sub add { |
744 | sub add { |
719 | my ($self, @widgets) = @_; |
745 | my ($self, @widgets) = @_; |
720 | |
746 | |
721 | $_->set_parent ($self) |
747 | $_->set_parent ($self) |
722 | for @widgets; |
748 | for @widgets; |
… | |
… | |
1338 | sub children { |
1364 | sub children { |
1339 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
1365 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
1340 | } |
1366 | } |
1341 | |
1367 | |
1342 | sub add { |
1368 | sub add { |
1343 | my ($self, $x, $y, $child) = @_; |
1369 | my ($self) = shift; |
1344 | |
1370 | |
|
|
1371 | while (@_) { |
|
|
1372 | my ($x, $y, $child) = splice @_, 0, 3, (); |
1345 | $child->set_parent ($self); |
1373 | $child->set_parent ($self); |
1346 | $self->{children}[$y][$x] = $child; |
1374 | $self->{children}[$y][$x] = $child; |
|
|
1375 | } |
1347 | |
1376 | |
|
|
1377 | $self->{force_realloc} = 1; |
|
|
1378 | $self->{force_size_alloc} = 1; |
1348 | $self->realloc; |
1379 | $self->realloc; |
1349 | } |
1380 | } |
1350 | |
1381 | |
1351 | sub remove { |
1382 | sub remove { |
1352 | my ($self, $child) = @_; |
1383 | my ($self, $child) = @_; |
… | |
… | |
1604 | } |
1635 | } |
1605 | |
1636 | |
1606 | $self |
1637 | $self |
1607 | } |
1638 | } |
1608 | |
1639 | |
1609 | sub escape($) { |
|
|
1610 | local $_ = $_[0]; |
|
|
1611 | |
|
|
1612 | s/&/&/g; |
|
|
1613 | s/>/>/g; |
|
|
1614 | s/</</g; |
|
|
1615 | |
|
|
1616 | $_ |
|
|
1617 | } |
|
|
1618 | |
|
|
1619 | sub update { |
1640 | sub update { |
1620 | my ($self) = @_; |
1641 | my ($self) = @_; |
1621 | |
1642 | |
1622 | delete $self->{texture}; |
1643 | delete $self->{texture}; |
1623 | $self->SUPER::update; |
1644 | $self->SUPER::update; |
… | |
… | |
2032 | $self->SUPER::_draw; |
2053 | $self->SUPER::_draw; |
2033 | } |
2054 | } |
2034 | |
2055 | |
2035 | ############################################################################# |
2056 | ############################################################################# |
2036 | |
2057 | |
|
|
2058 | package CFClient::UI::CheckBox; |
|
|
2059 | |
|
|
2060 | our @ISA = CFClient::UI::DrawBG::; |
|
|
2061 | |
|
|
2062 | my @tex = |
|
|
2063 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
2064 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
|
|
2065 | |
|
|
2066 | use CFClient::OpenGL; |
|
|
2067 | |
|
|
2068 | sub new { |
|
|
2069 | my $class = shift; |
|
|
2070 | |
|
|
2071 | $class->SUPER::new ( |
|
|
2072 | padding_x => 2, |
|
|
2073 | padding_y => 2, |
|
|
2074 | fg => [1, 1, 1], |
|
|
2075 | active_fg => [1, 1, 0], |
|
|
2076 | bg => [0, 0, 0, 0.2], |
|
|
2077 | active_bg => [1, 1, 1, 0.5], |
|
|
2078 | state => 0, |
|
|
2079 | can_hover => 1, |
|
|
2080 | @_ |
|
|
2081 | ) |
|
|
2082 | } |
|
|
2083 | |
|
|
2084 | sub size_request { |
|
|
2085 | my ($self) = @_; |
|
|
2086 | |
|
|
2087 | (6) x 2 |
|
|
2088 | } |
|
|
2089 | |
|
|
2090 | sub toggle { |
|
|
2091 | my ($self) = @_; |
|
|
2092 | |
|
|
2093 | $self->{state} = !$self->{state}; |
|
|
2094 | $self->emit (changed => $self->{state}); |
|
|
2095 | $self->update; |
|
|
2096 | } |
|
|
2097 | |
|
|
2098 | sub invoke_button_down { |
|
|
2099 | my ($self, $ev, $x, $y) = @_; |
|
|
2100 | |
|
|
2101 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
|
|
2102 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
|
|
2103 | $self->toggle; |
|
|
2104 | } else { |
|
|
2105 | return 0 |
|
|
2106 | } |
|
|
2107 | |
|
|
2108 | 1 |
|
|
2109 | } |
|
|
2110 | |
|
|
2111 | sub _draw { |
|
|
2112 | my ($self) = @_; |
|
|
2113 | |
|
|
2114 | $self->SUPER::_draw; |
|
|
2115 | |
|
|
2116 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
|
|
2117 | |
|
|
2118 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2119 | |
|
|
2120 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
|
|
2121 | |
|
|
2122 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
|
|
2123 | |
|
|
2124 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
2125 | |
|
|
2126 | glEnable GL_TEXTURE_2D; |
|
|
2127 | $tex->draw_quad_alpha (0, 0, $s, $s); |
|
|
2128 | glDisable GL_TEXTURE_2D; |
|
|
2129 | } |
|
|
2130 | |
|
|
2131 | ############################################################################# |
|
|
2132 | |
|
|
2133 | package CFClient::UI::Image; |
|
|
2134 | |
|
|
2135 | our @ISA = CFClient::UI::Base::; |
|
|
2136 | |
|
|
2137 | use CFClient::OpenGL; |
|
|
2138 | |
|
|
2139 | our %texture_cache; |
|
|
2140 | |
|
|
2141 | sub new { |
|
|
2142 | my $class = shift; |
|
|
2143 | |
|
|
2144 | my $self = $class->SUPER::new ( |
|
|
2145 | can_events => 0, |
|
|
2146 | @_, |
|
|
2147 | ); |
|
|
2148 | |
|
|
2149 | $self->{path} || $self->{tex} |
|
|
2150 | or Carp::croak "'path' or 'tex' attributes required"; |
|
|
2151 | |
|
|
2152 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
|
|
2153 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1; |
|
|
2154 | |
|
|
2155 | Scalar::Util::weaken $texture_cache{$self->{path}}; |
|
|
2156 | |
|
|
2157 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
|
|
2158 | |
|
|
2159 | $self |
|
|
2160 | } |
|
|
2161 | |
|
|
2162 | sub STORABLE_freeze { |
|
|
2163 | my ($self, $cloning) = @_; |
|
|
2164 | |
|
|
2165 | $self->{path} |
|
|
2166 | or die "cannot serialise CFClient::UI::Image on non-loadable images\n"; |
|
|
2167 | |
|
|
2168 | $self->{path} |
|
|
2169 | } |
|
|
2170 | |
|
|
2171 | sub STORABLE_attach { |
|
|
2172 | my ($self, $cloning, $path) = @_; |
|
|
2173 | |
|
|
2174 | $self->new (path => $path) |
|
|
2175 | } |
|
|
2176 | |
|
|
2177 | sub size_request { |
|
|
2178 | my ($self) = @_; |
|
|
2179 | |
|
|
2180 | ($self->{tex}{w}, $self->{tex}{h}) |
|
|
2181 | } |
|
|
2182 | |
|
|
2183 | sub _draw { |
|
|
2184 | my ($self) = @_; |
|
|
2185 | |
|
|
2186 | my $tex = $self->{tex}; |
|
|
2187 | |
|
|
2188 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
2189 | |
|
|
2190 | if ($self->{rot90}) { |
|
|
2191 | glRotate 90, 0, 0, 1; |
|
|
2192 | glTranslate 0, -$self->{w}, 0; |
|
|
2193 | |
|
|
2194 | ($w, $h) = ($h, $w); |
|
|
2195 | } |
|
|
2196 | |
|
|
2197 | glEnable GL_TEXTURE_2D; |
|
|
2198 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2199 | |
|
|
2200 | $tex->draw_quad (0, 0, $w, $h); |
|
|
2201 | |
|
|
2202 | glDisable GL_TEXTURE_2D; |
|
|
2203 | } |
|
|
2204 | |
|
|
2205 | ############################################################################# |
|
|
2206 | |
2037 | package CFClient::UI::ImageButton; |
2207 | package CFClient::UI::ImageButton; |
2038 | |
2208 | |
2039 | our @ISA = CFClient::UI::Image::; |
2209 | our @ISA = CFClient::UI::Image::; |
2040 | |
2210 | |
2041 | use CFClient::OpenGL; |
2211 | use CFClient::OpenGL; |
… | |
… | |
2064 | $self->emit ("activate") |
2234 | $self->emit ("activate") |
2065 | if $x >= 0 && $x < $self->{w} |
2235 | if $x >= 0 && $x < $self->{w} |
2066 | && $y >= 0 && $y < $self->{h}; |
2236 | && $y >= 0 && $y < $self->{h}; |
2067 | |
2237 | |
2068 | 1 |
2238 | 1 |
2069 | } |
|
|
2070 | |
|
|
2071 | ############################################################################# |
|
|
2072 | |
|
|
2073 | package CFClient::UI::CheckBox; |
|
|
2074 | |
|
|
2075 | our @ISA = CFClient::UI::DrawBG::; |
|
|
2076 | |
|
|
2077 | my @tex = |
|
|
2078 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
2079 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
|
|
2080 | |
|
|
2081 | use CFClient::OpenGL; |
|
|
2082 | |
|
|
2083 | sub new { |
|
|
2084 | my $class = shift; |
|
|
2085 | |
|
|
2086 | $class->SUPER::new ( |
|
|
2087 | padding_x => 2, |
|
|
2088 | padding_y => 2, |
|
|
2089 | fg => [1, 1, 1], |
|
|
2090 | active_fg => [1, 1, 0], |
|
|
2091 | bg => [0, 0, 0, 0.2], |
|
|
2092 | active_bg => [1, 1, 1, 0.5], |
|
|
2093 | state => 0, |
|
|
2094 | can_hover => 1, |
|
|
2095 | @_ |
|
|
2096 | ) |
|
|
2097 | } |
|
|
2098 | |
|
|
2099 | sub size_request { |
|
|
2100 | my ($self) = @_; |
|
|
2101 | |
|
|
2102 | (6) x 2 |
|
|
2103 | } |
|
|
2104 | |
|
|
2105 | sub toggle { |
|
|
2106 | my ($self) = @_; |
|
|
2107 | |
|
|
2108 | $self->{state} = !$self->{state}; |
|
|
2109 | $self->emit (changed => $self->{state}); |
|
|
2110 | $self->update; |
|
|
2111 | } |
|
|
2112 | |
|
|
2113 | sub invoke_button_down { |
|
|
2114 | my ($self, $ev, $x, $y) = @_; |
|
|
2115 | |
|
|
2116 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
|
|
2117 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
|
|
2118 | $self->toggle; |
|
|
2119 | } else { |
|
|
2120 | return 0 |
|
|
2121 | } |
|
|
2122 | |
|
|
2123 | 1 |
|
|
2124 | } |
|
|
2125 | |
|
|
2126 | sub _draw { |
|
|
2127 | my ($self) = @_; |
|
|
2128 | |
|
|
2129 | $self->SUPER::_draw; |
|
|
2130 | |
|
|
2131 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
|
|
2132 | |
|
|
2133 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2134 | |
|
|
2135 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
|
|
2136 | |
|
|
2137 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
|
|
2138 | |
|
|
2139 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
2140 | |
|
|
2141 | glEnable GL_TEXTURE_2D; |
|
|
2142 | $tex->draw_quad_alpha (0, 0, $s, $s); |
|
|
2143 | glDisable GL_TEXTURE_2D; |
|
|
2144 | } |
|
|
2145 | |
|
|
2146 | ############################################################################# |
|
|
2147 | |
|
|
2148 | package CFClient::UI::Image; |
|
|
2149 | |
|
|
2150 | our @ISA = CFClient::UI::Base::; |
|
|
2151 | |
|
|
2152 | use CFClient::OpenGL; |
|
|
2153 | |
|
|
2154 | our %texture_cache; |
|
|
2155 | |
|
|
2156 | sub new { |
|
|
2157 | my $class = shift; |
|
|
2158 | |
|
|
2159 | my $self = $class->SUPER::new ( |
|
|
2160 | can_events => 0, |
|
|
2161 | @_, |
|
|
2162 | ); |
|
|
2163 | |
|
|
2164 | $self->{path} || $self->{tex} |
|
|
2165 | or Carp::croak "'path' or 'tex' attributes required"; |
|
|
2166 | |
|
|
2167 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
|
|
2168 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1; |
|
|
2169 | |
|
|
2170 | Scalar::Util::weaken $texture_cache{$self->{path}}; |
|
|
2171 | |
|
|
2172 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
|
|
2173 | |
|
|
2174 | $self |
|
|
2175 | } |
|
|
2176 | |
|
|
2177 | sub size_request { |
|
|
2178 | my ($self) = @_; |
|
|
2179 | |
|
|
2180 | ($self->{tex}{w}, $self->{tex}{h}) |
|
|
2181 | } |
|
|
2182 | |
|
|
2183 | sub _draw { |
|
|
2184 | my ($self) = @_; |
|
|
2185 | |
|
|
2186 | my $tex = $self->{tex}; |
|
|
2187 | |
|
|
2188 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
2189 | |
|
|
2190 | if ($self->{rot90}) { |
|
|
2191 | glRotate 90, 0, 0, 1; |
|
|
2192 | glTranslate 0, -$self->{w}, 0; |
|
|
2193 | |
|
|
2194 | ($w, $h) = ($h, $w); |
|
|
2195 | } |
|
|
2196 | |
|
|
2197 | glEnable GL_TEXTURE_2D; |
|
|
2198 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2199 | |
|
|
2200 | $tex->draw_quad_alpha (0, 0, $w, $h); |
|
|
2201 | |
|
|
2202 | glDisable GL_TEXTURE_2D; |
|
|
2203 | } |
2239 | } |
2204 | |
2240 | |
2205 | ############################################################################# |
2241 | ############################################################################# |
2206 | |
2242 | |
2207 | package CFClient::UI::VGauge; |
2243 | package CFClient::UI::VGauge; |
… | |
… | |
2497 | sub invoke_mouse_wheel { |
2533 | sub invoke_mouse_wheel { |
2498 | my ($self, $ev) = @_; |
2534 | my ($self, $ev) = @_; |
2499 | |
2535 | |
2500 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2536 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2501 | |
2537 | |
2502 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.1); |
2538 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2); |
2503 | |
2539 | |
2504 | ! ! $delta |
2540 | ! ! $delta |
2505 | } |
2541 | } |
2506 | |
2542 | |
2507 | sub update { |
2543 | sub update { |
… | |
… | |
2977 | |
3013 | |
2978 | $self->{root}->on_post_alloc ("move_$self" => sub { |
3014 | $self->{root}->on_post_alloc ("move_$self" => sub { |
2979 | my $widget = $self->{owner} |
3015 | my $widget = $self->{owner} |
2980 | or return; |
3016 | or return; |
2981 | |
3017 | |
|
|
3018 | if ($widget->{visible}) { |
2982 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
3019 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2983 | |
3020 | |
2984 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
3021 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2985 | if $x + $self->{w} > $self->{root}{w}; |
3022 | if $x + $self->{w} > $self->{root}{w}; |
2986 | |
3023 | |
2987 | $self->move_abs ($x, $y); |
3024 | $self->move_abs ($x, $y); |
|
|
3025 | } else { |
|
|
3026 | $self->hide; |
|
|
3027 | } |
2988 | }); |
3028 | }); |
2989 | } |
3029 | } |
2990 | |
3030 | |
2991 | sub _draw { |
3031 | sub _draw { |
2992 | my ($self) = @_; |
3032 | my ($self) = @_; |
… | |
… | |
3530 | sub new { |
3570 | sub new { |
3531 | my $class = shift; |
3571 | my $class = shift; |
3532 | |
3572 | |
3533 | my $self = $class->SUPER::new ( |
3573 | my $self = $class->SUPER::new ( |
3534 | col_expand => [0, 1, 0], |
3574 | col_expand => [0, 1, 0], |
|
|
3575 | items => [], |
3535 | @_, |
3576 | @_, |
3536 | ); |
3577 | ); |
3537 | |
3578 | |
|
|
3579 | $self->set_sort_order (undef); |
|
|
3580 | |
3538 | $self |
3581 | $self |
|
|
3582 | } |
|
|
3583 | |
|
|
3584 | sub update_items { |
|
|
3585 | my ($self) = @_; |
|
|
3586 | |
|
|
3587 | $self->clear; |
|
|
3588 | |
|
|
3589 | my @item = $self->{sort}->(@{ $self->{items} }); |
|
|
3590 | |
|
|
3591 | my @adds; |
|
|
3592 | my $row = 0; |
|
|
3593 | for my $item ($self->{sort}->(@{ $self->{items} })) { |
|
|
3594 | CFClient::Item::update_widgets $item; |
|
|
3595 | |
|
|
3596 | push @adds, 0, $row, $item->{face_widget}; |
|
|
3597 | push @adds, 1, $row, $item->{desc_widget}; |
|
|
3598 | push @adds, 2, $row, $item->{weight_widget}; |
|
|
3599 | |
|
|
3600 | $row++; |
|
|
3601 | } |
|
|
3602 | |
|
|
3603 | $self->add (@adds); |
|
|
3604 | } |
|
|
3605 | |
|
|
3606 | sub set_sort_order { |
|
|
3607 | my ($self, $order) = @_; |
|
|
3608 | |
|
|
3609 | $self->{sort} = $order ||= sub { |
|
|
3610 | sort { |
|
|
3611 | $a->{type} <=> $b->{type} |
|
|
3612 | or $a->{name} cmp $b->{name} |
|
|
3613 | } @_ |
|
|
3614 | }; |
|
|
3615 | |
|
|
3616 | $self->update_items; |
3539 | } |
3617 | } |
3540 | |
3618 | |
3541 | sub set_items { |
3619 | sub set_items { |
3542 | my ($self, $items) = @_; |
3620 | my ($self, $items) = @_; |
3543 | |
3621 | |
3544 | $self->clear; |
3622 | $self->{items} = [$items ? values %$items : ()]; |
3545 | return unless $items; |
3623 | $self->update_items; |
3546 | |
|
|
3547 | my @items = sort { |
|
|
3548 | ($a->{type} <=> $b->{type}) |
|
|
3549 | or ($a->{name} cmp $b->{name}) |
|
|
3550 | } values %$items; |
|
|
3551 | |
|
|
3552 | $self->{real_items} = \@items; |
|
|
3553 | |
|
|
3554 | my $row = 0; |
|
|
3555 | for my $item (@items) { |
|
|
3556 | CFClient::Item::update_widgets $item; |
|
|
3557 | |
|
|
3558 | $self->add (0, $row, $item->{face_widget}); |
|
|
3559 | $self->add (1, $row, $item->{desc_widget}); |
|
|
3560 | $self->add (2, $row, $item->{weight_widget}); |
|
|
3561 | |
|
|
3562 | $row++; |
|
|
3563 | } |
|
|
3564 | } |
3624 | } |
3565 | |
3625 | |
3566 | ############################################################################# |
3626 | ############################################################################# |
3567 | |
3627 | |
3568 | package CFClient::UI::SpellList; |
3628 | package CFClient::UI::SpellList; |