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.125 by root, Mon Apr 17 20:52:15 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};
376sub remove { 390sub remove {
377 my ($self, $widget) = @_; 391 my ($self, $widget) = @_;
378 392
379 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 393 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
380 394
381 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 395 $self->check_size;
382} 396}
383 397
384sub find_widget { 398sub find_widget {
385 my ($self, $x, $y) = @_; 399 my ($self, $x, $y) = @_;
386 400
506 $tex->draw_quad (0, 0, $w, $h); 520 $tex->draw_quad (0, 0, $w, $h);
507 521
508 glDisable GL_BLEND; 522 glDisable GL_BLEND;
509 glDisable GL_TEXTURE_2D; 523 glDisable GL_TEXTURE_2D;
510} 524}
525
526#############################################################################
527
528package CFClient::UI::ViewPort;
529
530our @ISA = CFClient::UI::Window::;
531
532sub new { die }
533
534sub size_request {
535 my ($self) = @_;
536
537 @$self{qw(child_w child_h)} = $self->child->size_request;
538 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
539
540 @$self{qw(child_w child_h)}
541}
542
543sub size_allocate {
544 my ($self, $x, $y, $w, $h) = @_;
545
546 $self->_size_allocate ($x, $y, $w, $h) or return;
547}
548
549sub _draw {
550 my ($self) = @_;
551
552 $self->{children}[1]->draw;
553}
554
511 555
512############################################################################# 556#############################################################################
513 557
514package CFClient::UI::Frame; 558package CFClient::UI::Frame;
515 559
846} 890}
847 891
848sub size_allocate { 892sub size_allocate {
849 my ($self, $x, $y, $w, $h) = @_; 893 my ($self, $x, $y, $w, $h) = @_;
850 894
851 $self->_size_allocate ($x, $y, $w, $h); 895 $self->_size_allocate ($x, $y, $w, $h) or return;
852 896
853 ($h, $w) = ($w, $h); 897 ($h, $w) = ($w, $h);
854 898
855 my $children = $self->{children}; 899 my $children = $self->{children};
856 900
882 my $h = $h[$_]; 926 my $h = $h[$_];
883 $child->size_allocate ($y, 0, $h, $w); 927 $child->size_allocate ($y, 0, $h, $w);
884 928
885 $y += $h; 929 $y += $h;
886 } 930 }
931
932 1
887} 933}
888 934
889############################################################################# 935#############################################################################
890 936
891package CFClient::UI::VBox; 937package CFClient::UI::VBox;
906} 952}
907 953
908sub size_allocate { 954sub size_allocate {
909 my ($self, $x, $y, $w, $h) = @_; 955 my ($self, $x, $y, $w, $h) = @_;
910 956
911 $self->_size_allocate ($x, $y, $w, $h); 957 $self->_size_allocate ($x, $y, $w, $h) or return;
912 958
913 my $children = $self->{children}; 959 my $children = $self->{children};
914 960
915 my @h = map +($_->size_request)[1], @$children; 961 my @h = map +($_->size_request)[1], @$children;
916 962
938 my $h = $h[$_]; 984 my $h = $h[$_];
939 $child->size_allocate (0, $y, $w, $h); 985 $child->size_allocate (0, $y, $w, $h);
940 986
941 $y += $h; 987 $y += $h;
942 } 988 }
989
990 1
943} 991}
944 992
945############################################################################# 993#############################################################################
946 994
947package CFClient::UI::Label; 995package CFClient::UI::Label;
1116} 1164}
1117 1165
1118sub size_allocate { 1166sub size_allocate {
1119 my ($self, $x, $y, $w, $h) = @_; 1167 my ($self, $x, $y, $w, $h) = @_;
1120 1168
1121 $self->SUPER::size_allocate ($x, $y, $w, $h); 1169 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1122 1170
1123 $self->_set_text ($self->{text}); 1171 $self->_set_text ($self->{text});
1124} 1172}
1125 1173
1126sub set_text { 1174sub set_text {
1347} 1395}
1348 1396
1349sub size_allocate { 1397sub size_allocate {
1350 my ($self, $x, $y, $w, $h) = @_; 1398 my ($self, $x, $y, $w, $h) = @_;
1351 1399
1352 $self->_size_allocate ($x, $y, $w, $h); 1400 $self->_size_allocate ($x, $y, $w, $h) or return;
1353} 1401}
1354 1402
1355sub button_down { 1403sub button_down {
1356 my ($self, $ev, $x, $y) = @_; 1404 my ($self, $ev, $x, $y) = @_;
1357 1405
1381 1429
1382 $tex->draw_quad (0, 0, $s, $s); 1430 $tex->draw_quad (0, 0, $s, $s);
1383 1431
1384 glDisable GL_TEXTURE_2D; 1432 glDisable GL_TEXTURE_2D;
1385 glDisable GL_BLEND; 1433 glDisable GL_BLEND;
1434}
1435
1436#############################################################################
1437
1438package CFClient::UI::VGauge;
1439
1440our @ISA = CFClient::UI::Base::;
1441
1442use SDL::OpenGL;
1443
1444my %tex = (
1445 food => [
1446 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1447 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1448 ],
1449 grace => [
1450 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1451 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1452 ],
1453 hp => [
1454 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1455 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1456 ],
1457 mana => [
1458 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1459 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1460 ],
1461);
1462
1463# eg. VGauge->new (gauge => 'food'), default gauge: food
1464sub new {
1465 my $class = shift;
1466
1467 my $self = $class->SUPER::new (gauge => 'food', @_);
1468
1469 $self
1470}
1471
1472sub size_request {
1473 my ($self) = @_;
1474
1475 ($self->{w}, $self->{h})
1476}
1477
1478sub set_max {
1479 my ($self, $max) = @_;
1480 $self->{max_val} = $max;
1481}
1482
1483sub set_value {
1484 my ($self, $val, $max) = @_;
1485
1486 $self->set_max ($max)
1487 if defined $max;
1488
1489 $max = $self->{max_val};
1490 $self->{val} = $val;
1491
1492 $self->update;
1493}
1494
1495sub _draw {
1496 my ($self) = @_;
1497
1498 my $tex = $tex{$self->{gauge}};
1499
1500 my ($w, $h) = ($self->{w}, $self->{h});
1501
1502 my $ycut = $self->{val} / ($self->{max_val} || 1);
1503 $ycut = 1 if $self->{val} > $self->{max_val};
1504
1505 my $t1 = $tex->[0];
1506 my $t2 = $tex->[1];
1507
1508 glEnable GL_BLEND;
1509 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1510 glEnable GL_TEXTURE_2D;
1511 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1512
1513 my $h1 = $self->{h} - $ycut * $self->{h};
1514 my $h2 = $ycut * $self->{h};
1515
1516 my $yp = 0;
1517
1518 glBindTexture (GL_TEXTURE_2D, $t1->{name});
1519 glBegin (GL_QUADS);
1520 glTexCoord (0, 0); glVertex (0 , $yp);
1521 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1);
1522 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1);
1523 glTexCoord (1, 0); glVertex (0 + $w, $yp);
1524 glEnd ();
1525
1526 $yp += $h1;
1527
1528 glBindTexture (GL_TEXTURE_2D, $t2->{name});
1529 glBegin (GL_QUADS);
1530 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp);
1531 glTexCoord (0, 1); glVertex (0 , $yp + $h2);
1532 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2);
1533 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp);
1534 glEnd ();
1535
1536 glDisable GL_BLEND;
1537 glDisable GL_TEXTURE_2D;
1386} 1538}
1387 1539
1388############################################################################# 1540#############################################################################
1389 1541
1390package CFClient::UI::Slider; 1542package CFClient::UI::Slider;
1586} 1738}
1587 1739
1588sub size_allocate { 1740sub size_allocate {
1589 my ($self, $x, $y, $w, $h) = @_; 1741 my ($self, $x, $y, $w, $h) = @_;
1590 1742
1591 $self->SUPER::size_allocate ($x, $y, $w, $h); 1743 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1592 1744
1593 $self->{layout}->set_height ($self->{fontsize}); 1745 $self->{layout}->set_height ($self->{fontsize});
1594 $self->{layout}->set_width ($self->{w}); 1746 $self->{layout}->set_width ($self->{w});
1595 1747
1596 $self->reflow; 1748 $self->reflow;
1749 $self->update;
1597} 1750}
1598 1751
1599sub add_paragraph { 1752sub add_paragraph {
1600 my ($self, $color, $text) = @_; 1753 my ($self, $color, $text) = @_;
1601 1754
2009 2162
2010our @ISA = CFClient::UI::Container::; 2163our @ISA = CFClient::UI::Container::;
2011 2164
2012use SDL::OpenGL; 2165use SDL::OpenGL;
2013 2166
2167sub check_size {
2168 my ($self) = @_;
2169
2170 $self->size_allocate (0, 0, $::WITH, $::HEIGHT);
2171}
2172
2014sub size_request { 2173sub size_request {
2015 ($::WIDTH, $::HEIGHT) 2174 ($::WIDTH, $::HEIGHT)
2016} 2175}
2017 2176
2018sub size_allocate { 2177sub size_allocate {
2031} 2190}
2032 2191
2033sub update { 2192sub update {
2034 my ($self) = @_; 2193 my ($self) = @_;
2035 2194
2036 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2195 $self->check_size;
2037 ::refresh (); 2196 ::refresh ();
2038} 2197}
2039 2198
2040sub add { 2199sub add {
2041 my ($self, $widget) = @_; 2200 my ($self, $widget) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines