--- deliantra/Deliantra-Client/DC/UI.pm 2006/06/02 22:13:47 1.271 +++ 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 { @@ -665,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 } @@ -730,7 +737,7 @@ my $res; - for (reverse @{ $self->{children} }) { + for (reverse $self->visible_children) { $res = $_->find_widget ($x, $y) and return $res; } @@ -789,6 +796,8 @@ ############################################################################# +# back-buffered drawing area + package CFClient::UI::Window; our @ISA = CFClient::UI::Bin::; @@ -950,7 +959,9 @@ our @ISA = CFClient::UI::HBox::; sub new { - my $class = shift; + my ($class, %arg) = @_; + + my $child = delete $arg{child}; my $self; @@ -965,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) = @_; @@ -2330,7 +2346,14 @@ 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}}; @@ -2346,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 (); @@ -2856,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::; @@ -2934,6 +2959,114 @@ ############################################################################# +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}); +} + +############################################################################# + package CFClient::UI::Statusbox; our @ISA = CFClient::UI::VBox::; @@ -3052,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]), @_, ); @@ -3062,7 +3195,7 @@ sub set_items { my ($self, $items) = @_; - $self->{scrolled}->clear; + $self->{child}->clear; return unless $items; my @items = sort { @@ -3076,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++; } @@ -3285,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... @@ -3303,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}"]) }); }