--- deliantra/Deliantra-Client/DC/UI.pm 2006/06/03 22:50:48 1.275 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/06/05 01:22:08 1.280 @@ -385,6 +385,8 @@ delete $self->{max_w}; $self->{max_w} = $w if $w; delete $self->{max_h}; $self->{max_h} = $h if $h; + + $self->realloc; } sub set_tooltip { @@ -550,20 +552,16 @@ glPushMatrix; glTranslate $self->{x}, $self->{y}, 0; - $self->_draw; - glPopMatrix; if ($self == $HOVER && $self->{can_hover}) { - my ($x, $y) = @$self{qw(x y)}; - - glColor 1, 0.8, 0.5, 0.2; + glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2; glEnable GL_BLEND; - glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; glBegin GL_QUADS; - glVertex $x , $y; - glVertex $x + $self->{w}, $y; - glVertex $x + $self->{w}, $y + $self->{h}; - glVertex $x , $y + $self->{h}; + glVertex 0 , 0; + glVertex $self->{w}, 0; + glVertex $self->{w}, $self->{h}; + glVertex 0 , $self->{h}; glEnd; glDisable GL_BLEND; } @@ -571,7 +569,7 @@ if ($ENV{CFPLUS_DEBUG} & 1) { glPushMatrix; glColor 1, 1, 0, 1; - glTranslate $self->{x} + 0.375, $self->{y} + 0.375; + glTranslate 0.375, 0.375; glBegin GL_LINE_LOOP; glVertex 0 , 0; glVertex $self->{w} - 1, 0; @@ -581,6 +579,9 @@ glPopMatrix; #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; } + + $self->_draw; + glPopMatrix; } sub _draw { @@ -628,8 +629,8 @@ my ($w, $h) = @$self{qw(w h)}; glEnable GL_BLEND; - glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; - glColor @$color; + glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; + glColor_premultiply @$color; glBegin GL_QUADS; glVertex 0 , 0; @@ -858,7 +859,7 @@ glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - glColor 1, 1, 1, 1; + glColor 0, 0, 0, 1; $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); @@ -1037,8 +1038,8 @@ my ($w, $h) = @$self{qw(w h)}; glEnable GL_BLEND; - glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; - glColor @{ $self->{bg} }; + glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; + glColor_premultiply @{ $self->{bg} }; glBegin GL_QUADS; glVertex 0 , 0; @@ -1162,8 +1163,8 @@ $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); $self->{force_h} = $bh + $dy * ($my ? -1 : 1); - $self->realloc; $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); + $self->realloc; }; } elsif ($lr ^ $td) { @@ -1176,6 +1177,8 @@ ($x, $y) = ($ev->{x}, $ev->{y}); $self->move_abs ($bx + $x - $ox, $by + $y - $oy); + # HACK: the next line is required to enforce placement + $self->{parent}->size_allocate ($self->{parent}{w}, $self->{parent}{h}); }; } else { return 0; @@ -1636,12 +1639,10 @@ glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - if ($tex->{format} == GL_ALPHA) { - glColor @{$self->{fg}}; - $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); - } else { - $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); - } + glColor_premultiply @{$self->{fg}} + if $tex->{format} == GL_ALPHA; + + $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); glDisable GL_TEXTURE_2D; } @@ -1678,8 +1679,6 @@ return if $self->{text} eq $text; - delete $self->{texture}; - $self->{last_activity} = $::NOW; $self->{text} = $text; @@ -1687,6 +1686,7 @@ $self->{layout}->set_text ("$text "); $self->_emit (changed => $self->{text}); + $self->update; } sub set_text { @@ -1785,14 +1785,14 @@ local $self->{fg} = $self->{fg}; if ($FOCUS == $self) { - glColor @{$self->{active_bg}}; + glColor_premultiply @{$self->{active_bg}}; $self->{fg} = $self->{active_fg}; } else { - glColor @{$self->{bg}}; + glColor_premultiply @{$self->{bg}}; } glEnable GL_BLEND; - glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; glBegin GL_QUADS; glVertex 0 , 0; glVertex 0 , $self->{h}; @@ -1912,11 +1912,7 @@ sub _draw { my ($self) = @_; - local $self->{fg} = $self->{fg}; - - if ($GRAB == $self) { - $self->{fg} = $self->{active_fg}; - } + local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg}; glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; @@ -2151,7 +2147,8 @@ my $h2 = $self->{h} * (1 - $ycut2); glEnable GL_BLEND; - glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + glBlendFuncSeparate GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, + GL_ONE, GL_ONE_MINUS_SRC_ALPHA; glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; @@ -2573,7 +2570,7 @@ } $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { - glClearColor 0.5, 0.5, 0.5, 0; + glClearColor 0, 0, 0, 0; glClear GL_COLOR_BUFFER_BIT; my $top = int $self->{children}[1]{range}[0]; @@ -2618,8 +2615,8 @@ glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - glColor 1, 1, 1, 1; - $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); + glColor 0, 0, 0, 1; + $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); glDisable GL_TEXTURE_2D; $self->{children}[1]->draw; @@ -2856,7 +2853,7 @@ if ($tex) { glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - glColor 1, 1, 1, 1; + glColor 0, 0, 0, 1; $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); glDisable GL_TEXTURE_2D; } @@ -3074,15 +3071,24 @@ sub new { my $class = shift; - $class->SUPER::new ( + my $self = $class->SUPER::new ( fontsize => 0.8, @_, - ) + ); + + Scalar::Util::weaken (my $this = $self); + + $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { + $this->reorder; + $this->update; + }); + + $self } sub reorder { my ($self) = @_; - my $NOW = time; + my $NOW = Time::HiRes::time; while (my ($k, $v) = each %{ $self->{item} }) { delete $self->{item}{$k} if $v->{timeout} < $NOW; @@ -3095,6 +3101,8 @@ or $b->{id} <=> $a->{id} } values %{ $self->{item} }; + $self->{timer}->interval (1); + my $count = 10 + 1; for my $item (@items) { last unless --$count; @@ -3118,9 +3126,20 @@ fontsize => $item->{fontsize} || $self->{fontsize}, max_w => $::WIDTH * 0.44, fg => $item->{fg}, + orig_alpha => $item->{fg}[3] || 1, can_events => 1, can_hover => 1 }; + + if ((my $diff = $item->{timeout} - $NOW) < 2) { + $item->{label}{fg}[3] = $item->{label}{orig_alpha} * $diff / 2; + if ($diff < 1) { + $item->{label}{max_h} = $item->{label}{req_h} * $diff; + $item->{label}->realloc; + } + $item->{label}->update; + $self->{timer}->interval (1/30); + } } $self->clear; @@ -3135,7 +3154,7 @@ return unless $text; - my $timeout = time + ((delete $arg{timeout}) || 60); + my $timeout = (int time) + ((delete $arg{timeout}) || 60); my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; @@ -3175,6 +3194,14 @@ $self->SUPER::reconfigure; } +sub DESTROY { + my ($self) = @_; + + $self->{timer}->cancel; + + $self->SUPER::DESTROY; +} + ############################################################################# package CFClient::UI::Inventory; @@ -3476,6 +3503,8 @@ our @ISA = CFClient::UI::Container::; +use List::Util qw(min max); + use CFClient::OpenGL; sub new { @@ -3619,8 +3648,11 @@ my ($w, $h) = $widget->size_request; - $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; - $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; + $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; + $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; + + $w = min $widget->{max_w}, $w if exists $widget->{max_w}; + $h = min $widget->{max_h}, $h if exists $widget->{max_h}; $w = $widget->{force_w} if exists $widget->{force_w}; $h = $widget->{force_h} if exists $widget->{force_h};