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.227 by root, Wed May 24 03:29:20 2006 UTC vs.
Revision 1.229 by root, Wed May 24 21:49:58 2006 UTC

816 816
817 my $slider = new CFClient::UI::Slider 817 my $slider = new CFClient::UI::Slider
818 vertical => 1, 818 vertical => 1,
819 range => [0, 0, 1, 0.01], # HACK fix 819 range => [0, 0, 1, 0.01], # HACK fix
820 connect_changed => sub { 820 connect_changed => sub {
821 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); 821 $self->{vp}->set_offset (0, $_[1]);
822 }, 822 },
823 ; 823 ;
824 824
825 $self = $class->SUPER::new ( 825 $self = $class->SUPER::new (
826 vp => (new CFClient::UI::ViewPort expand => 1), 826 vp => (new CFClient::UI::ViewPort expand => 1),
831 $self->{vp}->add ($self->{scrolled}); 831 $self->{vp}->add ($self->{scrolled});
832 $self->add ($self->{vp}); 832 $self->add ($self->{vp});
833 $self->add ($self->{slider}); 833 $self->add ($self->{slider});
834 834
835 $self 835 $self
836}
837
838sub size_allocate {
839 my ($self, $w, $h) = @_;
840
841 $self->SUPER::size_allocate ($w, $h);
842
843 my $child = $self->{vp}->child;
844 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
836} 845}
837 846
838#TODO# update range on size_allocate depending on child 847#TODO# update range on size_allocate depending on child
839# update viewport offset on scroll 848# update viewport offset on scroll
840 849
2293 $self->{layout}->set_width ($self->{children}[0]{w}); 2302 $self->{layout}->set_width ($self->{children}[0]{w});
2294 2303
2295 $self->reflow; 2304 $self->reflow;
2296} 2305}
2297 2306
2298sub text_height { 2307sub text_size {
2299 my ($self, $text, $indent) = @_; 2308 my ($self, $text, $indent) = @_;
2300 2309
2301 my $layout = $self->{layout}; 2310 my $layout = $self->{layout};
2302 2311
2303 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2312 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2304 $layout->set_width ($self->{children}[0]{w} - $indent); 2313 $layout->set_width ($self->{children}[0]{w} - $indent);
2305 $layout->set_markup ($text); 2314 $layout->set_markup ($text);
2306 2315
2307 ($layout->size)[1] 2316 $layout->size
2308} 2317}
2309 2318
2310sub reflow { 2319sub reflow {
2311 my ($self) = @_; 2320 my ($self) = @_;
2312 2321
2331 2340
2332sub add_paragraph { 2341sub add_paragraph {
2333 my ($self, $color, $text, $indent) = @_; 2342 my ($self, $color, $text, $indent) = @_;
2334 2343
2335 for my $line (split /\n/, $text) { 2344 for my $line (split /\n/, $text) {
2336 my $height = $self->text_height ($line); 2345 my ($w, $h) = $self->text_size ($line);
2337 $self->{height} += $height; 2346 $self->{height} += $h;
2338 push @{$self->{par}}, [$height, $color, $indent, $line]; 2347 push @{$self->{par}}, [$w + $indent, $h, $color, $indent, $line];
2339 } 2348 }
2340 2349
2341 $self->{children}[1]->set_range ([$self->{height}, 0, $self->{height}, $self->{h}, 1]); 2350 $self->{children}[1]->set_range ([$self->{height}, 0, $self->{height}, $self->{h}, 1]);
2342} 2351}
2343 2352
2349 return unless $self->{h} > 0; 2358 return unless $self->{h} > 0;
2350 2359
2351 delete $self->{texture}; 2360 delete $self->{texture};
2352 2361
2353 $ROOT->on_post_alloc ($self, sub { 2362 $ROOT->on_post_alloc ($self, sub {
2363 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2364
2354 if (delete $self->{need_reflow}) { 2365 if (delete $self->{need_reflow}) {
2355 my $height = 0; 2366 my $height = 0;
2356 2367
2357 $height += $_->[0] = $self->text_height ($_->[3], $_->[2]) 2368 my $layout = $self->{layout};
2369
2370 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2371
2358 for @{$self->{par}}; 2372 for (@{$self->{par}}) {
2373 if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support
2374 $layout->set_width ($W - $_->[3]);
2375 $layout->set_markup ($_->[4]);
2376 my ($w, $h) = $layout->size;
2377 $_->[0] = $w + $_->[3];
2378 $_->[1] = $h;
2379 }
2380
2381 $height += $_->[1];
2382 }
2359 2383
2360 $self->{height} = $height; 2384 $self->{height} = $height;
2361 2385
2362 $self->{children}[1]->set_range ([$height, 0, $height, $self->{h}, 1]); 2386 $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]);
2363 2387
2364 delete $self->{texture}; 2388 delete $self->{texture};
2365 } 2389 }
2366 2390
2367 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2391 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub {
2368 glClearColor 0.5, 0.5, 0.5, 0; 2392 glClearColor 0.5, 0.5, 0.5, 0;
2369 glClear GL_COLOR_BUFFER_BIT; 2393 glClear GL_COLOR_BUFFER_BIT;
2370 2394
2371 my $top = int $self->{children}[1]{range}[0]; 2395 my $top = int $self->{children}[1]{range}[0];
2372 2396
2373 my $y0 = $top; 2397 my $y0 = $top;
2374 my $y1 = $top + $self->{h}; 2398 my $y1 = $top + $H;
2375 2399
2376 my $y = 0; 2400 my $y = 0;
2377 2401
2378 my $layout = $self->{layout}; 2402 my $layout = $self->{layout};
2379 2403
2380 $layout->set_font ($self->{font}) if $self->{font}; 2404 $layout->set_font ($self->{font}) if $self->{font};
2381 2405
2382 glEnable GL_BLEND; 2406 glEnable GL_BLEND;
2407 #TODO# not correct in windows where rgba is forced off
2383 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2408 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2384 2409
2385 for my $par (@{$self->{par}}) { 2410 for my $par (@{$self->{par}}) {
2386 my $h = $par->[0]; 2411 my $h = $par->[1];
2387 2412
2388 if ($y0 < $y + $h && $y < $y1) { 2413 if ($y0 < $y + $h && $y < $y1) {
2389 $layout->set_foreground (@{ $par->[1] }); 2414 $layout->set_foreground (@{ $par->[2] });
2390 $layout->set_width ($self->{w} - $par->[2]); 2415 $layout->set_width ($W - $par->[3]);
2391 $layout->set_markup ($par->[3]); 2416 $layout->set_markup ($par->[4]);
2392 2417
2393 my ($w, $h, $data, $format, $internalformat) = $layout->render; 2418 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2394 2419
2395 glRasterPos $par->[2], $y - $y0; 2420 glRasterPos $par->[3], $y - $y0;
2396 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data; 2421 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2397 } 2422 }
2398 2423
2399 $y += $h; 2424 $y += $h;
2400 } 2425 }
3072} 3097}
3073 3098
3074sub add { 3099sub add {
3075 my ($self, @children) = @_; 3100 my ($self, @children) = @_;
3076 3101
3102 for (my @widgets = @children; my $w = pop @widgets; ) {
3103 push @widgets, $w->children;
3104 $w->{root} = $self;
3105 $w->{visible} = 1;
3106 }
3107
3077 for my $child (@children) { 3108 for my $child (@children) {
3078 $child->{toplevel} = 1; 3109 $child->{toplevel} = 1;
3079 3110
3080 # integerise window positions 3111 # integerise window positions
3081 $child->{x} = int $child->{x}; 3112 $child->{x} = int $child->{x};
3082 $child->{y} = int $child->{y}; 3113 $child->{y} = int $child->{y};
3083 } 3114 }
3084 3115
3085 $self->SUPER::add (@children); 3116 $self->SUPER::add (@children);
3086
3087 while (@children) {
3088 my $w = pop @children;
3089 push @children, $w->children;
3090 $w->{visible} = 1;
3091 }
3092} 3117}
3093 3118
3094sub remove { 3119sub remove {
3095 my ($self, @children) = @_; 3120 my ($self, @children) = @_;
3096 3121

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines