--- deliantra/Deliantra-Client/DC/UI.pm 2006/06/02 06:22:55 1.269 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/06/03 22:50:48 1.275 @@ -373,6 +373,11 @@ } sub children { + # nop +} + +sub visible_children { + $_[0]->children } sub set_max_size { @@ -441,15 +446,17 @@ unless $FOCUS; } -sub mouse_motion { } -sub button_up { } -sub key_down { } -sub key_up { } +sub mouse_motion { 0 } +sub button_up { 0 } +sub key_down { 0 } +sub key_up { 0 } sub button_down { my ($self, $ev, $x, $y) = @_; $self->focus_in; + + 0 } sub find_widget { @@ -663,14 +670,16 @@ sub new { my ($class, %arg) = @_; - my $children = delete $arg{children} || []; + my $children = delete $arg{children}; my $self = $class->SUPER::new ( children => [], can_events => 0, %arg, ); - $self->add ($_) for @$children; + + $self->add (@$children) + if $children; $self } @@ -728,7 +737,7 @@ my $res; - for (reverse @{ $self->{children} }) { + for (reverse $self->visible_children) { $res = $_->find_widget ($x, $y) and return $res; } @@ -787,6 +796,8 @@ ############################################################################# +# back-buffered drawing area + package CFClient::UI::Window; our @ISA = CFClient::UI::Bin::; @@ -948,7 +959,9 @@ our @ISA = CFClient::UI::HBox::; sub new { - my $class = shift; + my ($class, %arg) = @_; + + my $child = delete $arg{child}; my $self; @@ -963,16 +976,21 @@ $self = $class->SUPER::new ( vp => (new CFClient::UI::ViewPort expand => 1), slider => $slider, - @_, + %arg, ); - $self->{vp}->add ($self->{scrolled}); - $self->add ($self->{vp}); - $self->add ($self->{slider}); + $self->SUPER::add ($self->{vp}, $self->{slider}); + $self->add ($child) if $child; $self } +sub add { + my ($self, $widget) = @_; + + $self->{vp}->add ($self->{child} = $widget); +} + sub update { my ($self) = @_; @@ -1159,19 +1177,25 @@ $self->move_abs ($bx + $x - $ox, $by + $y - $oy); }; + } else { + return 0; } + + 1 } sub button_up { my ($self, $ev, $x, $y) = @_; - delete $self->{motion}; + !!delete $self->{motion} } sub mouse_motion { my ($self, $ev, $x, $y) = @_; $self->{motion}->($ev, $x, $y) if $self->{motion}; + + !!$self->{motion} } sub _draw { @@ -1711,11 +1735,15 @@ $self->_emit ('escape'); } elsif ($uni) { substr $text, $self->{cursor}++, 0, chr $uni; + } else { + return 0; } $self->_set_text ($text); $self->realloc; + + 1 } sub focus_in { @@ -1740,11 +1768,15 @@ $self->_set_text ($self->{text}); $self->update; + + 1 } sub mouse_motion { my ($self, $ev, $x, $y) = @_; # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# + + 0 } sub _draw { @@ -1831,9 +1863,10 @@ } } else { - $self->SUPER::key_down ($ev); + return $self->SUPER::key_down ($ev) } + 1 } ############################################################################# @@ -1872,6 +1905,8 @@ $self->emit ("activate") if $x >= 0 && $x < $self->{w} && $y >= 0 && $y < $self->{h}; + + 1 } sub _draw { @@ -1935,7 +1970,11 @@ && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { $self->{state} = !$self->{state}; $self->_emit (changed => $self->{state}); + } else { + return 0 } + + 1 } sub _draw { @@ -2283,7 +2322,7 @@ $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; - $self->mouse_motion ($ev, $x, $y); + $self->mouse_motion ($ev, $x, $y) } sub mouse_motion { @@ -2297,13 +2336,24 @@ $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); + } else { + return 0; } + + 1 } sub update { my ($self) = @_; - $CFClient::UI::ROOT->on_post_alloc ($self => sub { + delete $self->{knob_w}; + $self->SUPER::update; +} + +sub _draw { + my ($self) = @_; + + unless ($self->{knob_w}) { $self->set_value ($self->{range}[0]); my ($value, $lo, $hi, $page) = @{$self->{range}}; @@ -2319,13 +2369,7 @@ $self->{knob_x} = $value - $knob_w * 0.5; $self->{knob_w} = $knob_w; - }); - - $self->SUPER::update; -} - -sub _draw { - my ($self) = @_; + } $self->SUPER::_draw (); @@ -2829,6 +2873,14 @@ ############################################################################# +package CFClient::UI::Buttonbar; + +our @ISA = CFClient::UI::HBox::; + +# TODO: should actualyl wrap buttons and other goodies. + +############################################################################# + package CFClient::UI::Menu; our @ISA = CFClient::UI::FancyFrame::; @@ -2885,6 +2937,8 @@ # TODO: should use vbox->find_widget or so $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); $self->{hover} = $self->{item}{$HOVER}; + + 0 } sub button_up { @@ -2896,7 +2950,119 @@ $self->_emit ("popdown"); $self->{hover}[1]->() if $self->{hover}; + } else { + return 0 } + + 1 +} + +############################################################################# + +package CFClient::UI::Multiplexer; + +our @ISA = CFClient::UI::Container::; + +sub new { + my $class = shift; + + my $self = $class->SUPER::new ( + @_, + ); + + $self->{current} = $self->{children}[0] + if @{ $self->{children} }; + + $self +} + +sub add { + my ($self, @widgets) = @_; + + $self->SUPER::add (@widgets); + + $self->{current} = $self->{children}[0] + if @{ $self->{children} }; +} + +sub set_current_page { + my ($self, $page_or_widget) = @_; + + my $widget = ref $page_or_widget + ? $page_or_widget + : $self->{children}[$page_or_widget]; + + $self->{current} = $widget; + $self->{current}->configure (0, 0, $self->{w}, $self->{h}); + + $self->_emit (page_changed => $self->{current}); + + $self->realloc; +} + +sub visible_children { + $_[0]{current} +} + +sub size_request { + my ($self) = @_; + + $self->{current}->size_request +} + +sub size_allocate { + my ($self, $w, $h) = @_; + + $self->{current}->configure (0, 0, $w, $h); +} + +sub _draw { + my ($self) = @_; + + $self->{current}->draw; +} + +############################################################################# + +package CFClient::UI::Notebook; + +our @ISA = CFClient::UI::VBox::; + +sub new { + my $class = shift; + + my $self = $class->SUPER::new ( + buttonbar => (new CFClient::UI::Buttonbar), + multiplexer => (new CFClient::UI::Multiplexer expand => 1), + # filter => # will be put between multiplexer and $self + @_, + ); + + $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; + $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); + + $self +} + +sub add { + my ($self, $title, $widget, $tooltip) = @_; + + Scalar::Util::weaken $self; + + $self->{buttonbar}->add (new CFClient::UI::Button + markup => $title, + tooltip => $tooltip, + on_activate => sub { $self->set_current_page ($widget) }, + ); + + $self->{multiplexer}->add ($widget); +} + +sub set_current_page { + my ($self, $page) = @_; + + $self->{multiplexer}->set_current_page ($page); + $self->_emit (page_changed => $self->{multiplexer}{current}); } ############################################################################# @@ -3019,7 +3185,7 @@ my $class = shift; my $self = $class->SUPER::new ( - scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), + child => (new CFClient::UI::Table col_expand => [0, 1, 0]), @_, ); @@ -3029,7 +3195,7 @@ sub set_items { my ($self, $items) = @_; - $self->{scrolled}->clear; + $self->{child}->clear; return unless $items; my @items = sort { @@ -3043,9 +3209,9 @@ for my $item (@items) { CFClient::Item::update_widgets $item; - $self->{scrolled}->add (0, $row, $item->{face_widget}); - $self->{scrolled}->add (1, $row, $item->{desc_widget}); - $self->{scrolled}->add (2, $row, $item->{weight_widget}); + $self->{child}->add (0, $row, $item->{face_widget}); + $self->{child}->add (1, $row, $item->{desc_widget}); + $self->{child}->add (2, $row, $item->{weight_widget}); $row++; } @@ -3153,7 +3319,12 @@ $self->set_command_list ($rec); } -# if $commit is true, the binding will be set after the user entered a key combo + +sub ask_for_bind_and_commit { + my ($self) = @_; + $self->ask_for_bind (1); +} + sub ask_for_bind { my ($self, $commit) = @_; @@ -3247,17 +3418,16 @@ package CFClient::UI::SpellList; -our @ISA = CFClient::UI::FancyFrame::; +our @ISA = CFClient::UI::Table::; sub new { my $class = shift; - my $self = $class->SUPER::new (binding => [], commands => [], @_); - - $self->add (new CFClient::UI::ScrolledWindow - scrolled => $self->{spellbox} = new CFClient::UI::Table); - - $self; + my $self = $class->SUPER::new ( + binding => [], + commands => [], + @_, + ) } # XXX: Do sorting? Argl... @@ -3265,25 +3435,25 @@ my ($self, $spell) = @_; $self->{spells}->{$spell->{name}} = $spell; - $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face + $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face face => $spell->{face}, can_hover => 1, can_events => 1, tooltip => $spell->{message}); - $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label + $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label text => $spell->{name}, can_hover => 1, can_events => 1, tooltip => $spell->{message}, expand => 1); - $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label + $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label text => (sprintf "lvl: %2d sp: %2d dmg: %2d", $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), expand => 1); - $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button + $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button text => "bind to key", on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); }