ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.270 by elmex, Fri Jun 2 09:02:49 2006 UTC vs.
Revision 1.272 by root, Sat Jun 3 01:47:14 2006 UTC

371sub size_allocate { 371sub size_allocate {
372 # nothing to be done 372 # nothing to be done
373} 373}
374 374
375sub children { 375sub children {
376 # nop
377}
378
379sub visible_children {
380 $_[0]->children
376} 381}
377 382
378sub set_max_size { 383sub set_max_size {
379 my ($self, $w, $h) = @_; 384 my ($self, $w, $h) = @_;
380 385
439 444
440 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus 445 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus
441 unless $FOCUS; 446 unless $FOCUS;
442} 447}
443 448
444sub mouse_motion { } 449sub mouse_motion { 0 }
445sub button_up { } 450sub button_up { 0 }
446sub key_down { } 451sub key_down { 0 }
447sub key_up { } 452sub key_up { 0 }
448 453
449sub button_down { 454sub button_down {
450 my ($self, $ev, $x, $y) = @_; 455 my ($self, $ev, $x, $y) = @_;
451 456
452 $self->focus_in; 457 $self->focus_in;
458
459 0
453} 460}
454 461
455sub find_widget { 462sub find_widget {
456 my ($self, $x, $y) = @_; 463 my ($self, $x, $y) = @_;
457 464
661our @ISA = CFClient::UI::Base::; 668our @ISA = CFClient::UI::Base::;
662 669
663sub new { 670sub new {
664 my ($class, %arg) = @_; 671 my ($class, %arg) = @_;
665 672
666 my $children = delete $arg{children} || []; 673 my $children = delete $arg{children};
667 674
668 my $self = $class->SUPER::new ( 675 my $self = $class->SUPER::new (
669 children => [], 676 children => [],
670 can_events => 0, 677 can_events => 0,
671 %arg, 678 %arg,
672 ); 679 );
680
673 $self->add ($_) for @$children; 681 $self->add (@$children)
682 if $children;
674 683
675 $self 684 $self
676} 685}
677 686
678sub add { 687sub add {
726 $x -= $self->{x}; 735 $x -= $self->{x};
727 $y -= $self->{y}; 736 $y -= $self->{y};
728 737
729 my $res; 738 my $res;
730 739
731 for (reverse @{ $self->{children} }) { 740 for (reverse $self->visible_children) {
732 $res = $_->find_widget ($x, $y) 741 $res = $_->find_widget ($x, $y)
733 and return $res; 742 and return $res;
734 } 743 }
735 744
736 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) 745 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
1157 1166
1158 ($x, $y) = ($ev->{x}, $ev->{y}); 1167 ($x, $y) = ($ev->{x}, $ev->{y});
1159 1168
1160 $self->move_abs ($bx + $x - $ox, $by + $y - $oy); 1169 $self->move_abs ($bx + $x - $ox, $by + $y - $oy);
1161 }; 1170 };
1171 } else {
1172 return 0;
1173 }
1174
1162 } 1175 1
1163} 1176}
1164 1177
1165sub button_up { 1178sub button_up {
1166 my ($self, $ev, $x, $y) = @_; 1179 my ($self, $ev, $x, $y) = @_;
1167 1180
1168 delete $self->{motion}; 1181 !!delete $self->{motion}
1169} 1182}
1170 1183
1171sub mouse_motion { 1184sub mouse_motion {
1172 my ($self, $ev, $x, $y) = @_; 1185 my ($self, $ev, $x, $y) = @_;
1173 1186
1174 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1187 $self->{motion}->($ev, $x, $y) if $self->{motion};
1188
1189 !!$self->{motion}
1175} 1190}
1176 1191
1177sub _draw { 1192sub _draw {
1178 my ($self) = @_; 1193 my ($self) = @_;
1179 1194
1709 $self->{cursor} = length $text; 1724 $self->{cursor} = length $text;
1710 } elsif ($uni == 27) { 1725 } elsif ($uni == 27) {
1711 $self->_emit ('escape'); 1726 $self->_emit ('escape');
1712 } elsif ($uni) { 1727 } elsif ($uni) {
1713 substr $text, $self->{cursor}++, 0, chr $uni; 1728 substr $text, $self->{cursor}++, 0, chr $uni;
1729 } else {
1730 return 0;
1714 } 1731 }
1715 1732
1716 $self->_set_text ($text); 1733 $self->_set_text ($text);
1717 1734
1718 $self->realloc; 1735 $self->realloc;
1736
1737 1
1719} 1738}
1720 1739
1721sub focus_in { 1740sub focus_in {
1722 my ($self) = @_; 1741 my ($self) = @_;
1723 1742
1738 utf8::encode $text; 1757 utf8::encode $text;
1739 $self->{cursor} = length substr $text, 0, $idx; 1758 $self->{cursor} = length substr $text, 0, $idx;
1740 1759
1741 $self->_set_text ($self->{text}); 1760 $self->_set_text ($self->{text});
1742 $self->update; 1761 $self->update;
1762
1763 1
1743} 1764}
1744 1765
1745sub mouse_motion { 1766sub mouse_motion {
1746 my ($self, $ev, $x, $y) = @_; 1767 my ($self, $ev, $x, $y) = @_;
1747# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# 1768# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
1769
1770 0
1748} 1771}
1749 1772
1750sub _draw { 1773sub _draw {
1751 my ($self) = @_; 1774 my ($self) = @_;
1752 1775
1829 } else { 1852 } else {
1830 $self->set_text ($self->{history_saveback}); 1853 $self->set_text ($self->{history_saveback});
1831 } 1854 }
1832 1855
1833 } else { 1856 } else {
1834 $self->SUPER::key_down ($ev); 1857 return $self->SUPER::key_down ($ev)
1858 }
1859
1835 } 1860 1
1836
1837} 1861}
1838 1862
1839############################################################################# 1863#############################################################################
1840 1864
1841package CFClient::UI::Button; 1865package CFClient::UI::Button;
1870 my ($self, $ev, $x, $y) = @_; 1894 my ($self, $ev, $x, $y) = @_;
1871 1895
1872 $self->emit ("activate") 1896 $self->emit ("activate")
1873 if $x >= 0 && $x < $self->{w} 1897 if $x >= 0 && $x < $self->{w}
1874 && $y >= 0 && $y < $self->{h}; 1898 && $y >= 0 && $y < $self->{h};
1899
1900 1
1875} 1901}
1876 1902
1877sub _draw { 1903sub _draw {
1878 my ($self) = @_; 1904 my ($self) = @_;
1879 1905
1933 1959
1934 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} 1960 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
1935 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { 1961 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
1936 $self->{state} = !$self->{state}; 1962 $self->{state} = !$self->{state};
1937 $self->_emit (changed => $self->{state}); 1963 $self->_emit (changed => $self->{state});
1964 } else {
1965 return 0
1966 }
1967
1938 } 1968 1
1939} 1969}
1940 1970
1941sub _draw { 1971sub _draw {
1942 my ($self) = @_; 1972 my ($self) = @_;
1943 1973
2281 2311
2282 $self->SUPER::button_down ($ev, $x, $y); 2312 $self->SUPER::button_down ($ev, $x, $y);
2283 2313
2284 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 2314 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2285 2315
2286 $self->mouse_motion ($ev, $x, $y); 2316 $self->mouse_motion ($ev, $x, $y)
2287} 2317}
2288 2318
2289sub mouse_motion { 2319sub mouse_motion {
2290 my ($self, $ev, $x, $y) = @_; 2320 my ($self, $ev, $x, $y) = @_;
2291 2321
2295 my (undef, $lo, $hi, $page) = @{$self->{range}}; 2325 my (undef, $lo, $hi, $page) = @{$self->{range}};
2296 2326
2297 $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); 2327 $x = ($x - $self->{click}[1]) / ($w * $self->{scale});
2298 2328
2299 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); 2329 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
2330 } else {
2331 return 0;
2332 }
2333
2300 } 2334 1
2301} 2335}
2302 2336
2303sub update { 2337sub update {
2304 my ($self) = @_; 2338 my ($self) = @_;
2305 2339
2827 $self->SUPER::DESTROY; 2861 $self->SUPER::DESTROY;
2828} 2862}
2829 2863
2830############################################################################# 2864#############################################################################
2831 2865
2866package CFClient::UI::Buttonbar;
2867
2868our @ISA = CFClient::UI::HBox::;
2869
2870# TODO: should actualyl wrap buttons and other goodies.
2871
2872#############################################################################
2873
2832package CFClient::UI::Menu; 2874package CFClient::UI::Menu;
2833 2875
2834our @ISA = CFClient::UI::FancyFrame::; 2876our @ISA = CFClient::UI::FancyFrame::;
2835 2877
2836use CFClient::OpenGL; 2878use CFClient::OpenGL;
2883 my ($self, $ev, $x, $y) = @_; 2925 my ($self, $ev, $x, $y) = @_;
2884 2926
2885 # TODO: should use vbox->find_widget or so 2927 # TODO: should use vbox->find_widget or so
2886 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); 2928 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2887 $self->{hover} = $self->{item}{$HOVER}; 2929 $self->{hover} = $self->{item}{$HOVER};
2930
2931 0
2888} 2932}
2889 2933
2890sub button_up { 2934sub button_up {
2891 my ($self, $ev, $x, $y) = @_; 2935 my ($self, $ev, $x, $y) = @_;
2892 2936
2894 undef $GRAB; 2938 undef $GRAB;
2895 $self->hide; 2939 $self->hide;
2896 2940
2897 $self->_emit ("popdown"); 2941 $self->_emit ("popdown");
2898 $self->{hover}[1]->() if $self->{hover}; 2942 $self->{hover}[1]->() if $self->{hover};
2943 } else {
2944 return 0
2945 }
2946
2899 } 2947 1
2948}
2949
2950#############################################################################
2951
2952package CFClient::UI::Multiplexer;
2953
2954our @ISA = CFClient::UI::Container::;
2955
2956sub new {
2957 my $class = shift;
2958
2959 my $self = $class->SUPER::new (
2960 @_,
2961 );
2962
2963 $self->{current} = $self->{children}[0]
2964 if @{ $self->{children} };
2965
2966 $self
2967}
2968
2969sub add {
2970 my ($self, @widgets) = @_;
2971
2972 $self->SUPER::add (@widgets);
2973
2974 $self->{current} = $self->{children}[0]
2975 if @{ $self->{children} };
2976}
2977
2978sub set_current_page {
2979 my ($self, $page_or_widget) = @_;
2980
2981 my $widget = ref $page_or_widget
2982 ? $page_or_widget
2983 : $self->{children}[$page_or_widget];
2984
2985 $self->{current} = $widget;
2986 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
2987
2988 $self->_emit (page_changed => $self->{current});
2989
2990 $self->realloc;
2991}
2992
2993sub visible_children {
2994 $_[0]{current}
2995}
2996
2997sub size_request {
2998 my ($self) = @_;
2999
3000 $self->{current}->size_request
3001}
3002
3003sub size_allocate {
3004 my ($self, $w, $h) = @_;
3005
3006 $self->{current}->configure (0, 0, $w, $h);
3007}
3008
3009sub _draw {
3010 my ($self) = @_;
3011
3012 $self->{current}->draw;
3013}
3014
3015#############################################################################
3016
3017package CFClient::UI::Notebook;
3018
3019our @ISA = CFClient::UI::VBox::;
3020
3021sub new {
3022 my $class = shift;
3023
3024 my $self = $class->SUPER::new (
3025 buttonbar => (new CFClient::UI::Buttonbar),
3026 multiplexer => (new CFClient::UI::Multiplexer expand => 1),
3027 @_,
3028 );
3029
3030 $self->SUPER::add ($self->{buttonbar}, $self->{multiplexer});
3031
3032 $self
3033}
3034
3035sub add {
3036 my ($self, $title, $widget, $tooltip) = @_;
3037
3038 Scalar::Util::weaken $self;
3039
3040 $self->{buttonbar}->add (new CFClient::UI::Button
3041 markup => $title,
3042 tooltip => $tooltip,
3043 on_activate => sub { $self->set_current_page ($widget) },
3044 );
3045
3046 $self->{multiplexer}->add ($widget);
3047}
3048
3049sub set_current_page {
3050 my ($self, $page) = @_;
3051
3052 $self->{multiplexer}->set_current_page ($page);
3053 $self->_emit (page_changed => $self->{multiplexer}{current});
2900} 3054}
2901 3055
2902############################################################################# 3056#############################################################################
2903 3057
2904package CFClient::UI::Statusbox; 3058package CFClient::UI::Statusbox;
3250 3404
3251############################################################################# 3405#############################################################################
3252 3406
3253package CFClient::UI::SpellList; 3407package CFClient::UI::SpellList;
3254 3408
3255our @ISA = CFClient::UI::FancyFrame::; 3409our @ISA = CFClient::UI::ScrolledWindow::;
3256 3410
3257sub new { 3411sub new {
3258 my $class = shift; 3412 my $class = shift;
3259 3413
3260 my $self = $class->SUPER::new (binding => [], commands => [], @_); 3414 my $self = $class->SUPER::new (
3261 3415 binding => [],
3262 $self->add (new CFClient::UI::ScrolledWindow 3416 commands => [],
3263 scrolled => $self->{spellbox} = new CFClient::UI::Table); 3417 scrolled => (new CFClient::UI::Table),
3264 3418 @_,
3265 $self; 3419 )
3266} 3420}
3267 3421
3268# XXX: Do sorting? Argl... 3422# XXX: Do sorting? Argl...
3269sub add_spell { 3423sub add_spell {
3270 my ($self, $spell) = @_; 3424 my ($self, $spell) = @_;
3271 $self->{spells}->{$spell->{name}} = $spell; 3425 $self->{spells}->{$spell->{name}} = $spell;
3272 3426
3273 $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face 3427 $self->{scrolled}->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3274 face => $spell->{face}, 3428 face => $spell->{face},
3275 can_hover => 1, 3429 can_hover => 1,
3276 can_events => 1, 3430 can_events => 1,
3277 tooltip => $spell->{message}); 3431 tooltip => $spell->{message});
3278 3432
3279 $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label 3433 $self->{scrolled}->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3280 text => $spell->{name}, 3434 text => $spell->{name},
3281 can_hover => 1, 3435 can_hover => 1,
3282 can_events => 1, 3436 can_events => 1,
3283 tooltip => $spell->{message}, 3437 tooltip => $spell->{message},
3284 expand => 1); 3438 expand => 1);
3285 3439
3286 $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label 3440 $self->{scrolled}->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3287 text => (sprintf "lvl: %2d sp: %2d dmg: %2d", 3441 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3288 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), 3442 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3289 expand => 1); 3443 expand => 1);
3290 3444
3291 $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button 3445 $self->{scrolled}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3292 text => "bind to key", 3446 text => "bind to key",
3293 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); 3447 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3294} 3448}
3295 3449
3296sub rebuild_spell_list { 3450sub rebuild_spell_list {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines