… | |
… | |
438 | |
438 | |
439 | # translate local coordinates to global coordinate system |
439 | # translate local coordinates to global coordinate system |
440 | sub coord2global { |
440 | sub coord2global { |
441 | my ($self, $x, $y) = @_; |
441 | my ($self, $x, $y) = @_; |
442 | |
442 | |
|
|
443 | Carp::confess unless $self->{parent};#d# |
|
|
444 | |
443 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
445 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
444 | } |
446 | } |
445 | |
447 | |
446 | sub invoke_focus_in { |
448 | sub invoke_focus_in { |
447 | my ($self) = @_; |
449 | my ($self) = @_; |
… | |
… | |
494 | |
496 | |
495 | sub connect { |
497 | sub connect { |
496 | my ($self, $signal, $cb) = @_; |
498 | my ($self, $signal, $cb) = @_; |
497 | |
499 | |
498 | 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 | } |
499 | } |
506 | } |
500 | |
507 | |
501 | my %has_coords = ( |
508 | my %has_coords = ( |
502 | button_down => 1, |
509 | button_down => 1, |
503 | button_up => 1, |
510 | button_up => 1, |
… | |
… | |
506 | ); |
513 | ); |
507 | |
514 | |
508 | sub emit { |
515 | sub emit { |
509 | my ($self, $signal, @args) = @_; |
516 | my ($self, $signal, @args) = @_; |
510 | |
517 | |
|
|
518 | # I do not really like this solution, but I dislike duplication |
|
|
519 | # and needlessly verbose code, too. |
511 | my @append |
520 | my @append |
512 | = $has_coords{$signal} |
521 | = $has_coords{$signal} |
513 | ? $args[0]->xy ($self) |
522 | ? $args[0]->xy ($self) |
514 | : (); |
523 | : (); |
515 | |
524 | |
… | |
… | |
722 | if $children; |
731 | if $children; |
723 | |
732 | |
724 | $self |
733 | $self |
725 | } |
734 | } |
726 | |
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 | |
727 | sub add { |
744 | sub add { |
728 | my ($self, @widgets) = @_; |
745 | my ($self, @widgets) = @_; |
729 | |
746 | |
730 | $_->set_parent ($self) |
747 | $_->set_parent ($self) |
731 | for @widgets; |
748 | for @widgets; |
… | |
… | |
1347 | sub children { |
1364 | sub children { |
1348 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
1365 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
1349 | } |
1366 | } |
1350 | |
1367 | |
1351 | sub add { |
1368 | sub add { |
1352 | my ($self, $x, $y, $child) = @_; |
1369 | my ($self) = shift; |
1353 | |
1370 | |
|
|
1371 | while (@_) { |
|
|
1372 | my ($x, $y, $child) = splice @_, 0, 3, (); |
1354 | $child->set_parent ($self); |
1373 | $child->set_parent ($self); |
1355 | $self->{children}[$y][$x] = $child; |
1374 | $self->{children}[$y][$x] = $child; |
|
|
1375 | } |
1356 | |
1376 | |
|
|
1377 | $self->{force_realloc} = 1; |
|
|
1378 | $self->{force_size_alloc} = 1; |
1357 | $self->realloc; |
1379 | $self->realloc; |
1358 | } |
1380 | } |
1359 | |
1381 | |
1360 | sub remove { |
1382 | sub remove { |
1361 | my ($self, $child) = @_; |
1383 | my ($self, $child) = @_; |
… | |
… | |
1613 | } |
1635 | } |
1614 | |
1636 | |
1615 | $self |
1637 | $self |
1616 | } |
1638 | } |
1617 | |
1639 | |
1618 | sub escape($) { |
|
|
1619 | local $_ = $_[0]; |
|
|
1620 | |
|
|
1621 | s/&/&/g; |
|
|
1622 | s/>/>/g; |
|
|
1623 | s/</</g; |
|
|
1624 | |
|
|
1625 | $_ |
|
|
1626 | } |
|
|
1627 | |
|
|
1628 | sub update { |
1640 | sub update { |
1629 | my ($self) = @_; |
1641 | my ($self) = @_; |
1630 | |
1642 | |
1631 | delete $self->{texture}; |
1643 | delete $self->{texture}; |
1632 | $self->SUPER::update; |
1644 | $self->SUPER::update; |
… | |
… | |
2181 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2193 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2182 | |
2194 | |
2183 | $self |
2195 | $self |
2184 | } |
2196 | } |
2185 | |
2197 | |
|
|
2198 | sub STORABLE_freeze { |
|
|
2199 | my ($self, $cloning) = @_; |
|
|
2200 | |
|
|
2201 | warn "freeze<$self>\n";#d# |
|
|
2202 | |
|
|
2203 | $self->{path} |
|
|
2204 | or die "cannot serialise CFClient::UI::Image on non-loadable images\n"; |
|
|
2205 | |
|
|
2206 | $self->{path} |
|
|
2207 | } |
|
|
2208 | |
|
|
2209 | sub STORABLE_attach { |
|
|
2210 | my ($self, $cloning, $path) = @_; |
|
|
2211 | warn "attach<@_>\n";#d# |
|
|
2212 | |
|
|
2213 | $self->new (path => $path) |
|
|
2214 | } |
|
|
2215 | |
2186 | sub size_request { |
2216 | sub size_request { |
2187 | my ($self) = @_; |
2217 | my ($self) = @_; |
2188 | |
2218 | |
2189 | ($self->{tex}{w}, $self->{tex}{h}) |
2219 | ($self->{tex}{w}, $self->{tex}{h}) |
2190 | } |
2220 | } |
… | |
… | |
2204 | } |
2234 | } |
2205 | |
2235 | |
2206 | glEnable GL_TEXTURE_2D; |
2236 | glEnable GL_TEXTURE_2D; |
2207 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2237 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2208 | |
2238 | |
2209 | $tex->draw_quad_alpha (0, 0, $w, $h); |
2239 | $tex->draw_quad (0, 0, $w, $h); |
2210 | |
2240 | |
2211 | glDisable GL_TEXTURE_2D; |
2241 | glDisable GL_TEXTURE_2D; |
2212 | } |
2242 | } |
2213 | |
2243 | |
2214 | ############################################################################# |
2244 | ############################################################################# |
… | |
… | |
2506 | sub invoke_mouse_wheel { |
2536 | sub invoke_mouse_wheel { |
2507 | my ($self, $ev) = @_; |
2537 | my ($self, $ev) = @_; |
2508 | |
2538 | |
2509 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2539 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2510 | |
2540 | |
2511 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.1); |
2541 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2); |
2512 | |
2542 | |
2513 | ! ! $delta |
2543 | ! ! $delta |
2514 | } |
2544 | } |
2515 | |
2545 | |
2516 | sub update { |
2546 | sub update { |
… | |
… | |
2986 | |
3016 | |
2987 | $self->{root}->on_post_alloc ("move_$self" => sub { |
3017 | $self->{root}->on_post_alloc ("move_$self" => sub { |
2988 | my $widget = $self->{owner} |
3018 | my $widget = $self->{owner} |
2989 | or return; |
3019 | or return; |
2990 | |
3020 | |
|
|
3021 | if ($widget->{visible}) { |
2991 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
3022 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2992 | |
3023 | |
2993 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
3024 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2994 | if $x + $self->{w} > $self->{root}{w}; |
3025 | if $x + $self->{w} > $self->{root}{w}; |
2995 | |
3026 | |
2996 | $self->move_abs ($x, $y); |
3027 | $self->move_abs ($x, $y); |
|
|
3028 | } else { |
|
|
3029 | $self->hide; |
|
|
3030 | } |
2997 | }); |
3031 | }); |
2998 | } |
3032 | } |
2999 | |
3033 | |
3000 | sub _draw { |
3034 | sub _draw { |
3001 | my ($self) = @_; |
3035 | my ($self) = @_; |
… | |
… | |
3539 | sub new { |
3573 | sub new { |
3540 | my $class = shift; |
3574 | my $class = shift; |
3541 | |
3575 | |
3542 | my $self = $class->SUPER::new ( |
3576 | my $self = $class->SUPER::new ( |
3543 | col_expand => [0, 1, 0], |
3577 | col_expand => [0, 1, 0], |
|
|
3578 | items => [], |
3544 | @_, |
3579 | @_, |
3545 | ); |
3580 | ); |
3546 | |
3581 | |
|
|
3582 | $self->set_sort_order (undef); |
|
|
3583 | |
3547 | $self |
3584 | $self |
|
|
3585 | } |
|
|
3586 | |
|
|
3587 | sub update_items { |
|
|
3588 | my ($self) = @_; |
|
|
3589 | |
|
|
3590 | $self->clear; |
|
|
3591 | |
|
|
3592 | my @item = $self->{sort}->(@{ $self->{items} }); |
|
|
3593 | |
|
|
3594 | my @adds; |
|
|
3595 | my $row = 0; |
|
|
3596 | for my $item ($self->{sort}->(@{ $self->{items} })) { |
|
|
3597 | CFClient::Item::update_widgets $item; |
|
|
3598 | |
|
|
3599 | push @adds, 0, $row, $item->{face_widget}; |
|
|
3600 | push @adds, 1, $row, $item->{desc_widget}; |
|
|
3601 | push @adds, 2, $row, $item->{weight_widget}; |
|
|
3602 | |
|
|
3603 | $row++; |
|
|
3604 | } |
|
|
3605 | |
|
|
3606 | $self->add (@adds); |
|
|
3607 | } |
|
|
3608 | |
|
|
3609 | sub set_sort_order { |
|
|
3610 | my ($self, $order) = @_; |
|
|
3611 | |
|
|
3612 | $self->{sort} = $order ||= sub { |
|
|
3613 | sort { |
|
|
3614 | $a->{type} <=> $b->{type} |
|
|
3615 | or $a->{name} cmp $b->{name} |
|
|
3616 | } @_ |
|
|
3617 | }; |
|
|
3618 | |
|
|
3619 | $self->update_items; |
3548 | } |
3620 | } |
3549 | |
3621 | |
3550 | sub set_items { |
3622 | sub set_items { |
3551 | my ($self, $items) = @_; |
3623 | my ($self, $items) = @_; |
3552 | |
3624 | |
3553 | $self->clear; |
3625 | $self->{items} = [$items ? values %$items : ()]; |
3554 | return unless $items; |
3626 | $self->update_items; |
3555 | |
|
|
3556 | my @items = sort { |
|
|
3557 | ($a->{type} <=> $b->{type}) |
|
|
3558 | or ($a->{name} cmp $b->{name}) |
|
|
3559 | } values %$items; |
|
|
3560 | |
|
|
3561 | $self->{real_items} = \@items; |
|
|
3562 | |
|
|
3563 | my $row = 0; |
|
|
3564 | for my $item (@items) { |
|
|
3565 | CFClient::Item::update_widgets $item; |
|
|
3566 | |
|
|
3567 | $self->add (0, $row, $item->{face_widget}); |
|
|
3568 | $self->add (1, $row, $item->{desc_widget}); |
|
|
3569 | $self->add (2, $row, $item->{weight_widget}); |
|
|
3570 | |
|
|
3571 | $row++; |
|
|
3572 | } |
|
|
3573 | } |
3627 | } |
3574 | |
3628 | |
3575 | ############################################################################# |
3629 | ############################################################################# |
3576 | |
3630 | |
3577 | package CFClient::UI::SpellList; |
3631 | package CFClient::UI::SpellList; |