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.147 by root, Sat Apr 22 03:50:25 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) {
625our @ISA = CFClient::UI::Bin::; 625our @ISA = CFClient::UI::Bin::;
626 626
627use CFClient::OpenGL; 627use CFClient::OpenGL;
628 628
629my @tex = 629my @tex =
630 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 630 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); 631 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
632 632
633sub new { 633sub new {
634 my $class = shift; 634 my $class = shift;
635 635
1109 1109
1110sub size_allocate { 1110sub size_allocate {
1111 my ($self, $w, $h) = @_; 1111 my ($self, $w, $h) = @_;
1112 1112
1113 delete $self->{texture}; 1113 delete $self->{texture};
1114}
1115
1116sub set_fontsize {
1117 my ($self, $fontsize) = @_;
1118
1119 $self->{fontsize} = $fontsize;
1120 $self->check_size;
1114} 1121}
1115 1122
1116sub _draw { 1123sub _draw {
1117 my ($self) = @_; 1124 my ($self) = @_;
1118 1125
1344our @ISA = CFClient::UI::Label::; 1351our @ISA = CFClient::UI::Label::;
1345 1352
1346use CFClient::OpenGL; 1353use CFClient::OpenGL;
1347 1354
1348my @tex = 1355my @tex =
1349 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1356 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1350 qw(b1_button_active.png); 1357 qw(b1_button_active.png);
1351 1358
1352sub new { 1359sub new {
1353 my $class = shift; 1360 my $class = shift;
1354 1361
1401package CFClient::UI::CheckBox; 1408package CFClient::UI::CheckBox;
1402 1409
1403our @ISA = CFClient::UI::DrawBG::; 1410our @ISA = CFClient::UI::DrawBG::;
1404 1411
1405my @tex = 1412my @tex =
1406 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1413 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1407 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1414 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1408 1415
1409use CFClient::OpenGL; 1416use CFClient::OpenGL;
1410 1417
1411sub new { 1418sub new {
1460 glDisable GL_BLEND; 1467 glDisable GL_BLEND;
1461} 1468}
1462 1469
1463############################################################################# 1470#############################################################################
1464 1471
1472package CFClient::UI::Image;
1473
1474our @ISA = CFClient::UI::Base::;
1475
1476use CFClient::OpenGL;
1477use Carp qw/confess/;
1478
1479our %loaded_images;
1480
1481sub new {
1482 my $class = shift;
1483
1484 my $self = $class->SUPER::new (@_);
1485
1486 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1487
1488 $loaded_images{$self->{image}} ||=
1489 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1490
1491 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1492
1493 Scalar::Util::weaken $loaded_images{$self->{image}};
1494
1495 $self->{aspect} = $tex->{w} / $tex->{h};
1496
1497 $self
1498}
1499
1500sub size_request {
1501 my ($self) = @_;
1502
1503 ($self->{tex}->{w}, $self->{tex}->{h})
1504}
1505
1506sub _draw {
1507 my ($self) = @_;
1508
1509 my $tex = $self->{tex};
1510
1511 my ($w, $h) = ($self->{w}, $self->{h});
1512
1513 if ($self->{rot90}) {
1514 glRotate 90, 0, 0, 1;
1515 glTranslate 0, -$self->{w}, 0;
1516
1517 ($w, $h) = ($h, $w);
1518 }
1519
1520 glEnable GL_BLEND;
1521 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1522 glEnable GL_TEXTURE_2D;
1523 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1524
1525 $tex->draw_quad (0, 0, $w, $h);
1526
1527 glDisable GL_BLEND;
1528 glDisable GL_TEXTURE_2D;
1529}
1530
1531#############################################################################
1532
1465package CFClient::UI::VGauge; 1533package CFClient::UI::VGauge;
1466 1534
1467our @ISA = CFClient::UI::Base::; 1535our @ISA = CFClient::UI::Base::;
1468 1536
1469use CFClient::OpenGL; 1537use CFClient::OpenGL;
1470 1538
1471my %tex = ( 1539my %tex = (
1472 food => [ 1540 food => [
1473 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1541 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1474 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1542 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1475 ], 1543 ],
1476 grace => [ 1544 grace => [
1477 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1545 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1478 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ 1546 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1479 ], 1547 ],
1480 hp => [ 1548 hp => [
1481 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1549 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1482 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1550 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1483 ], 1551 ],
1484 mana => [ 1552 mana => [
1485 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1553 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1486 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ 1554 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1487 ], 1555 ],
1488); 1556);
1489 1557
1490# eg. VGauge->new (gauge => 'food'), default gauge: food 1558# eg. VGauge->new (gauge => 'food'), default gauge: food
1591 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1659 $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); 1660 $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"); 1661 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1594 1662
1595 $self 1663 $self
1664}
1665
1666sub set_fontsize {
1667 my ($self, $fsize) = @_;
1668
1669 $self->{value}->set_fontsize ($fsize);
1670 $self->{max} ->set_fontsize ($fsize);
1596} 1671}
1597 1672
1598sub set_value { 1673sub set_value {
1599 my ($self, $val, $max) = @_; 1674 my ($self, $val, $max) = @_;
1600 1675
2027} 2102}
2028 2103
2029sub add { 2104sub add {
2030 my ($self, $child) = @_; 2105 my ($self, $child) = @_;
2031 2106
2107 # integerize window positions
2108 $child->{x} = int $child->{x};
2109 $child->{y} = int $child->{y};
2110
2032 $self->SUPER::add ($child); 2111 $self->SUPER::add ($child);
2033} 2112}
2034 2113
2035sub on_refresh { 2114sub on_refresh {
2036 my ($self, $id, $cb) = @_; 2115 my ($self, $id, $cb) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines