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.221 by root, Mon May 22 03:48:50 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) = @_;
199} 207}
200 208
201sub show { 209sub show {
202 my ($self) = @_; 210 my ($self) = @_;
203 211
212 for (my @w = $self; @w; ) {
213 my $w = pop @w;
214 push @w, $w->children;
215 $w->{visible} = 1;
216 }
217
204 return if $self->{parent}; 218 return if $self->{parent};
205 219
206 $CFClient::UI::ROOT->add ($self); 220 $CFClient::UI::ROOT->add ($self);
207} 221}
208 222
209sub hide { 223sub hide {
210 my ($self) = @_; 224 my ($self) = @_;
225
226 for (my @w = $self; @w; ) {
227 my $w = pop @w;
228 push @w, $w->children;
229 $w->{visible} = 1;
230 }
211 231
212 undef $GRAB if $GRAB == $self; 232 undef $GRAB if $GRAB == $self;
213 undef $HOVER if $HOVER == $self; 233 undef $HOVER if $HOVER == $self;
214 234
215 $self->{parent}->remove ($self) 235 $self->{parent}->remove ($self)
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 {
2612 } elsif ($ev->{button} == 2) { 2638 } elsif ($ev->{button} == 2) {
2613 $::CONN->send ("apply $item->{tag}"); 2639 $::CONN->send ("apply $item->{tag}");
2614 } elsif ($ev->{button} == 3) { 2640 } elsif ($ev->{button} == 3) {
2615 my @menu_items = ( 2641 my @menu_items = (
2616 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2642 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2617 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2643 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2618 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2644 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2645 (
2646 $item->{flags} & Crossfire::Protocol::F_LOCKED
2647 ? (
2648 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2649 )
2650 : (
2651 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2619 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2652 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2620 [ 2653 )
2621 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2622 sub { $::CONN->send ("lock $item->{tag}") },
2623 ], 2654 ),
2624 ); 2655 );
2625 2656
2626 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2657 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2627 } 2658 }
2628 2659
3049 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3080 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
3050 glClear GL_COLOR_BUFFER_BIT; 3081 glClear GL_COLOR_BUFFER_BIT;
3051 3082
3052 glMatrixMode GL_PROJECTION; 3083 glMatrixMode GL_PROJECTION;
3053 glLoadIdentity; 3084 glLoadIdentity;
3054 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3085 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3055 glMatrixMode GL_MODELVIEW; 3086 glMatrixMode GL_MODELVIEW;
3056 glLoadIdentity; 3087 glLoadIdentity;
3057 3088
3058 $self->_draw; 3089 $self->_draw;
3059} 3090}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines