--- deliantra/Deliantra-Client/DC/UI.pm 2006/05/12 00:16:34 1.196 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/05/12 01:47:04 1.197 @@ -36,6 +36,8 @@ } $TOOLTIP->move ($x, $y); + $TOOLTIP->check_size; + $TOOLTIP->update; } return; @@ -389,8 +391,9 @@ } sub check_size { - my ($self) = @_; + my ($self, $forced) = @_; + $self->{force_alloc} = 1 if $forced; $CFClient::UI::ROOT->{check_size}{$self} = $self; } @@ -510,7 +513,7 @@ @{$self->{children}}, @widgets ]; - $self->check_size; + $self->check_size (1); $self->update; } @@ -786,43 +789,6 @@ use CFClient::OpenGL; -sub new { - my $class = shift; - - my $self = $class->SUPER::new ( - bg => [1, 1, 1, 1], - border_bg => [1, 1, 1, 1], - border => 0.8, - @_ - ); - - $self -} - -sub _draw { - my ($self) = @_; - - my ($w, $h) = ($self->{w}, $self->{h}); - - glEnable GL_BLEND; - glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; - glEnable GL_TEXTURE_2D; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - -# glBegin GL_QUADS; -# glColor 0, 0, 0, 0; -# glVertex 0 , 0; -# glVertex 0 , $h; -# glVertex $w, $h; -# glVertex $w, 0; -# glEnd; - - - $self->child->draw; - glDisable GL_BLEND; - glDisable GL_TEXTURE_2D; -} - ############################################################################# package CFClient::UI::FancyFrame; @@ -946,18 +912,16 @@ my ($w, $h ) = ($self->{w}, $self->{h}); my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); - glEnable GL_BLEND; - glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; my $border = $self->border; glColor @{ $self->{border_bg} }; - $tex[1]->draw_quad (0, 0, $w, $border); - $tex[3]->draw_quad (0, $border, $border, $ch); - $tex[2]->draw_quad ($w - $border, $border, $border, $ch); - $tex[4]->draw_quad (0, $h - $border, $w, $border); + $tex[1]->draw_quad_alpha (0, 0, $w, $border); + $tex[3]->draw_quad_alpha (0, $border, $border, $ch); + $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); + $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border); if (@{$self->{bg}} < 4 || $self->{bg}[3]) { my $bg = $tex[0]; @@ -971,12 +935,11 @@ $bg->{s} = $rep_x; $bg->{t} = $rep_y; $bg->{wrap_mode} = 1; - $bg->draw_quad ($border, $border, $cw, $ch); - - glDisable GL_TEXTURE_2D; - glDisable GL_BLEND; + $bg->draw_quad_alpha ($border, $border, $cw, $ch); } + glDisable GL_TEXTURE_2D; + $self->{title}->draw if $self->{title}; $self->child->draw; @@ -1736,12 +1699,10 @@ glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; - glEnable GL_TEXTURE_2D; - my $tex = $self->{state} ? $tex[1] : $tex[0]; + glEnable GL_TEXTURE_2D; $tex->draw_quad_alpha (0, 0, $s, $s); - glDisable GL_TEXTURE_2D; } @@ -2371,14 +2332,13 @@ sub set_tooltip_from { my ($self, $widget) = @_; - $self->{label} = new CFClient::UI::Label + $self->add (new CFClient::UI::Label markup => $widget->{tooltip}, max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, fontsize => 0.8, fg => [0, 0, 0, 1], - font => ($widget->{tooltip_font} || $::FONT_PROP); - - $self->add ($self->{label}); + font => ($widget->{tooltip_font} || $::FONT_PROP), + ); } sub size_request { @@ -2398,7 +2358,6 @@ sub _draw { my ($self) = @_; - glPushMatrix; glTranslate 0.375, 0.375; my ($w, $h) = @$self{qw(w h)}; @@ -2419,9 +2378,7 @@ glVertex $w, 0; glEnd; - glPopMatrix; - - glTranslate 2, 2; + glTranslate 2 - 0.375, 2 - 0.375; $self->SUPER::_draw; } @@ -2658,54 +2615,74 @@ } my @widgets; - my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} }; + + my @items = sort { + $a->{pri} <=> $b->{pri} + or $b->{id} <=> $a->{id} + } values %{ $self->{item} }; + my $count = 10 + 1; for my $item (@items) { last unless --$count; push @widgets, $item->{label} ||= do { # TODO: doesn't handle markup well (read as: at all) - my $short = delete $item->{text}; + my $short = $item->{count} > 1 + ? "$item->{count} × $item->{text}" + : $item->{text}; + for ($short) { s/^\s+//; - s/\012.*//s; + s/\012.*/…/s; my $len = int 30 / $item->{fontsize}; substr $_, $len, length, "…" if $len < length; } new CFClient::UI::Label markup => $short, - tooltip => delete $item->{tooltip}, + tooltip => $item->{tooltip}, tooltip_font => $::FONT_PROP, - tooltip_width => 0.75, - fontsize => delete $item->{fontsize}, - color => delete $item->{color}, + tooltip_width => 0.67, + fontsize => $item->{fontsize}, + color => $item->{color}, can_events => 1, - can_hover => 1, + can_hover => 1 }; } $self->clear; - $self->SUPER::add (@widgets); + $self->SUPER::add (reverse @widgets); } sub add { my ($self, $text, %arg) = @_; - my $item = { - time => time, - text => $text, - timeout => 60, - tooltip => $text, - fontsize => 0.8, - color => [0.8, 0.8, 0.8, 0.8], - %arg, - }; + my $timeout = time + ((delete $arg{timeout}) || 60); - $item->{timeout} += time; - $item->{group} ||= $item+0; + my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; - $item = $self->{item}{$item->{group}} ||= $item; + if (my $item = $self->{item}{$group}) { + if ($item->{text} eq $text) { + $item->{count}++; + } else { + $item->{count} = 1; + $item->{text} = $item->{tooltip} = $text; + } + $item->{timeout} = $timeout; + delete $item->{label}; + } else { + $self->{item}{$group} = { + id => ++$self->{id}, + text => $text, + timeout => $timeout, + tooltip => $text, + fontsize => 0.8, + color => [0.8, 0.8, 0.8, 0.8], + pri => 0, + count => 1, + %arg, + }; + } $self->reorder; } @@ -2831,13 +2808,14 @@ ? @$widget{qw(user_w user_h)} : $widget->size_request; - if ($w != $widget->{req_w} || $h != $widget->{req_h}) { + if (delete $widget->{force_alloc} + or $w != $widget->{req_w} or $h != $widget->{req_h}) { Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# $widget->{req_w} = $w; $widget->{req_h} = $h; - $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; + $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; $widget->{parent}->check_size if $widget->{parent};