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.223 by elmex, Tue May 23 18:10: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);
214}
215
216sub show_centered {
217 my ($self) = @_;
218 return if $self->{parent};
219
220 $self->show;
221
222 $CFClient::UI::ROOT->on_post_alloc (
223 "centered $self" => sub {
224 $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5);
225 },
226 );
207} 227}
208 228
209sub hide { 229sub hide {
210 my ($self) = @_; 230 my ($self) = @_;
211 231
419 Scalar::Util::weaken ($self->{parent} = $parent); 439 Scalar::Util::weaken ($self->{parent} = $parent);
420 440
421 # TODO: req_w _does_change after ->reconfigure 441 # TODO: req_w _does_change after ->reconfigure
422 $self->check_size 442 $self->check_size
423 unless exists $self->{req_w}; 443 unless exists $self->{req_w};
444
445 $self->show;
424} 446}
425 447
426sub check_size { 448sub check_size {
427 my ($self, $forced) = @_; 449 my ($self, $forced) = @_;
428 450
2207 2229
2208 $self->{fontsize} = $fontsize; 2230 $self->{fontsize} = $fontsize;
2209 $self->reflow; 2231 $self->reflow;
2210} 2232}
2211 2233
2234sub size_allocate {
2235 my ($self, $w, $h) = @_;
2236
2237 $self->SUPER::size_allocate ($w, $h);
2238
2239 $self->{layout}->set_font ($self->{font}) if $self->{font};
2240 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2241 $self->{layout}->set_width ($self->{children}[0]{w});
2242
2243 $self->reflow;
2244}
2245
2212sub text_height { 2246sub text_height {
2213 my ($self, $text) = @_; 2247 my ($self, $text, $indent) = @_;
2214 2248
2215 my $layout = $self->{layout}; 2249 my $layout = $self->{layout};
2216 2250
2217 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2251 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2218 $layout->set_width ($self->{children}[0]{w}); 2252 $layout->set_width ($self->{children}[0]{w} - $indent);
2219 $layout->set_markup ($text); 2253 $layout->set_markup ($text);
2220 2254
2221 ($layout->size)[1] 2255 ($layout->size)[1]
2222} 2256}
2223 2257
2226 2260
2227 $self->{need_reflow}++; 2261 $self->{need_reflow}++;
2228 $self->update; 2262 $self->update;
2229} 2263}
2230 2264
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 { 2265sub add_paragraph {
2244 my ($self, $color, $text) = @_; 2266 my ($self, $color, $text, $indent) = @_;
2245 2267
2246 #TODO: intelligently "reformat" paragraph 2268 #TODO: intelligently "reformat" paragraph
2247 2269
2270 for my $line (split /\n/, $text) {
2248 my $height = $self->text_height ($text); 2271 my $height = $self->text_height ($line);
2249
2250 $self->{height} += $height; 2272 $self->{height} += $height;
2251
2252 push @{$self->{par}}, [$height, $color, $text]; 2273 push @{$self->{par}}, [$height, $color, $indent, $line];
2274 }
2253 2275
2254 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; 2276 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
2255 $self->{children}[1]->update; 2277 $self->{children}[1]->update;
2256} 2278}
2257 2279
2266 2288
2267 $ROOT->on_post_alloc ($self, sub { 2289 $ROOT->on_post_alloc ($self, sub {
2268 if (delete $self->{need_reflow}) { 2290 if (delete $self->{need_reflow}) {
2269 my $height = 0; 2291 my $height = 0;
2270 2292
2271 $height += $_->[0] = $self->text_height ($_->[2]) 2293 $height += $_->[0] = $self->text_height ($_->[3], $_->[2])
2272 for @{$self->{par}}; 2294 for @{$self->{par}};
2273 2295
2274 $self->{height} = $height; 2296 $self->{height} = $height;
2275 2297
2276 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2298 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2299 $self->{children}[1]->update;
2277 2300
2278 delete $self->{texture}; 2301 delete $self->{texture};
2279 } 2302 }
2280 2303
2281 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2304 $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; 2305 glClearColor 0.5, 0.5, 0.5, 0;
2283 glClear GL_COLOR_BUFFER_BIT; 2306 glClear GL_COLOR_BUFFER_BIT;
2284 2307
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]; 2308 my $top = int $self->{children}[1]{range}[0];
2289 2309
2290 my $y0 = $top; 2310 my $y0 = $top;
2291 my $y1 = $top + $self->{h}; 2311 my $y1 = $top + $self->{h};
2292 2312
2294 2314
2295 my $layout = $self->{layout}; 2315 my $layout = $self->{layout};
2296 2316
2297 $layout->set_font ($self->{font}) if $self->{font}; 2317 $layout->set_font ($self->{font}) if $self->{font};
2298 2318
2319 glEnable GL_BLEND;
2320 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2321
2299 for my $par (@{$self->{par}}) { 2322 for my $par (@{$self->{par}}) {
2300 my $h = $par->[0]; 2323 my $h = $par->[0];
2301 2324
2302 if ($y0 < $y + $h && $y < $y1) { 2325 if ($y0 < $y + $h && $y < $y1) {
2303 $layout->set_foreground (@{ $par->[1] }); 2326 $layout->set_foreground (@{ $par->[1] });
2327 $layout->set_width ($self->{w} - $par->[2]);
2304 $layout->set_markup ($par->[2]); 2328 $layout->set_markup ($par->[3]);
2305 2329
2306 my ($W, $H) = $layout->size; 2330 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2307 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); 2331
2332 glRasterPos $par->[2], $y - $y0;
2333 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2308 } 2334 }
2309 2335
2310 $y += $h; 2336 $y += $h;
2311 } 2337 }
2312 2338
2313 glDisable GL_TEXTURE_2D; 2339 glDisable GL_BLEND;
2314 }; 2340 };
2315 }); 2341 });
2316} 2342}
2317 2343
2318sub _draw { 2344sub _draw {
2515 2541
2516sub size_request { 2542sub size_request {
2517 (32, 8) 2543 (32, 8)
2518} 2544}
2519 2545
2546sub update {
2547 my ($self) = @_;
2548
2549 return unless $self->{visible};
2550
2551 $self->SUPER::update;
2552}
2553
2520sub _draw { 2554sub _draw {
2521 my ($self) = @_; 2555 my ($self) = @_;
2522 2556
2523 return unless $::CONN;#d# manage and cache textures differently 2557 return unless $::CONN;#d# manage and cache textures differently
2524 2558
2612 } elsif ($ev->{button} == 2) { 2646 } elsif ($ev->{button} == 2) {
2613 $::CONN->send ("apply $item->{tag}"); 2647 $::CONN->send ("apply $item->{tag}");
2614 } elsif ($ev->{button} == 3) { 2648 } elsif ($ev->{button} == 3) {
2615 my @menu_items = ( 2649 my @menu_items = (
2616 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2650 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2617 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2651 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2618 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2652 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2653 (
2654 $item->{flags} & Crossfire::Protocol::F_LOCKED
2655 ? (
2656 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2657 )
2658 : (
2659 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2619 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2660 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2620 [ 2661 )
2621 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2622 sub { $::CONN->send ("lock $item->{tag}") },
2623 ], 2662 ),
2624 ); 2663 );
2625 2664
2626 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2665 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2627 } 2666 }
2628 2667
2971 $child->{x} = int $child->{x}; 3010 $child->{x} = int $child->{x};
2972 $child->{y} = int $child->{y}; 3011 $child->{y} = int $child->{y};
2973 } 3012 }
2974 3013
2975 $self->SUPER::add (@children); 3014 $self->SUPER::add (@children);
3015
3016 while (@children) {
3017 my $w = pop @children;
3018 push @children, $w->children;
3019 $w->{visible} = 1;
3020 }
3021}
3022
3023sub remove {
3024 my ($self, @children) = @_;
3025
3026 $self->SUPER::remove (@children);
3027
3028 while (@children) {
3029 my $w = pop @children;
3030 push @children, $w->children;
3031 delete $w->{visible};
3032 }
2976} 3033}
2977 3034
2978sub on_refresh { 3035sub on_refresh {
2979 my ($self, $id, $cb) = @_; 3036 my ($self, $id, $cb) = @_;
2980 3037
3049 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3106 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
3050 glClear GL_COLOR_BUFFER_BIT; 3107 glClear GL_COLOR_BUFFER_BIT;
3051 3108
3052 glMatrixMode GL_PROJECTION; 3109 glMatrixMode GL_PROJECTION;
3053 glLoadIdentity; 3110 glLoadIdentity;
3054 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3111 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3055 glMatrixMode GL_MODELVIEW; 3112 glMatrixMode GL_MODELVIEW;
3056 glLoadIdentity; 3113 glLoadIdentity;
3057 3114
3058 $self->_draw; 3115 $self->_draw;
3059} 3116}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines