--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/14 00:15:52 1.96 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/14 02:03:11 1.97 @@ -118,13 +118,13 @@ sub _size_allocate { my ($self, $x, $y, $w, $h) = @_; - $self->{x} = $x; - $self->{y} = $y; + $self->{x} = int $x; + $self->{y} = int $y; return unless $self->{w} != $w || $self->{h} != $h; - $self->{w} = $w; - $self->{h} = $h; + $self->{w} = int $w; + $self->{h} = int $h; 1 } @@ -146,6 +146,7 @@ my ($self) = @_; return if $FOCUS == $self; + return unless $self->{can_focus}; my $focus = $FOCUS; $FOCUS = $self; $focus->update if $focus; @@ -188,7 +189,7 @@ $self->_draw; glPopMatrix; - if ($self == $HOVER) { + if ($self == $HOVER && $self->{can_hover}) { my ($x, $y) = @$self{qw(x y)}; glColor 0, 0, 1, 0.2; @@ -531,6 +532,19 @@ map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); +sub new { + my $class = shift; + + # TODO: user_x, user_y, overwrite moveto? + + $class->SUPER::new ( + bg => [1, 1, 1, 1], + border_bg => [1, 1, 1, 1], + border => $::FONTSIZE * 0.8, + @_ + ) +} + sub size_request { my ($self) = @_; @@ -538,12 +552,10 @@ my ($w, $h) = $self->SUPER::size_request; - $h += $tex[1]->{h}; - $h += $tex[4]->{h}; - $w += $tex[2]->{w}; - $w += $tex[3]->{w}; - - ($w, $h) + ( + $w + $self->{border} * 2, + $h + $self->{border} * 2, + ) } sub size_allocate { @@ -551,24 +563,17 @@ $self->_size_allocate ($x, $y, $w, $h) or return; - $h -= $tex[1]{h}; - $h -= $tex[4]{h}; - $w -= $tex[2]{w}; - $w -= $tex[3]{w}; + $h -= List::Util::max 0, $self->{border} * 2; + $w -= List::Util::max 0, $self->{border} * 2; - $h = $h < 0 ? 0 : $h; - $w = $w < 0 ? 0 : $w; - - my $child = $self->child; - - $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h); + $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); } sub button_down { my ($self, $ev, $x, $y) = @_; - if ($x < $self->{w} && $x >= $self->{w} - $tex[2]{w} - && $y < $self->{h} && $y >= $self->{h} - $tex[4]{h}) { + if ($x < $self->{w} && $x >= $self->{w} - $self->{border} + && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { my ($ox, $oy) = ($ev->button_x, $ev->button_y); my ($bw, $bh) = ($self->{w}, $self->{h}); @@ -584,7 +589,7 @@ }; } elsif ($x >= 0 && $x < $self->{w} - && $y >= 0 && $y < $tex[1]{h}) { + && $y >= 0 && $y < $self->{border}) { my ($ox, $oy) = ($ev->button_x, $ev->button_y); my ($bx, $by) = ($self->{x}, $self->{y}); @@ -615,41 +620,33 @@ sub _draw { my ($self) = @_; - my ($w, $h) = ($self->{w}, $self->{h}); + my ($w, $h ) = ($self->{w}, $self->{h}); my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); glEnable GL_BLEND; glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; glEnable GL_TEXTURE_2D; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - - my $top = $tex[1]; - $top->draw_quad (0, 0, $w, $top->{h}); - - my $left = $tex[3]; - $left->draw_quad (0, $top->{h}, $left->{w}, $ch); - - my $right = $tex[2]; - $right->draw_quad ($w - $right->{w}, $top->{h}, $right->{w}, $ch); + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; - my $bottom = $tex[4]; - $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h}); + glColor @{ $self->{border_bg} }; + $tex[1]->draw_quad (0, 0, $w, $self->{border}); + $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); + $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); + $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); my $bg = $tex[0]; - glBindTexture GL_TEXTURE_2D, $bg->{name}; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - + # TODO: repeat texture not scale my $rep_x = $cw / $bg->{w}; my $rep_y = $ch / $bg->{h}; - $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); + glColor @{ $self->{bg} }; + $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); glDisable GL_TEXTURE_2D; glDisable GL_BLEND; $self->child->draw; - } ############################################################################# @@ -995,7 +992,7 @@ : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} : ($self->{w} - $tex->{w}) * 0.5; - glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0; + glTranslate int $x, int +($self->{h} - $tex->{h}) * 0.5, 0; $tex->draw_quad (0, 0); glDisable GL_TEXTURE_2D; @@ -1019,6 +1016,8 @@ bg => [0, 0, 0, 0.2], active_bg => [1, 1, 1, 0.5], active_fg => [0, 0, 0], + can_hover => 1, + can_focus => 1, @_ ) } @@ -1180,8 +1179,7 @@ fg => [1, 1, 1], bg => [1, 1, 1, 0.2], active_fg => [1, 1, 0], -# active_bg => [0, 0, 0, 0.5], -# border_fg => [1, 1, 0], + can_hover => 1, @_ ) } @@ -1237,6 +1235,7 @@ fg => [1, 1, 1], active_fg => [1, 1, 0], state => 0, + can_hover => 1, @_ ) } @@ -1306,13 +1305,17 @@ # range [value, low, high, page] + # TODO: 0-width page + # TODO: req_w/h are wrong with vertical + # TODO: calculations are off my $self = $class->SUPER::new ( fg => [1, 1, 1], active_fg => [0, 0, 0], range => [0, 0, 100, 10], req_w => 40, - req_h => 10, + req_h => 13, vertical => 0, + can_hover => 1, @_ ); @@ -1411,6 +1414,73 @@ ############################################################################# +package CFClient::UI::TextView; + +our @ISA = CFClient::UI::HBox::; + +use SDL::OpenGL; + +sub new { + my $class = shift; + + my $self = $class->SUPER::new ( + par => [], + @_, + children => [ + (new CFClient::UI::Empty expand => 1), + (new CFClient::UI::Slider vertical => 1), + ], + ); + + $self +} + +sub add_paragraph { + my ($self, $color, $text) = @_; + + push @{$self->{par}}, [$color, $text]; + my $count = scalar @{$self->{par}}; + $self->{children}[1]{range} = [$count - 1, 0, $count, 1]; + $self->{children}[1]->update; +} + +sub _draw { + my ($self) = @_; + + my $par = $self->{par}; + + my $bottom = (scalar @$par) - 1; + + my $w = $self->{children}[0]{w}; + my $y = $self->{h}; + + glEnable GL_BLEND; + glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + glEnable GL_TEXTURE_2D; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; + + # TODO: everything! + while ($y > 0 && $bottom >= 0) { + my $par = $par->[$bottom--]; + + my $layout = new CFClient::Layout; + + $layout->set_height ($::FONTSIZE); + $layout->set_width ($w); + $layout->set_text ($par->[1]); + my $tex = new_from_layout CFClient::Texture $layout; + $y -= $tex->{h}; + + glColor @{ $par->[0] }; + $tex->draw_quad (0, $y); + } + + glDisable GL_TEXTURE_2D; + glDisable GL_BLEND; +} + +############################################################################# + package CFClient::UI::MapWidget; use strict; @@ -1426,8 +1496,9 @@ my $class = shift; $class->SUPER::new ( - z => -1, - list => (glGenLists 1), + z => -1, + can_focus => 1, + list => (glGenLists 1), @_ ) } @@ -1509,15 +1580,16 @@ glCallList $self->{list}; if ($FOCUS != $self) { - glEnable GL_BLEND; - glColor 0, 0, 1, 0.4; + glColor 64/255, 64/255, 64/255; + glLogicOp GL_AND; + glEnable GL_COLOR_LOGIC_OP; glBegin GL_QUADS; glVertex 0, 0; glVertex 0, $::HEIGHT; glVertex $::WIDTH, $::HEIGHT; glVertex $::WIDTH, 0; glEnd; - glDisable GL_BLEND; + glDisable GL_COLOR_LOGIC_OP; } } @@ -1642,6 +1714,7 @@ sub toggle_flopper { my ($self) = @_; + # TODO: use animation if ($self->{state} = !$self->{state}) { $CFClient::UI::TOPLEVEL->add ($self->{other}); $self->{other}->move (