--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/12 00:36:13 1.80 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/12 21:20:42 1.89 @@ -135,7 +135,7 @@ $self->_size_allocate ($x, $y, $w, $h); } -# translate global koordinates to local coordinate system +# translate global coordinates to local coordinate system sub translate { my ($self, $x, $y) = @_; @@ -639,8 +639,6 @@ glBindTexture GL_TEXTURE_2D, $bg->{name}; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; - glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; my $rep_x = $cw / $bg->{w}; my $rep_y = $ch / $bg->{h}; @@ -745,12 +743,11 @@ my $row_h = $hs->[$r]; for my $c (0 .. $#$row) { - my $widget = $row->[$c] - or next; - my $col_w = $ws->[$c]; - $widget->size_allocate ($x, $y, $col_w, $row_h); + if (my $widget = $row->[$c]) { + $widget->size_allocate ($x, $y, $col_w, $row_h); + } $x += $col_w; } @@ -806,9 +803,7 @@ sub size_allocate { my ($self, $x, $y, $w, $h) = @_; - $self->_size_allocate ($x, $y, $w, $h) or return; - - return unless $self->{w}; + $self->_size_allocate ($x, $y, $w, $h); ($h, $w) = ($w, $h); @@ -866,9 +861,7 @@ sub size_allocate { my ($self, $x, $y, $w, $h) = @_; - $self->_size_allocate ($x, $y, $w, $h) or return; - - return unless $self->{h}; + $self->_size_allocate ($x, $y, $w, $h); my $children = $self->{children}; @@ -943,6 +936,7 @@ $self->{layout}->set_markup ($text); delete $self->{texture}; +# $self->{w} = $self->{h} = -1; $self->update; } @@ -985,7 +979,7 @@ my $tex = $self->{texture} ||= do { $self->{layout}->set_width ($self->{w}); - $self->{layout}->set_height (List::Util::min $self->{h}, $self->{height}); + $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); new_from_layout CFClient::Texture $self->{layout} }; @@ -1001,7 +995,8 @@ : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} : ($self->{w} - $tex->{w}) * 0.5; - $tex->draw_quad ($x, $self->{padding}); + glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0; + $tex->draw_quad (0, 0); glDisable GL_TEXTURE_2D; glDisable GL_BLEND; @@ -1035,6 +1030,7 @@ $self->{text} = $text; $self->{layout}->set_width ($self->{w}); + $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); $text =~ s/./*/g if $self->{hidden}; @@ -1172,6 +1168,10 @@ use SDL; use SDL::OpenGL; +my @tex = + map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } + qw(b1_button_active.png); + sub new { my $class = shift; @@ -1179,9 +1179,9 @@ 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], +# active_bg => [0, 0, 0, 0.5], +# border_fg => [1, 1, 0], @_ ) } @@ -1199,33 +1199,22 @@ my ($self) = @_; local $self->{fg} = $self->{fg}; + my $tex = $tex[0]; glEnable GL_BLEND; + glEnable GL_TEXTURE_2D; 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; + glBindTexture GL_TEXTURE_2D, $tex->{name}; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; + + $tex->draw_quad (0, 0, $self->{w}, $self->{h}); + + glDisable GL_TEXTURE_2D; glDisable GL_BLEND; $self->SUPER::_draw; @@ -1233,6 +1222,77 @@ ############################################################################# +package CFClient::UI::CheckBox; + +our @ISA = CFClient::UI::DrawBG::; + +use SDL; +use SDL::OpenGL; + +sub new { + my $class = shift; + + $class->SUPER::new ( + padding => 2, + fg => [1, 1, 1], + active_fg => [1, 1, 0], + state => 0, + @_ + ) +} + +sub size_request { + my ($self) = @_; + + ($self->{padding} * 2 + 6) x 2 +} + +sub size_allocate { + my ($self, $x, $y, $w, $h) = @_; + + $self->_size_allocate ($x, $y, $w, $h); +} + +sub button_down { + my ($self, $ev, $x, $y) = @_; + + if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} + && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { + $self->{state} = !$self->{state}; + $self->emit (changed => $self->{state}); + } +} + +sub _draw { + my ($self) = @_; + + $self->SUPER::_draw; + + glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; + + my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; + + glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; + + glBegin GL_LINE_LOOP; + glVertex 0 , 0; + glVertex 0 , $s; + glVertex $s, $s; + glVertex $s, 0; + glEnd; + + if ($self->{state}) { + glBegin GL_LINES; + glVertex 0 , 0; + glVertex $s, $s; + glVertex $s, 0; + glVertex 0 , $s; + glEnd; + } +} + +############################################################################# + package CFClient::UI::Slider; use strict; @@ -1425,6 +1485,7 @@ glEnable GL_BLEND; glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; + glColor 1, 1, 1, 1; my $sw4 = ($sw + 3) & ~3; my $darkness = "\x00" x ($sw4 * $sh); @@ -1482,6 +1543,18 @@ } glCallList $self->{list}; + + if ($FOCUS != $self) { + glEnable GL_BLEND; + glColor 0, 0, 1, 0.4; + glBegin GL_QUADS; + glVertex 0, 0; + glVertex 0, $::HEIGHT; + glVertex $::WIDTH, $::HEIGHT; + glVertex $::WIDTH, 0; + glEnd; + glDisable GL_BLEND; + } } my %DIR = ( @@ -1507,16 +1580,18 @@ my $sym = $ev->key_sym; if ($sym == SDLK_KP5) { - $::CONN->send ("command stay fire"); + $::CONN->user_send ("command stay fire"); + } elsif ($sym == SDLK_a) { + $::CONN->user_send ("command apply"); } elsif (exists $DIR{$sym}) { if ($mod & KMOD_SHIFT) { $self->{shft}++; - $::CONN->send ("command fire $DIR{$sym}[0]"); + $::CONN->user_send ("command fire $DIR{$sym}[0]"); } elsif ($mod & KMOD_CTRL) { $self->{ctrl}++; - $::CONN->send ("command run $DIR{$sym}[0]"); + $::CONN->user_send ("command run $DIR{$sym}[0]"); } else { - $::CONN->send ("command $DIR{$sym}[1]"); + $::CONN->user_send ("command $DIR{$sym}[1]"); } } } @@ -1528,10 +1603,10 @@ my $sym = $ev->key_sym; if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { - $::CONN->send ("command fire_stop"); + $::CONN->user_send ("command fire_stop"); } if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { - $::CONN->send ("command run_stop"); + $::CONN->user_send ("command run_stop"); } }