--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/14 10:57:35 1.99 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/14 13:51:36 1.103 @@ -641,6 +641,10 @@ my $rep_y = $ch / $bg->{h}; glColor @{ $self->{bg} }; + + $bg->{s} = $rep_x; + $bg->{t} = $rep_y; + $bg->{wrap_mode} = 1; $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); glDisable GL_TEXTURE_2D; @@ -1025,6 +1029,8 @@ sub _set_text { my ($self, $text) = @_; + my $old_text = $self->{text}; + $self->{last_activity} = $::NOW; $self->{text} = $text; @@ -1039,6 +1045,9 @@ utf8::encode $text; @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); + + $self->emit (changed => $self->{text}) # XXX: is this the right place to do this? + if $old_text ne $self->{text}; } sub size_request { @@ -1087,6 +1096,8 @@ $self->{cursor} = 0; } elsif ($sym == SDLK_END) { $self->{cursor} = length $text; + } elsif ($sym == SDLK_ESCAPE) { + $self->emit ('escape'); } elsif ($uni) { substr $text, $self->{cursor}++, 0, chr $uni; } @@ -1246,6 +1257,10 @@ our @ISA = CFClient::UI::DrawBG::; +my @tex = + map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } + qw(c1_checkbox_bg.png c1_checkbox_active.png); + use SDL; use SDL::OpenGL; @@ -1292,24 +1307,19 @@ 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; + glEnable GL_BLEND; + glEnable GL_TEXTURE_2D; + glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; - if ($self->{state}) { - glBegin GL_LINES; - glVertex 0 , 0; - glVertex $s, $s; - glVertex $s, 0; - glVertex 0 , $s; - glEnd; - } + my $tex = $self->{state} ? $tex[1] : $tex[0]; + + $tex->draw_quad (0, 0, $s, $s); + + glDisable GL_TEXTURE_2D; + glDisable GL_BLEND; } ############################################################################# @@ -1342,6 +1352,7 @@ req_h => 13, vertical => 0, can_hover => 1, + inner_pad => 5, @_ ); @@ -1372,7 +1383,11 @@ my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); - $x = $x * ($hi - $lo) / $w + $lo; + my $inner_pad_px = $self->_calc_inner_pad_px ($w); + my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right + + $x -= $inner_pad_px; # substract the padding + $x = $x * ($hi - $lo) / $inner_w + $lo; $x = $lo if $x < $lo; $x = $hi - $page if $x > $hi - $page; $self->{range}[0] = $x; @@ -1382,6 +1397,14 @@ } } +# the inner_* stuff is for generating a padding for the slider handle, +# so that the handle doesn't leave the texture. This calculation isn't 100% +# correct propably, but it does the job for now +sub _calc_inner_pad_px { + my ($self, $w) = @_; + ($w / 100) * $self->{inner_pad} # % to pixels +} + sub _draw { my ($self) = @_; @@ -1403,12 +1426,8 @@ my ($value, $lo, $hi, $page) = @{$self->{range}}; - # the inner_* stuff is for generating a padding for the slider handle, - # so that the handle doesn't leave the texture. This calculation isn't 100% - # correct propably, but it does the job for now - my $inner_pad = 5; # 5% of width for slider bg texture border - my $inner_pad_px = ($w / 100) * $inner_pad; # % to pixels - my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right + my $inner_pad_px = $self->_calc_inner_pad_px ($w); + my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right $page = int $page * $inner_w / ($hi - $lo); $value = int +($value - $lo) * $inner_w / ($hi - $lo); @@ -1643,6 +1662,8 @@ $::CONN->user_send ("command stay fire"); } elsif ($sym == SDLK_a) { $::CONN->user_send ("command apply"); + } elsif ($sym == SDLK_QUOTE) { + $self->emit ('activate_console'); } elsif (exists $DIR{$sym}) { if ($mod & KMOD_SHIFT) { $self->{shft}++;