--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/12 12:16:58 1.83 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/12 23:59:42 1.93 @@ -803,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); @@ -863,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}; @@ -999,7 +995,7 @@ : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} : ($self->{w} - $tex->{w}) * 0.5; - glTranslate $x, $self->{padding}, 0; + glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0; $tex->draw_quad (0, 0); glDisable GL_TEXTURE_2D; @@ -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); @@ -1453,18 +1514,21 @@ } } -# if (1) { # higher quality darkness -# $lighting =~ s/(.)/$1$1$1/gs; -# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; -# -# $pb = $pb->scale_simple ($sw4 * 0.5, $sh * 0.5, "bilinear"); -# -# $lighting = $pb->get_pixels; -# $lighting =~ s/(.)../$1/gs; -# } - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; + if ($::CFG->{fow_smooth}) { # smooth fog of war + my @conv = ( + 0.1, 0.1, 0.1, + 0.1, 0.2, 0.1, + 0.1, 0.1, 0.1, + ); + glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; + glConvolutionFilter2D GL_CONVOLUTION_2D, + GL_ALPHA, 3, 3, GL_ALPHA, GL_FLOAT, + pack "f*", @conv; + glEnable GL_CONVOLUTION_2D; + } + $darkness = new CFClient::Texture w => $sw4, h => $sh, @@ -1472,9 +1536,11 @@ internalformat => GL_ALPHA, format => GL_ALPHA; - glColor 0.45, 0.45, 0.45, 1; + glColor +($::CFG->{fow_intensity}) x 3, 1; $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); + glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; + glDisable GL_TEXTURE_2D; glDisable GL_BLEND; @@ -1482,6 +1548,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 +1585,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 +1608,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"); } }