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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines