… | |
… | |
47 | my $tip = $widget->{tooltip}; |
47 | my $tip = $widget->{tooltip}; |
48 | |
48 | |
49 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
49 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
50 | |
50 | |
51 | $TOOLTIP->set_tooltip_from ($widget); |
51 | $TOOLTIP->set_tooltip_from ($widget); |
52 | $TOOLTIP->show; |
|
|
53 | |
52 | |
54 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
53 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
55 | |
54 | |
56 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) |
55 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) |
57 | if $x + $TOOLTIP->{w} > $::WIDTH; |
56 | if $x + $TOOLTIP->{w} > $::WIDTH; |
58 | |
57 | |
59 | $TOOLTIP->move ($x, $y); |
58 | $TOOLTIP->move ($x, $y); |
60 | $TOOLTIP->check_size; |
|
|
61 | $TOOLTIP->update; |
59 | $TOOLTIP->show; |
62 | } |
60 | } |
63 | |
61 | |
64 | return; |
62 | return; |
65 | } |
63 | } |
66 | } |
64 | } |
… | |
… | |
221 | } |
219 | } |
222 | |
220 | |
223 | $self |
221 | $self |
224 | } |
222 | } |
225 | |
223 | |
226 | sub toggle_visibility { |
|
|
227 | my ($self) = @_; |
|
|
228 | |
|
|
229 | if ($self->{visible}) { |
|
|
230 | $self->hide; |
|
|
231 | } else { |
|
|
232 | $self->show; |
|
|
233 | } |
|
|
234 | } |
|
|
235 | |
|
|
236 | sub destroy { |
224 | sub destroy { |
237 | my ($self) = @_; |
225 | my ($self) = @_; |
238 | |
226 | |
239 | $self->hide; |
227 | $self->hide; |
240 | %$self = (); |
228 | %$self = (); |
… | |
… | |
267 | |
255 | |
268 | $self->{root} = $self->{parent}{root}; |
256 | $self->{root} = $self->{parent}{root}; |
269 | $self->{visible} = $self->{parent}{visible} + 1; |
257 | $self->{visible} = $self->{parent}{visible} + 1; |
270 | |
258 | |
271 | $self->emit (visibility_change => 1); |
259 | $self->emit (visibility_change => 1); |
|
|
260 | |
|
|
261 | $self->realloc if !exists $self->{req_w}; |
|
|
262 | |
|
|
263 | $_->set_visible for $self->children; |
272 | } |
264 | } |
273 | |
265 | |
274 | sub set_invisible { |
266 | sub set_invisible { |
275 | my ($self) = @_; |
267 | my ($self) = @_; |
276 | |
268 | |
277 | return unless $self->{visible}; |
269 | return unless $self->{visible}; |
278 | |
270 | |
279 | # broken show/hide model |
271 | $_->set_invisible for $self->children; |
280 | |
272 | |
281 | delete $self->{root}; |
273 | delete $self->{root}; |
282 | delete $self->{visible}; |
274 | delete $self->{visible}; |
283 | |
275 | |
284 | undef $GRAB if $GRAB == $self; |
276 | undef $GRAB if $GRAB == $self; |
285 | undef $HOVER if $HOVER == $self; |
277 | undef $HOVER if $HOVER == $self; |
286 | |
278 | |
287 | CFClient::UI::check_tooltip |
279 | CFClient::UI::check_tooltip |
288 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
280 | if $TOOLTIP->{owner} == $self; |
289 | |
281 | |
290 | $self->focus_out; |
282 | $self->focus_out; |
291 | |
283 | |
292 | $self->emit (visibility_change => 0); |
284 | $self->emit (visibility_change => 0); |
|
|
285 | } |
|
|
286 | |
|
|
287 | sub set_visibility { |
|
|
288 | my ($self, $visible) = @_; |
|
|
289 | |
|
|
290 | return if $self->{visible} == $visible; |
|
|
291 | |
|
|
292 | $visible ? $self->hide |
|
|
293 | : $self->show; |
|
|
294 | } |
|
|
295 | |
|
|
296 | sub toggle_visibility { |
|
|
297 | my ($self) = @_; |
|
|
298 | |
|
|
299 | $self->{visible} |
|
|
300 | ? $self->hide |
|
|
301 | : $self->show; |
293 | } |
302 | } |
294 | |
303 | |
295 | sub hide { |
304 | sub hide { |
296 | my ($self) = @_; |
305 | my ($self) = @_; |
297 | |
306 | |
… | |
… | |
315 | my ($self, $w, $h) = @_; |
324 | my ($self, $w, $h) = @_; |
316 | |
325 | |
317 | $self->{def_w} = $w; |
326 | $self->{def_w} = $w; |
318 | $self->{def_h} = $h; |
327 | $self->{def_h} = $h; |
319 | |
328 | |
320 | $self->check_size; |
329 | $self->realloc; |
321 | } |
330 | } |
322 | |
331 | |
323 | sub size_request { |
332 | sub size_request { |
324 | require Carp; |
333 | require Carp; |
325 | Carp::confess "size_request is abstract"; |
334 | Carp::confess "size_request is abstract"; |
… | |
… | |
345 | $self->{y} = $y; |
354 | $self->{y} = $y; |
346 | $self->update; |
355 | $self->update; |
347 | } |
356 | } |
348 | |
357 | |
349 | if ($self->{w} != $w || $self->{h} != $h) { |
358 | if ($self->{w} != $w || $self->{h} != $h) { |
|
|
359 | return unless $self->{visible}; |
|
|
360 | |
350 | $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $w, $h]; |
361 | $self->{root}->{size_alloc}{$self+0} = [$self, $w, $h]; |
351 | } |
362 | } |
352 | } |
363 | } |
353 | |
364 | |
354 | sub size_allocate { |
365 | sub size_allocate { |
355 | # nothing to be done |
366 | # nothing to be done |
356 | } |
|
|
357 | |
|
|
358 | sub reconfigure { |
|
|
359 | my ($self) = @_; |
|
|
360 | |
|
|
361 | $self->check_size (1); |
|
|
362 | $self->update; |
|
|
363 | } |
367 | } |
364 | |
368 | |
365 | sub children { |
369 | sub children { |
366 | } |
370 | } |
367 | |
371 | |
… | |
… | |
445 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
449 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
446 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
450 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
447 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
451 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
448 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
452 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
449 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
453 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
|
|
454 | |
|
|
455 | sub find_widget { |
|
|
456 | my ($self, $x, $y) = @_; |
|
|
457 | |
|
|
458 | return () unless $self->{can_events}; |
|
|
459 | |
|
|
460 | return $self |
|
|
461 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
462 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
463 | |
|
|
464 | () |
|
|
465 | } |
|
|
466 | |
|
|
467 | sub set_parent { |
|
|
468 | my ($self, $parent) = @_; |
|
|
469 | |
|
|
470 | Scalar::Util::weaken ($self->{parent} = $parent); |
|
|
471 | |
|
|
472 | $self->set_visible if $parent->{visible}; |
|
|
473 | } |
|
|
474 | |
|
|
475 | sub connect { |
|
|
476 | my ($self, $signal, $cb) = @_; |
|
|
477 | |
|
|
478 | push @{ $self->{signal_cb}{$signal} }, $cb; |
|
|
479 | } |
|
|
480 | |
|
|
481 | sub _emit { |
|
|
482 | my ($self, $signal, @args) = @_; |
|
|
483 | |
|
|
484 | List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} |
|
|
485 | } |
|
|
486 | |
|
|
487 | sub emit { |
|
|
488 | my ($self, $signal, @args) = @_; |
|
|
489 | |
|
|
490 | $self->_emit ($signal, @args) |
|
|
491 | || $self->$signal (@args); |
|
|
492 | } |
|
|
493 | |
|
|
494 | sub visibility_change { |
|
|
495 | #my ($self, $visible) = @_; |
|
|
496 | } |
|
|
497 | |
|
|
498 | sub realloc { |
|
|
499 | my ($self) = @_; |
|
|
500 | |
|
|
501 | if ($self->{visible}) { |
|
|
502 | return if $self->{root}{realloc}{$self}; |
|
|
503 | |
|
|
504 | $self->{root}{realloc}{$self} = $self; |
|
|
505 | $self->{root}->update; |
|
|
506 | } else { |
|
|
507 | delete $self->{req_w}; |
|
|
508 | } |
|
|
509 | } |
|
|
510 | |
|
|
511 | sub update { |
|
|
512 | my ($self) = @_; |
|
|
513 | |
|
|
514 | $self->{parent}->update |
|
|
515 | if $self->{parent}; |
|
|
516 | } |
450 | |
517 | |
451 | sub draw { |
518 | sub draw { |
452 | my ($self) = @_; |
519 | my ($self) = @_; |
453 | |
520 | |
454 | return unless $self->{h} && $self->{w}; |
521 | return unless $self->{h} && $self->{w}; |
… | |
… | |
492 | my ($self) = @_; |
559 | my ($self) = @_; |
493 | |
560 | |
494 | warn "no draw defined for $self\n"; |
561 | warn "no draw defined for $self\n"; |
495 | } |
562 | } |
496 | |
563 | |
497 | sub find_widget { |
|
|
498 | my ($self, $x, $y) = @_; |
|
|
499 | |
|
|
500 | return () unless $self->{can_events}; |
|
|
501 | |
|
|
502 | return $self |
|
|
503 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
504 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
505 | |
|
|
506 | () |
|
|
507 | } |
|
|
508 | |
|
|
509 | sub set_parent { |
|
|
510 | my ($self, $parent) = @_; |
|
|
511 | |
|
|
512 | Scalar::Util::weaken ($self->{parent} = $parent); |
|
|
513 | |
|
|
514 | $self->set_visible; #TODO why breakssssss borked damn if $parent->{visible}; |
|
|
515 | |
|
|
516 | $self->check_size; |
|
|
517 | } |
|
|
518 | |
|
|
519 | sub check_size { |
|
|
520 | my ($self, $forced) = @_; |
|
|
521 | |
|
|
522 | $self->{force_alloc} = 1 if $forced; |
|
|
523 | $CFClient::UI::ROOT->{check_size}{$self} = $self; |
|
|
524 | } |
|
|
525 | |
|
|
526 | sub update { |
|
|
527 | my ($self) = @_; |
|
|
528 | |
|
|
529 | $self->{parent}->update |
|
|
530 | if $self->{parent}; |
|
|
531 | } |
|
|
532 | |
|
|
533 | sub connect { |
|
|
534 | my ($self, $signal, $cb) = @_; |
|
|
535 | |
|
|
536 | push @{ $self->{signal_cb}{$signal} }, $cb; |
|
|
537 | } |
|
|
538 | |
|
|
539 | sub _emit { |
|
|
540 | my ($self, $signal, @args) = @_; |
|
|
541 | |
|
|
542 | List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} |
|
|
543 | } |
|
|
544 | |
|
|
545 | sub emit { |
|
|
546 | my ($self, $signal, @args) = @_; |
|
|
547 | |
|
|
548 | $self->_emit ($signal, @args) |
|
|
549 | || $self->$signal (@args); |
|
|
550 | } |
|
|
551 | |
|
|
552 | sub visibility_change { |
|
|
553 | #my ($self, $visible) = @_; |
|
|
554 | } |
|
|
555 | |
|
|
556 | sub DESTROY { |
564 | sub DESTROY { |
557 | my ($self) = @_; |
565 | my ($self) = @_; |
558 | |
566 | |
559 | delete $WIDGET{$self+0}; |
567 | delete $WIDGET{$self+0}; |
560 | #$self->deactivate; |
568 | #$self->deactivate; |
… | |
… | |
655 | $self->{children} = [ |
663 | $self->{children} = [ |
656 | sort { $a->{z} <=> $b->{z} } |
664 | sort { $a->{z} <=> $b->{z} } |
657 | @{$self->{children}}, @widgets |
665 | @{$self->{children}}, @widgets |
658 | ]; |
666 | ]; |
659 | |
667 | |
660 | $self->check_size (1); |
668 | $self->realloc; |
661 | $self->update; |
|
|
662 | } |
669 | } |
663 | |
670 | |
664 | sub children { |
671 | sub children { |
665 | @{ $_[0]{children} } |
672 | @{ $_[0]{children} } |
666 | } |
673 | } |
… | |
… | |
671 | delete $child->{parent}; |
678 | delete $child->{parent}; |
672 | $child->hide; |
679 | $child->hide; |
673 | |
680 | |
674 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
681 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
675 | |
682 | |
676 | $self->check_size (1); |
683 | $self->realloc; |
677 | $self->update; |
|
|
678 | } |
684 | } |
679 | |
685 | |
680 | sub clear { |
686 | sub clear { |
681 | my ($self) = @_; |
687 | my ($self) = @_; |
682 | |
688 | |
… | |
… | |
686 | for (@$children) { |
692 | for (@$children) { |
687 | delete $_->{parent}; |
693 | delete $_->{parent}; |
688 | $_->hide; |
694 | $_->hide; |
689 | } |
695 | } |
690 | |
696 | |
691 | $self->check_size; |
697 | $self->realloc; |
692 | $self->update; |
|
|
693 | } |
698 | } |
694 | |
699 | |
695 | sub find_widget { |
700 | sub find_widget { |
696 | my ($self, $x, $y) = @_; |
701 | my ($self, $x, $y) = @_; |
697 | |
702 | |
… | |
… | |
750 | sub size_request { |
755 | sub size_request { |
751 | $_[0]{children}[0]->size_request |
756 | $_[0]{children}[0]->size_request |
752 | } |
757 | } |
753 | |
758 | |
754 | sub size_allocate { |
759 | sub size_allocate { |
755 | my ($self, $w, $h) = @_; |
760 | my ($self, $w, $h, $changed) = @_; |
756 | |
761 | |
757 | $self->{children}[0]->configure (0, 0, $w, $h); |
762 | $self->{children}[0]->configure (0, 0, $w, $h); |
758 | } |
763 | } |
759 | |
764 | |
760 | ############################################################################# |
765 | ############################################################################# |
… | |
… | |
777 | $ROOT->on_post_alloc ($self => sub { $self->render_child }); |
782 | $ROOT->on_post_alloc ($self => sub { $self->render_child }); |
778 | $self->SUPER::update; |
783 | $self->SUPER::update; |
779 | } |
784 | } |
780 | |
785 | |
781 | sub size_allocate { |
786 | sub size_allocate { |
782 | my ($self, $w, $h) = @_; |
787 | my ($self, $w, $h, $changed) = @_; |
783 | |
788 | |
784 | $self->SUPER::size_allocate ($w, $h); |
789 | $self->SUPER::size_allocate ($w, $h, $changed); |
785 | $self->update; |
790 | $self->update |
|
|
791 | if $changed; |
786 | } |
792 | } |
787 | |
793 | |
788 | sub _render { |
794 | sub _render { |
789 | $_[0]{children}[0]->draw; |
795 | $_[0]{children}[0]->draw; |
790 | } |
796 | } |
… | |
… | |
843 | |
849 | |
844 | ($w, $h) |
850 | ($w, $h) |
845 | } |
851 | } |
846 | |
852 | |
847 | sub size_allocate { |
853 | sub size_allocate { |
848 | my ($self, $w, $h) = @_; |
854 | my ($self, $w, $h, $changed) = @_; |
849 | |
855 | |
850 | $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; |
856 | $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; |
851 | $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; |
857 | $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; |
852 | |
858 | |
853 | $self->child->configure (0, 0, $w, $h); |
859 | $self->child->configure (0, 0, $w, $h); |
… | |
… | |
940 | my $child = $self->{vp}->child; |
946 | my $child = $self->{vp}->child; |
941 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
947 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
942 | } |
948 | } |
943 | |
949 | |
944 | sub size_allocate { |
950 | sub size_allocate { |
945 | my ($self, $w, $h) = @_; |
951 | my ($self, $w, $h, $changed) = @_; |
946 | |
952 | |
947 | $self->SUPER::size_allocate ($w, $h); |
953 | $self->SUPER::size_allocate ($w, $h, $changed); |
948 | |
954 | |
949 | my $child = $self->{vp}->child; |
955 | my $child = $self->{vp}->child; |
950 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
956 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
951 | } |
957 | } |
952 | |
958 | |
… | |
… | |
1040 | $h + $self->border * 2, |
1046 | $h + $self->border * 2, |
1041 | ) |
1047 | ) |
1042 | } |
1048 | } |
1043 | |
1049 | |
1044 | sub size_allocate { |
1050 | sub size_allocate { |
1045 | my ($self, $w, $h) = @_; |
1051 | my ($self, $w, $h, $changed) = @_; |
|
|
1052 | |
|
|
1053 | return unless $changed; |
1046 | |
1054 | |
1047 | $h -= List::Util::max 0, $self->border * 2; |
1055 | $h -= List::Util::max 0, $self->border * 2; |
1048 | $w -= List::Util::max 0, $self->border * 2; |
1056 | $w -= List::Util::max 0, $self->border * 2; |
1049 | |
1057 | |
1050 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
1058 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
… | |
… | |
1079 | $self->{user_x} = $wx + $dx * $mx; |
1087 | $self->{user_x} = $wx + $dx * $mx; |
1080 | $self->{user_y} = $wy + $dy * $my; |
1088 | $self->{user_y} = $wy + $dy * $my; |
1081 | $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); |
1089 | $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); |
1082 | $self->{def_h} = $bh + $dy * ($my ? -1 : 1); |
1090 | $self->{def_h} = $bh + $dy * ($my ? -1 : 1); |
1083 | $self->move ($self->{user_x}, $self->{user_y}); |
1091 | $self->move ($self->{user_x}, $self->{user_y}); |
1084 | $self->check_size; |
1092 | $self->realloc; |
1085 | }; |
1093 | }; |
1086 | |
1094 | |
1087 | } elsif ($lr ^ $td) { |
1095 | } elsif ($lr ^ $td) { |
1088 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1096 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1089 | my ($bx, $by) = ($self->{x}, $self->{y}); |
1097 | my ($bx, $by) = ($self->{x}, $self->{y}); |
… | |
… | |
1095 | |
1103 | |
1096 | $self->{user_x} = $bx + $x - $ox; |
1104 | $self->{user_x} = $bx + $x - $ox; |
1097 | $self->{user_y} = $by + $y - $oy; |
1105 | $self->{user_y} = $by + $y - $oy; |
1098 | |
1106 | |
1099 | $self->move ($self->{user_x}, $self->{user_y}); |
1107 | $self->move ($self->{user_x}, $self->{user_y}); |
1100 | $self->update; |
1108 | $self->realloc; |
1101 | }; |
1109 | }; |
1102 | } |
1110 | } |
1103 | } |
1111 | } |
1104 | |
1112 | |
1105 | sub button_up { |
1113 | sub button_up { |
… | |
… | |
1180 | my ($self, $x, $y, $child) = @_; |
1188 | my ($self, $x, $y, $child) = @_; |
1181 | |
1189 | |
1182 | $child->set_parent ($self); |
1190 | $child->set_parent ($self); |
1183 | $self->{children}[$y][$x] = $child; |
1191 | $self->{children}[$y][$x] = $child; |
1184 | |
1192 | |
1185 | $self->check_size (1); |
1193 | $self->realloc; |
1186 | } |
1194 | } |
1187 | |
1195 | |
1188 | # TODO: move to container class maybe? send children a signal on removal? |
1196 | # TODO: move to container class maybe? send children a signal on removal? |
1189 | sub clear { |
1197 | sub clear { |
1190 | my ($self) = @_; |
1198 | my ($self) = @_; |
… | |
… | |
1195 | for (@children) { |
1203 | for (@children) { |
1196 | delete $_->{parent}; |
1204 | delete $_->{parent}; |
1197 | $_->hide; |
1205 | $_->hide; |
1198 | } |
1206 | } |
1199 | |
1207 | |
1200 | $self->check_size (1); |
1208 | $self->realloc; |
1201 | $self->update; |
|
|
1202 | } |
1209 | } |
1203 | |
1210 | |
1204 | sub get_wh { |
1211 | sub get_wh { |
1205 | my ($self) = @_; |
1212 | my ($self) = @_; |
1206 | |
1213 | |
… | |
… | |
1233 | (sum @$hs), |
1240 | (sum @$hs), |
1234 | ) |
1241 | ) |
1235 | } |
1242 | } |
1236 | |
1243 | |
1237 | sub size_allocate { |
1244 | sub size_allocate { |
1238 | my ($self, $w, $h) = @_; |
1245 | my ($self, $w, $h, $changed) = @_; |
1239 | |
1246 | |
1240 | my ($ws, $hs) = $self->get_wh; |
1247 | my ($ws, $hs) = $self->get_wh; |
1241 | |
1248 | |
1242 | my $req_w = (sum @$ws) || 1; |
1249 | my $req_w = (sum @$ws) || 1; |
1243 | my $req_h = (sum @$hs) || 1; |
1250 | my $req_h = (sum @$hs) || 1; |
… | |
… | |
1321 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1328 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1322 | ) |
1329 | ) |
1323 | } |
1330 | } |
1324 | |
1331 | |
1325 | sub size_allocate { |
1332 | sub size_allocate { |
1326 | my ($self, $w, $h) = @_; |
1333 | my ($self, $w, $h, $changed) = @_; |
1327 | |
1334 | |
1328 | my $space = $self->{vertical} ? $h : $w; |
1335 | my $space = $self->{vertical} ? $h : $w; |
1329 | my $children = $self->{children}; |
1336 | my $children = $self->{children}; |
1330 | |
1337 | |
1331 | my @req; |
1338 | my @req; |
… | |
… | |
1460 | $self->{text} = "T$text"; |
1467 | $self->{text} = "T$text"; |
1461 | |
1468 | |
1462 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1469 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1463 | $self->{layout}->set_text ($text); |
1470 | $self->{layout}->set_text ($text); |
1464 | |
1471 | |
|
|
1472 | $self->realloc; |
1465 | $self->update; |
1473 | $self->update; |
1466 | $self->check_size; |
|
|
1467 | } |
1474 | } |
1468 | |
1475 | |
1469 | sub set_markup { |
1476 | sub set_markup { |
1470 | my ($self, $markup) = @_; |
1477 | my ($self, $markup) = @_; |
1471 | |
1478 | |
… | |
… | |
1475 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1482 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1476 | |
1483 | |
1477 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1484 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1478 | $self->{layout}->set_markup ($markup); |
1485 | $self->{layout}->set_markup ($markup); |
1479 | |
1486 | |
|
|
1487 | $self->realloc; |
1480 | $self->update; |
1488 | $self->update; |
1481 | $self->check_size; |
|
|
1482 | } |
1489 | } |
1483 | |
1490 | |
1484 | sub size_request { |
1491 | sub size_request { |
1485 | my ($self) = @_; |
1492 | my ($self) = @_; |
1486 | |
1493 | |
… | |
… | |
1507 | $h + $self->{padding} * 2, |
1514 | $h + $self->{padding} * 2, |
1508 | ) |
1515 | ) |
1509 | } |
1516 | } |
1510 | |
1517 | |
1511 | sub size_allocate { |
1518 | sub size_allocate { |
1512 | my ($self, $w, $h) = @_; |
1519 | my ($self, $w, $h, $changed) = @_; |
1513 | |
1520 | |
1514 | delete $self->{texture}; |
1521 | delete $self->{texture} |
|
|
1522 | if $changed; |
1515 | } |
1523 | } |
1516 | |
1524 | |
1517 | sub set_fontsize { |
1525 | sub set_fontsize { |
1518 | my ($self, $fontsize) = @_; |
1526 | my ($self, $fontsize) = @_; |
1519 | |
1527 | |
1520 | $self->{fontsize} = $fontsize; |
1528 | $self->{fontsize} = $fontsize; |
1521 | delete $self->{texture}; |
1529 | delete $self->{texture}; |
1522 | |
1530 | |
1523 | $self->update; |
1531 | $self->realloc; |
1524 | $self->check_size; |
|
|
1525 | } |
1532 | } |
1526 | |
1533 | |
1527 | sub _draw { |
1534 | sub _draw { |
1528 | my ($self) = @_; |
1535 | my ($self) = @_; |
1529 | |
1536 | |
… | |
… | |
1609 | sub set_text { |
1616 | sub set_text { |
1610 | my ($self, $text) = @_; |
1617 | my ($self, $text) = @_; |
1611 | |
1618 | |
1612 | $self->{cursor} = length $text; |
1619 | $self->{cursor} = length $text; |
1613 | $self->_set_text ($text); |
1620 | $self->_set_text ($text); |
1614 | $self->update; |
1621 | |
1615 | $self->check_size; |
1622 | $self->realloc; |
1616 | } |
1623 | } |
1617 | |
1624 | |
1618 | sub get_text { |
1625 | sub get_text { |
1619 | $_[0]{text} |
1626 | $_[0]{text} |
1620 | } |
1627 | } |
… | |
… | |
1653 | } elsif ($uni) { |
1660 | } elsif ($uni) { |
1654 | substr $text, $self->{cursor}++, 0, chr $uni; |
1661 | substr $text, $self->{cursor}++, 0, chr $uni; |
1655 | } |
1662 | } |
1656 | |
1663 | |
1657 | $self->_set_text ($text); |
1664 | $self->_set_text ($text); |
1658 | $self->update; |
1665 | |
1659 | $self->check_size; |
1666 | $self->realloc; |
1660 | } |
1667 | } |
1661 | |
1668 | |
1662 | sub focus_in { |
1669 | sub focus_in { |
1663 | my ($self) = @_; |
1670 | my ($self) = @_; |
1664 | |
1671 | |
… | |
… | |
2171 | $self->update; |
2178 | $self->update; |
2172 | |
2179 | |
2173 | $self |
2180 | $self |
2174 | } |
2181 | } |
2175 | |
2182 | |
|
|
2183 | sub changed { } |
|
|
2184 | |
2176 | sub set_range { |
2185 | sub set_range { |
2177 | my ($self, $range) = @_; |
2186 | my ($self, $range) = @_; |
2178 | |
2187 | |
2179 | ($range, $self->{range}) = ($self->{range}, $range); |
2188 | ($range, $self->{range}) = ($self->{range}, $range); |
2180 | |
2189 | |
… | |
… | |
2369 | $self->{fontsize} = $fontsize; |
2378 | $self->{fontsize} = $fontsize; |
2370 | $self->reflow; |
2379 | $self->reflow; |
2371 | } |
2380 | } |
2372 | |
2381 | |
2373 | sub size_allocate { |
2382 | sub size_allocate { |
2374 | my ($self, $w, $h) = @_; |
2383 | my ($self, $w, $h, $changed) = @_; |
2375 | |
2384 | |
2376 | $self->SUPER::size_allocate ($w, $h); |
2385 | $self->SUPER::size_allocate ($w, $h, $changed); |
|
|
2386 | |
|
|
2387 | return unless $changed; |
2377 | |
2388 | |
2378 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2389 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2379 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2390 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2380 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2391 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2381 | |
2392 | |
… | |
… | |
2623 | |
2634 | |
2624 | ($w + 4, $h + 4) |
2635 | ($w + 4, $h + 4) |
2625 | } |
2636 | } |
2626 | |
2637 | |
2627 | sub size_allocate { |
2638 | sub size_allocate { |
2628 | my ($self, $w, $h) = @_; |
2639 | my ($self, $w, $h, $changed) = @_; |
2629 | |
2640 | |
|
|
2641 | return unless $changed; |
|
|
2642 | |
2630 | $self->SUPER::size_allocate ($w - 4, $h - 4); |
2643 | $self->SUPER::size_allocate ($w - 4, $h - 4, $changed); |
2631 | } |
2644 | } |
2632 | |
2645 | |
2633 | sub _draw { |
2646 | sub _draw { |
2634 | my ($self) = @_; |
2647 | my ($self) = @_; |
2635 | |
2648 | |
… | |
… | |
2652 | glVertex $w, $h; |
2665 | glVertex $w, $h; |
2653 | glVertex $w, 0; |
2666 | glVertex $w, 0; |
2654 | glEnd; |
2667 | glEnd; |
2655 | |
2668 | |
2656 | glTranslate 2 - 0.375, 2 - 0.375; |
2669 | glTranslate 2 - 0.375, 2 - 0.375; |
|
|
2670 | |
2657 | $self->SUPER::_draw; |
2671 | $self->SUPER::_draw; |
2658 | } |
2672 | } |
2659 | |
2673 | |
2660 | ############################################################################# |
2674 | ############################################################################# |
2661 | |
2675 | |
… | |
… | |
2970 | use CFClient::OpenGL; |
2984 | use CFClient::OpenGL; |
2971 | |
2985 | |
2972 | sub new { |
2986 | sub new { |
2973 | my $class = shift; |
2987 | my $class = shift; |
2974 | |
2988 | |
2975 | $class->SUPER::new ( |
2989 | my $self = $class->SUPER::new ( |
2976 | visible => 1, |
2990 | visible => 1, |
2977 | @_, |
2991 | @_, |
2978 | ) |
2992 | ); |
|
|
2993 | |
|
|
2994 | Scalar::Util::weaken ($self->{root} = $self); |
|
|
2995 | |
|
|
2996 | $self |
2979 | } |
2997 | } |
2980 | |
2998 | |
2981 | sub configure { |
2999 | sub configure { |
2982 | my ($self, $x, $y, $w, $h) = @_; |
3000 | my ($self, $x, $y, $w, $h) = @_; |
2983 | |
3001 | |
2984 | $self->{w} = $w; |
3002 | $self->{w} = $w; |
2985 | $self->{h} = $h; |
3003 | $self->{h} = $h; |
2986 | } |
3004 | } |
2987 | |
3005 | |
2988 | sub check_size { |
3006 | sub reconfigure { |
2989 | my ($self) = @_; |
3007 | my ($self) = @_; |
2990 | |
3008 | |
|
|
3009 | $self->SUPER::reconfigure; |
|
|
3010 | |
2991 | $self->size_allocate ($self->{w}, $self->{h}) |
3011 | $self->size_allocate ($self->{w}, $self->{h}, 1) |
2992 | if $self->{w}; |
3012 | if $self->{w}; |
2993 | } |
3013 | } |
2994 | |
3014 | |
2995 | sub size_request { |
3015 | sub size_request { |
2996 | my ($self) = @_; |
3016 | my ($self) = @_; |
2997 | |
3017 | |
2998 | ($self->{w}, $self->{h}) |
3018 | ($self->{w}, $self->{h}) |
2999 | } |
3019 | } |
3000 | |
3020 | |
3001 | sub size_allocate { |
3021 | sub size_allocate { |
3002 | my ($self, $w, $h) = @_; |
3022 | my ($self, $w, $h, $changed) = @_; |
3003 | |
3023 | |
3004 | for my $child ($self->children) { |
3024 | for my $child ($self->children) { |
3005 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
3025 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
3006 | |
3026 | |
3007 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
3027 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
3008 | if exists $child->{req_x}; |
3028 | if exists $child->{req_x}; |
3009 | |
3029 | |
3010 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3030 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3011 | if exists $child->{req_y}; |
3031 | if exists $child->{req_y}; |
3012 | |
3032 | |
3013 | delete @$child{qw(req_x req_y)}; |
3033 | #delete @$child{qw(req_x req_y)};#d# def_x, def_y |
3014 | |
3034 | |
3015 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
3035 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
3016 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
3036 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
3017 | |
3037 | |
3018 | $child->configure ($X, $Y, $W, $H); |
3038 | $child->configure ($X, $Y, $W, $H); |
… | |
… | |
3032 | } |
3052 | } |
3033 | |
3053 | |
3034 | sub update { |
3054 | sub update { |
3035 | my ($self) = @_; |
3055 | my ($self) = @_; |
3036 | |
3056 | |
3037 | $self->check_size; |
|
|
3038 | $::WANT_REFRESH++; |
3057 | $::WANT_REFRESH++; |
3039 | } |
3058 | } |
3040 | |
3059 | |
3041 | sub add { |
3060 | sub add { |
3042 | my ($self, @children) = @_; |
3061 | my ($self, @children) = @_; |
… | |
… | |
3048 | $child->{x} = int $child->{x}; |
3067 | $child->{x} = int $child->{x}; |
3049 | $child->{y} = int $child->{y}; |
3068 | $child->{y} = int $child->{y}; |
3050 | } |
3069 | } |
3051 | |
3070 | |
3052 | $self->SUPER::add (@children); |
3071 | $self->SUPER::add (@children); |
3053 | |
|
|
3054 | for (my @widgets = @children; my $w = pop @widgets; ) { |
|
|
3055 | push @widgets, $w->children; |
|
|
3056 | $w->set_visible; |
|
|
3057 | } |
|
|
3058 | |
|
|
3059 | } |
3072 | } |
3060 | |
3073 | |
3061 | sub remove { |
3074 | sub remove { |
3062 | my ($self, @children) = @_; |
3075 | my ($self, @children) = @_; |
3063 | |
3076 | |
… | |
… | |
3088 | while ($self->{refresh_hook}) { |
3101 | while ($self->{refresh_hook}) { |
3089 | $_->() |
3102 | $_->() |
3090 | for values %{delete $self->{refresh_hook}}; |
3103 | for values %{delete $self->{refresh_hook}}; |
3091 | } |
3104 | } |
3092 | |
3105 | |
3093 | if ($self->{check_size}) { |
3106 | if ($self->{realloc}) { |
3094 | my @queue; |
3107 | my @queue; |
3095 | |
3108 | |
3096 | for (;;) { |
3109 | while () { |
3097 | if ($self->{check_size}) { |
3110 | if ($self->{realloc}) { |
3098 | #TODO use array-of-depth approach |
3111 | #TODO use array-of-depth approach |
3099 | |
3112 | |
3100 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3113 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3101 | @queue, values %{delete $self->{check_size}}; |
3114 | @queue, values %{delete $self->{realloc}}; |
3102 | } |
3115 | } |
3103 | |
3116 | |
3104 | my $widget = pop @queue || last; |
3117 | my $widget = pop @queue || last; |
3105 | |
3118 | |
3106 | defined $widget->{visible} or last; # do not resize invisible widgets |
3119 | $widget->{visible} or last; # do not resize invisible widgets |
3107 | |
3120 | |
3108 | my ($w, $h) = $widget->{def_w} && $widget->{def_h} |
3121 | my ($w, $h) = $widget->{def_w} && $widget->{def_h} |
3109 | ? @$widget{qw(def_w def_h)} |
3122 | ? @$widget{qw(def_w def_h)} |
3110 | : $widget->size_request; |
3123 | : $widget->size_request; |
3111 | |
3124 | |
3112 | if (delete $widget->{force_alloc} |
|
|
3113 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
|
|
3114 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3125 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3115 | |
3126 | |
3116 | $widget->{req_w} = $w; |
3127 | $widget->{req_w} = $w; |
3117 | $widget->{req_h} = $h; |
3128 | $widget->{req_h} = $h; |
3118 | |
3129 | |
3119 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
3130 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
3120 | |
3131 | |
3121 | $widget->{parent}->check_size |
3132 | push @queue, $widget->{parent} |
3122 | if $widget->{parent}; |
3133 | if $widget->{parent}; |
3123 | } |
|
|
3124 | } |
3134 | } |
3125 | } |
3135 | } |
3126 | |
3136 | |
3127 | while ($self->{size_alloc}) { |
3137 | while (my $size_alloc = delete $self->{size_alloc}) { |
3128 | for (values %{delete $self->{size_alloc}}) { |
3138 | my @queue = sort $b->[0]{visible} <=> $a->[0]{visible}, |
3129 | my ($widget, $w, $h) = @$_; |
3139 | values %$size_alloc; |
|
|
3140 | |
|
|
3141 | while () { |
|
|
3142 | my ($widget, $w, $h) = @{ pop @queue or last }; |
3130 | |
3143 | |
3131 | $w = 0 if $w < 0; |
3144 | $w = 0 if $w < 0; |
3132 | $h = 0 if $h < 0; |
3145 | $h = 0 if $h < 0; |
3133 | |
3146 | |
|
|
3147 | my $changed = $widget->{w} != $w || $widget->{h} != $h; |
|
|
3148 | |
3134 | $widget->{w} = $w; |
3149 | $widget->{w} = $w; |
3135 | $widget->{h} = $h; |
3150 | $widget->{h} = $h; |
|
|
3151 | |
3136 | $widget->emit (size_allocate => $w, $h); |
3152 | $widget->emit (size_allocate => $w, $h, $changed); |
3137 | } |
3153 | } |
3138 | } |
3154 | } |
3139 | |
3155 | |
3140 | while ($self->{post_alloc_hook}) { |
3156 | while ($self->{post_alloc_hook}) { |
3141 | $_->() |
3157 | $_->() |