… | |
… | |
140 | 0 |
140 | 0 |
141 | } |
141 | } |
142 | |
142 | |
143 | sub size_request { |
143 | sub 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 | |
148 | sub configure { |
148 | sub 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) { |
… | |
… | |
625 | our @ISA = CFClient::UI::Bin::; |
625 | our @ISA = CFClient::UI::Bin::; |
626 | |
626 | |
627 | use CFClient::OpenGL; |
627 | use CFClient::OpenGL; |
628 | |
628 | |
629 | my @tex = |
629 | my @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 | |
633 | sub new { |
633 | sub new { |
634 | my $class = shift; |
634 | my $class = shift; |
635 | |
635 | |
… | |
… | |
1109 | |
1109 | |
1110 | sub size_allocate { |
1110 | sub size_allocate { |
1111 | my ($self, $w, $h) = @_; |
1111 | my ($self, $w, $h) = @_; |
1112 | |
1112 | |
1113 | delete $self->{texture}; |
1113 | delete $self->{texture}; |
|
|
1114 | } |
|
|
1115 | |
|
|
1116 | sub set_fontsize { |
|
|
1117 | my ($self, $fontsize) = @_; |
|
|
1118 | |
|
|
1119 | $self->{fontsize} = $fontsize; |
|
|
1120 | $self->check_size; |
1114 | } |
1121 | } |
1115 | |
1122 | |
1116 | sub _draw { |
1123 | sub _draw { |
1117 | my ($self) = @_; |
1124 | my ($self) = @_; |
1118 | |
1125 | |
… | |
… | |
1344 | our @ISA = CFClient::UI::Label::; |
1351 | our @ISA = CFClient::UI::Label::; |
1345 | |
1352 | |
1346 | use CFClient::OpenGL; |
1353 | use CFClient::OpenGL; |
1347 | |
1354 | |
1348 | my @tex = |
1355 | my @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 | |
1352 | sub new { |
1359 | sub new { |
1353 | my $class = shift; |
1360 | my $class = shift; |
1354 | |
1361 | |
… | |
… | |
1401 | package CFClient::UI::CheckBox; |
1408 | package CFClient::UI::CheckBox; |
1402 | |
1409 | |
1403 | our @ISA = CFClient::UI::DrawBG::; |
1410 | our @ISA = CFClient::UI::DrawBG::; |
1404 | |
1411 | |
1405 | my @tex = |
1412 | my @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 | |
1409 | use CFClient::OpenGL; |
1416 | use CFClient::OpenGL; |
1410 | |
1417 | |
1411 | sub new { |
1418 | sub new { |
… | |
… | |
1460 | glDisable GL_BLEND; |
1467 | glDisable GL_BLEND; |
1461 | } |
1468 | } |
1462 | |
1469 | |
1463 | ############################################################################# |
1470 | ############################################################################# |
1464 | |
1471 | |
|
|
1472 | package CFClient::UI::Image; |
|
|
1473 | |
|
|
1474 | our @ISA = CFClient::UI::Base::; |
|
|
1475 | |
|
|
1476 | use CFClient::OpenGL; |
|
|
1477 | use Carp qw/confess/; |
|
|
1478 | |
|
|
1479 | our %loaded_images; |
|
|
1480 | |
|
|
1481 | sub 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 | |
|
|
1500 | sub size_request { |
|
|
1501 | my ($self) = @_; |
|
|
1502 | |
|
|
1503 | ($self->{tex}->{w}, $self->{tex}->{h}) |
|
|
1504 | } |
|
|
1505 | |
|
|
1506 | sub _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 | |
1465 | package CFClient::UI::VGauge; |
1533 | package CFClient::UI::VGauge; |
1466 | |
1534 | |
1467 | our @ISA = CFClient::UI::Base::; |
1535 | our @ISA = CFClient::UI::Base::; |
1468 | |
1536 | |
1469 | use CFClient::OpenGL; |
1537 | use CFClient::OpenGL; |
1470 | |
1538 | |
1471 | my %tex = ( |
1539 | my %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 |
… | |
… | |
1502 | } |
1570 | } |
1503 | |
1571 | |
1504 | sub size_request { |
1572 | sub size_request { |
1505 | my ($self) = @_; |
1573 | my ($self) = @_; |
1506 | |
1574 | |
1507 | my $tex = $tex{$self->{type}}[0]; |
1575 | #my $tex = $tex{$self->{type}}[0]; |
1508 | |
|
|
1509 | @$tex{qw(w h)} |
1576 | #@$tex{qw(w h)} |
|
|
1577 | (0, 0) |
1510 | } |
1578 | } |
1511 | |
1579 | |
1512 | sub set_max { |
1580 | sub set_max { |
1513 | my ($self, $max) = @_; |
1581 | my ($self, $max) = @_; |
1514 | |
1582 | |
… | |
… | |
1531 | my ($self) = @_; |
1599 | my ($self) = @_; |
1532 | |
1600 | |
1533 | my $tex = $tex{$self->{type}}; |
1601 | my $tex = $tex{$self->{type}}; |
1534 | |
1602 | |
1535 | my ($w, $h) = ($self->{w}, $self->{h}); |
1603 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1604 | |
|
|
1605 | if ($self->{vertical}) { |
|
|
1606 | glRotate 90, 0, 0, 1; |
|
|
1607 | glTranslate 0, -$self->{w}, 0; |
|
|
1608 | |
|
|
1609 | ($w, $h) = ($h, $w); |
|
|
1610 | } |
1536 | |
1611 | |
1537 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1612 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1538 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1613 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1539 | |
1614 | |
1540 | my $t1 = $tex->[0]; |
1615 | my $t1 = $tex->[0]; |
… | |
… | |
1584 | $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"); |
1585 | $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); |
1586 | $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"); |
1587 | |
1662 | |
1588 | $self |
1663 | $self |
|
|
1664 | } |
|
|
1665 | |
|
|
1666 | sub set_fontsize { |
|
|
1667 | my ($self, $fsize) = @_; |
|
|
1668 | |
|
|
1669 | $self->{value}->set_fontsize ($fsize); |
|
|
1670 | $self->{max} ->set_fontsize ($fsize); |
1589 | } |
1671 | } |
1590 | |
1672 | |
1591 | sub set_value { |
1673 | sub set_value { |
1592 | my ($self, $val, $max) = @_; |
1674 | my ($self, $val, $max) = @_; |
1593 | |
1675 | |
… | |
… | |
2020 | } |
2102 | } |
2021 | |
2103 | |
2022 | sub add { |
2104 | sub add { |
2023 | my ($self, $child) = @_; |
2105 | my ($self, $child) = @_; |
2024 | |
2106 | |
|
|
2107 | # integerize window positions |
|
|
2108 | $child->{x} = int $child->{x}; |
|
|
2109 | $child->{y} = int $child->{y}; |
|
|
2110 | |
2025 | $self->SUPER::add ($child); |
2111 | $self->SUPER::add ($child); |
2026 | } |
2112 | } |
2027 | |
2113 | |
2028 | sub on_refresh { |
2114 | sub on_refresh { |
2029 | my ($self, $id, $cb) = @_; |
2115 | my ($self, $id, $cb) = @_; |