--- deliantra/Deliantra-Client/DC/UI.pm 2007/08/10 04:02:13 1.425 +++ deliantra/Deliantra-Client/DC/UI.pm 2007/08/21 02:39:17 1.430 @@ -609,6 +609,7 @@ return if CFPlus::in_destruct; + local $@; eval { $self->destroy }; warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; @@ -627,8 +628,6 @@ sub new { my $class = shift; - # range [value, low, high, page] - $class->SUPER::new ( #bg => [0, 0, 0, 0.2], #active_bg => [1, 1, 1, 0.5], @@ -649,14 +648,7 @@ glEnable GL_BLEND; glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; glColor_premultiply @$color; - - glBegin GL_QUADS; - glVertex 0 , 0; - glVertex 0 , $h; - glVertex $w, $h; - glVertex $w, 0; - glEnd; - + glRect 0, 0, $w, $h; glDisable GL_BLEND; } } @@ -1221,14 +1213,7 @@ glEnable GL_BLEND; glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; glColor_premultiply @{ $self->{bg} }; - - glBegin GL_QUADS; - glVertex 0 , 0; - glVertex 0 , $h; - glVertex $w, $h; - glVertex $w, 0; - glEnd; - + glRect 0, 0, $w, $h; glDisable GL_BLEND; } @@ -2046,6 +2031,8 @@ $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} : ($self->{h} - $size->[1]) * 0.5); + + $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); }; # unless ($self->{list}) { @@ -2057,7 +2044,7 @@ # # CFPlus::OpenGL::glCallList $self->{list}; - $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); + $self->{layout}->draw; } #sub destroy { @@ -2235,12 +2222,7 @@ glEnable GL_BLEND; glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; - glBegin GL_QUADS; - glVertex 0 , 0; - glVertex 0 , $self->{h}; - glVertex $self->{w}, $self->{h}; - glVertex $self->{w}, 0; - glEnd; + glRect 0, 0, $self->{w}, $self->{h}; glDisable GL_BLEND; $self->SUPER::_draw; @@ -2263,12 +2245,7 @@ glLineWidth 3; glColor @{$self->{active_outline}}; - glBegin GL_LINE_LOOP; - glVertex 0, 0; - glVertex $self->{w} - 1, 0; - glVertex $self->{w} - 1, $self->{h} - 1; - glVertex 0, $self->{h} - 1; - glEnd; + glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; glLineWidth 1; } else { @@ -2653,6 +2630,12 @@ ); } +sub invoke_button_down { + my ($self, $ev, $x, $y) = @_; + + 1 +} + sub invoke_button_up { my ($self, $ev, $x, $y) = @_; @@ -2800,6 +2783,116 @@ ############################################################################# +package CFPlus::UI::Progress; + +our @ISA = CFPlus::UI::Label::; + +use CFPlus::OpenGL; + +sub new { + my ($class, %arg) = @_; + + my $self = $class->SUPER::new ( + fg => [1, 1, 1], + bg => [0, 0, 1, 0.2], + bar => [0.7, 0.5, 0.1, 0.8], + outline => [0.4, 0.3, 0], + fontsize => 0.9, + valign => 0, + align => 0, + can_events => 1, + ellipsise => 1, + %arg, + text => "-", + value => -1, + ); + + $self->set_value ($arg{value}) if exists $arg{value}; + + $self +} + +sub set_value { + my ($self, $value) = @_; + + if ($self->{value} != $value) { + $self->{value} = $value; + $self->set_text (sprintf "%d%%", $value * 100); + $self->update; + } +} + +sub _draw { + my ($self) = @_; + + glEnable GL_BLEND; + glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; + + if ($self->{value} >= 0) { + my $s = 3 + ($self->{w} - 6) * $self->{value}; + + glColor_premultiply @{$self->{bar}}; + glRect 2, 2, $s, $self->{h} - 2; + glColor_premultiply @{$self->{bg}}; + glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; + } + + glColor_premultiply @{$self->{outline}}; + glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2; + + glDisable GL_BLEND; + + { + local $self->{bg}; # do not draw background + $self->SUPER::_draw; + } +} + +############################################################################# + +package CFPlus::UI::ExperienceProgress; + +our @ISA = CFPlus::UI::Progress::; + +sub new { + my ($class, %arg) = @_; + + my $self = $class->SUPER::new ( + %arg + ); + + $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } + if $::CONN; + + $self +} + +sub DESTROY { + my ($self) = @_; + + delete $::CONN->{on_exp_update}{$self+0} + if $::CONN; + + $self->SUPER::DESTROY; +} + +sub set_value { + my ($self, $lvl, $exp) = @_; + + my $v = 0; + + if ($::CONN && (my $table = $::CONN->{exp_table})) { + my $l0 = $table->[$lvl - 1]; + my $l1 = $table->[$lvl]; + + $v = ($exp - $l0) / ($l1 - $l0); + } + + $self->SUPER::set_value ($v); +} + +############################################################################# + package CFPlus::UI::Gauge; our @ISA = CFPlus::UI::VBox::; @@ -3306,6 +3399,7 @@ my $layout = $self->get_layout ($para); $layout->render ($para->{indent}, $y - $y0); + $layout->draw; if (my @w = @{ $para->{widget} }) { my @s = $layout->get_shapes; @@ -3509,12 +3603,7 @@ glRect 0, 0, $w, $h; glColor 0, 0, 0; - glBegin GL_LINE_LOOP; - glVertex 0 , 0; - glVertex 0 , $h; - glVertex $w, $h; - glVertex $w, 0; - glEnd; + glRect_lineloop 0, 0, $w, $h; glTranslate 2 - 0.375, 2 - 0.375; @@ -3548,13 +3637,17 @@ $self->{timer} = Event->timer ( parked => 1, cb => sub { - return unless $::CONN && $widget; + return unless $::CONN; - ++$widget->{frame}; - $widget->update_face; - $widget->update; + my $w = $widget + or return; - $widget->update_timer; + ++$w->{frame}; + $w->update_face; + + # somehow, $widget can go away + $w->update; + $w->update_timer; }, ); @@ -3585,15 +3678,16 @@ sub update_face { my ($self) = @_; - return unless $::CONN; - - if (my $anim = $::CONN->{anim}[$self->{anim}]) { - if ($anim && @$anim) { - delete $self->{wait_face}; - $self->{face} = $anim->[ $self->{frame} % @$anim ]; - if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]) { - unless ($tex->{name} || $tex->{loading}) { - $tex->upload (sub { $self->reconfigure }); + if ($::CONN) { + if (my $anim = $::CONN->{anim}[$self->{anim}]) { + if ($anim && @$anim) { + $self->{face} = $anim->[ $self->{frame} % @$anim ]; + delete $self->{face_change_cb}; + + if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) { + unless ($tex->{name} || $tex->{loading}) { + $tex->upload (sub { $self->reconfigure }); + } } } } @@ -3604,18 +3698,16 @@ my ($self) = @_; if ($::CONN) { - if (my $faceid = $::CONN->{faceid}[$self->{face}]) { + if (my $faceid = $::CONN->{face}[$self->{face}]{id}) { if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) { if ($tex->{name}) { return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); } elsif (!$tex->{loading}) { $tex->upload (sub { $self->reconfigure }); } - } else { - $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { - $self->reconfigure; - }); } + + $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure }); } }