… | |
… | |
273 | $self->emit ("destroy"); |
273 | $self->emit ("destroy"); |
274 | %$self = (); |
274 | %$self = (); |
275 | } |
275 | } |
276 | |
276 | |
277 | sub TO_JSON { |
277 | sub TO_JSON { |
278 | { __widget_ref__ => $_[0]{s_id} } |
278 | { __w_ => $_[0]{s_id} } |
279 | } |
279 | } |
280 | |
280 | |
281 | sub show { |
281 | sub show { |
282 | my ($self) = @_; |
282 | my ($self) = @_; |
283 | |
283 | |
… | |
… | |
725 | @{$self->{children}}, @widgets |
725 | @{$self->{children}}, @widgets |
726 | ]; |
726 | ]; |
727 | |
727 | |
728 | $self->realloc; |
728 | $self->realloc; |
729 | |
729 | |
|
|
730 | $self->emit (c_add => \@widgets); |
|
|
731 | |
730 | map $_+0, @widgets |
732 | map $_+0, @widgets |
731 | } |
733 | } |
732 | |
734 | |
733 | sub children { |
735 | sub children { |
734 | @{ $_[0]{children} } |
736 | @{ $_[0]{children} } |
735 | } |
737 | } |
736 | |
738 | |
737 | sub remove { |
739 | sub remove { |
738 | my ($self, $child) = @_; |
740 | my ($self, @widgets) = @_; |
739 | |
741 | |
|
|
742 | $self->emit (c_remove => \@widgets); |
|
|
743 | |
|
|
744 | for my $child (@widgets) { |
740 | delete $child->{parent}; |
745 | delete $child->{parent}; |
741 | $child->hide; |
746 | $child->hide; |
742 | |
|
|
743 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
747 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
|
|
748 | } |
744 | |
749 | |
745 | $self->realloc; |
750 | $self->realloc; |
746 | } |
751 | } |
747 | |
752 | |
748 | sub clear { |
753 | sub clear { |
… | |
… | |
776 | } |
781 | } |
777 | |
782 | |
778 | sub _draw { |
783 | sub _draw { |
779 | my ($self) = @_; |
784 | my ($self) = @_; |
780 | |
785 | |
781 | $_->draw for @{$self->{children}}; |
786 | $_->draw for $self->visible_children; |
782 | } |
787 | } |
783 | |
788 | |
784 | ############################################################################# |
789 | ############################################################################# |
785 | |
790 | |
786 | package CFPlus::UI::Bin; |
791 | package CFPlus::UI::Bin; |
… | |
… | |
796 | } |
801 | } |
797 | |
802 | |
798 | sub add { |
803 | sub add { |
799 | my ($self, $child) = @_; |
804 | my ($self, $child) = @_; |
800 | |
805 | |
801 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
806 | $self->clear; |
802 | $self->SUPER::add ($child); |
807 | $self->SUPER::add ($child); |
803 | } |
808 | } |
804 | |
809 | |
805 | sub remove { |
810 | sub remove { |
806 | my ($self, $widget) = @_; |
811 | my ($self, $widget) = @_; |
… | |
… | |
948 | $self->{view_x} = $x; |
953 | $self->{view_x} = $x; |
949 | $self->{view_y} = $y; |
954 | $self->{view_y} = $y; |
950 | |
955 | |
951 | $self->emit (changed => $x, $y); |
956 | $self->emit (changed => $x, $y); |
952 | $self->update; |
957 | $self->update; |
|
|
958 | } |
|
|
959 | } |
|
|
960 | |
|
|
961 | sub set_center { |
|
|
962 | my ($self, $x, $y) = @_; |
|
|
963 | |
|
|
964 | $self->set_offset ($x - $self->{w} * .5, $y - $self->{h} * .5); |
|
|
965 | } |
|
|
966 | |
|
|
967 | sub make_visible { |
|
|
968 | my ($self, $x, $y, $border) = @_; |
|
|
969 | |
|
|
970 | if ( $x < $self->{view_x} + $self->{w} * $border |
|
|
971 | || $x > $self->{view_x} + $self->{w} * (1 - $border) |
|
|
972 | || $y < $self->{view_y} + $self->{h} * $border |
|
|
973 | || $y > $self->{view_y} + $self->{h} * (1 - $border) |
|
|
974 | ) { |
|
|
975 | $self->set_center ($x, $y); |
953 | } |
976 | } |
954 | } |
977 | } |
955 | |
978 | |
956 | # hmm, this does not work for topleft of $self... but we should not ask for that |
979 | # hmm, this does not work for topleft of $self... but we should not ask for that |
957 | sub coord2local { |
980 | sub coord2local { |
… | |
… | |
1070 | my ($self, $widget) = @_; |
1093 | my ($self, $widget) = @_; |
1071 | |
1094 | |
1072 | $self->{vp}->add ($self->{child} = $widget); |
1095 | $self->{vp}->add ($self->{child} = $widget); |
1073 | } |
1096 | } |
1074 | |
1097 | |
|
|
1098 | sub set_offset { shift->{vp}->set_offset (@_) } |
|
|
1099 | sub set_center { shift->{vp}->set_center (@_) } |
|
|
1100 | sub make_visible { shift->{vp}->make_visible (@_) } |
|
|
1101 | |
1075 | sub update_slider { |
1102 | sub update_slider { |
1076 | my ($self) = @_; |
1103 | my ($self) = @_; |
1077 | |
1104 | |
1078 | my $child = ($self->{vp} or return)->child; |
1105 | my $child = ($self->{vp} or return)->child; |
1079 | |
1106 | |
… | |
… | |
1686 | |
1713 | |
1687 | use List::Util qw(min max); |
1714 | use List::Util qw(min max); |
1688 | |
1715 | |
1689 | our @ISA = CFPlus::UI::Container::; |
1716 | our @ISA = CFPlus::UI::Container::; |
1690 | |
1717 | |
1691 | sub add_fixed { |
|
|
1692 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
|
|
1693 | |
|
|
1694 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
|
|
1695 | $self->SUPER::add ($child); |
|
|
1696 | } |
|
|
1697 | |
|
|
1698 | sub _scale($$$) { |
1718 | sub _scale($$$) { |
1699 | my ($mode, $val, $max) = @_; |
1719 | my ($rel, $val, $max) = @_; |
1700 | |
1720 | |
1701 | $mode eq "abs" ? $val |
1721 | $rel ? $val * $max : $val |
1702 | : $mode eq "rel" ? $val * $max |
|
|
1703 | : 0 |
|
|
1704 | } |
1722 | } |
1705 | |
1723 | |
1706 | sub size_request { |
1724 | sub size_request { |
1707 | my ($self) = @_; |
1725 | my ($self) = @_; |
1708 | |
1726 | |
1709 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1727 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1710 | |
1728 | |
1711 | # determine overall size by querying abs widgets |
1729 | # determine overall size by querying abs widgets |
1712 | for my $child ($self->visible_children) { |
1730 | for my $child ($self->visible_children) { |
1713 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1731 | unless ($child->{c_rel}) { |
|
|
1732 | my $x = $child->{c_x}; |
|
|
1733 | my $y = $child->{c_y}; |
1714 | |
1734 | |
1715 | if ($pos eq "abs") { |
|
|
1716 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1717 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1718 | |
|
|
1719 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1735 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1720 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1736 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1721 | } |
1737 | } |
1722 | } |
1738 | } |
1723 | |
1739 | |
1724 | my $W = $x2 - $x1; |
1740 | my $W = $x2 - $x1; |
1725 | my $H = $y2 - $y1; |
1741 | my $H = $y2 - $y1; |
1726 | |
1742 | |
1727 | # now layout remaining widgets |
1743 | # now layout remaining widgets |
1728 | for my $child ($self->visible_children) { |
1744 | for my $child ($self->visible_children) { |
1729 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1745 | if ($child->{c_rel}) { |
|
|
1746 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1747 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1730 | |
1748 | |
1731 | if ($pos ne "abs") { |
|
|
1732 | $x = _scale $pos, $x, $W; |
|
|
1733 | $y = _scale $pos, $x, $H; |
|
|
1734 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1735 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1736 | |
|
|
1737 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1749 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1738 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1750 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1739 | } |
1751 | } |
1740 | } |
1752 | } |
1741 | |
1753 | |
1742 | my $W = $x2 - $x1; |
1754 | my $W = $x2 - $x1; |
1743 | my $H = $y2 - $y1; |
1755 | my $H = $y2 - $y1; |
… | |
… | |
1747 | |
1759 | |
1748 | sub invoke_size_allocate { |
1760 | sub invoke_size_allocate { |
1749 | my ($self, $W, $H) = @_; |
1761 | my ($self, $W, $H) = @_; |
1750 | |
1762 | |
1751 | for my $child ($self->visible_children) { |
1763 | for my $child ($self->visible_children) { |
1752 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1764 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1765 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1753 | |
1766 | |
1754 | $x = _scale $pos, $x, $W; |
1767 | $x += $child->{c_halign} * $child->{req_w}; |
1755 | $y = _scale $pos, $x, $H; |
1768 | $y += $child->{c_valign} * $child->{req_h}; |
1756 | $w = _scale $size, $w, $W; |
|
|
1757 | $h = _scale $size, $h, $H; |
|
|
1758 | |
1769 | |
1759 | $child->configure ($x, $y, $w, $h); |
1770 | $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h}); |
1760 | } |
1771 | } |
1761 | |
1772 | |
1762 | 1 |
1773 | 1 |
1763 | } |
1774 | } |
1764 | |
1775 | |
… | |
… | |
1768 | |
1779 | |
1769 | our @ISA = CFPlus::UI::Container::; |
1780 | our @ISA = CFPlus::UI::Container::; |
1770 | |
1781 | |
1771 | sub size_request { |
1782 | sub size_request { |
1772 | my ($self) = @_; |
1783 | my ($self) = @_; |
|
|
1784 | |
|
|
1785 | my @children = $self->visible_children; |
1773 | |
1786 | |
1774 | $self->{vertical} |
1787 | $self->{vertical} |
1775 | ? ( |
1788 | ? ( |
1776 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
1789 | (List::Util::max map $_->{req_w}, @children), |
1777 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
1790 | (List::Util::sum map $_->{req_h}, @children), |
1778 | ) |
1791 | ) |
1779 | : ( |
1792 | : ( |
1780 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
1793 | (List::Util::sum map $_->{req_w}, @children), |
1781 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1794 | (List::Util::max map $_->{req_h}, @children), |
1782 | ) |
1795 | ) |
1783 | } |
1796 | } |
1784 | |
1797 | |
1785 | sub invoke_size_allocate { |
1798 | sub invoke_size_allocate { |
1786 | my ($self, $w, $h) = @_; |
1799 | my ($self, $w, $h) = @_; |
… | |
… | |
2027 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2040 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2028 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2041 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2029 | : ($self->{h} - $size->[1]) * 0.5); |
2042 | : ($self->{h} - $size->[1]) * 0.5); |
2030 | }; |
2043 | }; |
2031 | |
2044 | |
2032 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
2045 | # unless ($self->{list}) { |
2033 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
2046 | # $self->{list} = CFPlus::OpenGL::glGenList; |
|
|
2047 | # CFPlus::OpenGL::glNewList $self->{list}; |
|
|
2048 | # $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
|
|
2049 | # CFPlus::OpenGL::glEndList; |
|
|
2050 | # } |
|
|
2051 | # |
|
|
2052 | # CFPlus::OpenGL::glCallList $self->{list}; |
2034 | |
2053 | |
2035 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2054 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2036 | } |
2055 | } |
|
|
2056 | |
|
|
2057 | #sub destroy { |
|
|
2058 | # my ($self) = @_; |
|
|
2059 | # |
|
|
2060 | # CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; |
|
|
2061 | # |
|
|
2062 | # $self->SUPER::destroy; |
|
|
2063 | #} |
2037 | |
2064 | |
2038 | ############################################################################# |
2065 | ############################################################################# |
2039 | |
2066 | |
2040 | package CFPlus::UI::EntryBase; |
2067 | package CFPlus::UI::EntryBase; |
2041 | |
2068 | |
… | |
… | |
2047 | my $class = shift; |
2074 | my $class = shift; |
2048 | |
2075 | |
2049 | $class->SUPER::new ( |
2076 | $class->SUPER::new ( |
2050 | fg => [1, 1, 1], |
2077 | fg => [1, 1, 1], |
2051 | bg => [0, 0, 0, 0.2], |
2078 | bg => [0, 0, 0, 0.2], |
|
|
2079 | outline => [0.6, 0.3, 0.1], |
2052 | active_bg => [1, 1, 1, 0.5], |
2080 | active_bg => [0, 0, 1, .2], |
2053 | active_fg => [0, 0, 0], |
2081 | active_fg => [1, 1, 1], |
|
|
2082 | active_outline => [1, 1, 0], |
2054 | can_hover => 1, |
2083 | can_hover => 1, |
2055 | can_focus => 1, |
2084 | can_focus => 1, |
2056 | valign => 0, |
2085 | valign => 0, |
2057 | can_events => 1, |
2086 | can_events => 1, |
2058 | ellipsise => 0, |
2087 | ellipsise => 0, |
… | |
… | |
2215 | |
2244 | |
2216 | unless (exists $self->{cur_h}) { |
2245 | unless (exists $self->{cur_h}) { |
2217 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2246 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2218 | utf8::encode $text; |
2247 | utf8::encode $text; |
2219 | |
2248 | |
2220 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
2249 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2221 | } |
2250 | } |
2222 | |
2251 | |
|
|
2252 | glColor_premultiply @{$self->{active_fg}}; |
2223 | glBegin GL_LINES; |
2253 | glBegin GL_LINES; |
2224 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2254 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2225 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2255 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
|
|
2256 | glEnd; |
|
|
2257 | |
|
|
2258 | glLineWidth 3; |
|
|
2259 | glColor @{$self->{active_outline}}; |
|
|
2260 | glBegin GL_LINE_LOOP; |
|
|
2261 | glVertex 0, 0; |
|
|
2262 | glVertex $self->{w} - 1, 0; |
|
|
2263 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
2264 | glVertex 0, $self->{h} - 1; |
|
|
2265 | glEnd; |
|
|
2266 | glLineWidth 1; |
|
|
2267 | |
|
|
2268 | } else { |
|
|
2269 | glColor @{$self->{outline}}; |
|
|
2270 | glTranslate .375, .375; |
|
|
2271 | glBegin GL_LINE_STRIP; |
|
|
2272 | glVertex 0, $self->{h} * .5; |
|
|
2273 | glVertex 0, $self->{h} - 3; |
|
|
2274 | glVertex $self->{w} - 1, $self->{h} - 3; |
|
|
2275 | glVertex $self->{w} - 1, $self->{h} * .5; |
2226 | glEnd; |
2276 | glEnd; |
2227 | } |
2277 | } |
2228 | } |
2278 | } |
2229 | |
2279 | |
2230 | ############################################################################# |
2280 | ############################################################################# |
… | |
… | |
2317 | 1 |
2367 | 1 |
2318 | } |
2368 | } |
2319 | |
2369 | |
2320 | ############################################################################# |
2370 | ############################################################################# |
2321 | |
2371 | |
|
|
2372 | package CFPlus::UI::ButtonBin; |
|
|
2373 | |
|
|
2374 | our @ISA = CFPlus::UI::Bin::; |
|
|
2375 | |
|
|
2376 | use CFPlus::OpenGL; |
|
|
2377 | |
|
|
2378 | my @tex = |
|
|
2379 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
2380 | qw(b1_button_inactive.png b1_button_active.png); |
|
|
2381 | |
|
|
2382 | sub new { |
|
|
2383 | my $class = shift; |
|
|
2384 | |
|
|
2385 | $class->SUPER::new ( |
|
|
2386 | can_hover => 1, |
|
|
2387 | align => 0, |
|
|
2388 | valign => 0, |
|
|
2389 | can_events => 1, |
|
|
2390 | @_ |
|
|
2391 | ) |
|
|
2392 | } |
|
|
2393 | |
|
|
2394 | sub invoke_button_up { |
|
|
2395 | my ($self, $ev, $x, $y) = @_; |
|
|
2396 | |
|
|
2397 | $self->emit ("activate") |
|
|
2398 | if $x >= 0 && $x < $self->{w} |
|
|
2399 | && $y >= 0 && $y < $self->{h}; |
|
|
2400 | |
|
|
2401 | 1 |
|
|
2402 | } |
|
|
2403 | |
|
|
2404 | sub _draw { |
|
|
2405 | my ($self) = @_; |
|
|
2406 | |
|
|
2407 | glEnable GL_TEXTURE_2D; |
|
|
2408 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2409 | glColor 0, 0, 0, 1; |
|
|
2410 | |
|
|
2411 | my $tex = $tex[$GRAB == $self]; |
|
|
2412 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
|
|
2413 | |
|
|
2414 | glDisable GL_TEXTURE_2D; |
|
|
2415 | |
|
|
2416 | $self->SUPER::_draw; |
|
|
2417 | } |
|
|
2418 | |
|
|
2419 | ############################################################################# |
|
|
2420 | |
2322 | package CFPlus::UI::Button; |
2421 | package CFPlus::UI::Button; |
2323 | |
2422 | |
2324 | our @ISA = CFPlus::UI::Label::; |
2423 | our @ISA = CFPlus::UI::Label::; |
2325 | |
2424 | |
2326 | use CFPlus::OpenGL; |
2425 | use CFPlus::OpenGL; |
… | |
… | |
2460 | sub new { |
2559 | sub new { |
2461 | my $class = shift; |
2560 | my $class = shift; |
2462 | |
2561 | |
2463 | my $self = $class->SUPER::new ( |
2562 | my $self = $class->SUPER::new ( |
2464 | can_events => 0, |
2563 | can_events => 0, |
|
|
2564 | scale => 1, |
2465 | @_, |
2565 | @_, |
2466 | ); |
2566 | ); |
2467 | |
2567 | |
2468 | $self->{path} || $self->{tex} |
2568 | $self->{path} || $self->{tex} |
2469 | or Carp::croak "'path' or 'tex' attributes required"; |
2569 | or Carp::croak "'path' or 'tex' attributes required"; |
… | |
… | |
2494 | } |
2594 | } |
2495 | |
2595 | |
2496 | sub size_request { |
2596 | sub size_request { |
2497 | my ($self) = @_; |
2597 | my ($self) = @_; |
2498 | |
2598 | |
2499 | ($self->{tex}{w}, $self->{tex}{h}) |
2599 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2500 | } |
2600 | } |
2501 | |
2601 | |
2502 | sub _draw { |
2602 | sub _draw { |
2503 | my ($self) = @_; |
2603 | my ($self) = @_; |
2504 | |
2604 | |
… | |
… | |
2514 | } |
2614 | } |
2515 | |
2615 | |
2516 | glEnable GL_TEXTURE_2D; |
2616 | glEnable GL_TEXTURE_2D; |
2517 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2617 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2518 | |
2618 | |
2519 | $tex->draw_quad (0, 0, $w, $h); |
2619 | $tex->draw_quad_alpha (0, 0, $w, $h); |
2520 | |
2620 | |
2521 | glDisable GL_TEXTURE_2D; |
2621 | glDisable GL_TEXTURE_2D; |
2522 | } |
2622 | } |
2523 | |
2623 | |
2524 | ############################################################################# |
2624 | ############################################################################# |
… | |
… | |
2826 | |
2926 | |
2827 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2927 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2828 | |
2928 | |
2829 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2929 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2830 | |
2930 | |
2831 | $self->invoke_mouse_motion ($ev, $x, $y) |
2931 | $self->invoke_mouse_motion ($ev, $x, $y); |
|
|
2932 | |
|
|
2933 | 1 |
2832 | } |
2934 | } |
2833 | |
2935 | |
2834 | sub invoke_mouse_motion { |
2936 | sub invoke_mouse_motion { |
2835 | my ($self, $ev, $x, $y) = @_; |
2937 | my ($self, $ev, $x, $y) = @_; |
2836 | |
2938 | |
… | |
… | |
2856 | |
2958 | |
2857 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2959 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2858 | |
2960 | |
2859 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2961 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2860 | |
2962 | |
2861 | ! ! $delta |
2963 | 1 |
2862 | } |
2964 | } |
2863 | |
2965 | |
2864 | sub update { |
2966 | sub update { |
2865 | my ($self) = @_; |
2967 | my ($self) = @_; |
2866 | |
2968 | |
… | |
… | |
2997 | } |
3099 | } |
2998 | |
3100 | |
2999 | sub size_request { |
3101 | sub size_request { |
3000 | my ($self) = @_; |
3102 | my ($self) = @_; |
3001 | |
3103 | |
3002 | my ($empty, $slider) = @{ $self->{children} }; |
3104 | my ($empty, $slider) = $self->visible_children; |
3003 | |
3105 | |
3004 | local $self->{children} = [$empty, $slider]; |
3106 | local $self->{children} = [$empty, $slider]; |
3005 | $self->SUPER::size_request |
3107 | $self->SUPER::size_request |
3006 | } |
3108 | } |
3007 | |
3109 | |
… | |
… | |
3396 | glTranslate 0.375, 0.375; |
3498 | glTranslate 0.375, 0.375; |
3397 | |
3499 | |
3398 | my ($w, $h) = @$self{qw(w h)}; |
3500 | my ($w, $h) = @$self{qw(w h)}; |
3399 | |
3501 | |
3400 | glColor 1, 0.8, 0.4; |
3502 | glColor 1, 0.8, 0.4; |
3401 | glBegin GL_QUADS; |
3503 | glRect 0, 0, $w, $h; |
3402 | glVertex 0 , 0; |
|
|
3403 | glVertex 0 , $h; |
|
|
3404 | glVertex $w, $h; |
|
|
3405 | glVertex $w, 0; |
|
|
3406 | glEnd; |
|
|
3407 | |
3504 | |
3408 | glColor 0, 0, 0; |
3505 | glColor 0, 0, 0; |
3409 | glBegin GL_LINE_LOOP; |
3506 | glBegin GL_LINE_LOOP; |
3410 | glVertex 0 , 0; |
3507 | glVertex 0 , 0; |
3411 | glVertex 0 , $h; |
3508 | glVertex 0 , $h; |
… | |
… | |
3593 | children => [ |
3690 | children => [ |
3594 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3691 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3595 | (new CFPlus::UI::Label markup => $right, align => +1), |
3692 | (new CFPlus::UI::Label markup => $right, align => +1), |
3596 | ], |
3693 | ], |
3597 | ; |
3694 | ; |
3598 | |
3695 | |
3599 | } else { |
3696 | } else { |
3600 | $widget = new CFPlus::UI::Label |
3697 | $widget = new CFPlus::UI::Label |
3601 | can_hover => 1, |
3698 | can_hover => 1, |
3602 | can_events => 1, |
3699 | can_events => 1, |
3603 | markup => $widget, |
3700 | markup => $widget, |
… | |
… | |
3739 | buttonbar => (new CFPlus::UI::Buttonbar), |
3836 | buttonbar => (new CFPlus::UI::Buttonbar), |
3740 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3837 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3741 | # filter => # will be put between multiplexer and $self |
3838 | # filter => # will be put between multiplexer and $self |
3742 | @_, |
3839 | @_, |
3743 | ); |
3840 | ); |
3744 | |
3841 | |
3745 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3842 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3746 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3843 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3747 | |
3844 | |
|
|
3845 | { |
|
|
3846 | Scalar::Util::weaken (my $wself = $self); |
|
|
3847 | |
|
|
3848 | $self->{multiplexer}->connect (c_add => sub { |
|
|
3849 | my ($mplex, $widgets) = @_; |
|
|
3850 | |
|
|
3851 | for my $child (@$widgets) { |
|
|
3852 | Scalar::Util::weaken $child; |
|
|
3853 | $child->{c_tab_} ||= do { |
|
|
3854 | my $tab = |
|
|
3855 | (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") |
|
|
3856 | ? $child->{c_tab} |
|
|
3857 | : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; |
|
|
3858 | |
|
|
3859 | $tab->connect (activate => sub { |
|
|
3860 | $wself->set_current_page ($child); |
|
|
3861 | }); |
|
|
3862 | |
|
|
3863 | $tab |
|
|
3864 | }; |
|
|
3865 | |
|
|
3866 | $self->{buttonbar}->add ($child->{c_tab_}); |
|
|
3867 | } |
|
|
3868 | }); |
|
|
3869 | |
|
|
3870 | $self->{multiplexer}->connect (c_remove => sub { |
|
|
3871 | my ($mplex, $widgets) = @_; |
|
|
3872 | |
|
|
3873 | for my $child (@$widgets) { |
|
|
3874 | $wself->{buttonbar}->remove ($child->{c_tab_}); |
|
|
3875 | } |
|
|
3876 | }); |
|
|
3877 | } |
|
|
3878 | |
3748 | $self |
3879 | $self |
3749 | } |
3880 | } |
3750 | |
3881 | |
3751 | sub add { |
3882 | sub add { |
|
|
3883 | my ($self, @widgets) = @_; |
|
|
3884 | |
|
|
3885 | $self->{multiplexer}->add (@widgets) |
|
|
3886 | } |
|
|
3887 | |
|
|
3888 | sub remove { |
|
|
3889 | my ($self, @widgets) = @_; |
|
|
3890 | |
|
|
3891 | $self->{multiplexer}->remove (@widgets) |
|
|
3892 | } |
|
|
3893 | |
|
|
3894 | sub pages { |
|
|
3895 | my ($self) = @_; |
|
|
3896 | $self->{multiplexer}->children |
|
|
3897 | } |
|
|
3898 | |
|
|
3899 | sub add_tab { |
3752 | my ($self, $title, $widget, $tooltip) = @_; |
3900 | my ($self, $title, $widget, $tooltip) = @_; |
3753 | |
3901 | |
3754 | CFPlus::weaken $self; |
3902 | $title = [$title, $tooltip] unless ref $title; |
|
|
3903 | $widget->{c_tab} = $title; |
3755 | |
3904 | |
3756 | $self->{buttonbar}->add (new CFPlus::UI::Button |
|
|
3757 | markup => $title, |
|
|
3758 | tooltip => $tooltip, |
|
|
3759 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3760 | ); |
|
|
3761 | |
|
|
3762 | $self->{multiplexer}->add ($widget); |
3905 | $self->add ($widget); |
3763 | } |
3906 | } |
3764 | |
3907 | |
3765 | sub get_current_page { |
3908 | sub get_current_page { |
3766 | my ($self) = @_; |
3909 | my ($self) = @_; |
3767 | |
3910 | |