… | |
… | |
646 | my ($self) = @_; |
646 | my ($self) = @_; |
647 | |
647 | |
648 | warn "no draw defined for $self\n"; |
648 | warn "no draw defined for $self\n"; |
649 | } |
649 | } |
650 | |
650 | |
651 | my $cntx;#d# |
|
|
652 | sub DESTROY { |
651 | sub DESTROY { |
653 | my ($self) = @_; |
652 | my ($self) = @_; |
654 | |
653 | |
655 | return if CFPlus::in_destruct; |
654 | return if CFPlus::in_destruct; |
656 | |
655 | |
… | |
… | |
741 | can_events => 0, |
740 | can_events => 0, |
742 | %arg, |
741 | %arg, |
743 | ); |
742 | ); |
744 | |
743 | |
745 | $self->add (@$children) |
744 | $self->add (@$children) |
746 | if $children; |
745 | if $children && @$children; |
747 | |
746 | |
748 | $self |
747 | $self |
749 | } |
748 | } |
750 | |
749 | |
751 | sub realloc { |
750 | sub realloc { |
… | |
… | |
760 | my ($self, @widgets) = @_; |
759 | my ($self, @widgets) = @_; |
761 | |
760 | |
762 | $_->set_parent ($self) |
761 | $_->set_parent ($self) |
763 | for @widgets; |
762 | for @widgets; |
764 | |
763 | |
|
|
764 | # TODO: only do this in widgets that need it, e.g. root, fixed |
765 | use sort 'stable'; |
765 | use sort 'stable'; |
766 | |
766 | |
767 | $self->{children} = [ |
767 | $self->{children} = [ |
768 | sort { $a->{z} <=> $b->{z} } |
768 | sort { $a->{z} <=> $b->{z} } |
769 | @{$self->{children}}, @widgets |
769 | @{$self->{children}}, @widgets |
770 | ]; |
770 | ]; |
771 | |
771 | |
772 | $self->realloc; |
772 | $self->realloc; |
|
|
773 | |
|
|
774 | map $_+0, @widgets |
773 | } |
775 | } |
774 | |
776 | |
775 | sub children { |
777 | sub children { |
776 | @{ $_[0]{children} } |
778 | @{ $_[0]{children} } |
777 | } |
779 | } |
… | |
… | |
788 | } |
790 | } |
789 | |
791 | |
790 | sub clear { |
792 | sub clear { |
791 | my ($self) = @_; |
793 | my ($self) = @_; |
792 | |
794 | |
793 | my $children = delete $self->{children}; |
795 | my $children = $self->{children}; |
794 | $self->{children} = []; |
796 | $self->{children} = []; |
795 | |
797 | |
796 | for (@$children) { |
798 | for (@$children) { |
797 | delete $_->{parent}; |
799 | delete $_->{parent}; |
798 | $_->hide; |
800 | $_->hide; |
… | |
… | |
958 | sub size_request { |
960 | sub size_request { |
959 | my ($self) = @_; |
961 | my ($self) = @_; |
960 | |
962 | |
961 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
963 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
962 | |
964 | |
963 | $w = 10 if $self->{scroll_x}; |
965 | $w = 1 if $self->{scroll_x}; |
964 | $h = 10 if $self->{scroll_y}; |
966 | $h = 1 if $self->{scroll_y}; |
965 | |
967 | |
966 | ($w, $h) |
968 | ($w, $h) |
967 | } |
969 | } |
968 | |
970 | |
969 | sub invoke_size_allocate { |
971 | sub invoke_size_allocate { |
… | |
… | |
1046 | my $child = delete $arg{child}; |
1048 | my $child = delete $arg{child}; |
1047 | |
1049 | |
1048 | my $self; |
1050 | my $self; |
1049 | |
1051 | |
1050 | my $hslider = new CFPlus::UI::Slider |
1052 | my $hslider = new CFPlus::UI::Slider |
|
|
1053 | col => 0, |
|
|
1054 | row => 1, |
1051 | vertical => 0, |
1055 | vertical => 0, |
1052 | range => [0, 0, 1, 0.01], # HACK fix |
1056 | range => [0, 0, 1, 0.01], # HACK fix |
1053 | on_changed => sub { |
1057 | on_changed => sub { |
1054 | $self->{hpos} = $_[1]; |
1058 | $self->{hpos} = $_[1]; |
1055 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1059 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1056 | }, |
1060 | }, |
1057 | ; |
1061 | ; |
1058 | |
1062 | |
1059 | my $vslider = new CFPlus::UI::Slider |
1063 | my $vslider = new CFPlus::UI::Slider |
|
|
1064 | col => 1, |
|
|
1065 | row => 0, |
1060 | vertical => 1, |
1066 | vertical => 1, |
1061 | range => [0, 0, 1, 0.01], # HACK fix |
1067 | range => [0, 0, 1, 0.01], # HACK fix |
1062 | on_changed => sub { |
1068 | on_changed => sub { |
1063 | $self->{vpos} = $_[1]; |
1069 | $self->{vpos} = $_[1]; |
1064 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1070 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
… | |
… | |
1075 | row_expand => [1, 0], |
1081 | row_expand => [1, 0], |
1076 | %arg, |
1082 | %arg, |
1077 | ); |
1083 | ); |
1078 | |
1084 | |
1079 | $self->{vp} = new CFPlus::UI::ViewPort |
1085 | $self->{vp} = new CFPlus::UI::ViewPort |
|
|
1086 | col => 0, |
|
|
1087 | row => 0, |
1080 | expand => 1, |
1088 | expand => 1, |
1081 | scroll_x => $self->{scroll_x}, |
1089 | scroll_x => $self->{scroll_x}, |
1082 | scroll_y => $self->{scroll_y}, |
1090 | scroll_y => $self->{scroll_y}, |
1083 | on_changed => sub { |
1091 | on_changed => sub { |
1084 | my ($vp, $x, $y) = @_; |
1092 | my ($vp, $x, $y) = @_; |
… | |
… | |
1086 | $vp->{parent}{hslider}->set_value ($x); |
1094 | $vp->{parent}{hslider}->set_value ($x); |
1087 | $vp->{parent}{vslider}->set_value ($y); |
1095 | $vp->{parent}{vslider}->set_value ($y); |
1088 | |
1096 | |
1089 | 0 |
1097 | 0 |
1090 | }, |
1098 | }, |
|
|
1099 | on_size_allocate => sub { |
|
|
1100 | my ($vp, $w, $h) = @_; |
|
|
1101 | $vp->{parent}->update_slider; |
|
|
1102 | 0 |
|
|
1103 | }, |
1091 | ; |
1104 | ; |
1092 | |
1105 | |
1093 | $self->SUPER::add_at (0, 0, $self->{vp}); |
1106 | $self->SUPER::add ($self->{vp}); |
1094 | |
1107 | |
1095 | $self->add ($child) if $child; |
1108 | $self->add ($child) if $child; |
1096 | |
1109 | |
1097 | $self |
1110 | $self |
1098 | } |
1111 | } |
1099 | |
|
|
1100 | #TODO# update range on size_allocate depending on child |
|
|
1101 | |
1112 | |
1102 | sub add { |
1113 | sub add { |
1103 | my ($self, $widget) = @_; |
1114 | my ($self, $widget) = @_; |
1104 | |
1115 | |
1105 | $self->{vp}->add ($self->{child} = $widget); |
1116 | $self->{vp}->add ($self->{child} = $widget); |
… | |
… | |
1108 | sub update_slider { |
1119 | sub update_slider { |
1109 | my ($self) = @_; |
1120 | my ($self) = @_; |
1110 | |
1121 | |
1111 | my $child = ($self->{vp} or return)->child; |
1122 | my $child = ($self->{vp} or return)->child; |
1112 | |
1123 | |
|
|
1124 | if ($self->{scroll_x}) { |
1113 | my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); |
1125 | my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w}); |
1114 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1126 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1115 | |
1127 | |
1116 | my $visible = $w1 > $w2; |
1128 | my $visible = $w1 > $w2; |
1117 | if ($visible != $self->{hslider}{visible}) { |
1129 | if ($visible != $self->{hslider_visible}) { |
|
|
1130 | $self->{hslider_visible} = $visible; |
1118 | $visible ? $self->SUPER::add_at (0, 1, $self->{hslider}) |
1131 | $visible ? $self->SUPER::add ($self->{hslider}) |
1119 | : $self->{hslider}->hide; |
1132 | : $self->SUPER::remove ($self->{hslider}); |
|
|
1133 | } |
1120 | } |
1134 | } |
1121 | |
1135 | |
|
|
1136 | if ($self->{scroll_y}) { |
1122 | my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); |
1137 | my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h}); |
1123 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1138 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1124 | |
1139 | |
1125 | my $visible = $h1 > $h2; |
1140 | my $visible = $h1 > $h2; |
1126 | if ($visible != $self->{vslider}{visible}) { |
1141 | if ($visible != $self->{vslider_visible}) { |
|
|
1142 | $self->{vslider_visible} = $visible; |
1127 | $visible ? $self->SUPER::add_at (1, 0, $self->{vslider}) |
1143 | $visible ? $self->SUPER::add ($self->{vslider}) |
1128 | : $self->{vslider}->hide; |
1144 | : $self->SUPER::remove ($self->{vslider}); |
|
|
1145 | } |
|
|
1146 | } |
|
|
1147 | } |
|
|
1148 | |
|
|
1149 | sub start_dragging { |
|
|
1150 | my ($self, $ev) = @_; |
|
|
1151 | |
|
|
1152 | $self->grab_focus; |
|
|
1153 | |
|
|
1154 | my $ox = $self->{vp}{view_x}; |
|
|
1155 | my $oy = $self->{vp}{view_y}; |
|
|
1156 | |
|
|
1157 | $self->{motion} = sub { |
|
|
1158 | my ($ev, $x, $y) = @_; |
|
|
1159 | |
|
|
1160 | $ox -= $ev->{xrel}; |
|
|
1161 | $oy -= $ev->{yrel}; |
|
|
1162 | |
|
|
1163 | $self->{vp}->set_offset ($ox, $oy); |
1129 | } |
1164 | }; |
1130 | } |
|
|
1131 | |
|
|
1132 | sub update { |
|
|
1133 | my ($self) = @_; |
|
|
1134 | |
|
|
1135 | $self->update_slider; |
|
|
1136 | $self->SUPER::update; |
|
|
1137 | } |
1165 | } |
1138 | |
1166 | |
1139 | sub invoke_mouse_wheel { |
1167 | sub invoke_mouse_wheel { |
1140 | my ($self, $ev) = @_; |
1168 | my ($self, $ev) = @_; |
1141 | |
1169 | |
1142 | $self->{vslider}->emit (mouse_wheel => $ev) |
1170 | $self->{vslider}->emit (mouse_wheel => $ev) if $self->{vslider_visible}; |
1143 | if $ev->{dy}; |
|
|
1144 | |
|
|
1145 | $self->{hslider}->emit (mouse_wheel => $ev) |
1171 | $self->{hslider}->emit (mouse_wheel => $ev) if $self->{hslider_visible}; |
1146 | if $ev->{dx}; |
|
|
1147 | |
1172 | |
1148 | 1 |
1173 | 1 |
1149 | } |
1174 | } |
1150 | |
1175 | |
1151 | sub invoke_button_down { |
1176 | sub invoke_button_down { |
1152 | my ($self, $ev, $x, $y) = @_; |
1177 | my ($self, $ev, $x, $y) = @_; |
1153 | |
1178 | |
1154 | if ($ev->{button} == 2) { |
1179 | if ($ev->{button} == 2) { |
1155 | $self->grab_focus; |
1180 | $self->start_dragging ($ev); |
1156 | |
|
|
1157 | my $ox = $self->{vp}{view_x} + $ev->{x}; |
|
|
1158 | my $oy = $self->{vp}{view_y} + $ev->{y}; |
|
|
1159 | |
|
|
1160 | $self->{motion} = sub { |
|
|
1161 | my ($ev, $x, $y) = @_; |
|
|
1162 | |
|
|
1163 | $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y}); |
|
|
1164 | $self->update; |
|
|
1165 | }; |
|
|
1166 | |
|
|
1167 | return 1; |
1181 | return 1; |
1168 | } |
1182 | } |
1169 | |
1183 | |
1170 | 0 |
1184 | 0 |
1171 | } |
1185 | } |
… | |
… | |
1581 | |
1595 | |
1582 | ############################################################################# |
1596 | ############################################################################# |
1583 | |
1597 | |
1584 | package CFPlus::UI::Table; |
1598 | package CFPlus::UI::Table; |
1585 | |
1599 | |
1586 | our @ISA = CFPlus::UI::Base::; |
1600 | our @ISA = CFPlus::UI::Container::; |
1587 | |
1601 | |
1588 | use List::Util qw(max sum); |
1602 | use List::Util qw(max sum); |
1589 | |
1603 | |
1590 | use CFPlus::OpenGL; |
1604 | use CFPlus::OpenGL; |
1591 | |
1605 | |
1592 | sub new { |
1606 | sub new { |
1593 | my $class = shift; |
1607 | my $class = shift; |
1594 | |
1608 | |
1595 | $class->SUPER::new ( |
1609 | $class->SUPER::new ( |
1596 | children => [], |
|
|
1597 | col_expand => [], |
1610 | col_expand => [], |
1598 | row_expand => [], |
1611 | row_expand => [], |
1599 | @_, |
1612 | @_, |
1600 | ) |
1613 | ) |
1601 | } |
1614 | } |
1602 | |
1615 | |
1603 | sub children { |
|
|
1604 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1605 | } |
|
|
1606 | |
|
|
1607 | # TODO: store row/col info in child widget and use standard add/del |
|
|
1608 | sub add { |
1616 | sub add { |
1609 | my $self = shift; |
1617 | my ($self, @widgets) = @_; |
1610 | |
1618 | |
1611 | Carp::cluck "please use the add_at method instead of calling add, thank you.\n";#d# |
1619 | for my $child (@widgets) { |
1612 | $self->add_at (@_); |
1620 | $child->{rowspan} ||= 1; |
|
|
1621 | $child->{colspan} ||= 1; |
|
|
1622 | } |
|
|
1623 | |
|
|
1624 | $self->SUPER::add (@widgets); |
1613 | } |
1625 | } |
1614 | |
1626 | |
1615 | sub add_at { |
1627 | sub add_at { |
1616 | my $self = shift; |
1628 | my $self = shift; |
1617 | |
1629 | |
|
|
1630 | my @widgets; |
|
|
1631 | |
1618 | while (@_) { |
1632 | while (@_) { |
1619 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1633 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1620 | |
1634 | |
1621 | $child->set_parent ($self); |
1635 | $child->{row} = $row; |
1622 | $self->{children}[$row][$col] = $child; |
1636 | $child->{col} = $col; |
1623 | } |
|
|
1624 | |
1637 | |
1625 | $self->{force_realloc} = 1; |
1638 | push @widgets, $child; |
1626 | $self->{force_size_alloc} = 1; |
1639 | } |
1627 | $self->realloc; |
|
|
1628 | } |
|
|
1629 | |
1640 | |
1630 | sub remove { |
1641 | $self->add (@widgets); |
|
|
1642 | } |
|
|
1643 | |
|
|
1644 | sub get_wh { |
1631 | my ($self, $child) = @_; |
1645 | my ($self) = @_; |
1632 | |
1646 | |
1633 | for (@{ $self->{children} }) { |
1647 | my (@w, @h); |
1634 | for (@{ $_ || [] }) { |
1648 | |
1635 | $_ = undef if $_ == $child; |
1649 | my @children = $self->children; |
|
|
1650 | |
|
|
1651 | # first pass, columns |
|
|
1652 | for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { |
|
|
1653 | my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; |
|
|
1654 | |
|
|
1655 | my $sw = sum @w[$c .. $c + $cs - 1]; |
|
|
1656 | |
|
|
1657 | if ($w > $sw) { |
|
|
1658 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1636 | } |
1659 | } |
1637 | } |
1660 | } |
1638 | } |
|
|
1639 | |
1661 | |
1640 | # TODO: move to container class maybe? send children a signal on removal? |
1662 | # second pass, rows |
1641 | sub clear { |
1663 | for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { |
1642 | my ($self) = @_; |
|
|
1643 | |
|
|
1644 | my @children = $self->children; |
|
|
1645 | delete $self->{children}; |
|
|
1646 | |
|
|
1647 | for (@children) { |
|
|
1648 | delete $_->{parent}; |
|
|
1649 | $_->hide; |
|
|
1650 | } |
|
|
1651 | |
|
|
1652 | $self->realloc; |
|
|
1653 | } |
|
|
1654 | |
|
|
1655 | sub get_wh { |
|
|
1656 | my ($self) = @_; |
|
|
1657 | |
|
|
1658 | my (@w, @h); |
|
|
1659 | |
|
|
1660 | for my $y (0 .. $#{$self->{children}}) { |
|
|
1661 | my $row = $self->{children}[$y] |
|
|
1662 | or next; |
|
|
1663 | |
|
|
1664 | for my $x (0 .. $#$row) { |
|
|
1665 | my $widget = $row->[$x] |
|
|
1666 | or next; |
|
|
1667 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
1664 | my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; |
1668 | |
1665 | |
1669 | $w[$x] = max $w[$x], $w; |
1666 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1670 | $h[$y] = max $h[$y], $h; |
1667 | |
|
|
1668 | if ($h > $sh) { |
|
|
1669 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1671 | } |
1670 | } |
1672 | } |
1671 | } |
1673 | |
1672 | |
1674 | (\@w, \@h) |
1673 | (\@w, \@h) |
1675 | } |
1674 | } |
… | |
… | |
1691 | my ($ws, $hs) = $self->get_wh; |
1690 | my ($ws, $hs) = $self->get_wh; |
1692 | |
1691 | |
1693 | my $req_w = (sum @$ws) || 1; |
1692 | my $req_w = (sum @$ws) || 1; |
1694 | my $req_h = (sum @$hs) || 1; |
1693 | my $req_h = (sum @$hs) || 1; |
1695 | |
1694 | |
1696 | # TODO: nicer code |
1695 | # now linearly scale the rows/columns to the allocated size |
1697 | my @col_expand = @{$self->{col_expand}}; |
1696 | my @col_expand = @{$self->{col_expand}}; |
1698 | @col_expand = (1) x @$ws unless @col_expand; |
1697 | @col_expand = (1) x @$ws unless @col_expand; |
1699 | my $col_expand = (sum @col_expand) || 1; |
1698 | my $col_expand = (sum @col_expand) || 1; |
1700 | |
1699 | |
1701 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1700 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
… | |
… | |
1708 | |
1707 | |
1709 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1708 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1710 | |
1709 | |
1711 | CFPlus::UI::harmonize $hs; |
1710 | CFPlus::UI::harmonize $hs; |
1712 | |
1711 | |
1713 | my $y; |
1712 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
|
|
1713 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1714 | |
1714 | |
1715 | for my $r (0 .. $#{$self->{children}}) { |
1715 | for my $widget ($self->children) { |
1716 | my $row = $self->{children}[$r] |
1716 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1717 | or next; |
|
|
1718 | |
1717 | |
1719 | my $x = 0; |
1718 | $widget->configure ( |
1720 | my $row_h = $hs->[$r]; |
1719 | $x[$c], $y[$r], |
|
|
1720 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1721 | |
1721 | ); |
1722 | for my $c (0 .. $#$row) { |
|
|
1723 | my $col_w = $ws->[$c]; |
|
|
1724 | |
|
|
1725 | if (my $widget = $row->[$c]) { |
|
|
1726 | $widget->configure ($x, $y, $col_w, $row_h); |
|
|
1727 | } |
|
|
1728 | |
|
|
1729 | $x += $col_w; |
|
|
1730 | } |
|
|
1731 | |
|
|
1732 | $y += $row_h; |
|
|
1733 | } |
1722 | } |
1734 | |
1723 | |
1735 | 1 |
1724 | 1 |
1736 | } |
1725 | } |
1737 | |
1726 | |
1738 | sub find_widget { |
|
|
1739 | my ($self, $x, $y) = @_; |
|
|
1740 | |
|
|
1741 | $x -= $self->{x}; |
|
|
1742 | $y -= $self->{y}; |
|
|
1743 | |
|
|
1744 | my $res; |
|
|
1745 | |
|
|
1746 | for (grep $_, map @$_, grep $_, @{ $self->{children} }) { |
|
|
1747 | $res = $_->find_widget ($x, $y) |
|
|
1748 | and return $res; |
|
|
1749 | } |
|
|
1750 | |
|
|
1751 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
|
|
1752 | } |
|
|
1753 | |
|
|
1754 | sub _draw { |
|
|
1755 | my ($self) = @_; |
|
|
1756 | |
|
|
1757 | for (grep $_, @{$self->{children}}) { |
|
|
1758 | $_->draw for grep $_, @$_; |
|
|
1759 | } |
|
|
1760 | } |
|
|
1761 | |
|
|
1762 | ############################################################################# |
1727 | ############################################################################# |
1763 | |
1728 | |
1764 | package CFPlus::UI::Fixed; |
1729 | package CFPlus::UI::Fixed; |
1765 | |
1730 | |
1766 | use List::Util qw(min max); |
1731 | use List::Util qw(min max); |
1767 | |
1732 | |
1768 | our @ISA = CFPlus::UI::Container::; |
1733 | our @ISA = CFPlus::UI::Container::; |
1769 | |
1734 | |
1770 | sub add { |
1735 | sub add_fixed { |
1771 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
1736 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
1772 | |
1737 | |
1773 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
1738 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
1774 | $self->SUPER::add ($child); |
1739 | $self->SUPER::add ($child); |
1775 | } |
1740 | } |
… | |
… | |
1830 | for my $child ($self->visible_children) { |
1795 | for my $child ($self->visible_children) { |
1831 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1796 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1832 | |
1797 | |
1833 | $x = _scale $pos, $x, $W; |
1798 | $x = _scale $pos, $x, $W; |
1834 | $y = _scale $pos, $x, $H; |
1799 | $y = _scale $pos, $x, $H; |
1835 | $w = _scale $size, $w, $child->{req_w}; |
1800 | $w = _scale $size, $w, $W; |
1836 | $h = _scale $size, $h, $child->{req_h}; |
1801 | $h = _scale $size, $h, $H; |
1837 | |
1802 | |
1838 | $child->configure ($x, $y, $w, $h); |
1803 | $child->configure ($x, $y, $w, $h); |
1839 | } |
1804 | } |
1840 | |
1805 | |
1841 | 1 |
1806 | 1 |
… | |
… | |
3575 | my ($self) = @_; |
3540 | my ($self) = @_; |
3576 | |
3541 | |
3577 | if ($::CONN) { |
3542 | if ($::CONN) { |
3578 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3543 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3579 | if (my $tex = $::CONN->{texture}[$faceid]) { |
3544 | if (my $tex = $::CONN->{texture}[$faceid]) { |
|
|
3545 | $self->{tex} = $tex; |
3580 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3546 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3581 | } else { |
3547 | } else { |
3582 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3548 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3583 | $self->realloc; |
3549 | $self->realloc; |
3584 | }); |
3550 | }); |
… | |
… | |
3606 | } |
3572 | } |
3607 | |
3573 | |
3608 | sub _draw { |
3574 | sub _draw { |
3609 | my ($self) = @_; |
3575 | my ($self) = @_; |
3610 | |
3576 | |
3611 | return unless $::CONN; |
|
|
3612 | |
|
|
3613 | $self->SUPER::_draw; |
3577 | $self->SUPER::_draw; |
3614 | |
3578 | |
3615 | my $faceid = $::CONN->{faceid}[$self->{face}] |
3579 | if (my $tex = $self->{tex}) { |
3616 | or return; |
|
|
3617 | |
|
|
3618 | my $tex = $::CONN->{texture}[$faceid]; |
|
|
3619 | |
|
|
3620 | if ($tex) { |
|
|
3621 | glEnable GL_TEXTURE_2D; |
3580 | glEnable GL_TEXTURE_2D; |
3622 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3581 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3623 | glColor 0, 0, 0, 1; |
3582 | glColor 0, 0, 0, 1; |
3624 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3583 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3625 | glDisable GL_TEXTURE_2D; |
3584 | glDisable GL_TEXTURE_2D; |
… | |
… | |
4181 | while ($self->{refresh_hook}) { |
4140 | while ($self->{refresh_hook}) { |
4182 | $_->() |
4141 | $_->() |
4183 | for values %{delete $self->{refresh_hook}}; |
4142 | for values %{delete $self->{refresh_hook}}; |
4184 | } |
4143 | } |
4185 | |
4144 | |
4186 | if ($self->{realloc}) { |
4145 | while ($self->{realloc}) { |
4187 | my %queue; |
4146 | my %queue; |
4188 | my @queue; |
4147 | my @queue; |
4189 | my $widget; |
4148 | my $widget; |
4190 | |
4149 | |
4191 | outer: |
4150 | outer: |
… | |
… | |
4238 | } |
4197 | } |
4239 | } |
4198 | } |
4240 | |
4199 | |
4241 | delete $self->{realloc}{$widget+0}; |
4200 | delete $self->{realloc}{$widget+0}; |
4242 | } |
4201 | } |
4243 | } |
|
|
4244 | |
4202 | |
4245 | while (my $size_alloc = delete $self->{size_alloc}) { |
4203 | while (my $size_alloc = delete $self->{size_alloc}) { |
4246 | my @queue = sort { $b->{visible} <=> $a->{visible} } |
4204 | my @queue = sort { $a->{visible} <=> $b->{visible} } |
4247 | values %$size_alloc; |
4205 | values %$size_alloc; |
4248 | |
4206 | |
4249 | while () { |
4207 | while () { |
4250 | my $widget = pop @queue || last; |
4208 | my $widget = pop @queue || last; |
4251 | |
4209 | |
4252 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4210 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4253 | |
4211 | |
4254 | $w = 0 if $w < 0; |
|
|
4255 | $h = 0 if $h < 0; |
|
|
4256 | |
|
|
4257 | $w = max $widget->{min_w}, $w; |
4212 | $w = max $widget->{min_w}, $w; |
4258 | $h = max $widget->{min_h}, $h; |
4213 | $h = max $widget->{min_h}, $h; |
4259 | |
4214 | |
4260 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4215 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4261 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4216 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4262 | |
4217 | |
4263 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4218 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4264 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4219 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4265 | |
4220 | |
4266 | $w = int $w + 0.5; |
4221 | $w = int $w + 0.5; |
4267 | $h = int $h + 0.5; |
4222 | $h = int $h + 0.5; |
4268 | |
4223 | |
4269 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4224 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4270 | $widget->{old_w} = $widget->{w}; |
4225 | $widget->{old_w} = $widget->{w}; |
4271 | $widget->{old_h} = $widget->{h}; |
4226 | $widget->{old_h} = $widget->{h}; |
4272 | |
4227 | |
4273 | $widget->{w} = $w; |
4228 | $widget->{w} = $w; |
4274 | $widget->{h} = $h; |
4229 | $widget->{h} = $h; |
4275 | |
4230 | |
4276 | $widget->emit (size_allocate => $w, $h); |
4231 | $widget->emit (size_allocate => $w, $h); |
|
|
4232 | } |
4277 | } |
4233 | } |
4278 | } |
4234 | } |
4279 | } |
4235 | } |
4280 | |
4236 | |
4281 | while ($self->{post_alloc_hook}) { |
4237 | while ($self->{post_alloc_hook}) { |