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.273 by root, Sat Jun 3 02:32:35 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})
946package CFClient::UI::ScrolledWindow; 955package CFClient::UI::ScrolledWindow;
947 956
948our @ISA = CFClient::UI::HBox::; 957our @ISA = CFClient::UI::HBox::;
949 958
950sub new { 959sub new {
951 my $class = shift; 960 my ($class, %arg) = @_;
961
962 my $child = delete $arg{child};
952 963
953 my $self; 964 my $self;
954 965
955 my $slider = new CFClient::UI::Slider 966 my $slider = new CFClient::UI::Slider
956 vertical => 1, 967 vertical => 1,
961 ; 972 ;
962 973
963 $self = $class->SUPER::new ( 974 $self = $class->SUPER::new (
964 vp => (new CFClient::UI::ViewPort expand => 1), 975 vp => (new CFClient::UI::ViewPort expand => 1),
965 slider => $slider, 976 slider => $slider,
966 @_, 977 %arg,
967 ); 978 );
968 979
969 $self->{vp}->add ($self->{scrolled});
970 $self->add ($self->{vp});
971 $self->add ($self->{slider}); 980 $self->SUPER::add ($self->{vp}, $self->{slider});
981 $self->add ($child) if $child;
972 982
973 $self 983 $self
984}
985
986sub add {
987 my ($self, $widget) = @_;
988
989 $self->{vp}->add ($self->{child} = $widget);
974} 990}
975 991
976sub update { 992sub update {
977 my ($self) = @_; 993 my ($self) = @_;
978 994
1157 1173
1158 ($x, $y) = ($ev->{x}, $ev->{y}); 1174 ($x, $y) = ($ev->{x}, $ev->{y});
1159 1175
1160 $self->move_abs ($bx + $x - $ox, $by + $y - $oy); 1176 $self->move_abs ($bx + $x - $ox, $by + $y - $oy);
1161 }; 1177 };
1178 } else {
1179 return 0;
1180 }
1181
1162 } 1182 1
1163} 1183}
1164 1184
1165sub button_up { 1185sub button_up {
1166 my ($self, $ev, $x, $y) = @_; 1186 my ($self, $ev, $x, $y) = @_;
1167 1187
1168 delete $self->{motion}; 1188 !!delete $self->{motion}
1169} 1189}
1170 1190
1171sub mouse_motion { 1191sub mouse_motion {
1172 my ($self, $ev, $x, $y) = @_; 1192 my ($self, $ev, $x, $y) = @_;
1173 1193
1174 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1194 $self->{motion}->($ev, $x, $y) if $self->{motion};
1195
1196 !!$self->{motion}
1175} 1197}
1176 1198
1177sub _draw { 1199sub _draw {
1178 my ($self) = @_; 1200 my ($self) = @_;
1179 1201
1709 $self->{cursor} = length $text; 1731 $self->{cursor} = length $text;
1710 } elsif ($uni == 27) { 1732 } elsif ($uni == 27) {
1711 $self->_emit ('escape'); 1733 $self->_emit ('escape');
1712 } elsif ($uni) { 1734 } elsif ($uni) {
1713 substr $text, $self->{cursor}++, 0, chr $uni; 1735 substr $text, $self->{cursor}++, 0, chr $uni;
1736 } else {
1737 return 0;
1714 } 1738 }
1715 1739
1716 $self->_set_text ($text); 1740 $self->_set_text ($text);
1717 1741
1718 $self->realloc; 1742 $self->realloc;
1743
1744 1
1719} 1745}
1720 1746
1721sub focus_in { 1747sub focus_in {
1722 my ($self) = @_; 1748 my ($self) = @_;
1723 1749
1738 utf8::encode $text; 1764 utf8::encode $text;
1739 $self->{cursor} = length substr $text, 0, $idx; 1765 $self->{cursor} = length substr $text, 0, $idx;
1740 1766
1741 $self->_set_text ($self->{text}); 1767 $self->_set_text ($self->{text});
1742 $self->update; 1768 $self->update;
1769
1770 1
1743} 1771}
1744 1772
1745sub mouse_motion { 1773sub mouse_motion {
1746 my ($self, $ev, $x, $y) = @_; 1774 my ($self, $ev, $x, $y) = @_;
1747# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# 1775# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
1776
1777 0
1748} 1778}
1749 1779
1750sub _draw { 1780sub _draw {
1751 my ($self) = @_; 1781 my ($self) = @_;
1752 1782
1829 } else { 1859 } else {
1830 $self->set_text ($self->{history_saveback}); 1860 $self->set_text ($self->{history_saveback});
1831 } 1861 }
1832 1862
1833 } else { 1863 } else {
1834 $self->SUPER::key_down ($ev); 1864 return $self->SUPER::key_down ($ev)
1865 }
1866
1835 } 1867 1
1836
1837} 1868}
1838 1869
1839############################################################################# 1870#############################################################################
1840 1871
1841package CFClient::UI::Button; 1872package CFClient::UI::Button;
1870 my ($self, $ev, $x, $y) = @_; 1901 my ($self, $ev, $x, $y) = @_;
1871 1902
1872 $self->emit ("activate") 1903 $self->emit ("activate")
1873 if $x >= 0 && $x < $self->{w} 1904 if $x >= 0 && $x < $self->{w}
1874 && $y >= 0 && $y < $self->{h}; 1905 && $y >= 0 && $y < $self->{h};
1906
1907 1
1875} 1908}
1876 1909
1877sub _draw { 1910sub _draw {
1878 my ($self) = @_; 1911 my ($self) = @_;
1879 1912
1933 1966
1934 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} 1967 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
1935 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { 1968 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
1936 $self->{state} = !$self->{state}; 1969 $self->{state} = !$self->{state};
1937 $self->_emit (changed => $self->{state}); 1970 $self->_emit (changed => $self->{state});
1971 } else {
1972 return 0
1973 }
1974
1938 } 1975 1
1939} 1976}
1940 1977
1941sub _draw { 1978sub _draw {
1942 my ($self) = @_; 1979 my ($self) = @_;
1943 1980
2281 2318
2282 $self->SUPER::button_down ($ev, $x, $y); 2319 $self->SUPER::button_down ($ev, $x, $y);
2283 2320
2284 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 2321 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2285 2322
2286 $self->mouse_motion ($ev, $x, $y); 2323 $self->mouse_motion ($ev, $x, $y)
2287} 2324}
2288 2325
2289sub mouse_motion { 2326sub mouse_motion {
2290 my ($self, $ev, $x, $y) = @_; 2327 my ($self, $ev, $x, $y) = @_;
2291 2328
2295 my (undef, $lo, $hi, $page) = @{$self->{range}}; 2332 my (undef, $lo, $hi, $page) = @{$self->{range}};
2296 2333
2297 $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); 2334 $x = ($x - $self->{click}[1]) / ($w * $self->{scale});
2298 2335
2299 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); 2336 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
2337 } else {
2338 return 0;
2339 }
2340
2300 } 2341 1
2301} 2342}
2302 2343
2303sub update { 2344sub update {
2304 my ($self) = @_; 2345 my ($self) = @_;
2305 2346
2827 $self->SUPER::DESTROY; 2868 $self->SUPER::DESTROY;
2828} 2869}
2829 2870
2830############################################################################# 2871#############################################################################
2831 2872
2873package CFClient::UI::Buttonbar;
2874
2875our @ISA = CFClient::UI::HBox::;
2876
2877# TODO: should actualyl wrap buttons and other goodies.
2878
2879#############################################################################
2880
2832package CFClient::UI::Menu; 2881package CFClient::UI::Menu;
2833 2882
2834our @ISA = CFClient::UI::FancyFrame::; 2883our @ISA = CFClient::UI::FancyFrame::;
2835 2884
2836use CFClient::OpenGL; 2885use CFClient::OpenGL;
2883 my ($self, $ev, $x, $y) = @_; 2932 my ($self, $ev, $x, $y) = @_;
2884 2933
2885 # TODO: should use vbox->find_widget or so 2934 # TODO: should use vbox->find_widget or so
2886 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); 2935 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2887 $self->{hover} = $self->{item}{$HOVER}; 2936 $self->{hover} = $self->{item}{$HOVER};
2937
2938 0
2888} 2939}
2889 2940
2890sub button_up { 2941sub button_up {
2891 my ($self, $ev, $x, $y) = @_; 2942 my ($self, $ev, $x, $y) = @_;
2892 2943
2894 undef $GRAB; 2945 undef $GRAB;
2895 $self->hide; 2946 $self->hide;
2896 2947
2897 $self->_emit ("popdown"); 2948 $self->_emit ("popdown");
2898 $self->{hover}[1]->() if $self->{hover}; 2949 $self->{hover}[1]->() if $self->{hover};
2950 } else {
2951 return 0
2952 }
2953
2954 1
2955}
2956
2957#############################################################################
2958
2959package CFClient::UI::Multiplexer;
2960
2961our @ISA = CFClient::UI::Container::;
2962
2963sub new {
2964 my $class = shift;
2965
2966 my $self = $class->SUPER::new (
2967 @_,
2968 );
2969
2970 $self->{current} = $self->{children}[0]
2971 if @{ $self->{children} };
2972
2973 $self
2974}
2975
2976sub add {
2977 my ($self, @widgets) = @_;
2978
2979 $self->SUPER::add (@widgets);
2980
2981 $self->{current} = $self->{children}[0]
2982 if @{ $self->{children} };
2983}
2984
2985sub set_current_page {
2986 my ($self, $page_or_widget) = @_;
2987
2988 my $widget = ref $page_or_widget
2989 ? $page_or_widget
2990 : $self->{children}[$page_or_widget];
2991
2992 $self->{current} = $widget;
2993 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
2994
2995 $self->_emit (page_changed => $self->{current});
2996
2997 $self->realloc;
2998}
2999
3000sub visible_children {
3001 $_[0]{current}
3002}
3003
3004sub size_request {
3005 my ($self) = @_;
3006
3007 $self->{current}->size_request
3008}
3009
3010sub size_allocate {
3011 my ($self, $w, $h) = @_;
3012
3013 $self->{current}->configure (0, 0, $w, $h);
3014}
3015
3016sub _draw {
3017 my ($self) = @_;
3018
3019 $self->{current}->draw;
3020}
3021
3022#############################################################################
3023
3024package CFClient::UI::Notebook;
3025
3026our @ISA = CFClient::UI::VBox::;
3027
3028sub new {
3029 my $class = shift;
3030
3031 my $self = $class->SUPER::new (
3032 buttonbar => (new CFClient::UI::Buttonbar),
3033 multiplexer => (new CFClient::UI::Multiplexer expand => 1),
3034 # filter => # will be put between multiplexer and $self
3035 @_,
3036 );
2899 } 3037
3038 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3039 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3040
3041 $self
3042}
3043
3044sub add {
3045 my ($self, $title, $widget, $tooltip) = @_;
3046
3047 Scalar::Util::weaken $self;
3048
3049 $self->{buttonbar}->add (new CFClient::UI::Button
3050 markup => $title,
3051 tooltip => $tooltip,
3052 on_activate => sub { $self->set_current_page ($widget) },
3053 );
3054
3055 $self->{multiplexer}->add ($widget);
3056}
3057
3058sub set_current_page {
3059 my ($self, $page) = @_;
3060
3061 $self->{multiplexer}->set_current_page ($page);
3062 $self->_emit (page_changed => $self->{multiplexer}{current});
2900} 3063}
2901 3064
2902############################################################################# 3065#############################################################################
2903 3066
2904package CFClient::UI::Statusbox; 3067package CFClient::UI::Statusbox;
3017 3180
3018sub new { 3181sub new {
3019 my $class = shift; 3182 my $class = shift;
3020 3183
3021 my $self = $class->SUPER::new ( 3184 my $self = $class->SUPER::new (
3022 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), 3185 child => (new CFClient::UI::Table col_expand => [0, 1, 0]),
3023 @_, 3186 @_,
3024 ); 3187 );
3025 3188
3026 $self 3189 $self
3027} 3190}
3028 3191
3029sub set_items { 3192sub set_items {
3030 my ($self, $items) = @_; 3193 my ($self, $items) = @_;
3031 3194
3032 $self->{scrolled}->clear; 3195 $self->{child}->clear;
3033 return unless $items; 3196 return unless $items;
3034 3197
3035 my @items = sort { 3198 my @items = sort {
3036 ($a->{type} <=> $b->{type}) 3199 ($a->{type} <=> $b->{type})
3037 or ($a->{name} cmp $b->{name}) 3200 or ($a->{name} cmp $b->{name})
3041 3204
3042 my $row = 0; 3205 my $row = 0;
3043 for my $item (@items) { 3206 for my $item (@items) {
3044 CFClient::Item::update_widgets $item; 3207 CFClient::Item::update_widgets $item;
3045 3208
3046 $self->{scrolled}->add (0, $row, $item->{face_widget}); 3209 $self->{child}->add (0, $row, $item->{face_widget});
3047 $self->{scrolled}->add (1, $row, $item->{desc_widget}); 3210 $self->{child}->add (1, $row, $item->{desc_widget});
3048 $self->{scrolled}->add (2, $row, $item->{weight_widget}); 3211 $self->{child}->add (2, $row, $item->{weight_widget});
3049 3212
3050 $row++; 3213 $row++;
3051 } 3214 }
3052} 3215}
3053 3216
3250 3413
3251############################################################################# 3414#############################################################################
3252 3415
3253package CFClient::UI::SpellList; 3416package CFClient::UI::SpellList;
3254 3417
3255our @ISA = CFClient::UI::FancyFrame::; 3418our @ISA = CFClient::UI::Table::;
3256 3419
3257sub new { 3420sub new {
3258 my $class = shift; 3421 my $class = shift;
3259 3422
3260 my $self = $class->SUPER::new (binding => [], commands => [], @_); 3423 my $self = $class->SUPER::new (
3261 3424 binding => [],
3262 $self->add (new CFClient::UI::ScrolledWindow 3425 commands => [],
3263 scrolled => $self->{spellbox} = new CFClient::UI::Table); 3426 @_,
3264 3427 )
3265 $self;
3266} 3428}
3267 3429
3268# XXX: Do sorting? Argl... 3430# XXX: Do sorting? Argl...
3269sub add_spell { 3431sub add_spell {
3270 my ($self, $spell) = @_; 3432 my ($self, $spell) = @_;
3271 $self->{spells}->{$spell->{name}} = $spell; 3433 $self->{spells}->{$spell->{name}} = $spell;
3272 3434
3273 $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face 3435 $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3274 face => $spell->{face}, 3436 face => $spell->{face},
3275 can_hover => 1, 3437 can_hover => 1,
3276 can_events => 1, 3438 can_events => 1,
3277 tooltip => $spell->{message}); 3439 tooltip => $spell->{message});
3278 3440
3279 $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label 3441 $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3280 text => $spell->{name}, 3442 text => $spell->{name},
3281 can_hover => 1, 3443 can_hover => 1,
3282 can_events => 1, 3444 can_events => 1,
3283 tooltip => $spell->{message}, 3445 tooltip => $spell->{message},
3284 expand => 1); 3446 expand => 1);
3285 3447
3286 $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label 3448 $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3287 text => (sprintf "lvl: %2d sp: %2d dmg: %2d", 3449 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3288 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), 3450 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3289 expand => 1); 3451 expand => 1);
3290 3452
3291 $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button 3453 $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3292 text => "bind to key", 3454 text => "bind to key",
3293 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); 3455 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3294} 3456}
3295 3457
3296sub rebuild_spell_list { 3458sub rebuild_spell_list {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines