… | |
… | |
2293 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2293 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2294 | |
2294 | |
2295 | $self->reflow; |
2295 | $self->reflow; |
2296 | } |
2296 | } |
2297 | |
2297 | |
2298 | sub text_height { |
2298 | sub text_size { |
2299 | my ($self, $text, $indent) = @_; |
2299 | my ($self, $text, $indent) = @_; |
2300 | |
2300 | |
2301 | my $layout = $self->{layout}; |
2301 | my $layout = $self->{layout}; |
2302 | |
2302 | |
2303 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2303 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2304 | $layout->set_width ($self->{children}[0]{w} - $indent); |
2304 | $layout->set_width ($self->{children}[0]{w} - $indent); |
2305 | $layout->set_markup ($text); |
2305 | $layout->set_markup ($text); |
2306 | |
2306 | |
2307 | ($layout->size)[1] |
2307 | $layout->size |
2308 | } |
2308 | } |
2309 | |
2309 | |
2310 | sub reflow { |
2310 | sub reflow { |
2311 | my ($self) = @_; |
2311 | my ($self) = @_; |
2312 | |
2312 | |
… | |
… | |
2331 | |
2331 | |
2332 | sub add_paragraph { |
2332 | sub add_paragraph { |
2333 | my ($self, $color, $text, $indent) = @_; |
2333 | my ($self, $color, $text, $indent) = @_; |
2334 | |
2334 | |
2335 | for my $line (split /\n/, $text) { |
2335 | for my $line (split /\n/, $text) { |
2336 | my $height = $self->text_height ($line); |
2336 | my ($w, $h) = $self->text_size ($line); |
2337 | $self->{height} += $height; |
2337 | $self->{height} += $h; |
2338 | push @{$self->{par}}, [$height, $color, $indent, $line]; |
2338 | push @{$self->{par}}, [$w + $indent, $h, $color, $indent, $line]; |
2339 | } |
2339 | } |
2340 | |
2340 | |
2341 | $self->{children}[1]->set_range ([$self->{height}, 0, $self->{height}, $self->{h}, 1]); |
2341 | $self->{children}[1]->set_range ([$self->{height}, 0, $self->{height}, $self->{h}, 1]); |
2342 | } |
2342 | } |
2343 | |
2343 | |
… | |
… | |
2349 | return unless $self->{h} > 0; |
2349 | return unless $self->{h} > 0; |
2350 | |
2350 | |
2351 | delete $self->{texture}; |
2351 | delete $self->{texture}; |
2352 | |
2352 | |
2353 | $ROOT->on_post_alloc ($self, sub { |
2353 | $ROOT->on_post_alloc ($self, sub { |
|
|
2354 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
|
|
2355 | |
2354 | if (delete $self->{need_reflow}) { |
2356 | if (delete $self->{need_reflow}) { |
2355 | my $height = 0; |
2357 | my $height = 0; |
2356 | |
2358 | |
2357 | $height += $_->[0] = $self->text_height ($_->[3], $_->[2]) |
2359 | my $layout = $self->{layout}; |
|
|
2360 | |
|
|
2361 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
2362 | |
2358 | for @{$self->{par}}; |
2363 | for (@{$self->{par}}) { |
|
|
2364 | if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support |
|
|
2365 | $layout->set_width ($W - $_->[3]); |
|
|
2366 | $layout->set_markup ($_->[4]); |
|
|
2367 | my ($w, $h) = $layout->size; |
|
|
2368 | $_->[0] = $w + $_->[3]; |
|
|
2369 | $_->[1] = $h; |
|
|
2370 | } |
|
|
2371 | |
|
|
2372 | $height += $_->[1]; |
|
|
2373 | } |
2359 | |
2374 | |
2360 | $self->{height} = $height; |
2375 | $self->{height} = $height; |
2361 | |
2376 | |
2362 | $self->{children}[1]->set_range ([$height, 0, $height, $self->{h}, 1]); |
2377 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2363 | |
2378 | |
2364 | delete $self->{texture}; |
2379 | delete $self->{texture}; |
2365 | } |
2380 | } |
2366 | |
2381 | |
2367 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2382 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2368 | glClearColor 0.5, 0.5, 0.5, 0; |
2383 | glClearColor 0.5, 0.5, 0.5, 0; |
2369 | glClear GL_COLOR_BUFFER_BIT; |
2384 | glClear GL_COLOR_BUFFER_BIT; |
2370 | |
2385 | |
2371 | my $top = int $self->{children}[1]{range}[0]; |
2386 | my $top = int $self->{children}[1]{range}[0]; |
2372 | |
2387 | |
2373 | my $y0 = $top; |
2388 | my $y0 = $top; |
2374 | my $y1 = $top + $self->{h}; |
2389 | my $y1 = $top + $H; |
2375 | |
2390 | |
2376 | my $y = 0; |
2391 | my $y = 0; |
2377 | |
2392 | |
2378 | my $layout = $self->{layout}; |
2393 | my $layout = $self->{layout}; |
2379 | |
2394 | |
2380 | $layout->set_font ($self->{font}) if $self->{font}; |
2395 | $layout->set_font ($self->{font}) if $self->{font}; |
2381 | |
2396 | |
2382 | glEnable GL_BLEND; |
2397 | glEnable GL_BLEND; |
|
|
2398 | #TODO# not correct in windows where rgba is forced off |
2383 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2399 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2384 | |
2400 | |
2385 | for my $par (@{$self->{par}}) { |
2401 | for my $par (@{$self->{par}}) { |
2386 | my $h = $par->[0]; |
2402 | my $h = $par->[1]; |
2387 | |
2403 | |
2388 | if ($y0 < $y + $h && $y < $y1) { |
2404 | if ($y0 < $y + $h && $y < $y1) { |
2389 | $layout->set_foreground (@{ $par->[1] }); |
2405 | $layout->set_foreground (@{ $par->[2] }); |
2390 | $layout->set_width ($self->{w} - $par->[2]); |
2406 | $layout->set_width ($W - $par->[3]); |
2391 | $layout->set_markup ($par->[3]); |
2407 | $layout->set_markup ($par->[4]); |
2392 | |
2408 | |
2393 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2409 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2394 | |
2410 | |
2395 | glRasterPos $par->[2], $y - $y0; |
2411 | glRasterPos $par->[3], $y - $y0; |
2396 | glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data; |
2412 | glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data; |
2397 | } |
2413 | } |
2398 | |
2414 | |
2399 | $y += $h; |
2415 | $y += $h; |
2400 | } |
2416 | } |