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.83 by root, Wed Apr 12 12:16:58 2006 UTC vs.
Revision 1.86 by root, Wed Apr 12 15:35:54 2006 UTC

801} 801}
802 802
803sub size_allocate { 803sub size_allocate {
804 my ($self, $x, $y, $w, $h) = @_; 804 my ($self, $x, $y, $w, $h) = @_;
805 805
806 $self->_size_allocate ($x, $y, $w, $h) or return; 806 $self->_size_allocate ($x, $y, $w, $h);
807
808 return unless $self->{w};
809 807
810 ($h, $w) = ($w, $h); 808 ($h, $w) = ($w, $h);
811 809
812 my $children = $self->{children}; 810 my $children = $self->{children};
813 811
861} 859}
862 860
863sub size_allocate { 861sub size_allocate {
864 my ($self, $x, $y, $w, $h) = @_; 862 my ($self, $x, $y, $w, $h) = @_;
865 863
866 $self->_size_allocate ($x, $y, $w, $h) or return; 864 $self->_size_allocate ($x, $y, $w, $h);
867
868 return unless $self->{h};
869 865
870 my $children = $self->{children}; 866 my $children = $self->{children};
871 867
872 my @h = map +($_->size_request)[1], @$children; 868 my @h = map +($_->size_request)[1], @$children;
873 869
997 my $x = 993 my $x =
998 $self->{align} < 0 ? $self->{padding} 994 $self->{align} < 0 ? $self->{padding}
999 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 995 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1000 : ($self->{w} - $tex->{w}) * 0.5; 996 : ($self->{w} - $tex->{w}) * 0.5;
1001 997
1002 glTranslate $x, $self->{padding}, 0; 998 glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0;
1003 $tex->draw_quad (0, 0); 999 $tex->draw_quad (0, 0);
1004 1000
1005 glDisable GL_TEXTURE_2D; 1001 glDisable GL_TEXTURE_2D;
1006 glDisable GL_BLEND; 1002 glDisable GL_BLEND;
1007} 1003}
1170our @ISA = CFClient::UI::Label::; 1166our @ISA = CFClient::UI::Label::;
1171 1167
1172use SDL; 1168use SDL;
1173use SDL::OpenGL; 1169use SDL::OpenGL;
1174 1170
1171my @tex =
1172 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1173 qw(b1_button_active.png);
1174
1175sub new { 1175sub new {
1176 my $class = shift; 1176 my $class = shift;
1177 1177
1178 $class->SUPER::new ( 1178 $class->SUPER::new (
1179 padding => 4, 1179 padding => 4,
1180 fg => [1, 1, 1], 1180 fg => [1, 1, 1],
1181 bg => [1, 1, 1, 0.2], 1181 bg => [1, 1, 1, 0.2],
1182 active_bg => [0, 0, 0, 0.5],
1183 active_fg => [1, 1, 0], 1182 active_fg => [1, 1, 0],
1183# active_bg => [0, 0, 0, 0.5],
1184 border_fg => [1, 1, 0], 1184# border_fg => [1, 1, 0],
1185 @_ 1185 @_
1186 ) 1186 )
1187} 1187}
1188 1188
1189sub button_up { 1189sub button_up {
1197 1197
1198sub _draw { 1198sub _draw {
1199 my ($self) = @_; 1199 my ($self) = @_;
1200 1200
1201 local $self->{fg} = $self->{fg}; 1201 local $self->{fg} = $self->{fg};
1202 my $tex = $tex[0];
1202 1203
1203 glEnable GL_BLEND; 1204 glEnable GL_BLEND;
1205 glEnable GL_TEXTURE_2D;
1204 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1206 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1205 1207
1206 glTranslate 0.375, 0.375, 0; # make line and polyogon coordinates behave similarly
1207
1208 glBegin GL_LINE_LOOP;
1209 glColor @{$self->{border_fg}};
1210 glVertex 1 , 1;
1211 glVertex 1 , $self->{h} - 2;
1212 glVertex $self->{w} - 2, $self->{h} - 2;
1213 glVertex $self->{w} - 2, 1;
1214 glEnd;
1215
1216 if ($GRAB == $self) { 1208 if ($GRAB == $self) {
1217 glColor @{$self->{active_bg}};
1218 $self->{fg} = $self->{active_fg}; 1209 $self->{fg} = $self->{active_fg};
1219 } else { 1210 }
1220 glColor @{$self->{bg}}; 1211
1212 glBindTexture GL_TEXTURE_2D, $tex->{name};
1213 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1214
1215 $tex->draw_quad (0, 0, $self->{w}, $self->{h});
1216
1217 glDisable GL_TEXTURE_2D;
1218 glDisable GL_BLEND;
1219
1220 $self->SUPER::_draw;
1221}
1222
1223#############################################################################
1224
1225package CFClient::UI::CheckBox;
1226
1227our @ISA = CFClient::UI::DrawBG::;
1228
1229use SDL;
1230use SDL::OpenGL;
1231
1232my @tex =
1233 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1234 qw(b1_button_active.png);
1235
1236sub new {
1237 my $class = shift;
1238
1239 $class->SUPER::new (
1240 padding => 4,
1241 fg => [1, 1, 1],
1242 active_fg => [1, 1, 0],
1243 state => 0,
1244 @_
1221 } 1245 )
1246}
1222 1247
1223 glBegin GL_QUADS; 1248sub button_down {
1224 glVertex 2 , 2; 1249 my ($self, $ev, $x, $y) = @_;
1225 glVertex 2 , $self->{h} - 2; 1250
1226 glVertex $self->{w} - 2, $self->{h} - 2; 1251 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding}
1227 glVertex $self->{w} - 2, 2; 1252 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) {
1228 glEnd; 1253 $self->{state} = !$self->{state};
1254 $self->emit ("changed");
1255 }
1256}
1257
1258sub _draw {
1259 my ($self) = @_;
1260
1261 local $self->{fg} = $self->{fg};
1262 my $tex = $tex[0];
1263
1264 glEnable GL_BLEND;
1265 glEnable GL_TEXTURE_2D;
1266 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1267
1268 if ($GRAB == $self) {
1269 $self->{fg} = $self->{active_fg};
1270 }
1271
1272 glBindTexture GL_TEXTURE_2D, $tex->{name};
1273 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1274
1275 $tex->draw_quad (0, 0, $self->{w}, $self->{h});
1276
1277 glDisable GL_TEXTURE_2D;
1229 glDisable GL_BLEND; 1278 glDisable GL_BLEND;
1230 1279
1231 $self->SUPER::_draw; 1280 $self->SUPER::_draw;
1232} 1281}
1233 1282
1506 my $mod = $ev->key_mod; 1555 my $mod = $ev->key_mod;
1507 my $sym = $ev->key_sym; 1556 my $sym = $ev->key_sym;
1508 1557
1509 if ($sym == SDLK_KP5) { 1558 if ($sym == SDLK_KP5) {
1510 $::CONN->send ("command stay fire"); 1559 $::CONN->send ("command stay fire");
1560 } elsif ($sym == SDLK_a) {
1561 $::CONN->send ("command apply");
1511 } elsif (exists $DIR{$sym}) { 1562 } elsif (exists $DIR{$sym}) {
1512 if ($mod & KMOD_SHIFT) { 1563 if ($mod & KMOD_SHIFT) {
1513 $self->{shft}++; 1564 $self->{shft}++;
1514 $::CONN->send ("command fire $DIR{$sym}[0]"); 1565 $::CONN->send ("command fire $DIR{$sym}[0]");
1515 } elsif ($mod & KMOD_CTRL) { 1566 } elsif ($mod & KMOD_CTRL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines