… | |
… | |
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 | |
… | |
… | |
1456 | |
1463 | |
1457 | $tex->draw_quad (0, 0, $s, $s); |
1464 | $tex->draw_quad (0, 0, $s, $s); |
1458 | |
1465 | |
1459 | glDisable GL_TEXTURE_2D; |
1466 | glDisable GL_TEXTURE_2D; |
1460 | glDisable GL_BLEND; |
1467 | glDisable GL_BLEND; |
|
|
1468 | } |
|
|
1469 | |
|
|
1470 | ############################################################################# |
|
|
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; |
1461 | } |
1527 | } |
1462 | |
1528 | |
1463 | ############################################################################# |
1529 | ############################################################################# |
1464 | |
1530 | |
1465 | package CFClient::UI::VGauge; |
1531 | package CFClient::UI::VGauge; |
… | |
… | |
1593 | $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"); |
1594 | |
1660 | |
1595 | $self |
1661 | $self |
1596 | } |
1662 | } |
1597 | |
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; |
|
|
1670 | } |
|
|
1671 | |
1598 | sub set_value { |
1672 | sub set_value { |
1599 | my ($self, $val, $max) = @_; |
1673 | my ($self, $val, $max) = @_; |
1600 | |
1674 | |
1601 | $self->set_max ($max) |
1675 | $self->set_max ($max) |
1602 | if defined $max; |
1676 | if defined $max; |
… | |
… | |
2027 | } |
2101 | } |
2028 | |
2102 | |
2029 | sub add { |
2103 | sub add { |
2030 | my ($self, $child) = @_; |
2104 | my ($self, $child) = @_; |
2031 | |
2105 | |
|
|
2106 | # integerize window positions |
|
|
2107 | $child->{x} = int $child->{x}; |
|
|
2108 | $child->{y} = int $child->{y}; |
|
|
2109 | |
2032 | $self->SUPER::add ($child); |
2110 | $self->SUPER::add ($child); |
2033 | } |
2111 | } |
2034 | |
2112 | |
2035 | sub on_refresh { |
2113 | sub on_refresh { |
2036 | my ($self, $id, $cb) = @_; |
2114 | my ($self, $id, $cb) = @_; |