… | |
… | |
593 | |
593 | |
594 | # using global variables seems a bit hacky, but passing through all drawing |
594 | # using global variables seems a bit hacky, but passing through all drawing |
595 | # functions seems pointless. |
595 | # functions seems pointless. |
596 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
596 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
597 | |
597 | |
598 | sub draw { |
598 | #sub draw { |
599 | my ($self) = @_; |
599 | #CFPlus.xs |
600 | |
|
|
601 | return unless $self->{h} && $self->{w}; |
|
|
602 | |
|
|
603 | # update screen rectangle |
|
|
604 | local $draw_x = $draw_x + $self->{x}; |
|
|
605 | local $draw_y = $draw_y + $self->{y}; |
|
|
606 | |
|
|
607 | # skip widgets that are entirely outside the drawing area |
|
|
608 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
|
|
609 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
|
|
610 | |
|
|
611 | glPushMatrix; |
|
|
612 | glTranslate $self->{x}, $self->{y}, 0; |
|
|
613 | |
|
|
614 | if ($self == $HOVER && $self->{can_hover}) { |
|
|
615 | glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2; |
|
|
616 | glEnable GL_BLEND; |
|
|
617 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
618 | glBegin GL_QUADS; |
|
|
619 | glVertex 0 , 0; |
|
|
620 | glVertex $self->{w}, 0; |
|
|
621 | glVertex $self->{w}, $self->{h}; |
|
|
622 | glVertex 0 , $self->{h}; |
|
|
623 | glEnd; |
|
|
624 | glDisable GL_BLEND; |
|
|
625 | } |
|
|
626 | |
|
|
627 | if ($ENV{CFPLUS_DEBUG} & 1) { |
|
|
628 | glPushMatrix; |
|
|
629 | glColor 1, 1, 0, 1; |
|
|
630 | glTranslate 0.375, 0.375; |
|
|
631 | glBegin GL_LINE_LOOP; |
|
|
632 | glVertex 0 , 0; |
|
|
633 | glVertex $self->{w} - 1, 0; |
|
|
634 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
635 | glVertex 0 , $self->{h} - 1; |
|
|
636 | glEnd; |
|
|
637 | glPopMatrix; |
|
|
638 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
639 | } |
|
|
640 | |
|
|
641 | $self->_draw; |
|
|
642 | glPopMatrix; |
|
|
643 | } |
|
|
644 | |
600 | |
645 | sub _draw { |
601 | sub _draw { |
646 | my ($self) = @_; |
602 | my ($self) = @_; |
647 | |
603 | |
648 | warn "no draw defined for $self\n"; |
604 | warn "no draw defined for $self\n"; |
649 | } |
605 | } |
650 | |
606 | |
651 | my $cntx;#d# |
|
|
652 | sub DESTROY { |
607 | sub DESTROY { |
653 | my ($self) = @_; |
608 | my ($self) = @_; |
654 | |
609 | |
655 | return if CFPlus::in_destruct; |
610 | return if CFPlus::in_destruct; |
656 | |
611 | |
… | |
… | |
769 | sort { $a->{z} <=> $b->{z} } |
724 | sort { $a->{z} <=> $b->{z} } |
770 | @{$self->{children}}, @widgets |
725 | @{$self->{children}}, @widgets |
771 | ]; |
726 | ]; |
772 | |
727 | |
773 | $self->realloc; |
728 | $self->realloc; |
|
|
729 | |
|
|
730 | map $_+0, @widgets |
774 | } |
731 | } |
775 | |
732 | |
776 | sub children { |
733 | sub children { |
777 | @{ $_[0]{children} } |
734 | @{ $_[0]{children} } |
778 | } |
735 | } |
… | |
… | |
1093 | $vp->{parent}{hslider}->set_value ($x); |
1050 | $vp->{parent}{hslider}->set_value ($x); |
1094 | $vp->{parent}{vslider}->set_value ($y); |
1051 | $vp->{parent}{vslider}->set_value ($y); |
1095 | |
1052 | |
1096 | 0 |
1053 | 0 |
1097 | }, |
1054 | }, |
|
|
1055 | on_size_allocate => sub { |
|
|
1056 | my ($vp, $w, $h) = @_; |
|
|
1057 | $vp->{parent}->update_slider; |
|
|
1058 | 0 |
|
|
1059 | }, |
1098 | ; |
1060 | ; |
1099 | |
1061 | |
1100 | $self->SUPER::add ($self->{vp}); |
1062 | $self->SUPER::add ($self->{vp}); |
1101 | |
1063 | |
1102 | $self->add ($child) if $child; |
1064 | $self->add ($child) if $child; |
… | |
… | |
1113 | sub update_slider { |
1075 | sub update_slider { |
1114 | my ($self) = @_; |
1076 | my ($self) = @_; |
1115 | |
1077 | |
1116 | my $child = ($self->{vp} or return)->child; |
1078 | my $child = ($self->{vp} or return)->child; |
1117 | |
1079 | |
|
|
1080 | if ($self->{scroll_x}) { |
1118 | my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); |
1081 | my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w}); |
1119 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1082 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1120 | |
1083 | |
1121 | my $visible = $w1 > $w2; |
1084 | my $visible = $w1 > $w2; |
1122 | if ($visible != $self->{hslider_visible}) { |
1085 | if ($visible != $self->{hslider_visible}) { |
1123 | $self->{hslider_visible} = $visible; |
1086 | $self->{hslider_visible} = $visible; |
1124 | $visible ? $self->SUPER::add ($self->{hslider}) |
1087 | $visible ? $self->SUPER::add ($self->{hslider}) |
1125 | : $self->SUPER::remove ($self->{hslider}); |
1088 | : $self->SUPER::remove ($self->{hslider}); |
|
|
1089 | } |
1126 | } |
1090 | } |
1127 | |
1091 | |
|
|
1092 | if ($self->{scroll_y}) { |
1128 | my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); |
1093 | my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h}); |
1129 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1094 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1130 | |
1095 | |
1131 | my $visible = $h1 > $h2; |
1096 | my $visible = $h1 > $h2; |
1132 | if ($visible != $self->{vslider_visible}) { |
1097 | if ($visible != $self->{vslider_visible}) { |
1133 | $self->{vslider_visible} = $visible; |
1098 | $self->{vslider_visible} = $visible; |
1134 | $visible ? $self->SUPER::add ($self->{vslider}) |
1099 | $visible ? $self->SUPER::add ($self->{vslider}) |
1135 | : $self->SUPER::remove ($self->{vslider}); |
1100 | : $self->SUPER::remove ($self->{vslider}); |
|
|
1101 | } |
1136 | } |
1102 | } |
1137 | } |
1103 | } |
1138 | |
1104 | |
1139 | sub start_dragging { |
1105 | sub start_dragging { |
1140 | my ($self, $ev) = @_; |
1106 | my ($self, $ev) = @_; |
… | |
… | |
1720 | |
1686 | |
1721 | use List::Util qw(min max); |
1687 | use List::Util qw(min max); |
1722 | |
1688 | |
1723 | our @ISA = CFPlus::UI::Container::; |
1689 | our @ISA = CFPlus::UI::Container::; |
1724 | |
1690 | |
1725 | sub add { |
|
|
1726 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
|
|
1727 | |
|
|
1728 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
|
|
1729 | $self->SUPER::add ($child); |
|
|
1730 | } |
|
|
1731 | |
|
|
1732 | sub _scale($$$) { |
1691 | sub _scale($$$) { |
1733 | my ($mode, $val, $max) = @_; |
1692 | my ($rel, $val, $max) = @_; |
1734 | |
1693 | |
1735 | $mode eq "abs" ? $val |
1694 | $rel ? $val * $max : $val |
1736 | : $mode eq "rel" ? $val * $max |
|
|
1737 | : 0 |
|
|
1738 | } |
1695 | } |
1739 | |
1696 | |
1740 | sub size_request { |
1697 | sub size_request { |
1741 | my ($self) = @_; |
1698 | my ($self) = @_; |
1742 | |
1699 | |
1743 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1700 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1744 | |
1701 | |
1745 | # determine overall size by querying abs widgets |
1702 | # determine overall size by querying abs widgets |
1746 | for my $child ($self->visible_children) { |
1703 | for my $child ($self->visible_children) { |
1747 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1704 | unless ($child->{c_rel}) { |
|
|
1705 | my $x = $child->{c_x}; |
|
|
1706 | my $y = $child->{c_y}; |
1748 | |
1707 | |
1749 | if ($pos eq "abs") { |
|
|
1750 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1751 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1752 | |
|
|
1753 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1708 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1754 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1709 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1755 | } |
1710 | } |
1756 | } |
1711 | } |
1757 | |
1712 | |
1758 | my $W = $x2 - $x1; |
1713 | my $W = $x2 - $x1; |
1759 | my $H = $y2 - $y1; |
1714 | my $H = $y2 - $y1; |
1760 | |
1715 | |
1761 | # now layout remaining widgets |
1716 | # now layout remaining widgets |
1762 | for my $child ($self->visible_children) { |
1717 | for my $child ($self->visible_children) { |
1763 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1718 | if ($child->{c_rel}) { |
|
|
1719 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1720 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1764 | |
1721 | |
1765 | if ($pos ne "abs") { |
|
|
1766 | $x = _scale $pos, $x, $W; |
|
|
1767 | $y = _scale $pos, $x, $H; |
|
|
1768 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1769 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1770 | |
|
|
1771 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1722 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1772 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1723 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1773 | } |
1724 | } |
1774 | } |
1725 | } |
1775 | |
1726 | |
1776 | my $W = $x2 - $x1; |
1727 | my $W = $x2 - $x1; |
1777 | my $H = $y2 - $y1; |
1728 | my $H = $y2 - $y1; |
… | |
… | |
1781 | |
1732 | |
1782 | sub invoke_size_allocate { |
1733 | sub invoke_size_allocate { |
1783 | my ($self, $W, $H) = @_; |
1734 | my ($self, $W, $H) = @_; |
1784 | |
1735 | |
1785 | for my $child ($self->visible_children) { |
1736 | for my $child ($self->visible_children) { |
1786 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1737 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1738 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1787 | |
1739 | |
1788 | $x = _scale $pos, $x, $W; |
1740 | $x += $child->{c_halign} * $child->{req_w}; |
1789 | $y = _scale $pos, $x, $H; |
1741 | $y += $child->{c_valign} * $child->{req_h}; |
1790 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1791 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1792 | |
1742 | |
1793 | $child->configure ($x, $y, $w, $h); |
1743 | $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h}); |
1794 | } |
1744 | } |
1795 | |
1745 | |
1796 | 1 |
1746 | 1 |
1797 | } |
1747 | } |
1798 | |
1748 | |
… | |
… | |
2061 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2011 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2062 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2012 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2063 | : ($self->{h} - $size->[1]) * 0.5); |
2013 | : ($self->{h} - $size->[1]) * 0.5); |
2064 | }; |
2014 | }; |
2065 | |
2015 | |
2066 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
2016 | # unless ($self->{list}) { |
2067 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
2017 | # $self->{list} = CFPlus::OpenGL::glGenList; |
|
|
2018 | # CFPlus::OpenGL::glNewList $self->{list}; |
|
|
2019 | # $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
|
|
2020 | # CFPlus::OpenGL::glEndList; |
|
|
2021 | # } |
|
|
2022 | # |
|
|
2023 | # CFPlus::OpenGL::glCallList $self->{list}; |
2068 | |
2024 | |
2069 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2025 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2070 | } |
2026 | } |
|
|
2027 | |
|
|
2028 | #sub destroy { |
|
|
2029 | # my ($self) = @_; |
|
|
2030 | # |
|
|
2031 | # CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; |
|
|
2032 | # |
|
|
2033 | # $self->SUPER::destroy; |
|
|
2034 | #} |
2071 | |
2035 | |
2072 | ############################################################################# |
2036 | ############################################################################# |
2073 | |
2037 | |
2074 | package CFPlus::UI::EntryBase; |
2038 | package CFPlus::UI::EntryBase; |
2075 | |
2039 | |
… | |
… | |
2860 | |
2824 | |
2861 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2825 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2862 | |
2826 | |
2863 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2827 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2864 | |
2828 | |
2865 | $self->invoke_mouse_motion ($ev, $x, $y) |
2829 | $self->invoke_mouse_motion ($ev, $x, $y); |
|
|
2830 | |
|
|
2831 | 1 |
2866 | } |
2832 | } |
2867 | |
2833 | |
2868 | sub invoke_mouse_motion { |
2834 | sub invoke_mouse_motion { |
2869 | my ($self, $ev, $x, $y) = @_; |
2835 | my ($self, $ev, $x, $y) = @_; |
2870 | |
2836 | |
… | |
… | |
2890 | |
2856 | |
2891 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2857 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2892 | |
2858 | |
2893 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2859 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2894 | |
2860 | |
2895 | ! ! $delta |
2861 | 1 |
2896 | } |
2862 | } |
2897 | |
2863 | |
2898 | sub update { |
2864 | sub update { |
2899 | my ($self) = @_; |
2865 | my ($self) = @_; |
2900 | |
2866 | |
… | |
… | |
3473 | |
3439 | |
3474 | if ($self->{anim} && $self->{animspeed}) { |
3440 | if ($self->{anim} && $self->{animspeed}) { |
3475 | CFPlus::weaken (my $widget = $self); |
3441 | CFPlus::weaken (my $widget = $self); |
3476 | |
3442 | |
3477 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3443 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3478 | $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; |
3444 | $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; |
3479 | $self->{timer} = Event->timer ( |
3445 | $self->{timer} = Event->timer ( |
3480 | parked => 1, |
3446 | parked => 1, |
3481 | cb => sub { |
3447 | cb => sub { |
3482 | return unless $::CONN && $widget; |
3448 | return unless $::CONN && $widget; |
3483 | |
3449 | |
… | |
… | |
3520 | |
3486 | |
3521 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3487 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3522 | if ($anim && @$anim) { |
3488 | if ($anim && @$anim) { |
3523 | delete $self->{wait_face}; |
3489 | delete $self->{wait_face}; |
3524 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
3490 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3491 | $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]; |
3525 | } |
3492 | } |
3526 | } |
3493 | } |
3527 | } |
3494 | } |
3528 | |
3495 | |
3529 | sub size_request { |
3496 | sub size_request { |
3530 | my ($self) = @_; |
3497 | my ($self) = @_; |
3531 | |
3498 | |
3532 | if ($::CONN) { |
3499 | if ($::CONN) { |
3533 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3500 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3534 | if (my $tex = $::CONN->{texture}[$faceid]) { |
3501 | if (my $tex = $::CONN->{texture}[$faceid]) { |
|
|
3502 | $self->{tex} = $tex; |
3535 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3503 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3536 | } else { |
3504 | } else { |
3537 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3505 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3538 | $self->realloc; |
3506 | $self->realloc; |
3539 | }); |
3507 | }); |
… | |
… | |
3561 | } |
3529 | } |
3562 | |
3530 | |
3563 | sub _draw { |
3531 | sub _draw { |
3564 | my ($self) = @_; |
3532 | my ($self) = @_; |
3565 | |
3533 | |
3566 | return unless $::CONN; |
|
|
3567 | |
|
|
3568 | $self->SUPER::_draw; |
3534 | $self->SUPER::_draw; |
3569 | |
3535 | |
3570 | my $faceid = $::CONN->{faceid}[$self->{face}] |
3536 | if (my $tex = $self->{tex}) { |
3571 | or return; |
|
|
3572 | |
|
|
3573 | my $tex = $::CONN->{texture}[$faceid]; |
|
|
3574 | |
|
|
3575 | if ($tex) { |
|
|
3576 | glEnable GL_TEXTURE_2D; |
3537 | glEnable GL_TEXTURE_2D; |
3577 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3538 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3578 | glColor 0, 0, 0, 1; |
3539 | glColor 0, 0, 0, 1; |
3579 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3540 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3580 | glDisable GL_TEXTURE_2D; |
3541 | glDisable GL_TEXTURE_2D; |
… | |
… | |
3790 | sub add { |
3751 | sub add { |
3791 | my ($self, $title, $widget, $tooltip) = @_; |
3752 | my ($self, $title, $widget, $tooltip) = @_; |
3792 | |
3753 | |
3793 | CFPlus::weaken $self; |
3754 | CFPlus::weaken $self; |
3794 | |
3755 | |
3795 | $self->{buttonbar}->add (new CFPlus::UI::Button |
3756 | unless (ref $title) { |
|
|
3757 | $title = new CFPlus::UI::Button |
3796 | markup => $title, |
3758 | markup => $title, |
3797 | tooltip => $tooltip, |
3759 | tooltip => $tooltip, |
|
|
3760 | ; |
|
|
3761 | } |
|
|
3762 | |
3798 | on_activate => sub { $self->set_current_page ($widget) }, |
3763 | $title->connect (activate => sub { $self->set_current_page ($widget) }); |
3799 | ); |
3764 | $self->{buttonbar}->add ($title); |
3800 | |
3765 | |
3801 | $self->{multiplexer}->add ($widget); |
3766 | $self->{multiplexer}->add ($widget); |
3802 | } |
3767 | } |
3803 | |
3768 | |
3804 | sub get_current_page { |
3769 | sub get_current_page { |
… | |
… | |
4136 | while ($self->{refresh_hook}) { |
4101 | while ($self->{refresh_hook}) { |
4137 | $_->() |
4102 | $_->() |
4138 | for values %{delete $self->{refresh_hook}}; |
4103 | for values %{delete $self->{refresh_hook}}; |
4139 | } |
4104 | } |
4140 | |
4105 | |
4141 | if ($self->{realloc}) { |
4106 | while ($self->{realloc}) { |
4142 | my %queue; |
4107 | my %queue; |
4143 | my @queue; |
4108 | my @queue; |
4144 | my $widget; |
4109 | my $widget; |
4145 | |
4110 | |
4146 | outer: |
4111 | outer: |
… | |
… | |
4193 | } |
4158 | } |
4194 | } |
4159 | } |
4195 | |
4160 | |
4196 | delete $self->{realloc}{$widget+0}; |
4161 | delete $self->{realloc}{$widget+0}; |
4197 | } |
4162 | } |
4198 | } |
|
|
4199 | |
4163 | |
4200 | while (my $size_alloc = delete $self->{size_alloc}) { |
4164 | while (my $size_alloc = delete $self->{size_alloc}) { |
4201 | my @queue = sort { $b->{visible} <=> $a->{visible} } |
4165 | my @queue = sort { $a->{visible} <=> $b->{visible} } |
4202 | values %$size_alloc; |
4166 | values %$size_alloc; |
4203 | |
4167 | |
4204 | while () { |
4168 | while () { |
4205 | my $widget = pop @queue || last; |
4169 | my $widget = pop @queue || last; |
4206 | |
4170 | |
4207 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4171 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4208 | |
4172 | |
4209 | $w = 0 if $w < 0; |
|
|
4210 | $h = 0 if $h < 0; |
|
|
4211 | |
|
|
4212 | $w = max $widget->{min_w}, $w; |
4173 | $w = max $widget->{min_w}, $w; |
4213 | $h = max $widget->{min_h}, $h; |
4174 | $h = max $widget->{min_h}, $h; |
4214 | |
4175 | |
4215 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4176 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4216 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4177 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4217 | |
4178 | |
4218 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4179 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4219 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4180 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4220 | |
4181 | |
4221 | $w = int $w + 0.5; |
4182 | $w = int $w + 0.5; |
4222 | $h = int $h + 0.5; |
4183 | $h = int $h + 0.5; |
4223 | |
4184 | |
4224 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4185 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4225 | $widget->{old_w} = $widget->{w}; |
4186 | $widget->{old_w} = $widget->{w}; |
4226 | $widget->{old_h} = $widget->{h}; |
4187 | $widget->{old_h} = $widget->{h}; |
4227 | |
4188 | |
4228 | $widget->{w} = $w; |
4189 | $widget->{w} = $w; |
4229 | $widget->{h} = $h; |
4190 | $widget->{h} = $h; |
4230 | |
4191 | |
4231 | $widget->emit (size_allocate => $w, $h); |
4192 | $widget->emit (size_allocate => $w, $h); |
|
|
4193 | } |
4232 | } |
4194 | } |
4233 | } |
4195 | } |
4234 | } |
4196 | } |
4235 | |
4197 | |
4236 | while ($self->{post_alloc_hook}) { |
4198 | while ($self->{post_alloc_hook}) { |