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.126 by root, Mon Apr 17 20:59:20 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 { }
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;
956 padding => 2, 1012 padding => 2,
957 layout => new CFClient::Layout, 1013 layout => new CFClient::Layout,
958 %arg 1014 %arg
959 ); 1015 );
960 1016
961 $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};
962 1021
963 $self 1022 $self
964} 1023}
965 1024
966sub escape_text { 1025sub escape_text {
974} 1033}
975 1034
976sub set_text { 1035sub set_text {
977 my ($self, $text) = @_; 1036 my ($self, $text) = @_;
978 1037
979 $self->{text} = $text;
980 $self->{layout}->set_markup ($text); 1038 $self->{layout}->set_text ($text);
981 1039
982 delete $self->{texture}; 1040 delete $self->{texture};
983# $self->{w} = $self->{h} = -1;
984 $self->update; 1041 $self->update;
985} 1042}
986 1043
987sub get_text { 1044sub set_markup {
988 my ($self, $text) = @_; 1045 my ($self, $markup) = @_;
989 1046
990 $self->{text} 1047 $self->{layout}->set_markup ($markup);
1048
1049 delete $self->{texture};
1050 $self->update;
991} 1051}
992 1052
993sub size_request { 1053sub size_request {
994 my ($self) = @_; 1054 my ($self) = @_;
995 1055
996 $self->{layout}->set_width; 1056 $self->{layout}->set_width;
997 $self->{layout}->set_height ($self->{fontsize}); 1057 $self->{layout}->set_height ($self->{fontsize});
1058
998 my ($w, $h) = $self->{layout}->size; 1059 my ($w, $h) = $self->{layout}->size;
999 1060
1000 ( 1061 (
1001 $w + $self->{padding} * 2, 1062 $w + $self->{padding} * 2,
1002 $h + $self->{padding} * 2, 1063 $h + $self->{padding} * 2,
1021sub _draw { 1082sub _draw {
1022 my ($self) = @_; 1083 my ($self) = @_;
1023 1084
1024 my $tex = $self->{texture} ||= do { 1085 my $tex = $self->{texture} ||= do {
1025 $self->{layout}->set_width ($self->{w}); 1086 $self->{layout}->set_width ($self->{w});
1026 $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});
1027 new_from_layout CFClient::Texture $self->{layout} 1088 new_from_layout CFClient::Texture $self->{layout}
1028 }; 1089 };
1029 1090
1030 glEnable GL_BLEND; 1091 glEnable GL_BLEND;
1031 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1092 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1032 glEnable GL_TEXTURE_2D; 1093 glEnable GL_TEXTURE_2D;
1033 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1094 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1034 1095
1035 glColor @{$self->{fg}}; 1096 glColor @{$self->{fg}};
1036 1097
1037 my $x = 1098 $self->{ox} = int (
1038 $self->{align} < 0 ? $self->{padding} 1099 $self->{align} < 0 ? $self->{padding}
1039 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1100 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1040 : ($self->{w} - $tex->{w}) * 0.5; 1101 : ($self->{w} - $tex->{w}) * 0.5
1102 );
1041 1103
1042 my $y = 1104 $self->{oy} = int (
1043 $self->{valign} < 0 ? $self->{padding} 1105 $self->{valign} < 0 ? $self->{padding}
1044 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1106 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1045 : ($self->{h} - $tex->{h}) * 0.5; 1107 : ($self->{h} - $tex->{h}) * 0.5
1108 );
1046 1109
1047 $tex->draw_quad (int $x, int $y); 1110 $tex->draw_quad ($self->{ox}, $self->{oy});
1048 1111
1049 glDisable GL_TEXTURE_2D; 1112 glDisable GL_TEXTURE_2D;
1050 glDisable GL_BLEND; 1113 glDisable GL_BLEND;
1051} 1114}
1052 1115
1053############################################################################# 1116#############################################################################
1054 1117
1055package CFClient::UI::Entry; 1118package CFClient::UI::EntryBase;
1056 1119
1057our @ISA = CFClient::UI::Label::; 1120our @ISA = CFClient::UI::Label::;
1058 1121
1059use SDL; 1122use SDL;
1060use SDL::OpenGL; 1123use SDL::OpenGL;
1075} 1138}
1076 1139
1077sub _set_text { 1140sub _set_text {
1078 my ($self, $text) = @_; 1141 my ($self, $text) = @_;
1079 1142
1080 my $old_text = $self->{text}; 1143 delete $self->{cur_h};
1144
1145 return if $self->{text} eq $text;
1081 1146
1082 $self->{last_activity} = $::NOW; 1147 $self->{last_activity} = $::NOW;
1083
1084 $self->{text} = $text; 1148 $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 1149
1088 $text =~ s/./*/g if $self->{hidden}; 1150 $text =~ s/./*/g if $self->{hidden};
1151 $self->{layout}->set_text ("$text ");
1089 1152
1090 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1153 $self->emit (changed => $self->{text});
1154}
1091 1155
1092 $text = substr $text, 0, $self->{cursor}; 1156sub get_text {
1093 utf8::encode $text; 1157 $_[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} 1158}
1100 1159
1101sub size_request { 1160sub size_request {
1102 my ($self) = @_; 1161 my ($self) = @_;
1103 1162
1107} 1166}
1108 1167
1109sub size_allocate { 1168sub size_allocate {
1110 my ($self, $x, $y, $w, $h) = @_; 1169 my ($self, $x, $y, $w, $h) = @_;
1111 1170
1112 $self->SUPER::size_allocate ($x, $y, $w, $h); 1171 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1113 1172
1114 $self->_set_text ($self->{text}); 1173 $self->_set_text ($self->{text});
1115} 1174}
1116 1175
1117sub set_text { 1176sub set_text {
1207 1266
1208 $self->SUPER::_draw; 1267 $self->SUPER::_draw;
1209 1268
1210 #TODO: force update every cursor change :( 1269 #TODO: force update every cursor change :(
1211 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
1212 glColor @{$self->{fg}}; 1279 glColor @{$self->{fg}};
1213 glBegin GL_LINES; 1280 glBegin GL_LINES;
1214 glVertex $self->{cur_x}, $self->{cur_y};
1215 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};
1216 glEnd; 1283 glEnd;
1217 } 1284 }
1218} 1285}
1219 1286
1220package CFClient::UI::LineEntry; 1287package CFClient::UI::Entry;
1221 1288
1222our @ISA = CFClient::UI::Entry::; 1289our @ISA = CFClient::UI::EntryBase::;
1223 1290
1224use SDL; 1291use SDL;
1225use SDL::OpenGL; 1292use SDL::OpenGL;
1226 1293
1227sub key_down { 1294sub key_down {
1257 1324
1258 $class->SUPER::new ( 1325 $class->SUPER::new (
1259 padding => 4, 1326 padding => 4,
1260 fg => [1, 1, 1], 1327 fg => [1, 1, 1],
1261 bg => [1, 1, 1, 0.2], 1328 bg => [1, 1, 1, 0.2],
1262 active_fg => [1, 1, 0], 1329 active_fg => [0, 0, 1],
1263 can_hover => 1, 1330 can_hover => 1,
1331 align => 0,
1332 valign => 0,
1264 @_ 1333 @_
1265 ) 1334 )
1266} 1335}
1267 1336
1268sub button_up { 1337sub button_up {
1276 1345
1277sub _draw { 1346sub _draw {
1278 my ($self) = @_; 1347 my ($self) = @_;
1279 1348
1280 local $self->{fg} = $self->{fg}; 1349 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 1350
1287 if ($GRAB == $self) { 1351 if ($GRAB == $self) {
1288 $self->{fg} = $self->{active_fg}; 1352 $self->{fg} = $self->{active_fg};
1289 } 1353 }
1290 1354
1291 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;
1292 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;
1293 1360
1294 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 1361 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h});
1295 1362
1296 glDisable GL_TEXTURE_2D; 1363 glDisable GL_TEXTURE_2D;
1297 glDisable GL_BLEND; 1364 glDisable GL_BLEND;
1298 1365
1299 $self->SUPER::_draw; 1366 $self->SUPER::_draw;
1332} 1399}
1333 1400
1334sub size_allocate { 1401sub size_allocate {
1335 my ($self, $x, $y, $w, $h) = @_; 1402 my ($self, $x, $y, $w, $h) = @_;
1336 1403
1337 $self->_size_allocate ($x, $y, $w, $h); 1404 $self->_size_allocate ($x, $y, $w, $h) or return;
1338} 1405}
1339 1406
1340sub button_down { 1407sub button_down {
1341 my ($self, $ev, $x, $y) = @_; 1408 my ($self, $ev, $x, $y) = @_;
1342 1409
1366 1433
1367 $tex->draw_quad (0, 0, $s, $s); 1434 $tex->draw_quad (0, 0, $s, $s);
1368 1435
1369 glDisable GL_TEXTURE_2D; 1436 glDisable GL_TEXTURE_2D;
1370 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 (30, 100)
1480}
1481
1482sub set_max {
1483 my ($self, $max) = @_;
1484 $self->{max_val} = $max;
1485}
1486
1487sub set_value {
1488 my ($self, $val, $max) = @_;
1489
1490 $self->set_max ($max)
1491 if defined $max;
1492
1493 $max = $self->{max_val};
1494 $self->{val} = $val;
1495
1496 $self->update;
1497}
1498
1499sub _draw {
1500 my ($self) = @_;
1501
1502 my $tex = $tex{$self->{gauge}};
1503
1504 my ($w, $h) = ($self->{w}, $self->{h});
1505
1506 my $ycut = $self->{val} / ($self->{max_val} || 1);
1507 $ycut = 1 if $self->{val} > $self->{max_val};
1508
1509 my $t1 = $tex->[0];
1510 my $t2 = $tex->[1];
1511
1512 glEnable GL_BLEND;
1513 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1514 glEnable GL_TEXTURE_2D;
1515 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1516
1517 my $h1 = $self->{h} - $ycut * $self->{h};
1518 my $h2 = $ycut * $self->{h};
1519
1520 my $yp = 0;
1521
1522 glBindTexture (GL_TEXTURE_2D, $t1->{name});
1523 glBegin (GL_QUADS);
1524 glTexCoord (0, 0); glVertex (0 , $yp);
1525 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1);
1526 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1);
1527 glTexCoord (1, 0); glVertex (0 + $w, $yp);
1528 glEnd ();
1529
1530 $yp += $h1;
1531
1532 glBindTexture (GL_TEXTURE_2D, $t2->{name});
1533 glBegin (GL_QUADS);
1534 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp);
1535 glTexCoord (0, 1); glVertex (0 , $yp + $h2);
1536 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2);
1537 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp);
1538 glEnd ();
1539
1540 glDisable GL_BLEND;
1541 glDisable GL_TEXTURE_2D;
1371} 1542}
1372 1543
1373############################################################################# 1544#############################################################################
1374 1545
1375package CFClient::UI::Slider; 1546package CFClient::UI::Slider;
1571} 1742}
1572 1743
1573sub size_allocate { 1744sub size_allocate {
1574 my ($self, $x, $y, $w, $h) = @_; 1745 my ($self, $x, $y, $w, $h) = @_;
1575 1746
1576 $self->SUPER::size_allocate ($x, $y, $w, $h); 1747 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1577 1748
1578 $self->{layout}->set_height ($self->{fontsize}); 1749 $self->{layout}->set_height ($self->{fontsize});
1579 $self->{layout}->set_width ($self->{w}); 1750 $self->{layout}->set_width ($self->{w});
1580 1751
1581 $self->reflow; 1752 $self->reflow;
1753 $self->update;
1582} 1754}
1583 1755
1584sub add_paragraph { 1756sub add_paragraph {
1585 my ($self, $color, $text) = @_; 1757 my ($self, $color, $text) = @_;
1586 1758
1781 0.1, 0.1, 0.1, 1953 0.1, 0.1, 0.1,
1782 ; 1954 ;
1783 glEnable GL_CONVOLUTION_2D; 1955 glEnable GL_CONVOLUTION_2D;
1784 } 1956 }
1785 1957
1786 my $tex = new CFClient::Texture 1958 $self->{fow_texture} = new CFClient::Texture
1787 w => $w, 1959 w => $w,
1788 h => $h, 1960 h => $h,
1789 data => $data, 1961 data => $data,
1790 internalformat => GL_ALPHA, 1962 internalformat => GL_ALPHA,
1791 format => GL_ALPHA; 1963 format => GL_ALPHA;
1796 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1968 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1797 glEnable GL_TEXTURE_2D; 1969 glEnable GL_TEXTURE_2D;
1798 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1970 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1799 1971
1800 glColor +($::CFG->{fow_intensity}) x 3, 1; 1972 glColor +($::CFG->{fow_intensity}) x 3, 1;
1801 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1973 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1802 1974
1803 glDisable GL_TEXTURE_2D; 1975 glDisable GL_TEXTURE_2D;
1804 glDisable GL_BLEND; 1976 glDisable GL_BLEND;
1805 } 1977 }
1806 1978
1812 glEnable GL_BLEND; 1984 glEnable GL_BLEND;
1813 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1985 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1814 glEnable GL_TEXTURE_2D; 1986 glEnable GL_TEXTURE_2D;
1815 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1987 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1816 1988
1989 $self->{mapmap_texture} =
1817 CFClient::Texture->new ( 1990 new CFClient::Texture
1818 w => $w, 1991 w => $w,
1819 h => $h, 1992 h => $h,
1820 data => $::MAP->mapmap ($w, $h), 1993 data => $::MAP->mapmap ($w, $h),
1821 type => GL_UNSIGNED_INT_8_8_8_8_REV 1994 type => GL_UNSIGNED_INT_8_8_8_8_REV;
1822 )->draw_quad (100, 100); 1995
1996 $self->{mapmap_texture}->draw_quad (100, 100);
1823 1997
1824 glDisable GL_TEXTURE_2D; 1998 glDisable GL_TEXTURE_2D;
1825 glDisable GL_BLEND; 1999 glDisable GL_BLEND;
1826 } 2000 }
1827 # HACK END 2001 # HACK END
1869 2043
1870 my $mod = $ev->key_mod; 2044 my $mod = $ev->key_mod;
1871 my $sym = $ev->key_sym; 2045 my $sym = $ev->key_sym;
1872 2046
1873 if ($sym == SDLK_KP5) { 2047 if ($sym == SDLK_KP5) {
1874 $::CONN->user_send ("command stay fire"); 2048 $::CONN->user_send ("stay fire");
1875 } elsif ($sym == SDLK_a) { 2049 } elsif ($sym == SDLK_a) {
1876 $::CONN->user_send ("command apply"); 2050 $::CONN->user_send ("apply");
1877 } elsif ($sym == SDLK_QUOTE) { 2051 } elsif ($sym == SDLK_QUOTE) {
1878 $self->emit ('activate_console'); 2052 $self->emit ('activate_console');
1879 } elsif ($sym == SDLK_SLASH) { 2053 } elsif ($sym == SDLK_SLASH) {
1880 $self->emit ('activate_console' => '/'); 2054 $self->emit ('activate_console' => '/');
1881 } elsif (exists $DIR{$sym}) { 2055 } elsif (exists $DIR{$sym}) {
1882 if ($mod & KMOD_SHIFT) { 2056 if ($mod & KMOD_SHIFT) {
1883 $self->{shft}++; 2057 $self->{shft}++;
1884 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 2058 $::CONN->user_send ("fire $DIR{$sym}[0]");
1885 } elsif ($mod & KMOD_CTRL) { 2059 } elsif ($mod & KMOD_CTRL) {
1886 $self->{ctrl}++; 2060 $self->{ctrl}++;
1887 $::CONN->user_send ("command run $DIR{$sym}[0]"); 2061 $::CONN->user_send ("run $DIR{$sym}[0]");
1888 } else { 2062 } else {
1889 $::CONN->user_send ("command $DIR{$sym}[1]"); 2063 $::CONN->user_send ("$DIR{$sym}[1]");
1890 } 2064 }
1891 } 2065 }
1892} 2066}
1893 2067
1894sub key_up { 2068sub key_up {
1896 2070
1897 my $mod = $ev->key_mod; 2071 my $mod = $ev->key_mod;
1898 my $sym = $ev->key_sym; 2072 my $sym = $ev->key_sym;
1899 2073
1900 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 2074 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1901 $::CONN->user_send ("command fire_stop"); 2075 $::CONN->user_send ("fire_stop");
1902 } 2076 }
1903 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 2077 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1904 $::CONN->user_send ("command run_stop"); 2078 $::CONN->user_send ("run_stop");
1905 } 2079 }
1906} 2080}
1907 2081
1908############################################################################# 2082#############################################################################
1909 2083
1992 2166
1993our @ISA = CFClient::UI::Container::; 2167our @ISA = CFClient::UI::Container::;
1994 2168
1995use SDL::OpenGL; 2169use SDL::OpenGL;
1996 2170
2171sub check_size {
2172 my ($self) = @_;
2173
2174 $self->size_allocate (0, 0, $::WITH, $::HEIGHT);
2175}
2176
1997sub size_request { 2177sub size_request {
1998 ($::WIDTH, $::HEIGHT) 2178 ($::WIDTH, $::HEIGHT)
1999} 2179}
2000 2180
2001sub size_allocate { 2181sub size_allocate {
2014} 2194}
2015 2195
2016sub update { 2196sub update {
2017 my ($self) = @_; 2197 my ($self) = @_;
2018 2198
2019 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2199 $self->check_size;
2020 ::refresh (); 2200 ::refresh ();
2021} 2201}
2022 2202
2023sub add { 2203sub add {
2024 my ($self, $widget) = @_; 2204 my ($self, $widget) = @_;
2025 2205
2026 $self->SUPER::add ($widget); 2206 $self->SUPER::add ($widget);
2027 2207
2028 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 2208 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2029} 2209}
2030 2210
2031sub on_refresh { 2211sub on_refresh {
2032 my ($self, $id, $cb) = @_; 2212 my ($self, $id, $cb) = @_;
2033 2213

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines