--- deliantra/Deliantra-Client/DC/UI.pm 2006/05/21 00:34:59 1.219 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/05/22 03:28:55 1.220 @@ -138,6 +138,14 @@ } } +sub full_refresh { + # make a copy, otherwise for complains about freed values. + my @widgets = values %WIDGET; + + $_->update + for @widgets; +} + # call when resolution changes etc. sub rescale_widgets { my ($sx, $sy) = @_; @@ -2209,13 +2217,25 @@ $self->reflow; } +sub size_allocate { + my ($self, $w, $h) = @_; + + $self->SUPER::size_allocate ($w, $h); + + $self->{layout}->set_font ($self->{font}) if $self->{font}; + $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); + $self->{layout}->set_width ($self->{children}[0]{w}); + + $self->reflow; +} + sub text_height { - my ($self, $text) = @_; + my ($self, $text, $indent) = @_; my $layout = $self->{layout}; $layout->set_height ($self->{fontsize} * $::FONTSIZE); - $layout->set_width ($self->{children}[0]{w}); + $layout->set_width ($self->{children}[0]{w} - $indent); $layout->set_markup ($text); ($layout->size)[1] @@ -2228,28 +2248,16 @@ $self->update; } -sub size_allocate { - my ($self, $w, $h) = @_; - - $self->SUPER::size_allocate ($w, $h); - - $self->{layout}->set_font ($self->{font}) if $self->{font}; - $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); - $self->{layout}->set_width ($self->{children}[0]{w}); - - $self->reflow; -} - sub add_paragraph { - my ($self, $color, $text) = @_; + my ($self, $color, $text, $indent) = @_; #TODO: intelligently "reformat" paragraph - my $height = $self->text_height ($text); - - $self->{height} += $height; - - push @{$self->{par}}, [$height, $color, $text]; + for my $line (split /\n/, $text) { + my $height = $self->text_height ($line); + $self->{height} += $height; + push @{$self->{par}}, [$height, $color, $indent, $line]; + } $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; $self->{children}[1]->update; @@ -2268,12 +2276,13 @@ if (delete $self->{need_reflow}) { my $height = 0; - $height += $_->[0] = $self->text_height ($_->[2]) + $height += $_->[0] = $self->text_height ($_->[3], $_->[2]) for @{$self->{par}}; $self->{height} = $height; $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; + $self->{children}[1]->update; delete $self->{texture}; } @@ -2282,9 +2291,6 @@ glClearColor 0.5, 0.5, 0.5, 0; glClear GL_COLOR_BUFFER_BIT; - glEnable GL_TEXTURE_2D; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - my $top = int $self->{children}[1]{range}[0]; my $y0 = $top; @@ -2296,21 +2302,27 @@ $layout->set_font ($self->{font}) if $self->{font}; + glEnable GL_BLEND; + glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; + for my $par (@{$self->{par}}) { my $h = $par->[0]; if ($y0 < $y + $h && $y < $y1) { $layout->set_foreground (@{ $par->[1] }); - $layout->set_markup ($par->[2]); + $layout->set_width ($self->{w} - $par->[2]); + $layout->set_markup ($par->[3]); + + my ($w, $h, $data, $format, $internalformat) = $layout->render; - my ($W, $H) = $layout->size; - CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); + glRasterPos $par->[2], $y - $y0; + glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data; } $y += $h; } - glDisable GL_TEXTURE_2D; + glDisable GL_BLEND; }; }); }