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.191 by root, Tue May 9 22:27:53 2006 UTC vs.
Revision 1.196 by root, Fri May 12 00:16:34 2006 UTC

1package CFClient::UI; 1package CFClient::UI;
2 2
3use utf8;
3use strict; 4use strict;
4 5
5use Scalar::Util (); 6use Scalar::Util ();
6use List::Util (); 7use List::Util ();
7 8
23 24
24 my $tip = $widget->{tooltip}; 25 my $tip = $widget->{tooltip};
25 26
26 $tip = $tip->($widget) if CODE:: eq ref $tip; 27 $tip = $tip->($widget) if CODE:: eq ref $tip;
27 28
28 $TOOLTIP->set_markup ($widget->{tooltip}); 29 $TOOLTIP->set_tooltip_from ($widget);
29
30 $TOOLTIP->show; 30 $TOOLTIP->show;
31 31
32 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 32 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
33 33
34 if ($x + $TOOLTIP->{w} > $::WIDTH) { 34 if ($x + $TOOLTIP->{w} > $::WIDTH) {
251 251
252 $_->reconfigure 252 $_->reconfigure
253 for $self->children; 253 for $self->children;
254 254
255 $self->check_size; 255 $self->check_size;
256 $self->size_allocate ($self->{w}, $self->{h}); 256 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $self->{w}, $self->{h}];
257 $self->update; 257 $self->update;
258} 258}
259 259
260sub set_max_size { 260sub set_max_size {
261 my ($self, $w, $h) = @_; 261 my ($self, $w, $h) = @_;
380} 380}
381 381
382sub set_parent { 382sub set_parent {
383 my ($self, $parent) = @_; 383 my ($self, $parent) = @_;
384 384
385 $self->{_tree_depth} = $parent->{_tree_depth} + 1;
386 Scalar::Util::weaken ($self->{parent} = $parent); 385 Scalar::Util::weaken ($self->{parent} = $parent);
386
387 $self->check_size
388 unless exists $self->{req_w};
387} 389}
388 390
389sub check_size { 391sub check_size {
390 my ($self) = @_; 392 my ($self) = @_;
391 393
506 $self->{children} = [ 508 $self->{children} = [
507 sort { $a->{z} <=> $b->{z} } 509 sort { $a->{z} <=> $b->{z} }
508 @{$self->{children}}, @widgets 510 @{$self->{children}}, @widgets
509 ]; 511 ];
510 512
511 $_->check_size 513 $self->check_size;
512 for @widgets;
513
514 $self->update; 514 $self->update;
515} 515}
516 516
517sub children { 517sub children {
518 @{ $_[0]{children} } 518 @{ $_[0]{children} }
666 my ($w, $h) = ($self->w, $self->h); 666 my ($w, $h) = ($self->w, $self->h);
667 667
668 my $tex = $self->{texture} 668 my $tex = $self->{texture}
669 or return; 669 or return;
670 670
671 glEnable GL_BLEND;
672 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
673 glEnable GL_TEXTURE_2D; 671 glEnable GL_TEXTURE_2D;
674 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 672 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
675 glColor 0, 0, 0, 1; 673 glColor 0, 0, 0, 1;
676 674
677 $tex->draw_quad (0, 0, $w, $h); 675 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
678 676
679 glDisable GL_BLEND;
680 glDisable GL_TEXTURE_2D; 677 glDisable GL_TEXTURE_2D;
681} 678}
682 679
683############################################################################# 680#############################################################################
684 681
1213} 1210}
1214 1211
1215sub size_allocate { 1212sub size_allocate {
1216 my ($self, $w, $h) = @_; 1213 my ($self, $w, $h) = @_;
1217 1214
1215 Carp::confess "negative size" if $w < 0 || $h < 0;#d#
1216
1218 my $children = $self->{children}; 1217 my $children = $self->{children};
1219 1218
1220 my @h = map $_->{req_h}, @$children; 1219 my @h = map $_->{req_h}, @$children;
1221 1220
1222 my $req_h = List::Util::sum @h; 1221 my $req_h = List::Util::sum @h;
1261 my ($class, %arg) = @_; 1260 my ($class, %arg) = @_;
1262 1261
1263 my $self = $class->SUPER::new ( 1262 my $self = $class->SUPER::new (
1264 fg => [1, 1, 1], 1263 fg => [1, 1, 1],
1265 #font => default_font 1264 #font => default_font
1265 #text => initial text
1266 #markup => initial narkup
1267 layout => (new CFClient::Layout),
1266 fontsize => 1, 1268 fontsize => 1,
1267 text => "",
1268 align => -1, 1269 align => -1,
1269 valign => -1, 1270 valign => -1,
1270 padding => 2, 1271 padding => 2,
1271 layout => new CFClient::Layout,
1272 can_events => 0, 1272 can_events => 0,
1273 %arg 1273 %arg
1274 ); 1274 );
1275 1275
1276 if (exists $self->{template}) { 1276 if (exists $self->{template}) {
1277 my $layout = new CFClient::Layout; 1277 my $layout = new CFClient::Layout;
1278 $layout->set_text (delete $self->{template}); 1278 $layout->set_text (delete $self->{template});
1279 $self->{template} = $layout; 1279 $self->{template} = $layout;
1280 } 1280 }
1281 1281
1282 $self->set_text (delete $self->{text}) if exists $self->{text}; 1282 if (exists $self->{markup}) {
1283 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1283 $self->set_markup (delete $self->{markup});
1284 } else {
1285 $self->set_text (delete $self->{text});
1286 }
1284 1287
1285 $self 1288 $self
1286} 1289}
1287 1290
1288sub escape { 1291sub escape {
1306 my ($self, $text) = @_; 1309 my ($self, $text) = @_;
1307 1310
1308 return if $self->{text} eq "T$text"; 1311 return if $self->{text} eq "T$text";
1309 $self->{text} = "T$text"; 1312 $self->{text} = "T$text";
1310 1313
1314 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1311 $self->{layout}->set_text ($text); 1315 $self->{layout}->set_text ($text);
1312 1316
1313 $self->update; 1317 $self->update;
1314 $self->check_size; 1318 $self->check_size;
1315} 1319}
1318 my ($self, $markup) = @_; 1322 my ($self, $markup) = @_;
1319 1323
1320 return if $self->{text} eq "M$markup"; 1324 return if $self->{text} eq "M$markup";
1321 $self->{text} = "M$markup"; 1325 $self->{text} = "M$markup";
1322 1326
1327 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1328
1329 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1323 $self->{layout}->set_markup ($markup); 1330 $self->{layout}->set_markup ($markup);
1324 1331
1325 $self->update; 1332 $self->update;
1326 $self->check_size; 1333 $self->check_size;
1327} 1334}
1369 1376
1370sub _draw { 1377sub _draw {
1371 my ($self) = @_; 1378 my ($self) = @_;
1372 1379
1373 my $tex = $self->{texture} ||= do { 1380 my $tex = $self->{texture} ||= do {
1381 $self->{layout}->set_foreground (@{$self->{fg}});
1374 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1382 $self->{layout}->set_font ($self->{font}) if $self->{font};
1375 $self->{layout}->set_width ($self->{w}); 1383 $self->{layout}->set_width ($self->{w});
1376 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1384 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1385
1377 new_from_layout CFClient::Texture $self->{layout} 1386 my $tex = new_from_layout CFClient::Texture $self->{layout};
1387
1388 $self->{ox} = int $self->{align} < 0 ? $self->{padding}
1389 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1390 : ($self->{w} - $tex->{w}) * 0.5;
1391
1392 $self->{oy} = int $self->{valign} < 0 ? $self->{padding}
1393 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1394 : ($self->{h} - $tex->{h}) * 0.5;
1395
1396 $tex
1378 }; 1397 };
1379 1398
1380 glEnable GL_BLEND;
1381 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1382 glEnable GL_TEXTURE_2D; 1399 glEnable GL_TEXTURE_2D;
1383 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1400 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1384 1401
1402 if ($tex->{format} == GL_ALPHA) {
1385 glColor @{$self->{fg}}; 1403 glColor @{$self->{fg}};
1386
1387 $self->{ox} = int (
1388 $self->{align} < 0 ? $self->{padding}
1389 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1390 : ($self->{w} - $tex->{w}) * 0.5
1391 );
1392
1393 $self->{oy} = int (
1394 $self->{valign} < 0 ? $self->{padding}
1395 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1396 : ($self->{h} - $tex->{h}) * 0.5
1397 );
1398
1399 $tex->draw_quad ($self->{ox}, $self->{oy}); 1404 $tex->draw_quad_alpha ($self->{ox}, $self->{oy});
1405 } else {
1406 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy});
1407 }
1400 1408
1401 glDisable GL_TEXTURE_2D; 1409 glDisable GL_TEXTURE_2D;
1402 glDisable GL_BLEND;
1403} 1410}
1404 1411
1405############################################################################# 1412#############################################################################
1406 1413
1407package CFClient::UI::EntryBase; 1414package CFClient::UI::EntryBase;
1442 $self->{layout}->set_text ("$text "); 1449 $self->{layout}->set_text ("$text ");
1443 1450
1444 $self->emit (changed => $self->{text}); 1451 $self->emit (changed => $self->{text});
1445} 1452}
1446 1453
1454sub set_text {
1455 my ($self, $text) = @_;
1456
1457 $self->{cursor} = length $text;
1458 $self->_set_text ($text);
1459 $self->check_size;
1460 $self->update;
1461}
1462
1447sub get_text { 1463sub get_text {
1448 $_[0]{text} 1464 $_[0]{text}
1449} 1465}
1450 1466
1451sub size_request { 1467sub size_request {
1458 1474
1459sub size_allocate { 1475sub size_allocate {
1460 my ($self, $w, $h) = @_; 1476 my ($self, $w, $h) = @_;
1461 1477
1462 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text 1478 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1463}
1464
1465sub set_text {
1466 my ($self, $text) = @_;
1467
1468 $self->{cursor} = length $text;
1469 $self->_set_text ($text);
1470 $self->update;
1471} 1479}
1472 1480
1473sub key_down { 1481sub key_down {
1474 my ($self, $ev) = @_; 1482 my ($self, $ev) = @_;
1475 1483
1663 1671
1664 if ($GRAB == $self) { 1672 if ($GRAB == $self) {
1665 $self->{fg} = $self->{active_fg}; 1673 $self->{fg} = $self->{active_fg};
1666 } 1674 }
1667 1675
1668 glEnable GL_BLEND;
1669 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1670 glEnable GL_TEXTURE_2D; 1676 glEnable GL_TEXTURE_2D;
1671 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1677 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1672 glColor 0, 0, 0, 1; 1678 glColor 0, 0, 0, 1;
1673 1679
1674 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); 1680 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
1675 1681
1676 glDisable GL_TEXTURE_2D; 1682 glDisable GL_TEXTURE_2D;
1677 glDisable GL_BLEND;
1678 1683
1679 $self->SUPER::_draw; 1684 $self->SUPER::_draw;
1680} 1685}
1681 1686
1682############################################################################# 1687#############################################################################
1729 1734
1730 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1735 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1731 1736
1732 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1737 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1733 1738
1734 glEnable GL_BLEND;
1735 glEnable GL_TEXTURE_2D; 1739 glEnable GL_TEXTURE_2D;
1736 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1737 1740
1738 my $tex = $self->{state} ? $tex[1] : $tex[0]; 1741 my $tex = $self->{state} ? $tex[1] : $tex[0];
1739 1742
1740 $tex->draw_quad (0, 0, $s, $s); 1743 $tex->draw_quad_alpha (0, 0, $s, $s);
1741 1744
1742 glDisable GL_TEXTURE_2D; 1745 glDisable GL_TEXTURE_2D;
1743 glDisable GL_BLEND;
1744} 1746}
1745 1747
1746############################################################################# 1748#############################################################################
1747 1749
1748package CFClient::UI::Image; 1750package CFClient::UI::Image;
1791 glTranslate 0, -$self->{w}, 0; 1793 glTranslate 0, -$self->{w}, 0;
1792 1794
1793 ($w, $h) = ($h, $w); 1795 ($w, $h) = ($h, $w);
1794 } 1796 }
1795 1797
1796 glEnable GL_BLEND;
1797 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1798 glEnable GL_TEXTURE_2D; 1798 glEnable GL_TEXTURE_2D;
1799 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1799 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1800 1800
1801 $tex->draw_quad (0, 0, $w, $h); 1801 $tex->draw_quad_alpha (0, 0, $w, $h);
1802 1802
1803 glDisable GL_BLEND;
1804 glDisable GL_TEXTURE_2D; 1803 glDisable GL_TEXTURE_2D;
1805} 1804}
1806 1805
1807############################################################################# 1806#############################################################################
1808 1807
2100 $page ||= 2; 2099 $page ||= 2;
2101 2100
2102 my $knob_a = $inner_pad_px + ($value - $page * 0.5); 2101 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
2103 my $knob_b = $inner_pad_px + ($value + $page * 0.5); 2102 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
2104 2103
2105 glEnable GL_BLEND;
2106 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2107 glEnable GL_TEXTURE_2D; 2104 glEnable GL_TEXTURE_2D;
2108 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2105 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2109 2106
2110 # draw background 2107 # draw background
2111 $tex[1]->draw_quad (0, 0, $w, $h); 2108 $tex[1]->draw_quad_alpha (0, 0, $w, $h);
2112 2109
2113 # draw handle 2110 # draw handle
2114 $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); 2111 $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h);
2115 2112
2116 glDisable GL_BLEND;
2117 glDisable GL_TEXTURE_2D; 2113 glDisable GL_TEXTURE_2D;
2118} 2114}
2119 2115
2120############################################################################# 2116#############################################################################
2121 2117
2132 fontsize => 1, 2128 fontsize => 1,
2133 can_events => 0, 2129 can_events => 0,
2134 #font => default_font 2130 #font => default_font
2135 @_, 2131 @_,
2136 2132
2137 layout => (new CFClient::Layout), 2133 layout => (new CFClient::Layout 1),
2138 par => [], 2134 par => [],
2139 height => 0, 2135 height => 0,
2140 children => [ 2136 children => [
2141 (new CFClient::UI::Empty expand => 1), 2137 (new CFClient::UI::Empty expand => 1),
2142 (new CFClient::UI::Slider vertical => 1), 2138 (new CFClient::UI::Slider vertical => 1),
2160 2156
2161 my $layout = $self->{layout}; 2157 my $layout = $self->{layout};
2162 2158
2163 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2159 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2164 $layout->set_width ($self->{children}[0]{w}); 2160 $layout->set_width ($self->{children}[0]{w});
2165 $layout->set_text ($text); 2161 $layout->set_markup ($text);
2166 2162
2167 ($layout->size)[1] 2163 ($layout->size)[1]
2168} 2164}
2169 2165
2170sub reflow { 2166sub reflow {
2226 2222
2227 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2223 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2228 glClearColor 0, 0, 0, 0; 2224 glClearColor 0, 0, 0, 0;
2229 glClear GL_COLOR_BUFFER_BIT; 2225 glClear GL_COLOR_BUFFER_BIT;
2230 2226
2231 glEnable GL_BLEND;
2232 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2233 glEnable GL_TEXTURE_2D; 2227 glEnable GL_TEXTURE_2D;
2234 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2228 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2235 2229
2236 my $top = int $self->{children}[1]{range}[0]; 2230 my $top = int $self->{children}[1]{range}[0];
2237 2231
2246 2240
2247 for my $par (@{$self->{par}}) { 2241 for my $par (@{$self->{par}}) {
2248 my $h = $par->[0]; 2242 my $h = $par->[0];
2249 2243
2250 if ($y0 < $y + $h && $y < $y1) { 2244 if ($y0 < $y + $h && $y < $y1) {
2245 $layout->set_foreground (@{ $par->[1] });
2251 $layout->set_text ($par->[2]); 2246 $layout->set_markup ($par->[2]);
2252 2247
2253 glColor @{ $par->[1] };
2254 my ($W, $H) = $layout->size; 2248 my ($W, $H) = $layout->size;
2255 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); 2249 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0);
2256 } 2250 }
2257 2251
2258 $y += $h; 2252 $y += $h;
2259 } 2253 }
2260 2254
2261 glDisable GL_TEXTURE_2D; 2255 glDisable GL_TEXTURE_2D;
2262 glDisable GL_BLEND;
2263 }; 2256 };
2264 }); 2257 });
2265} 2258}
2266 2259
2267sub _draw { 2260sub _draw {
2268 my ($self) = @_; 2261 my ($self) = @_;
2269 2262
2270 glEnable GL_BLEND;
2271 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2272 glEnable GL_TEXTURE_2D; 2263 glEnable GL_TEXTURE_2D;
2273 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2264 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2274 glColor 1, 1, 1, 1; 2265 glColor 1, 1, 1, 1;
2275 $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2266 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2276 glDisable GL_TEXTURE_2D; 2267 glDisable GL_TEXTURE_2D;
2277 glDisable GL_BLEND;
2278 2268
2279 $self->{children}[1]->draw; 2269 $self->{children}[1]->draw;
2280 2270
2281} 2271}
2282 2272
2376 @_, 2366 @_,
2377 can_events => 0, 2367 can_events => 0,
2378 ) 2368 )
2379} 2369}
2380 2370
2381sub set_markup { 2371sub set_tooltip_from {
2382 my ($self, $text) = @_; 2372 my ($self, $widget) = @_;
2383 2373
2384 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; 2374 $self->{label} = new CFClient::UI::Label
2385 $self->{label}->set_markup ($text); 2375 markup => $widget->{tooltip},
2376 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2377 fontsize => 0.8,
2378 fg => [0, 0, 0, 1],
2379 font => ($widget->{tooltip_font} || $::FONT_PROP);
2380
2386 $self->add ($self->{label}); 2381 $self->add ($self->{label});
2387} 2382}
2388 2383
2389sub size_request { 2384sub size_request {
2390 my ($self) = @_; 2385 my ($self) = @_;
2391
2392 $self->child->set_max_size ($::WIDTH * 0.3);
2393 2386
2394 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 2387 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2395 2388
2396 ($w + 4, $h + 4) 2389 ($w + 4, $h + 4)
2397} 2390}
2459 return unless $::CONN;#d# manage and cache textures differently 2452 return unless $::CONN;#d# manage and cache textures differently
2460 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2453 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2461 2454
2462 # TODO animation 2455 # TODO animation
2463 if ($tex) { 2456 if ($tex) {
2464 glEnable GL_BLEND;
2465 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2466 glEnable GL_TEXTURE_2D; 2457 glEnable GL_TEXTURE_2D;
2467 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2458 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2468 glColor 1, 1, 1, 1; 2459 glColor 1, 1, 1, 1;
2469 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 2460 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2470 glDisable GL_TEXTURE_2D; 2461 glDisable GL_TEXTURE_2D;
2471 glDisable GL_BLEND;
2472 } 2462 }
2473} 2463}
2474 2464
2475############################################################################# 2465#############################################################################
2476 2466
2481sub new { 2471sub new {
2482 my $class = shift; 2472 my $class = shift;
2483 2473
2484 my %args = @_; 2474 my %args = @_;
2485 2475
2486 my $item = $args{item}; 2476 my $item = delete $args{item};
2487 2477
2488 my $desc = $item->{nrof} < 2 2478 my $desc = $item->{nrof} < 2
2489 ? $item->{name} 2479 ? $item->{name}
2490 : "$item->{nrof} $item->{name_pl}"; 2480 : "$item->{nrof} $item->{name_pl}";
2491 2481
2520 2510
2521 1 2511 1
2522 }, 2512 },
2523 %args 2513 %args
2524 ); 2514 );
2515
2525 $self->add(new CFClient::UI::Face 2516 $self->add (new CFClient::UI::Face
2526 can_events => 0, 2517 can_events => 0,
2527 face => $item->{face}, 2518 face => $item->{face},
2528 anim => $item->{anim}, 2519 anim => $item->{anim},
2529 animspeed => $item->{animspeed}); 2520 animspeed => $item->{animspeed},
2521 );
2522
2530 $self->add(new CFClient::UI::Label 2523 $self->add (new CFClient::UI::Label
2531 can_events => 0, 2524 can_events => 0,
2532 text => $desc); 2525 text => $desc,
2526 );
2533 2527
2534 $self 2528 $self
2535} 2529}
2536 2530
2537############################################################################# 2531#############################################################################
2564 for my $item (@items) { 2558 for my $item (@items) {
2565 my $desc = $item->{nrof} < 2 2559 my $desc = $item->{nrof} < 2
2566 ? $item->{name} 2560 ? $item->{name}
2567 : "$item->{nrof} $item->{name_pl}"; 2561 : "$item->{nrof} $item->{name_pl}";
2568 2562
2569 $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item); 2563 $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item);
2570 } 2564 }
2571 2565
2572# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2566# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2573} 2567}
2574 2568
2645 $self->hide; 2639 $self->hide;
2646 2640
2647 $self->emit ("popdown"); 2641 $self->emit ("popdown");
2648 $self->{hover}[1]->() if $self->{hover}; 2642 $self->{hover}[1]->() if $self->{hover};
2649 } 2643 }
2644}
2645
2646#############################################################################
2647
2648package CFClient::UI::Statusbox;
2649
2650our @ISA = CFClient::UI::VBox::;
2651
2652sub reorder {
2653 my ($self) = @_;
2654 my $NOW = time;
2655
2656 while (my ($k, $v) = each %{ $self->{item} }) {
2657 delete $self->{item}{$k} if $v->{timeout} < $NOW;
2658 }
2659
2660 my @widgets;
2661 my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} };
2662 my $count = 10 + 1;
2663 for my $item (@items) {
2664 last unless --$count;
2665
2666 push @widgets, $item->{label} ||= do {
2667 # TODO: doesn't handle markup well (read as: at all)
2668 my $short = delete $item->{text};
2669 for ($short) {
2670 s/^\s+//;
2671 s/\012.*//s;
2672 my $len = int 30 / $item->{fontsize};
2673 substr $_, $len, length, "…" if $len < length;
2674 }
2675
2676 new CFClient::UI::Label
2677 markup => $short,
2678 tooltip => delete $item->{tooltip},
2679 tooltip_font => $::FONT_PROP,
2680 tooltip_width => 0.75,
2681 fontsize => delete $item->{fontsize},
2682 color => delete $item->{color},
2683 can_events => 1,
2684 can_hover => 1,
2685 };
2686 }
2687
2688 $self->clear;
2689 $self->SUPER::add (@widgets);
2690}
2691
2692sub add {
2693 my ($self, $text, %arg) = @_;
2694
2695 my $item = {
2696 time => time,
2697 text => $text,
2698 timeout => 60,
2699 tooltip => $text,
2700 fontsize => 0.8,
2701 color => [0.8, 0.8, 0.8, 0.8],
2702 %arg,
2703 };
2704
2705 $item->{timeout} += time;
2706 $item->{group} ||= $item+0;
2707
2708 $item = $self->{item}{$item->{group}} ||= $item;
2709
2710 $self->reorder;
2650} 2711}
2651 2712
2652############################################################################# 2713#############################################################################
2653 2714
2654package CFClient::UI::Root; 2715package CFClient::UI::Root;
2769 my ($w, $h) = $widget->{user_w} && $widget->{user_h} 2830 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
2770 ? @$widget{qw(user_w user_h)} 2831 ? @$widget{qw(user_w user_h)}
2771 : $widget->size_request; 2832 : $widget->size_request;
2772 2833
2773 if ($w != $widget->{req_w} || $h != $widget->{req_h}) { 2834 if ($w != $widget->{req_w} || $h != $widget->{req_h}) {
2835 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
2836
2774 $widget->{req_w} = $w; 2837 $widget->{req_w} = $w;
2775 $widget->{req_h} = $h; 2838 $widget->{req_h} = $h;
2776 2839
2777 $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; 2840 $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}];
2778 2841
2783 } 2846 }
2784 2847
2785 while ($self->{size_alloc}) { 2848 while ($self->{size_alloc}) {
2786 for (values %{delete $self->{size_alloc}}) { 2849 for (values %{delete $self->{size_alloc}}) {
2787 my ($widget, $w, $h) = @$_; 2850 my ($widget, $w, $h) = @$_;
2851
2852 $w = 0 if $w < 0;
2853 $h = 0 if $h < 0;
2788 2854
2789 $widget->{w} = $w; 2855 $widget->{w} = $w;
2790 $widget->{h} = $h; 2856 $widget->{h} = $h;
2791 $widget->size_allocate ($w, $h); 2857 $widget->size_allocate ($w, $h);
2792 $widget->emit (size_allocate => $w, $h); 2858 $widget->emit (size_allocate => $w, $h);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines