… | |
… | |
669 | |
669 | |
670 | $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 { |
671 | glClearColor 0, 0, 0, 0; |
671 | glClearColor 0, 0, 0, 0; |
672 | glClear GL_COLOR_BUFFER_BIT; |
672 | glClear GL_COLOR_BUFFER_BIT; |
673 | $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; |
674 | }; |
681 | }; |
675 | } |
682 | } |
676 | |
683 | |
677 | sub _draw { |
684 | sub _draw { |
678 | my ($self) = @_; |
685 | my ($self) = @_; |
… | |
… | |
781 | # TODO: user_x, user_y, overwrite moveto? |
788 | # TODO: user_x, user_y, overwrite moveto? |
782 | |
789 | |
783 | my $self = $class->SUPER::new ( |
790 | my $self = $class->SUPER::new ( |
784 | bg => [1, 1, 1, 1], |
791 | bg => [1, 1, 1, 1], |
785 | border_bg => [1, 1, 1, 1], |
792 | border_bg => [1, 1, 1, 1], |
786 | border => 0.8, |
793 | border => 0.6, |
787 | can_events => 1, |
794 | can_events => 1, |
788 | @_ |
795 | @_ |
789 | ); |
796 | ); |
790 | |
797 | |
791 | $self->{title} &&= new CFClient::UI::Label |
798 | $self->{title} &&= new CFClient::UI::Label |
792 | align => 0, |
799 | align => 0, |
793 | valign => 1, |
800 | valign => 1, |
794 | text => $self->{title}, |
801 | text => $self->{title}, |
795 | fontsize => 1; |
802 | fontsize => $self->{border}; |
796 | |
803 | |
797 | $self |
804 | $self |
798 | } |
805 | } |
799 | |
806 | |
800 | sub border { |
807 | sub border { |
… | |
… | |
825 | } |
832 | } |
826 | |
833 | |
827 | sub button_down { |
834 | sub button_down { |
828 | my ($self, $ev, $x, $y) = @_; |
835 | my ($self, $ev, $x, $y) = @_; |
829 | |
836 | |
|
|
837 | my ($w, $h) = @$self{qw(w h)}; |
830 | my $border = $self->border; |
838 | my $border = $self->border; |
831 | |
839 | |
832 | if ($x < $self->{w} && $x >= $self->{w} - $border |
840 | my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w); |
833 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
841 | my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h); |
834 | |
842 | |
|
|
843 | if ($lr & $td) { |
|
|
844 | my ($wx, $wy) = ($self->{x}, $self->{y}); |
835 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
845 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
836 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
846 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
837 | |
847 | |
|
|
848 | my $mx = $x < $border; |
|
|
849 | my $my = $y < $border; |
|
|
850 | |
838 | $self->{motion} = sub { |
851 | $self->{motion} = sub { |
839 | my ($ev, $x, $y) = @_; |
852 | my ($ev, $x, $y) = @_; |
840 | |
853 | |
841 | ($x, $y) = ($ev->{x}, $ev->{y}); |
854 | my $dx = $ev->{x} - $ox; |
|
|
855 | my $dy = $ev->{y} - $oy; |
842 | |
856 | |
843 | $self->{user_w} = $bw + $x - $ox; |
857 | $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); |
844 | $self->{user_h} = $bh + $y - $oy; |
858 | $self->{user_h} = $bh + $dy * ($my ? -1 : 1); |
|
|
859 | $self->move ($wx + $dx * $mx, $wy + $dy * $my); |
845 | $self->check_size; |
860 | $self->check_size; |
846 | }; |
861 | }; |
847 | |
862 | |
848 | } elsif ($x >= 0 && $x < $self->{w} |
863 | } elsif ($lr ^ $td) { |
849 | && $y >= 0 && $y < $border) { |
|
|
850 | |
|
|
851 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
864 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
852 | my ($bx, $by) = ($self->{x}, $self->{y}); |
865 | my ($bx, $by) = ($self->{x}, $self->{y}); |
853 | |
866 | |
854 | $self->{motion} = sub { |
867 | $self->{motion} = sub { |
855 | my ($ev, $x, $y) = @_; |
868 | my ($ev, $x, $y) = @_; |
… | |
… | |
891 | $tex[1]->draw_quad (0, 0, $w, $border); |
904 | $tex[1]->draw_quad (0, 0, $w, $border); |
892 | $tex[3]->draw_quad (0, $border, $border, $ch); |
905 | $tex[3]->draw_quad (0, $border, $border, $ch); |
893 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
906 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
894 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
907 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
895 | |
908 | |
|
|
909 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
896 | my $bg = $tex[0]; |
910 | my $bg = $tex[0]; |
897 | |
911 | |
898 | # TODO: repeat texture not scale |
912 | # TODO: repeat texture not scale |
899 | my $rep_x = $cw / $bg->{w}; |
913 | my $rep_x = $cw / $bg->{w}; |
900 | my $rep_y = $ch / $bg->{h}; |
914 | my $rep_y = $ch / $bg->{h}; |
901 | |
915 | |
902 | glColor @{ $self->{bg} }; |
916 | glColor @{ $self->{bg} }; |
903 | |
917 | |
904 | $bg->{s} = $rep_x; |
918 | $bg->{s} = $rep_x; |
905 | $bg->{t} = $rep_y; |
919 | $bg->{t} = $rep_y; |
906 | $bg->{wrap_mode} = 1; |
920 | $bg->{wrap_mode} = 1; |
907 | $bg->draw_quad ($border, $border, $cw, $ch); |
921 | $bg->draw_quad ($border, $border, $cw, $ch); |
908 | |
922 | |
909 | glDisable GL_TEXTURE_2D; |
923 | glDisable GL_TEXTURE_2D; |
910 | glDisable GL_BLEND; |
924 | glDisable GL_BLEND; |
|
|
925 | } |
911 | |
926 | |
912 | $self->{title}->draw if $self->{title}; |
927 | $self->{title}->draw if $self->{title}; |
|
|
928 | |
913 | $self->child->draw; |
929 | $self->child->draw; |
914 | } |
930 | } |
915 | |
931 | |
916 | ############################################################################# |
932 | ############################################################################# |
917 | |
933 | |
… | |
… | |
2076 | (new CFClient::UI::Empty expand => 1), |
2092 | (new CFClient::UI::Empty expand => 1), |
2077 | (new CFClient::UI::Slider vertical => 1), |
2093 | (new CFClient::UI::Slider vertical => 1), |
2078 | ], |
2094 | ], |
2079 | ); |
2095 | ); |
2080 | |
2096 | |
2081 | $self->{children}[1]->connect (changed => sub { |
2097 | $self->{children}[1]->connect (changed => sub { $self->update }); |
2082 | $self->update; |
|
|
2083 | }); |
|
|
2084 | |
2098 | |
2085 | $self |
2099 | $self |
2086 | } |
2100 | } |
2087 | |
2101 | |
2088 | sub set_fontsize { |
2102 | sub set_fontsize { |
… | |
… | |
2096 | my ($self, $text) = @_; |
2110 | my ($self, $text) = @_; |
2097 | |
2111 | |
2098 | my $layout = $self->{layout}; |
2112 | my $layout = $self->{layout}; |
2099 | |
2113 | |
2100 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2114 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2101 | $layout->set_width ($self->{w}); |
2115 | $layout->set_width ($self->{children}[0]{w}); |
2102 | $layout->set_text ($text); |
2116 | $layout->set_text ($text); |
2103 | |
2117 | |
2104 | ($layout->size)[1] |
2118 | ($layout->size)[1] |
2105 | } |
2119 | } |
2106 | |
2120 | |
… | |
… | |
2159 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2173 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
2160 | |
2174 | |
2161 | delete $self->{texture}; |
2175 | delete $self->{texture}; |
2162 | } |
2176 | } |
2163 | |
2177 | |
2164 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
2178 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2165 | glClearColor 0, 0, 0, 1; |
2179 | glClearColor 0, 0, 0, 0; |
2166 | glClear GL_COLOR_BUFFER_BIT; |
2180 | glClear GL_COLOR_BUFFER_BIT; |
2167 | |
2181 | |
2168 | glEnable GL_BLEND; |
2182 | glEnable GL_BLEND; |
2169 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2183 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2170 | glEnable GL_TEXTURE_2D; |
2184 | glEnable GL_TEXTURE_2D; |
… | |
… | |
2202 | } |
2216 | } |
2203 | |
2217 | |
2204 | sub _draw { |
2218 | sub _draw { |
2205 | my ($self) = @_; |
2219 | my ($self) = @_; |
2206 | |
2220 | |
2207 | if ($self->{texture}) { |
2221 | glEnable GL_BLEND; |
|
|
2222 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2208 | glEnable GL_TEXTURE_2D; |
2223 | glEnable GL_TEXTURE_2D; |
2209 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2224 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2210 | glColor 1, 1, 1, 1; |
2225 | glColor 1, 1, 1, 1; |
2211 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
2226 | $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2212 | glDisable GL_TEXTURE_2D; |
2227 | glDisable GL_TEXTURE_2D; |
2213 | } |
2228 | glDisable GL_BLEND; |
2214 | |
2229 | |
2215 | $self->{children}[1]->draw; |
2230 | $self->{children}[1]->draw; |
2216 | |
2231 | |
2217 | } |
2232 | } |
2218 | |
2233 | |
… | |
… | |
2392 | sub draw { |
2407 | sub draw { |
2393 | my ($self) = @_; |
2408 | my ($self) = @_; |
2394 | |
2409 | |
2395 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2410 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2396 | |
2411 | |
|
|
2412 | # TODO animation |
2397 | if ($tex) { |
2413 | if ($tex) { |
2398 | glEnable GL_BLEND; |
2414 | glEnable GL_BLEND; |
2399 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2415 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
2400 | glEnable GL_TEXTURE_2D; |
2416 | glEnable GL_TEXTURE_2D; |
2401 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2417 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
… | |
… | |
2406 | } |
2422 | } |
2407 | } |
2423 | } |
2408 | |
2424 | |
2409 | ############################################################################# |
2425 | ############################################################################# |
2410 | |
2426 | |
|
|
2427 | package CFClient::UI::Menu; |
|
|
2428 | |
|
|
2429 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
2430 | |
|
|
2431 | use CFClient::OpenGL; |
|
|
2432 | |
|
|
2433 | sub new { |
|
|
2434 | my $class = shift; |
|
|
2435 | |
|
|
2436 | my $self = $class->SUPER::new ( |
|
|
2437 | items => [], |
|
|
2438 | z => 100, |
|
|
2439 | @_, |
|
|
2440 | ); |
|
|
2441 | |
|
|
2442 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
|
|
2443 | |
|
|
2444 | for my $item (@{ $self->{items} }) { |
|
|
2445 | my ($widget, $cb) = @$item; |
|
|
2446 | |
|
|
2447 | # handle various types of items, only text for now |
|
|
2448 | if (!ref $widget) { |
|
|
2449 | $widget = new CFClient::UI::Label |
|
|
2450 | can_hover => 1, |
|
|
2451 | can_events => 1, |
|
|
2452 | text => $widget; |
|
|
2453 | } |
|
|
2454 | |
|
|
2455 | $self->{item}{$widget} = $item; |
|
|
2456 | |
|
|
2457 | $self->{vbox}->add ($widget); |
|
|
2458 | } |
|
|
2459 | |
|
|
2460 | $self |
|
|
2461 | } |
|
|
2462 | |
|
|
2463 | # popup given the event (must be a mouse button down event currently) |
|
|
2464 | sub popup { |
|
|
2465 | my ($self, $ev) = @_; |
|
|
2466 | |
|
|
2467 | $self->emit ("popdown"); |
|
|
2468 | |
|
|
2469 | # maybe save $GRAB? must be careful about events... |
|
|
2470 | $GRAB = $self; |
|
|
2471 | $self->{button} = $ev->{button}; |
|
|
2472 | |
|
|
2473 | $self->show; |
|
|
2474 | $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); |
|
|
2475 | } |
|
|
2476 | |
|
|
2477 | sub mouse_motion { |
|
|
2478 | my ($self, $ev, $x, $y) = @_; |
|
|
2479 | |
|
|
2480 | # TODO: should use vbox->fdind_widget or so |
|
|
2481 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
|
|
2482 | $self->{hover} = $self->{item}{$HOVER}; |
|
|
2483 | } |
|
|
2484 | |
|
|
2485 | sub button_up { |
|
|
2486 | my ($self, $ev, $x, $y) = @_; |
|
|
2487 | |
|
|
2488 | if ($ev->{button} == $self->{button}) { |
|
|
2489 | undef $GRAB; |
|
|
2490 | $self->hide; |
|
|
2491 | |
|
|
2492 | $self->emit ("popdown"); |
|
|
2493 | $self->{hover}[1]->() if $self->{hover}; |
|
|
2494 | } |
|
|
2495 | } |
|
|
2496 | |
|
|
2497 | ############################################################################# |
|
|
2498 | |
2411 | package CFClient::UI::Root; |
2499 | package CFClient::UI::Root; |
2412 | |
2500 | |
2413 | our @ISA = CFClient::UI::Container::; |
2501 | our @ISA = CFClient::UI::Container::; |
2414 | |
2502 | |
2415 | use CFClient::OpenGL; |
2503 | use CFClient::OpenGL; |