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.115 by root, Sat Apr 15 19:35:20 2006 UTC vs.
Revision 1.127 by root, Mon Apr 17 21:03:31 2006 UTC

74sub harmonize { 74sub harmonize {
75 my ($vals) = @_; 75 my ($vals) = @_;
76 76
77 my $rem = 0; 77 my $rem = 0;
78 78
79 for ($vals) { 79 for (@$vals) {
80 my $i = int $_ + $rem; 80 my $i = int $_ + $rem;
81 $rem += $_ - $i; 81 $rem += $_ - $i;
82 $_ = $i; 82 $_ = $i;
83 } 83 }
84} 84}
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 { }
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;
254 my ($self, $parent) = @_; 260 my ($self, $parent) = @_;
255 261
256 Scalar::Util::weaken ($self->{parent} = $parent); 262 Scalar::Util::weaken ($self->{parent} = $parent);
257} 263}
258 264
265sub check_size {
266 my ($self) = @_;
267
268 my ($w, $h) = $self->size_request;
269
270 if ($w != $self->{req_w} || $h != $self->{req_h}) {
271 $self->{req_w} = $w;
272 $self->{req_h} = $h;
273
274 $self->{parent}->check_size
275 if $self->{parent};
276 }
277}
278
259sub update { 279sub update {
260 my ($self) = @_; 280 my ($self) = @_;
261 281
262 $self->{parent}->update 282 $self->{parent}->update
263 if $self->{parent}; 283 if $self->{parent};
362 sort { $a->{z} <=> $b->{z} } 382 sort { $a->{z} <=> $b->{z} }
363 @{$self->{children}}, $child 383 @{$self->{children}}, $child
364 ]; 384 ];
365 385
366 $self->{w} = $self->{h} = -1; 386 $self->{w} = $self->{h} = -1;
367 $self->update; 387
388 $child->check_size;
368} 389}
369 390
370sub remove { 391sub remove {
371 my ($self, $widget) = @_; 392 my ($self, $widget) = @_;
372 393
373 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 394 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
374 395
375 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 396 $self->check_size;
376} 397}
377 398
378sub find_widget { 399sub find_widget {
379 my ($self, $x, $y) = @_; 400 my ($self, $x, $y) = @_;
380 401
500 $tex->draw_quad (0, 0, $w, $h); 521 $tex->draw_quad (0, 0, $w, $h);
501 522
502 glDisable GL_BLEND; 523 glDisable GL_BLEND;
503 glDisable GL_TEXTURE_2D; 524 glDisable GL_TEXTURE_2D;
504} 525}
526
527#############################################################################
528
529package CFClient::UI::ViewPort;
530
531our @ISA = CFClient::UI::Window::;
532
533sub new { die }
534
535sub size_request {
536 my ($self) = @_;
537
538 @$self{qw(child_w child_h)} = $self->child->size_request;
539 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
540
541 @$self{qw(child_w child_h)}
542}
543
544sub size_allocate {
545 my ($self, $x, $y, $w, $h) = @_;
546
547 $self->_size_allocate ($x, $y, $w, $h) or return;
548}
549
550sub _draw {
551 my ($self) = @_;
552
553 $self->{children}[1]->draw;
554}
555
505 556
506############################################################################# 557#############################################################################
507 558
508package CFClient::UI::Frame; 559package CFClient::UI::Frame;
509 560
565 # TODO: user_x, user_y, overwrite moveto? 616 # TODO: user_x, user_y, overwrite moveto?
566 617
567 $class->SUPER::new ( 618 $class->SUPER::new (
568 bg => [1, 1, 1, 1], 619 bg => [1, 1, 1, 1],
569 border_bg => [1, 1, 1, 1], 620 border_bg => [1, 1, 1, 1],
570 border => $::FONTSIZE * 0.8, 621 border => int $::FONTSIZE * 0.8,
571 @_ 622 @_
572 ) 623 )
573} 624}
574 625
575sub size_request { 626sub size_request {
704 755
705 $child->set_parent ($self); 756 $child->set_parent ($self);
706 $self->{children}[$y][$x] = $child; 757 $self->{children}[$y][$x] = $child;
707 758
708 $self->{w} = $self->{h} = -1; 759 $self->{w} = $self->{h} = -1;
709 $self->update; 760
761 $child->check_size;
710} 762}
711 763
712# TODO: move to container class maybe? send childs a signal on removal? 764# TODO: move to container class maybe? send childs a signal on removal?
713sub clear { 765sub clear {
714 my ($self) = @_; 766 my ($self) = @_;
840} 892}
841 893
842sub size_allocate { 894sub size_allocate {
843 my ($self, $x, $y, $w, $h) = @_; 895 my ($self, $x, $y, $w, $h) = @_;
844 896
845 $self->_size_allocate ($x, $y, $w, $h); 897 $self->_size_allocate ($x, $y, $w, $h) or return;
846 898
847 ($h, $w) = ($w, $h); 899 ($h, $w) = ($w, $h);
848 900
849 my $children = $self->{children}; 901 my $children = $self->{children};
850 902
876 my $h = $h[$_]; 928 my $h = $h[$_];
877 $child->size_allocate ($y, 0, $h, $w); 929 $child->size_allocate ($y, 0, $h, $w);
878 930
879 $y += $h; 931 $y += $h;
880 } 932 }
933
934 1
881} 935}
882 936
883############################################################################# 937#############################################################################
884 938
885package CFClient::UI::VBox; 939package CFClient::UI::VBox;
900} 954}
901 955
902sub size_allocate { 956sub size_allocate {
903 my ($self, $x, $y, $w, $h) = @_; 957 my ($self, $x, $y, $w, $h) = @_;
904 958
905 $self->_size_allocate ($x, $y, $w, $h); 959 $self->_size_allocate ($x, $y, $w, $h) or return;
906 960
907 my $children = $self->{children}; 961 my $children = $self->{children};
908 962
909 my @h = map +($_->size_request)[1], @$children; 963 my @h = map +($_->size_request)[1], @$children;
910 964
932 my $h = $h[$_]; 986 my $h = $h[$_];
933 $child->size_allocate (0, $y, $w, $h); 987 $child->size_allocate (0, $y, $w, $h);
934 988
935 $y += $h; 989 $y += $h;
936 } 990 }
991
992 1
937} 993}
938 994
939############################################################################# 995#############################################################################
940 996
941package CFClient::UI::Label; 997package CFClient::UI::Label;
950 my $self = $class->SUPER::new ( 1006 my $self = $class->SUPER::new (
951 fg => [1, 1, 1], 1007 fg => [1, 1, 1],
952 fontsize => $::FONTSIZE, 1008 fontsize => $::FONTSIZE,
953 text => "", 1009 text => "",
954 align => -1, 1010 align => -1,
1011 valign => -1,
955 padding => 2, 1012 padding => 2,
956 layout => new CFClient::Layout, 1013 layout => new CFClient::Layout,
957 %arg 1014 %arg
958 ); 1015 );
959 1016
960 $self->set_text ($self->{text}); 1017 $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d#
1018
1019 $self->set_text (delete $self->{text}) if exists $self->{text};
1020 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
961 1021
962 $self 1022 $self
963} 1023}
964 1024
965sub escape_text { 1025sub escape_text {
973} 1033}
974 1034
975sub set_text { 1035sub set_text {
976 my ($self, $text) = @_; 1036 my ($self, $text) = @_;
977 1037
978 $self->{text} = $text;
979 $self->{layout}->set_markup ($text); 1038 $self->{layout}->set_text ($text);
980 1039
981 delete $self->{texture}; 1040 delete $self->{texture};
982# $self->{w} = $self->{h} = -1;
983 $self->update; 1041 $self->update;
984} 1042}
985 1043
986sub get_text { 1044sub set_markup {
987 my ($self, $text) = @_; 1045 my ($self, $markup) = @_;
988 1046
989 $self->{text} 1047 $self->{layout}->set_markup ($markup);
1048
1049 delete $self->{texture};
1050 $self->update;
990} 1051}
991 1052
992sub size_request { 1053sub size_request {
993 my ($self) = @_; 1054 my ($self) = @_;
994 1055
995 $self->{layout}->set_width; 1056 $self->{layout}->set_width;
996 $self->{layout}->set_height ($self->{fontsize}); 1057 $self->{layout}->set_height ($self->{fontsize});
1058
997 my ($w, $h) = $self->{layout}->size; 1059 my ($w, $h) = $self->{layout}->size;
998 1060
999 ( 1061 (
1000 $w + $self->{padding} * 2, 1062 $w + $self->{padding} * 2,
1001 $h + $self->{padding} * 2, 1063 $h + $self->{padding} * 2,
1020sub _draw { 1082sub _draw {
1021 my ($self) = @_; 1083 my ($self) = @_;
1022 1084
1023 my $tex = $self->{texture} ||= do { 1085 my $tex = $self->{texture} ||= do {
1024 $self->{layout}->set_width ($self->{w}); 1086 $self->{layout}->set_width ($self->{w});
1025 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); 1087 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize});
1026 new_from_layout CFClient::Texture $self->{layout} 1088 new_from_layout CFClient::Texture $self->{layout}
1027 }; 1089 };
1028 1090
1029 glEnable GL_BLEND; 1091 glEnable GL_BLEND;
1030 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1092 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1031 glEnable GL_TEXTURE_2D; 1093 glEnable GL_TEXTURE_2D;
1032 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1094 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1033 1095
1034 glColor @{$self->{fg}}; 1096 glColor @{$self->{fg}};
1035 1097
1036 my $x = 1098 $self->{ox} = int (
1037 $self->{align} < 0 ? $self->{padding} 1099 $self->{align} < 0 ? $self->{padding}
1038 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1100 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1039 : ($self->{w} - $tex->{w}) * 0.5; 1101 : ($self->{w} - $tex->{w}) * 0.5
1102 );
1040 1103
1041 $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); 1104 $self->{oy} = int (
1105 $self->{valign} < 0 ? $self->{padding}
1106 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1107 : ($self->{h} - $tex->{h}) * 0.5
1108 );
1109
1110 $tex->draw_quad ($self->{ox}, $self->{oy});
1042 1111
1043 glDisable GL_TEXTURE_2D; 1112 glDisable GL_TEXTURE_2D;
1044 glDisable GL_BLEND; 1113 glDisable GL_BLEND;
1045} 1114}
1046 1115
1047############################################################################# 1116#############################################################################
1048 1117
1049package CFClient::UI::Entry; 1118package CFClient::UI::EntryBase;
1050 1119
1051our @ISA = CFClient::UI::Label::; 1120our @ISA = CFClient::UI::Label::;
1052 1121
1053use SDL; 1122use SDL;
1054use SDL::OpenGL; 1123use SDL::OpenGL;
1061 bg => [0, 0, 0, 0.2], 1130 bg => [0, 0, 0, 0.2],
1062 active_bg => [1, 1, 1, 0.5], 1131 active_bg => [1, 1, 1, 0.5],
1063 active_fg => [0, 0, 0], 1132 active_fg => [0, 0, 0],
1064 can_hover => 1, 1133 can_hover => 1,
1065 can_focus => 1, 1134 can_focus => 1,
1135 valign => 0,
1066 @_ 1136 @_
1067 ) 1137 )
1068} 1138}
1069 1139
1070sub _set_text { 1140sub _set_text {
1071 my ($self, $text) = @_; 1141 my ($self, $text) = @_;
1072 1142
1073 my $old_text = $self->{text}; 1143 delete $self->{cur_h};
1144
1145 return if $self->{text} eq $text;
1074 1146
1075 $self->{last_activity} = $::NOW; 1147 $self->{last_activity} = $::NOW;
1076
1077 $self->{text} = $text; 1148 $self->{text} = $text;
1078 $self->{layout}->set_width ($self->{w});
1079 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1080 1149
1081 $text =~ s/./*/g if $self->{hidden}; 1150 $text =~ s/./*/g if $self->{hidden};
1151 $self->{layout}->set_text ("$text ");
1082 1152
1083 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1153 $self->emit (changed => $self->{text});
1154}
1084 1155
1085 $text = substr $text, 0, $self->{cursor}; 1156sub get_text {
1086 utf8::encode $text; 1157 $_[0]{text}
1087
1088 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
1089
1090 $self->emit (changed => $self->{text}) # XXX: is this the right place to do this?
1091 if $old_text ne $self->{text};
1092} 1158}
1093 1159
1094sub size_request { 1160sub size_request {
1095 my ($self) = @_; 1161 my ($self) = @_;
1096 1162
1100} 1166}
1101 1167
1102sub size_allocate { 1168sub size_allocate {
1103 my ($self, $x, $y, $w, $h) = @_; 1169 my ($self, $x, $y, $w, $h) = @_;
1104 1170
1105 $self->SUPER::size_allocate ($x, $y, $w, $h); 1171 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1106 1172
1107 $self->_set_text ($self->{text}); 1173 $self->_set_text ($self->{text});
1108} 1174}
1109 1175
1110sub set_text { 1176sub set_text {
1200 1266
1201 $self->SUPER::_draw; 1267 $self->SUPER::_draw;
1202 1268
1203 #TODO: force update every cursor change :( 1269 #TODO: force update every cursor change :(
1204 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1270 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1271
1272 unless (exists $self->{cur_h}) {
1273 my $text = substr $self->{text}, 0, $self->{cursor};
1274 utf8::encode $text;
1275
1276 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1277 }
1278
1205 glColor @{$self->{fg}}; 1279 glColor @{$self->{fg}};
1206 glBegin GL_LINES; 1280 glBegin GL_LINES;
1207 glVertex $self->{cur_x}, $self->{cur_y};
1208 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1281 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1282 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1209 glEnd; 1283 glEnd;
1210 } 1284 }
1211} 1285}
1212 1286
1213package CFClient::UI::LineEntry; 1287package CFClient::UI::Entry;
1214 1288
1215our @ISA = CFClient::UI::Entry::; 1289our @ISA = CFClient::UI::EntryBase::;
1216 1290
1217use SDL; 1291use SDL;
1218use SDL::OpenGL; 1292use SDL::OpenGL;
1219 1293
1220sub key_down { 1294sub key_down {
1250 1324
1251 $class->SUPER::new ( 1325 $class->SUPER::new (
1252 padding => 4, 1326 padding => 4,
1253 fg => [1, 1, 1], 1327 fg => [1, 1, 1],
1254 bg => [1, 1, 1, 0.2], 1328 bg => [1, 1, 1, 0.2],
1255 active_fg => [1, 1, 0], 1329 active_fg => [0, 0, 1],
1256 can_hover => 1, 1330 can_hover => 1,
1331 align => 0,
1332 valign => 0,
1257 @_ 1333 @_
1258 ) 1334 )
1259} 1335}
1260 1336
1261sub button_up { 1337sub button_up {
1269 1345
1270sub _draw { 1346sub _draw {
1271 my ($self) = @_; 1347 my ($self) = @_;
1272 1348
1273 local $self->{fg} = $self->{fg}; 1349 local $self->{fg} = $self->{fg};
1274 my $tex = $tex[0];
1275
1276 glEnable GL_BLEND;
1277 glEnable GL_TEXTURE_2D;
1278 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1279 1350
1280 if ($GRAB == $self) { 1351 if ($GRAB == $self) {
1281 $self->{fg} = $self->{active_fg}; 1352 $self->{fg} = $self->{active_fg};
1282 } 1353 }
1283 1354
1284 glBindTexture GL_TEXTURE_2D, $tex->{name}; 1355 glEnable GL_BLEND;
1356 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1357 glEnable GL_TEXTURE_2D;
1285 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1358 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1359 glColor 0, 0, 0, 1;
1286 1360
1287 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 1361 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h});
1288 1362
1289 glDisable GL_TEXTURE_2D; 1363 glDisable GL_TEXTURE_2D;
1290 glDisable GL_BLEND; 1364 glDisable GL_BLEND;
1291 1365
1292 $self->SUPER::_draw; 1366 $self->SUPER::_draw;
1325} 1399}
1326 1400
1327sub size_allocate { 1401sub size_allocate {
1328 my ($self, $x, $y, $w, $h) = @_; 1402 my ($self, $x, $y, $w, $h) = @_;
1329 1403
1330 $self->_size_allocate ($x, $y, $w, $h); 1404 $self->_size_allocate ($x, $y, $w, $h) or return;
1331} 1405}
1332 1406
1333sub button_down { 1407sub button_down {
1334 my ($self, $ev, $x, $y) = @_; 1408 my ($self, $ev, $x, $y) = @_;
1335 1409
1359 1433
1360 $tex->draw_quad (0, 0, $s, $s); 1434 $tex->draw_quad (0, 0, $s, $s);
1361 1435
1362 glDisable GL_TEXTURE_2D; 1436 glDisable GL_TEXTURE_2D;
1363 glDisable GL_BLEND; 1437 glDisable GL_BLEND;
1438}
1439
1440#############################################################################
1441
1442package CFClient::UI::VGauge;
1443
1444our @ISA = CFClient::UI::Base::;
1445
1446use SDL::OpenGL;
1447
1448my %tex = (
1449 food => [
1450 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1451 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1452 ],
1453 grace => [
1454 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1455 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1456 ],
1457 hp => [
1458 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1459 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1460 ],
1461 mana => [
1462 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1463 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1464 ],
1465);
1466
1467# eg. VGauge->new (gauge => 'food'), default gauge: food
1468sub new {
1469 my $class = shift;
1470
1471 my $self = $class->SUPER::new (gauge => 'food', @_);
1472
1473 $self
1474}
1475
1476sub size_request {
1477 my ($self) = @_;
1478
1479 my $tex = $tex{$self->{gauge}}[0];
1480
1481 @$tex{qw(w h)}
1482}
1483
1484sub set_max {
1485 my ($self, $max) = @_;
1486
1487 $self->{max_val} = $max;
1488}
1489
1490sub set_value {
1491 my ($self, $val, $max) = @_;
1492
1493 $self->set_max ($max)
1494 if defined $max;
1495
1496 $max = $self->{max_val};
1497 $self->{val} = $val;
1498
1499 $self->update;
1500}
1501
1502sub _draw {
1503 my ($self) = @_;
1504
1505 my $tex = $tex{$self->{gauge}};
1506
1507 my ($w, $h) = ($self->{w}, $self->{h});
1508
1509 my $ycut = $self->{val} / ($self->{max_val} || 1);
1510 $ycut = 1 if $self->{val} > $self->{max_val};
1511
1512 my $t1 = $tex->[0];
1513 my $t2 = $tex->[1];
1514
1515 glEnable GL_BLEND;
1516 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1517 glEnable GL_TEXTURE_2D;
1518 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1519
1520 my $h1 = $self->{h} - $ycut * $self->{h};
1521 my $h2 = $ycut * $self->{h};
1522
1523 my $yp = 0;
1524
1525 glBindTexture (GL_TEXTURE_2D, $t1->{name});
1526 glBegin (GL_QUADS);
1527 glTexCoord (0, 0); glVertex (0 , $yp);
1528 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1);
1529 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1);
1530 glTexCoord (1, 0); glVertex (0 + $w, $yp);
1531 glEnd ();
1532
1533 $yp += $h1;
1534
1535 glBindTexture (GL_TEXTURE_2D, $t2->{name});
1536 glBegin (GL_QUADS);
1537 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp);
1538 glTexCoord (0, 1); glVertex (0 , $yp + $h2);
1539 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2);
1540 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp);
1541 glEnd ();
1542
1543 glDisable GL_BLEND;
1544 glDisable GL_TEXTURE_2D;
1364} 1545}
1365 1546
1366############################################################################# 1547#############################################################################
1367 1548
1368package CFClient::UI::Slider; 1549package CFClient::UI::Slider;
1564} 1745}
1565 1746
1566sub size_allocate { 1747sub size_allocate {
1567 my ($self, $x, $y, $w, $h) = @_; 1748 my ($self, $x, $y, $w, $h) = @_;
1568 1749
1569 $self->SUPER::size_allocate ($x, $y, $w, $h); 1750 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1570 1751
1571 $self->{layout}->set_height ($self->{fontsize}); 1752 $self->{layout}->set_height ($self->{fontsize});
1572 $self->{layout}->set_width ($self->{w}); 1753 $self->{layout}->set_width ($self->{w});
1573 1754
1574 $self->reflow; 1755 $self->reflow;
1756 $self->update;
1575} 1757}
1576 1758
1577sub add_paragraph { 1759sub add_paragraph {
1578 my ($self, $color, $text) = @_; 1760 my ($self, $color, $text) = @_;
1579 1761
1774 0.1, 0.1, 0.1, 1956 0.1, 0.1, 0.1,
1775 ; 1957 ;
1776 glEnable GL_CONVOLUTION_2D; 1958 glEnable GL_CONVOLUTION_2D;
1777 } 1959 }
1778 1960
1779 my $tex = new CFClient::Texture 1961 $self->{fow_texture} = new CFClient::Texture
1780 w => $w, 1962 w => $w,
1781 h => $h, 1963 h => $h,
1782 data => $data, 1964 data => $data,
1783 internalformat => GL_ALPHA, 1965 internalformat => GL_ALPHA,
1784 format => GL_ALPHA; 1966 format => GL_ALPHA;
1789 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1971 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1790 glEnable GL_TEXTURE_2D; 1972 glEnable GL_TEXTURE_2D;
1791 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1973 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1792 1974
1793 glColor +($::CFG->{fow_intensity}) x 3, 1; 1975 glColor +($::CFG->{fow_intensity}) x 3, 1;
1794 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1976 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1795 1977
1796 glDisable GL_TEXTURE_2D; 1978 glDisable GL_TEXTURE_2D;
1797 glDisable GL_BLEND; 1979 glDisable GL_BLEND;
1798 } 1980 }
1799 1981
1805 glEnable GL_BLEND; 1987 glEnable GL_BLEND;
1806 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1988 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1807 glEnable GL_TEXTURE_2D; 1989 glEnable GL_TEXTURE_2D;
1808 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1990 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1809 1991
1992 $self->{mapmap_texture} =
1810 CFClient::Texture->new ( 1993 new CFClient::Texture
1811 w => $w, 1994 w => $w,
1812 h => $h, 1995 h => $h,
1813 data => $::MAP->mapmap ($w, $h), 1996 data => $::MAP->mapmap ($w, $h),
1814 type => GL_UNSIGNED_INT_8_8_8_8_REV 1997 type => GL_UNSIGNED_INT_8_8_8_8_REV;
1815 )->draw_quad (100, 100); 1998
1999 $self->{mapmap_texture}->draw_quad (100, 100);
1816 2000
1817 glDisable GL_TEXTURE_2D; 2001 glDisable GL_TEXTURE_2D;
1818 glDisable GL_BLEND; 2002 glDisable GL_BLEND;
1819 } 2003 }
1820 # HACK END 2004 # HACK END
1862 2046
1863 my $mod = $ev->key_mod; 2047 my $mod = $ev->key_mod;
1864 my $sym = $ev->key_sym; 2048 my $sym = $ev->key_sym;
1865 2049
1866 if ($sym == SDLK_KP5) { 2050 if ($sym == SDLK_KP5) {
1867 $::CONN->user_send ("command stay fire"); 2051 $::CONN->user_send ("stay fire");
1868 } elsif ($sym == SDLK_a) { 2052 } elsif ($sym == SDLK_a) {
1869 $::CONN->user_send ("command apply"); 2053 $::CONN->user_send ("apply");
1870 } elsif ($sym == SDLK_QUOTE) { 2054 } elsif ($sym == SDLK_QUOTE) {
1871 $self->emit ('activate_console'); 2055 $self->emit ('activate_console');
1872 } elsif ($sym == SDLK_SLASH) { 2056 } elsif ($sym == SDLK_SLASH) {
1873 $self->emit ('activate_console' => '/'); 2057 $self->emit ('activate_console' => '/');
1874 } elsif (exists $DIR{$sym}) { 2058 } elsif (exists $DIR{$sym}) {
1875 if ($mod & KMOD_SHIFT) { 2059 if ($mod & KMOD_SHIFT) {
1876 $self->{shft}++; 2060 $self->{shft}++;
1877 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 2061 $::CONN->user_send ("fire $DIR{$sym}[0]");
1878 } elsif ($mod & KMOD_CTRL) { 2062 } elsif ($mod & KMOD_CTRL) {
1879 $self->{ctrl}++; 2063 $self->{ctrl}++;
1880 $::CONN->user_send ("command run $DIR{$sym}[0]"); 2064 $::CONN->user_send ("run $DIR{$sym}[0]");
1881 } else { 2065 } else {
1882 $::CONN->user_send ("command $DIR{$sym}[1]"); 2066 $::CONN->user_send ("$DIR{$sym}[1]");
1883 } 2067 }
1884 } 2068 }
1885} 2069}
1886 2070
1887sub key_up { 2071sub key_up {
1889 2073
1890 my $mod = $ev->key_mod; 2074 my $mod = $ev->key_mod;
1891 my $sym = $ev->key_sym; 2075 my $sym = $ev->key_sym;
1892 2076
1893 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 2077 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1894 $::CONN->user_send ("command fire_stop"); 2078 $::CONN->user_send ("fire_stop");
1895 } 2079 }
1896 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 2080 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1897 $::CONN->user_send ("command run_stop"); 2081 $::CONN->user_send ("run_stop");
1898 } 2082 }
1899} 2083}
1900 2084
1901############################################################################# 2085#############################################################################
1902 2086
1985 2169
1986our @ISA = CFClient::UI::Container::; 2170our @ISA = CFClient::UI::Container::;
1987 2171
1988use SDL::OpenGL; 2172use SDL::OpenGL;
1989 2173
2174sub check_size {
2175 my ($self) = @_;
2176
2177 $self->size_allocate (0, 0, $::WITH, $::HEIGHT);
2178}
2179
1990sub size_request { 2180sub size_request {
1991 ($::WIDTH, $::HEIGHT) 2181 ($::WIDTH, $::HEIGHT)
1992} 2182}
1993 2183
1994sub size_allocate { 2184sub size_allocate {
2007} 2197}
2008 2198
2009sub update { 2199sub update {
2010 my ($self) = @_; 2200 my ($self) = @_;
2011 2201
2012 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2202 $self->check_size;
2013 ::refresh (); 2203 ::refresh ();
2014} 2204}
2015 2205
2016sub add { 2206sub add {
2017 my ($self, $widget) = @_; 2207 my ($self, $widget) = @_;
2018 2208
2019 $self->SUPER::add ($widget); 2209 $self->SUPER::add ($widget);
2020 2210
2021 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 2211 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2022} 2212}
2023 2213
2024sub on_refresh { 2214sub on_refresh {
2025 my ($self, $id, $cb) = @_; 2215 my ($self, $id, $cb) = @_;
2026 2216

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines