… | |
… | |
371 | sub size_allocate { |
371 | sub size_allocate { |
372 | # nothing to be done |
372 | # nothing to be done |
373 | } |
373 | } |
374 | |
374 | |
375 | sub children { |
375 | sub children { |
|
|
376 | # nop |
|
|
377 | } |
|
|
378 | |
|
|
379 | sub visible_children { |
|
|
380 | $_[0]->children |
376 | } |
381 | } |
377 | |
382 | |
378 | sub set_max_size { |
383 | sub set_max_size { |
379 | my ($self, $w, $h) = @_; |
384 | my ($self, $w, $h) = @_; |
380 | |
385 | |
… | |
… | |
663 | our @ISA = CFClient::UI::Base::; |
668 | our @ISA = CFClient::UI::Base::; |
664 | |
669 | |
665 | sub new { |
670 | sub new { |
666 | my ($class, %arg) = @_; |
671 | my ($class, %arg) = @_; |
667 | |
672 | |
668 | my $children = delete $arg{children} || []; |
673 | my $children = delete $arg{children}; |
669 | |
674 | |
670 | my $self = $class->SUPER::new ( |
675 | my $self = $class->SUPER::new ( |
671 | children => [], |
676 | children => [], |
672 | can_events => 0, |
677 | can_events => 0, |
673 | %arg, |
678 | %arg, |
674 | ); |
679 | ); |
|
|
680 | |
675 | $self->add ($_) for @$children; |
681 | $self->add (@$children) |
|
|
682 | if $children; |
676 | |
683 | |
677 | $self |
684 | $self |
678 | } |
685 | } |
679 | |
686 | |
680 | sub add { |
687 | sub add { |
… | |
… | |
728 | $x -= $self->{x}; |
735 | $x -= $self->{x}; |
729 | $y -= $self->{y}; |
736 | $y -= $self->{y}; |
730 | |
737 | |
731 | my $res; |
738 | my $res; |
732 | |
739 | |
733 | for (reverse @{ $self->{children} }) { |
740 | for (reverse $self->visible_children) { |
734 | $res = $_->find_widget ($x, $y) |
741 | $res = $_->find_widget ($x, $y) |
735 | and return $res; |
742 | and return $res; |
736 | } |
743 | } |
737 | |
744 | |
738 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
745 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
… | |
… | |
786 | |
793 | |
787 | $self->{children}[0]->configure (0, 0, $w, $h); |
794 | $self->{children}[0]->configure (0, 0, $w, $h); |
788 | } |
795 | } |
789 | |
796 | |
790 | ############################################################################# |
797 | ############################################################################# |
|
|
798 | |
|
|
799 | # back-buffered drawing area |
791 | |
800 | |
792 | package CFClient::UI::Window; |
801 | package CFClient::UI::Window; |
793 | |
802 | |
794 | our @ISA = CFClient::UI::Bin::; |
803 | our @ISA = CFClient::UI::Bin::; |
795 | |
804 | |
… | |
… | |
948 | package CFClient::UI::ScrolledWindow; |
957 | package CFClient::UI::ScrolledWindow; |
949 | |
958 | |
950 | our @ISA = CFClient::UI::HBox::; |
959 | our @ISA = CFClient::UI::HBox::; |
951 | |
960 | |
952 | sub new { |
961 | sub new { |
953 | my $class = shift; |
962 | my ($class, %arg) = @_; |
|
|
963 | |
|
|
964 | my $child = delete $arg{child}; |
954 | |
965 | |
955 | my $self; |
966 | my $self; |
956 | |
967 | |
957 | my $slider = new CFClient::UI::Slider |
968 | my $slider = new CFClient::UI::Slider |
958 | vertical => 1, |
969 | vertical => 1, |
… | |
… | |
963 | ; |
974 | ; |
964 | |
975 | |
965 | $self = $class->SUPER::new ( |
976 | $self = $class->SUPER::new ( |
966 | vp => (new CFClient::UI::ViewPort expand => 1), |
977 | vp => (new CFClient::UI::ViewPort expand => 1), |
967 | slider => $slider, |
978 | slider => $slider, |
968 | @_, |
979 | %arg, |
969 | ); |
980 | ); |
970 | |
981 | |
971 | $self->{vp}->add ($self->{scrolled}); |
|
|
972 | $self->add ($self->{vp}); |
|
|
973 | $self->add ($self->{slider}); |
982 | $self->SUPER::add ($self->{vp}, $self->{slider}); |
|
|
983 | $self->add ($child) if $child; |
974 | |
984 | |
975 | $self |
985 | $self |
|
|
986 | } |
|
|
987 | |
|
|
988 | sub add { |
|
|
989 | my ($self, $widget) = @_; |
|
|
990 | |
|
|
991 | $self->{vp}->add ($self->{child} = $widget); |
976 | } |
992 | } |
977 | |
993 | |
978 | sub update { |
994 | sub update { |
979 | my ($self) = @_; |
995 | my ($self) = @_; |
980 | |
996 | |
… | |
… | |
2328 | } |
2344 | } |
2329 | |
2345 | |
2330 | sub update { |
2346 | sub update { |
2331 | my ($self) = @_; |
2347 | my ($self) = @_; |
2332 | |
2348 | |
2333 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
2349 | delete $self->{knob_w}; |
|
|
2350 | $self->SUPER::update; |
|
|
2351 | } |
|
|
2352 | |
|
|
2353 | sub _draw { |
|
|
2354 | my ($self) = @_; |
|
|
2355 | |
|
|
2356 | unless ($self->{knob_w}) { |
2334 | $self->set_value ($self->{range}[0]); |
2357 | $self->set_value ($self->{range}[0]); |
2335 | |
2358 | |
2336 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2359 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2337 | my $range = ($hi - $page - $lo) || 1e-100; |
2360 | my $range = ($hi - $page - $lo) || 1e-100; |
2338 | |
2361 | |
… | |
… | |
2344 | $value = ($value - $lo) / $range; |
2367 | $value = ($value - $lo) / $range; |
2345 | $value = $value * $self->{scale} + $self->{offset}; |
2368 | $value = $value * $self->{scale} + $self->{offset}; |
2346 | |
2369 | |
2347 | $self->{knob_x} = $value - $knob_w * 0.5; |
2370 | $self->{knob_x} = $value - $knob_w * 0.5; |
2348 | $self->{knob_w} = $knob_w; |
2371 | $self->{knob_w} = $knob_w; |
2349 | }); |
2372 | } |
2350 | |
|
|
2351 | $self->SUPER::update; |
|
|
2352 | } |
|
|
2353 | |
|
|
2354 | sub _draw { |
|
|
2355 | my ($self) = @_; |
|
|
2356 | |
2373 | |
2357 | $self->SUPER::_draw (); |
2374 | $self->SUPER::_draw (); |
2358 | |
2375 | |
2359 | glScale $self->{w}, $self->{h}; |
2376 | glScale $self->{w}, $self->{h}; |
2360 | |
2377 | |
… | |
… | |
2854 | $self->SUPER::DESTROY; |
2871 | $self->SUPER::DESTROY; |
2855 | } |
2872 | } |
2856 | |
2873 | |
2857 | ############################################################################# |
2874 | ############################################################################# |
2858 | |
2875 | |
|
|
2876 | package CFClient::UI::Buttonbar; |
|
|
2877 | |
|
|
2878 | our @ISA = CFClient::UI::HBox::; |
|
|
2879 | |
|
|
2880 | # TODO: should actualyl wrap buttons and other goodies. |
|
|
2881 | |
|
|
2882 | ############################################################################# |
|
|
2883 | |
2859 | package CFClient::UI::Menu; |
2884 | package CFClient::UI::Menu; |
2860 | |
2885 | |
2861 | our @ISA = CFClient::UI::FancyFrame::; |
2886 | our @ISA = CFClient::UI::FancyFrame::; |
2862 | |
2887 | |
2863 | use CFClient::OpenGL; |
2888 | use CFClient::OpenGL; |
… | |
… | |
2928 | } else { |
2953 | } else { |
2929 | return 0 |
2954 | return 0 |
2930 | } |
2955 | } |
2931 | |
2956 | |
2932 | 1 |
2957 | 1 |
|
|
2958 | } |
|
|
2959 | |
|
|
2960 | ############################################################################# |
|
|
2961 | |
|
|
2962 | package CFClient::UI::Multiplexer; |
|
|
2963 | |
|
|
2964 | our @ISA = CFClient::UI::Container::; |
|
|
2965 | |
|
|
2966 | sub new { |
|
|
2967 | my $class = shift; |
|
|
2968 | |
|
|
2969 | my $self = $class->SUPER::new ( |
|
|
2970 | @_, |
|
|
2971 | ); |
|
|
2972 | |
|
|
2973 | $self->{current} = $self->{children}[0] |
|
|
2974 | if @{ $self->{children} }; |
|
|
2975 | |
|
|
2976 | $self |
|
|
2977 | } |
|
|
2978 | |
|
|
2979 | sub add { |
|
|
2980 | my ($self, @widgets) = @_; |
|
|
2981 | |
|
|
2982 | $self->SUPER::add (@widgets); |
|
|
2983 | |
|
|
2984 | $self->{current} = $self->{children}[0] |
|
|
2985 | if @{ $self->{children} }; |
|
|
2986 | } |
|
|
2987 | |
|
|
2988 | sub set_current_page { |
|
|
2989 | my ($self, $page_or_widget) = @_; |
|
|
2990 | |
|
|
2991 | my $widget = ref $page_or_widget |
|
|
2992 | ? $page_or_widget |
|
|
2993 | : $self->{children}[$page_or_widget]; |
|
|
2994 | |
|
|
2995 | $self->{current} = $widget; |
|
|
2996 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
|
|
2997 | |
|
|
2998 | $self->_emit (page_changed => $self->{current}); |
|
|
2999 | |
|
|
3000 | $self->realloc; |
|
|
3001 | } |
|
|
3002 | |
|
|
3003 | sub visible_children { |
|
|
3004 | $_[0]{current} |
|
|
3005 | } |
|
|
3006 | |
|
|
3007 | sub size_request { |
|
|
3008 | my ($self) = @_; |
|
|
3009 | |
|
|
3010 | $self->{current}->size_request |
|
|
3011 | } |
|
|
3012 | |
|
|
3013 | sub size_allocate { |
|
|
3014 | my ($self, $w, $h) = @_; |
|
|
3015 | |
|
|
3016 | $self->{current}->configure (0, 0, $w, $h); |
|
|
3017 | } |
|
|
3018 | |
|
|
3019 | sub _draw { |
|
|
3020 | my ($self) = @_; |
|
|
3021 | |
|
|
3022 | $self->{current}->draw; |
|
|
3023 | } |
|
|
3024 | |
|
|
3025 | ############################################################################# |
|
|
3026 | |
|
|
3027 | package CFClient::UI::Notebook; |
|
|
3028 | |
|
|
3029 | our @ISA = CFClient::UI::VBox::; |
|
|
3030 | |
|
|
3031 | sub new { |
|
|
3032 | my $class = shift; |
|
|
3033 | |
|
|
3034 | my $self = $class->SUPER::new ( |
|
|
3035 | buttonbar => (new CFClient::UI::Buttonbar), |
|
|
3036 | multiplexer => (new CFClient::UI::Multiplexer expand => 1), |
|
|
3037 | # filter => # will be put between multiplexer and $self |
|
|
3038 | @_, |
|
|
3039 | ); |
|
|
3040 | |
|
|
3041 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
|
|
3042 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
|
|
3043 | |
|
|
3044 | $self |
|
|
3045 | } |
|
|
3046 | |
|
|
3047 | sub add { |
|
|
3048 | my ($self, $title, $widget, $tooltip) = @_; |
|
|
3049 | |
|
|
3050 | Scalar::Util::weaken $self; |
|
|
3051 | |
|
|
3052 | $self->{buttonbar}->add (new CFClient::UI::Button |
|
|
3053 | markup => $title, |
|
|
3054 | tooltip => $tooltip, |
|
|
3055 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3056 | ); |
|
|
3057 | |
|
|
3058 | $self->{multiplexer}->add ($widget); |
|
|
3059 | } |
|
|
3060 | |
|
|
3061 | sub set_current_page { |
|
|
3062 | my ($self, $page) = @_; |
|
|
3063 | |
|
|
3064 | $self->{multiplexer}->set_current_page ($page); |
|
|
3065 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
2933 | } |
3066 | } |
2934 | |
3067 | |
2935 | ############################################################################# |
3068 | ############################################################################# |
2936 | |
3069 | |
2937 | package CFClient::UI::Statusbox; |
3070 | package CFClient::UI::Statusbox; |
… | |
… | |
3050 | |
3183 | |
3051 | sub new { |
3184 | sub new { |
3052 | my $class = shift; |
3185 | my $class = shift; |
3053 | |
3186 | |
3054 | my $self = $class->SUPER::new ( |
3187 | my $self = $class->SUPER::new ( |
3055 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3188 | child => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3056 | @_, |
3189 | @_, |
3057 | ); |
3190 | ); |
3058 | |
3191 | |
3059 | $self |
3192 | $self |
3060 | } |
3193 | } |
3061 | |
3194 | |
3062 | sub set_items { |
3195 | sub set_items { |
3063 | my ($self, $items) = @_; |
3196 | my ($self, $items) = @_; |
3064 | |
3197 | |
3065 | $self->{scrolled}->clear; |
3198 | $self->{child}->clear; |
3066 | return unless $items; |
3199 | return unless $items; |
3067 | |
3200 | |
3068 | my @items = sort { |
3201 | my @items = sort { |
3069 | ($a->{type} <=> $b->{type}) |
3202 | ($a->{type} <=> $b->{type}) |
3070 | or ($a->{name} cmp $b->{name}) |
3203 | or ($a->{name} cmp $b->{name}) |
… | |
… | |
3074 | |
3207 | |
3075 | my $row = 0; |
3208 | my $row = 0; |
3076 | for my $item (@items) { |
3209 | for my $item (@items) { |
3077 | CFClient::Item::update_widgets $item; |
3210 | CFClient::Item::update_widgets $item; |
3078 | |
3211 | |
3079 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
3212 | $self->{child}->add (0, $row, $item->{face_widget}); |
3080 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
3213 | $self->{child}->add (1, $row, $item->{desc_widget}); |
3081 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
3214 | $self->{child}->add (2, $row, $item->{weight_widget}); |
3082 | |
3215 | |
3083 | $row++; |
3216 | $row++; |
3084 | } |
3217 | } |
3085 | } |
3218 | } |
3086 | |
3219 | |
… | |
… | |
3283 | |
3416 | |
3284 | ############################################################################# |
3417 | ############################################################################# |
3285 | |
3418 | |
3286 | package CFClient::UI::SpellList; |
3419 | package CFClient::UI::SpellList; |
3287 | |
3420 | |
3288 | our @ISA = CFClient::UI::FancyFrame::; |
3421 | our @ISA = CFClient::UI::Table::; |
3289 | |
3422 | |
3290 | sub new { |
3423 | sub new { |
3291 | my $class = shift; |
3424 | my $class = shift; |
3292 | |
3425 | |
3293 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
3426 | my $self = $class->SUPER::new ( |
3294 | |
3427 | binding => [], |
3295 | $self->add (new CFClient::UI::ScrolledWindow |
3428 | commands => [], |
3296 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
3429 | @_, |
3297 | |
3430 | ) |
3298 | $self; |
|
|
3299 | } |
3431 | } |
3300 | |
3432 | |
3301 | # XXX: Do sorting? Argl... |
3433 | # XXX: Do sorting? Argl... |
3302 | sub add_spell { |
3434 | sub add_spell { |
3303 | my ($self, $spell) = @_; |
3435 | my ($self, $spell) = @_; |
3304 | $self->{spells}->{$spell->{name}} = $spell; |
3436 | $self->{spells}->{$spell->{name}} = $spell; |
3305 | |
3437 | |
3306 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3438 | $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3307 | face => $spell->{face}, |
3439 | face => $spell->{face}, |
3308 | can_hover => 1, |
3440 | can_hover => 1, |
3309 | can_events => 1, |
3441 | can_events => 1, |
3310 | tooltip => $spell->{message}); |
3442 | tooltip => $spell->{message}); |
3311 | |
3443 | |
3312 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3444 | $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3313 | text => $spell->{name}, |
3445 | text => $spell->{name}, |
3314 | can_hover => 1, |
3446 | can_hover => 1, |
3315 | can_events => 1, |
3447 | can_events => 1, |
3316 | tooltip => $spell->{message}, |
3448 | tooltip => $spell->{message}, |
3317 | expand => 1); |
3449 | expand => 1); |
3318 | |
3450 | |
3319 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3451 | $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3320 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3452 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3321 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3453 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3322 | expand => 1); |
3454 | expand => 1); |
3323 | |
3455 | |
3324 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3456 | $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3325 | text => "bind to key", |
3457 | text => "bind to key", |
3326 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3458 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3327 | } |
3459 | } |
3328 | |
3460 | |
3329 | sub rebuild_spell_list { |
3461 | sub rebuild_spell_list { |