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 | } |
… | |
… | |
3279 | indent => 0, |
3287 | indent => 0, |
3280 | #font => default_font |
3288 | #font => default_font |
3281 | @_, |
3289 | @_, |
3282 | |
3290 | |
3283 | layout => (new DC::Layout), |
3291 | layout => (new DC::Layout), |
3284 | par => [], |
|
|
3285 | max_par => 0, |
3292 | max_par => 0, |
3286 | height => 0, |
3293 | height => 0, |
3287 | children => [ |
3294 | children => [ |
3288 | (new DC::UI::Empty expand => 1), |
3295 | (new DC::UI::Empty expand => 1), |
3289 | (new DC::UI::Slider vertical => 1), |
3296 | (new DC::UI::Slider vertical => 1), |
3290 | ], |
3297 | ], |
3291 | ); |
3298 | ); |
3292 | |
3299 | |
3293 | $self->{children}[1]->connect (changed => sub { $self->update }); |
3300 | $self->{children}[1]->connect (changed => sub { $self->update }); |
|
|
3301 | |
|
|
3302 | $self->add_paragraph (@{ delete $self->{par} }) if @{ $self->{par} }; |
3294 | |
3303 | |
3295 | $self |
3304 | $self |
3296 | } |
3305 | } |
3297 | |
3306 | |
3298 | sub set_fontsize { |
3307 | sub set_fontsize { |
… | |
… | |
4285 | $self |
4294 | $self |
4286 | } |
4295 | } |
4287 | |
4296 | |
4288 | sub reorder { |
4297 | sub reorder { |
4289 | my ($self) = @_; |
4298 | my ($self) = @_; |
4290 | my $NOW = EV::time; |
4299 | my $NOW = AE::time; |
4291 | |
4300 | |
4292 | # freeze display when hovering over any label |
4301 | # freeze display when hovering over any label |
4293 | return if $DC::UI::TOOLTIP->{owner} |
4302 | return if $DC::UI::TOOLTIP->{owner} |
4294 | && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, |
4303 | && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, |
4295 | values %{ $self->{item} }; |
4304 | values %{ $self->{item} }; |
… | |
… | |
4394 | $ROOT->on_refresh (reorder => sub { |
4403 | $ROOT->on_refresh (reorder => sub { |
4395 | $self->reorder; |
4404 | $self->reorder; |
4396 | }); |
4405 | }); |
4397 | } |
4406 | } |
4398 | |
4407 | |
|
|
4408 | sub clr_group { |
|
|
4409 | my ($self, $group) = @_; |
|
|
4410 | |
|
|
4411 | if (delete $self->{item}{$group}) { |
|
|
4412 | $ROOT->on_refresh (reorder => sub { |
|
|
4413 | $self->reorder; |
|
|
4414 | }); |
|
|
4415 | } |
|
|
4416 | } |
|
|
4417 | |
4399 | sub reconfigure { |
4418 | sub reconfigure { |
4400 | my ($self) = @_; |
4419 | my ($self) = @_; |
4401 | |
4420 | |
4402 | delete $_->{label} |
4421 | delete $_->{label} |
4403 | for values %{ $self->{item} || {} }; |
4422 | for values %{ $self->{item} || {} }; |