--- deliantra/Deliantra-Client/DC/UI.pm 2007/07/23 18:13:33 1.415 +++ deliantra/Deliantra-Client/DC/UI.pm 2007/07/25 15:50:17 1.420 @@ -275,7 +275,7 @@ } sub TO_JSON { - { __widget_ref__ => $_[0]{s_id} } + { __w_ => $_[0]{s_id} } } sub show { @@ -2076,8 +2076,10 @@ $class->SUPER::new ( fg => [1, 1, 1], bg => [0, 0, 0, 0.2], - active_bg => [1, 1, 1, 0.5], - active_fg => [0, 0, 0], + outline => [0.6, 0.3, 0.1], + active_bg => [0, 0, 1, .2], + active_fg => [1, 1, 1], + active_outline => [1, 1, 0], can_hover => 1, can_focus => 1, valign => 0, @@ -2244,13 +2246,34 @@ my $text = substr $self->{text}, 0, $self->{cursor}; utf8::encode $text; - @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) + @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); } + glColor_premultiply @{$self->{active_fg}}; glBegin GL_LINES; glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; glEnd; + + 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; + glLineWidth 1; + + } else { + glColor @{$self->{outline}}; + glTranslate .375, .375; + glBegin GL_LINE_STRIP; + glVertex 0, $self->{h} * .5; + glVertex 0, $self->{h} - 3; + glVertex $self->{w} - 1, $self->{h} - 3; + glVertex $self->{w} - 1, $self->{h} * .5; + glEnd; } } @@ -2346,6 +2369,55 @@ ############################################################################# +package CFPlus::UI::ButtonBin; + +our @ISA = CFPlus::UI::Bin::; + +use CFPlus::OpenGL; + +my @tex = + map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } + qw(b1_button_inactive.png b1_button_active.png); + +sub new { + my $class = shift; + + $class->SUPER::new ( + can_hover => 1, + align => 0, + valign => 0, + can_events => 1, + @_ + ) +} + +sub invoke_button_up { + my ($self, $ev, $x, $y) = @_; + + $self->emit ("activate") + if $x >= 0 && $x < $self->{w} + && $y >= 0 && $y < $self->{h}; + + 1 +} + +sub _draw { + my ($self) = @_; + + glEnable GL_TEXTURE_2D; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; + glColor 0, 0, 0, 1; + + my $tex = $tex[$GRAB == $self]; + $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); + + glDisable GL_TEXTURE_2D; + + $self->SUPER::_draw; +} + +############################################################################# + package CFPlus::UI::Button; our @ISA = CFPlus::UI::Label::; @@ -2489,6 +2561,7 @@ my $self = $class->SUPER::new ( can_events => 0, + scale => 1, @_, ); @@ -2523,7 +2596,7 @@ sub size_request { my ($self) = @_; - ($self->{tex}{w}, $self->{tex}{h}) + (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) } sub _draw { @@ -2543,7 +2616,7 @@ glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - $tex->draw_quad (0, 0, $w, $h); + $tex->draw_quad_alpha (0, 0, $w, $h); glDisable GL_TEXTURE_2D; } @@ -3427,12 +3500,7 @@ my ($w, $h) = @$self{qw(w h)}; glColor 1, 0.8, 0.4; - glBegin GL_QUADS; - glVertex 0 , 0; - glVertex 0 , $h; - glVertex $w, $h; - glVertex $w, 0; - glEnd; + glRect 0, 0, $w, $h; glColor 0, 0, 0; glBegin GL_LINE_LOOP; @@ -3624,7 +3692,7 @@ (new CFPlus::UI::Label markup => $right, align => +1), ], ; - + } else { $widget = new CFPlus::UI::Label can_hover => 1,