--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/11 17:39:39 1.71 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/11 18:00:45 1.72 @@ -157,18 +157,21 @@ glPushMatrix; glTranslate $self->{x}, $self->{y}, 0; $self->_draw; + glPopMatrix; + if ($self == $HOVER) { - glColor 1, 1, 1, 0.4; + my ($x, $y) = @$self->{qw(x y)}; + + glColor 1, 1, 1, 0.1; glEnable GL_BLEND; glBegin GL_QUADS; - glVertex 0 , 0; - glVertex $self->{w}, 0; - glVertex $self->{w}, $self->{h}; - glVertex 0 , $self->{h}; + glVertex $x , $y; + glVertex $x + $self->{w}, $y; + glVertex $x + $self->{w}, $y + $self->{h}; + glVertex $x , $y + $self->{h}; glEnd; glDisable GL_BLEND; } - glPopMatrix; } sub _draw { @@ -218,6 +221,19 @@ if $self->{parent}; } +sub connect { + my ($self, $signal, $cb) = @_; + + push @{ $self->{cb}{$signal} }, $cb; +} + +sub emit { + my ($self, $signal, @args) = @_; + + $_->($self, @args) + for @{$self->{cb}{$signal} || []}; +} + sub DESTROY { my ($self) = @_; @@ -506,10 +522,10 @@ my ($w, $h) = $self->SUPER::size_request; - $h += $tex[1]->{height}; - $h += $tex[4]->{height}; - $w += $tex[2]->{width}; - $w += $tex[3]->{width}; + $h += $tex[1]->{h}; + $h += $tex[4]->{h}; + $w += $tex[2]->{w}; + $w += $tex[3]->{w}; ($w, $h) } @@ -521,10 +537,10 @@ $self->SUPER::size_allocate ($w, $h); - $h -= $tex[1]->{height}; - $h -= $tex[4]->{height}; - $w -= $tex[2]->{width}; - $w -= $tex[3]->{width}; + $h -= $tex[1]->{h}; + $h -= $tex[4]->{h}; + $w -= $tex[2]->{w}; + $w -= $tex[3]->{w}; $h = $h < 0 ? 0 : $h; $w = $w < 0 ? 0 : $w; @@ -532,7 +548,7 @@ my $child = $self->child; $child->size_allocate ($w, $h); - $child->move ($tex[3]->{width}, $tex[1]->{height}); + $child->move ($tex[3]->{w}, $tex[1]->{h}); } sub _draw { @@ -547,16 +563,16 @@ glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; my $top = $tex[1]; - $top->draw_quad (0, 0, $w, $top->{height}); + $top->draw_quad (0, 0, $w, $top->{h}); my $left = $tex[3]; - $left->draw_quad (0, $top->{height}, $left->{width}, $ch); + $left->draw_quad (0, $top->{h}, $left->{w}, $ch); my $right = $tex[2]; - $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch); + $right->draw_quad ($w - $right->{w}, $top->{h}, $right->{w}, $ch); my $bottom = $tex[4]; - $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height}); + $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h}); my $bg = $tex[0]; glBindTexture GL_TEXTURE_2D, $bg->{name}; @@ -564,10 +580,10 @@ 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->{width}; - my $rep_y = $ch / $bg->{height}; + my $rep_x = $cw / $bg->{w}; + my $rep_y = $ch / $bg->{h}; - $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch); + $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); glDisable GL_BLEND; glDisable GL_TEXTURE_2D; @@ -580,7 +596,7 @@ package CFClient::Widget::Table; -our @ISA = CFClient::Widget::Bin::; +our @ISA = CFClient::Widget::; use SDL::OpenGL; @@ -742,6 +758,7 @@ fg => [1, 1, 1], height => $::FONTSIZE, text => "", + align => -1, layout => new CFClient::Layout, %arg ); @@ -783,13 +800,13 @@ $self->{layout}->set_width; $self->{layout}->set_height ($self->{height}); $self->{layout}->size -# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack +# if ($self->{texture}{w} > 1 && $self->{texture}{height} > 1) { #TODO: hack # ( -# $self->{texture}{width}, -# $self->{texture}{height}, +# $self->{texture}{w}, +# $self->{texture}{h}, # ) # } else { -# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height}; +# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{h}; # # ($w, $h) # } @@ -826,7 +843,12 @@ glColor @{$self->{fg}}; - $tex->draw_quad (0, 0); + my $x = + $self->{align} < 0 ? 0 + : $self->{align} > 0 ? $self->{w} - $self->{texture}{w} + : ($self->{w} + $self->{texture}{w}) * 0.5; + + $tex->draw_quad ($x, 0); glDisable GL_BLEND; glDisable GL_TEXTURE_2D; @@ -860,6 +882,10 @@ $self->{text} = $text; $self->{layout}->set_width ($self->{w}); + + $text =~ s/./*/g if $self->{hidden}; + + $self->{layout}->set_markup ($self->escape_text ($text)); $text = substr $text, 0, $self->{cursor}; @@ -1034,7 +1060,7 @@ $x = $hi - $page if $x > $hi - $page; $self->{range}[0] = $x; - $self->{changed}($x) if $self->{changed}; + $self->emit (changed => $x); $self->update; } } @@ -1044,8 +1070,6 @@ $self->SUPER::_draw (); - glPushMatrix; - my ($w, $h) = @$self{qw(w h)}; if ($self->{vertical}) { @@ -1094,8 +1118,6 @@ glVertex $knob_b - 1, 1; } glEnd; - - glPopMatrix; } ############################################################################# @@ -1194,8 +1216,7 @@ for my $num (grep $_, @$cell[1,2,3]) { my $tex = $::CONN->{face}[$num]{texture} || next; - my $w = $tex->{width}; - my $h = $tex->{height}; + my ($w, $h) = @$tex{qw(w h)}; $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); }