--- deliantra/Deliantra-Client/DC/UI.pm 2006/06/26 21:59:04 1.314 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/07/17 01:41:53 1.327 @@ -425,10 +425,9 @@ return if $FOCUS == $self; return unless $self->{can_focus}; - my $focus = $FOCUS; $FOCUS = $self; + $FOCUS = $self; - $focus->update if $focus; - $FOCUS->update; + $self->update; 0 } @@ -438,9 +437,9 @@ return unless $FOCUS == $self; - my $focus = $FOCUS; undef $FOCUS; + undef $FOCUS; - $focus->update if $focus; #? + $self->update; $::MAPWIDGET->grab_focus #d# focus mapwidget if no other widget has focus unless $FOCUS; @@ -451,6 +450,7 @@ sub grab_focus { my ($self) = @_; + $FOCUS->emit ("focus_out") if $FOCUS; $self->emit ("focus_in"); } @@ -589,6 +589,8 @@ sub DESTROY { my ($self) = @_; + return if CFClient::in_destruct; + delete $WIDGET{$self+0}; eval { $self->destroy }; @@ -1082,8 +1084,8 @@ border_bg => [1, 1, 1, 1], border => 0.6, can_events => 1, - min_w => 16, - min_h => 16, + min_w => 64, + min_h => 32, %arg, ); @@ -1098,7 +1100,7 @@ $self->{close_button} = new CFClient::UI::ImageButton path => 'x1_close.png', - on_activate => sub { $self->hide }; + on_activate => sub { $self->emit ("delete") }; $self->CFClient::UI::Container::add ($self->{close_button}); } @@ -1157,6 +1159,14 @@ 1 } +sub invoke_delete { + my ($self) = @_; + + $self->hide; + + 1 +} + sub invoke_button_down { my ($self, $ev, $x, $y) = @_; @@ -1585,7 +1595,6 @@ return if $self->{text} eq "T$text"; $self->{text} = "T$text"; - $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; $self->{layout}->set_text ($text); delete $self->{size_req}; @@ -1601,7 +1610,6 @@ my $rgba = $markup =~ /span.*(?:foreground|background)/; - $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; $self->{layout}->set_markup ($markup); delete $self->{size_req}; @@ -1623,6 +1631,7 @@ if (exists $self->{template}) { $self->{template}->set_font ($self->{font}) if $self->{font}; + $self->{template}->set_width ($self->{max_w} || -1); $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); my ($w2, $h2) = $self->{template}->size; @@ -1656,6 +1665,7 @@ my ($self, $fontsize) = @_; $self->{fontsize} = $fontsize; + delete $self->{size_req}; delete $self->{texture}; $self->realloc; @@ -1665,6 +1675,7 @@ my ($self) = @_; delete $self->{size_req}; + delete $self->{texture}; $self->SUPER::reconfigure; } @@ -1674,7 +1685,7 @@ $self->SUPER::_draw; # draw background, if applicable - my $tex = $self->{texture} ||= do { + my $size = $self->{texture} ||= do { $self->{layout}->set_foreground (@{$self->{fg}}); $self->{layout}->set_font ($self->{font}) if $self->{font}; $self->{layout}->set_width ($self->{w}); @@ -1682,34 +1693,23 @@ $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); - new_from_layout CFClient::Texture $self->{layout} + [$self->{layout}->size] }; unless (exists $self->{ox}) { $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} - : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} - : ($self->{w} - $tex->{w}) * 0.5); + : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} + : ($self->{w} - $size->[0]) * 0.5); $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} - : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} - : ($self->{h} - $tex->{h}) * 0.5); + : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} + : ($self->{h} - $size->[1]) * 0.5); }; - glEnable GL_TEXTURE_2D; - - my $w = List::Util::min $self->{w} + 4, $tex->{w}; - my $h = List::Util::min $self->{h} + 2, $tex->{h}; + my $w = List::Util::min $self->{w} + 4, $size->[0]; + my $h = List::Util::min $self->{h} + 2, $size->[1]; - if ($tex->{format} == GL_ALPHA) { - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; - glColor @{$self->{fg}}; - $tex->draw_quad_alpha ($self->{ox}, $self->{oy}, $w, $h); - } else { - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}, $w, $h); - } - - glDisable GL_TEXTURE_2D; + $self->{layout}->render ($self->{ox}, $self->{oy}); } ############################################################################# @@ -1830,8 +1830,8 @@ # byte-index to char-index my $text = $self->{text}; - utf8::encode $text; - $self->{cursor} = length substr $text, 0, $idx; + utf8::encode $text; $text = substr $text, 0, $idx; utf8::decode $text; + $self->{cursor} = length $text; $self->_set_text ($self->{text}); $self->update; @@ -2061,13 +2061,20 @@ (6) x 2 } +sub toggle { + my ($self) = @_; + + $self->{state} = !$self->{state}; + $self->emit (changed => $self->{state}); + $self->update; +} + sub invoke_button_down { my ($self, $ev, $x, $y) = @_; if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { - $self->{state} = !$self->{state}; - $self->emit (changed => $self->{state}); + $self->toggle; } else { return 0 } @@ -2113,10 +2120,10 @@ @_, ); - $self->{path} - or Carp::croak "required attribute 'path' not set"; + $self->{path} || $self->{tex} + or Carp::croak "'path' or 'tex' attributes required"; - $self->{tex} = $texture_cache{$self->{path}} ||= + $self->{tex} ||= $texture_cache{$self->{path}} ||= new_from_file CFClient::Texture CFClient::find_rcfile $self->{path}, mipmap => 1; Scalar::Util::weaken $texture_cache{$self->{path}}; @@ -2248,6 +2255,9 @@ my $h1 = $self->{h} * (1 - $ycut1); my $h2 = $self->{h} * (1 - $ycut2); + my $h3 = $self->{h}; + + $_ = $_ * (284-4)/288 + 4/288 for ($h1, $h2, $h3); glEnable GL_BLEND; glBlendFuncSeparate GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, @@ -2276,8 +2286,8 @@ glBindTexture GL_TEXTURE_2D, $t3->{name}; glBegin GL_QUADS; glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2; - glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h}; - glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h}; + glTexCoord 0 , $t3->{t}; glVertex 0 , $h3; + glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $h3; glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2; glEnd; } @@ -2556,7 +2566,7 @@ #font => default_font @_, - layout => (new CFClient::Layout 1), + layout => (new CFClient::Layout), par => [], height => 0, children => [ @@ -2727,10 +2737,6 @@ my $y = 0; - glEnable GL_BLEND; - #TODO# not correct in windows where rgba is forced off - glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; - for my $para (@{$self->{par}}) { my $h = $para->{h}; @@ -2738,15 +2744,11 @@ my $layout = $self->get_layout ($para); - my ($w, $h, $data, $format, $internalformat) = $layout->render; - - glRasterPos $para->{indent}, $y - $y0; - glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data; + $layout->render ($para->{indent}, $y - $y0); if (my @w = @{ $para->{widget} }) { my @s = $layout->get_shapes; - glDisable GL_BLEND; for (@w) { my ($dx, $dy) = splice @s, 0, 2, (); @@ -2755,15 +2757,11 @@ $_->draw; } - glEnable GL_BLEND; - glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; } } $y += $h; } - - glDisable GL_BLEND; }; }); } @@ -3069,11 +3067,26 @@ # handle various types of items, only text for now if (!ref $widget) { - $widget = new CFClient::UI::Label - can_hover => 1, - can_events => 1, - markup => $widget, - tooltip => $tooltip + if ($widget =~ /\t/) { + my ($left, $right) = split /\t/, $widget, 2; + + $widget = new CFClient::UI::HBox + can_hover => 1, + can_events => 1, + tooltip => $tooltip, + children => [ + (new CFClient::UI::Label markup => $left, expand => 1), + (new CFClient::UI::Label markup => $right, align => +1), + ], + ; + + } else { + $widget = new CFClient::UI::Label + can_hover => 1, + can_events => 1, + markup => $widget, + tooltip => $tooltip; + } } $self->{item}{$widget} = $item; @@ -3152,6 +3165,12 @@ if @{ $self->{children} }; } +sub get_current_page { + my ($self) = @_; + + $self->{current} +} + sub set_current_page { my ($self, $page_or_widget) = @_; @@ -3227,6 +3246,12 @@ $self->{multiplexer}->add ($widget); } +sub get_current_page { + my ($self) = @_; + + $self->{multiplexer}->get_current_page +} + sub set_current_page { my ($self, $page) = @_; @@ -3412,7 +3437,9 @@ }; } - $self->reorder; + $ROOT->on_refresh (reorder => sub { + $self->reorder; + }); } sub reconfigure { @@ -3437,13 +3464,13 @@ package CFClient::UI::Inventory; -our @ISA = CFClient::UI::ScrolledWindow::; +our @ISA = CFClient::UI::Table::; sub new { my $class = shift; my $self = $class->SUPER::new ( - child => (new CFClient::UI::Table col_expand => [0, 1, 0]), + col_expand => [0, 1, 0], @_, ); @@ -3453,13 +3480,13 @@ sub set_items { my ($self, $items) = @_; - $self->{child}->clear; + $self->clear; return unless $items; my @items = sort { ($a->{type} <=> $b->{type}) or ($a->{name} cmp $b->{name}) - } @$items; + } values %$items; $self->{real_items} = \@items; @@ -3467,9 +3494,9 @@ for my $item (@items) { CFClient::Item::update_widgets $item; - $self->{child}->add (0, $row, $item->{face_widget}); - $self->{child}->add (1, $row, $item->{desc_widget}); - $self->{child}->add (2, $row, $item->{weight_widget}); + $self->add (0, $row, $item->{face_widget}); + $self->add (1, $row, $item->{desc_widget}); + $self->add (2, $row, $item->{weight_widget}); $row++; } @@ -3791,6 +3818,12 @@ $w = 0 if $w < 0; $h = 0 if $h < 0; + $w = max $widget->{min_w}, $w; + $h = max $widget->{min_h}, $h; + + $w = min $widget->{max_w}, $w if exists $widget->{max_w}; + $h = min $widget->{max_h}, $h if exists $widget->{max_h}; + $w = int $w + 0.5; $h = int $h + 0.5;