… | |
… | |
24 | my $tip = $widget->{tooltip}; |
24 | my $tip = $widget->{tooltip}; |
25 | |
25 | |
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
27 | |
27 | |
28 | $TOOLTIP->set_markup ($widget->{tooltip}); |
28 | $TOOLTIP->set_markup ($widget->{tooltip}); |
29 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
29 | |
30 | $TOOLTIP->show; |
30 | $TOOLTIP->show; |
|
|
31 | |
|
|
32 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
|
|
33 | |
|
|
34 | if ($x + $TOOLTIP->{w} > $::WIDTH) { |
|
|
35 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); |
|
|
36 | } |
|
|
37 | |
|
|
38 | $TOOLTIP->move ($x, $y); |
31 | } |
39 | } |
32 | |
40 | |
33 | return; |
41 | return; |
34 | } |
42 | } |
35 | } |
43 | } |
… | |
… | |
643 | } |
651 | } |
644 | |
652 | |
645 | sub update { |
653 | sub update { |
646 | my ($self) = @_; |
654 | my ($self) = @_; |
647 | |
655 | |
648 | # we want to do this delayed... |
656 | $ROOT->on_refresh ($self => sub { $self->render_child }); |
649 | $self->render_chld; |
|
|
650 | $self->SUPER::update; |
657 | $self->SUPER::update; |
651 | } |
658 | } |
652 | |
659 | |
|
|
660 | sub size_allocate { |
|
|
661 | my ($self, $w, $h) = @_; |
|
|
662 | |
|
|
663 | $self->SUPER::size_allocate ($w, $h); |
|
|
664 | $self->update; |
|
|
665 | } |
|
|
666 | |
653 | sub render_chld { |
667 | sub render_child { |
654 | my ($self) = @_; |
668 | my ($self) = @_; |
655 | |
669 | |
656 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
670 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
657 | glClearColor 0, 0, 0, 1; |
671 | glClearColor 0, 0, 0, 0; |
658 | glClear GL_COLOR_BUFFER_BIT; |
672 | glClear GL_COLOR_BUFFER_BIT; |
659 | $self->child->draw; |
673 | $self->child->draw; |
|
|
674 | # glColorMask 1, 1, 1, 0; |
|
|
675 | # glEnable GL_BLEND; |
|
|
676 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
|
|
677 | # glRasterPos 0, 0; |
|
|
678 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
|
|
679 | # glDisable GL_BLEND; |
|
|
680 | # glColorMask 1, 1, 1, 1; |
660 | }; |
681 | }; |
661 | } |
|
|
662 | |
|
|
663 | sub size_allocate { |
|
|
664 | my ($self, $w, $h) = @_; |
|
|
665 | |
|
|
666 | $self->child->configure (0, 0, $w, $h); |
|
|
667 | |
|
|
668 | $self->render_chld; |
|
|
669 | } |
682 | } |
670 | |
683 | |
671 | sub _draw { |
684 | sub _draw { |
672 | my ($self) = @_; |
685 | my ($self) = @_; |
673 | |
686 | |
… | |
… | |
675 | |
688 | |
676 | my $tex = $self->{texture} |
689 | my $tex = $self->{texture} |
677 | or return; |
690 | or return; |
678 | |
691 | |
679 | glEnable GL_BLEND; |
692 | glEnable GL_BLEND; |
680 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
693 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
681 | glEnable GL_TEXTURE_2D; |
694 | glEnable GL_TEXTURE_2D; |
682 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
695 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
696 | glColor 0, 0, 0, 1; |
683 | |
697 | |
684 | $tex->draw_quad (0, 0, $w, $h); |
698 | $tex->draw_quad (0, 0, $w, $h); |
685 | |
699 | |
686 | glDisable GL_BLEND; |
700 | glDisable GL_BLEND; |
687 | glDisable GL_TEXTURE_2D; |
701 | glDisable GL_TEXTURE_2D; |
… | |
… | |
774 | # TODO: user_x, user_y, overwrite moveto? |
788 | # TODO: user_x, user_y, overwrite moveto? |
775 | |
789 | |
776 | my $self = $class->SUPER::new ( |
790 | my $self = $class->SUPER::new ( |
777 | bg => [1, 1, 1, 1], |
791 | bg => [1, 1, 1, 1], |
778 | border_bg => [1, 1, 1, 1], |
792 | border_bg => [1, 1, 1, 1], |
779 | border => 0.8, |
793 | border => 0.6, |
780 | can_events => 1, |
794 | can_events => 1, |
781 | @_ |
795 | @_ |
782 | ); |
796 | ); |
783 | |
797 | |
784 | $self->{title} &&= new CFClient::UI::Label |
798 | $self->{title} &&= new CFClient::UI::Label |
785 | align => 0, |
799 | align => 0, |
786 | valign => 1, |
800 | valign => 1, |
787 | text => $self->{title}, |
801 | text => $self->{title}, |
788 | fontsize => 1; |
802 | fontsize => $self->{border}; |
789 | |
803 | |
790 | $self |
804 | $self |
791 | } |
805 | } |
792 | |
806 | |
793 | sub border { |
807 | sub border { |
… | |
… | |
818 | } |
832 | } |
819 | |
833 | |
820 | sub button_down { |
834 | sub button_down { |
821 | my ($self, $ev, $x, $y) = @_; |
835 | my ($self, $ev, $x, $y) = @_; |
822 | |
836 | |
|
|
837 | my ($w, $h) = @$self{qw(w h)}; |
823 | my $border = $self->border; |
838 | my $border = $self->border; |
824 | |
839 | |
825 | if ($x < $self->{w} && $x >= $self->{w} - $border |
840 | my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w); |
826 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
841 | my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h); |
827 | |
842 | |
|
|
843 | if ($lr & $td) { |
|
|
844 | my ($wx, $wy) = ($self->{x}, $self->{y}); |
828 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
845 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
829 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
846 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
830 | |
847 | |
|
|
848 | my $mx = $x < $border; |
|
|
849 | my $my = $y < $border; |
|
|
850 | |
831 | $self->{motion} = sub { |
851 | $self->{motion} = sub { |
832 | my ($ev, $x, $y) = @_; |
852 | my ($ev, $x, $y) = @_; |
833 | |
853 | |
834 | ($x, $y) = ($ev->{x}, $ev->{y}); |
854 | my $dx = $ev->{x} - $ox; |
|
|
855 | my $dy = $ev->{y} - $oy; |
835 | |
856 | |
836 | $self->{user_w} = $bw + $x - $ox; |
857 | $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); |
837 | $self->{user_h} = $bh + $y - $oy; |
858 | $self->{user_h} = $bh + $dy * ($my ? -1 : 1); |
|
|
859 | $self->move ($wx + $dx * $mx, $wy + $dy * $my); |
838 | $self->check_size; |
860 | $self->check_size; |
839 | }; |
861 | }; |
840 | |
862 | |
841 | } elsif ($x >= 0 && $x < $self->{w} |
863 | } elsif ($lr ^ $td) { |
842 | && $y >= 0 && $y < $border) { |
|
|
843 | |
|
|
844 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
864 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
845 | my ($bx, $by) = ($self->{x}, $self->{y}); |
865 | my ($bx, $by) = ($self->{x}, $self->{y}); |
846 | |
866 | |
847 | $self->{motion} = sub { |
867 | $self->{motion} = sub { |
848 | my ($ev, $x, $y) = @_; |
868 | my ($ev, $x, $y) = @_; |
… | |
… | |
2069 | (new CFClient::UI::Empty expand => 1), |
2089 | (new CFClient::UI::Empty expand => 1), |
2070 | (new CFClient::UI::Slider vertical => 1), |
2090 | (new CFClient::UI::Slider vertical => 1), |
2071 | ], |
2091 | ], |
2072 | ); |
2092 | ); |
2073 | |
2093 | |
2074 | $self->{children}[1]->connect (changed => sub { |
2094 | $self->{children}[1]->connect (changed => sub { $self->update }); |
2075 | $self->update; |
|
|
2076 | }); |
|
|
2077 | |
2095 | |
2078 | $self |
2096 | $self |
2079 | } |
2097 | } |
2080 | |
2098 | |
2081 | sub set_fontsize { |
2099 | sub set_fontsize { |
… | |
… | |
2089 | my ($self, $text) = @_; |
2107 | my ($self, $text) = @_; |
2090 | |
2108 | |
2091 | my $layout = $self->{layout}; |
2109 | my $layout = $self->{layout}; |
2092 | |
2110 | |
2093 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2111 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2094 | $layout->set_width ($self->{w}); |
2112 | $layout->set_width ($self->{children}[0]{w}); |
2095 | $layout->set_text ($text); |
2113 | $layout->set_text ($text); |
2096 | |
2114 | |
2097 | ($layout->size)[1] |
2115 | ($layout->size)[1] |
2098 | } |
2116 | } |
2099 | |
2117 | |
… | |
… | |
2152 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2170 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2153 | |
2171 | |
2154 | delete $self->{texture}; |
2172 | delete $self->{texture}; |
2155 | } |
2173 | } |
2156 | |
2174 | |
2157 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
2175 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2158 | glClearColor 0, 0, 0, 1; |
2176 | glClearColor 0, 0, 0, 0; |
2159 | glClear GL_COLOR_BUFFER_BIT; |
2177 | glClear GL_COLOR_BUFFER_BIT; |
2160 | |
2178 | |
2161 | glEnable GL_BLEND; |
2179 | glEnable GL_BLEND; |
2162 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2180 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2163 | glEnable GL_TEXTURE_2D; |
2181 | glEnable GL_TEXTURE_2D; |
… | |
… | |
2195 | } |
2213 | } |
2196 | |
2214 | |
2197 | sub _draw { |
2215 | sub _draw { |
2198 | my ($self) = @_; |
2216 | my ($self) = @_; |
2199 | |
2217 | |
2200 | if ($self->{texture}) { |
2218 | glEnable GL_BLEND; |
|
|
2219 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2201 | glEnable GL_TEXTURE_2D; |
2220 | glEnable GL_TEXTURE_2D; |
2202 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2221 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2203 | glColor 1, 1, 1, 1; |
2222 | glColor 1, 1, 1, 1; |
2204 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2223 | $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2205 | glDisable GL_TEXTURE_2D; |
2224 | glDisable GL_TEXTURE_2D; |
2206 | } |
2225 | glDisable GL_BLEND; |
2207 | |
2226 | |
2208 | $self->{children}[1]->draw; |
2227 | $self->{children}[1]->draw; |
2209 | |
2228 | |
2210 | } |
2229 | } |
2211 | |
2230 | |