… | |
… | |
40 | if (!$GRAB) { |
40 | if (!$GRAB) { |
41 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
41 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
42 | if (length $widget->{tooltip}) { |
42 | if (length $widget->{tooltip}) { |
43 | |
43 | |
44 | if ($TOOLTIP->{owner} != $widget) { |
44 | if ($TOOLTIP->{owner} != $widget) { |
|
|
45 | $TOOLTIP->hide; |
|
|
46 | |
45 | $TOOLTIP->{owner} = $widget; |
47 | $TOOLTIP->{owner} = $widget; |
46 | |
48 | |
47 | my $tip = $widget->{tooltip}; |
49 | my $tip = $widget->{tooltip}; |
48 | |
50 | |
49 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
51 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
50 | |
52 | |
51 | $TOOLTIP->set_tooltip_from ($widget); |
53 | $TOOLTIP->set_tooltip_from ($widget); |
52 | $TOOLTIP->show; |
54 | $TOOLTIP->show; |
53 | |
|
|
54 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
|
|
55 | |
|
|
56 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) |
|
|
57 | if $x + $TOOLTIP->{w} > $::WIDTH; |
|
|
58 | |
|
|
59 | $TOOLTIP->move ($x, $y); |
|
|
60 | $TOOLTIP->check_size; |
|
|
61 | $TOOLTIP->update; |
|
|
62 | } |
55 | } |
63 | |
56 | |
64 | return; |
57 | return; |
65 | } |
58 | } |
66 | } |
59 | } |
… | |
… | |
175 | for my $widget (values %WIDGET) { |
168 | for my $widget (values %WIDGET) { |
176 | if ($widget->{is_toplevel}) { |
169 | if ($widget->{is_toplevel}) { |
177 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
170 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
178 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
171 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
179 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
172 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
180 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
|
|
181 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
173 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
182 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
174 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
183 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
175 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
184 | $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; |
|
|
185 | } |
176 | } |
186 | } |
177 | } |
187 | |
178 | |
188 | reconfigure_widgets; |
179 | reconfigure_widgets; |
189 | } |
180 | } |
… | |
… | |
214 | } |
205 | } |
215 | |
206 | |
216 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
207 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
217 | |
208 | |
218 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
209 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
219 | $self->{user_x} = $layout->{x} * $::WIDTH; |
210 | $self->{req_x} = $layout->{x} * $::WIDTH; |
220 | $self->{user_y} = $layout->{y} * $::HEIGHT; |
211 | $self->{req_y} = $layout->{y} * $::HEIGHT; |
221 | $self->{user_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH; |
212 | $self->{def_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH; |
222 | $self->{user_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT; |
213 | $self->{def_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT; |
223 | } |
214 | } |
224 | |
215 | |
225 | $self |
216 | $self |
226 | } |
217 | } |
227 | |
218 | |
… | |
… | |
232 | %$self = (); |
223 | %$self = (); |
233 | } |
224 | } |
234 | |
225 | |
235 | sub show { |
226 | sub show { |
236 | my ($self) = @_; |
227 | my ($self) = @_; |
|
|
228 | |
237 | return if $self->{parent}; |
229 | return if $self->{parent}; |
238 | |
230 | |
239 | $CFClient::UI::ROOT->add ($self); |
231 | $CFClient::UI::ROOT->add ($self); |
240 | } |
232 | } |
241 | |
233 | |
242 | sub show_centered { |
234 | sub center { |
243 | my ($self) = @_; |
235 | my ($self) = @_; |
244 | return if $self->{parent}; |
|
|
245 | |
|
|
246 | $self->show; |
|
|
247 | |
236 | |
248 | $CFClient::UI::ROOT->on_post_alloc ( |
237 | $CFClient::UI::ROOT->on_post_alloc ( |
249 | "centered $self" => sub { |
238 | "center_$self" => sub { |
250 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
239 | $self->move (($self->{parent}{w} - $self->{w}) * 0.5, ($self->{parent}{h} - $self->{h}) * 0.5); |
251 | }, |
240 | }, |
252 | ); |
241 | ); |
|
|
242 | |
|
|
243 | $self->update; |
|
|
244 | } |
|
|
245 | |
|
|
246 | sub set_visible { |
|
|
247 | my ($self) = @_; |
|
|
248 | |
|
|
249 | return if $self->{visible}; |
|
|
250 | |
|
|
251 | $self->{root} = $self->{parent}{root}; |
|
|
252 | $self->{visible} = $self->{parent}{visible} + 1; |
|
|
253 | |
|
|
254 | $self->emit (visibility_change => 1); |
|
|
255 | |
|
|
256 | $self->realloc if !exists $self->{req_w}; |
|
|
257 | |
|
|
258 | $_->set_visible for $self->children; |
253 | } |
259 | } |
254 | |
260 | |
255 | sub set_invisible { |
261 | sub set_invisible { |
256 | my ($self) = @_; |
262 | my ($self) = @_; |
257 | |
263 | |
258 | return unless $self->{visible}; |
264 | return unless $self->{visible}; |
259 | |
265 | |
260 | # broken show/hide model |
266 | $_->set_invisible for $self->children; |
261 | |
267 | |
262 | delete $self->{root}; |
268 | delete $self->{root}; |
263 | delete $self->{visible}; |
269 | delete $self->{visible}; |
264 | |
270 | |
265 | undef $GRAB if $GRAB == $self; |
271 | undef $GRAB if $GRAB == $self; |
266 | undef $HOVER if $HOVER == $self; |
272 | undef $HOVER if $HOVER == $self; |
267 | |
273 | |
268 | CFClient::UI::check_tooltip |
274 | CFClient::UI::check_tooltip |
269 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
275 | if $TOOLTIP->{owner} == $self; |
270 | |
276 | |
271 | $self->focus_out; |
277 | $self->focus_out; |
272 | |
278 | |
273 | $self->emit (visibility_change => 0); |
279 | $self->emit (visibility_change => 0); |
|
|
280 | } |
|
|
281 | |
|
|
282 | sub set_visibility { |
|
|
283 | my ($self, $visible) = @_; |
|
|
284 | |
|
|
285 | return if $self->{visible} == $visible; |
|
|
286 | |
|
|
287 | $visible ? $self->hide |
|
|
288 | : $self->show; |
|
|
289 | } |
|
|
290 | |
|
|
291 | sub toggle_visibility { |
|
|
292 | my ($self) = @_; |
|
|
293 | |
|
|
294 | $self->{visible} |
|
|
295 | ? $self->hide |
|
|
296 | : $self->show; |
274 | } |
297 | } |
275 | |
298 | |
276 | sub hide { |
299 | sub hide { |
277 | my ($self) = @_; |
300 | my ($self) = @_; |
278 | |
301 | |
… | |
… | |
293 | } |
316 | } |
294 | |
317 | |
295 | sub set_size { |
318 | sub set_size { |
296 | my ($self, $w, $h) = @_; |
319 | my ($self, $w, $h) = @_; |
297 | |
320 | |
298 | $self->{user_w} = $w; |
321 | $self->{def_w} = $w; |
299 | $self->{user_h} = $h; |
322 | $self->{def_h} = $h; |
300 | |
323 | |
301 | $self->check_size; |
324 | $self->realloc; |
302 | } |
325 | } |
303 | |
326 | |
304 | sub size_request { |
327 | sub size_request { |
305 | require Carp; |
328 | require Carp; |
306 | Carp::confess "size_request is abstract"; |
329 | Carp::confess "size_request is abstract"; |
… | |
… | |
326 | $self->{y} = $y; |
349 | $self->{y} = $y; |
327 | $self->update; |
350 | $self->update; |
328 | } |
351 | } |
329 | |
352 | |
330 | if ($self->{w} != $w || $self->{h} != $h) { |
353 | if ($self->{w} != $w || $self->{h} != $h) { |
|
|
354 | return unless $self->{visible}; |
|
|
355 | |
331 | $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $w, $h]; |
356 | $self->{root}->{size_alloc}{$self+0} = [$self, $w, $h]; |
332 | } |
357 | } |
333 | } |
358 | } |
334 | |
359 | |
335 | sub size_allocate { |
360 | sub size_allocate { |
336 | # nothing to be done |
361 | # nothing to be done |
337 | } |
|
|
338 | |
|
|
339 | sub reconfigure { |
|
|
340 | my ($self) = @_; |
|
|
341 | |
|
|
342 | $self->check_size (1); |
|
|
343 | $self->update; |
|
|
344 | } |
362 | } |
345 | |
363 | |
346 | sub children { |
364 | sub children { |
347 | } |
365 | } |
348 | |
366 | |
… | |
… | |
426 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
444 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
427 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
445 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
428 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
446 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
429 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
447 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
430 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
448 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
|
|
449 | |
|
|
450 | sub find_widget { |
|
|
451 | my ($self, $x, $y) = @_; |
|
|
452 | |
|
|
453 | return () unless $self->{can_events}; |
|
|
454 | |
|
|
455 | return $self |
|
|
456 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
457 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
458 | |
|
|
459 | () |
|
|
460 | } |
|
|
461 | |
|
|
462 | sub set_parent { |
|
|
463 | my ($self, $parent) = @_; |
|
|
464 | |
|
|
465 | Scalar::Util::weaken ($self->{parent} = $parent); |
|
|
466 | |
|
|
467 | $self->set_visible if $parent->{visible}; |
|
|
468 | } |
|
|
469 | |
|
|
470 | sub connect { |
|
|
471 | my ($self, $signal, $cb) = @_; |
|
|
472 | |
|
|
473 | push @{ $self->{signal_cb}{$signal} }, $cb; |
|
|
474 | } |
|
|
475 | |
|
|
476 | sub _emit { |
|
|
477 | my ($self, $signal, @args) = @_; |
|
|
478 | |
|
|
479 | List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} |
|
|
480 | } |
|
|
481 | |
|
|
482 | sub emit { |
|
|
483 | my ($self, $signal, @args) = @_; |
|
|
484 | |
|
|
485 | $self->_emit ($signal, @args) |
|
|
486 | || $self->$signal (@args); |
|
|
487 | } |
|
|
488 | |
|
|
489 | sub visibility_change { |
|
|
490 | #my ($self, $visible) = @_; |
|
|
491 | } |
|
|
492 | |
|
|
493 | sub realloc { |
|
|
494 | my ($self) = @_; |
|
|
495 | |
|
|
496 | if ($self->{visible}) { |
|
|
497 | return if $self->{root}{realloc}{$self}; |
|
|
498 | |
|
|
499 | $self->{root}{realloc}{$self} = $self; |
|
|
500 | $self->{root}->update; |
|
|
501 | } else { |
|
|
502 | delete $self->{req_w}; |
|
|
503 | } |
|
|
504 | } |
|
|
505 | |
|
|
506 | sub update { |
|
|
507 | my ($self) = @_; |
|
|
508 | |
|
|
509 | $self->{parent}->update |
|
|
510 | if $self->{parent}; |
|
|
511 | } |
431 | |
512 | |
432 | sub draw { |
513 | sub draw { |
433 | my ($self) = @_; |
514 | my ($self) = @_; |
434 | |
515 | |
435 | return unless $self->{h} && $self->{w}; |
516 | return unless $self->{h} && $self->{w}; |
… | |
… | |
473 | my ($self) = @_; |
554 | my ($self) = @_; |
474 | |
555 | |
475 | warn "no draw defined for $self\n"; |
556 | warn "no draw defined for $self\n"; |
476 | } |
557 | } |
477 | |
558 | |
478 | sub find_widget { |
|
|
479 | my ($self, $x, $y) = @_; |
|
|
480 | |
|
|
481 | return () unless $self->{can_events}; |
|
|
482 | |
|
|
483 | return $self |
|
|
484 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
485 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
486 | |
|
|
487 | () |
|
|
488 | } |
|
|
489 | |
|
|
490 | sub set_parent { |
|
|
491 | my ($self, $parent) = @_; |
|
|
492 | |
|
|
493 | Scalar::Util::weaken ($self->{parent} = $parent); |
|
|
494 | |
|
|
495 | if ($parent->{visible} || 1) { |
|
|
496 | $self->{root} = $parent->{root}; |
|
|
497 | $self->{visible} = $parent->{visible} + 1; |
|
|
498 | |
|
|
499 | $self->emit (visibility_change => 1) |
|
|
500 | unless $self->{parent}{visible}; |
|
|
501 | } |
|
|
502 | |
|
|
503 | # TODO: req_w _does_change after ->reconfigure |
|
|
504 | $self->check_size |
|
|
505 | unless exists $self->{req_w}; |
|
|
506 | |
|
|
507 | $self->show; |
|
|
508 | } |
|
|
509 | |
|
|
510 | sub check_size { |
|
|
511 | my ($self, $forced) = @_; |
|
|
512 | |
|
|
513 | $self->{force_alloc} = 1 if $forced; |
|
|
514 | $CFClient::UI::ROOT->{check_size}{$self} = $self; |
|
|
515 | } |
|
|
516 | |
|
|
517 | sub update { |
|
|
518 | my ($self) = @_; |
|
|
519 | |
|
|
520 | $self->{parent}->update |
|
|
521 | if $self->{parent}; |
|
|
522 | } |
|
|
523 | |
|
|
524 | sub connect { |
|
|
525 | my ($self, $signal, $cb) = @_; |
|
|
526 | |
|
|
527 | push @{ $self->{signal_cb}{$signal} }, $cb; |
|
|
528 | } |
|
|
529 | |
|
|
530 | sub _emit { |
|
|
531 | my ($self, $signal, @args) = @_; |
|
|
532 | |
|
|
533 | List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} |
|
|
534 | } |
|
|
535 | |
|
|
536 | sub emit { |
|
|
537 | my ($self, $signal, @args) = @_; |
|
|
538 | |
|
|
539 | $self->_emit ($signal, @args) |
|
|
540 | || $self->$signal (@args); |
|
|
541 | } |
|
|
542 | |
|
|
543 | sub visibility_change { |
|
|
544 | #my ($self, $visible) = @_; |
|
|
545 | } |
|
|
546 | |
|
|
547 | sub DESTROY { |
559 | sub DESTROY { |
548 | my ($self) = @_; |
560 | my ($self) = @_; |
549 | |
561 | |
550 | delete $WIDGET{$self+0}; |
562 | delete $WIDGET{$self+0}; |
551 | #$self->deactivate; |
563 | #$self->deactivate; |
… | |
… | |
646 | $self->{children} = [ |
658 | $self->{children} = [ |
647 | sort { $a->{z} <=> $b->{z} } |
659 | sort { $a->{z} <=> $b->{z} } |
648 | @{$self->{children}}, @widgets |
660 | @{$self->{children}}, @widgets |
649 | ]; |
661 | ]; |
650 | |
662 | |
651 | $self->check_size (1); |
663 | $self->realloc; |
652 | $self->update; |
|
|
653 | } |
664 | } |
654 | |
665 | |
655 | sub children { |
666 | sub children { |
656 | @{ $_[0]{children} } |
667 | @{ $_[0]{children} } |
657 | } |
668 | } |
… | |
… | |
662 | delete $child->{parent}; |
673 | delete $child->{parent}; |
663 | $child->hide; |
674 | $child->hide; |
664 | |
675 | |
665 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
676 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
666 | |
677 | |
667 | $self->check_size (1); |
678 | $self->realloc; |
668 | $self->update; |
|
|
669 | } |
679 | } |
670 | |
680 | |
671 | sub clear { |
681 | sub clear { |
672 | my ($self) = @_; |
682 | my ($self) = @_; |
673 | |
683 | |
… | |
… | |
677 | for (@$children) { |
687 | for (@$children) { |
678 | delete $_->{parent}; |
688 | delete $_->{parent}; |
679 | $_->hide; |
689 | $_->hide; |
680 | } |
690 | } |
681 | |
691 | |
682 | $self->check_size; |
692 | $self->realloc; |
683 | $self->update; |
|
|
684 | } |
693 | } |
685 | |
694 | |
686 | sub find_widget { |
695 | sub find_widget { |
687 | my ($self, $x, $y) = @_; |
696 | my ($self, $x, $y) = @_; |
688 | |
697 | |
… | |
… | |
741 | sub size_request { |
750 | sub size_request { |
742 | $_[0]{children}[0]->size_request |
751 | $_[0]{children}[0]->size_request |
743 | } |
752 | } |
744 | |
753 | |
745 | sub size_allocate { |
754 | sub size_allocate { |
746 | my ($self, $w, $h) = @_; |
755 | my ($self, $w, $h, $changed) = @_; |
747 | |
756 | |
748 | $self->{children}[0]->configure (0, 0, $w, $h); |
757 | $self->{children}[0]->configure (0, 0, $w, $h); |
749 | } |
758 | } |
750 | |
759 | |
751 | ############################################################################# |
760 | ############################################################################# |
… | |
… | |
768 | $ROOT->on_post_alloc ($self => sub { $self->render_child }); |
777 | $ROOT->on_post_alloc ($self => sub { $self->render_child }); |
769 | $self->SUPER::update; |
778 | $self->SUPER::update; |
770 | } |
779 | } |
771 | |
780 | |
772 | sub size_allocate { |
781 | sub size_allocate { |
773 | my ($self, $w, $h) = @_; |
782 | my ($self, $w, $h, $changed) = @_; |
774 | |
783 | |
775 | $self->SUPER::size_allocate ($w, $h); |
784 | $self->SUPER::size_allocate ($w, $h, $changed); |
776 | $self->update; |
785 | $self->update |
|
|
786 | if $changed; |
777 | } |
787 | } |
778 | |
788 | |
779 | sub _render { |
789 | sub _render { |
780 | $_[0]{children}[0]->draw; |
790 | $_[0]{children}[0]->draw; |
781 | } |
791 | } |
… | |
… | |
825 | } |
835 | } |
826 | |
836 | |
827 | sub size_request { |
837 | sub size_request { |
828 | my ($self) = @_; |
838 | my ($self) = @_; |
829 | |
839 | |
830 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
840 | my ($w, $h) = @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
831 | |
841 | |
832 | @$self{qw(child_w child_h)} |
842 | $w = 10 if $self->{scroll_x}; |
|
|
843 | $h = 10 if $self->{scroll_y}; |
|
|
844 | |
|
|
845 | ($w, $h) |
833 | } |
846 | } |
834 | |
847 | |
835 | sub size_allocate { |
848 | sub size_allocate { |
836 | my ($self, $w, $h) = @_; |
849 | my ($self, $w, $h, $changed) = @_; |
837 | |
850 | |
838 | $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; |
851 | $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; |
839 | $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; |
852 | $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; |
840 | |
853 | |
841 | $self->child->configure (0, 0, $w, $h); |
854 | $self->child->configure (0, 0, $w, $h); |
… | |
… | |
928 | my $child = $self->{vp}->child; |
941 | my $child = $self->{vp}->child; |
929 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
942 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
930 | } |
943 | } |
931 | |
944 | |
932 | sub size_allocate { |
945 | sub size_allocate { |
933 | my ($self, $w, $h) = @_; |
946 | my ($self, $w, $h, $changed) = @_; |
934 | |
947 | |
935 | $self->SUPER::size_allocate ($w, $h); |
948 | $self->SUPER::size_allocate ($w, $h, $changed); |
936 | |
949 | |
937 | my $child = $self->{vp}->child; |
950 | my $child = $self->{vp}->child; |
938 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
951 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
939 | } |
952 | } |
940 | |
953 | |
… | |
… | |
993 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1006 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
994 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1007 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
995 | |
1008 | |
996 | sub new { |
1009 | sub new { |
997 | my $class = shift; |
1010 | my $class = shift; |
998 | |
|
|
999 | # TODO: user_x, user_y, overwrite moveto? |
|
|
1000 | |
1011 | |
1001 | my $self = $class->SUPER::new ( |
1012 | my $self = $class->SUPER::new ( |
1002 | bg => [1, 1, 1, 1], |
1013 | bg => [1, 1, 1, 1], |
1003 | border_bg => [1, 1, 1, 1], |
1014 | border_bg => [1, 1, 1, 1], |
1004 | border => 0.6, |
1015 | border => 0.6, |
… | |
… | |
1030 | $h + $self->border * 2, |
1041 | $h + $self->border * 2, |
1031 | ) |
1042 | ) |
1032 | } |
1043 | } |
1033 | |
1044 | |
1034 | sub size_allocate { |
1045 | sub size_allocate { |
1035 | my ($self, $w, $h) = @_; |
1046 | my ($self, $w, $h, $changed) = @_; |
|
|
1047 | |
|
|
1048 | return unless $changed; |
1036 | |
1049 | |
1037 | $h -= List::Util::max 0, $self->border * 2; |
1050 | $h -= List::Util::max 0, $self->border * 2; |
1038 | $w -= List::Util::max 0, $self->border * 2; |
1051 | $w -= List::Util::max 0, $self->border * 2; |
1039 | |
1052 | |
1040 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
1053 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
… | |
… | |
1066 | my $dx = $ev->{x} - $ox; |
1079 | my $dx = $ev->{x} - $ox; |
1067 | my $dy = $ev->{y} - $oy; |
1080 | my $dy = $ev->{y} - $oy; |
1068 | |
1081 | |
1069 | $self->{user_x} = $wx + $dx * $mx; |
1082 | $self->{user_x} = $wx + $dx * $mx; |
1070 | $self->{user_y} = $wy + $dy * $my; |
1083 | $self->{user_y} = $wy + $dy * $my; |
1071 | $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); |
1084 | $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); |
1072 | $self->{user_h} = $bh + $dy * ($my ? -1 : 1); |
1085 | $self->{def_h} = $bh + $dy * ($my ? -1 : 1); |
1073 | $self->move ($self->{user_x}, $self->{user_y}); |
1086 | $self->move ($self->{user_x}, $self->{user_y}); |
1074 | $self->check_size; |
1087 | $self->realloc; |
1075 | }; |
1088 | }; |
1076 | |
1089 | |
1077 | } elsif ($lr ^ $td) { |
1090 | } elsif ($lr ^ $td) { |
1078 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1091 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1079 | my ($bx, $by) = ($self->{x}, $self->{y}); |
1092 | my ($bx, $by) = ($self->{x}, $self->{y}); |
… | |
… | |
1083 | |
1096 | |
1084 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1097 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1085 | |
1098 | |
1086 | $self->{user_x} = $bx + $x - $ox; |
1099 | $self->{user_x} = $bx + $x - $ox; |
1087 | $self->{user_y} = $by + $y - $oy; |
1100 | $self->{user_y} = $by + $y - $oy; |
|
|
1101 | |
1088 | $self->move ($self->{user_x}, $self->{user_y}); |
1102 | $self->move ($self->{user_x}, $self->{user_y}); |
1089 | $self->update; |
1103 | $self->realloc; |
1090 | }; |
1104 | }; |
1091 | } |
1105 | } |
1092 | } |
1106 | } |
1093 | |
1107 | |
1094 | sub button_up { |
1108 | sub button_up { |
… | |
… | |
1169 | my ($self, $x, $y, $child) = @_; |
1183 | my ($self, $x, $y, $child) = @_; |
1170 | |
1184 | |
1171 | $child->set_parent ($self); |
1185 | $child->set_parent ($self); |
1172 | $self->{children}[$y][$x] = $child; |
1186 | $self->{children}[$y][$x] = $child; |
1173 | |
1187 | |
1174 | $self->check_size (1); |
1188 | $self->realloc; |
1175 | } |
1189 | } |
1176 | |
1190 | |
1177 | # TODO: move to container class maybe? send children a signal on removal? |
1191 | # TODO: move to container class maybe? send children a signal on removal? |
1178 | sub clear { |
1192 | sub clear { |
1179 | my ($self) = @_; |
1193 | my ($self) = @_; |
… | |
… | |
1184 | for (@children) { |
1198 | for (@children) { |
1185 | delete $_->{parent}; |
1199 | delete $_->{parent}; |
1186 | $_->hide; |
1200 | $_->hide; |
1187 | } |
1201 | } |
1188 | |
1202 | |
1189 | $self->check_size (1); |
1203 | $self->realloc; |
1190 | $self->update; |
|
|
1191 | } |
1204 | } |
1192 | |
1205 | |
1193 | sub get_wh { |
1206 | sub get_wh { |
1194 | my ($self) = @_; |
1207 | my ($self) = @_; |
1195 | |
1208 | |
… | |
… | |
1222 | (sum @$hs), |
1235 | (sum @$hs), |
1223 | ) |
1236 | ) |
1224 | } |
1237 | } |
1225 | |
1238 | |
1226 | sub size_allocate { |
1239 | sub size_allocate { |
1227 | my ($self, $w, $h) = @_; |
1240 | my ($self, $w, $h, $changed) = @_; |
1228 | |
1241 | |
1229 | my ($ws, $hs) = $self->get_wh; |
1242 | my ($ws, $hs) = $self->get_wh; |
1230 | |
1243 | |
1231 | my $req_w = (sum @$ws) || 1; |
1244 | my $req_w = (sum @$ws) || 1; |
1232 | my $req_h = (sum @$hs) || 1; |
1245 | my $req_h = (sum @$hs) || 1; |
… | |
… | |
1291 | } |
1304 | } |
1292 | } |
1305 | } |
1293 | |
1306 | |
1294 | ############################################################################# |
1307 | ############################################################################# |
1295 | |
1308 | |
|
|
1309 | package CFClient::UI::Box; |
|
|
1310 | |
|
|
1311 | our @ISA = CFClient::UI::Container::; |
|
|
1312 | |
|
|
1313 | sub size_request { |
|
|
1314 | my ($self) = @_; |
|
|
1315 | |
|
|
1316 | $self->{vertical} |
|
|
1317 | ? ( |
|
|
1318 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
|
|
1319 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
|
|
1320 | ) |
|
|
1321 | : ( |
|
|
1322 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
|
|
1323 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
|
|
1324 | ) |
|
|
1325 | } |
|
|
1326 | |
|
|
1327 | sub size_allocate { |
|
|
1328 | my ($self, $w, $h, $changed) = @_; |
|
|
1329 | |
|
|
1330 | my $space = $self->{vertical} ? $h : $w; |
|
|
1331 | my $children = $self->{children}; |
|
|
1332 | |
|
|
1333 | my @req; |
|
|
1334 | |
|
|
1335 | if ($self->{homogeneous}) { |
|
|
1336 | @req = ($space / (@$children || 1)) x @$children; |
|
|
1337 | } else { |
|
|
1338 | @req = map $_->{$self->{vertical} ? "req_h" : "req_w"}, @$children; |
|
|
1339 | my $req = List::Util::sum @req; |
|
|
1340 | |
|
|
1341 | if ($req > $space) { |
|
|
1342 | # ah well, not enough space |
|
|
1343 | $_ *= $space / $req for @req; |
|
|
1344 | } else { |
|
|
1345 | my $expand = (List::Util::sum map $_->{expand}, @$children) || 1; |
|
|
1346 | |
|
|
1347 | $space = ($space - $req) / $expand; # remaining space to give away |
|
|
1348 | |
|
|
1349 | $req[$_] += $space * $children->[$_]{expand} |
|
|
1350 | for 0 .. $#$children; |
|
|
1351 | } |
|
|
1352 | } |
|
|
1353 | |
|
|
1354 | CFClient::UI::harmonize \@req; |
|
|
1355 | |
|
|
1356 | my $pos = 0; |
|
|
1357 | for (0 .. $#$children) { |
|
|
1358 | my $alloc = $req[$_]; |
|
|
1359 | $children->[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
|
|
1360 | |
|
|
1361 | $pos += $alloc; |
|
|
1362 | } |
|
|
1363 | |
|
|
1364 | 1 |
|
|
1365 | } |
|
|
1366 | |
|
|
1367 | ############################################################################# |
|
|
1368 | |
1296 | package CFClient::UI::HBox; |
1369 | package CFClient::UI::HBox; |
1297 | |
1370 | |
1298 | # TODO: wrap into common Box base class |
|
|
1299 | |
|
|
1300 | our @ISA = CFClient::UI::Container::; |
1371 | our @ISA = CFClient::UI::Box::; |
1301 | |
1372 | |
1302 | sub size_request { |
1373 | sub new { |
1303 | my ($self) = @_; |
1374 | my $class = shift; |
1304 | |
1375 | |
1305 | my @alloc = map [$_->size_request], @{$self->{children}}; |
1376 | $class->SUPER::new ( |
1306 | |
1377 | vertical => 0, |
1307 | ( |
1378 | @_, |
1308 | (List::Util::sum map $_->[0], @alloc), |
|
|
1309 | (List::Util::max map $_->[1], @alloc), |
|
|
1310 | ) |
1379 | ) |
1311 | } |
1380 | } |
1312 | |
1381 | |
1313 | sub size_allocate { |
|
|
1314 | my ($self, $w, $h) = @_; |
|
|
1315 | |
|
|
1316 | ($h, $w) = ($w, $h); |
|
|
1317 | |
|
|
1318 | my $children = $self->{children}; |
|
|
1319 | |
|
|
1320 | my @h = map $_->{req_w}, @$children; |
|
|
1321 | |
|
|
1322 | my $req_h = List::Util::sum @h; |
|
|
1323 | |
|
|
1324 | if ($req_h > $h) { |
|
|
1325 | # ah well, not enough space |
|
|
1326 | $_ *= $h / $req_h for @h; |
|
|
1327 | } else { |
|
|
1328 | my $exp = List::Util::sum map $_->{expand}, @$children; |
|
|
1329 | $exp ||= 1; |
|
|
1330 | |
|
|
1331 | for (0 .. $#$children) { |
|
|
1332 | my $child = $children->[$_]; |
|
|
1333 | |
|
|
1334 | my $alloc_h = $h[$_]; |
|
|
1335 | $alloc_h += ($h - $req_h) * $child->{expand} / $exp; |
|
|
1336 | $h[$_] = $alloc_h; |
|
|
1337 | } |
|
|
1338 | } |
|
|
1339 | |
|
|
1340 | CFClient::UI::harmonize \@h; |
|
|
1341 | |
|
|
1342 | my $y = 0; |
|
|
1343 | for (0 .. $#$children) { |
|
|
1344 | my $child = $children->[$_]; |
|
|
1345 | my $h = $h[$_]; |
|
|
1346 | $child->configure ($y, 0, $h, $w); |
|
|
1347 | |
|
|
1348 | $y += $h; |
|
|
1349 | } |
|
|
1350 | |
|
|
1351 | 1 |
|
|
1352 | } |
|
|
1353 | |
|
|
1354 | ############################################################################# |
1382 | ############################################################################# |
1355 | |
1383 | |
1356 | package CFClient::UI::VBox; |
1384 | package CFClient::UI::VBox; |
1357 | |
1385 | |
1358 | # TODO: wrap into common Box base class |
|
|
1359 | |
|
|
1360 | our @ISA = CFClient::UI::Container::; |
1386 | our @ISA = CFClient::UI::Box::; |
1361 | |
1387 | |
1362 | sub size_request { |
1388 | sub new { |
1363 | my ($self) = @_; |
1389 | my $class = shift; |
1364 | |
1390 | |
1365 | my @alloc = map [$_->size_request], @{$self->{children}}; |
1391 | $class->SUPER::new ( |
1366 | |
1392 | vertical => 1, |
1367 | ( |
1393 | @_, |
1368 | (List::Util::max map $_->[0], @alloc), |
|
|
1369 | (List::Util::sum map $_->[1], @alloc), |
|
|
1370 | ) |
1394 | ) |
1371 | } |
|
|
1372 | |
|
|
1373 | sub size_allocate { |
|
|
1374 | my ($self, $w, $h) = @_; |
|
|
1375 | |
|
|
1376 | Carp::confess "negative size" if $w < 0 || $h < 0;#d# |
|
|
1377 | |
|
|
1378 | my $children = $self->{children}; |
|
|
1379 | |
|
|
1380 | my @h = map $_->{req_h}, @$children; |
|
|
1381 | |
|
|
1382 | my $req_h = List::Util::sum @h; |
|
|
1383 | |
|
|
1384 | if ($req_h > $h) { |
|
|
1385 | # ah well, not enough space |
|
|
1386 | $_ *= $h / $req_h for @h; |
|
|
1387 | } else { |
|
|
1388 | my $exp = List::Util::sum map $_->{expand}, @$children; |
|
|
1389 | $exp ||= 1; |
|
|
1390 | |
|
|
1391 | for (0 .. $#$children) { |
|
|
1392 | my $child = $children->[$_]; |
|
|
1393 | |
|
|
1394 | $h[$_] += ($h - $req_h) * $child->{expand} / $exp; |
|
|
1395 | } |
|
|
1396 | } |
|
|
1397 | |
|
|
1398 | CFClient::UI::harmonize \@h; |
|
|
1399 | |
|
|
1400 | my $y = 0; |
|
|
1401 | for (0 .. $#$children) { |
|
|
1402 | my $child = $children->[$_]; |
|
|
1403 | my $h = $h[$_]; |
|
|
1404 | $child->configure (0, $y, $w, $h); |
|
|
1405 | |
|
|
1406 | $y += $h; |
|
|
1407 | } |
|
|
1408 | |
|
|
1409 | 1 |
|
|
1410 | } |
1395 | } |
1411 | |
1396 | |
1412 | ############################################################################# |
1397 | ############################################################################# |
1413 | |
1398 | |
1414 | package CFClient::UI::Label; |
1399 | package CFClient::UI::Label; |
… | |
… | |
1477 | $self->{text} = "T$text"; |
1462 | $self->{text} = "T$text"; |
1478 | |
1463 | |
1479 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1464 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1480 | $self->{layout}->set_text ($text); |
1465 | $self->{layout}->set_text ($text); |
1481 | |
1466 | |
|
|
1467 | $self->realloc; |
1482 | $self->update; |
1468 | $self->update; |
1483 | $self->check_size; |
|
|
1484 | } |
1469 | } |
1485 | |
1470 | |
1486 | sub set_markup { |
1471 | sub set_markup { |
1487 | my ($self, $markup) = @_; |
1472 | my ($self, $markup) = @_; |
1488 | |
1473 | |
… | |
… | |
1492 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1477 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1493 | |
1478 | |
1494 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1479 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1495 | $self->{layout}->set_markup ($markup); |
1480 | $self->{layout}->set_markup ($markup); |
1496 | |
1481 | |
|
|
1482 | $self->realloc; |
1497 | $self->update; |
1483 | $self->update; |
1498 | $self->check_size; |
|
|
1499 | } |
1484 | } |
1500 | |
1485 | |
1501 | sub size_request { |
1486 | sub size_request { |
1502 | my ($self) = @_; |
1487 | my ($self) = @_; |
1503 | |
1488 | |
… | |
… | |
1524 | $h + $self->{padding} * 2, |
1509 | $h + $self->{padding} * 2, |
1525 | ) |
1510 | ) |
1526 | } |
1511 | } |
1527 | |
1512 | |
1528 | sub size_allocate { |
1513 | sub size_allocate { |
1529 | my ($self, $w, $h) = @_; |
1514 | my ($self, $w, $h, $changed) = @_; |
1530 | |
1515 | |
1531 | delete $self->{texture}; |
1516 | delete $self->{texture} |
|
|
1517 | if $changed; |
1532 | } |
1518 | } |
1533 | |
1519 | |
1534 | sub set_fontsize { |
1520 | sub set_fontsize { |
1535 | my ($self, $fontsize) = @_; |
1521 | my ($self, $fontsize) = @_; |
1536 | |
1522 | |
1537 | $self->{fontsize} = $fontsize; |
1523 | $self->{fontsize} = $fontsize; |
1538 | delete $self->{texture}; |
1524 | delete $self->{texture}; |
1539 | |
1525 | |
1540 | $self->update; |
1526 | $self->realloc; |
1541 | $self->check_size; |
|
|
1542 | } |
1527 | } |
1543 | |
1528 | |
1544 | sub _draw { |
1529 | sub _draw { |
1545 | my ($self) = @_; |
1530 | my ($self) = @_; |
1546 | |
1531 | |
… | |
… | |
1626 | sub set_text { |
1611 | sub set_text { |
1627 | my ($self, $text) = @_; |
1612 | my ($self, $text) = @_; |
1628 | |
1613 | |
1629 | $self->{cursor} = length $text; |
1614 | $self->{cursor} = length $text; |
1630 | $self->_set_text ($text); |
1615 | $self->_set_text ($text); |
1631 | $self->update; |
1616 | |
1632 | $self->check_size; |
1617 | $self->realloc; |
1633 | } |
1618 | } |
1634 | |
1619 | |
1635 | sub get_text { |
1620 | sub get_text { |
1636 | $_[0]{text} |
1621 | $_[0]{text} |
1637 | } |
1622 | } |
… | |
… | |
1670 | } elsif ($uni) { |
1655 | } elsif ($uni) { |
1671 | substr $text, $self->{cursor}++, 0, chr $uni; |
1656 | substr $text, $self->{cursor}++, 0, chr $uni; |
1672 | } |
1657 | } |
1673 | |
1658 | |
1674 | $self->_set_text ($text); |
1659 | $self->_set_text ($text); |
1675 | $self->update; |
1660 | |
1676 | $self->check_size; |
1661 | $self->realloc; |
1677 | } |
1662 | } |
1678 | |
1663 | |
1679 | sub focus_in { |
1664 | sub focus_in { |
1680 | my ($self) = @_; |
1665 | my ($self) = @_; |
1681 | |
1666 | |
… | |
… | |
2188 | $self->update; |
2173 | $self->update; |
2189 | |
2174 | |
2190 | $self |
2175 | $self |
2191 | } |
2176 | } |
2192 | |
2177 | |
|
|
2178 | sub changed { } |
|
|
2179 | |
2193 | sub set_range { |
2180 | sub set_range { |
2194 | my ($self, $range) = @_; |
2181 | my ($self, $range) = @_; |
2195 | |
2182 | |
2196 | ($range, $self->{range}) = ($self->{range}, $range); |
2183 | ($range, $self->{range}) = ($self->{range}, $range); |
2197 | |
2184 | |
… | |
… | |
2386 | $self->{fontsize} = $fontsize; |
2373 | $self->{fontsize} = $fontsize; |
2387 | $self->reflow; |
2374 | $self->reflow; |
2388 | } |
2375 | } |
2389 | |
2376 | |
2390 | sub size_allocate { |
2377 | sub size_allocate { |
2391 | my ($self, $w, $h) = @_; |
2378 | my ($self, $w, $h, $changed) = @_; |
2392 | |
2379 | |
2393 | $self->SUPER::size_allocate ($w, $h); |
2380 | $self->SUPER::size_allocate ($w, $h, $changed); |
|
|
2381 | |
|
|
2382 | return unless $changed; |
2394 | |
2383 | |
2395 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2384 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2396 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2385 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2397 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2386 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2398 | |
2387 | |
… | |
… | |
2592 | state => 0, |
2581 | state => 0, |
2593 | on_activate => \&toggle_flopper, |
2582 | on_activate => \&toggle_flopper, |
2594 | @_ |
2583 | @_ |
2595 | ); |
2584 | ); |
2596 | |
2585 | |
2597 | if ($self->{state}) { |
|
|
2598 | $self->{state} = 0; |
|
|
2599 | $self->toggle_flopper; |
|
|
2600 | } |
|
|
2601 | |
|
|
2602 | $self |
2586 | $self |
2603 | } |
2587 | } |
2604 | |
2588 | |
2605 | sub toggle_flopper { |
2589 | sub toggle_flopper { |
2606 | my ($self) = @_; |
2590 | my ($self) = @_; |
2607 | |
2591 | |
2608 | # TODO: use animation |
2592 | $self->{other}->toggle_visibility; |
2609 | if ($self->{state} = !$self->{state}) { |
|
|
2610 | $CFClient::UI::ROOT->add ($self->{other}); |
|
|
2611 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
|
|
2612 | $self->_emit ("open"); |
|
|
2613 | } else { |
|
|
2614 | $CFClient::UI::ROOT->remove ($self->{other}); |
|
|
2615 | $self->_emit ("close"); |
|
|
2616 | } |
|
|
2617 | |
|
|
2618 | $self->_emit (changed => $self->{state}); |
|
|
2619 | } |
2593 | } |
2620 | |
2594 | |
2621 | ############################################################################# |
2595 | ############################################################################# |
2622 | |
2596 | |
2623 | package CFClient::UI::Tooltip; |
2597 | package CFClient::UI::Tooltip; |
… | |
… | |
2655 | |
2629 | |
2656 | ($w + 4, $h + 4) |
2630 | ($w + 4, $h + 4) |
2657 | } |
2631 | } |
2658 | |
2632 | |
2659 | sub size_allocate { |
2633 | sub size_allocate { |
2660 | my ($self, $w, $h) = @_; |
2634 | my ($self, $w, $h, $changed) = @_; |
2661 | |
2635 | |
|
|
2636 | return unless $changed; |
|
|
2637 | |
2662 | $self->SUPER::size_allocate ($w - 4, $h - 4); |
2638 | $self->SUPER::size_allocate ($w - 4, $h - 4, $changed); |
|
|
2639 | } |
|
|
2640 | |
|
|
2641 | sub visibility_change { |
|
|
2642 | my ($self, $visible) = @_; |
|
|
2643 | |
|
|
2644 | return unless $visible; |
|
|
2645 | |
|
|
2646 | $self->{root}->on_post_alloc ("move_$self" => sub { |
|
|
2647 | my $widget = $self->{owner}; |
|
|
2648 | |
|
|
2649 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
|
|
2650 | |
|
|
2651 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
|
|
2652 | if $x + $self->{w} > $::WIDTH; |
|
|
2653 | |
|
|
2654 | $self->move ($x, $y); |
|
|
2655 | }); |
2663 | } |
2656 | } |
2664 | |
2657 | |
2665 | sub _draw { |
2658 | sub _draw { |
2666 | my ($self) = @_; |
2659 | my ($self) = @_; |
2667 | |
2660 | |
… | |
… | |
2684 | glVertex $w, $h; |
2677 | glVertex $w, $h; |
2685 | glVertex $w, 0; |
2678 | glVertex $w, 0; |
2686 | glEnd; |
2679 | glEnd; |
2687 | |
2680 | |
2688 | glTranslate 2 - 0.375, 2 - 0.375; |
2681 | glTranslate 2 - 0.375, 2 - 0.375; |
|
|
2682 | |
2689 | $self->SUPER::_draw; |
2683 | $self->SUPER::_draw; |
2690 | } |
2684 | } |
2691 | |
2685 | |
2692 | ############################################################################# |
2686 | ############################################################################# |
2693 | |
2687 | |
… | |
… | |
2807 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2801 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2808 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2802 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2809 | |
2803 | |
2810 | $row++; |
2804 | $row++; |
2811 | } |
2805 | } |
2812 | } |
|
|
2813 | |
|
|
2814 | sub size_request { |
|
|
2815 | my ($self) = @_; |
|
|
2816 | ($self->{req_w}, $self->{req_h}); |
|
|
2817 | } |
2806 | } |
2818 | |
2807 | |
2819 | ############################################################################# |
2808 | ############################################################################# |
2820 | |
2809 | |
2821 | package CFClient::UI::Menu; |
2810 | package CFClient::UI::Menu; |
… | |
… | |
3007 | use CFClient::OpenGL; |
2996 | use CFClient::OpenGL; |
3008 | |
2997 | |
3009 | sub new { |
2998 | sub new { |
3010 | my $class = shift; |
2999 | my $class = shift; |
3011 | |
3000 | |
3012 | $class->SUPER::new ( |
3001 | my $self = $class->SUPER::new ( |
3013 | visible => 1, |
3002 | visible => 1, |
3014 | @_, |
3003 | @_, |
3015 | ) |
3004 | ); |
|
|
3005 | |
|
|
3006 | Scalar::Util::weaken ($self->{root} = $self); |
|
|
3007 | |
|
|
3008 | $self |
3016 | } |
3009 | } |
3017 | |
3010 | |
3018 | sub configure { |
3011 | sub configure { |
3019 | my ($self, $x, $y, $w, $h) = @_; |
3012 | my ($self, $x, $y, $w, $h) = @_; |
3020 | |
3013 | |
3021 | $self->{w} = $w; |
3014 | $self->{w} = $w; |
3022 | $self->{h} = $h; |
3015 | $self->{h} = $h; |
3023 | } |
3016 | } |
3024 | |
3017 | |
3025 | sub check_size { |
3018 | sub reconfigure { |
3026 | my ($self) = @_; |
3019 | my ($self) = @_; |
3027 | |
3020 | |
|
|
3021 | $self->SUPER::reconfigure; |
|
|
3022 | |
3028 | $self->size_allocate ($self->{w}, $self->{h}) |
3023 | $self->size_allocate ($self->{w}, $self->{h}, 1) |
3029 | if $self->{w}; |
3024 | if $self->{w}; |
3030 | } |
3025 | } |
3031 | |
3026 | |
3032 | sub size_request { |
3027 | sub size_request { |
3033 | my ($self) = @_; |
3028 | my ($self) = @_; |
3034 | |
3029 | |
3035 | ($self->{w}, $self->{h}) |
3030 | ($self->{w}, $self->{h}) |
3036 | } |
3031 | } |
3037 | |
3032 | |
3038 | sub size_allocate { |
3033 | sub size_allocate { |
3039 | my ($self, $w, $h) = @_; |
3034 | my ($self, $w, $h, $changed) = @_; |
3040 | |
3035 | |
3041 | for my $child ($self->children) { |
3036 | for my $child ($self->children) { |
3042 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
3037 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
3043 | |
3038 | |
3044 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
3039 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
3045 | if exists $child->{req_x}; |
3040 | if exists $child->{req_x}; |
3046 | |
3041 | |
3047 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3042 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3048 | if exists $child->{req_y}; |
3043 | if exists $child->{req_y}; |
3049 | |
3044 | |
3050 | $X = $self->{user_x} if exists $self->{user_x}; |
3045 | #delete @$child{qw(req_x req_y)};#d# def_x, def_y |
3051 | $Y = $self->{user_y} if exists $self->{user_y}; |
|
|
3052 | |
3046 | |
3053 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
3047 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
3054 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
3048 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
3055 | |
3049 | |
3056 | $child->configure ($X, $Y, $W, $H); |
3050 | $child->configure ($X, $Y, $W, $H); |
… | |
… | |
3070 | } |
3064 | } |
3071 | |
3065 | |
3072 | sub update { |
3066 | sub update { |
3073 | my ($self) = @_; |
3067 | my ($self) = @_; |
3074 | |
3068 | |
3075 | $self->check_size; |
|
|
3076 | $::WANT_REFRESH++; |
3069 | $::WANT_REFRESH++; |
3077 | } |
3070 | } |
3078 | |
3071 | |
3079 | sub add { |
3072 | sub add { |
3080 | my ($self, @children) = @_; |
3073 | my ($self, @children) = @_; |
3081 | |
|
|
3082 | for (my @widgets = @children; my $w = pop @widgets; ) { |
|
|
3083 | push @widgets, $w->children; |
|
|
3084 | $w->{root} = $self; |
|
|
3085 | $w->{visible} = $self->{visible} + 1; |
|
|
3086 | } |
|
|
3087 | |
3074 | |
3088 | for my $child (@children) { |
3075 | for my $child (@children) { |
3089 | $child->{is_toplevel} = 1; |
3076 | $child->{is_toplevel} = 1; |
3090 | |
3077 | |
3091 | # integerise window positions |
3078 | # integerise window positions |
… | |
… | |
3126 | while ($self->{refresh_hook}) { |
3113 | while ($self->{refresh_hook}) { |
3127 | $_->() |
3114 | $_->() |
3128 | for values %{delete $self->{refresh_hook}}; |
3115 | for values %{delete $self->{refresh_hook}}; |
3129 | } |
3116 | } |
3130 | |
3117 | |
3131 | if ($self->{check_size}) { |
3118 | if ($self->{realloc}) { |
3132 | my @queue; |
3119 | my @queue; |
3133 | |
3120 | |
3134 | for (;;) { |
3121 | while () { |
3135 | if ($self->{check_size}) { |
3122 | if ($self->{realloc}) { |
3136 | #TODO use array-of-depth approach |
3123 | #TODO use array-of-depth approach |
3137 | |
3124 | |
3138 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3125 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3139 | @queue, values %{delete $self->{check_size}}; |
3126 | @queue, values %{delete $self->{realloc}}; |
3140 | } |
3127 | } |
3141 | |
3128 | |
3142 | my $widget = pop @queue || last; |
3129 | my $widget = pop @queue || last; |
3143 | |
3130 | |
3144 | defined $widget->{visible} or last; # do not resize invisible widgets |
3131 | $widget->{visible} or last; # do not resize invisible widgets |
3145 | |
3132 | |
3146 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
3133 | my ($w, $h) = $widget->{def_w} && $widget->{def_h} |
3147 | ? @$widget{qw(user_w user_h)} |
3134 | ? @$widget{qw(def_w def_h)} |
3148 | : $widget->size_request; |
3135 | : $widget->size_request; |
3149 | |
3136 | |
3150 | if (delete $widget->{force_alloc} |
|
|
3151 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
|
|
3152 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3137 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3153 | |
3138 | |
3154 | $widget->{req_w} = $w; |
3139 | $widget->{req_w} = $w; |
3155 | $widget->{req_h} = $h; |
3140 | $widget->{req_h} = $h; |
3156 | |
3141 | |
3157 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
3142 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
3158 | |
3143 | |
3159 | $widget->{parent}->check_size |
3144 | push @queue, $widget->{parent} |
3160 | if $widget->{parent}; |
3145 | if $widget->{parent}; |
3161 | } |
|
|
3162 | } |
3146 | } |
3163 | } |
3147 | } |
3164 | |
3148 | |
3165 | while ($self->{size_alloc}) { |
3149 | while (my $size_alloc = delete $self->{size_alloc}) { |
3166 | for (values %{delete $self->{size_alloc}}) { |
3150 | my @queue = sort $b->[0]{visible} <=> $a->[0]{visible}, |
3167 | my ($widget, $w, $h) = @$_; |
3151 | values %$size_alloc; |
|
|
3152 | |
|
|
3153 | while () { |
|
|
3154 | my ($widget, $w, $h) = @{ pop @queue or last }; |
3168 | |
3155 | |
3169 | $w = 0 if $w < 0; |
3156 | $w = 0 if $w < 0; |
3170 | $h = 0 if $h < 0; |
3157 | $h = 0 if $h < 0; |
3171 | |
3158 | |
|
|
3159 | my $changed = $widget->{w} != $w || $widget->{h} != $h; |
|
|
3160 | |
3172 | $widget->{w} = $w; |
3161 | $widget->{w} = $w; |
3173 | $widget->{h} = $h; |
3162 | $widget->{h} = $h; |
|
|
3163 | |
3174 | $widget->emit (size_allocate => $w, $h); |
3164 | $widget->emit (size_allocate => $w, $h, $changed); |
3175 | } |
3165 | } |
3176 | } |
3166 | } |
3177 | |
3167 | |
3178 | while ($self->{post_alloc_hook}) { |
3168 | while ($self->{post_alloc_hook}) { |
3179 | $_->() |
3169 | $_->() |