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.80 by root, Wed Apr 12 00:36:13 2006 UTC vs.
Revision 1.85 by elmex, Wed Apr 12 12:55:56 2006 UTC

133 my ($self, $x, $y, $w, $h) = @_; 133 my ($self, $x, $y, $w, $h) = @_;
134 134
135 $self->_size_allocate ($x, $y, $w, $h); 135 $self->_size_allocate ($x, $y, $w, $h);
136} 136}
137 137
138# translate global koordinates to local coordinate system 138# translate global coordinates to local coordinate system
139sub translate { 139sub translate {
140 my ($self, $x, $y) = @_; 140 my ($self, $x, $y) = @_;
141 141
142 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); 142 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y});
143} 143}
637 637
638 my $bg = $tex[0]; 638 my $bg = $tex[0];
639 639
640 glBindTexture GL_TEXTURE_2D, $bg->{name}; 640 glBindTexture GL_TEXTURE_2D, $bg->{name};
641 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 641 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
642 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
643 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
644 642
645 my $rep_x = $cw / $bg->{w}; 643 my $rep_x = $cw / $bg->{w};
646 my $rep_y = $ch / $bg->{h}; 644 my $rep_y = $ch / $bg->{h};
647 645
648 $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); 646 $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch);
743 741
744 my $x = 0; 742 my $x = 0;
745 my $row_h = $hs->[$r]; 743 my $row_h = $hs->[$r];
746 744
747 for my $c (0 .. $#$row) { 745 for my $c (0 .. $#$row) {
748 my $widget = $row->[$c]
749 or next;
750
751 my $col_w = $ws->[$c]; 746 my $col_w = $ws->[$c];
752 747
748 if (my $widget = $row->[$c]) {
753 $widget->size_allocate ($x, $y, $col_w, $row_h); 749 $widget->size_allocate ($x, $y, $col_w, $row_h);
750 }
754 751
755 $x += $col_w; 752 $x += $col_w;
756 } 753 }
757 754
758 $y += $row_h; 755 $y += $row_h;
941 938
942 $self->{text} = $text; 939 $self->{text} = $text;
943 $self->{layout}->set_markup ($text); 940 $self->{layout}->set_markup ($text);
944 941
945 delete $self->{texture}; 942 delete $self->{texture};
943# $self->{w} = $self->{h} = -1;
946 $self->update; 944 $self->update;
947} 945}
948 946
949sub get_text { 947sub get_text {
950 my ($self, $text) = @_; 948 my ($self, $text) = @_;
983sub _draw { 981sub _draw {
984 my ($self) = @_; 982 my ($self) = @_;
985 983
986 my $tex = $self->{texture} ||= do { 984 my $tex = $self->{texture} ||= do {
987 $self->{layout}->set_width ($self->{w}); 985 $self->{layout}->set_width ($self->{w});
988 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{height}); 986 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height});
989 new_from_layout CFClient::Texture $self->{layout} 987 new_from_layout CFClient::Texture $self->{layout}
990 }; 988 };
991 989
992 glEnable GL_BLEND; 990 glEnable GL_BLEND;
993 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 991 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
999 my $x = 997 my $x =
1000 $self->{align} < 0 ? $self->{padding} 998 $self->{align} < 0 ? $self->{padding}
1001 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 999 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1002 : ($self->{w} - $tex->{w}) * 0.5; 1000 : ($self->{w} - $tex->{w}) * 0.5;
1003 1001
1004 $tex->draw_quad ($x, $self->{padding}); 1002 glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0;
1003 $tex->draw_quad (0, 0);
1005 1004
1006 glDisable GL_TEXTURE_2D; 1005 glDisable GL_TEXTURE_2D;
1007 glDisable GL_BLEND; 1006 glDisable GL_BLEND;
1008} 1007}
1009 1008
1033 1032
1034 $self->{last_activity} = $::NOW; 1033 $self->{last_activity} = $::NOW;
1035 1034
1036 $self->{text} = $text; 1035 $self->{text} = $text;
1037 $self->{layout}->set_width ($self->{w}); 1036 $self->{layout}->set_width ($self->{w});
1037 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height});
1038 1038
1039 $text =~ s/./*/g if $self->{hidden}; 1039 $text =~ s/./*/g if $self->{hidden};
1040 1040
1041 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1041 $self->{layout}->set_markup ($self->escape_text ($text) . " ");
1042 1042
1170our @ISA = CFClient::UI::Label::; 1170our @ISA = CFClient::UI::Label::;
1171 1171
1172use SDL; 1172use SDL;
1173use SDL::OpenGL; 1173use SDL::OpenGL;
1174 1174
1175my @tex =
1176 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1177 qw(b1_button_active.png);
1178
1175sub new { 1179sub new {
1176 my $class = shift; 1180 my $class = shift;
1177 1181
1178 $class->SUPER::new ( 1182 $class->SUPER::new (
1179 padding => 4, 1183 padding => 4,
1180 fg => [1, 1, 1], 1184 fg => [1, 1, 1],
1181 bg => [1, 1, 1, 0.2], 1185 bg => [1, 1, 1, 0.2],
1182 active_bg => [0, 0, 0, 0.5],
1183 active_fg => [1, 1, 0], 1186 active_fg => [1, 1, 0],
1187# active_bg => [0, 0, 0, 0.5],
1184 border_fg => [1, 1, 0], 1188# border_fg => [1, 1, 0],
1185 @_ 1189 @_
1186 ) 1190 )
1187} 1191}
1188 1192
1189sub button_up { 1193sub button_up {
1197 1201
1198sub _draw { 1202sub _draw {
1199 my ($self) = @_; 1203 my ($self) = @_;
1200 1204
1201 local $self->{fg} = $self->{fg}; 1205 local $self->{fg} = $self->{fg};
1206 my $tex = $tex[0];
1202 1207
1203 glEnable GL_BLEND; 1208 glEnable GL_BLEND;
1209 glEnable GL_TEXTURE_2D;
1204 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1210 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1205 1211
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) { 1212 if ($GRAB == $self) {
1217 glColor @{$self->{active_bg}};
1218 $self->{fg} = $self->{active_fg}; 1213 $self->{fg} = $self->{active_fg};
1219 } else {
1220 glColor @{$self->{bg}};
1221 } 1214 }
1222 1215
1223 glBegin GL_QUADS; 1216 glBindTexture GL_TEXTURE_2D, $tex->{name};
1224 glVertex 2 , 2; 1217 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1225 glVertex 2 , $self->{h} - 2; 1218
1226 glVertex $self->{w} - 2, $self->{h} - 2; 1219 $tex->draw_quad (0, 0, $self->{w}, $self->{h});
1227 glVertex $self->{w} - 2, 2; 1220
1228 glEnd; 1221 glDisable GL_TEXTURE_2D;
1229 glDisable GL_BLEND; 1222 glDisable GL_BLEND;
1230 1223
1231 $self->SUPER::_draw; 1224 $self->SUPER::_draw;
1232} 1225}
1233 1226
1506 my $mod = $ev->key_mod; 1499 my $mod = $ev->key_mod;
1507 my $sym = $ev->key_sym; 1500 my $sym = $ev->key_sym;
1508 1501
1509 if ($sym == SDLK_KP5) { 1502 if ($sym == SDLK_KP5) {
1510 $::CONN->send ("command stay fire"); 1503 $::CONN->send ("command stay fire");
1504 } elsif ($sym == SDLK_a) {
1505 $::CONN->send ("command apply");
1511 } elsif (exists $DIR{$sym}) { 1506 } elsif (exists $DIR{$sym}) {
1512 if ($mod & KMOD_SHIFT) { 1507 if ($mod & KMOD_SHIFT) {
1513 $self->{shft}++; 1508 $self->{shft}++;
1514 $::CONN->send ("command fire $DIR{$sym}[0]"); 1509 $::CONN->send ("command fire $DIR{$sym}[0]");
1515 } elsif ($mod & KMOD_CTRL) { 1510 } elsif ($mod & KMOD_CTRL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines