… | |
… | |
9 | use CFClient; |
9 | use CFClient; |
10 | use CFClient::Texture; |
10 | use CFClient::Texture; |
11 | |
11 | |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
13 | |
13 | |
|
|
14 | our $LAYOUT; |
14 | our $ROOT; |
15 | our $ROOT; |
15 | our $TOOLTIP; |
16 | our $TOOLTIP; |
16 | our $BUTTON_STATE; |
17 | our $BUTTON_STATE; |
17 | |
18 | |
18 | our %WIDGET; # all widgets, weak-referenced |
19 | our %WIDGET; # all widgets, weak-referenced |
|
|
20 | |
|
|
21 | sub get_layout { |
|
|
22 | for (grep { $_->{name} } values %WIDGET) { |
|
|
23 | $LAYOUT->{$_->{name}} = { |
|
|
24 | x => $_->{x} / $::WIDTH, |
|
|
25 | y => $_->{y} / $::HEIGHT, |
|
|
26 | w => $_->{w} / $::WIDTH, |
|
|
27 | h => $_->{h} / $::HEIGHT |
|
|
28 | }; |
|
|
29 | } |
|
|
30 | |
|
|
31 | return $LAYOUT; |
|
|
32 | } |
|
|
33 | |
|
|
34 | sub set_layout { |
|
|
35 | my ($layout) = @_; |
|
|
36 | $LAYOUT = $layout; |
|
|
37 | } |
19 | |
38 | |
20 | sub check_tooltip { |
39 | sub check_tooltip { |
21 | if (!$GRAB) { |
40 | if (!$GRAB) { |
22 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
41 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
23 | if (length $widget->{tooltip}) { |
42 | if (length $widget->{tooltip}) { |
… | |
… | |
194 | } |
213 | } |
195 | } |
214 | } |
196 | |
215 | |
197 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
216 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
198 | |
217 | |
|
|
218 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
|
|
219 | $self->{user_x} = $layout->{x} * $::WIDTH; |
|
|
220 | $self->{user_y} = $layout->{y} * $::HEIGHT; |
|
|
221 | $self->{user_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH; |
|
|
222 | $self->{user_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT; |
|
|
223 | } |
|
|
224 | |
199 | $self |
225 | $self |
200 | } |
226 | } |
201 | |
227 | |
202 | sub destroy { |
228 | sub destroy { |
203 | my ($self) = @_; |
229 | my ($self) = @_; |
… | |
… | |
229 | sub set_invisible { |
255 | sub set_invisible { |
230 | my ($self) = @_; |
256 | my ($self) = @_; |
231 | |
257 | |
232 | # broken show/hide model |
258 | # broken show/hide model |
233 | |
259 | |
|
|
260 | delete $self->{root}; |
234 | delete $self->{visible}; |
261 | delete $self->{visible}; |
235 | |
262 | |
236 | undef $GRAB if $GRAB == $self; |
263 | undef $GRAB if $GRAB == $self; |
237 | undef $HOVER if $HOVER == $self; |
264 | undef $HOVER if $HOVER == $self; |
238 | |
265 | |
… | |
… | |
460 | my ($self, $parent) = @_; |
487 | my ($self, $parent) = @_; |
461 | |
488 | |
462 | Scalar::Util::weaken ($self->{parent} = $parent); |
489 | Scalar::Util::weaken ($self->{parent} = $parent); |
463 | |
490 | |
464 | $self->{root} = $parent->{root}; |
491 | $self->{root} = $parent->{root}; |
465 | $self->{visible} = $parent->{visible}; |
492 | $self->{visible} = $parent->{visible} + 1; |
466 | |
493 | |
467 | # TODO: req_w _does_change after ->reconfigure |
494 | # TODO: req_w _does_change after ->reconfigure |
468 | $self->check_size |
495 | $self->check_size |
469 | unless exists $self->{req_w}; |
496 | unless exists $self->{req_w}; |
470 | |
497 | |
… | |
… | |
2964 | |
2991 | |
2965 | sub new { |
2992 | sub new { |
2966 | my $class = shift; |
2993 | my $class = shift; |
2967 | |
2994 | |
2968 | $class->SUPER::new ( |
2995 | $class->SUPER::new ( |
|
|
2996 | visible => 1, |
2969 | @_, |
2997 | @_, |
2970 | ) |
2998 | ) |
2971 | } |
2999 | } |
2972 | |
3000 | |
2973 | sub configure { |
3001 | sub configure { |
… | |
… | |
3031 | sub add { |
3059 | sub add { |
3032 | my ($self, @children) = @_; |
3060 | my ($self, @children) = @_; |
3033 | |
3061 | |
3034 | for (my @widgets = @children; my $w = pop @widgets; ) { |
3062 | for (my @widgets = @children; my $w = pop @widgets; ) { |
3035 | push @widgets, $w->children; |
3063 | push @widgets, $w->children; |
3036 | $w->{root} = $self; |
3064 | $w->{root} = $self; |
3037 | $w->{visible} = 1; |
3065 | $w->{visible} = $self->{visible} + 1; |
3038 | } |
3066 | } |
3039 | |
3067 | |
3040 | for my $child (@children) { |
3068 | for my $child (@children) { |
3041 | $child->{is_toplevel} = 1; |
3069 | $child->{is_toplevel} = 1; |
3042 | |
3070 | |