… | |
… | |
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 | |
… | |
… | |
1144 | my $dy = $ev->{y} - $oy; |
1160 | my $dy = $ev->{y} - $oy; |
1145 | |
1161 | |
1146 | $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); |
1162 | $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); |
1147 | $self->{force_h} = $bh + $dy * ($my ? -1 : 1); |
1163 | $self->{force_h} = $bh + $dy * ($my ? -1 : 1); |
1148 | |
1164 | |
|
|
1165 | $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); |
1149 | $self->realloc; |
1166 | $self->realloc; |
1150 | $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); |
|
|
1151 | }; |
1167 | }; |
1152 | |
1168 | |
1153 | } elsif ($lr ^ $td) { |
1169 | } elsif ($lr ^ $td) { |
1154 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1170 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1155 | my ($bx, $by) = ($self->{x}, $self->{y}); |
1171 | my ($bx, $by) = ($self->{x}, $self->{y}); |
… | |
… | |
1158 | my ($ev, $x, $y) = @_; |
1174 | my ($ev, $x, $y) = @_; |
1159 | |
1175 | |
1160 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1176 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1161 | |
1177 | |
1162 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
1178 | $self->move_abs ($bx + $x - $ox, $by + $y - $oy); |
|
|
1179 | # HACK: the next line is required to enforce placement |
|
|
1180 | $self->{parent}->size_allocate ($self->{parent}{w}, $self->{parent}{h}); |
1163 | }; |
1181 | }; |
1164 | } else { |
1182 | } else { |
1165 | return 0; |
1183 | return 0; |
1166 | } |
1184 | } |
1167 | |
1185 | |
… | |
… | |
1660 | |
1678 | |
1661 | delete $self->{cur_h}; |
1679 | delete $self->{cur_h}; |
1662 | |
1680 | |
1663 | return if $self->{text} eq $text; |
1681 | return if $self->{text} eq $text; |
1664 | |
1682 | |
1665 | delete $self->{texture}; |
|
|
1666 | |
|
|
1667 | $self->{last_activity} = $::NOW; |
1683 | $self->{last_activity} = $::NOW; |
1668 | $self->{text} = $text; |
1684 | $self->{text} = $text; |
1669 | |
1685 | |
1670 | $text =~ s/./*/g if $self->{hidden}; |
1686 | $text =~ s/./*/g if $self->{hidden}; |
1671 | $self->{layout}->set_text ("$text "); |
1687 | $self->{layout}->set_text ("$text "); |
1672 | |
1688 | |
1673 | $self->_emit (changed => $self->{text}); |
1689 | $self->_emit (changed => $self->{text}); |
|
|
1690 | $self->update; |
1674 | } |
1691 | } |
1675 | |
1692 | |
1676 | sub set_text { |
1693 | sub set_text { |
1677 | my ($self, $text) = @_; |
1694 | my ($self, $text) = @_; |
1678 | |
1695 | |
… | |
… | |
2328 | } |
2345 | } |
2329 | |
2346 | |
2330 | sub update { |
2347 | sub update { |
2331 | my ($self) = @_; |
2348 | my ($self) = @_; |
2332 | |
2349 | |
2333 | $CFClient::UI::ROOT->on_post_alloc ($self => sub { |
2350 | delete $self->{knob_w}; |
|
|
2351 | $self->SUPER::update; |
|
|
2352 | } |
|
|
2353 | |
|
|
2354 | sub _draw { |
|
|
2355 | my ($self) = @_; |
|
|
2356 | |
|
|
2357 | unless ($self->{knob_w}) { |
2334 | $self->set_value ($self->{range}[0]); |
2358 | $self->set_value ($self->{range}[0]); |
2335 | |
2359 | |
2336 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2360 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
2337 | my $range = ($hi - $page - $lo) || 1e-100; |
2361 | my $range = ($hi - $page - $lo) || 1e-100; |
2338 | |
2362 | |
… | |
… | |
2344 | $value = ($value - $lo) / $range; |
2368 | $value = ($value - $lo) / $range; |
2345 | $value = $value * $self->{scale} + $self->{offset}; |
2369 | $value = $value * $self->{scale} + $self->{offset}; |
2346 | |
2370 | |
2347 | $self->{knob_x} = $value - $knob_w * 0.5; |
2371 | $self->{knob_x} = $value - $knob_w * 0.5; |
2348 | $self->{knob_w} = $knob_w; |
2372 | $self->{knob_w} = $knob_w; |
2349 | }); |
2373 | } |
2350 | |
|
|
2351 | $self->SUPER::update; |
|
|
2352 | } |
|
|
2353 | |
|
|
2354 | sub _draw { |
|
|
2355 | my ($self) = @_; |
|
|
2356 | |
2374 | |
2357 | $self->SUPER::_draw (); |
2375 | $self->SUPER::_draw (); |
2358 | |
2376 | |
2359 | glScale $self->{w}, $self->{h}; |
2377 | glScale $self->{w}, $self->{h}; |
2360 | |
2378 | |
… | |
… | |
2854 | $self->SUPER::DESTROY; |
2872 | $self->SUPER::DESTROY; |
2855 | } |
2873 | } |
2856 | |
2874 | |
2857 | ############################################################################# |
2875 | ############################################################################# |
2858 | |
2876 | |
|
|
2877 | package CFClient::UI::Buttonbar; |
|
|
2878 | |
|
|
2879 | our @ISA = CFClient::UI::HBox::; |
|
|
2880 | |
|
|
2881 | # TODO: should actualyl wrap buttons and other goodies. |
|
|
2882 | |
|
|
2883 | ############################################################################# |
|
|
2884 | |
2859 | package CFClient::UI::Menu; |
2885 | package CFClient::UI::Menu; |
2860 | |
2886 | |
2861 | our @ISA = CFClient::UI::FancyFrame::; |
2887 | our @ISA = CFClient::UI::FancyFrame::; |
2862 | |
2888 | |
2863 | use CFClient::OpenGL; |
2889 | use CFClient::OpenGL; |
… | |
… | |
2928 | } else { |
2954 | } else { |
2929 | return 0 |
2955 | return 0 |
2930 | } |
2956 | } |
2931 | |
2957 | |
2932 | 1 |
2958 | 1 |
|
|
2959 | } |
|
|
2960 | |
|
|
2961 | ############################################################################# |
|
|
2962 | |
|
|
2963 | package CFClient::UI::Multiplexer; |
|
|
2964 | |
|
|
2965 | our @ISA = CFClient::UI::Container::; |
|
|
2966 | |
|
|
2967 | sub new { |
|
|
2968 | my $class = shift; |
|
|
2969 | |
|
|
2970 | my $self = $class->SUPER::new ( |
|
|
2971 | @_, |
|
|
2972 | ); |
|
|
2973 | |
|
|
2974 | $self->{current} = $self->{children}[0] |
|
|
2975 | if @{ $self->{children} }; |
|
|
2976 | |
|
|
2977 | $self |
|
|
2978 | } |
|
|
2979 | |
|
|
2980 | sub add { |
|
|
2981 | my ($self, @widgets) = @_; |
|
|
2982 | |
|
|
2983 | $self->SUPER::add (@widgets); |
|
|
2984 | |
|
|
2985 | $self->{current} = $self->{children}[0] |
|
|
2986 | if @{ $self->{children} }; |
|
|
2987 | } |
|
|
2988 | |
|
|
2989 | sub set_current_page { |
|
|
2990 | my ($self, $page_or_widget) = @_; |
|
|
2991 | |
|
|
2992 | my $widget = ref $page_or_widget |
|
|
2993 | ? $page_or_widget |
|
|
2994 | : $self->{children}[$page_or_widget]; |
|
|
2995 | |
|
|
2996 | $self->{current} = $widget; |
|
|
2997 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
|
|
2998 | |
|
|
2999 | $self->_emit (page_changed => $self->{current}); |
|
|
3000 | |
|
|
3001 | $self->realloc; |
|
|
3002 | } |
|
|
3003 | |
|
|
3004 | sub visible_children { |
|
|
3005 | $_[0]{current} |
|
|
3006 | } |
|
|
3007 | |
|
|
3008 | sub size_request { |
|
|
3009 | my ($self) = @_; |
|
|
3010 | |
|
|
3011 | $self->{current}->size_request |
|
|
3012 | } |
|
|
3013 | |
|
|
3014 | sub size_allocate { |
|
|
3015 | my ($self, $w, $h) = @_; |
|
|
3016 | |
|
|
3017 | $self->{current}->configure (0, 0, $w, $h); |
|
|
3018 | } |
|
|
3019 | |
|
|
3020 | sub _draw { |
|
|
3021 | my ($self) = @_; |
|
|
3022 | |
|
|
3023 | $self->{current}->draw; |
|
|
3024 | } |
|
|
3025 | |
|
|
3026 | ############################################################################# |
|
|
3027 | |
|
|
3028 | package CFClient::UI::Notebook; |
|
|
3029 | |
|
|
3030 | our @ISA = CFClient::UI::VBox::; |
|
|
3031 | |
|
|
3032 | sub new { |
|
|
3033 | my $class = shift; |
|
|
3034 | |
|
|
3035 | my $self = $class->SUPER::new ( |
|
|
3036 | buttonbar => (new CFClient::UI::Buttonbar), |
|
|
3037 | multiplexer => (new CFClient::UI::Multiplexer expand => 1), |
|
|
3038 | # filter => # will be put between multiplexer and $self |
|
|
3039 | @_, |
|
|
3040 | ); |
|
|
3041 | |
|
|
3042 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
|
|
3043 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
|
|
3044 | |
|
|
3045 | $self |
|
|
3046 | } |
|
|
3047 | |
|
|
3048 | sub add { |
|
|
3049 | my ($self, $title, $widget, $tooltip) = @_; |
|
|
3050 | |
|
|
3051 | Scalar::Util::weaken $self; |
|
|
3052 | |
|
|
3053 | $self->{buttonbar}->add (new CFClient::UI::Button |
|
|
3054 | markup => $title, |
|
|
3055 | tooltip => $tooltip, |
|
|
3056 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3057 | ); |
|
|
3058 | |
|
|
3059 | $self->{multiplexer}->add ($widget); |
|
|
3060 | } |
|
|
3061 | |
|
|
3062 | sub set_current_page { |
|
|
3063 | my ($self, $page) = @_; |
|
|
3064 | |
|
|
3065 | $self->{multiplexer}->set_current_page ($page); |
|
|
3066 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
2933 | } |
3067 | } |
2934 | |
3068 | |
2935 | ############################################################################# |
3069 | ############################################################################# |
2936 | |
3070 | |
2937 | package CFClient::UI::Statusbox; |
3071 | package CFClient::UI::Statusbox; |
… | |
… | |
3050 | |
3184 | |
3051 | sub new { |
3185 | sub new { |
3052 | my $class = shift; |
3186 | my $class = shift; |
3053 | |
3187 | |
3054 | my $self = $class->SUPER::new ( |
3188 | my $self = $class->SUPER::new ( |
3055 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3189 | child => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3056 | @_, |
3190 | @_, |
3057 | ); |
3191 | ); |
3058 | |
3192 | |
3059 | $self |
3193 | $self |
3060 | } |
3194 | } |
3061 | |
3195 | |
3062 | sub set_items { |
3196 | sub set_items { |
3063 | my ($self, $items) = @_; |
3197 | my ($self, $items) = @_; |
3064 | |
3198 | |
3065 | $self->{scrolled}->clear; |
3199 | $self->{child}->clear; |
3066 | return unless $items; |
3200 | return unless $items; |
3067 | |
3201 | |
3068 | my @items = sort { |
3202 | my @items = sort { |
3069 | ($a->{type} <=> $b->{type}) |
3203 | ($a->{type} <=> $b->{type}) |
3070 | or ($a->{name} cmp $b->{name}) |
3204 | or ($a->{name} cmp $b->{name}) |
… | |
… | |
3074 | |
3208 | |
3075 | my $row = 0; |
3209 | my $row = 0; |
3076 | for my $item (@items) { |
3210 | for my $item (@items) { |
3077 | CFClient::Item::update_widgets $item; |
3211 | CFClient::Item::update_widgets $item; |
3078 | |
3212 | |
3079 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
3213 | $self->{child}->add (0, $row, $item->{face_widget}); |
3080 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
3214 | $self->{child}->add (1, $row, $item->{desc_widget}); |
3081 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
3215 | $self->{child}->add (2, $row, $item->{weight_widget}); |
3082 | |
3216 | |
3083 | $row++; |
3217 | $row++; |
3084 | } |
3218 | } |
3085 | } |
3219 | } |
3086 | |
3220 | |
… | |
… | |
3283 | |
3417 | |
3284 | ############################################################################# |
3418 | ############################################################################# |
3285 | |
3419 | |
3286 | package CFClient::UI::SpellList; |
3420 | package CFClient::UI::SpellList; |
3287 | |
3421 | |
3288 | our @ISA = CFClient::UI::FancyFrame::; |
3422 | our @ISA = CFClient::UI::Table::; |
3289 | |
3423 | |
3290 | sub new { |
3424 | sub new { |
3291 | my $class = shift; |
3425 | my $class = shift; |
3292 | |
3426 | |
3293 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
3427 | my $self = $class->SUPER::new ( |
3294 | |
3428 | binding => [], |
3295 | $self->add (new CFClient::UI::ScrolledWindow |
3429 | commands => [], |
3296 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
3430 | @_, |
3297 | |
3431 | ) |
3298 | $self; |
|
|
3299 | } |
3432 | } |
3300 | |
3433 | |
3301 | # XXX: Do sorting? Argl... |
3434 | # XXX: Do sorting? Argl... |
3302 | sub add_spell { |
3435 | sub add_spell { |
3303 | my ($self, $spell) = @_; |
3436 | my ($self, $spell) = @_; |
3304 | $self->{spells}->{$spell->{name}} = $spell; |
3437 | $self->{spells}->{$spell->{name}} = $spell; |
3305 | |
3438 | |
3306 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3439 | $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3307 | face => $spell->{face}, |
3440 | face => $spell->{face}, |
3308 | can_hover => 1, |
3441 | can_hover => 1, |
3309 | can_events => 1, |
3442 | can_events => 1, |
3310 | tooltip => $spell->{message}); |
3443 | tooltip => $spell->{message}); |
3311 | |
3444 | |
3312 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3445 | $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3313 | text => $spell->{name}, |
3446 | text => $spell->{name}, |
3314 | can_hover => 1, |
3447 | can_hover => 1, |
3315 | can_events => 1, |
3448 | can_events => 1, |
3316 | tooltip => $spell->{message}, |
3449 | tooltip => $spell->{message}, |
3317 | expand => 1); |
3450 | expand => 1); |
3318 | |
3451 | |
3319 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3452 | $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3320 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3453 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3321 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3454 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3322 | expand => 1); |
3455 | expand => 1); |
3323 | |
3456 | |
3324 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3457 | $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3325 | text => "bind to key", |
3458 | text => "bind to key", |
3326 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3459 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3327 | } |
3460 | } |
3328 | |
3461 | |
3329 | sub rebuild_spell_list { |
3462 | sub rebuild_spell_list { |