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.175 by root, Tue Apr 25 11:48:31 2006 UTC vs.
Revision 1.176 by root, Tue Apr 25 12:10:58 2006 UTC

788 # TODO: user_x, user_y, overwrite moveto? 788 # TODO: user_x, user_y, overwrite moveto?
789 789
790 my $self = $class->SUPER::new ( 790 my $self = $class->SUPER::new (
791 bg => [1, 1, 1, 1], 791 bg => [1, 1, 1, 1],
792 border_bg => [1, 1, 1, 1], 792 border_bg => [1, 1, 1, 1],
793 border => 0.8, 793 border => 0.6,
794 can_events => 1, 794 can_events => 1,
795 @_ 795 @_
796 ); 796 );
797 797
798 $self->{title} &&= new CFClient::UI::Label 798 $self->{title} &&= new CFClient::UI::Label
799 align => 0, 799 align => 0,
800 valign => 1, 800 valign => 1,
801 text => $self->{title}, 801 text => $self->{title},
802 fontsize => 1; 802 fontsize => $self->{border};
803 803
804 $self 804 $self
805} 805}
806 806
807sub border { 807sub border {
832} 832}
833 833
834sub button_down { 834sub button_down {
835 my ($self, $ev, $x, $y) = @_; 835 my ($self, $ev, $x, $y) = @_;
836 836
837 my ($w, $h) = @$self{qw(w h)};
837 my $border = $self->border; 838 my $border = $self->border;
838 839
839 if ($x < $self->{w} && $x >= $self->{w} - $border 840 my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w);
840 && $y < $self->{h} && $y >= $self->{h} - $border) { 841 my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h);
841 842
843 if ($lr & $td) {
844 my ($wx, $wy) = ($self->{x}, $self->{y});
842 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 845 my ($ox, $oy) = ($ev->{x}, $ev->{y});
843 my ($bw, $bh) = ($self->{w}, $self->{h}); 846 my ($bw, $bh) = ($self->{w}, $self->{h});
844 847
848 my $mx = $x < $border;
849 my $my = $y < $border;
850
845 $self->{motion} = sub { 851 $self->{motion} = sub {
846 my ($ev, $x, $y) = @_; 852 my ($ev, $x, $y) = @_;
847 853
848 ($x, $y) = ($ev->{x}, $ev->{y}); 854 my $dx = $ev->{x} - $ox;
855 my $dy = $ev->{y} - $oy;
849 856
850 $self->{user_w} = $bw + $x - $ox; 857 $self->{user_w} = $bw + $dx * ($mx ? -1 : 1);
851 $self->{user_h} = $bh + $y - $oy; 858 $self->{user_h} = $bh + $dy * ($my ? -1 : 1);
859 $self->move ($wx + $dx * $mx, $wy + $dy * $my);
852 $self->check_size; 860 $self->check_size;
853 }; 861 };
854 862
855 } elsif ($x >= 0 && $x < $self->{w} 863 } elsif ($lr ^ $td) {
856 && $y >= 0 && $y < $border) {
857
858 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 864 my ($ox, $oy) = ($ev->{x}, $ev->{y});
859 my ($bx, $by) = ($self->{x}, $self->{y}); 865 my ($bx, $by) = ($self->{x}, $self->{y});
860 866
861 $self->{motion} = sub { 867 $self->{motion} = sub {
862 my ($ev, $x, $y) = @_; 868 my ($ev, $x, $y) = @_;
2083 (new CFClient::UI::Empty expand => 1), 2089 (new CFClient::UI::Empty expand => 1),
2084 (new CFClient::UI::Slider vertical => 1), 2090 (new CFClient::UI::Slider vertical => 1),
2085 ], 2091 ],
2086 ); 2092 );
2087 2093
2088 $self->{children}[1]->connect (changed => sub { 2094 $self->{children}[1]->connect (changed => sub { $self->update });
2089 $self->update;
2090 });
2091 2095
2092 $self 2096 $self
2093} 2097}
2094 2098
2095sub set_fontsize { 2099sub set_fontsize {
2103 my ($self, $text) = @_; 2107 my ($self, $text) = @_;
2104 2108
2105 my $layout = $self->{layout}; 2109 my $layout = $self->{layout};
2106 2110
2107 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2111 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2108 $layout->set_width ($self->{w}); 2112 $layout->set_width ($self->{children}[0]{w});
2109 $layout->set_text ($text); 2113 $layout->set_text ($text);
2110 2114
2111 ($layout->size)[1] 2115 ($layout->size)[1]
2112} 2116}
2113 2117
2166 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2170 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2167 2171
2168 delete $self->{texture}; 2172 delete $self->{texture};
2169 } 2173 }
2170 2174
2171 $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 {
2172 glClearColor 0, 0, 0, 0; 2176 glClearColor 0, 0, 0, 0;
2173 glClear GL_COLOR_BUFFER_BIT; 2177 glClear GL_COLOR_BUFFER_BIT;
2174 2178
2175 glEnable GL_BLEND; 2179 glEnable GL_BLEND;
2176 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2180 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2209} 2213}
2210 2214
2211sub _draw { 2215sub _draw {
2212 my ($self) = @_; 2216 my ($self) = @_;
2213 2217
2214 if ($self->{texture}) {
2215 glEnable GL_BLEND; 2218 glEnable GL_BLEND;
2216 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2219 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2217 glEnable GL_TEXTURE_2D; 2220 glEnable GL_TEXTURE_2D;
2218 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2221 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2219 glColor 1, 1, 1, 1; 2222 glColor 1, 1, 1, 1;
2220 $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});
2221 glDisable GL_TEXTURE_2D; 2224 glDisable GL_TEXTURE_2D;
2222 glDisable GL_BLEND; 2225 glDisable GL_BLEND;
2223 }
2224 2226
2225 $self->{children}[1]->draw; 2227 $self->{children}[1]->draw;
2226 2228
2227} 2229}
2228 2230

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines