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.116 by root, Sat Apr 15 21:16:50 2006 UTC vs.
Revision 1.121 by root, Mon Apr 17 19:21:00 2006 UTC

112 $self 112 $self
113} 113}
114 114
115sub move { 115sub move {
116 my ($self, $x, $y, $z) = @_; 116 my ($self, $x, $y, $z) = @_;
117 $self->{x} = $x; 117 $self->{x} = int $x;
118 $self->{y} = $y; 118 $self->{y} = int $y;
119 $self->{z} = $z if defined $z; 119 $self->{z} = $z if defined $z;
120} 120}
121 121
122sub needs_redraw { 122sub needs_redraw {
123 0 123 0
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 { }
565 # TODO: user_x, user_y, overwrite moveto? 571 # TODO: user_x, user_y, overwrite moveto?
566 572
567 $class->SUPER::new ( 573 $class->SUPER::new (
568 bg => [1, 1, 1, 1], 574 bg => [1, 1, 1, 1],
569 border_bg => [1, 1, 1, 1], 575 border_bg => [1, 1, 1, 1],
570 border => $::FONTSIZE * 0.8, 576 border => int $::FONTSIZE * 0.8,
571 @_ 577 @_
572 ) 578 )
573} 579}
574 580
575sub size_request { 581sub size_request {
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;
1050 glDisable GL_BLEND; 1061 glDisable GL_BLEND;
1051} 1062}
1052 1063
1053############################################################################# 1064#############################################################################
1054 1065
1055package CFClient::UI::Entry; 1066package CFClient::UI::EntryBase;
1056 1067
1057our @ISA = CFClient::UI::Label::; 1068our @ISA = CFClient::UI::Label::;
1058 1069
1059use SDL; 1070use SDL;
1060use SDL::OpenGL; 1071use SDL::OpenGL;
1075} 1086}
1076 1087
1077sub _set_text { 1088sub _set_text {
1078 my ($self, $text) = @_; 1089 my ($self, $text) = @_;
1079 1090
1080 my $old_text = $self->{text}; 1091 delete $self->{cur_h};
1092
1093 return if $self->{text} eq $text;
1081 1094
1082 $self->{last_activity} = $::NOW; 1095 $self->{last_activity} = $::NOW;
1083
1084 $self->{text} = $text; 1096 $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 1097
1088 $text =~ s/./*/g if $self->{hidden}; 1098 $text =~ s/./*/g if $self->{hidden};
1099 $self->{layout}->set_text ("$text ");
1089 1100
1090 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1101 $self->emit (changed => $self->{text});
1102}
1091 1103
1092 $text = substr $text, 0, $self->{cursor}; 1104sub get_text {
1093 utf8::encode $text; 1105 $_[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} 1106}
1100 1107
1101sub size_request { 1108sub size_request {
1102 my ($self) = @_; 1109 my ($self) = @_;
1103 1110
1207 1214
1208 $self->SUPER::_draw; 1215 $self->SUPER::_draw;
1209 1216
1210 #TODO: force update every cursor change :( 1217 #TODO: force update every cursor change :(
1211 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1218 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1219
1220 unless (exists $self->{cur_h}) {
1221 my $text = substr $self->{text}, 0, $self->{cursor};
1222 utf8::encode $text;
1223
1224 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1225 }
1226
1212 glColor @{$self->{fg}}; 1227 glColor @{$self->{fg}};
1213 glBegin GL_LINES; 1228 glBegin GL_LINES;
1214 glVertex $self->{cur_x}, $self->{cur_y}; 1229 glVertex $self->{cur_x}, $self->{cur_y};
1215 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1230 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h};
1216 glEnd; 1231 glEnd;
1217 } 1232 }
1218} 1233}
1219 1234
1220package CFClient::UI::LineEntry; 1235package CFClient::UI::Entry;
1221 1236
1222our @ISA = CFClient::UI::Entry::; 1237our @ISA = CFClient::UI::EntryBase::;
1223 1238
1224use SDL; 1239use SDL;
1225use SDL::OpenGL; 1240use SDL::OpenGL;
1226 1241
1227sub key_down { 1242sub key_down {
1276 1291
1277sub _draw { 1292sub _draw {
1278 my ($self) = @_; 1293 my ($self) = @_;
1279 1294
1280 local $self->{fg} = $self->{fg}; 1295 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 1296
1287 if ($GRAB == $self) { 1297 if ($GRAB == $self) {
1288 $self->{fg} = $self->{active_fg}; 1298 $self->{fg} = $self->{active_fg};
1289 } 1299 }
1290 1300
1291 glBindTexture GL_TEXTURE_2D, $tex->{name}; 1301 glEnable GL_BLEND;
1302 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1303 glEnable GL_TEXTURE_2D;
1292 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1304 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1305 glColor 0, 0, 0, 1;
1293 1306
1294 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 1307 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h});
1295 1308
1296 glDisable GL_TEXTURE_2D; 1309 glDisable GL_TEXTURE_2D;
1297 glDisable GL_BLEND; 1310 glDisable GL_BLEND;
1298 1311
1299 $self->SUPER::_draw; 1312 $self->SUPER::_draw;
1781 0.1, 0.1, 0.1, 1794 0.1, 0.1, 0.1,
1782 ; 1795 ;
1783 glEnable GL_CONVOLUTION_2D; 1796 glEnable GL_CONVOLUTION_2D;
1784 } 1797 }
1785 1798
1786 my $tex = new CFClient::Texture 1799 $self->{fow_texture} = new CFClient::Texture
1787 w => $w, 1800 w => $w,
1788 h => $h, 1801 h => $h,
1789 data => $data, 1802 data => $data,
1790 internalformat => GL_ALPHA, 1803 internalformat => GL_ALPHA,
1791 format => GL_ALPHA; 1804 format => GL_ALPHA;
1796 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1809 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1797 glEnable GL_TEXTURE_2D; 1810 glEnable GL_TEXTURE_2D;
1798 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1811 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1799 1812
1800 glColor +($::CFG->{fow_intensity}) x 3, 1; 1813 glColor +($::CFG->{fow_intensity}) x 3, 1;
1801 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1814 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1802 1815
1803 glDisable GL_TEXTURE_2D; 1816 glDisable GL_TEXTURE_2D;
1804 glDisable GL_BLEND; 1817 glDisable GL_BLEND;
1805 } 1818 }
1806 1819
1812 glEnable GL_BLEND; 1825 glEnable GL_BLEND;
1813 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1826 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1814 glEnable GL_TEXTURE_2D; 1827 glEnable GL_TEXTURE_2D;
1815 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1828 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1816 1829
1830 $self->{mapmap_texture} =
1817 CFClient::Texture->new ( 1831 new CFClient::Texture
1818 w => $w, 1832 w => $w,
1819 h => $h, 1833 h => $h,
1820 data => $::MAP->mapmap ($w, $h), 1834 data => $::MAP->mapmap ($w, $h),
1821 type => GL_UNSIGNED_INT_8_8_8_8_REV 1835 type => GL_UNSIGNED_INT_8_8_8_8_REV;
1822 )->draw_quad (100, 100); 1836
1837 $self->{mapmap_texture}->draw_quad (100, 100);
1823 1838
1824 glDisable GL_TEXTURE_2D; 1839 glDisable GL_TEXTURE_2D;
1825 glDisable GL_BLEND; 1840 glDisable GL_BLEND;
1826 } 1841 }
1827 # HACK END 1842 # HACK END
2023sub add { 2038sub add {
2024 my ($self, $widget) = @_; 2039 my ($self, $widget) = @_;
2025 2040
2026 $self->SUPER::add ($widget); 2041 $self->SUPER::add ($widget);
2027 2042
2028 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 2043 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2029} 2044}
2030 2045
2031sub on_refresh { 2046sub on_refresh {
2032 my ($self, $id, $cb) = @_; 2047 my ($self, $id, $cb) = @_;
2033 2048

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines