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.117 by root, Sat Apr 15 22:55:59 2006 UTC vs.
Revision 1.123 by root, Mon Apr 17 19:50:22 2006 UTC

176 176
177 return if $FOCUS == $self; 177 return if $FOCUS == $self;
178 return unless $self->{can_focus}; 178 return unless $self->{can_focus};
179 179
180 my $focus = $FOCUS; $FOCUS = $self; 180 my $focus = $FOCUS; $FOCUS = $self;
181
182 $self->emit (focus_in => $focus);
183
181 $focus->update if $focus; 184 $focus->update if $focus;
182 $FOCUS->update; 185 $FOCUS->update;
183} 186}
184 187
185sub focus_out { 188sub focus_out {
186 my ($self) = @_; 189 my ($self) = @_;
187 190
188 return unless $FOCUS == $self; 191 return unless $FOCUS == $self;
189 192
190 my $focus = $FOCUS; undef $FOCUS; 193 my $focus = $FOCUS; undef $FOCUS;
194
195 $self->emit (focus_out => $focus);
196
191 $focus->update if $focus; #? 197 $focus->update if $focus; #?
192} 198}
193 199
194sub mouse_motion { } 200sub mouse_motion { }
195sub button_up { } 201sub button_up { }
219 glPopMatrix; 225 glPopMatrix;
220 226
221 if ($self == $HOVER && $self->{can_hover}) { 227 if ($self == $HOVER && $self->{can_hover}) {
222 my ($x, $y) = @$self{qw(x y)}; 228 my ($x, $y) = @$self{qw(x y)};
223 229
224 glColor 0, 0, 1, 0.2; 230 glColor 1, 0.8, 0.5, 0.2;
225 glEnable GL_BLEND; 231 glEnable GL_BLEND;
226 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 232 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
227 glBegin GL_QUADS; 233 glBegin GL_QUADS;
228 glVertex $x , $y; 234 glVertex $x , $y;
229 glVertex $x + $self->{w}, $y; 235 glVertex $x + $self->{w}, $y;
956 padding => 2, 962 padding => 2,
957 layout => new CFClient::Layout, 963 layout => new CFClient::Layout,
958 %arg 964 %arg
959 ); 965 );
960 966
961 $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};
962 971
963 $self 972 $self
964} 973}
965 974
966sub escape_text { 975sub escape_text {
974} 983}
975 984
976sub set_text { 985sub set_text {
977 my ($self, $text) = @_; 986 my ($self, $text) = @_;
978 987
979 $self->{text} = $text;
980 $self->{layout}->set_markup ($text); 988 $self->{layout}->set_text ($text);
981 989
982 delete $self->{texture}; 990 delete $self->{texture};
983# $self->{w} = $self->{h} = -1;
984 $self->update; 991 $self->update;
985} 992}
986 993
987sub get_text { 994sub set_markup {
988 my ($self, $text) = @_; 995 my ($self, $markup) = @_;
989 996
990 $self->{text} 997 $self->{layout}->set_markup ($markup);
998
999 delete $self->{texture};
1000 $self->update;
991} 1001}
992 1002
993sub size_request { 1003sub size_request {
994 my ($self) = @_; 1004 my ($self) = @_;
995 1005
996 $self->{layout}->set_width; 1006 $self->{layout}->set_width;
997 $self->{layout}->set_height ($self->{fontsize}); 1007 $self->{layout}->set_height ($self->{fontsize});
1008
998 my ($w, $h) = $self->{layout}->size; 1009 my ($w, $h) = $self->{layout}->size;
999 1010
1000 ( 1011 (
1001 $w + $self->{padding} * 2, 1012 $w + $self->{padding} * 2,
1002 $h + $self->{padding} * 2, 1013 $h + $self->{padding} * 2,
1021sub _draw { 1032sub _draw {
1022 my ($self) = @_; 1033 my ($self) = @_;
1023 1034
1024 my $tex = $self->{texture} ||= do { 1035 my $tex = $self->{texture} ||= do {
1025 $self->{layout}->set_width ($self->{w}); 1036 $self->{layout}->set_width ($self->{w});
1026 $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});
1027 new_from_layout CFClient::Texture $self->{layout} 1038 new_from_layout CFClient::Texture $self->{layout}
1028 }; 1039 };
1029 1040
1030 glEnable GL_BLEND; 1041 glEnable GL_BLEND;
1031 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1042 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1032 glEnable GL_TEXTURE_2D; 1043 glEnable GL_TEXTURE_2D;
1033 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1044 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1034 1045
1035 glColor @{$self->{fg}}; 1046 glColor @{$self->{fg}};
1036 1047
1037 my $x = 1048 $self->{ox} = int (
1038 $self->{align} < 0 ? $self->{padding} 1049 $self->{align} < 0 ? $self->{padding}
1039 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1050 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1040 : ($self->{w} - $tex->{w}) * 0.5; 1051 : ($self->{w} - $tex->{w}) * 0.5
1052 );
1041 1053
1042 my $y = 1054 $self->{oy} = int (
1043 $self->{valign} < 0 ? $self->{padding} 1055 $self->{valign} < 0 ? $self->{padding}
1044 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1056 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1045 : ($self->{h} - $tex->{h}) * 0.5; 1057 : ($self->{h} - $tex->{h}) * 0.5
1058 );
1046 1059
1047 $tex->draw_quad (int $x, int $y); 1060 $tex->draw_quad ($self->{ox}, $self->{oy});
1048 1061
1049 glDisable GL_TEXTURE_2D; 1062 glDisable GL_TEXTURE_2D;
1050 glDisable GL_BLEND; 1063 glDisable GL_BLEND;
1051} 1064}
1052 1065
1053############################################################################# 1066#############################################################################
1054 1067
1055package CFClient::UI::Entry; 1068package CFClient::UI::EntryBase;
1056 1069
1057our @ISA = CFClient::UI::Label::; 1070our @ISA = CFClient::UI::Label::;
1058 1071
1059use SDL; 1072use SDL;
1060use SDL::OpenGL; 1073use SDL::OpenGL;
1075} 1088}
1076 1089
1077sub _set_text { 1090sub _set_text {
1078 my ($self, $text) = @_; 1091 my ($self, $text) = @_;
1079 1092
1080 my $old_text = $self->{text}; 1093 delete $self->{cur_h};
1094
1095 return if $self->{text} eq $text;
1081 1096
1082 $self->{last_activity} = $::NOW; 1097 $self->{last_activity} = $::NOW;
1083
1084 $self->{text} = $text; 1098 $self->{text} = $text;
1085 $self->{layout}->set_width ($self->{w});
1086 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1087 1099
1088 $text =~ s/./*/g if $self->{hidden}; 1100 $text =~ s/./*/g if $self->{hidden};
1101 $self->{layout}->set_text ("$text ");
1089 1102
1090 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1103 $self->emit (changed => $self->{text});
1104}
1091 1105
1092 $text = substr $text, 0, $self->{cursor}; 1106sub get_text {
1093 utf8::encode $text; 1107 $_[0]{text}
1094
1095 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
1096
1097 $self->emit (changed => $self->{text}) # XXX: is this the right place to do this?
1098 if $old_text ne $self->{text};
1099} 1108}
1100 1109
1101sub size_request { 1110sub size_request {
1102 my ($self) = @_; 1111 my ($self) = @_;
1103 1112
1207 1216
1208 $self->SUPER::_draw; 1217 $self->SUPER::_draw;
1209 1218
1210 #TODO: force update every cursor change :( 1219 #TODO: force update every cursor change :(
1211 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
1212 glColor @{$self->{fg}}; 1229 glColor @{$self->{fg}};
1213 glBegin GL_LINES; 1230 glBegin GL_LINES;
1214 glVertex $self->{cur_x}, $self->{cur_y};
1215 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};
1216 glEnd; 1233 glEnd;
1217 } 1234 }
1218} 1235}
1219 1236
1220package CFClient::UI::LineEntry; 1237package CFClient::UI::Entry;
1221 1238
1222our @ISA = CFClient::UI::Entry::; 1239our @ISA = CFClient::UI::EntryBase::;
1223 1240
1224use SDL; 1241use SDL;
1225use SDL::OpenGL; 1242use SDL::OpenGL;
1226 1243
1227sub key_down { 1244sub key_down {
1257 1274
1258 $class->SUPER::new ( 1275 $class->SUPER::new (
1259 padding => 4, 1276 padding => 4,
1260 fg => [1, 1, 1], 1277 fg => [1, 1, 1],
1261 bg => [1, 1, 1, 0.2], 1278 bg => [1, 1, 1, 0.2],
1262 active_fg => [1, 1, 0], 1279 active_fg => [0, 0, 1],
1263 can_hover => 1, 1280 can_hover => 1,
1264 @_ 1281 @_
1265 ) 1282 )
1266} 1283}
1267 1284
1276 1293
1277sub _draw { 1294sub _draw {
1278 my ($self) = @_; 1295 my ($self) = @_;
1279 1296
1280 local $self->{fg} = $self->{fg}; 1297 local $self->{fg} = $self->{fg};
1281 my $tex = $tex[0];
1282
1283 glEnable GL_BLEND;
1284 glEnable GL_TEXTURE_2D;
1285 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1286 1298
1287 if ($GRAB == $self) { 1299 if ($GRAB == $self) {
1288 $self->{fg} = $self->{active_fg}; 1300 $self->{fg} = $self->{active_fg};
1289 } 1301 }
1290 1302
1291 glBindTexture GL_TEXTURE_2D, $tex->{name}; 1303 glEnable GL_BLEND;
1304 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1305 glEnable GL_TEXTURE_2D;
1292 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1306 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1307 glColor 0, 0, 0, 1;
1293 1308
1294 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 1309 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h});
1295 1310
1296 glDisable GL_TEXTURE_2D; 1311 glDisable GL_TEXTURE_2D;
1297 glDisable GL_BLEND; 1312 glDisable GL_BLEND;
1298 1313
1299 $self->SUPER::_draw; 1314 $self->SUPER::_draw;
1781 0.1, 0.1, 0.1, 1796 0.1, 0.1, 0.1,
1782 ; 1797 ;
1783 glEnable GL_CONVOLUTION_2D; 1798 glEnable GL_CONVOLUTION_2D;
1784 } 1799 }
1785 1800
1786 my $tex = new CFClient::Texture 1801 $self->{fow_texture} = new CFClient::Texture
1787 w => $w, 1802 w => $w,
1788 h => $h, 1803 h => $h,
1789 data => $data, 1804 data => $data,
1790 internalformat => GL_ALPHA, 1805 internalformat => GL_ALPHA,
1791 format => GL_ALPHA; 1806 format => GL_ALPHA;
1796 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1811 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1797 glEnable GL_TEXTURE_2D; 1812 glEnable GL_TEXTURE_2D;
1798 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1813 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1799 1814
1800 glColor +($::CFG->{fow_intensity}) x 3, 1; 1815 glColor +($::CFG->{fow_intensity}) x 3, 1;
1801 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1816 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1802 1817
1803 glDisable GL_TEXTURE_2D; 1818 glDisable GL_TEXTURE_2D;
1804 glDisable GL_BLEND; 1819 glDisable GL_BLEND;
1805 } 1820 }
1806 1821
1812 glEnable GL_BLEND; 1827 glEnable GL_BLEND;
1813 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1828 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1814 glEnable GL_TEXTURE_2D; 1829 glEnable GL_TEXTURE_2D;
1815 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1830 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1816 1831
1832 $self->{mapmap_texture} =
1817 CFClient::Texture->new ( 1833 new CFClient::Texture
1818 w => $w, 1834 w => $w,
1819 h => $h, 1835 h => $h,
1820 data => $::MAP->mapmap ($w, $h), 1836 data => $::MAP->mapmap ($w, $h),
1821 type => GL_UNSIGNED_INT_8_8_8_8_REV 1837 type => GL_UNSIGNED_INT_8_8_8_8_REV;
1822 )->draw_quad (100, 100); 1838
1839 $self->{mapmap_texture}->draw_quad (100, 100);
1823 1840
1824 glDisable GL_TEXTURE_2D; 1841 glDisable GL_TEXTURE_2D;
1825 glDisable GL_BLEND; 1842 glDisable GL_BLEND;
1826 } 1843 }
1827 # HACK END 1844 # HACK END
1869 1886
1870 my $mod = $ev->key_mod; 1887 my $mod = $ev->key_mod;
1871 my $sym = $ev->key_sym; 1888 my $sym = $ev->key_sym;
1872 1889
1873 if ($sym == SDLK_KP5) { 1890 if ($sym == SDLK_KP5) {
1874 $::CONN->user_send ("command stay fire"); 1891 $::CONN->user_send ("stay fire");
1875 } elsif ($sym == SDLK_a) { 1892 } elsif ($sym == SDLK_a) {
1876 $::CONN->user_send ("command apply"); 1893 $::CONN->user_send ("apply");
1877 } elsif ($sym == SDLK_QUOTE) { 1894 } elsif ($sym == SDLK_QUOTE) {
1878 $self->emit ('activate_console'); 1895 $self->emit ('activate_console');
1879 } elsif ($sym == SDLK_SLASH) { 1896 } elsif ($sym == SDLK_SLASH) {
1880 $self->emit ('activate_console' => '/'); 1897 $self->emit ('activate_console' => '/');
1881 } elsif (exists $DIR{$sym}) { 1898 } elsif (exists $DIR{$sym}) {
1882 if ($mod & KMOD_SHIFT) { 1899 if ($mod & KMOD_SHIFT) {
1883 $self->{shft}++; 1900 $self->{shft}++;
1884 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 1901 $::CONN->user_send ("fire $DIR{$sym}[0]");
1885 } elsif ($mod & KMOD_CTRL) { 1902 } elsif ($mod & KMOD_CTRL) {
1886 $self->{ctrl}++; 1903 $self->{ctrl}++;
1887 $::CONN->user_send ("command run $DIR{$sym}[0]"); 1904 $::CONN->user_send ("run $DIR{$sym}[0]");
1888 } else { 1905 } else {
1889 $::CONN->user_send ("command $DIR{$sym}[1]"); 1906 $::CONN->user_send ("$DIR{$sym}[1]");
1890 } 1907 }
1891 } 1908 }
1892} 1909}
1893 1910
1894sub key_up { 1911sub key_up {
1896 1913
1897 my $mod = $ev->key_mod; 1914 my $mod = $ev->key_mod;
1898 my $sym = $ev->key_sym; 1915 my $sym = $ev->key_sym;
1899 1916
1900 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 1917 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1901 $::CONN->user_send ("command fire_stop"); 1918 $::CONN->user_send ("fire_stop");
1902 } 1919 }
1903 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 1920 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1904 $::CONN->user_send ("command run_stop"); 1921 $::CONN->user_send ("run_stop");
1905 } 1922 }
1906} 1923}
1907 1924
1908############################################################################# 1925#############################################################################
1909 1926

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines