… | |
… | |
986 | $self->add ($child) if $child; |
986 | $self->add ($child) if $child; |
987 | |
987 | |
988 | $self |
988 | $self |
989 | } |
989 | } |
990 | |
990 | |
|
|
991 | #TODO# update range on size_allocate depending on child |
|
|
992 | |
991 | sub add { |
993 | sub add { |
992 | my ($self, $widget) = @_; |
994 | my ($self, $widget) = @_; |
993 | |
995 | |
994 | $self->{vp}->add ($self->{child} = $widget); |
996 | $self->{vp}->add ($self->{child} = $widget); |
995 | } |
997 | } |
996 | |
998 | |
|
|
999 | sub update_slider { |
|
|
1000 | my ($self) = @_; |
|
|
1001 | |
|
|
1002 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]); |
|
|
1003 | } |
|
|
1004 | |
997 | sub update { |
1005 | sub update { |
998 | my ($self) = @_; |
1006 | my ($self) = @_; |
999 | |
1007 | |
1000 | $self->SUPER::update; |
1008 | $self->SUPER::update; |
1001 | |
1009 | |
1002 | # todo: overwrite size_allocate of child |
1010 | $self->update_slider; |
1003 | my $child = $self->{vp}->child; |
|
|
1004 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
|
|
1005 | } |
1011 | } |
1006 | |
1012 | |
1007 | sub invoke_size_allocate { |
1013 | sub invoke_size_allocate { |
1008 | my ($self, $w, $h) = @_; |
1014 | my ($self, $w, $h) = @_; |
1009 | |
1015 | |
1010 | my $child = $self->{vp}->child; |
1016 | $self->update_slider; |
1011 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
|
|
1012 | |
1017 | |
1013 | $self->SUPER::invoke_size_allocate ($w, $h) |
1018 | $self->SUPER::invoke_size_allocate ($w, $h) |
1014 | } |
1019 | } |
1015 | |
|
|
1016 | #TODO# update range on size_allocate depending on child |
|
|
1017 | # update viewport offset on scroll |
|
|
1018 | |
1020 | |
1019 | ############################################################################# |
1021 | ############################################################################# |
1020 | |
1022 | |
1021 | package CFClient::UI::Frame; |
1023 | package CFClient::UI::Frame; |
1022 | |
1024 | |
… | |
… | |
1652 | |
1654 | |
1653 | sub set_fontsize { |
1655 | sub set_fontsize { |
1654 | my ($self, $fontsize) = @_; |
1656 | my ($self, $fontsize) = @_; |
1655 | |
1657 | |
1656 | $self->{fontsize} = $fontsize; |
1658 | $self->{fontsize} = $fontsize; |
|
|
1659 | delete $self->{size_req}; |
1657 | delete $self->{texture}; |
1660 | delete $self->{texture}; |
1658 | |
1661 | |
1659 | $self->realloc; |
1662 | $self->realloc; |
1660 | } |
1663 | } |
1661 | |
1664 | |
… | |
… | |
3408 | count => 1, |
3411 | count => 1, |
3409 | %arg, |
3412 | %arg, |
3410 | }; |
3413 | }; |
3411 | } |
3414 | } |
3412 | |
3415 | |
|
|
3416 | $ROOT->on_refresh (reorder => sub { |
3413 | $self->reorder; |
3417 | $self->reorder; |
|
|
3418 | }); |
3414 | } |
3419 | } |
3415 | |
3420 | |
3416 | sub reconfigure { |
3421 | sub reconfigure { |
3417 | my ($self) = @_; |
3422 | my ($self) = @_; |
3418 | |
3423 | |
… | |
… | |
3455 | return unless $items; |
3460 | return unless $items; |
3456 | |
3461 | |
3457 | my @items = sort { |
3462 | my @items = sort { |
3458 | ($a->{type} <=> $b->{type}) |
3463 | ($a->{type} <=> $b->{type}) |
3459 | or ($a->{name} cmp $b->{name}) |
3464 | or ($a->{name} cmp $b->{name}) |
3460 | } @$items; |
3465 | } values %$items; |
3461 | |
3466 | |
3462 | $self->{real_items} = \@items; |
3467 | $self->{real_items} = \@items; |
3463 | |
3468 | |
3464 | my $row = 0; |
3469 | my $row = 0; |
3465 | for my $item (@items) { |
3470 | for my $item (@items) { |
… | |
… | |
3468 | $self->{child}->add (0, $row, $item->{face_widget}); |
3473 | $self->{child}->add (0, $row, $item->{face_widget}); |
3469 | $self->{child}->add (1, $row, $item->{desc_widget}); |
3474 | $self->{child}->add (1, $row, $item->{desc_widget}); |
3470 | $self->{child}->add (2, $row, $item->{weight_widget}); |
3475 | $self->{child}->add (2, $row, $item->{weight_widget}); |
3471 | |
3476 | |
3472 | $row++; |
3477 | $row++; |
3473 | } |
|
|
3474 | } |
|
|
3475 | |
|
|
3476 | ############################################################################# |
|
|
3477 | |
|
|
3478 | package CFClient::UI::BindEditor; |
|
|
3479 | |
|
|
3480 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
3481 | |
|
|
3482 | sub new { |
|
|
3483 | my $class = shift; |
|
|
3484 | |
|
|
3485 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
|
|
3486 | |
|
|
3487 | $self->add (my $vb = new CFClient::UI::VBox); |
|
|
3488 | |
|
|
3489 | |
|
|
3490 | $vb->add ($self->{rec_btn} = new CFClient::UI::Button |
|
|
3491 | text => "start recording", |
|
|
3492 | tooltip => "Start/Stops recording of actions." |
|
|
3493 | ."All subsequent actions after the recording started will be captured." |
|
|
3494 | ."The actions are displayed after the record was stopped." |
|
|
3495 | ."To bind the action you have to click on the 'Bind' button", |
|
|
3496 | on_activate => sub { |
|
|
3497 | unless ($self->{recording}) { |
|
|
3498 | $self->start; |
|
|
3499 | } else { |
|
|
3500 | $self->stop; |
|
|
3501 | } |
|
|
3502 | }); |
|
|
3503 | |
|
|
3504 | $vb->add (new CFClient::UI::Label text => "Actions:"); |
|
|
3505 | $vb->add ($self->{cmdbox} = new CFClient::UI::VBox); |
|
|
3506 | |
|
|
3507 | $vb->add (new CFClient::UI::Label text => "Bound to: "); |
|
|
3508 | $vb->add (my $hb = new CFClient::UI::HBox); |
|
|
3509 | $hb->add ($self->{keylbl} = new CFClient::UI::Label expand => 1); |
|
|
3510 | $hb->add (new CFClient::UI::Button |
|
|
3511 | text => "bind", |
|
|
3512 | tooltip => "This opens a query where you have to press the key combination to bind the recorded actions", |
|
|
3513 | on_activate => sub { |
|
|
3514 | $self->ask_for_bind; |
|
|
3515 | }); |
|
|
3516 | |
|
|
3517 | $vb->add (my $hb = new CFClient::UI::HBox); |
|
|
3518 | $hb->add (new CFClient::UI::Button |
|
|
3519 | text => "ok", |
|
|
3520 | expand => 1, |
|
|
3521 | tooltip => "This closes the binding editor and saves the binding", |
|
|
3522 | on_activate => sub { |
|
|
3523 | $self->hide; |
|
|
3524 | $self->commit; |
|
|
3525 | }); |
|
|
3526 | |
|
|
3527 | $hb->add (new CFClient::UI::Button |
|
|
3528 | text => "cancel", |
|
|
3529 | expand => 1, |
|
|
3530 | tooltip => "This closes the binding editor without saving", |
|
|
3531 | on_activate => sub { |
|
|
3532 | $self->hide; |
|
|
3533 | $self->{binding_cancel}->() |
|
|
3534 | if $self->{binding_cancel}; |
|
|
3535 | }); |
|
|
3536 | |
|
|
3537 | $self->update_binding_widgets; |
|
|
3538 | |
|
|
3539 | $self |
|
|
3540 | } |
|
|
3541 | |
|
|
3542 | sub cfg_bind { |
|
|
3543 | my ($self, $mod, $sym, $cmds) = @_; |
|
|
3544 | $::CFG->{profile}{default}{bindings}{$mod}{$sym} = $cmds; |
|
|
3545 | ::update_bindings (); |
|
|
3546 | } |
|
|
3547 | |
|
|
3548 | sub cfg_unbind { |
|
|
3549 | my ($self, $mod, $sym, $cmds) = @_; |
|
|
3550 | delete $::CFG->{profile}{default}{bindings}{$mod}{$sym}; |
|
|
3551 | ::update_bindings (); |
|
|
3552 | } |
|
|
3553 | |
|
|
3554 | sub commit { |
|
|
3555 | my ($self) = @_; |
|
|
3556 | my ($mod, $sym, $cmds) = $self->get_binding; |
|
|
3557 | if ($sym != 0 && @$cmds > 0) { |
|
|
3558 | $::STATUSBOX->add ("Bound actions to '".CFClient::Binder::keycombo_to_name ($mod, $sym) |
|
|
3559 | ."'. Don't forget 'Save Config'!"); |
|
|
3560 | $self->{binding_change}->($mod, $sym, $cmds) |
|
|
3561 | if $self->{binding_change}; |
|
|
3562 | } else { |
|
|
3563 | $::STATUSBOX->add ("No action bound, no key or action specified!"); |
|
|
3564 | $self->{binding_cancel}->() |
|
|
3565 | if $self->{binding_cancel}; |
|
|
3566 | } |
|
|
3567 | } |
|
|
3568 | |
|
|
3569 | sub start { |
|
|
3570 | my ($self) = @_; |
|
|
3571 | |
|
|
3572 | $self->{rec_btn}->set_text ("stop recording"); |
|
|
3573 | $self->{recording} = 1; |
|
|
3574 | $self->clear_command_list; |
|
|
3575 | $::CONN->start_record if $::CONN; |
|
|
3576 | } |
|
|
3577 | |
|
|
3578 | sub stop { |
|
|
3579 | my ($self) = @_; |
|
|
3580 | |
|
|
3581 | $self->{rec_btn}->set_text ("start recording"); |
|
|
3582 | $self->{recording} = 0; |
|
|
3583 | |
|
|
3584 | my $rec; |
|
|
3585 | $rec = $::CONN->stop_record if $::CONN; |
|
|
3586 | return unless ref $rec eq 'ARRAY'; |
|
|
3587 | $self->set_command_list ($rec); |
|
|
3588 | } |
|
|
3589 | |
|
|
3590 | |
|
|
3591 | sub ask_for_bind_and_commit { |
|
|
3592 | my ($self) = @_; |
|
|
3593 | $self->ask_for_bind (1); |
|
|
3594 | } |
|
|
3595 | |
|
|
3596 | sub ask_for_bind { |
|
|
3597 | my ($self, $commit, $end_cb) = @_; |
|
|
3598 | |
|
|
3599 | CFClient::Binder::open_binding_dialog (sub { |
|
|
3600 | my ($mod, $sym) = @_; |
|
|
3601 | $self->{binding} = [$mod, $sym]; # XXX: how to stop that memleak? |
|
|
3602 | $self->update_binding_widgets; |
|
|
3603 | $self->commit if $commit; |
|
|
3604 | $end_cb->() if $end_cb; |
|
|
3605 | }); |
|
|
3606 | } |
|
|
3607 | |
|
|
3608 | # $mod and $sym are the modifiers and key symbol |
|
|
3609 | # $cmds is a array ref of strings (the commands) |
|
|
3610 | # $cb is the callback that is executed on OK |
|
|
3611 | # $ccb is the callback that is executed on CANCEL and |
|
|
3612 | # when the binding was unsuccessful on OK |
|
|
3613 | sub set_binding { |
|
|
3614 | my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; |
|
|
3615 | |
|
|
3616 | $self->clear_command_list; |
|
|
3617 | $self->{recording} = 0; |
|
|
3618 | $self->{rec_btn}->set_text ("start recording"); |
|
|
3619 | |
|
|
3620 | $self->{binding} = [$mod, $sym]; |
|
|
3621 | $self->{commands} = $cmds; |
|
|
3622 | |
|
|
3623 | $self->{binding_change} = $cb; |
|
|
3624 | $self->{binding_cancel} = $ccb; |
|
|
3625 | |
|
|
3626 | $self->update_binding_widgets; |
|
|
3627 | } |
|
|
3628 | |
|
|
3629 | # this is a shortcut method that asks for a binding |
|
|
3630 | # and then just binds it. |
|
|
3631 | sub do_quick_binding { |
|
|
3632 | my ($self, $cmds, $end_cb) = @_; |
|
|
3633 | $self->set_binding (undef, undef, $cmds, sub { $self->cfg_bind (@_) }); |
|
|
3634 | $self->ask_for_bind (1, $end_cb); |
|
|
3635 | } |
|
|
3636 | |
|
|
3637 | sub update_binding_widgets { |
|
|
3638 | my ($self) = @_; |
|
|
3639 | my ($mod, $sym, $cmds) = $self->get_binding; |
|
|
3640 | $self->{keylbl}->set_text (CFClient::Binder::keycombo_to_name ($mod, $sym)); |
|
|
3641 | $self->set_command_list ($cmds); |
|
|
3642 | } |
|
|
3643 | |
|
|
3644 | sub get_binding { |
|
|
3645 | my ($self) = @_; |
|
|
3646 | return ( |
|
|
3647 | $self->{binding}->[0], |
|
|
3648 | $self->{binding}->[1], |
|
|
3649 | [ grep { defined $_ } @{$self->{commands}} ] |
|
|
3650 | ); |
|
|
3651 | } |
|
|
3652 | |
|
|
3653 | sub clear_command_list { |
|
|
3654 | my ($self) = @_; |
|
|
3655 | $self->{cmdbox}->clear (); |
|
|
3656 | } |
|
|
3657 | |
|
|
3658 | sub set_command_list { |
|
|
3659 | my ($self, $cmds) = @_; |
|
|
3660 | |
|
|
3661 | $self->{cmdbox}->clear (); |
|
|
3662 | $self->{commands} = $cmds; |
|
|
3663 | |
|
|
3664 | my $idx = 0; |
|
|
3665 | |
|
|
3666 | for (@$cmds) { |
|
|
3667 | $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox); |
|
|
3668 | |
|
|
3669 | my $i = $idx; |
|
|
3670 | $hb->add (new CFClient::UI::Label text => $_); |
|
|
3671 | $hb->add (new CFClient::UI::Button |
|
|
3672 | text => "delete", |
|
|
3673 | tooltip => "Deletes the action from the record", |
|
|
3674 | on_activate => sub { |
|
|
3675 | $self->{cmdbox}->remove ($hb); |
|
|
3676 | $cmds->[$i] = undef; |
|
|
3677 | }); |
|
|
3678 | |
|
|
3679 | |
|
|
3680 | $idx++ |
|
|
3681 | } |
3478 | } |
3682 | } |
3479 | } |
3683 | |
3480 | |
3684 | ############################################################################# |
3481 | ############################################################################# |
3685 | |
3482 | |
… | |
… | |
3739 | } elsif ($ev->{button} == 2) { |
3536 | } elsif ($ev->{button} == 2) { |
3740 | $::CONN->user_send ("invoke $spell->{name}"); |
3537 | $::CONN->user_send ("invoke $spell->{name}"); |
3741 | } elsif ($ev->{button} == 3) { |
3538 | } elsif ($ev->{button} == 3) { |
3742 | (new CFClient::UI::Menu |
3539 | (new CFClient::UI::Menu |
3743 | items => [ |
3540 | items => [ |
3744 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
3541 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
3745 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
3542 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
3746 | ], |
3543 | ], |
3747 | )->popup ($ev); |
3544 | )->popup ($ev); |
3748 | } else { |
3545 | } else { |
3749 | return 0; |
3546 | return 0; |