--- deliantra/Deliantra-Client/DC/UI.pm 2006/08/13 21:46:10 1.345 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/10/01 12:08:58 1.351 @@ -900,7 +900,7 @@ { package CFPlus::UI::Base; - ($draw_x, $draw_y, $draw_w, $draw_h) = + local ($draw_x, $draw_y, $draw_w, $draw_h) = (0, 0, $self->{w}, $self->{h}); } @@ -1134,6 +1134,106 @@ use CFPlus::OpenGL; +sub new { + my ($class, %arg) = @_; + + if ((exists $arg{label}) && !ref $arg{label}) { + $arg{label} = new CFPlus::UI::Label + align => 1, + valign => 0, + text => $arg{label}, + fontsize => ($arg{border} || 0.8) * 0.75; + } + + my $self = $class->SUPER::new ( + # label => "", + fg => [0.6, 0.3, 0.1], + border => 0.8, + style => 'single', + %arg, + ); + + $self +} + +sub add { + my ($self, @widgets) = @_; + + $self->SUPER::add (@widgets); + $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label}; +} + +sub border { + int $_[0]{border} * $::FONTSIZE +} + +sub size_request { + my ($self) = @_; + + ($self->{label_w}, undef) = $self->{label}->size_request + if $self->{label}; + + my ($w, $h) = $self->SUPER::size_request; + + ( + $w + $self->border * 2, + $h + $self->border * 2, + ) +} + +sub invoke_size_allocate { + my ($self, $w, $h) = @_; + + my $border = $self->border; + + $w -= List::Util::max 0, $border * 2; + $h -= List::Util::max 0, $border * 2; + + if (my $label = $self->{label}) { + $label->{w} = List::Util::max 0, List::Util::min $self->{label_w}, $w - $border * 2; + $label->{h} = List::Util::min $h, $border; + $label->invoke_size_allocate ($label->{w}, $label->{h}); + } + + $self->child->configure ($border, $border, $w, $h); + + 1 +} + +sub _draw { + my ($self) = @_; + + my $child = $self->{children}[0]; + + my $border = $self->border; + my ($w, $h) = ($self->{w}, $self->{h}); + + $child->draw; + + glColor @{$self->{fg}}; + glBegin GL_LINE_STRIP; + glVertex $border * 1.5 , $border * 0.5 + 0.5; + glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; + glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; + glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; + glVertex $w - $border * 0.5 + 0.5, $border * 0.5 + 0.5; + glVertex $self->{label} ? $border * 2 + $self->{label}{w} : $border * 1.5, $border * 0.5 + 0.5; + glEnd; + + if ($self->{label}) { + glTranslate $border * 2, 0; + $self->{label}->_draw; + } +} + +############################################################################# + +package CFPlus::UI::Toplevel; + +our @ISA = CFPlus::UI::Bin::; + +use CFPlus::OpenGL; + my $bg = new_from_file CFPlus::Texture CFPlus::find_rcfile "d1_bg.png", mipmap => 1, wrap => 1; @@ -1868,6 +1968,9 @@ $self->{cursor} = 0; } elsif ($sym == CFPlus::SDLK_END) { $self->{cursor} = length $text; + } elsif ($uni == 21) { # ctrl-u + $text = ""; + $self->{cursor} = 0; } elsif ($uni == 27) { $self->emit ('escape'); } elsif ($uni) { @@ -2755,18 +2858,16 @@ sub current_paragraph { my ($self) = @_; - $self->force_uptodate; $self->{top_paragraph} - 1 } sub scroll_to { my ($self, $para) = @_; - $self->force_uptodate; - $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; - $self->{children}[1]->set_value ($self->{par}[$para]{y}); + $self->{scroll_to} = $para; + $self->update; } sub clear { @@ -2805,7 +2906,7 @@ sub scroll_to_bottom { my ($self) = @_; - $self->{scroll_to_bottom} = 1; + $self->{scroll_to} = $#{$self->{par}}; $self->update; } @@ -2816,9 +2917,6 @@ my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; my $height = 0; - my $paridx; - my $top_paragraph; - my $top = int $self->{children}[1]{range}[0]; for my $para (@{$self->{par}}) { if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { @@ -2831,23 +2929,17 @@ } $para->{y} = $height; - - $paridx++; - $top_paragraph ||= $paridx if $height >= $top; - $height += $para->{h}; } - $self->{top_paragraph} = $top_paragraph; $self->{height} = $height; - $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); delete $self->{texture}; } - if (delete $self->{scroll_to_bottom}) { - $self->{children}[1]->set_value (1e10); + if (my $paridx = delete $self->{scroll_to}) { + $self->{children}[1]->set_value ($self->{par}[$paridx]{y}); } } @@ -2869,6 +2961,17 @@ glClearColor 0, 0, 0, 0; glClear GL_COLOR_BUFFER_BIT; + { + package CFPlus::UI::Base; + + local ($draw_x, $draw_y, $draw_w, $draw_h) = + (0, 0, $self->{w}, $self->{h}); + } + + my $top = int $self->{children}[1]{range}[0]; + + my $paridx = 0; + my $top_paragraph; my $top = int $self->{children}[1]{range}[0]; my $y0 = $top; @@ -2896,7 +2999,12 @@ } } } + + $paridx++; + $top_paragraph ||= $paridx if $y >= $top; } + + $self->{top_paragraph} = $top_paragraph; }; }); } @@ -3191,7 +3299,7 @@ package CFPlus::UI::Menu; -our @ISA = CFPlus::UI::FancyFrame::; +our @ISA = CFPlus::UI::Toplevel::; use CFPlus::OpenGL; @@ -3737,7 +3845,7 @@ 1 }; - my $tooltip = "$spell->{message}$TOOLTIP_ALL"; + my $tooltip = (CFPlus::asxml $spell->{message}) . $TOOLTIP_ALL; #TODO: add path info to tooltip #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); @@ -4025,7 +4133,7 @@ { package CFPlus::UI::Base; - ($draw_x, $draw_y, $draw_w, $draw_h) = + local ($draw_x, $draw_y, $draw_w, $draw_h) = (0, 0, $self->{w}, $self->{h}); }