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.217 by root, Fri May 19 23:18:42 2006 UTC vs.
Revision 1.222 by root, Mon May 22 03:59:51 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) = @_;
198 %$self = (); 206 %$self = ();
199} 207}
200 208
201sub show { 209sub show {
202 my ($self) = @_; 210 my ($self) = @_;
203
204 return if $self->{parent}; 211 return if $self->{parent};
205 212
206 $CFClient::UI::ROOT->add ($self); 213 $CFClient::UI::ROOT->add ($self);
207} 214}
208 215
419 Scalar::Util::weaken ($self->{parent} = $parent); 426 Scalar::Util::weaken ($self->{parent} = $parent);
420 427
421 # TODO: req_w _does_change after ->reconfigure 428 # TODO: req_w _does_change after ->reconfigure
422 $self->check_size 429 $self->check_size
423 unless exists $self->{req_w}; 430 unless exists $self->{req_w};
431
432 $self->show;
424} 433}
425 434
426sub check_size { 435sub check_size {
427 my ($self, $forced) = @_; 436 my ($self, $forced) = @_;
428 437
2207 2216
2208 $self->{fontsize} = $fontsize; 2217 $self->{fontsize} = $fontsize;
2209 $self->reflow; 2218 $self->reflow;
2210} 2219}
2211 2220
2221sub size_allocate {
2222 my ($self, $w, $h) = @_;
2223
2224 $self->SUPER::size_allocate ($w, $h);
2225
2226 $self->{layout}->set_font ($self->{font}) if $self->{font};
2227 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2228 $self->{layout}->set_width ($self->{children}[0]{w});
2229
2230 $self->reflow;
2231}
2232
2212sub text_height { 2233sub text_height {
2213 my ($self, $text) = @_; 2234 my ($self, $text, $indent) = @_;
2214 2235
2215 my $layout = $self->{layout}; 2236 my $layout = $self->{layout};
2216 2237
2217 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2238 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2218 $layout->set_width ($self->{children}[0]{w}); 2239 $layout->set_width ($self->{children}[0]{w} - $indent);
2219 $layout->set_markup ($text); 2240 $layout->set_markup ($text);
2220 2241
2221 ($layout->size)[1] 2242 ($layout->size)[1]
2222} 2243}
2223 2244
2226 2247
2227 $self->{need_reflow}++; 2248 $self->{need_reflow}++;
2228 $self->update; 2249 $self->update;
2229} 2250}
2230 2251
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 { 2252sub add_paragraph {
2244 my ($self, $color, $text) = @_; 2253 my ($self, $color, $text, $indent) = @_;
2245 2254
2246 #TODO: intelligently "reformat" paragraph 2255 #TODO: intelligently "reformat" paragraph
2247 2256
2257 for my $line (split /\n/, $text) {
2248 my $height = $self->text_height ($text); 2258 my $height = $self->text_height ($line);
2249
2250 $self->{height} += $height; 2259 $self->{height} += $height;
2251
2252 push @{$self->{par}}, [$height, $color, $text]; 2260 push @{$self->{par}}, [$height, $color, $indent, $line];
2261 }
2253 2262
2254 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; 2263 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
2255 $self->{children}[1]->update; 2264 $self->{children}[1]->update;
2256} 2265}
2257 2266
2266 2275
2267 $ROOT->on_post_alloc ($self, sub { 2276 $ROOT->on_post_alloc ($self, sub {
2268 if (delete $self->{need_reflow}) { 2277 if (delete $self->{need_reflow}) {
2269 my $height = 0; 2278 my $height = 0;
2270 2279
2271 $height += $_->[0] = $self->text_height ($_->[2]) 2280 $height += $_->[0] = $self->text_height ($_->[3], $_->[2])
2272 for @{$self->{par}}; 2281 for @{$self->{par}};
2273 2282
2274 $self->{height} = $height; 2283 $self->{height} = $height;
2275 2284
2276 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2285 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2286 $self->{children}[1]->update;
2277 2287
2278 delete $self->{texture}; 2288 delete $self->{texture};
2279 } 2289 }
2280 2290
2281 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2291 $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; 2292 glClearColor 0.5, 0.5, 0.5, 0;
2283 glClear GL_COLOR_BUFFER_BIT; 2293 glClear GL_COLOR_BUFFER_BIT;
2284 2294
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]; 2295 my $top = int $self->{children}[1]{range}[0];
2289 2296
2290 my $y0 = $top; 2297 my $y0 = $top;
2291 my $y1 = $top + $self->{h}; 2298 my $y1 = $top + $self->{h};
2292 2299
2294 2301
2295 my $layout = $self->{layout}; 2302 my $layout = $self->{layout};
2296 2303
2297 $layout->set_font ($self->{font}) if $self->{font}; 2304 $layout->set_font ($self->{font}) if $self->{font};
2298 2305
2306 glEnable GL_BLEND;
2307 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2308
2299 for my $par (@{$self->{par}}) { 2309 for my $par (@{$self->{par}}) {
2300 my $h = $par->[0]; 2310 my $h = $par->[0];
2301 2311
2302 if ($y0 < $y + $h && $y < $y1) { 2312 if ($y0 < $y + $h && $y < $y1) {
2303 $layout->set_foreground (@{ $par->[1] }); 2313 $layout->set_foreground (@{ $par->[1] });
2314 $layout->set_width ($self->{w} - $par->[2]);
2304 $layout->set_markup ($par->[2]); 2315 $layout->set_markup ($par->[3]);
2305 2316
2306 my ($W, $H) = $layout->size; 2317 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2307 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); 2318
2319 glRasterPos $par->[2], $y - $y0;
2320 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2308 } 2321 }
2309 2322
2310 $y += $h; 2323 $y += $h;
2311 } 2324 }
2312 2325
2313 glDisable GL_TEXTURE_2D; 2326 glDisable GL_BLEND;
2314 }; 2327 };
2315 }); 2328 });
2316} 2329}
2317 2330
2318sub _draw { 2331sub _draw {
2515 2528
2516sub size_request { 2529sub size_request {
2517 (32, 8) 2530 (32, 8)
2518} 2531}
2519 2532
2533sub update {
2534 my ($self) = @_;
2535
2536 return unless $self->{visible};
2537
2538 $self->SUPER::update;
2539}
2540
2520sub _draw { 2541sub _draw {
2521 my ($self) = @_; 2542 my ($self) = @_;
2522 2543
2523 return unless $::CONN;#d# manage and cache textures differently 2544 return unless $::CONN;#d# manage and cache textures differently
2524 2545
2612 } elsif ($ev->{button} == 2) { 2633 } elsif ($ev->{button} == 2) {
2613 $::CONN->send ("apply $item->{tag}"); 2634 $::CONN->send ("apply $item->{tag}");
2614 } elsif ($ev->{button} == 3) { 2635 } elsif ($ev->{button} == 3) {
2615 my @menu_items = ( 2636 my @menu_items = (
2616 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2637 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2617 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2638 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2618 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2639 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2640 (
2641 $item->{flags} & Crossfire::Protocol::F_LOCKED
2642 ? (
2643 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2644 )
2645 : (
2646 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2619 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2647 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2620 [ 2648 )
2621 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2622 sub { $::CONN->send ("lock $item->{tag}") },
2623 ], 2649 ),
2624 ); 2650 );
2625 2651
2626 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2652 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2627 } 2653 }
2628 2654
2971 $child->{x} = int $child->{x}; 2997 $child->{x} = int $child->{x};
2972 $child->{y} = int $child->{y}; 2998 $child->{y} = int $child->{y};
2973 } 2999 }
2974 3000
2975 $self->SUPER::add (@children); 3001 $self->SUPER::add (@children);
3002
3003 while (@children) {
3004 my $w = pop @children;
3005 push @children, $w->children;
3006 $w->{visible} = 1;
3007 }
3008}
3009
3010sub remove {
3011 my ($self, @children) = @_;
3012
3013 $self->SUPER::remove (@children);
3014
3015 while (@children) {
3016 my $w = pop @children;
3017 push @children, $w->children;
3018 delete $w->{visible};
3019 }
2976} 3020}
2977 3021
2978sub on_refresh { 3022sub on_refresh {
2979 my ($self, $id, $cb) = @_; 3023 my ($self, $id, $cb) = @_;
2980 3024
3049 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3093 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
3050 glClear GL_COLOR_BUFFER_BIT; 3094 glClear GL_COLOR_BUFFER_BIT;
3051 3095
3052 glMatrixMode GL_PROJECTION; 3096 glMatrixMode GL_PROJECTION;
3053 glLoadIdentity; 3097 glLoadIdentity;
3054 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3098 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3055 glMatrixMode GL_MODELVIEW; 3099 glMatrixMode GL_MODELVIEW;
3056 glLoadIdentity; 3100 glLoadIdentity;
3057 3101
3058 $self->_draw; 3102 $self->_draw;
3059} 3103}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines