ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.219 by root, Sun May 21 00:34:59 2006 UTC vs.
Revision 1.220 by root, Mon May 22 03:28:55 2006 UTC

134 for (@$vals) { 134 for (@$vals) {
135 my $i = int $_ + $rem; 135 my $i = int $_ + $rem;
136 $rem += $_ - $i; 136 $rem += $_ - $i;
137 $_ = $i; 137 $_ = $i;
138 } 138 }
139}
140
141sub full_refresh {
142 # make a copy, otherwise for complains about freed values.
143 my @widgets = values %WIDGET;
144
145 $_->update
146 for @widgets;
139} 147}
140 148
141# call when resolution changes etc. 149# call when resolution changes etc.
142sub rescale_widgets { 150sub rescale_widgets {
143 my ($sx, $sy) = @_; 151 my ($sx, $sy) = @_;
2207 2215
2208 $self->{fontsize} = $fontsize; 2216 $self->{fontsize} = $fontsize;
2209 $self->reflow; 2217 $self->reflow;
2210} 2218}
2211 2219
2220sub size_allocate {
2221 my ($self, $w, $h) = @_;
2222
2223 $self->SUPER::size_allocate ($w, $h);
2224
2225 $self->{layout}->set_font ($self->{font}) if $self->{font};
2226 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2227 $self->{layout}->set_width ($self->{children}[0]{w});
2228
2229 $self->reflow;
2230}
2231
2212sub text_height { 2232sub text_height {
2213 my ($self, $text) = @_; 2233 my ($self, $text, $indent) = @_;
2214 2234
2215 my $layout = $self->{layout}; 2235 my $layout = $self->{layout};
2216 2236
2217 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2237 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2218 $layout->set_width ($self->{children}[0]{w}); 2238 $layout->set_width ($self->{children}[0]{w} - $indent);
2219 $layout->set_markup ($text); 2239 $layout->set_markup ($text);
2220 2240
2221 ($layout->size)[1] 2241 ($layout->size)[1]
2222} 2242}
2223 2243
2226 2246
2227 $self->{need_reflow}++; 2247 $self->{need_reflow}++;
2228 $self->update; 2248 $self->update;
2229} 2249}
2230 2250
2231sub size_allocate {
2232 my ($self, $w, $h) = @_;
2233
2234 $self->SUPER::size_allocate ($w, $h);
2235
2236 $self->{layout}->set_font ($self->{font}) if $self->{font};
2237 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2238 $self->{layout}->set_width ($self->{children}[0]{w});
2239
2240 $self->reflow;
2241}
2242
2243sub add_paragraph { 2251sub add_paragraph {
2244 my ($self, $color, $text) = @_; 2252 my ($self, $color, $text, $indent) = @_;
2245 2253
2246 #TODO: intelligently "reformat" paragraph 2254 #TODO: intelligently "reformat" paragraph
2247 2255
2256 for my $line (split /\n/, $text) {
2248 my $height = $self->text_height ($text); 2257 my $height = $self->text_height ($line);
2249
2250 $self->{height} += $height; 2258 $self->{height} += $height;
2251
2252 push @{$self->{par}}, [$height, $color, $text]; 2259 push @{$self->{par}}, [$height, $color, $indent, $line];
2260 }
2253 2261
2254 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; 2262 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
2255 $self->{children}[1]->update; 2263 $self->{children}[1]->update;
2256} 2264}
2257 2265
2266 2274
2267 $ROOT->on_post_alloc ($self, sub { 2275 $ROOT->on_post_alloc ($self, sub {
2268 if (delete $self->{need_reflow}) { 2276 if (delete $self->{need_reflow}) {
2269 my $height = 0; 2277 my $height = 0;
2270 2278
2271 $height += $_->[0] = $self->text_height ($_->[2]) 2279 $height += $_->[0] = $self->text_height ($_->[3], $_->[2])
2272 for @{$self->{par}}; 2280 for @{$self->{par}};
2273 2281
2274 $self->{height} = $height; 2282 $self->{height} = $height;
2275 2283
2276 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2284 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2285 $self->{children}[1]->update;
2277 2286
2278 delete $self->{texture}; 2287 delete $self->{texture};
2279 } 2288 }
2280 2289
2281 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2290 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2282 glClearColor 0.5, 0.5, 0.5, 0; 2291 glClearColor 0.5, 0.5, 0.5, 0;
2283 glClear GL_COLOR_BUFFER_BIT; 2292 glClear GL_COLOR_BUFFER_BIT;
2284 2293
2285 glEnable GL_TEXTURE_2D;
2286 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2287
2288 my $top = int $self->{children}[1]{range}[0]; 2294 my $top = int $self->{children}[1]{range}[0];
2289 2295
2290 my $y0 = $top; 2296 my $y0 = $top;
2291 my $y1 = $top + $self->{h}; 2297 my $y1 = $top + $self->{h};
2292 2298
2294 2300
2295 my $layout = $self->{layout}; 2301 my $layout = $self->{layout};
2296 2302
2297 $layout->set_font ($self->{font}) if $self->{font}; 2303 $layout->set_font ($self->{font}) if $self->{font};
2298 2304
2305 glEnable GL_BLEND;
2306 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2307
2299 for my $par (@{$self->{par}}) { 2308 for my $par (@{$self->{par}}) {
2300 my $h = $par->[0]; 2309 my $h = $par->[0];
2301 2310
2302 if ($y0 < $y + $h && $y < $y1) { 2311 if ($y0 < $y + $h && $y < $y1) {
2303 $layout->set_foreground (@{ $par->[1] }); 2312 $layout->set_foreground (@{ $par->[1] });
2313 $layout->set_width ($self->{w} - $par->[2]);
2304 $layout->set_markup ($par->[2]); 2314 $layout->set_markup ($par->[3]);
2305 2315
2306 my ($W, $H) = $layout->size; 2316 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2307 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); 2317
2318 glRasterPos $par->[2], $y - $y0;
2319 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2308 } 2320 }
2309 2321
2310 $y += $h; 2322 $y += $h;
2311 } 2323 }
2312 2324
2313 glDisable GL_TEXTURE_2D; 2325 glDisable GL_BLEND;
2314 }; 2326 };
2315 }); 2327 });
2316} 2328}
2317 2329
2318sub _draw { 2330sub _draw {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines