--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/11 22:49:13 1.78 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/12 00:26:50 1.79 @@ -81,14 +81,22 @@ sub new { my $class = shift; - bless { + my $self = bless { x => 0, y => 0, z => 0, w => -1, h => -1, @_ - }, $class + }, $class; + + for (keys %$self) { + if (/^connect_(.*)$/) { + $self->connect ($1 => delete $self->{$_}); + } + } + + $self } sub move { @@ -265,7 +273,7 @@ $class->SUPER::new ( bg => [0, 0, 0, 0.2], - active_bg => [1, 1, 1], + active_bg => [1, 1, 1, 0.5], @_ ) } @@ -1014,7 +1022,7 @@ $class->SUPER::new ( fg => [1, 1, 1], bg => [0, 0, 0, 0.2], - active_bg => [1, 1, 1], + active_bg => [1, 1, 1, 0.5], active_fg => [0, 0, 0], @_ ) @@ -1156,6 +1164,74 @@ } ############################################################################# + +package CFClient::UI::Button; + +our @ISA = CFClient::UI::Label::; + +use SDL; +use SDL::OpenGL; + +sub new { + my $class = shift; + + $class->SUPER::new ( + padding => 4, + fg => [1, 1, 1], + bg => [1, 1, 1, 0.2], + active_bg => [0, 0, 0, 0.5], + active_fg => [1, 1, 0], + border_fg => [1, 1, 0], + @_ + ) +} + +sub button_up { + my ($self, $ev, $x, $y) = @_; + + if ($x >= 0 && $x < $self->{w} + && $y >= 0 && $y < $self->{h}) { + $self->emit ("activate"); + } +} + +sub _draw { + my ($self) = @_; + + local $self->{fg} = $self->{fg}; + + glEnable GL_BLEND; + glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + + glTranslate 0.375, 0.375, 0; # make line and polyogon coordinates behave similarly + + glBegin GL_LINE_LOOP; + glColor @{$self->{border_fg}}; + glVertex 1 , 1; + glVertex 1 , $self->{h} - 2; + glVertex $self->{w} - 2, $self->{h} - 2; + glVertex $self->{w} - 2, 1; + glEnd; + + if ($GRAB == $self) { + glColor @{$self->{active_bg}}; + $self->{fg} = $self->{active_fg}; + } else { + glColor @{$self->{bg}}; + } + + glBegin GL_QUADS; + glVertex 2 , 2; + glVertex 2 , $self->{h} - 2; + glVertex $self->{w} - 2, $self->{h} - 2; + glVertex $self->{w} - 2, 2; + glEnd; + glDisable GL_BLEND; + + $self->SUPER::_draw; +} + +############################################################################# package CFClient::UI::Slider;