… | |
… | |
55 | |
55 | |
56 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) |
56 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) |
57 | if $x + $TOOLTIP->{w} > $::WIDTH; |
57 | if $x + $TOOLTIP->{w} > $::WIDTH; |
58 | |
58 | |
59 | $TOOLTIP->move ($x, $y); |
59 | $TOOLTIP->move ($x, $y); |
60 | $TOOLTIP->check_size; |
|
|
61 | $TOOLTIP->update; |
60 | $TOOLTIP->realloc; |
62 | } |
61 | } |
63 | |
62 | |
64 | return; |
63 | return; |
65 | } |
64 | } |
66 | } |
65 | } |
… | |
… | |
257 | |
256 | |
258 | $self->{root} = $self->{parent}{root}; |
257 | $self->{root} = $self->{parent}{root}; |
259 | $self->{visible} = $self->{parent}{visible} + 1; |
258 | $self->{visible} = $self->{parent}{visible} + 1; |
260 | |
259 | |
261 | $self->emit (visibility_change => 1); |
260 | $self->emit (visibility_change => 1); |
|
|
261 | |
|
|
262 | $self->realloc unless exists $self->{req_w}; |
|
|
263 | |
|
|
264 | $_->set_visible for $self->children; |
262 | } |
265 | } |
263 | |
266 | |
264 | sub set_invisible { |
267 | sub set_invisible { |
265 | my ($self) = @_; |
268 | my ($self) = @_; |
266 | |
269 | |
267 | return unless $self->{visible}; |
270 | return unless $self->{visible}; |
268 | |
271 | |
269 | # broken show/hide model |
272 | $_->set_invisible for $self->children; |
270 | |
273 | |
271 | delete $self->{root}; |
274 | delete $self->{root}; |
272 | delete $self->{visible}; |
275 | delete $self->{visible}; |
273 | |
276 | |
274 | undef $GRAB if $GRAB == $self; |
277 | undef $GRAB if $GRAB == $self; |
275 | undef $HOVER if $HOVER == $self; |
278 | undef $HOVER if $HOVER == $self; |
276 | |
279 | |
277 | CFClient::UI::check_tooltip |
280 | CFClient::UI::check_tooltip |
278 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
281 | if $TOOLTIP->{owner} == $self; |
279 | |
282 | |
280 | $self->focus_out; |
283 | $self->focus_out; |
281 | |
284 | |
282 | $self->emit (visibility_change => 0); |
285 | $self->emit (visibility_change => 0); |
283 | } |
286 | } |
… | |
… | |
322 | my ($self, $w, $h) = @_; |
325 | my ($self, $w, $h) = @_; |
323 | |
326 | |
324 | $self->{def_w} = $w; |
327 | $self->{def_w} = $w; |
325 | $self->{def_h} = $h; |
328 | $self->{def_h} = $h; |
326 | |
329 | |
327 | $self->check_size; |
330 | $self->realloc; |
328 | } |
331 | } |
329 | |
332 | |
330 | sub size_request { |
333 | sub size_request { |
331 | require Carp; |
334 | require Carp; |
332 | Carp::confess "size_request is abstract"; |
335 | Carp::confess "size_request is abstract"; |
… | |
… | |
352 | $self->{y} = $y; |
355 | $self->{y} = $y; |
353 | $self->update; |
356 | $self->update; |
354 | } |
357 | } |
355 | |
358 | |
356 | if ($self->{w} != $w || $self->{h} != $h) { |
359 | if ($self->{w} != $w || $self->{h} != $h) { |
|
|
360 | return unless $self->{visible}; |
|
|
361 | |
357 | $CFClient::UI::ROOT->{size_alloc}{$self+0} = [$self, $w, $h]; |
362 | $self->{root}->{size_alloc}{$self+0} = [$self, $w, $h]; |
358 | } |
363 | } |
359 | } |
364 | } |
360 | |
365 | |
361 | sub size_allocate { |
366 | sub size_allocate { |
362 | # nothing to be done |
367 | # nothing to be done |
363 | } |
|
|
364 | |
|
|
365 | sub reconfigure { |
|
|
366 | my ($self) = @_; |
|
|
367 | |
|
|
368 | $self->check_size (1); |
|
|
369 | $self->update; |
|
|
370 | } |
368 | } |
371 | |
369 | |
372 | sub children { |
370 | sub children { |
373 | } |
371 | } |
374 | |
372 | |
… | |
… | |
452 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
450 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
453 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
451 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
454 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
452 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
455 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
453 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
456 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
454 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
|
|
455 | |
|
|
456 | sub find_widget { |
|
|
457 | my ($self, $x, $y) = @_; |
|
|
458 | |
|
|
459 | return () unless $self->{can_events}; |
|
|
460 | |
|
|
461 | return $self |
|
|
462 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
463 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
464 | |
|
|
465 | () |
|
|
466 | } |
|
|
467 | |
|
|
468 | sub set_parent { |
|
|
469 | my ($self, $parent) = @_; |
|
|
470 | |
|
|
471 | Scalar::Util::weaken ($self->{parent} = $parent); |
|
|
472 | |
|
|
473 | $self->set_visible if $parent->{visible}; |
|
|
474 | |
|
|
475 | $self->realloc; |
|
|
476 | } |
|
|
477 | |
|
|
478 | sub connect { |
|
|
479 | my ($self, $signal, $cb) = @_; |
|
|
480 | |
|
|
481 | push @{ $self->{signal_cb}{$signal} }, $cb; |
|
|
482 | } |
|
|
483 | |
|
|
484 | sub _emit { |
|
|
485 | my ($self, $signal, @args) = @_; |
|
|
486 | |
|
|
487 | List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} |
|
|
488 | } |
|
|
489 | |
|
|
490 | sub emit { |
|
|
491 | my ($self, $signal, @args) = @_; |
|
|
492 | |
|
|
493 | $self->_emit ($signal, @args) |
|
|
494 | || $self->$signal (@args); |
|
|
495 | } |
|
|
496 | |
|
|
497 | sub visibility_change { |
|
|
498 | #my ($self, $visible) = @_; |
|
|
499 | } |
|
|
500 | |
|
|
501 | sub realloc { |
|
|
502 | my ($self) = @_; |
|
|
503 | |
|
|
504 | return unless $self->{visible}; |
|
|
505 | |
|
|
506 | return if $self->{root}{realloc}{$self}; |
|
|
507 | |
|
|
508 | $self->{root}{realloc}{$self} = $self; |
|
|
509 | $self->{root}->update; |
|
|
510 | } |
|
|
511 | |
|
|
512 | sub update { |
|
|
513 | my ($self) = @_; |
|
|
514 | |
|
|
515 | $self->{parent}->update |
|
|
516 | if $self->{parent}; |
|
|
517 | } |
457 | |
518 | |
458 | sub draw { |
519 | sub draw { |
459 | my ($self) = @_; |
520 | my ($self) = @_; |
460 | |
521 | |
461 | return unless $self->{h} && $self->{w}; |
522 | return unless $self->{h} && $self->{w}; |
… | |
… | |
499 | my ($self) = @_; |
560 | my ($self) = @_; |
500 | |
561 | |
501 | warn "no draw defined for $self\n"; |
562 | warn "no draw defined for $self\n"; |
502 | } |
563 | } |
503 | |
564 | |
504 | sub find_widget { |
|
|
505 | my ($self, $x, $y) = @_; |
|
|
506 | |
|
|
507 | return () unless $self->{can_events}; |
|
|
508 | |
|
|
509 | return $self |
|
|
510 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
511 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
512 | |
|
|
513 | () |
|
|
514 | } |
|
|
515 | |
|
|
516 | sub set_parent { |
|
|
517 | my ($self, $parent) = @_; |
|
|
518 | |
|
|
519 | Scalar::Util::weaken ($self->{parent} = $parent); |
|
|
520 | |
|
|
521 | $self->set_visible; #TODO why breakssssss borked damn if $parent->{visible}; |
|
|
522 | |
|
|
523 | $self->check_size; |
|
|
524 | } |
|
|
525 | |
|
|
526 | sub check_size { |
|
|
527 | my ($self, $forced) = @_; |
|
|
528 | |
|
|
529 | $self->{force_alloc} = 1 if $forced; |
|
|
530 | $CFClient::UI::ROOT->{check_size}{$self} = $self; |
|
|
531 | } |
|
|
532 | |
|
|
533 | sub update { |
|
|
534 | my ($self) = @_; |
|
|
535 | |
|
|
536 | $self->{parent}->update |
|
|
537 | if $self->{parent}; |
|
|
538 | } |
|
|
539 | |
|
|
540 | sub connect { |
|
|
541 | my ($self, $signal, $cb) = @_; |
|
|
542 | |
|
|
543 | push @{ $self->{signal_cb}{$signal} }, $cb; |
|
|
544 | } |
|
|
545 | |
|
|
546 | sub _emit { |
|
|
547 | my ($self, $signal, @args) = @_; |
|
|
548 | |
|
|
549 | List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} |
|
|
550 | } |
|
|
551 | |
|
|
552 | sub emit { |
|
|
553 | my ($self, $signal, @args) = @_; |
|
|
554 | |
|
|
555 | $self->_emit ($signal, @args) |
|
|
556 | || $self->$signal (@args); |
|
|
557 | } |
|
|
558 | |
|
|
559 | sub visibility_change { |
|
|
560 | #my ($self, $visible) = @_; |
|
|
561 | } |
|
|
562 | |
|
|
563 | sub DESTROY { |
565 | sub DESTROY { |
564 | my ($self) = @_; |
566 | my ($self) = @_; |
565 | |
567 | |
566 | delete $WIDGET{$self+0}; |
568 | delete $WIDGET{$self+0}; |
567 | #$self->deactivate; |
569 | #$self->deactivate; |
… | |
… | |
662 | $self->{children} = [ |
664 | $self->{children} = [ |
663 | sort { $a->{z} <=> $b->{z} } |
665 | sort { $a->{z} <=> $b->{z} } |
664 | @{$self->{children}}, @widgets |
666 | @{$self->{children}}, @widgets |
665 | ]; |
667 | ]; |
666 | |
668 | |
667 | $self->check_size (1); |
669 | $self->realloc; |
668 | $self->update; |
|
|
669 | } |
670 | } |
670 | |
671 | |
671 | sub children { |
672 | sub children { |
672 | @{ $_[0]{children} } |
673 | @{ $_[0]{children} } |
673 | } |
674 | } |
… | |
… | |
678 | delete $child->{parent}; |
679 | delete $child->{parent}; |
679 | $child->hide; |
680 | $child->hide; |
680 | |
681 | |
681 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
682 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
682 | |
683 | |
683 | $self->check_size (1); |
684 | $self->realloc; |
684 | $self->update; |
|
|
685 | } |
685 | } |
686 | |
686 | |
687 | sub clear { |
687 | sub clear { |
688 | my ($self) = @_; |
688 | my ($self) = @_; |
689 | |
689 | |
… | |
… | |
693 | for (@$children) { |
693 | for (@$children) { |
694 | delete $_->{parent}; |
694 | delete $_->{parent}; |
695 | $_->hide; |
695 | $_->hide; |
696 | } |
696 | } |
697 | |
697 | |
698 | $self->check_size; |
698 | $self->realloc; |
699 | $self->update; |
|
|
700 | } |
699 | } |
701 | |
700 | |
702 | sub find_widget { |
701 | sub find_widget { |
703 | my ($self, $x, $y) = @_; |
702 | my ($self, $x, $y) = @_; |
704 | |
703 | |
… | |
… | |
757 | sub size_request { |
756 | sub size_request { |
758 | $_[0]{children}[0]->size_request |
757 | $_[0]{children}[0]->size_request |
759 | } |
758 | } |
760 | |
759 | |
761 | sub size_allocate { |
760 | sub size_allocate { |
762 | my ($self, $w, $h) = @_; |
761 | my ($self, $w, $h, $changed) = @_; |
763 | |
762 | |
764 | $self->{children}[0]->configure (0, 0, $w, $h); |
763 | $self->{children}[0]->configure (0, 0, $w, $h); |
765 | } |
764 | } |
766 | |
765 | |
767 | ############################################################################# |
766 | ############################################################################# |
… | |
… | |
784 | $ROOT->on_post_alloc ($self => sub { $self->render_child }); |
783 | $ROOT->on_post_alloc ($self => sub { $self->render_child }); |
785 | $self->SUPER::update; |
784 | $self->SUPER::update; |
786 | } |
785 | } |
787 | |
786 | |
788 | sub size_allocate { |
787 | sub size_allocate { |
789 | my ($self, $w, $h) = @_; |
788 | my ($self, $w, $h, $changed) = @_; |
790 | |
789 | |
791 | $self->SUPER::size_allocate ($w, $h); |
790 | $self->SUPER::size_allocate ($w, $h, $changed); |
792 | $self->update; |
791 | $self->update |
|
|
792 | if $changed; |
793 | } |
793 | } |
794 | |
794 | |
795 | sub _render { |
795 | sub _render { |
796 | $_[0]{children}[0]->draw; |
796 | $_[0]{children}[0]->draw; |
797 | } |
797 | } |
… | |
… | |
850 | |
850 | |
851 | ($w, $h) |
851 | ($w, $h) |
852 | } |
852 | } |
853 | |
853 | |
854 | sub size_allocate { |
854 | sub size_allocate { |
855 | my ($self, $w, $h) = @_; |
855 | my ($self, $w, $h, $changed) = @_; |
856 | |
856 | |
857 | $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; |
857 | $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; |
858 | $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; |
858 | $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; |
859 | |
859 | |
860 | $self->child->configure (0, 0, $w, $h); |
860 | $self->child->configure (0, 0, $w, $h); |
… | |
… | |
947 | my $child = $self->{vp}->child; |
947 | my $child = $self->{vp}->child; |
948 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
948 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
949 | } |
949 | } |
950 | |
950 | |
951 | sub size_allocate { |
951 | sub size_allocate { |
952 | my ($self, $w, $h) = @_; |
952 | my ($self, $w, $h, $changed) = @_; |
953 | |
953 | |
954 | $self->SUPER::size_allocate ($w, $h); |
954 | $self->SUPER::size_allocate ($w, $h, $changed); |
955 | |
955 | |
956 | my $child = $self->{vp}->child; |
956 | my $child = $self->{vp}->child; |
957 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
957 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
958 | } |
958 | } |
959 | |
959 | |
… | |
… | |
1047 | $h + $self->border * 2, |
1047 | $h + $self->border * 2, |
1048 | ) |
1048 | ) |
1049 | } |
1049 | } |
1050 | |
1050 | |
1051 | sub size_allocate { |
1051 | sub size_allocate { |
1052 | my ($self, $w, $h) = @_; |
1052 | my ($self, $w, $h, $changed) = @_; |
|
|
1053 | |
|
|
1054 | return unless $changed; |
1053 | |
1055 | |
1054 | $h -= List::Util::max 0, $self->border * 2; |
1056 | $h -= List::Util::max 0, $self->border * 2; |
1055 | $w -= List::Util::max 0, $self->border * 2; |
1057 | $w -= List::Util::max 0, $self->border * 2; |
1056 | |
1058 | |
1057 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
1059 | $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) |
… | |
… | |
1086 | $self->{user_x} = $wx + $dx * $mx; |
1088 | $self->{user_x} = $wx + $dx * $mx; |
1087 | $self->{user_y} = $wy + $dy * $my; |
1089 | $self->{user_y} = $wy + $dy * $my; |
1088 | $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); |
1090 | $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); |
1089 | $self->{def_h} = $bh + $dy * ($my ? -1 : 1); |
1091 | $self->{def_h} = $bh + $dy * ($my ? -1 : 1); |
1090 | $self->move ($self->{user_x}, $self->{user_y}); |
1092 | $self->move ($self->{user_x}, $self->{user_y}); |
1091 | $self->check_size; |
1093 | $self->realloc; |
1092 | }; |
1094 | }; |
1093 | |
1095 | |
1094 | } elsif ($lr ^ $td) { |
1096 | } elsif ($lr ^ $td) { |
1095 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1097 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1096 | my ($bx, $by) = ($self->{x}, $self->{y}); |
1098 | my ($bx, $by) = ($self->{x}, $self->{y}); |
… | |
… | |
1102 | |
1104 | |
1103 | $self->{user_x} = $bx + $x - $ox; |
1105 | $self->{user_x} = $bx + $x - $ox; |
1104 | $self->{user_y} = $by + $y - $oy; |
1106 | $self->{user_y} = $by + $y - $oy; |
1105 | |
1107 | |
1106 | $self->move ($self->{user_x}, $self->{user_y}); |
1108 | $self->move ($self->{user_x}, $self->{user_y}); |
1107 | $self->update; |
1109 | $self->realloc; |
1108 | }; |
1110 | }; |
1109 | } |
1111 | } |
1110 | } |
1112 | } |
1111 | |
1113 | |
1112 | sub button_up { |
1114 | sub button_up { |
… | |
… | |
1187 | my ($self, $x, $y, $child) = @_; |
1189 | my ($self, $x, $y, $child) = @_; |
1188 | |
1190 | |
1189 | $child->set_parent ($self); |
1191 | $child->set_parent ($self); |
1190 | $self->{children}[$y][$x] = $child; |
1192 | $self->{children}[$y][$x] = $child; |
1191 | |
1193 | |
1192 | $self->check_size (1); |
1194 | $self->realloc; |
1193 | } |
1195 | } |
1194 | |
1196 | |
1195 | # TODO: move to container class maybe? send children a signal on removal? |
1197 | # TODO: move to container class maybe? send children a signal on removal? |
1196 | sub clear { |
1198 | sub clear { |
1197 | my ($self) = @_; |
1199 | my ($self) = @_; |
… | |
… | |
1202 | for (@children) { |
1204 | for (@children) { |
1203 | delete $_->{parent}; |
1205 | delete $_->{parent}; |
1204 | $_->hide; |
1206 | $_->hide; |
1205 | } |
1207 | } |
1206 | |
1208 | |
1207 | $self->check_size (1); |
1209 | $self->realloc; |
1208 | $self->update; |
|
|
1209 | } |
1210 | } |
1210 | |
1211 | |
1211 | sub get_wh { |
1212 | sub get_wh { |
1212 | my ($self) = @_; |
1213 | my ($self) = @_; |
1213 | |
1214 | |
… | |
… | |
1240 | (sum @$hs), |
1241 | (sum @$hs), |
1241 | ) |
1242 | ) |
1242 | } |
1243 | } |
1243 | |
1244 | |
1244 | sub size_allocate { |
1245 | sub size_allocate { |
1245 | my ($self, $w, $h) = @_; |
1246 | my ($self, $w, $h, $changed) = @_; |
1246 | |
1247 | |
1247 | my ($ws, $hs) = $self->get_wh; |
1248 | my ($ws, $hs) = $self->get_wh; |
1248 | |
1249 | |
1249 | my $req_w = (sum @$ws) || 1; |
1250 | my $req_w = (sum @$ws) || 1; |
1250 | my $req_h = (sum @$hs) || 1; |
1251 | my $req_h = (sum @$hs) || 1; |
… | |
… | |
1328 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1329 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1329 | ) |
1330 | ) |
1330 | } |
1331 | } |
1331 | |
1332 | |
1332 | sub size_allocate { |
1333 | sub size_allocate { |
1333 | my ($self, $w, $h) = @_; |
1334 | my ($self, $w, $h, $changed) = @_; |
1334 | |
1335 | |
1335 | my $space = $self->{vertical} ? $h : $w; |
1336 | my $space = $self->{vertical} ? $h : $w; |
1336 | my $children = $self->{children}; |
1337 | my $children = $self->{children}; |
1337 | |
1338 | |
1338 | my @req; |
1339 | my @req; |
… | |
… | |
1467 | $self->{text} = "T$text"; |
1468 | $self->{text} = "T$text"; |
1468 | |
1469 | |
1469 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1470 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1470 | $self->{layout}->set_text ($text); |
1471 | $self->{layout}->set_text ($text); |
1471 | |
1472 | |
1472 | $self->update; |
1473 | $self->realloc; |
1473 | $self->check_size; |
|
|
1474 | } |
1474 | } |
1475 | |
1475 | |
1476 | sub set_markup { |
1476 | sub set_markup { |
1477 | my ($self, $markup) = @_; |
1477 | my ($self, $markup) = @_; |
1478 | |
1478 | |
… | |
… | |
1482 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1482 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
1483 | |
1483 | |
1484 | $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; |
1485 | $self->{layout}->set_markup ($markup); |
1485 | $self->{layout}->set_markup ($markup); |
1486 | |
1486 | |
1487 | $self->update; |
1487 | $self->realloc; |
1488 | $self->check_size; |
|
|
1489 | } |
1488 | } |
1490 | |
1489 | |
1491 | sub size_request { |
1490 | sub size_request { |
1492 | my ($self) = @_; |
1491 | my ($self) = @_; |
1493 | |
1492 | |
… | |
… | |
1514 | $h + $self->{padding} * 2, |
1513 | $h + $self->{padding} * 2, |
1515 | ) |
1514 | ) |
1516 | } |
1515 | } |
1517 | |
1516 | |
1518 | sub size_allocate { |
1517 | sub size_allocate { |
1519 | my ($self, $w, $h) = @_; |
1518 | my ($self, $w, $h, $changed) = @_; |
1520 | |
1519 | |
1521 | delete $self->{texture}; |
1520 | delete $self->{texture} |
|
|
1521 | if $changed; |
1522 | } |
1522 | } |
1523 | |
1523 | |
1524 | sub set_fontsize { |
1524 | sub set_fontsize { |
1525 | my ($self, $fontsize) = @_; |
1525 | my ($self, $fontsize) = @_; |
1526 | |
1526 | |
1527 | $self->{fontsize} = $fontsize; |
1527 | $self->{fontsize} = $fontsize; |
1528 | delete $self->{texture}; |
1528 | delete $self->{texture}; |
1529 | |
1529 | |
1530 | $self->update; |
1530 | $self->realloc; |
1531 | $self->check_size; |
|
|
1532 | } |
1531 | } |
1533 | |
1532 | |
1534 | sub _draw { |
1533 | sub _draw { |
1535 | my ($self) = @_; |
1534 | my ($self) = @_; |
1536 | |
1535 | |
… | |
… | |
1616 | sub set_text { |
1615 | sub set_text { |
1617 | my ($self, $text) = @_; |
1616 | my ($self, $text) = @_; |
1618 | |
1617 | |
1619 | $self->{cursor} = length $text; |
1618 | $self->{cursor} = length $text; |
1620 | $self->_set_text ($text); |
1619 | $self->_set_text ($text); |
1621 | $self->update; |
1620 | |
1622 | $self->check_size; |
1621 | $self->realloc; |
1623 | } |
1622 | } |
1624 | |
1623 | |
1625 | sub get_text { |
1624 | sub get_text { |
1626 | $_[0]{text} |
1625 | $_[0]{text} |
1627 | } |
1626 | } |
… | |
… | |
1660 | } elsif ($uni) { |
1659 | } elsif ($uni) { |
1661 | substr $text, $self->{cursor}++, 0, chr $uni; |
1660 | substr $text, $self->{cursor}++, 0, chr $uni; |
1662 | } |
1661 | } |
1663 | |
1662 | |
1664 | $self->_set_text ($text); |
1663 | $self->_set_text ($text); |
1665 | $self->update; |
1664 | |
1666 | $self->check_size; |
1665 | $self->realloc; |
1667 | } |
1666 | } |
1668 | |
1667 | |
1669 | sub focus_in { |
1668 | sub focus_in { |
1670 | my ($self) = @_; |
1669 | my ($self) = @_; |
1671 | |
1670 | |
… | |
… | |
2178 | $self->update; |
2177 | $self->update; |
2179 | |
2178 | |
2180 | $self |
2179 | $self |
2181 | } |
2180 | } |
2182 | |
2181 | |
|
|
2182 | sub changed { } |
|
|
2183 | |
2183 | sub set_range { |
2184 | sub set_range { |
2184 | my ($self, $range) = @_; |
2185 | my ($self, $range) = @_; |
2185 | |
2186 | |
2186 | ($range, $self->{range}) = ($self->{range}, $range); |
2187 | ($range, $self->{range}) = ($self->{range}, $range); |
2187 | |
2188 | |
… | |
… | |
2376 | $self->{fontsize} = $fontsize; |
2377 | $self->{fontsize} = $fontsize; |
2377 | $self->reflow; |
2378 | $self->reflow; |
2378 | } |
2379 | } |
2379 | |
2380 | |
2380 | sub size_allocate { |
2381 | sub size_allocate { |
2381 | my ($self, $w, $h) = @_; |
2382 | my ($self, $w, $h, $changed) = @_; |
2382 | |
2383 | |
2383 | $self->SUPER::size_allocate ($w, $h); |
2384 | $self->SUPER::size_allocate ($w, $h, $changed); |
|
|
2385 | |
|
|
2386 | return unless $changed; |
2384 | |
2387 | |
2385 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2388 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2386 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2389 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2387 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2390 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2388 | |
2391 | |
… | |
… | |
2630 | |
2633 | |
2631 | ($w + 4, $h + 4) |
2634 | ($w + 4, $h + 4) |
2632 | } |
2635 | } |
2633 | |
2636 | |
2634 | sub size_allocate { |
2637 | sub size_allocate { |
2635 | my ($self, $w, $h) = @_; |
2638 | my ($self, $w, $h, $changed) = @_; |
2636 | |
2639 | |
|
|
2640 | return unless $changed; |
|
|
2641 | |
2637 | $self->SUPER::size_allocate ($w - 4, $h - 4); |
2642 | $self->SUPER::size_allocate ($w - 4, $h - 4, $changed); |
2638 | } |
2643 | } |
2639 | |
2644 | |
2640 | sub _draw { |
2645 | sub _draw { |
2641 | my ($self) = @_; |
2646 | my ($self) = @_; |
2642 | |
2647 | |
… | |
… | |
2977 | use CFClient::OpenGL; |
2982 | use CFClient::OpenGL; |
2978 | |
2983 | |
2979 | sub new { |
2984 | sub new { |
2980 | my $class = shift; |
2985 | my $class = shift; |
2981 | |
2986 | |
2982 | $class->SUPER::new ( |
2987 | my $self = $class->SUPER::new ( |
2983 | visible => 1, |
2988 | visible => 1, |
2984 | @_, |
2989 | @_, |
2985 | ) |
2990 | ); |
|
|
2991 | |
|
|
2992 | Scalar::Util::weaken ($self->{root} = $self); |
|
|
2993 | |
|
|
2994 | $self |
2986 | } |
2995 | } |
2987 | |
2996 | |
2988 | sub configure { |
2997 | sub configure { |
2989 | my ($self, $x, $y, $w, $h) = @_; |
2998 | my ($self, $x, $y, $w, $h) = @_; |
2990 | |
2999 | |
2991 | $self->{w} = $w; |
3000 | $self->{w} = $w; |
2992 | $self->{h} = $h; |
3001 | $self->{h} = $h; |
2993 | } |
3002 | } |
2994 | |
3003 | |
2995 | sub check_size { |
3004 | sub reconfigure { |
2996 | my ($self) = @_; |
3005 | my ($self) = @_; |
2997 | |
3006 | |
|
|
3007 | $self->SUPER::reconfigure; |
|
|
3008 | |
2998 | $self->size_allocate ($self->{w}, $self->{h}) |
3009 | $self->size_allocate ($self->{w}, $self->{h}, 1) |
2999 | if $self->{w}; |
3010 | if $self->{w}; |
3000 | } |
3011 | } |
3001 | |
3012 | |
3002 | sub size_request { |
3013 | sub size_request { |
3003 | my ($self) = @_; |
3014 | my ($self) = @_; |
3004 | |
3015 | |
3005 | ($self->{w}, $self->{h}) |
3016 | ($self->{w}, $self->{h}) |
3006 | } |
3017 | } |
3007 | |
3018 | |
3008 | sub size_allocate { |
3019 | sub size_allocate { |
3009 | my ($self, $w, $h) = @_; |
3020 | my ($self, $w, $h, $changed) = @_; |
3010 | |
3021 | |
3011 | for my $child ($self->children) { |
3022 | for my $child ($self->children) { |
3012 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
3023 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
3013 | |
3024 | |
3014 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
3025 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
… | |
… | |
3039 | } |
3050 | } |
3040 | |
3051 | |
3041 | sub update { |
3052 | sub update { |
3042 | my ($self) = @_; |
3053 | my ($self) = @_; |
3043 | |
3054 | |
3044 | $self->check_size; |
|
|
3045 | $::WANT_REFRESH++; |
3055 | $::WANT_REFRESH++; |
3046 | } |
3056 | } |
3047 | |
3057 | |
3048 | sub add { |
3058 | sub add { |
3049 | my ($self, @children) = @_; |
3059 | my ($self, @children) = @_; |
… | |
… | |
3055 | $child->{x} = int $child->{x}; |
3065 | $child->{x} = int $child->{x}; |
3056 | $child->{y} = int $child->{y}; |
3066 | $child->{y} = int $child->{y}; |
3057 | } |
3067 | } |
3058 | |
3068 | |
3059 | $self->SUPER::add (@children); |
3069 | $self->SUPER::add (@children); |
3060 | |
|
|
3061 | for (my @widgets = @children; my $w = pop @widgets; ) { |
|
|
3062 | push @widgets, $w->children; |
|
|
3063 | $w->set_visible; |
|
|
3064 | } |
|
|
3065 | |
|
|
3066 | } |
3070 | } |
3067 | |
3071 | |
3068 | sub remove { |
3072 | sub remove { |
3069 | my ($self, @children) = @_; |
3073 | my ($self, @children) = @_; |
3070 | |
3074 | |
… | |
… | |
3095 | while ($self->{refresh_hook}) { |
3099 | while ($self->{refresh_hook}) { |
3096 | $_->() |
3100 | $_->() |
3097 | for values %{delete $self->{refresh_hook}}; |
3101 | for values %{delete $self->{refresh_hook}}; |
3098 | } |
3102 | } |
3099 | |
3103 | |
3100 | if ($self->{check_size}) { |
3104 | if ($self->{realloc}) { |
3101 | my @queue; |
3105 | my @queue; |
3102 | |
3106 | |
3103 | while () { |
3107 | while () { |
3104 | if ($self->{check_size}) { |
3108 | if ($self->{realloc}) { |
3105 | #TODO use array-of-depth approach |
3109 | #TODO use array-of-depth approach |
3106 | |
3110 | |
3107 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3111 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3108 | @queue, values %{delete $self->{check_size}}; |
3112 | @queue, values %{delete $self->{realloc}}; |
3109 | } |
3113 | } |
3110 | |
3114 | |
3111 | my $widget = pop @queue || last; |
3115 | my $widget = pop @queue || last; |
3112 | |
3116 | |
3113 | defined $widget->{visible} or last; # do not resize invisible widgets |
3117 | $widget->{visible} or last; # do not resize invisible widgets |
3114 | |
3118 | |
3115 | my ($w, $h) = $widget->{def_w} && $widget->{def_h} |
3119 | my ($w, $h) = $widget->{def_w} && $widget->{def_h} |
3116 | ? @$widget{qw(def_w def_h)} |
3120 | ? @$widget{qw(def_w def_h)} |
3117 | : $widget->size_request; |
3121 | : $widget->size_request; |
3118 | |
3122 | |
3119 | if (delete $widget->{force_alloc} |
|
|
3120 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
|
|
3121 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3123 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3122 | |
3124 | |
3123 | $widget->{req_w} = $w; |
3125 | $widget->{req_w} = $w; |
3124 | $widget->{req_h} = $h; |
3126 | $widget->{req_h} = $h; |
3125 | |
3127 | |
3126 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
3128 | $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; |
3127 | |
3129 | |
3128 | $widget->{parent}->check_size |
3130 | push @queue, $widget->{parent} |
3129 | if $widget->{parent}; |
3131 | if $widget->{parent}; |
3130 | } |
|
|
3131 | } |
3132 | } |
3132 | } |
3133 | } |
3133 | |
3134 | |
3134 | while (my $size_alloc = delete $self->{size_alloc}) { |
3135 | while (my $size_alloc = delete $self->{size_alloc}) { |
3135 | my @queue = sort $b->[0]{visible} <=> $a->[0]{visible}, |
3136 | my @queue = sort $b->[0]{visible} <=> $a->[0]{visible}, |
… | |
… | |
3141 | $w = 0 if $w < 0; |
3142 | $w = 0 if $w < 0; |
3142 | $h = 0 if $h < 0; |
3143 | $h = 0 if $h < 0; |
3143 | |
3144 | |
3144 | $widget->{w} = $w; |
3145 | $widget->{w} = $w; |
3145 | $widget->{h} = $h; |
3146 | $widget->{h} = $h; |
3146 | $widget->emit (size_allocate => $w, $h); |
3147 | $widget->emit (size_allocate => $w, $h, 1); |
3147 | } |
3148 | } |
3148 | } |
3149 | } |
3149 | |
3150 | |
3150 | while ($self->{post_alloc_hook}) { |
3151 | while ($self->{post_alloc_hook}) { |
3151 | $_->() |
3152 | $_->() |