1 | package DC::UI; |
1 | package DC::UI; |
2 | |
2 | |
3 | use utf8; |
3 | use common::sense; |
4 | use strict; |
|
|
5 | |
4 | |
6 | use List::Util (); |
5 | use List::Util (); |
7 | |
6 | |
8 | use Guard (); |
7 | use Guard (); |
9 | |
8 | |
… | |
… | |
666 | } |
665 | } |
667 | |
666 | |
668 | sub _draw { |
667 | sub _draw { |
669 | my ($self) = @_; |
668 | my ($self) = @_; |
670 | |
669 | |
671 | my $color = $FOCUS == $self && $self->{active_bg} |
670 | my $color = $FOCUS == $self |
672 | ? $self->{active_bg} |
671 | ? $self->{active_bg} || $self->{bg} |
673 | : $self->{bg}; |
672 | : $self->{bg}; |
674 | |
673 | |
675 | if ($color && (@$color < 4 || $color->[3])) { |
674 | if ($color && (@$color < 4 || $color->[3])) { |
676 | my ($w, $h) = @$self{qw(w h)}; |
675 | my ($w, $h) = @$self{qw(w h)}; |
677 | |
676 | |
… | |
… | |
2594 | |
2593 | |
2595 | ############################################################################# |
2594 | ############################################################################# |
2596 | |
2595 | |
2597 | package DC::UI::Image; |
2596 | package DC::UI::Image; |
2598 | |
2597 | |
2599 | our @ISA = DC::UI::Base::; |
2598 | our @ISA = DC::UI::DrawBG::; |
2600 | |
2599 | |
2601 | use DC::OpenGL; |
2600 | use DC::OpenGL; |
2602 | |
2601 | |
2603 | our %texture_cache; |
2602 | our %texture_cache; |
2604 | |
2603 | |
… | |
… | |
2637 | my ($self, $cloning, $path) = @_; |
2636 | my ($self, $cloning, $path) = @_; |
2638 | |
2637 | |
2639 | $self->new (path => $path) |
2638 | $self->new (path => $path) |
2640 | } |
2639 | } |
2641 | |
2640 | |
|
|
2641 | sub set_texture { |
|
|
2642 | my ($self, $tex) = @_; |
|
|
2643 | |
|
|
2644 | $self->{tex} = $tex; |
|
|
2645 | $self->update; |
|
|
2646 | } |
|
|
2647 | |
2642 | sub size_request { |
2648 | sub size_request { |
2643 | my ($self) = @_; |
2649 | my ($self) = @_; |
2644 | |
2650 | |
2645 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2651 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2646 | } |
2652 | } |
2647 | |
2653 | |
2648 | sub _draw { |
2654 | sub _draw { |
2649 | my ($self) = @_; |
2655 | my ($self) = @_; |
|
|
2656 | |
|
|
2657 | $self->SUPER::_draw; |
2650 | |
2658 | |
2651 | my $tex = $self->{tex}; |
2659 | my $tex = $self->{tex}; |
2652 | |
2660 | |
2653 | my ($w, $h) = ($self->{w}, $self->{h}); |
2661 | my ($w, $h) = ($self->{w}, $self->{h}); |
2654 | |
2662 | |
… | |
… | |
2672 | package DC::UI::ImageButton; |
2680 | package DC::UI::ImageButton; |
2673 | |
2681 | |
2674 | our @ISA = DC::UI::Image::; |
2682 | our @ISA = DC::UI::Image::; |
2675 | |
2683 | |
2676 | use DC::OpenGL; |
2684 | use DC::OpenGL; |
2677 | |
|
|
2678 | my %textures; |
|
|
2679 | |
2685 | |
2680 | sub new { |
2686 | sub new { |
2681 | my $class = shift; |
2687 | my $class = shift; |
2682 | |
2688 | |
2683 | my $self = $class->SUPER::new ( |
2689 | my $self = $class->SUPER::new ( |