ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.174 by root, Tue Apr 25 11:18:49 2006 UTC vs.
Revision 1.176 by root, Tue Apr 25 12:10:58 2006 UTC

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
677sub _draw { 684sub _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
800sub border { 807sub border {
825} 832}
826 833
827sub button_down { 834sub 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) = @_;
2076 (new CFClient::UI::Empty expand => 1), 2089 (new CFClient::UI::Empty expand => 1),
2077 (new CFClient::UI::Slider vertical => 1), 2090 (new CFClient::UI::Slider vertical => 1),
2078 ], 2091 ],
2079 ); 2092 );
2080 2093
2081 $self->{children}[1]->connect (changed => sub { 2094 $self->{children}[1]->connect (changed => sub { $self->update });
2082 $self->update;
2083 });
2084 2095
2085 $self 2096 $self
2086} 2097}
2087 2098
2088sub set_fontsize { 2099sub set_fontsize {
2096 my ($self, $text) = @_; 2107 my ($self, $text) = @_;
2097 2108
2098 my $layout = $self->{layout}; 2109 my $layout = $self->{layout};
2099 2110
2100 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2111 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2101 $layout->set_width ($self->{w}); 2112 $layout->set_width ($self->{children}[0]{w});
2102 $layout->set_text ($text); 2113 $layout->set_text ($text);
2103 2114
2104 ($layout->size)[1] 2115 ($layout->size)[1]
2105} 2116}
2106 2117
2159 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2170 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2160 2171
2161 delete $self->{texture}; 2172 delete $self->{texture};
2162 } 2173 }
2163 2174
2164 $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 {
2165 glClearColor 0, 0, 0, 1; 2176 glClearColor 0, 0, 0, 0;
2166 glClear GL_COLOR_BUFFER_BIT; 2177 glClear GL_COLOR_BUFFER_BIT;
2167 2178
2168 glEnable GL_BLEND; 2179 glEnable GL_BLEND;
2169 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2180 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2170 glEnable GL_TEXTURE_2D; 2181 glEnable GL_TEXTURE_2D;
2202} 2213}
2203 2214
2204sub _draw { 2215sub _draw {
2205 my ($self) = @_; 2216 my ($self) = @_;
2206 2217
2207 if ($self->{texture}) { 2218 glEnable GL_BLEND;
2219 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2208 glEnable GL_TEXTURE_2D; 2220 glEnable GL_TEXTURE_2D;
2209 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2221 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2210 glColor 1, 1, 1, 1; 2222 glColor 1, 1, 1, 1;
2211 $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});
2212 glDisable GL_TEXTURE_2D; 2224 glDisable GL_TEXTURE_2D;
2213 } 2225 glDisable GL_BLEND;
2214 2226
2215 $self->{children}[1]->draw; 2227 $self->{children}[1]->draw;
2216 2228
2217} 2229}
2218 2230

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines