… | |
… | |
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->update; |
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 | $self->{aspect} = $tex->{w} / $tex->{h}; |
|
|
1494 | |
|
|
1495 | $self |
|
|
1496 | } |
|
|
1497 | |
|
|
1498 | sub size_request { |
|
|
1499 | my ($self) = @_; |
|
|
1500 | |
|
|
1501 | ($self->{tex}->{w}, $self->{tex}->{h}) |
|
|
1502 | } |
|
|
1503 | |
|
|
1504 | sub _draw { |
|
|
1505 | my ($self) = @_; |
|
|
1506 | |
|
|
1507 | my $tex = $self->{tex}; |
|
|
1508 | |
|
|
1509 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1510 | |
|
|
1511 | if ($self->{rot90}) { |
|
|
1512 | glRotate 90, 0, 0, 1; |
|
|
1513 | glTranslate 0, -$self->{w}, 0; |
|
|
1514 | |
|
|
1515 | ($w, $h) = ($h, $w); |
|
|
1516 | } |
|
|
1517 | |
|
|
1518 | glEnable GL_BLEND; |
|
|
1519 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1520 | glEnable GL_TEXTURE_2D; |
|
|
1521 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1522 | |
|
|
1523 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1524 | |
|
|
1525 | glDisable GL_BLEND; |
|
|
1526 | glDisable GL_TEXTURE_2D; |
|
|
1527 | } |
|
|
1528 | |
|
|
1529 | ############################################################################# |
|
|
1530 | |
1465 | package CFClient::UI::VGauge; |
1531 | package CFClient::UI::VGauge; |
1466 | |
1532 | |
1467 | our @ISA = CFClient::UI::Base::; |
1533 | our @ISA = CFClient::UI::Base::; |
1468 | |
1534 | |
1469 | use CFClient::OpenGL; |
1535 | use CFClient::OpenGL; |
1470 | |
1536 | |
1471 | my %tex = ( |
1537 | my %tex = ( |
1472 | food => [ |
1538 | food => [ |
1473 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1539 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1474 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
1540 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
1475 | ], |
1541 | ], |
1476 | grace => [ |
1542 | grace => [ |
1477 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1543 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1478 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
1544 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
1479 | ], |
1545 | ], |
1480 | hp => [ |
1546 | hp => [ |
1481 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1547 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1482 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
1548 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
1483 | ], |
1549 | ], |
1484 | mana => [ |
1550 | mana => [ |
1485 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1551 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1486 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
1552 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
1487 | ], |
1553 | ], |
1488 | ); |
1554 | ); |
1489 | |
1555 | |
1490 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1556 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
… | |
… | |
1502 | } |
1568 | } |
1503 | |
1569 | |
1504 | sub size_request { |
1570 | sub size_request { |
1505 | my ($self) = @_; |
1571 | my ($self) = @_; |
1506 | |
1572 | |
1507 | my $tex = $tex{$self->{type}}[0]; |
1573 | #my $tex = $tex{$self->{type}}[0]; |
1508 | |
|
|
1509 | @$tex{qw(w h)} |
1574 | #@$tex{qw(w h)} |
|
|
1575 | (0, 0) |
1510 | } |
1576 | } |
1511 | |
1577 | |
1512 | sub set_max { |
1578 | sub set_max { |
1513 | my ($self, $max) = @_; |
1579 | my ($self, $max) = @_; |
1514 | |
1580 | |
… | |
… | |
1531 | my ($self) = @_; |
1597 | my ($self) = @_; |
1532 | |
1598 | |
1533 | my $tex = $tex{$self->{type}}; |
1599 | my $tex = $tex{$self->{type}}; |
1534 | |
1600 | |
1535 | my ($w, $h) = ($self->{w}, $self->{h}); |
1601 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1602 | |
|
|
1603 | if ($self->{vertical}) { |
|
|
1604 | glRotate 90, 0, 0, 1; |
|
|
1605 | glTranslate 0, -$self->{w}, 0; |
|
|
1606 | |
|
|
1607 | ($w, $h) = ($h, $w); |
|
|
1608 | } |
1536 | |
1609 | |
1537 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1610 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1538 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1611 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1539 | |
1612 | |
1540 | my $t1 = $tex->[0]; |
1613 | my $t1 = $tex->[0]; |
… | |
… | |
1584 | $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
1657 | $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); |
1658 | $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"); |
1659 | $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
1587 | |
1660 | |
1588 | $self |
1661 | $self |
|
|
1662 | } |
|
|
1663 | |
|
|
1664 | sub set_fontsize { |
|
|
1665 | my ($self, $fsize) = @_; |
|
|
1666 | |
|
|
1667 | $self->{value}->set_fontsize ($fsize); |
|
|
1668 | $self->{max} ->set_fontsize ($fsize); |
|
|
1669 | $self->update; |
1589 | } |
1670 | } |
1590 | |
1671 | |
1591 | sub set_value { |
1672 | sub set_value { |
1592 | my ($self, $val, $max) = @_; |
1673 | my ($self, $val, $max) = @_; |
1593 | |
1674 | |
… | |
… | |
2020 | } |
2101 | } |
2021 | |
2102 | |
2022 | sub add { |
2103 | sub add { |
2023 | my ($self, $child) = @_; |
2104 | my ($self, $child) = @_; |
2024 | |
2105 | |
|
|
2106 | # integerize window positions |
|
|
2107 | $child->{x} = int $child->{x}; |
|
|
2108 | $child->{y} = int $child->{y}; |
|
|
2109 | |
2025 | $self->SUPER::add ($child); |
2110 | $self->SUPER::add ($child); |
2026 | } |
2111 | } |
2027 | |
2112 | |
2028 | sub on_refresh { |
2113 | sub on_refresh { |
2029 | my ($self, $id, $cb) = @_; |
2114 | my ($self, $id, $cb) = @_; |