--- deliantra/Deliantra-Client/DC/UI.pm 2009/01/11 22:15:23 1.475 +++ deliantra/Deliantra-Client/DC/UI.pm 2011/08/13 23:18:19 1.482 @@ -1,10 +1,10 @@ package DC::UI; -use utf8; -use strict; +use common::sense; use List::Util (); +use AnyEvent (); use Guard (); use DC; @@ -225,7 +225,7 @@ package DC::UI::Base; -use strict; +use common::sense; use DC::OpenGL; @@ -645,7 +645,8 @@ our @ISA = DC::UI::Base::; -use strict; +use common::sense; + use DC::OpenGL; sub new { @@ -658,11 +659,18 @@ ) } +sub set_bg { + my ($self, $bg) = @_; + + $self->{bg} = $bg; + $self->update; +} + sub _draw { my ($self) = @_; - my $color = $FOCUS == $self && $self->{active_bg} - ? $self->{active_bg} + my $color = $FOCUS == $self + ? $self->{active_bg} || $self->{bg} : $self->{bg}; if ($color && (@$color < 4 || $color->[3])) { @@ -2589,7 +2597,7 @@ package DC::UI::Image; -our @ISA = DC::UI::Base::; +our @ISA = DC::UI::DrawBG::; use DC::OpenGL; @@ -2632,6 +2640,13 @@ $self->new (path => $path) } +sub set_texture { + my ($self, $tex) = @_; + + $self->{tex} = $tex; + $self->update; +} + sub size_request { my ($self) = @_; @@ -2641,6 +2656,8 @@ sub _draw { my ($self) = @_; + $self->SUPER::_draw; + my $tex = $self->{tex}; my ($w, $h) = ($self->{w}, $self->{h}); @@ -2668,8 +2685,6 @@ use DC::OpenGL; -my %textures; - sub new { my $class = shift; @@ -3042,7 +3057,7 @@ package DC::UI::Slider; -use strict; +use common::sense; use DC::OpenGL; @@ -3138,7 +3153,7 @@ my (undef, $lo, $hi, $page) = @{$self->{range}}; - $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); + $x = ($x - $self->{click}[1]) / ($w * $self->{scale} || 1e999); $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); } else { @@ -3728,27 +3743,7 @@ @_, ); - if ($self->{anim} && $self->{animspeed}) { - DC::weaken (my $widget = $self); - - $self->{animspeed} = List::Util::max 0.05, $self->{animspeed}; - $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub { - return unless $::CONN; - - my $w = $widget - or return; - - ++$w->{frame}; - $w->update_face; - - # somehow, $widget can go away - $w->update; - $w->update_timer; - }; - - $self->update_face; - $self->update_timer; - } + $self->update_anim; $self } @@ -3784,6 +3779,34 @@ } } +sub update_anim { + my ($self) = @_; + + if ($self->{anim} && $self->{animspeed}) { + DC::weaken (my $widget = $self); + + $self->{animspeed} = List::Util::max 0.05, $self->{animspeed}; + $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub { + return unless $::CONN; + + my $w = $widget + or return; + + ++$w->{frame}; + $w->update_face; + + # somehow, $widget can go away + $w->update; + $w->update_timer; + }; + + $self->update_face; + $self->update_timer; + } else { + delete $self->{timer}; + } +} + sub size_request { my ($self) = @_; @@ -3812,6 +3835,27 @@ $self->SUPER::update; } +sub set_face { + my ($self, $face) = @_; + + $self->{face} = $face; + $self->reconfigure; +} + +sub set_anim { + my ($self, $anim) = @_; + + $self->{anim} = $anim; + $self->update_anim; +} + +sub set_animspeed { + my ($self, $animspeed) = @_; + + $self->{animspeed} = $animspeed; + $self->update_anim; +} + sub invoke_visibility_change { my ($self) = @_; @@ -4251,7 +4295,7 @@ sub reorder { my ($self) = @_; - my $NOW = EV::time; + my $NOW = AE::time; # freeze display when hovering over any label return if $DC::UI::TOOLTIP->{owner}