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.123 by root, Mon Apr 17 19:50:22 2006 UTC vs.
Revision 1.127 by root, Mon Apr 17 21:03:31 2006 UTC

260 my ($self, $parent) = @_; 260 my ($self, $parent) = @_;
261 261
262 Scalar::Util::weaken ($self->{parent} = $parent); 262 Scalar::Util::weaken ($self->{parent} = $parent);
263} 263}
264 264
265sub check_size {
266 my ($self) = @_;
267
268 my ($w, $h) = $self->size_request;
269
270 if ($w != $self->{req_w} || $h != $self->{req_h}) {
271 $self->{req_w} = $w;
272 $self->{req_h} = $h;
273
274 $self->{parent}->check_size
275 if $self->{parent};
276 }
277}
278
265sub update { 279sub update {
266 my ($self) = @_; 280 my ($self) = @_;
267 281
268 $self->{parent}->update 282 $self->{parent}->update
269 if $self->{parent}; 283 if $self->{parent};
368 sort { $a->{z} <=> $b->{z} } 382 sort { $a->{z} <=> $b->{z} }
369 @{$self->{children}}, $child 383 @{$self->{children}}, $child
370 ]; 384 ];
371 385
372 $self->{w} = $self->{h} = -1; 386 $self->{w} = $self->{h} = -1;
373 $self->update; 387
388 $child->check_size;
374} 389}
375 390
376sub remove { 391sub remove {
377 my ($self, $widget) = @_; 392 my ($self, $widget) = @_;
378 393
379 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 394 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
380 395
381 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 396 $self->check_size;
382} 397}
383 398
384sub find_widget { 399sub find_widget {
385 my ($self, $x, $y) = @_; 400 my ($self, $x, $y) = @_;
386 401
506 $tex->draw_quad (0, 0, $w, $h); 521 $tex->draw_quad (0, 0, $w, $h);
507 522
508 glDisable GL_BLEND; 523 glDisable GL_BLEND;
509 glDisable GL_TEXTURE_2D; 524 glDisable GL_TEXTURE_2D;
510} 525}
526
527#############################################################################
528
529package CFClient::UI::ViewPort;
530
531our @ISA = CFClient::UI::Window::;
532
533sub new { die }
534
535sub size_request {
536 my ($self) = @_;
537
538 @$self{qw(child_w child_h)} = $self->child->size_request;
539 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
540
541 @$self{qw(child_w child_h)}
542}
543
544sub size_allocate {
545 my ($self, $x, $y, $w, $h) = @_;
546
547 $self->_size_allocate ($x, $y, $w, $h) or return;
548}
549
550sub _draw {
551 my ($self) = @_;
552
553 $self->{children}[1]->draw;
554}
555
511 556
512############################################################################# 557#############################################################################
513 558
514package CFClient::UI::Frame; 559package CFClient::UI::Frame;
515 560
710 755
711 $child->set_parent ($self); 756 $child->set_parent ($self);
712 $self->{children}[$y][$x] = $child; 757 $self->{children}[$y][$x] = $child;
713 758
714 $self->{w} = $self->{h} = -1; 759 $self->{w} = $self->{h} = -1;
715 $self->update; 760
761 $child->check_size;
716} 762}
717 763
718# TODO: move to container class maybe? send childs a signal on removal? 764# TODO: move to container class maybe? send childs a signal on removal?
719sub clear { 765sub clear {
720 my ($self) = @_; 766 my ($self) = @_;
846} 892}
847 893
848sub size_allocate { 894sub size_allocate {
849 my ($self, $x, $y, $w, $h) = @_; 895 my ($self, $x, $y, $w, $h) = @_;
850 896
851 $self->_size_allocate ($x, $y, $w, $h); 897 $self->_size_allocate ($x, $y, $w, $h) or return;
852 898
853 ($h, $w) = ($w, $h); 899 ($h, $w) = ($w, $h);
854 900
855 my $children = $self->{children}; 901 my $children = $self->{children};
856 902
882 my $h = $h[$_]; 928 my $h = $h[$_];
883 $child->size_allocate ($y, 0, $h, $w); 929 $child->size_allocate ($y, 0, $h, $w);
884 930
885 $y += $h; 931 $y += $h;
886 } 932 }
933
934 1
887} 935}
888 936
889############################################################################# 937#############################################################################
890 938
891package CFClient::UI::VBox; 939package CFClient::UI::VBox;
906} 954}
907 955
908sub size_allocate { 956sub size_allocate {
909 my ($self, $x, $y, $w, $h) = @_; 957 my ($self, $x, $y, $w, $h) = @_;
910 958
911 $self->_size_allocate ($x, $y, $w, $h); 959 $self->_size_allocate ($x, $y, $w, $h) or return;
912 960
913 my $children = $self->{children}; 961 my $children = $self->{children};
914 962
915 my @h = map +($_->size_request)[1], @$children; 963 my @h = map +($_->size_request)[1], @$children;
916 964
938 my $h = $h[$_]; 986 my $h = $h[$_];
939 $child->size_allocate (0, $y, $w, $h); 987 $child->size_allocate (0, $y, $w, $h);
940 988
941 $y += $h; 989 $y += $h;
942 } 990 }
991
992 1
943} 993}
944 994
945############################################################################# 995#############################################################################
946 996
947package CFClient::UI::Label; 997package CFClient::UI::Label;
1116} 1166}
1117 1167
1118sub size_allocate { 1168sub size_allocate {
1119 my ($self, $x, $y, $w, $h) = @_; 1169 my ($self, $x, $y, $w, $h) = @_;
1120 1170
1121 $self->SUPER::size_allocate ($x, $y, $w, $h); 1171 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1122 1172
1123 $self->_set_text ($self->{text}); 1173 $self->_set_text ($self->{text});
1124} 1174}
1125 1175
1126sub set_text { 1176sub set_text {
1276 padding => 4, 1326 padding => 4,
1277 fg => [1, 1, 1], 1327 fg => [1, 1, 1],
1278 bg => [1, 1, 1, 0.2], 1328 bg => [1, 1, 1, 0.2],
1279 active_fg => [0, 0, 1], 1329 active_fg => [0, 0, 1],
1280 can_hover => 1, 1330 can_hover => 1,
1331 align => 0,
1332 valign => 0,
1281 @_ 1333 @_
1282 ) 1334 )
1283} 1335}
1284 1336
1285sub button_up { 1337sub button_up {
1347} 1399}
1348 1400
1349sub size_allocate { 1401sub size_allocate {
1350 my ($self, $x, $y, $w, $h) = @_; 1402 my ($self, $x, $y, $w, $h) = @_;
1351 1403
1352 $self->_size_allocate ($x, $y, $w, $h); 1404 $self->_size_allocate ($x, $y, $w, $h) or return;
1353} 1405}
1354 1406
1355sub button_down { 1407sub button_down {
1356 my ($self, $ev, $x, $y) = @_; 1408 my ($self, $ev, $x, $y) = @_;
1357 1409
1381 1433
1382 $tex->draw_quad (0, 0, $s, $s); 1434 $tex->draw_quad (0, 0, $s, $s);
1383 1435
1384 glDisable GL_TEXTURE_2D; 1436 glDisable GL_TEXTURE_2D;
1385 glDisable GL_BLEND; 1437 glDisable GL_BLEND;
1438}
1439
1440#############################################################################
1441
1442package CFClient::UI::VGauge;
1443
1444our @ISA = CFClient::UI::Base::;
1445
1446use SDL::OpenGL;
1447
1448my %tex = (
1449 food => [
1450 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1451 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1452 ],
1453 grace => [
1454 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1455 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1456 ],
1457 hp => [
1458 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1459 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1460 ],
1461 mana => [
1462 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1463 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1464 ],
1465);
1466
1467# eg. VGauge->new (gauge => 'food'), default gauge: food
1468sub new {
1469 my $class = shift;
1470
1471 my $self = $class->SUPER::new (gauge => 'food', @_);
1472
1473 $self
1474}
1475
1476sub size_request {
1477 my ($self) = @_;
1478
1479 my $tex = $tex{$self->{gauge}}[0];
1480
1481 @$tex{qw(w h)}
1482}
1483
1484sub set_max {
1485 my ($self, $max) = @_;
1486
1487 $self->{max_val} = $max;
1488}
1489
1490sub set_value {
1491 my ($self, $val, $max) = @_;
1492
1493 $self->set_max ($max)
1494 if defined $max;
1495
1496 $max = $self->{max_val};
1497 $self->{val} = $val;
1498
1499 $self->update;
1500}
1501
1502sub _draw {
1503 my ($self) = @_;
1504
1505 my $tex = $tex{$self->{gauge}};
1506
1507 my ($w, $h) = ($self->{w}, $self->{h});
1508
1509 my $ycut = $self->{val} / ($self->{max_val} || 1);
1510 $ycut = 1 if $self->{val} > $self->{max_val};
1511
1512 my $t1 = $tex->[0];
1513 my $t2 = $tex->[1];
1514
1515 glEnable GL_BLEND;
1516 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1517 glEnable GL_TEXTURE_2D;
1518 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1519
1520 my $h1 = $self->{h} - $ycut * $self->{h};
1521 my $h2 = $ycut * $self->{h};
1522
1523 my $yp = 0;
1524
1525 glBindTexture (GL_TEXTURE_2D, $t1->{name});
1526 glBegin (GL_QUADS);
1527 glTexCoord (0, 0); glVertex (0 , $yp);
1528 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1);
1529 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1);
1530 glTexCoord (1, 0); glVertex (0 + $w, $yp);
1531 glEnd ();
1532
1533 $yp += $h1;
1534
1535 glBindTexture (GL_TEXTURE_2D, $t2->{name});
1536 glBegin (GL_QUADS);
1537 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp);
1538 glTexCoord (0, 1); glVertex (0 , $yp + $h2);
1539 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2);
1540 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp);
1541 glEnd ();
1542
1543 glDisable GL_BLEND;
1544 glDisable GL_TEXTURE_2D;
1386} 1545}
1387 1546
1388############################################################################# 1547#############################################################################
1389 1548
1390package CFClient::UI::Slider; 1549package CFClient::UI::Slider;
1586} 1745}
1587 1746
1588sub size_allocate { 1747sub size_allocate {
1589 my ($self, $x, $y, $w, $h) = @_; 1748 my ($self, $x, $y, $w, $h) = @_;
1590 1749
1591 $self->SUPER::size_allocate ($x, $y, $w, $h); 1750 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1592 1751
1593 $self->{layout}->set_height ($self->{fontsize}); 1752 $self->{layout}->set_height ($self->{fontsize});
1594 $self->{layout}->set_width ($self->{w}); 1753 $self->{layout}->set_width ($self->{w});
1595 1754
1596 $self->reflow; 1755 $self->reflow;
1756 $self->update;
1597} 1757}
1598 1758
1599sub add_paragraph { 1759sub add_paragraph {
1600 my ($self, $color, $text) = @_; 1760 my ($self, $color, $text) = @_;
1601 1761
2009 2169
2010our @ISA = CFClient::UI::Container::; 2170our @ISA = CFClient::UI::Container::;
2011 2171
2012use SDL::OpenGL; 2172use SDL::OpenGL;
2013 2173
2174sub check_size {
2175 my ($self) = @_;
2176
2177 $self->size_allocate (0, 0, $::WITH, $::HEIGHT);
2178}
2179
2014sub size_request { 2180sub size_request {
2015 ($::WIDTH, $::HEIGHT) 2181 ($::WIDTH, $::HEIGHT)
2016} 2182}
2017 2183
2018sub size_allocate { 2184sub size_allocate {
2031} 2197}
2032 2198
2033sub update { 2199sub update {
2034 my ($self) = @_; 2200 my ($self) = @_;
2035 2201
2036 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2202 $self->check_size;
2037 ::refresh (); 2203 ::refresh ();
2038} 2204}
2039 2205
2040sub add { 2206sub add {
2041 my ($self, $widget) = @_; 2207 my ($self, $widget) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines