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.120 by elmex, Sun Apr 16 17:43:17 2006 UTC vs.
Revision 1.123 by root, Mon Apr 17 19:50:22 2006 UTC

225 glPopMatrix; 225 glPopMatrix;
226 226
227 if ($self == $HOVER && $self->{can_hover}) { 227 if ($self == $HOVER && $self->{can_hover}) {
228 my ($x, $y) = @$self{qw(x y)}; 228 my ($x, $y) = @$self{qw(x y)};
229 229
230 glColor 0, 0, 1, 0.2; 230 glColor 1, 0.8, 0.5, 0.2;
231 glEnable GL_BLEND; 231 glEnable GL_BLEND;
232 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 232 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
233 glBegin GL_QUADS; 233 glBegin GL_QUADS;
234 glVertex $x , $y; 234 glVertex $x , $y;
235 glVertex $x + $self->{w}, $y; 235 glVertex $x + $self->{w}, $y;
962 padding => 2, 962 padding => 2,
963 layout => new CFClient::Layout, 963 layout => new CFClient::Layout,
964 %arg 964 %arg
965 ); 965 );
966 966
967 $self->set_text ($self->{text}); 967 $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d#
968
969 $self->set_text (delete $self->{text}) if exists $self->{text};
970 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
968 971
969 $self 972 $self
970} 973}
971 974
972sub escape_text { 975sub escape_text {
980} 983}
981 984
982sub set_text { 985sub set_text {
983 my ($self, $text) = @_; 986 my ($self, $text) = @_;
984 987
985 $self->{text} = $text;
986 $self->{layout}->set_markup ($text); 988 $self->{layout}->set_text ($text);
987 989
988 delete $self->{texture}; 990 delete $self->{texture};
989# $self->{w} = $self->{h} = -1;
990 $self->update; 991 $self->update;
991} 992}
992 993
993sub get_text { 994sub set_markup {
994 my ($self, $text) = @_; 995 my ($self, $markup) = @_;
995 996
996 $self->{text} 997 $self->{layout}->set_markup ($markup);
998
999 delete $self->{texture};
1000 $self->update;
997} 1001}
998 1002
999sub size_request { 1003sub size_request {
1000 my ($self) = @_; 1004 my ($self) = @_;
1001 1005
1002 $self->{layout}->set_width; 1006 $self->{layout}->set_width;
1003 $self->{layout}->set_height ($self->{fontsize}); 1007 $self->{layout}->set_height ($self->{fontsize});
1008
1004 my ($w, $h) = $self->{layout}->size; 1009 my ($w, $h) = $self->{layout}->size;
1005 1010
1006 ( 1011 (
1007 $w + $self->{padding} * 2, 1012 $w + $self->{padding} * 2,
1008 $h + $self->{padding} * 2, 1013 $h + $self->{padding} * 2,
1027sub _draw { 1032sub _draw {
1028 my ($self) = @_; 1033 my ($self) = @_;
1029 1034
1030 my $tex = $self->{texture} ||= do { 1035 my $tex = $self->{texture} ||= do {
1031 $self->{layout}->set_width ($self->{w}); 1036 $self->{layout}->set_width ($self->{w});
1032 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); 1037 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize});
1033 new_from_layout CFClient::Texture $self->{layout} 1038 new_from_layout CFClient::Texture $self->{layout}
1034 }; 1039 };
1035 1040
1036 glEnable GL_BLEND; 1041 glEnable GL_BLEND;
1037 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1042 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1038 glEnable GL_TEXTURE_2D; 1043 glEnable GL_TEXTURE_2D;
1039 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1044 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1040 1045
1041 glColor @{$self->{fg}}; 1046 glColor @{$self->{fg}};
1042 1047
1043 my $x = 1048 $self->{ox} = int (
1044 $self->{align} < 0 ? $self->{padding} 1049 $self->{align} < 0 ? $self->{padding}
1045 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1050 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1046 : ($self->{w} - $tex->{w}) * 0.5; 1051 : ($self->{w} - $tex->{w}) * 0.5
1052 );
1047 1053
1048 my $y = 1054 $self->{oy} = int (
1049 $self->{valign} < 0 ? $self->{padding} 1055 $self->{valign} < 0 ? $self->{padding}
1050 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1056 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1051 : ($self->{h} - $tex->{h}) * 0.5; 1057 : ($self->{h} - $tex->{h}) * 0.5
1058 );
1052 1059
1053 $tex->draw_quad (int $x, int $y); 1060 $tex->draw_quad ($self->{ox}, $self->{oy});
1054 1061
1055 glDisable GL_TEXTURE_2D; 1062 glDisable GL_TEXTURE_2D;
1056 glDisable GL_BLEND; 1063 glDisable GL_BLEND;
1057} 1064}
1058 1065
1059############################################################################# 1066#############################################################################
1060 1067
1061package CFClient::UI::Entry; 1068package CFClient::UI::EntryBase;
1062 1069
1063our @ISA = CFClient::UI::Label::; 1070our @ISA = CFClient::UI::Label::;
1064 1071
1065use SDL; 1072use SDL;
1066use SDL::OpenGL; 1073use SDL::OpenGL;
1081} 1088}
1082 1089
1083sub _set_text { 1090sub _set_text {
1084 my ($self, $text) = @_; 1091 my ($self, $text) = @_;
1085 1092
1086 my $old_text = $self->{text}; 1093 delete $self->{cur_h};
1094
1095 return if $self->{text} eq $text;
1087 1096
1088 $self->{last_activity} = $::NOW; 1097 $self->{last_activity} = $::NOW;
1089
1090 $self->{text} = $text; 1098 $self->{text} = $text;
1091 $self->{layout}->set_width ($self->{w});
1092 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1093 1099
1094 $text =~ s/./*/g if $self->{hidden}; 1100 $text =~ s/./*/g if $self->{hidden};
1101 $self->{layout}->set_text ("$text ");
1095 1102
1096 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1103 $self->emit (changed => $self->{text});
1104}
1097 1105
1098 $text = substr $text, 0, $self->{cursor}; 1106sub get_text {
1099 utf8::encode $text; 1107 $_[0]{text}
1100
1101 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
1102
1103 $self->emit (changed => $self->{text}) # XXX: is this the right place to do this?
1104 if $old_text ne $self->{text};
1105} 1108}
1106 1109
1107sub size_request { 1110sub size_request {
1108 my ($self) = @_; 1111 my ($self) = @_;
1109 1112
1213 1216
1214 $self->SUPER::_draw; 1217 $self->SUPER::_draw;
1215 1218
1216 #TODO: force update every cursor change :( 1219 #TODO: force update every cursor change :(
1217 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1220 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1221
1222 unless (exists $self->{cur_h}) {
1223 my $text = substr $self->{text}, 0, $self->{cursor};
1224 utf8::encode $text;
1225
1226 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1227 }
1228
1218 glColor @{$self->{fg}}; 1229 glColor @{$self->{fg}};
1219 glBegin GL_LINES; 1230 glBegin GL_LINES;
1220 glVertex $self->{cur_x}, $self->{cur_y};
1221 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1231 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1232 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1222 glEnd; 1233 glEnd;
1223 } 1234 }
1224} 1235}
1225 1236
1226package CFClient::UI::LineEntry; 1237package CFClient::UI::Entry;
1227 1238
1228our @ISA = CFClient::UI::Entry::; 1239our @ISA = CFClient::UI::EntryBase::;
1229 1240
1230use SDL; 1241use SDL;
1231use SDL::OpenGL; 1242use SDL::OpenGL;
1232 1243
1233sub key_down { 1244sub key_down {
1263 1274
1264 $class->SUPER::new ( 1275 $class->SUPER::new (
1265 padding => 4, 1276 padding => 4,
1266 fg => [1, 1, 1], 1277 fg => [1, 1, 1],
1267 bg => [1, 1, 1, 0.2], 1278 bg => [1, 1, 1, 0.2],
1268 active_fg => [1, 1, 0], 1279 active_fg => [0, 0, 1],
1269 can_hover => 1, 1280 can_hover => 1,
1270 @_ 1281 @_
1271 ) 1282 )
1272} 1283}
1273 1284
1875 1886
1876 my $mod = $ev->key_mod; 1887 my $mod = $ev->key_mod;
1877 my $sym = $ev->key_sym; 1888 my $sym = $ev->key_sym;
1878 1889
1879 if ($sym == SDLK_KP5) { 1890 if ($sym == SDLK_KP5) {
1880 $::CONN->user_send ("command stay fire"); 1891 $::CONN->user_send ("stay fire");
1881 } elsif ($sym == SDLK_a) { 1892 } elsif ($sym == SDLK_a) {
1882 $::CONN->user_send ("command apply"); 1893 $::CONN->user_send ("apply");
1883 } elsif ($sym == SDLK_QUOTE) { 1894 } elsif ($sym == SDLK_QUOTE) {
1884 $self->emit ('activate_console'); 1895 $self->emit ('activate_console');
1885 } elsif ($sym == SDLK_SLASH) { 1896 } elsif ($sym == SDLK_SLASH) {
1886 $self->emit ('activate_console' => '/'); 1897 $self->emit ('activate_console' => '/');
1887 } elsif (exists $DIR{$sym}) { 1898 } elsif (exists $DIR{$sym}) {
1888 if ($mod & KMOD_SHIFT) { 1899 if ($mod & KMOD_SHIFT) {
1889 $self->{shft}++; 1900 $self->{shft}++;
1890 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 1901 $::CONN->user_send ("fire $DIR{$sym}[0]");
1891 } elsif ($mod & KMOD_CTRL) { 1902 } elsif ($mod & KMOD_CTRL) {
1892 $self->{ctrl}++; 1903 $self->{ctrl}++;
1893 $::CONN->user_send ("command run $DIR{$sym}[0]"); 1904 $::CONN->user_send ("run $DIR{$sym}[0]");
1894 } else { 1905 } else {
1895 $::CONN->user_send ("command $DIR{$sym}[1]"); 1906 $::CONN->user_send ("$DIR{$sym}[1]");
1896 } 1907 }
1897 } 1908 }
1898} 1909}
1899 1910
1900sub key_up { 1911sub key_up {
1902 1913
1903 my $mod = $ev->key_mod; 1914 my $mod = $ev->key_mod;
1904 my $sym = $ev->key_sym; 1915 my $sym = $ev->key_sym;
1905 1916
1906 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 1917 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1907 $::CONN->user_send ("command fire_stop"); 1918 $::CONN->user_send ("fire_stop");
1908 } 1919 }
1909 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 1920 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1910 $::CONN->user_send ("command run_stop"); 1921 $::CONN->user_send ("run_stop");
1911 } 1922 }
1912} 1923}
1913 1924
1914############################################################################# 1925#############################################################################
1915 1926

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines