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.182 by root, Sun Apr 30 11:17:08 2006 UTC vs.
Revision 1.198 by root, Fri May 12 02:08:52 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) {
35 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); 35 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0);
36 } 36 }
37 37
38 $TOOLTIP->move ($x, $y); 38 $TOOLTIP->move ($x, $y);
39 $TOOLTIP->check_size;
40 $TOOLTIP->update;
39 } 41 }
40 42
41 return; 43 return;
42 } 44 }
43 } 45 }
232 $self->{y} = $y; 234 $self->{y} = $y;
233 $self->update; 235 $self->update;
234 } 236 }
235 237
236 if ($self->{w} != $w || $self->{h} != $h) { 238 if ($self->{w} != $w || $self->{h} != $h) {
237 $self->{w} = $w; 239 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $w, $h];
238 $self->{h} = $h;
239
240 $self->size_allocate ($w, $h);
241 $self->update;
242 $self->emit (size_allocate => $w, $h);
243 } 240 }
244} 241}
245 242
246sub size_allocate { 243sub size_allocate {
247 # nothing to be done 244 # nothing to be done
255 my ($self) = @_; 252 my ($self) = @_;
256 253
257 $_->reconfigure 254 $_->reconfigure
258 for $self->children; 255 for $self->children;
259 256
260 $_->check_size; 257 $self->check_size (1);
258 $self->update;
261} 259}
262 260
263sub set_max_size { 261sub set_max_size {
264 my ($self, $w, $h) = @_; 262 my ($self, $w, $h) = @_;
265 263
266 delete $self->{max_w}; $self->{max_w} = $w if $w; 264 delete $self->{max_w}; $self->{max_w} = $w if $w;
267 delete $self->{max_h}; $self->{max_h} = $h if $h; 265 delete $self->{max_h}; $self->{max_h} = $h if $h;
268}
269
270# return top left coordinates
271sub _topleft {
272 my ($self, $x, $y) = @_;
273
274 $self->{parent}
275 or Carp::confess "no parent widget in _topleft\n";#d#
276
277 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y});
278} 266}
279 267
280# translate global coordinates to local coordinate system 268# translate global coordinates to local coordinate system
281sub coord2local { 269sub coord2local {
282 my ($self, $x, $y) = @_; 270 my ($self, $x, $y) = @_;
283 271
284 my ($X, $Y) = $self->_topleft; 272 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
285 ($x - $X, $y - $Y)
286} 273}
287 274
288# translate local coordinates to global coordinate system 275# translate local coordinates to global coordinate system
289sub coord2global { 276sub coord2global {
290 my ($self, $x, $y) = @_; 277 my ($self, $x, $y) = @_;
291 278
292 my ($X, $Y) = $self->_topleft; 279 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
293 ($x + $X, $y + $Y)
294} 280}
295 281
296sub focus_in { 282sub focus_in {
297 my ($self) = @_; 283 my ($self) = @_;
298 284
396 382
397sub set_parent { 383sub set_parent {
398 my ($self, $parent) = @_; 384 my ($self, $parent) = @_;
399 385
400 Scalar::Util::weaken ($self->{parent} = $parent); 386 Scalar::Util::weaken ($self->{parent} = $parent);
387
388
389 # TODO: req_w _does_change after ->reconfigure
390 $self->check_size
391 unless exists $self->{req_w};
401} 392}
402 393
403sub check_size { 394sub check_size {
404 my ($self) = @_; 395 my ($self, $forced) = @_;
405 396
406 $self->{parent} 397 $self->{force_alloc} = 1 if $forced;
407 or return 1; 398 $CFClient::UI::ROOT->{check_size}{$self} = $self;
408
409 my ($w, $h) = $self->{user_w} && $self->{user_h}
410 ? @$self{qw(user_w user_h)}
411 : $self->size_request;
412
413 if ($w != $self->{req_w} || $h != $self->{req_h}) {
414 $self->{req_w} = $w;
415 $self->{req_h} = $h;
416
417 $self->{parent}->check_size
418 or $self->size_allocate (
419 (List::Util::max $self->{w}, $w),
420 (List::Util::max $self->{h}, $h),
421 );
422
423 1
424 } else {
425 0
426 }
427} 399}
428 400
429sub update { 401sub update {
430 my ($self) = @_; 402 my ($self) = @_;
431 403
528 500
529 $self 501 $self
530} 502}
531 503
532sub add { 504sub add {
533 my ($self, $child) = @_; 505 my ($self, @widgets) = @_;
534 506
535 $child->set_parent ($self); 507 $_->set_parent ($self)
508 for @widgets;
536 509
537 use sort 'stable'; 510 use sort 'stable';
538 511
539 $self->{children} = [ 512 $self->{children} = [
540 sort { $a->{z} <=> $b->{z} } 513 sort { $a->{z} <=> $b->{z} }
541 @{$self->{children}}, $child 514 @{$self->{children}}, @widgets
542 ]; 515 ];
543 516
544 $child->check_size; 517 $self->check_size (1);
545 $self->update; 518 $self->update;
546} 519}
547 520
548sub children { 521sub children {
549 @{ $_[0]{children} } 522 @{ $_[0]{children} }
656} 629}
657 630
658sub update { 631sub update {
659 my ($self) = @_; 632 my ($self) = @_;
660 633
661 $ROOT->on_refresh ($self => sub { $self->render_child }); 634 $ROOT->on_post_alloc ($self => sub { $self->render_child });
662 $self->SUPER::update; 635 $self->SUPER::update;
663} 636}
664 637
665sub size_allocate { 638sub size_allocate {
666 my ($self, $w, $h) = @_; 639 my ($self, $w, $h) = @_;
697 my ($w, $h) = ($self->w, $self->h); 670 my ($w, $h) = ($self->w, $self->h);
698 671
699 my $tex = $self->{texture} 672 my $tex = $self->{texture}
700 or return; 673 or return;
701 674
702 glEnable GL_BLEND;
703 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
704 glEnable GL_TEXTURE_2D; 675 glEnable GL_TEXTURE_2D;
705 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 676 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
706 glColor 0, 0, 0, 1; 677 glColor 0, 0, 0, 1;
707 678
708 $tex->draw_quad (0, 0, $w, $h); 679 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
709 680
710 glDisable GL_BLEND;
711 glDisable GL_TEXTURE_2D; 681 glDisable GL_TEXTURE_2D;
712} 682}
713 683
714############################################################################# 684#############################################################################
715 685
737 707
738 $self->{view_x} = int $x; 708 $self->{view_x} = int $x;
739 $self->{view_y} = int $y; 709 $self->{view_y} = int $y;
740 710
741 $self->update; 711 $self->update;
712}
713
714# hmm, this does not work for topleft of $self... but we should not ask for that
715sub coord2local {
716 my ($self, $x, $y) = @_;
717
718 $self->SUPER::coord2local ($x + $self->{view_x}, $y + $self->{view_y})
719}
720
721sub coord2global {
722 my ($self, $x, $y) = @_;
723
724 $x = List::Util::min $self->{w}, $x - $self->{view_x};
725 $y = List::Util::min $self->{h}, $y - $self->{view_y};
726
727 $self->SUPER::coord2global ($x, $y)
728}
729
730sub find_widget {
731 my ($self, $x, $y) = @_;
732
733 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
734 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
735 ) {
736 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
737 } else {
738 $self->CFClient::UI::Base::find_widget ($x, $y)
739 }
742} 740}
743 741
744sub _render { 742sub _render {
745 my ($self) = @_; 743 my ($self) = @_;
746 744
790 788
791our @ISA = CFClient::UI::Bin::; 789our @ISA = CFClient::UI::Bin::;
792 790
793use CFClient::OpenGL; 791use CFClient::OpenGL;
794 792
795sub new {
796 my $class = shift;
797
798 my $self = $class->SUPER::new (
799 bg => [1, 1, 1, 1],
800 border_bg => [1, 1, 1, 1],
801 border => 0.8,
802 @_
803 );
804
805 $self
806}
807
808sub _draw {
809 my ($self) = @_;
810
811 my ($w, $h) = ($self->{w}, $self->{h});
812
813 glEnable GL_BLEND;
814 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
815 glEnable GL_TEXTURE_2D;
816 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
817
818# glBegin GL_QUADS;
819# glColor 0, 0, 0, 0;
820# glVertex 0 , 0;
821# glVertex 0 , $h;
822# glVertex $w, $h;
823# glVertex $w, 0;
824# glEnd;
825
826
827 $self->child->draw;
828 glDisable GL_BLEND;
829 glDisable GL_TEXTURE_2D;
830}
831
832############################################################################# 793#############################################################################
833 794
834package CFClient::UI::FancyFrame; 795package CFClient::UI::FancyFrame;
835 796
836our @ISA = CFClient::UI::Bin::; 797our @ISA = CFClient::UI::Bin::;
950 my ($self) = @_; 911 my ($self) = @_;
951 912
952 my ($w, $h ) = ($self->{w}, $self->{h}); 913 my ($w, $h ) = ($self->{w}, $self->{h});
953 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 914 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
954 915
955 glEnable GL_BLEND;
956 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
957 glEnable GL_TEXTURE_2D; 916 glEnable GL_TEXTURE_2D;
958 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 917 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
959 918
960 my $border = $self->border; 919 my $border = $self->border;
961 920
962 glColor @{ $self->{border_bg} }; 921 glColor @{ $self->{border_bg} };
963 $tex[1]->draw_quad (0, 0, $w, $border); 922 $tex[1]->draw_quad_alpha (0, 0, $w, $border);
964 $tex[3]->draw_quad (0, $border, $border, $ch); 923 $tex[3]->draw_quad_alpha (0, $border, $border, $ch);
965 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 924 $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
966 $tex[4]->draw_quad (0, $h - $border, $w, $border); 925 $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border);
967 926
968 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 927 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
969 my $bg = $tex[0]; 928 my $bg = $tex[0];
970 929
971 # TODO: repeat texture not scale 930 # TODO: repeat texture not scale
975 glColor @{ $self->{bg} }; 934 glColor @{ $self->{bg} };
976 935
977 $bg->{s} = $rep_x; 936 $bg->{s} = $rep_x;
978 $bg->{t} = $rep_y; 937 $bg->{t} = $rep_y;
979 $bg->{wrap_mode} = 1; 938 $bg->{wrap_mode} = 1;
980 $bg->draw_quad ($border, $border, $cw, $ch); 939 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
940 }
981 941
982 glDisable GL_TEXTURE_2D; 942 glDisable GL_TEXTURE_2D;
983 glDisable GL_BLEND;
984 }
985 943
986 $self->{title}->draw if $self->{title}; 944 $self->{title}->draw if $self->{title};
987 945
988 $self->child->draw; 946 $self->child->draw;
989} 947}
1216} 1174}
1217 1175
1218sub size_allocate { 1176sub size_allocate {
1219 my ($self, $w, $h) = @_; 1177 my ($self, $w, $h) = @_;
1220 1178
1179 Carp::confess "negative size" if $w < 0 || $h < 0;#d#
1180
1221 my $children = $self->{children}; 1181 my $children = $self->{children};
1222 1182
1223 my @h = map $_->{req_h}, @$children; 1183 my @h = map $_->{req_h}, @$children;
1224 1184
1225 my $req_h = List::Util::sum @h; 1185 my $req_h = List::Util::sum @h;
1264 my ($class, %arg) = @_; 1224 my ($class, %arg) = @_;
1265 1225
1266 my $self = $class->SUPER::new ( 1226 my $self = $class->SUPER::new (
1267 fg => [1, 1, 1], 1227 fg => [1, 1, 1],
1268 #font => default_font 1228 #font => default_font
1229 #text => initial text
1230 #markup => initial narkup
1231 layout => (new CFClient::Layout),
1269 fontsize => 1, 1232 fontsize => 1,
1270 text => "",
1271 align => -1, 1233 align => -1,
1272 valign => -1, 1234 valign => -1,
1273 padding => 2, 1235 padding => 2,
1274 layout => new CFClient::Layout,
1275 can_events => 0, 1236 can_events => 0,
1276 %arg 1237 %arg
1277 ); 1238 );
1278 1239
1279 if (exists $self->{template}) { 1240 if (exists $self->{template}) {
1280 my $layout = new CFClient::Layout; 1241 my $layout = new CFClient::Layout;
1281 $layout->set_text (delete $self->{template}); 1242 $layout->set_text (delete $self->{template});
1282 $self->{template} = $layout; 1243 $self->{template} = $layout;
1283 } 1244 }
1284 1245
1285 $self->set_text (delete $self->{text}) if exists $self->{text}; 1246 if (exists $self->{markup}) {
1286 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1247 $self->set_markup (delete $self->{markup});
1248 } else {
1249 $self->set_text (delete $self->{text});
1250 }
1287 1251
1288 $self 1252 $self
1289} 1253}
1290 1254
1291sub escape { 1255sub escape {
1303 1267
1304 delete $self->{texture}; 1268 delete $self->{texture};
1305 $self->SUPER::update; 1269 $self->SUPER::update;
1306} 1270}
1307 1271
1308sub reconfigure {
1309 my ($self) = @_;
1310
1311 delete $self->{texture};
1312}
1313
1314sub set_text { 1272sub set_text {
1315 my ($self, $text) = @_; 1273 my ($self, $text) = @_;
1316 1274
1317 return if $self->{text} eq "T$text"; 1275 return if $self->{text} eq "T$text";
1318 $self->{text} = "T$text"; 1276 $self->{text} = "T$text";
1319 1277
1278 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1320 $self->{layout}->set_text ($text); 1279 $self->{layout}->set_text ($text);
1321 1280
1322 delete $self->{texture};
1323 $self->update; 1281 $self->update;
1324 $self->check_size; 1282 $self->check_size;
1325} 1283}
1326 1284
1327sub set_markup { 1285sub set_markup {
1328 my ($self, $markup) = @_; 1286 my ($self, $markup) = @_;
1329 1287
1330 return if $self->{text} eq "M$markup"; 1288 return if $self->{text} eq "M$markup";
1331 $self->{text} = "M$markup"; 1289 $self->{text} = "M$markup";
1332 1290
1291 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1292
1293 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1333 $self->{layout}->set_markup ($markup); 1294 $self->{layout}->set_markup ($markup);
1334 1295
1335 delete $self->{texture};
1336 $self->update; 1296 $self->update;
1337 $self->check_size; 1297 $self->check_size;
1338} 1298}
1339 1299
1340sub size_request { 1300sub size_request {
1371sub set_fontsize { 1331sub set_fontsize {
1372 my ($self, $fontsize) = @_; 1332 my ($self, $fontsize) = @_;
1373 1333
1374 $self->{fontsize} = $fontsize; 1334 $self->{fontsize} = $fontsize;
1375 delete $self->{texture}; 1335 delete $self->{texture};
1336
1337 $self->update;
1376 $self->check_size; 1338 $self->check_size;
1377 $self->update;
1378} 1339}
1379 1340
1380sub _draw { 1341sub _draw {
1381 my ($self) = @_; 1342 my ($self) = @_;
1382 1343
1383 my $tex = $self->{texture} ||= do { 1344 my $tex = $self->{texture} ||= do {
1345 $self->{layout}->set_foreground (@{$self->{fg}});
1384 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1346 $self->{layout}->set_font ($self->{font}) if $self->{font};
1385 $self->{layout}->set_width ($self->{w}); 1347 $self->{layout}->set_width ($self->{w});
1386 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1348 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1349
1387 new_from_layout CFClient::Texture $self->{layout} 1350 my $tex = new_from_layout CFClient::Texture $self->{layout};
1351
1352 $self->{ox} = int $self->{align} < 0 ? $self->{padding}
1353 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1354 : ($self->{w} - $tex->{w}) * 0.5;
1355
1356 $self->{oy} = int $self->{valign} < 0 ? $self->{padding}
1357 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1358 : ($self->{h} - $tex->{h}) * 0.5;
1359
1360 $tex
1388 }; 1361 };
1389 1362
1390 glEnable GL_BLEND;
1391 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1392 glEnable GL_TEXTURE_2D; 1363 glEnable GL_TEXTURE_2D;
1393 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1364 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1394 1365
1366 if ($tex->{format} == GL_ALPHA) {
1395 glColor @{$self->{fg}}; 1367 glColor @{$self->{fg}};
1396
1397 $self->{ox} = int (
1398 $self->{align} < 0 ? $self->{padding}
1399 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1400 : ($self->{w} - $tex->{w}) * 0.5
1401 );
1402
1403 $self->{oy} = int (
1404 $self->{valign} < 0 ? $self->{padding}
1405 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1406 : ($self->{h} - $tex->{h}) * 0.5
1407 );
1408
1409 $tex->draw_quad ($self->{ox}, $self->{oy}); 1368 $tex->draw_quad_alpha ($self->{ox}, $self->{oy});
1369 } else {
1370 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy});
1371 }
1410 1372
1411 glDisable GL_TEXTURE_2D; 1373 glDisable GL_TEXTURE_2D;
1412 glDisable GL_BLEND;
1413} 1374}
1414 1375
1415############################################################################# 1376#############################################################################
1416 1377
1417package CFClient::UI::EntryBase; 1378package CFClient::UI::EntryBase;
1452 $self->{layout}->set_text ("$text "); 1413 $self->{layout}->set_text ("$text ");
1453 1414
1454 $self->emit (changed => $self->{text}); 1415 $self->emit (changed => $self->{text});
1455} 1416}
1456 1417
1418sub set_text {
1419 my ($self, $text) = @_;
1420
1421 $self->{cursor} = length $text;
1422 $self->_set_text ($text);
1423 $self->check_size;
1424 $self->update;
1425}
1426
1457sub get_text { 1427sub get_text {
1458 $_[0]{text} 1428 $_[0]{text}
1459} 1429}
1460 1430
1461sub size_request { 1431sub size_request {
1468 1438
1469sub size_allocate { 1439sub size_allocate {
1470 my ($self, $w, $h) = @_; 1440 my ($self, $w, $h) = @_;
1471 1441
1472 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text 1442 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1473}
1474
1475sub set_text {
1476 my ($self, $text) = @_;
1477
1478 $self->{cursor} = length $text;
1479 $self->_set_text ($text);
1480 $self->update;
1481} 1443}
1482 1444
1483sub key_down { 1445sub key_down {
1484 my ($self, $ev) = @_; 1446 my ($self, $ev) = @_;
1485 1447
1673 1635
1674 if ($GRAB == $self) { 1636 if ($GRAB == $self) {
1675 $self->{fg} = $self->{active_fg}; 1637 $self->{fg} = $self->{active_fg};
1676 } 1638 }
1677 1639
1678 glEnable GL_BLEND;
1679 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1680 glEnable GL_TEXTURE_2D; 1640 glEnable GL_TEXTURE_2D;
1681 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1641 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1682 glColor 0, 0, 0, 1; 1642 glColor 0, 0, 0, 1;
1683 1643
1684 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); 1644 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
1685 1645
1686 glDisable GL_TEXTURE_2D; 1646 glDisable GL_TEXTURE_2D;
1687 glDisable GL_BLEND;
1688 1647
1689 $self->SUPER::_draw; 1648 $self->SUPER::_draw;
1690} 1649}
1691 1650
1692############################################################################# 1651#############################################################################
1739 1698
1740 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1699 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1741 1700
1742 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1701 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1743 1702
1744 glEnable GL_BLEND; 1703 my $tex = $self->{state} ? $tex[1] : $tex[0];
1704
1745 glEnable GL_TEXTURE_2D; 1705 glEnable GL_TEXTURE_2D;
1746 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1747
1748 my $tex = $self->{state} ? $tex[1] : $tex[0];
1749
1750 $tex->draw_quad (0, 0, $s, $s); 1706 $tex->draw_quad_alpha (0, 0, $s, $s);
1751
1752 glDisable GL_TEXTURE_2D; 1707 glDisable GL_TEXTURE_2D;
1753 glDisable GL_BLEND;
1754} 1708}
1755 1709
1756############################################################################# 1710#############################################################################
1757 1711
1758package CFClient::UI::Image; 1712package CFClient::UI::Image;
1801 glTranslate 0, -$self->{w}, 0; 1755 glTranslate 0, -$self->{w}, 0;
1802 1756
1803 ($w, $h) = ($h, $w); 1757 ($w, $h) = ($h, $w);
1804 } 1758 }
1805 1759
1806 glEnable GL_BLEND;
1807 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1808 glEnable GL_TEXTURE_2D; 1760 glEnable GL_TEXTURE_2D;
1809 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1761 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1810 1762
1811 $tex->draw_quad (0, 0, $w, $h); 1763 $tex->draw_quad_alpha (0, 0, $w, $h);
1812 1764
1813 glDisable GL_BLEND;
1814 glDisable GL_TEXTURE_2D; 1765 glDisable GL_TEXTURE_2D;
1815} 1766}
1816 1767
1817############################################################################# 1768#############################################################################
1818 1769
2110 $page ||= 2; 2061 $page ||= 2;
2111 2062
2112 my $knob_a = $inner_pad_px + ($value - $page * 0.5); 2063 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
2113 my $knob_b = $inner_pad_px + ($value + $page * 0.5); 2064 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
2114 2065
2115 glEnable GL_BLEND;
2116 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2117 glEnable GL_TEXTURE_2D; 2066 glEnable GL_TEXTURE_2D;
2118 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2067 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2119 2068
2120 # draw background 2069 # draw background
2121 $tex[1]->draw_quad (0, 0, $w, $h); 2070 $tex[1]->draw_quad_alpha (0, 0, $w, $h);
2122 2071
2123 # draw handle 2072 # draw handle
2124 $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); 2073 $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h);
2125 2074
2126 glDisable GL_BLEND;
2127 glDisable GL_TEXTURE_2D; 2075 glDisable GL_TEXTURE_2D;
2128} 2076}
2129 2077
2130############################################################################# 2078#############################################################################
2131 2079
2142 fontsize => 1, 2090 fontsize => 1,
2143 can_events => 0, 2091 can_events => 0,
2144 #font => default_font 2092 #font => default_font
2145 @_, 2093 @_,
2146 2094
2147 layout => (new CFClient::Layout), 2095 layout => (new CFClient::Layout 1),
2148 par => [], 2096 par => [],
2149 height => 0, 2097 height => 0,
2150 children => [ 2098 children => [
2151 (new CFClient::UI::Empty expand => 1), 2099 (new CFClient::UI::Empty expand => 1),
2152 (new CFClient::UI::Slider vertical => 1), 2100 (new CFClient::UI::Slider vertical => 1),
2170 2118
2171 my $layout = $self->{layout}; 2119 my $layout = $self->{layout};
2172 2120
2173 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2121 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2174 $layout->set_width ($self->{children}[0]{w}); 2122 $layout->set_width ($self->{children}[0]{w});
2175 $layout->set_text ($text); 2123 $layout->set_markup ($text);
2176 2124
2177 ($layout->size)[1] 2125 ($layout->size)[1]
2178} 2126}
2179 2127
2180sub reflow { 2128sub reflow {
2218 2166
2219 return unless $self->{h} > 0; 2167 return unless $self->{h} > 0;
2220 2168
2221 delete $self->{texture}; 2169 delete $self->{texture};
2222 2170
2223 $ROOT->on_refresh ($self, sub { 2171 $ROOT->on_post_alloc ($self, sub {
2224 if (delete $self->{need_reflow}) { 2172 if (delete $self->{need_reflow}) {
2225 my $height = 0; 2173 my $height = 0;
2226 2174
2227 $height += $_->[0] = $self->text_height ($_->[2]) 2175 $height += $_->[0] = $self->text_height ($_->[2])
2228 for @{$self->{par}}; 2176 for @{$self->{par}};
2236 2184
2237 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2185 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2238 glClearColor 0, 0, 0, 0; 2186 glClearColor 0, 0, 0, 0;
2239 glClear GL_COLOR_BUFFER_BIT; 2187 glClear GL_COLOR_BUFFER_BIT;
2240 2188
2241 glEnable GL_BLEND;
2242 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2243 glEnable GL_TEXTURE_2D; 2189 glEnable GL_TEXTURE_2D;
2244 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2190 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2245 2191
2246 my $top = int $self->{children}[1]{range}[0]; 2192 my $top = int $self->{children}[1]{range}[0];
2247 2193
2256 2202
2257 for my $par (@{$self->{par}}) { 2203 for my $par (@{$self->{par}}) {
2258 my $h = $par->[0]; 2204 my $h = $par->[0];
2259 2205
2260 if ($y0 < $y + $h && $y < $y1) { 2206 if ($y0 < $y + $h && $y < $y1) {
2207 $layout->set_foreground (@{ $par->[1] });
2261 $layout->set_text ($par->[2]); 2208 $layout->set_markup ($par->[2]);
2262 2209
2263 glColor @{ $par->[1] };
2264 my ($W, $H) = $layout->size; 2210 my ($W, $H) = $layout->size;
2265 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); 2211 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0);
2266 } 2212 }
2267 2213
2268 $y += $h; 2214 $y += $h;
2269 } 2215 }
2270 2216
2271 glDisable GL_TEXTURE_2D; 2217 glDisable GL_TEXTURE_2D;
2272 glDisable GL_BLEND;
2273 }; 2218 };
2274 }); 2219 });
2275} 2220}
2276 2221
2277sub _draw { 2222sub _draw {
2278 my ($self) = @_; 2223 my ($self) = @_;
2279 2224
2280 glEnable GL_BLEND;
2281 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2282 glEnable GL_TEXTURE_2D; 2225 glEnable GL_TEXTURE_2D;
2283 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2226 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2284 glColor 1, 1, 1, 1; 2227 glColor 1, 1, 1, 1;
2285 $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2228 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2286 glDisable GL_TEXTURE_2D; 2229 glDisable GL_TEXTURE_2D;
2287 glDisable GL_BLEND;
2288 2230
2289 $self->{children}[1]->draw; 2231 $self->{children}[1]->draw;
2290 2232
2291} 2233}
2292 2234
2386 @_, 2328 @_,
2387 can_events => 0, 2329 can_events => 0,
2388 ) 2330 )
2389} 2331}
2390 2332
2391sub set_markup { 2333sub set_tooltip_from {
2392 my ($self, $text) = @_; 2334 my ($self, $widget) = @_;
2393 2335
2394 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; 2336 $self->add (new CFClient::UI::Label
2395 $self->{label}->set_markup ($text); 2337 markup => $widget->{tooltip},
2396 $self->add ($self->{label}); 2338 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2339 fontsize => 0.8,
2340 fg => [0, 0, 0, 1],
2341 font => ($widget->{tooltip_font} || $::FONT_PROP),
2342 );
2397} 2343}
2398 2344
2399sub size_request { 2345sub size_request {
2400 my ($self) = @_; 2346 my ($self) = @_;
2401
2402 $self->child->set_max_size ($::WIDTH * 0.3);
2403 2347
2404 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 2348 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2405 2349
2406 ($w + 4, $h + 4) 2350 ($w + 4, $h + 4)
2407} 2351}
2413} 2357}
2414 2358
2415sub _draw { 2359sub _draw {
2416 my ($self) = @_; 2360 my ($self) = @_;
2417 2361
2418 glPushMatrix;
2419 glTranslate 0.375, 0.375; 2362 glTranslate 0.375, 0.375;
2420 2363
2421 my ($w, $h) = @$self{qw(w h)}; 2364 my ($w, $h) = @$self{qw(w h)};
2422 2365
2423 glColor 1, 0.8, 0.4; 2366 glColor 1, 0.8, 0.4;
2434 glVertex 0 , $h; 2377 glVertex 0 , $h;
2435 glVertex $w, $h; 2378 glVertex $w, $h;
2436 glVertex $w, 0; 2379 glVertex $w, 0;
2437 glEnd; 2380 glEnd;
2438 2381
2439 glPopMatrix; 2382 glTranslate 2 - 0.375, 2 - 0.375;
2440
2441 glTranslate 2, 2;
2442 $self->SUPER::_draw; 2383 $self->SUPER::_draw;
2443} 2384}
2444 2385
2445############################################################################# 2386#############################################################################
2446 2387
2464} 2405}
2465 2406
2466sub _draw { 2407sub _draw {
2467 my ($self) = @_; 2408 my ($self) = @_;
2468 2409
2410 return unless $::CONN;#d# manage and cache textures differently
2469 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2411 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2470 2412
2471 # TODO animation 2413 # TODO animation
2472 if ($tex) { 2414 if ($tex) {
2473 glEnable GL_BLEND;
2474 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2475 glEnable GL_TEXTURE_2D; 2415 glEnable GL_TEXTURE_2D;
2476 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2416 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2477 glColor 1, 1, 1, 1; 2417 glColor 1, 1, 1, 1;
2478 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 2418 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2479 glDisable GL_TEXTURE_2D; 2419 glDisable GL_TEXTURE_2D;
2480 glDisable GL_BLEND;
2481 } 2420 }
2421}
2422
2423#############################################################################
2424
2425package CFClient::UI::InventoryItem;
2426
2427our @ISA = CFClient::UI::HBox::;
2428
2429sub new {
2430 my $class = shift;
2431
2432 my %args = @_;
2433
2434 my $item = delete $args{item};
2435
2436 my $desc = $item->{nrof} < 2
2437 ? $item->{name}
2438 : "$item->{nrof} $item->{name_pl}";
2439
2440
2441 my $self = $class->SUPER::new (
2442 can_hover => 1,
2443 can_events => 1,
2444 tooltip => (CFClient::UI::Label->escape ($desc)
2445 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2446 connect_button_down => sub {
2447 my ($self, $ev, $x, $y) = @_;
2448
2449 # todo: maybe put examine on 1? but should just be a tooltip :(
2450 if ($ev->{button} == 1) {
2451 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0");
2452 } elsif ($ev->{button} == 2) {
2453 $::CONN->send ("apply $item->{tag}");
2454 } elsif ($ev->{button} == 3) {
2455 CFClient::UI::Menu->new (
2456 items => [
2457 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2458 [
2459 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2460 sub { $::CONN->send ("lock $item->{tag}") },
2461 ],
2462 ["mark", sub { $::CONN->send ("mark $item->{tag}") }],
2463 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2464 ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }],
2465 ],
2466 )->popup ($ev);
2467 }
2468
2469 1
2470 },
2471 %args
2472 );
2473
2474 $self->add (new CFClient::UI::Face
2475 can_events => 0,
2476 face => $item->{face},
2477 anim => $item->{anim},
2478 animspeed => $item->{animspeed},
2479 );
2480
2481 $self->add (new CFClient::UI::Label
2482 can_events => 0,
2483 text => $desc,
2484 );
2485
2486 $self
2487}
2488
2489#############################################################################
2490
2491package CFClient::UI::Inventory;
2492
2493our @ISA = CFClient::UI::ScrolledWindow::;
2494
2495sub new {
2496 my $class = shift;
2497
2498 my $self = $class->SUPER::new (
2499 scrolled => (new CFClient::UI::VBox),
2500 @_,
2501 );
2502
2503 $self
2504}
2505
2506sub set_items {
2507 my ($self, $items) = @_;
2508
2509 $self->{scrolled}->clear;
2510 return unless $items;
2511
2512 my @items = sort { $a->{type} <=> $b->{type} } @$items;
2513
2514 $self->{real_items} = \@items;
2515
2516 for my $item (@items) {
2517 my $desc = $item->{nrof} < 2
2518 ? $item->{name}
2519 : "$item->{nrof} $item->{name_pl}";
2520
2521 $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item);
2522 }
2523
2524# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2525}
2526
2527sub size_request {
2528 my ($self) = @_;
2529 ($self->{req_w}, $self->{req_h});
2482} 2530}
2483 2531
2484############################################################################# 2532#############################################################################
2485 2533
2486package CFClient::UI::Menu; 2534package CFClient::UI::Menu;
2553 } 2601 }
2554} 2602}
2555 2603
2556############################################################################# 2604#############################################################################
2557 2605
2606package CFClient::UI::Statusbox;
2607
2608our @ISA = CFClient::UI::VBox::;
2609
2610sub reorder {
2611 my ($self) = @_;
2612 my $NOW = time;
2613
2614 while (my ($k, $v) = each %{ $self->{item} }) {
2615 delete $self->{item}{$k} if $v->{timeout} < $NOW;
2616 }
2617
2618 my @widgets;
2619
2620 my @items = sort {
2621 $a->{pri} <=> $b->{pri}
2622 or $b->{id} <=> $a->{id}
2623 } values %{ $self->{item} };
2624
2625 my $count = 10 + 1;
2626 for my $item (@items) {
2627 last unless --$count;
2628
2629 push @widgets, $item->{label} ||= do {
2630 # TODO: doesn't handle markup well (read as: at all)
2631 my $short = $item->{count} > 1
2632 ? "<b>$item->{count} ×</b> $item->{text}"
2633 : $item->{text};
2634
2635 for ($short) {
2636 s/^\s+//;
2637 s/\012.*/…/s;
2638 my $len = int 40 / $item->{fontsize};
2639 substr $_, $len, length, "…" if $len < length;
2640 }
2641
2642 new CFClient::UI::Label
2643 markup => $short,
2644 tooltip => $item->{tooltip},
2645 tooltip_font => $::FONT_PROP,
2646 tooltip_width => 0.67,
2647 fontsize => $item->{fontsize},
2648 color => $item->{color},
2649 can_events => 1,
2650 can_hover => 1
2651 };
2652 }
2653
2654 $self->clear;
2655 $self->SUPER::add (reverse @widgets);
2656}
2657
2658sub add {
2659 my ($self, $text, %arg) = @_;
2660
2661 $text =~ s/^\s+//;
2662 $text =~ s/\s+$//;
2663
2664 my $timeout = time + ((delete $arg{timeout}) || 60);
2665
2666 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2667
2668 if (my $item = $self->{item}{$group}) {
2669 if ($item->{text} eq $text) {
2670 $item->{count}++;
2671 } else {
2672 $item->{count} = 1;
2673 $item->{text} = $item->{tooltip} = $text;
2674 }
2675 $item->{id} = ++$self->{id};
2676 $item->{timeout} = $timeout;
2677 delete $item->{label};
2678 } else {
2679 $self->{item}{$group} = {
2680 id => ++$self->{id},
2681 text => $text,
2682 timeout => $timeout,
2683 tooltip => $text,
2684 fontsize => 0.8,
2685 color => [0.8, 0.8, 0.8, 0.8],
2686 pri => 0,
2687 count => 1,
2688 %arg,
2689 };
2690 }
2691
2692 $self->reorder;
2693}
2694
2695#############################################################################
2696
2558package CFClient::UI::Root; 2697package CFClient::UI::Root;
2559 2698
2560our @ISA = CFClient::UI::Container::; 2699our @ISA = CFClient::UI::Container::;
2561 2700
2562use CFClient::OpenGL; 2701use CFClient::OpenGL;
2563 2702
2564sub check_size { 2703sub new {
2565 my ($self) = @_; 2704 my $class = shift;
2566 2705
2567 $self->configure (0, 0, $::WIDTH, $::HEIGHT); 2706 $class->SUPER::new (
2568} 2707 @_,
2569 2708 )
2570sub size_request {
2571 ($::WIDTH, $::HEIGHT)
2572} 2709}
2573 2710
2574sub configure { 2711sub configure {
2575 my ($self, $x, $y, $w, $h) = @_; 2712 my ($self, $x, $y, $w, $h) = @_;
2576 2713
2577 $self->SUPER::configure ($x, $y, $w, $h); 2714 $self->{w} = $w;
2715 $self->{h} = $h;
2716}
2578 2717
2718sub check_size {
2719 my ($self) = @_;
2720
2721 $self->size_allocate ($self->{w}, $self->{h})
2722 if $self->{w};
2723}
2724
2725sub size_request {
2726 my ($self) = @_;
2727
2728 ($self->{w}, $self->{h})
2729}
2730
2731sub size_allocate {
2732 my ($self, $w, $h) = @_;
2733
2734 my $old_w = $self->{old_w};
2735 my $old_h = $self->{old_h};
2736
2737 if ($old_w && $old_h) {
2738 for my $child ($self->children) {
2739 $child->{x} = int 0.5 + $child->{x} * $w / $old_w;
2740 $child->{w} = int 0.5 + $child->{w} * $w / $old_w;
2741 $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w};
2742 $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w};
2743 $child->{y} = int 0.5 + $child->{y} * $h / $old_h;
2744 $child->{h} = int 0.5 + $child->{h} * $h / $old_h;
2745 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h};
2746 $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h};
2747 }
2748 }
2749
2579 for my $child (@{$self->{children}}) { 2750 for my $child ($self->children) {
2580 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 2751 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2581 2752
2582 $X = List::Util::max 0, List::Util::min $w - $W, $X; 2753 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2583 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 2754 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2584 $child->configure ($X, $Y, $W,$H); 2755 $child->configure ($X, $Y, $W, $H);
2585 } 2756 }
2586}
2587 2757
2588sub _topleft { 2758 $self->{old_w} = $w;
2759 $self->{old_h} = $h;
2760}
2761
2762sub coord2local {
2589 my ($self, $x, $y) = @_; 2763 my ($self, $x, $y) = @_;
2590 2764
2591 ($x, $y) 2765 ($x, $y)
2592} 2766}
2593 2767
2768sub coord2global {
2769 my ($self, $x, $y) = @_;
2770
2771 ($x, $y)
2772}
2773
2594sub update { 2774sub update {
2595 my ($self) = @_; 2775 my ($self) = @_;
2596 2776
2597 $self->check_size; 2777 $self->check_size;
2598 ::refresh (); 2778 $::WANT_REFRESH++;
2599} 2779}
2600 2780
2601sub add { 2781sub add {
2602 my ($self, $child) = @_; 2782 my ($self, $child) = @_;
2603 2783
2604 # integerize window positions 2784 # integerise window positions
2605 $child->{x} = int $child->{x}; 2785 $child->{x} = int $child->{x};
2606 $child->{y} = int $child->{y}; 2786 $child->{y} = int $child->{y};
2607 2787
2608 $self->SUPER::add ($child); 2788 $self->SUPER::add ($child);
2609} 2789}
2612 my ($self, $id, $cb) = @_; 2792 my ($self, $id, $cb) = @_;
2613 2793
2614 $self->{refresh_hook}{$id} = $cb; 2794 $self->{refresh_hook}{$id} = $cb;
2615} 2795}
2616 2796
2797sub on_post_alloc {
2798 my ($self, $id, $cb) = @_;
2799
2800 $self->{post_alloc_hook}{$id} = $cb;
2801}
2802
2617sub draw { 2803sub draw {
2618 my ($self) = @_; 2804 my ($self) = @_;
2619 2805
2620 while (my $rcb = delete $self->{refresh_hook}) { 2806 while ($self->{refresh_hook}) {
2621 $_->() for values %$rcb; 2807 $_->()
2808 for values %{delete $self->{refresh_hook}};
2809 }
2810
2811 if ($self->{check_size}) {
2812 my @queue = ([], []);
2813
2814 for (;;) {
2815 if ($self->{check_size}) {
2816 # heuristic: check containers last
2817 push @{ $queue[ ! ! $_->isa ("CFClient::UI::Container") ] }, $_
2818 for values %{delete $self->{check_size}}
2819 }
2820
2821 my $widget = (pop @{ $queue[0] }) || (pop @{ $queue[1] }) || last;
2822
2823 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
2824 ? @$widget{qw(user_w user_h)}
2825 : $widget->size_request;
2826
2827 if (delete $widget->{force_alloc}
2828 or $w != $widget->{req_w} or $h != $widget->{req_h}) {
2829 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
2830
2831 $widget->{req_w} = $w;
2832 $widget->{req_h} = $h;
2833
2834 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
2835
2836 $widget->{parent}->check_size
2837 if $widget->{parent};
2838 }
2839 }
2840 }
2841
2842 while ($self->{size_alloc}) {
2843 for (values %{delete $self->{size_alloc}}) {
2844 my ($widget, $w, $h) = @$_;
2845
2846 $w = 0 if $w < 0;
2847 $h = 0 if $h < 0;
2848
2849 $widget->{w} = $w;
2850 $widget->{h} = $h;
2851 $widget->size_allocate ($w, $h);
2852 $widget->emit (size_allocate => $w, $h);
2853 }
2854 }
2855
2856 while ($self->{post_alloc_hook}) {
2857 $_->()
2858 for values %{delete $self->{post_alloc_hook}};
2622 } 2859 }
2623 2860
2624 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2861 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2625 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2862 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2626 glClear GL_COLOR_BUFFER_BIT; 2863 glClear GL_COLOR_BUFFER_BIT;
2634 $self->_draw; 2871 $self->_draw;
2635} 2872}
2636 2873
2637############################################################################# 2874#############################################################################
2638 2875
2639package CFClient::UI::Inventory;
2640
2641our @ISA = CFClient::UI::ScrolledWindow::;
2642
2643sub new {
2644 my $class = shift;
2645
2646 my $self = $class->SUPER::new (
2647 scrolled => (new CFClient::UI::VBox),
2648 @_,
2649 );
2650
2651 $self
2652}
2653
2654sub set_items {
2655 my ($self, $items) = @_;
2656
2657 $self->{scrolled}->clear;
2658 return unless $items;
2659
2660 my @items = sort { $a->{type} <=> $b->{type} } @$items;
2661
2662 $self->{real_items} = \@items;
2663
2664 for my $item (@items) {
2665 my $desc = $item->{nrof} < 2
2666 ? $item->{name}
2667 : "$item->{nrof} $item->{name_pl}";
2668
2669 my $hb = new CFClient::UI::HBox;
2670
2671 $hb->add (my $f = new CFClient::UI::Face
2672 can_events => 0,
2673 face => $item->{face},
2674 anim => $item->{anim},
2675 animspeed => $item->{animspeed},
2676 expand => 1,
2677 );
2678 $hb->add (new CFClient::UI::Label text => $desc, expand => 1);
2679 $self->{scrolled}->add ($hb);
2680 }
2681
2682# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2683}
2684
2685sub size_request {
2686 my ($self) = @_;
2687 (100, 200)
2688}
2689
2690#############################################################################
2691
2692package CFClient::UI; 2876package CFClient::UI;
2693 2877
2694$ROOT = new CFClient::UI::Root; 2878$ROOT = new CFClient::UI::Root;
2695$TOOLTIP = new CFClient::UI::Tooltip; 2879$TOOLTIP = new CFClient::UI::Tooltip;
2696 2880

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines