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.143 by root, Thu Apr 20 21:28:51 2006 UTC vs.
Revision 1.148 by elmex, Sat Apr 22 12:14:45 2006 UTC

140 0 140 0
141} 141}
142 142
143sub size_request { 143sub size_request {
144 require Carp; 144 require Carp;
145 Carp::confess "size_request is abtract"; 145 Carp::confess "size_request is abstract";
146} 146}
147 147
148sub configure { 148sub configure {
149 my ($self, $x, $y, $w, $h) = @_; 149 my ($self, $x, $y, $w, $h) = @_;
150 150
152 my $w2 = List::Util::min $w, int $h * $self->{aspect}; 152 my $w2 = List::Util::min $w, int $h * $self->{aspect};
153 my $h2 = List::Util::min $h, int $w / $self->{aspect}; 153 my $h2 = List::Util::min $h, int $w / $self->{aspect};
154 154
155 # use alignment to adjust x, y 155 # use alignment to adjust x, y
156 156
157 $x += ($w - $w2) * 0.5; 157 $x += int +($w - $w2) * 0.5;
158 $y += ($h - $h2) * 0.5; 158 $y += int +($h - $h2) * 0.5;
159 159
160 ($w, $h) = ($w2, $h2); 160 ($w, $h) = ($w2, $h2);
161 } 161 }
162 162
163 if ($self->{x} != $x || $self->{y} != $y) { 163 if ($self->{x} != $x || $self->{y} != $y) {
582 582
583our @ISA = CFClient::UI::Bin::; 583our @ISA = CFClient::UI::Bin::;
584 584
585use CFClient::OpenGL; 585use CFClient::OpenGL;
586 586
587sub new {
588 my $class = shift;
589
590 my $self = $class->SUPER::new (
591 bg => [1, 1, 1, 1],
592 border_bg => [1, 1, 1, 1],
593 border => 0.8,
594 @_
595 );
596
597 $self
598}
599
600sub set_size {
601 my ($self, $w, $h) = @_;
602 $self->{req_w} = $w;
603 $self->{req_h} = $h;
604 $self->check_size;
605}
606
587sub size_request { 607sub size_request {
588 my ($self) = @_; 608 my ($self) = @_;
589 my $chld = $self->child 609 ($self->{req_w}, $self->{req_h})
590 or return (0, 0);
591
592 $chld->move (2, 2);
593
594 map { $_ + 4 } $chld->size_request;
595} 610}
596 611
597sub size_allocate { 612sub size_allocate {
598 my ($self, $x, $y, $w, $h) = @_; 613 my ($self, $w, $h) = @_;
599 614 $self->{w} = $w;
615 $self->{h} = $h;
600 $self->child->configure (2, 2, $w - 4, $h - 4); 616 $self->child->configure (0, 0, $w, $h);
601} 617}
602 618
603sub _draw { 619sub _draw {
604 my ($self) = @_; 620 my ($self) = @_;
605 621
606 my $chld = $self->child; 622 my ($w, $h) = ($self->{w}, $self->{h});
607 623
608 my ($w, $h) = $chld->size_request; 624 glEnable GL_BLEND;
625 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
626 glEnable GL_TEXTURE_2D;
627 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
609 628
610 glBegin GL_QUADS; 629# glBegin GL_QUADS;
611 glColor 0, 0, 0; 630# glColor 0, 0, 0, 0;
612 glVertex 0 , 0; 631# glVertex 0 , 0;
613 glVertex 0 , $h + 4; 632# glVertex 0 , $h;
614 glVertex $w + 4 , $h + 4; 633# glVertex $w, $h;
615 glVertex $w + 4 , 0; 634# glVertex $w, 0;
616 glEnd; 635# glEnd;
617 636
637
618 $chld->draw; 638 $self->child->draw;
639 glDisable GL_BLEND;
640 glDisable GL_TEXTURE_2D;
619} 641}
620 642
621############################################################################# 643#############################################################################
622 644
623package CFClient::UI::FancyFrame; 645package CFClient::UI::FancyFrame;
625our @ISA = CFClient::UI::Bin::; 647our @ISA = CFClient::UI::Bin::;
626 648
627use CFClient::OpenGL; 649use CFClient::OpenGL;
628 650
629my @tex = 651my @tex =
630 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 652 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
631 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 653 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
632 654
633sub new { 655sub new {
634 my $class = shift; 656 my $class = shift;
635 657
1109 1131
1110sub size_allocate { 1132sub size_allocate {
1111 my ($self, $w, $h) = @_; 1133 my ($self, $w, $h) = @_;
1112 1134
1113 delete $self->{texture}; 1135 delete $self->{texture};
1136}
1137
1138sub set_fontsize {
1139 my ($self, $fontsize) = @_;
1140
1141 $self->{fontsize} = $fontsize;
1142 $self->check_size;
1114} 1143}
1115 1144
1116sub _draw { 1145sub _draw {
1117 my ($self) = @_; 1146 my ($self) = @_;
1118 1147
1344our @ISA = CFClient::UI::Label::; 1373our @ISA = CFClient::UI::Label::;
1345 1374
1346use CFClient::OpenGL; 1375use CFClient::OpenGL;
1347 1376
1348my @tex = 1377my @tex =
1349 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1378 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1350 qw(b1_button_active.png); 1379 qw(b1_button_active.png);
1351 1380
1352sub new { 1381sub new {
1353 my $class = shift; 1382 my $class = shift;
1354 1383
1401package CFClient::UI::CheckBox; 1430package CFClient::UI::CheckBox;
1402 1431
1403our @ISA = CFClient::UI::DrawBG::; 1432our @ISA = CFClient::UI::DrawBG::;
1404 1433
1405my @tex = 1434my @tex =
1406 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1435 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1407 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1436 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1408 1437
1409use CFClient::OpenGL; 1438use CFClient::OpenGL;
1410 1439
1411sub new { 1440sub new {
1460 glDisable GL_BLEND; 1489 glDisable GL_BLEND;
1461} 1490}
1462 1491
1463############################################################################# 1492#############################################################################
1464 1493
1494package CFClient::UI::Image;
1495
1496our @ISA = CFClient::UI::Base::;
1497
1498use CFClient::OpenGL;
1499use Carp qw/confess/;
1500
1501our %loaded_images;
1502
1503sub new {
1504 my $class = shift;
1505
1506 my $self = $class->SUPER::new (@_);
1507
1508 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1509
1510 $loaded_images{$self->{image}} ||=
1511 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1512
1513 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1514
1515 Scalar::Util::weaken $loaded_images{$self->{image}};
1516
1517 $self->{aspect} = $tex->{w} / $tex->{h};
1518
1519 $self
1520}
1521
1522sub size_request {
1523 my ($self) = @_;
1524
1525 ($self->{tex}->{w}, $self->{tex}->{h})
1526}
1527
1528sub _draw {
1529 my ($self) = @_;
1530
1531 my $tex = $self->{tex};
1532
1533 my ($w, $h) = ($self->{w}, $self->{h});
1534
1535 if ($self->{rot90}) {
1536 glRotate 90, 0, 0, 1;
1537 glTranslate 0, -$self->{w}, 0;
1538
1539 ($w, $h) = ($h, $w);
1540 }
1541
1542 glEnable GL_BLEND;
1543 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1544 glEnable GL_TEXTURE_2D;
1545 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1546
1547 $tex->draw_quad (0, 0, $w, $h);
1548
1549 glDisable GL_BLEND;
1550 glDisable GL_TEXTURE_2D;
1551}
1552
1553#############################################################################
1554
1465package CFClient::UI::VGauge; 1555package CFClient::UI::VGauge;
1466 1556
1467our @ISA = CFClient::UI::Base::; 1557our @ISA = CFClient::UI::Base::;
1468 1558
1469use CFClient::OpenGL; 1559use CFClient::OpenGL;
1470 1560
1471my %tex = ( 1561my %tex = (
1472 food => [ 1562 food => [
1473 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1563 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1474 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1564 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1475 ], 1565 ],
1476 grace => [ 1566 grace => [
1477 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1567 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1478 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ 1568 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1479 ], 1569 ],
1480 hp => [ 1570 hp => [
1481 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1571 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1482 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1572 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1483 ], 1573 ],
1484 mana => [ 1574 mana => [
1485 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1575 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1486 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ 1576 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1487 ], 1577 ],
1488); 1578);
1489 1579
1490# eg. VGauge->new (gauge => 'food'), default gauge: food 1580# eg. VGauge->new (gauge => 'food'), default gauge: food
1591 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1681 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1592 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); 1682 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1);
1593 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1683 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1594 1684
1595 $self 1685 $self
1686}
1687
1688sub set_fontsize {
1689 my ($self, $fsize) = @_;
1690
1691 $self->{value}->set_fontsize ($fsize);
1692 $self->{max} ->set_fontsize ($fsize);
1596} 1693}
1597 1694
1598sub set_value { 1695sub set_value {
1599 my ($self, $val, $max) = @_; 1696 my ($self, $val, $max) = @_;
1600 1697
2027} 2124}
2028 2125
2029sub add { 2126sub add {
2030 my ($self, $child) = @_; 2127 my ($self, $child) = @_;
2031 2128
2129 # integerize window positions
2130 $child->{x} = int $child->{x};
2131 $child->{y} = int $child->{y};
2132
2032 $self->SUPER::add ($child); 2133 $self->SUPER::add ($child);
2033} 2134}
2034 2135
2035sub on_refresh { 2136sub on_refresh {
2036 my ($self, $id, $cb) = @_; 2137 my ($self, $id, $cb) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines