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.212 by elmex, Wed May 17 14:55:14 2006 UTC vs.
Revision 1.220 by root, Mon May 22 03:28:55 2006 UTC

136 $rem += $_ - $i; 136 $rem += $_ - $i;
137 $_ = $i; 137 $_ = $i;
138 } 138 }
139} 139}
140 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;
147}
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) = @_;
144 152
153 # make a copy, otherwise for complains about freed values.
145 for my $widget (values %WIDGET) { 154 my @widgets = values %WIDGET;
155
156 for my $widget (@widgets) {
146 if ($widget->{toplevel}) { 157 if ($widget->{toplevel}) {
147 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; 158 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x};
148 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 159 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
149 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; 160 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w};
150 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; 161 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
688 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 699 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
689 glClearColor 0, 0, 0, 0; 700 glClearColor 0, 0, 0, 0;
690 glClear GL_COLOR_BUFFER_BIT; 701 glClear GL_COLOR_BUFFER_BIT;
691 702
692 $self->_render; 703 $self->_render;
693# glColorMask 1, 1, 1, 0;
694# glEnable GL_BLEND;
695# glBlendFunc GL_SRC_ALPHA, GL_ZERO;
696# glRasterPos 0, 0;
697# glCopyPixels 0, 0, $self->{w}, $self->{h};
698# glDisable GL_BLEND;
699# glColorMask 1, 1, 1, 1;
700 }; 704 };
701} 705}
702 706
703sub _draw { 707sub _draw {
704 my ($self) = @_; 708 my ($self) = @_;
708 my $tex = $self->{texture} 712 my $tex = $self->{texture}
709 or return; 713 or return;
710 714
711 glEnable GL_TEXTURE_2D; 715 glEnable GL_TEXTURE_2D;
712 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 716 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
713 glColor 0, 0, 0, 1; 717 glColor 1, 1, 1, 1;
714 718
715 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 719 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
716 720
717 glDisable GL_TEXTURE_2D; 721 glDisable GL_TEXTURE_2D;
718} 722}
801 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); 805 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h}));
802 }, 806 },
803 ; 807 ;
804 808
805 $self = $class->SUPER::new ( 809 $self = $class->SUPER::new (
806 vp => (new CFClient::UI::ViewPort), 810 vp => (new CFClient::UI::ViewPort expand => 1),
807 slider => $slider, 811 slider => $slider,
808 @_, 812 @_,
809 ); 813 );
810 814
811 $self->{vp}->add ($self->{scrolled}); 815 $self->{vp}->add ($self->{scrolled});
1297 #bg => none 1301 #bg => none
1298 #active_bg => none 1302 #active_bg => none
1299 #font => default_font 1303 #font => default_font
1300 #text => initial text 1304 #text => initial text
1301 #markup => initial narkup 1305 #markup => initial narkup
1306 #max_w => maximum pixel width
1307 ellipsise => 3, # end
1302 layout => (new CFClient::Layout), 1308 layout => (new CFClient::Layout),
1303 fontsize => 1, 1309 fontsize => 1,
1304 align => -1, 1310 align => -1,
1305 valign => -1, 1311 valign => -1,
1306 padding => 2, 1312 padding => 2,
1371sub size_request { 1377sub size_request {
1372 my ($self) = @_; 1378 my ($self) = @_;
1373 1379
1374 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1380 $self->{layout}->set_font ($self->{font}) if $self->{font};
1375 $self->{layout}->set_width ($self->{max_w} || -1); 1381 $self->{layout}->set_width ($self->{max_w} || -1);
1382 $self->{layout}->set_ellipsise ($self->{ellipsise});
1383 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1376 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1384 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1377 1385
1378 my ($w, $h) = $self->{layout}->size; 1386 my ($w, $h) = $self->{layout}->size;
1379 1387
1380 if (exists $self->{template}) { 1388 if (exists $self->{template}) {
1416 1424
1417 my $tex = $self->{texture} ||= do { 1425 my $tex = $self->{texture} ||= do {
1418 $self->{layout}->set_foreground (@{$self->{fg}}); 1426 $self->{layout}->set_foreground (@{$self->{fg}});
1419 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1427 $self->{layout}->set_font ($self->{font}) if $self->{font};
1420 $self->{layout}->set_width ($self->{w}); 1428 $self->{layout}->set_width ($self->{w});
1429 $self->{layout}->set_ellipsise ($self->{ellipsise});
1430 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1421 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1431 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1422 1432
1423 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1433 my $tex = new_from_layout CFClient::Texture $self->{layout};
1424 1434
1425 $self->{ox} = int ($self->{align} < 0 ? $self->{padding} 1435 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1426 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1436 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
2048 range => [0, 0, 100, 10], 2058 range => [0, 0, 100, 10],
2049 req_w => $::WIDTH / 80, 2059 req_w => $::WIDTH / 80,
2050 req_h => $::WIDTH / 80, 2060 req_h => $::WIDTH / 80,
2051 vertical => 0, 2061 vertical => 0,
2052 can_hover => 1, 2062 can_hover => 1,
2053 inner_pad => .05, 2063 inner_pad => 0.02,
2054 @_ 2064 @_
2055 ); 2065 );
2056 2066
2057 $self->set_value ($self->{range}[0]); 2067 $self->set_value ($self->{range}[0]);
2058 $self->update; 2068 $self->update;
2148 glScale $self->{w}, $self->{h}; 2158 glScale $self->{w}, $self->{h};
2149 2159
2150 if ($self->{vertical}) { 2160 if ($self->{vertical}) {
2151 # draw a vertical slider like a rotated horizontal slider 2161 # draw a vertical slider like a rotated horizontal slider
2152 2162
2163 glTranslate 1, 0, 0;
2153 glRotate 90, 0, 0, 1; 2164 glRotate 90, 0, 0, 1;
2154 glTranslate 0, 1, 0;
2155 } 2165 }
2156 2166
2157 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2167 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2158 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2168 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2159 2169
2205 2215
2206 $self->{fontsize} = $fontsize; 2216 $self->{fontsize} = $fontsize;
2207 $self->reflow; 2217 $self->reflow;
2208} 2218}
2209 2219
2220sub size_allocate {
2221 my ($self, $w, $h) = @_;
2222
2223 $self->SUPER::size_allocate ($w, $h);
2224
2225 $self->{layout}->set_font ($self->{font}) if $self->{font};
2226 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2227 $self->{layout}->set_width ($self->{children}[0]{w});
2228
2229 $self->reflow;
2230}
2231
2210sub text_height { 2232sub text_height {
2211 my ($self, $text) = @_; 2233 my ($self, $text, $indent) = @_;
2212 2234
2213 my $layout = $self->{layout}; 2235 my $layout = $self->{layout};
2214 2236
2215 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2237 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2216 $layout->set_width ($self->{children}[0]{w}); 2238 $layout->set_width ($self->{children}[0]{w} - $indent);
2217 $layout->set_markup ($text); 2239 $layout->set_markup ($text);
2218 2240
2219 ($layout->size)[1] 2241 ($layout->size)[1]
2220} 2242}
2221 2243
2224 2246
2225 $self->{need_reflow}++; 2247 $self->{need_reflow}++;
2226 $self->update; 2248 $self->update;
2227} 2249}
2228 2250
2229sub size_allocate {
2230 my ($self, $w, $h) = @_;
2231
2232 $self->SUPER::size_allocate ($w, $h);
2233
2234 $self->{layout}->set_font ($self->{font}) if $self->{font};
2235 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2236 $self->{layout}->set_width ($self->{children}[0]{w});
2237
2238 $self->reflow;
2239}
2240
2241sub add_paragraph { 2251sub add_paragraph {
2242 my ($self, $color, $text) = @_; 2252 my ($self, $color, $text, $indent) = @_;
2243 2253
2244 #TODO: intelligently "reformat" paragraph 2254 #TODO: intelligently "reformat" paragraph
2245 2255
2256 for my $line (split /\n/, $text) {
2246 my $height = $self->text_height ($text); 2257 my $height = $self->text_height ($line);
2247
2248 $self->{height} += $height; 2258 $self->{height} += $height;
2249
2250 push @{$self->{par}}, [$height, $color, $text]; 2259 push @{$self->{par}}, [$height, $color, $indent, $line];
2260 }
2251 2261
2252 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; 2262 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
2253 $self->{children}[1]->update; 2263 $self->{children}[1]->update;
2254} 2264}
2255 2265
2264 2274
2265 $ROOT->on_post_alloc ($self, sub { 2275 $ROOT->on_post_alloc ($self, sub {
2266 if (delete $self->{need_reflow}) { 2276 if (delete $self->{need_reflow}) {
2267 my $height = 0; 2277 my $height = 0;
2268 2278
2269 $height += $_->[0] = $self->text_height ($_->[2]) 2279 $height += $_->[0] = $self->text_height ($_->[3], $_->[2])
2270 for @{$self->{par}}; 2280 for @{$self->{par}};
2271 2281
2272 $self->{height} = $height; 2282 $self->{height} = $height;
2273 2283
2274 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2284 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2285 $self->{children}[1]->update;
2275 2286
2276 delete $self->{texture}; 2287 delete $self->{texture};
2277 } 2288 }
2278 2289
2279 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2290 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2280 glClearColor 0, 0, 0, 0; 2291 glClearColor 0.5, 0.5, 0.5, 0;
2281 glClear GL_COLOR_BUFFER_BIT; 2292 glClear GL_COLOR_BUFFER_BIT;
2282
2283 glEnable GL_TEXTURE_2D;
2284 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2285 2293
2286 my $top = int $self->{children}[1]{range}[0]; 2294 my $top = int $self->{children}[1]{range}[0];
2287 2295
2288 my $y0 = $top; 2296 my $y0 = $top;
2289 my $y1 = $top + $self->{h}; 2297 my $y1 = $top + $self->{h};
2292 2300
2293 my $layout = $self->{layout}; 2301 my $layout = $self->{layout};
2294 2302
2295 $layout->set_font ($self->{font}) if $self->{font}; 2303 $layout->set_font ($self->{font}) if $self->{font};
2296 2304
2305 glEnable GL_BLEND;
2306 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2307
2297 for my $par (@{$self->{par}}) { 2308 for my $par (@{$self->{par}}) {
2298 my $h = $par->[0]; 2309 my $h = $par->[0];
2299 2310
2300 if ($y0 < $y + $h && $y < $y1) { 2311 if ($y0 < $y + $h && $y < $y1) {
2301 $layout->set_foreground (@{ $par->[1] }); 2312 $layout->set_foreground (@{ $par->[1] });
2313 $layout->set_width ($self->{w} - $par->[2]);
2302 $layout->set_markup ($par->[2]); 2314 $layout->set_markup ($par->[3]);
2303 2315
2304 my ($W, $H) = $layout->size; 2316 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2305 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); 2317
2318 glRasterPos $par->[2], $y - $y0;
2319 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2306 } 2320 }
2307 2321
2308 $y += $h; 2322 $y += $h;
2309 } 2323 }
2310 2324
2311 glDisable GL_TEXTURE_2D; 2325 glDisable GL_BLEND;
2312 }; 2326 };
2313 }); 2327 });
2314} 2328}
2315 2329
2316sub _draw { 2330sub _draw {
2317 my ($self) = @_; 2331 my ($self) = @_;
2318 2332
2319 glEnable GL_TEXTURE_2D; 2333 glEnable GL_TEXTURE_2D;
2320 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2334 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2321 glColor 1, 1, 1, 1; 2335 glColor 1, 1, 1, 1;
2322 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2336 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2323 glDisable GL_TEXTURE_2D; 2337 glDisable GL_TEXTURE_2D;
2324 2338
2325 $self->{children}[1]->draw; 2339 $self->{children}[1]->draw;
2326 2340
2327} 2341}
2426 2440
2427sub set_tooltip_from { 2441sub set_tooltip_from {
2428 my ($self, $widget) = @_; 2442 my ($self, $widget) = @_;
2429 2443
2430 $self->add (new CFClient::UI::Label 2444 $self->add (new CFClient::UI::Label
2431 markup => $widget->{tooltip}, 2445 markup => $widget->{tooltip},
2432 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2446 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2433 fontsize => 0.8, 2447 fontsize => 0.8,
2434 fg => [0, 0, 0, 1], 2448 fg => [0, 0, 0, 1],
2449 ellipsise => 0,
2435 font => ($widget->{tooltip_font} || $::FONT_PROP), 2450 font => ($widget->{tooltip_font} || $::FONT_PROP),
2436 ); 2451 );
2437} 2452}
2438 2453
2439sub size_request { 2454sub size_request {
2440 my ($self) = @_; 2455 my ($self) = @_;
2486use CFClient::OpenGL; 2501use CFClient::OpenGL;
2487 2502
2488sub new { 2503sub new {
2489 my $class = shift; 2504 my $class = shift;
2490 2505
2491 $class->SUPER::new ( 2506 my $self = $class->SUPER::new (
2492 aspect => 1, 2507 aspect => 1,
2493 @_, 2508 @_,
2494 ) 2509 );
2510
2511 if ($self->{anim} && $self->{animspeed}) {
2512 Scalar::Util::weaken (my $widget = $self);
2513
2514 $self->{timer} = Event->timer (
2515 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
2516 hard => 1,
2517 interval => $self->{animspeed},
2518 cb => sub {
2519 ++$widget->{frame};
2520 $widget->update;
2521 },
2522 );
2523 }
2524
2525 $self
2495} 2526}
2496 2527
2497sub size_request { 2528sub size_request {
2498 (32, 8) 2529 (32, 8)
2499} 2530}
2500 2531
2501sub _draw { 2532sub _draw {
2502 my ($self) = @_; 2533 my ($self) = @_;
2503 2534
2504 return unless $::CONN;#d# manage and cache textures differently 2535 return unless $::CONN;#d# manage and cache textures differently
2536
2537 my $face;
2538
2539 if ($self->{frame}) {
2540 my $anim = $::CONN->{anim}[$self->{anim}];
2541
2542 $face = $anim->[ $self->{frame} % @$anim ]
2543 if $anim && @$anim;
2544 }
2545
2505 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2546 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2506 2547
2507 # TODO animation
2508 if ($tex) { 2548 if ($tex) {
2509 glEnable GL_TEXTURE_2D; 2549 glEnable GL_TEXTURE_2D;
2510 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2550 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2511 glColor 1, 1, 1, 1; 2551 glColor 1, 1, 1, 1;
2512 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2552 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2513 glDisable GL_TEXTURE_2D; 2553 glDisable GL_TEXTURE_2D;
2514 } 2554 }
2515} 2555}
2516 2556
2557sub DESTROY {
2558 my ($self) = @_;
2559
2560 $self->{timer}->cancel
2561 if $self->{timer};
2562
2563 $self->SUPER::DESTROY;
2564}
2565
2517############################################################################# 2566#############################################################################
2518 2567
2519package CFClient::UI::InventoryItem; 2568package CFClient::UI::InventoryItem;
2520 2569
2521our @ISA = CFClient::UI::HBox::; 2570our @ISA = CFClient::UI::HBox::;
2524 my ($item) = @_; 2573 my ($item) = @_;
2525 2574
2526 my $desc = 2575 my $desc =
2527 $item->{nrof} < 2 2576 $item->{nrof} < 2
2528 ? $item->{name} 2577 ? $item->{name}
2529 : "$item->{nrof} $item->{name_pl}"; 2578 : "$item->{nrof} × $item->{name_pl}";
2530 2579
2531 $item->{flags} & Crossfire::Protocol::F_OPEN 2580 $item->{flags} & Crossfire::Protocol::F_OPEN
2532 and $desc .= " (open)"; 2581 and $desc .= " (open)";
2533 $item->{flags} & Crossfire::Protocol::F_APPLIED 2582 $item->{flags} & Crossfire::Protocol::F_APPLIED
2534 and $desc .= " (applied)"; 2583 and $desc .= " (applied)";
2554 my $item = delete $args{item}; 2603 my $item = delete $args{item};
2555 2604
2556 my $desc = _item_to_desc ($item); 2605 my $desc = _item_to_desc ($item);
2557 2606
2558 my $self = $class->SUPER::new ( 2607 my $self = $class->SUPER::new (
2559 can_hover => 1, 2608 can_hover => 1,
2560 can_events => 1, 2609 can_events => 1,
2561 tooltip => ((CFClient::UI::Label::escape $desc) 2610 tooltip => ((CFClient::UI::Label::escape $desc)
2562 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2611 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2563 connect_button_down => sub { 2612 connect_button_down => sub {
2564 my ($self, $ev, $x, $y) = @_; 2613 my ($self, $ev, $x, $y) = @_;
2565 2614
2566 # todo: maybe put examine on 1? but should just be a tooltip :( 2615 # todo: maybe put examine on 1? but should just be a tooltip :(
2575 } elsif ($ev->{button} == 2) { 2624 } elsif ($ev->{button} == 2) {
2576 $::CONN->send ("apply $item->{tag}"); 2625 $::CONN->send ("apply $item->{tag}");
2577 } elsif ($ev->{button} == 3) { 2626 } elsif ($ev->{button} == 3) {
2578 my @menu_items = ( 2627 my @menu_items = (
2579 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2628 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2580 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2629 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2581 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2630 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2631 (
2632 $item->{flags} & Crossfire::Protocol::F_LOCKED
2633 ? (
2634 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2635 )
2636 : (
2637 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2582 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2638 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2583 [ 2639 )
2584 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2585 sub { $::CONN->send ("lock $item->{tag}") },
2586 ], 2640 ),
2587 ); 2641 );
2588 2642
2589 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2643 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2590 } 2644 }
2591 2645
2774 # TODO: doesn't handle markup well (read as: at all) 2828 # TODO: doesn't handle markup well (read as: at all)
2775 my $short = $item->{count} > 1 2829 my $short = $item->{count} > 1
2776 ? "<b>$item->{count} ×</b> $item->{text}" 2830 ? "<b>$item->{count} ×</b> $item->{text}"
2777 : $item->{text}; 2831 : $item->{text};
2778 2832
2779 my $fontsize = $item->{fontsize} || $self->{fontsize};
2780
2781 for ($short) { 2833 for ($short) {
2782 s/^\s+//; 2834 s/^\s+//;
2783 s/\s+/ /g; 2835 s/\s+/ /g;
2784 my $len = int 40 / $fontsize;
2785 substr $_, $len, length, "…" if $len < length;
2786 } 2836 }
2787 2837
2788 new CFClient::UI::Label 2838 new CFClient::UI::Label
2789 markup => $short, 2839 markup => $short,
2790 tooltip => $item->{tooltip}, 2840 tooltip => $item->{tooltip},
2791 tooltip_font => $::FONT_PROP, 2841 tooltip_font => $::FONT_PROP,
2792 tooltip_width => 0.67, 2842 tooltip_width => 0.67,
2793 fontsize => $fontsize, 2843 fontsize => $item->{fontsize} || $self->{fontsize},
2844 max_w => $::WIDTH * 0.44,
2794 fg => $item->{fg}, 2845 fg => $item->{fg},
2795 can_events => 1, 2846 can_events => 1,
2796 can_hover => 1 2847 can_hover => 1
2797 }; 2848 };
2798 } 2849 }
2835 } 2886 }
2836 2887
2837 $self->reorder; 2888 $self->reorder;
2838} 2889}
2839 2890
2891sub reconfigure {
2892 my ($self) = @_;
2893
2894 delete $_->{label}
2895 for values %{ $self->{item} || {} };
2896
2897 $self->reorder;
2898 $self->SUPER::reconfigure;
2899}
2900
2840############################################################################# 2901#############################################################################
2841 2902
2842package CFClient::UI::Root; 2903package CFClient::UI::Root;
2843 2904
2844our @ISA = CFClient::UI::Container::; 2905our @ISA = CFClient::UI::Container::;
3005 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3066 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
3006 glClear GL_COLOR_BUFFER_BIT; 3067 glClear GL_COLOR_BUFFER_BIT;
3007 3068
3008 glMatrixMode GL_PROJECTION; 3069 glMatrixMode GL_PROJECTION;
3009 glLoadIdentity; 3070 glLoadIdentity;
3010 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3071 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3011 glMatrixMode GL_MODELVIEW; 3072 glMatrixMode GL_MODELVIEW;
3012 glLoadIdentity; 3073 glLoadIdentity;
3013 3074
3014 $self->_draw; 3075 $self->_draw;
3015} 3076}
3017############################################################################# 3078#############################################################################
3018 3079
3019package CFClient::UI; 3080package CFClient::UI;
3020 3081
3021$ROOT = new CFClient::UI::Root; 3082$ROOT = new CFClient::UI::Root;
3022$TOOLTIP = new CFClient::UI::Tooltip; 3083$TOOLTIP = new CFClient::UI::Tooltip z => 900;
3023 3084
30241 30851
3025 3086

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines