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 | |
|
|
7 | use AnyEvent (); |
8 | use Guard (); |
8 | use Guard (); |
9 | |
9 | |
10 | use DC; |
10 | use DC; |
11 | use DC::Pod; |
11 | use DC::Pod; |
12 | use DC::Texture; |
12 | use DC::Texture; |
… | |
… | |
223 | |
223 | |
224 | ############################################################################# |
224 | ############################################################################# |
225 | |
225 | |
226 | package DC::UI::Base; |
226 | package DC::UI::Base; |
227 | |
227 | |
228 | use strict; |
228 | use common::sense; |
229 | |
229 | |
230 | use DC::OpenGL; |
230 | use DC::OpenGL; |
231 | |
231 | |
232 | sub new { |
232 | sub new { |
233 | my $class = shift; |
233 | my $class = shift; |
… | |
… | |
643 | |
643 | |
644 | package DC::UI::DrawBG; |
644 | package DC::UI::DrawBG; |
645 | |
645 | |
646 | our @ISA = DC::UI::Base::; |
646 | our @ISA = DC::UI::Base::; |
647 | |
647 | |
648 | use strict; |
648 | use common::sense; |
|
|
649 | |
649 | use DC::OpenGL; |
650 | use DC::OpenGL; |
650 | |
651 | |
651 | sub new { |
652 | sub new { |
652 | my $class = shift; |
653 | my $class = shift; |
653 | |
654 | |
… | |
… | |
666 | } |
667 | } |
667 | |
668 | |
668 | sub _draw { |
669 | sub _draw { |
669 | my ($self) = @_; |
670 | my ($self) = @_; |
670 | |
671 | |
671 | my $color = $FOCUS == $self && $self->{active_bg} |
672 | my $color = $FOCUS == $self |
672 | ? $self->{active_bg} |
673 | ? $self->{active_bg} || $self->{bg} |
673 | : $self->{bg}; |
674 | : $self->{bg}; |
674 | |
675 | |
675 | if ($color && (@$color < 4 || $color->[3])) { |
676 | if ($color && (@$color < 4 || $color->[3])) { |
676 | my ($w, $h) = @$self{qw(w h)}; |
677 | my ($w, $h) = @$self{qw(w h)}; |
677 | |
678 | |
… | |
… | |
2594 | |
2595 | |
2595 | ############################################################################# |
2596 | ############################################################################# |
2596 | |
2597 | |
2597 | package DC::UI::Image; |
2598 | package DC::UI::Image; |
2598 | |
2599 | |
2599 | our @ISA = DC::UI::Base::; |
2600 | our @ISA = DC::UI::DrawBG::; |
2600 | |
2601 | |
2601 | use DC::OpenGL; |
2602 | use DC::OpenGL; |
2602 | |
2603 | |
2603 | our %texture_cache; |
2604 | our %texture_cache; |
2604 | |
2605 | |
… | |
… | |
2637 | my ($self, $cloning, $path) = @_; |
2638 | my ($self, $cloning, $path) = @_; |
2638 | |
2639 | |
2639 | $self->new (path => $path) |
2640 | $self->new (path => $path) |
2640 | } |
2641 | } |
2641 | |
2642 | |
|
|
2643 | sub set_texture { |
|
|
2644 | my ($self, $tex) = @_; |
|
|
2645 | |
|
|
2646 | $self->{tex} = $tex; |
|
|
2647 | $self->update; |
|
|
2648 | } |
|
|
2649 | |
2642 | sub size_request { |
2650 | sub size_request { |
2643 | my ($self) = @_; |
2651 | my ($self) = @_; |
2644 | |
2652 | |
2645 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2653 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2646 | } |
2654 | } |
2647 | |
2655 | |
2648 | sub _draw { |
2656 | sub _draw { |
2649 | my ($self) = @_; |
2657 | my ($self) = @_; |
|
|
2658 | |
|
|
2659 | $self->SUPER::_draw; |
2650 | |
2660 | |
2651 | my $tex = $self->{tex}; |
2661 | my $tex = $self->{tex}; |
2652 | |
2662 | |
2653 | my ($w, $h) = ($self->{w}, $self->{h}); |
2663 | my ($w, $h) = ($self->{w}, $self->{h}); |
2654 | |
2664 | |
… | |
… | |
2672 | package DC::UI::ImageButton; |
2682 | package DC::UI::ImageButton; |
2673 | |
2683 | |
2674 | our @ISA = DC::UI::Image::; |
2684 | our @ISA = DC::UI::Image::; |
2675 | |
2685 | |
2676 | use DC::OpenGL; |
2686 | use DC::OpenGL; |
2677 | |
|
|
2678 | my %textures; |
|
|
2679 | |
2687 | |
2680 | sub new { |
2688 | sub new { |
2681 | my $class = shift; |
2689 | my $class = shift; |
2682 | |
2690 | |
2683 | my $self = $class->SUPER::new ( |
2691 | my $self = $class->SUPER::new ( |
… | |
… | |
3047 | |
3055 | |
3048 | ############################################################################# |
3056 | ############################################################################# |
3049 | |
3057 | |
3050 | package DC::UI::Slider; |
3058 | package DC::UI::Slider; |
3051 | |
3059 | |
3052 | use strict; |
3060 | use common::sense; |
3053 | |
3061 | |
3054 | use DC::OpenGL; |
3062 | use DC::OpenGL; |
3055 | |
3063 | |
3056 | our @ISA = DC::UI::DrawBG::; |
3064 | our @ISA = DC::UI::DrawBG::; |
3057 | |
3065 | |
… | |
… | |
3143 | if ($GRAB == $self) { |
3151 | if ($GRAB == $self) { |
3144 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
3152 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
3145 | |
3153 | |
3146 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
3154 | my (undef, $lo, $hi, $page) = @{$self->{range}}; |
3147 | |
3155 | |
3148 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); |
3156 | $x = ($x - $self->{click}[1]) / ($w * $self->{scale} || 1e999); |
3149 | |
3157 | |
3150 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
3158 | $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); |
3151 | } else { |
3159 | } else { |
3152 | return 0; |
3160 | return 0; |
3153 | } |
3161 | } |
… | |
… | |
4285 | $self |
4293 | $self |
4286 | } |
4294 | } |
4287 | |
4295 | |
4288 | sub reorder { |
4296 | sub reorder { |
4289 | my ($self) = @_; |
4297 | my ($self) = @_; |
4290 | my $NOW = EV::time; |
4298 | my $NOW = AE::time; |
4291 | |
4299 | |
4292 | # freeze display when hovering over any label |
4300 | # freeze display when hovering over any label |
4293 | return if $DC::UI::TOOLTIP->{owner} |
4301 | return if $DC::UI::TOOLTIP->{owner} |
4294 | && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, |
4302 | && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, |
4295 | values %{ $self->{item} }; |
4303 | values %{ $self->{item} }; |