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.125 by root, Mon Apr 17 20:52:15 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};
370sub remove { 390sub remove {
371 my ($self, $widget) = @_; 391 my ($self, $widget) = @_;
372 392
373 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 393 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
374 394
375 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 395 $self->check_size;
376} 396}
377 397
378sub find_widget { 398sub find_widget {
379 my ($self, $x, $y) = @_; 399 my ($self, $x, $y) = @_;
380 400
500 $tex->draw_quad (0, 0, $w, $h); 520 $tex->draw_quad (0, 0, $w, $h);
501 521
502 glDisable GL_BLEND; 522 glDisable GL_BLEND;
503 glDisable GL_TEXTURE_2D; 523 glDisable GL_TEXTURE_2D;
504} 524}
525
526#############################################################################
527
528package CFClient::UI::ViewPort;
529
530our @ISA = CFClient::UI::Window::;
531
532sub new { die }
533
534sub size_request {
535 my ($self) = @_;
536
537 @$self{qw(child_w child_h)} = $self->child->size_request;
538 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
539
540 @$self{qw(child_w child_h)}
541}
542
543sub size_allocate {
544 my ($self, $x, $y, $w, $h) = @_;
545
546 $self->_size_allocate ($x, $y, $w, $h) or return;
547}
548
549sub _draw {
550 my ($self) = @_;
551
552 $self->{children}[1]->draw;
553}
554
505 555
506############################################################################# 556#############################################################################
507 557
508package CFClient::UI::Frame; 558package CFClient::UI::Frame;
509 559
565 # TODO: user_x, user_y, overwrite moveto? 615 # TODO: user_x, user_y, overwrite moveto?
566 616
567 $class->SUPER::new ( 617 $class->SUPER::new (
568 bg => [1, 1, 1, 1], 618 bg => [1, 1, 1, 1],
569 border_bg => [1, 1, 1, 1], 619 border_bg => [1, 1, 1, 1],
570 border => $::FONTSIZE * 0.8, 620 border => int $::FONTSIZE * 0.8,
571 @_ 621 @_
572 ) 622 )
573} 623}
574 624
575sub size_request { 625sub size_request {
840} 890}
841 891
842sub size_allocate { 892sub size_allocate {
843 my ($self, $x, $y, $w, $h) = @_; 893 my ($self, $x, $y, $w, $h) = @_;
844 894
845 $self->_size_allocate ($x, $y, $w, $h); 895 $self->_size_allocate ($x, $y, $w, $h) or return;
846 896
847 ($h, $w) = ($w, $h); 897 ($h, $w) = ($w, $h);
848 898
849 my $children = $self->{children}; 899 my $children = $self->{children};
850 900
876 my $h = $h[$_]; 926 my $h = $h[$_];
877 $child->size_allocate ($y, 0, $h, $w); 927 $child->size_allocate ($y, 0, $h, $w);
878 928
879 $y += $h; 929 $y += $h;
880 } 930 }
931
932 1
881} 933}
882 934
883############################################################################# 935#############################################################################
884 936
885package CFClient::UI::VBox; 937package CFClient::UI::VBox;
900} 952}
901 953
902sub size_allocate { 954sub size_allocate {
903 my ($self, $x, $y, $w, $h) = @_; 955 my ($self, $x, $y, $w, $h) = @_;
904 956
905 $self->_size_allocate ($x, $y, $w, $h); 957 $self->_size_allocate ($x, $y, $w, $h) or return;
906 958
907 my $children = $self->{children}; 959 my $children = $self->{children};
908 960
909 my @h = map +($_->size_request)[1], @$children; 961 my @h = map +($_->size_request)[1], @$children;
910 962
932 my $h = $h[$_]; 984 my $h = $h[$_];
933 $child->size_allocate (0, $y, $w, $h); 985 $child->size_allocate (0, $y, $w, $h);
934 986
935 $y += $h; 987 $y += $h;
936 } 988 }
989
990 1
937} 991}
938 992
939############################################################################# 993#############################################################################
940 994
941package CFClient::UI::Label; 995package CFClient::UI::Label;
950 my $self = $class->SUPER::new ( 1004 my $self = $class->SUPER::new (
951 fg => [1, 1, 1], 1005 fg => [1, 1, 1],
952 fontsize => $::FONTSIZE, 1006 fontsize => $::FONTSIZE,
953 text => "", 1007 text => "",
954 align => -1, 1008 align => -1,
1009 valign => -1,
955 padding => 2, 1010 padding => 2,
956 layout => new CFClient::Layout, 1011 layout => new CFClient::Layout,
957 %arg 1012 %arg
958 ); 1013 );
959 1014
960 $self->set_text ($self->{text}); 1015 $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d#
1016
1017 $self->set_text (delete $self->{text}) if exists $self->{text};
1018 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
961 1019
962 $self 1020 $self
963} 1021}
964 1022
965sub escape_text { 1023sub escape_text {
973} 1031}
974 1032
975sub set_text { 1033sub set_text {
976 my ($self, $text) = @_; 1034 my ($self, $text) = @_;
977 1035
978 $self->{text} = $text;
979 $self->{layout}->set_markup ($text); 1036 $self->{layout}->set_text ($text);
980 1037
981 delete $self->{texture}; 1038 delete $self->{texture};
982# $self->{w} = $self->{h} = -1;
983 $self->update; 1039 $self->update;
984} 1040}
985 1041
986sub get_text { 1042sub set_markup {
987 my ($self, $text) = @_; 1043 my ($self, $markup) = @_;
988 1044
989 $self->{text} 1045 $self->{layout}->set_markup ($markup);
1046
1047 delete $self->{texture};
1048 $self->update;
990} 1049}
991 1050
992sub size_request { 1051sub size_request {
993 my ($self) = @_; 1052 my ($self) = @_;
994 1053
995 $self->{layout}->set_width; 1054 $self->{layout}->set_width;
996 $self->{layout}->set_height ($self->{fontsize}); 1055 $self->{layout}->set_height ($self->{fontsize});
1056
997 my ($w, $h) = $self->{layout}->size; 1057 my ($w, $h) = $self->{layout}->size;
998 1058
999 ( 1059 (
1000 $w + $self->{padding} * 2, 1060 $w + $self->{padding} * 2,
1001 $h + $self->{padding} * 2, 1061 $h + $self->{padding} * 2,
1020sub _draw { 1080sub _draw {
1021 my ($self) = @_; 1081 my ($self) = @_;
1022 1082
1023 my $tex = $self->{texture} ||= do { 1083 my $tex = $self->{texture} ||= do {
1024 $self->{layout}->set_width ($self->{w}); 1084 $self->{layout}->set_width ($self->{w});
1025 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); 1085 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize});
1026 new_from_layout CFClient::Texture $self->{layout} 1086 new_from_layout CFClient::Texture $self->{layout}
1027 }; 1087 };
1028 1088
1029 glEnable GL_BLEND; 1089 glEnable GL_BLEND;
1030 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1090 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1031 glEnable GL_TEXTURE_2D; 1091 glEnable GL_TEXTURE_2D;
1032 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1092 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1033 1093
1034 glColor @{$self->{fg}}; 1094 glColor @{$self->{fg}};
1035 1095
1036 my $x = 1096 $self->{ox} = int (
1037 $self->{align} < 0 ? $self->{padding} 1097 $self->{align} < 0 ? $self->{padding}
1038 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1098 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1039 : ($self->{w} - $tex->{w}) * 0.5; 1099 : ($self->{w} - $tex->{w}) * 0.5
1100 );
1040 1101
1041 $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); 1102 $self->{oy} = int (
1103 $self->{valign} < 0 ? $self->{padding}
1104 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1105 : ($self->{h} - $tex->{h}) * 0.5
1106 );
1107
1108 $tex->draw_quad ($self->{ox}, $self->{oy});
1042 1109
1043 glDisable GL_TEXTURE_2D; 1110 glDisable GL_TEXTURE_2D;
1044 glDisable GL_BLEND; 1111 glDisable GL_BLEND;
1045} 1112}
1046 1113
1047############################################################################# 1114#############################################################################
1048 1115
1049package CFClient::UI::Entry; 1116package CFClient::UI::EntryBase;
1050 1117
1051our @ISA = CFClient::UI::Label::; 1118our @ISA = CFClient::UI::Label::;
1052 1119
1053use SDL; 1120use SDL;
1054use SDL::OpenGL; 1121use SDL::OpenGL;
1061 bg => [0, 0, 0, 0.2], 1128 bg => [0, 0, 0, 0.2],
1062 active_bg => [1, 1, 1, 0.5], 1129 active_bg => [1, 1, 1, 0.5],
1063 active_fg => [0, 0, 0], 1130 active_fg => [0, 0, 0],
1064 can_hover => 1, 1131 can_hover => 1,
1065 can_focus => 1, 1132 can_focus => 1,
1133 valign => 0,
1066 @_ 1134 @_
1067 ) 1135 )
1068} 1136}
1069 1137
1070sub _set_text { 1138sub _set_text {
1071 my ($self, $text) = @_; 1139 my ($self, $text) = @_;
1072 1140
1073 my $old_text = $self->{text}; 1141 delete $self->{cur_h};
1142
1143 return if $self->{text} eq $text;
1074 1144
1075 $self->{last_activity} = $::NOW; 1145 $self->{last_activity} = $::NOW;
1076
1077 $self->{text} = $text; 1146 $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 1147
1081 $text =~ s/./*/g if $self->{hidden}; 1148 $text =~ s/./*/g if $self->{hidden};
1149 $self->{layout}->set_text ("$text ");
1082 1150
1083 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1151 $self->emit (changed => $self->{text});
1152}
1084 1153
1085 $text = substr $text, 0, $self->{cursor}; 1154sub get_text {
1086 utf8::encode $text; 1155 $_[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} 1156}
1093 1157
1094sub size_request { 1158sub size_request {
1095 my ($self) = @_; 1159 my ($self) = @_;
1096 1160
1100} 1164}
1101 1165
1102sub size_allocate { 1166sub size_allocate {
1103 my ($self, $x, $y, $w, $h) = @_; 1167 my ($self, $x, $y, $w, $h) = @_;
1104 1168
1105 $self->SUPER::size_allocate ($x, $y, $w, $h); 1169 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1106 1170
1107 $self->_set_text ($self->{text}); 1171 $self->_set_text ($self->{text});
1108} 1172}
1109 1173
1110sub set_text { 1174sub set_text {
1200 1264
1201 $self->SUPER::_draw; 1265 $self->SUPER::_draw;
1202 1266
1203 #TODO: force update every cursor change :( 1267 #TODO: force update every cursor change :(
1204 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1268 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1269
1270 unless (exists $self->{cur_h}) {
1271 my $text = substr $self->{text}, 0, $self->{cursor};
1272 utf8::encode $text;
1273
1274 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1275 }
1276
1205 glColor @{$self->{fg}}; 1277 glColor @{$self->{fg}};
1206 glBegin GL_LINES; 1278 glBegin GL_LINES;
1207 glVertex $self->{cur_x}, $self->{cur_y};
1208 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1279 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1280 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1209 glEnd; 1281 glEnd;
1210 } 1282 }
1211} 1283}
1212 1284
1213package CFClient::UI::LineEntry; 1285package CFClient::UI::Entry;
1214 1286
1215our @ISA = CFClient::UI::Entry::; 1287our @ISA = CFClient::UI::EntryBase::;
1216 1288
1217use SDL; 1289use SDL;
1218use SDL::OpenGL; 1290use SDL::OpenGL;
1219 1291
1220sub key_down { 1292sub key_down {
1250 1322
1251 $class->SUPER::new ( 1323 $class->SUPER::new (
1252 padding => 4, 1324 padding => 4,
1253 fg => [1, 1, 1], 1325 fg => [1, 1, 1],
1254 bg => [1, 1, 1, 0.2], 1326 bg => [1, 1, 1, 0.2],
1255 active_fg => [1, 1, 0], 1327 active_fg => [0, 0, 1],
1256 can_hover => 1, 1328 can_hover => 1,
1257 @_ 1329 @_
1258 ) 1330 )
1259} 1331}
1260 1332
1269 1341
1270sub _draw { 1342sub _draw {
1271 my ($self) = @_; 1343 my ($self) = @_;
1272 1344
1273 local $self->{fg} = $self->{fg}; 1345 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 1346
1280 if ($GRAB == $self) { 1347 if ($GRAB == $self) {
1281 $self->{fg} = $self->{active_fg}; 1348 $self->{fg} = $self->{active_fg};
1282 } 1349 }
1283 1350
1284 glBindTexture GL_TEXTURE_2D, $tex->{name}; 1351 glEnable GL_BLEND;
1352 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1353 glEnable GL_TEXTURE_2D;
1285 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1354 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1355 glColor 0, 0, 0, 1;
1286 1356
1287 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 1357 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h});
1288 1358
1289 glDisable GL_TEXTURE_2D; 1359 glDisable GL_TEXTURE_2D;
1290 glDisable GL_BLEND; 1360 glDisable GL_BLEND;
1291 1361
1292 $self->SUPER::_draw; 1362 $self->SUPER::_draw;
1325} 1395}
1326 1396
1327sub size_allocate { 1397sub size_allocate {
1328 my ($self, $x, $y, $w, $h) = @_; 1398 my ($self, $x, $y, $w, $h) = @_;
1329 1399
1330 $self->_size_allocate ($x, $y, $w, $h); 1400 $self->_size_allocate ($x, $y, $w, $h) or return;
1331} 1401}
1332 1402
1333sub button_down { 1403sub button_down {
1334 my ($self, $ev, $x, $y) = @_; 1404 my ($self, $ev, $x, $y) = @_;
1335 1405
1359 1429
1360 $tex->draw_quad (0, 0, $s, $s); 1430 $tex->draw_quad (0, 0, $s, $s);
1361 1431
1362 glDisable GL_TEXTURE_2D; 1432 glDisable GL_TEXTURE_2D;
1363 glDisable GL_BLEND; 1433 glDisable GL_BLEND;
1434}
1435
1436#############################################################################
1437
1438package CFClient::UI::VGauge;
1439
1440our @ISA = CFClient::UI::Base::;
1441
1442use SDL::OpenGL;
1443
1444my %tex = (
1445 food => [
1446 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1447 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1448 ],
1449 grace => [
1450 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1451 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1452 ],
1453 hp => [
1454 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1455 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1456 ],
1457 mana => [
1458 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1459 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1460 ],
1461);
1462
1463# eg. VGauge->new (gauge => 'food'), default gauge: food
1464sub new {
1465 my $class = shift;
1466
1467 my $self = $class->SUPER::new (gauge => 'food', @_);
1468
1469 $self
1470}
1471
1472sub size_request {
1473 my ($self) = @_;
1474
1475 ($self->{w}, $self->{h})
1476}
1477
1478sub set_max {
1479 my ($self, $max) = @_;
1480 $self->{max_val} = $max;
1481}
1482
1483sub set_value {
1484 my ($self, $val, $max) = @_;
1485
1486 $self->set_max ($max)
1487 if defined $max;
1488
1489 $max = $self->{max_val};
1490 $self->{val} = $val;
1491
1492 $self->update;
1493}
1494
1495sub _draw {
1496 my ($self) = @_;
1497
1498 my $tex = $tex{$self->{gauge}};
1499
1500 my ($w, $h) = ($self->{w}, $self->{h});
1501
1502 my $ycut = $self->{val} / ($self->{max_val} || 1);
1503 $ycut = 1 if $self->{val} > $self->{max_val};
1504
1505 my $t1 = $tex->[0];
1506 my $t2 = $tex->[1];
1507
1508 glEnable GL_BLEND;
1509 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1510 glEnable GL_TEXTURE_2D;
1511 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1512
1513 my $h1 = $self->{h} - $ycut * $self->{h};
1514 my $h2 = $ycut * $self->{h};
1515
1516 my $yp = 0;
1517
1518 glBindTexture (GL_TEXTURE_2D, $t1->{name});
1519 glBegin (GL_QUADS);
1520 glTexCoord (0, 0); glVertex (0 , $yp);
1521 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1);
1522 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1);
1523 glTexCoord (1, 0); glVertex (0 + $w, $yp);
1524 glEnd ();
1525
1526 $yp += $h1;
1527
1528 glBindTexture (GL_TEXTURE_2D, $t2->{name});
1529 glBegin (GL_QUADS);
1530 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp);
1531 glTexCoord (0, 1); glVertex (0 , $yp + $h2);
1532 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2);
1533 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp);
1534 glEnd ();
1535
1536 glDisable GL_BLEND;
1537 glDisable GL_TEXTURE_2D;
1364} 1538}
1365 1539
1366############################################################################# 1540#############################################################################
1367 1541
1368package CFClient::UI::Slider; 1542package CFClient::UI::Slider;
1564} 1738}
1565 1739
1566sub size_allocate { 1740sub size_allocate {
1567 my ($self, $x, $y, $w, $h) = @_; 1741 my ($self, $x, $y, $w, $h) = @_;
1568 1742
1569 $self->SUPER::size_allocate ($x, $y, $w, $h); 1743 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1570 1744
1571 $self->{layout}->set_height ($self->{fontsize}); 1745 $self->{layout}->set_height ($self->{fontsize});
1572 $self->{layout}->set_width ($self->{w}); 1746 $self->{layout}->set_width ($self->{w});
1573 1747
1574 $self->reflow; 1748 $self->reflow;
1749 $self->update;
1575} 1750}
1576 1751
1577sub add_paragraph { 1752sub add_paragraph {
1578 my ($self, $color, $text) = @_; 1753 my ($self, $color, $text) = @_;
1579 1754
1774 0.1, 0.1, 0.1, 1949 0.1, 0.1, 0.1,
1775 ; 1950 ;
1776 glEnable GL_CONVOLUTION_2D; 1951 glEnable GL_CONVOLUTION_2D;
1777 } 1952 }
1778 1953
1779 my $tex = new CFClient::Texture 1954 $self->{fow_texture} = new CFClient::Texture
1780 w => $w, 1955 w => $w,
1781 h => $h, 1956 h => $h,
1782 data => $data, 1957 data => $data,
1783 internalformat => GL_ALPHA, 1958 internalformat => GL_ALPHA,
1784 format => GL_ALPHA; 1959 format => GL_ALPHA;
1789 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1964 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1790 glEnable GL_TEXTURE_2D; 1965 glEnable GL_TEXTURE_2D;
1791 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1966 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1792 1967
1793 glColor +($::CFG->{fow_intensity}) x 3, 1; 1968 glColor +($::CFG->{fow_intensity}) x 3, 1;
1794 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1969 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1795 1970
1796 glDisable GL_TEXTURE_2D; 1971 glDisable GL_TEXTURE_2D;
1797 glDisable GL_BLEND; 1972 glDisable GL_BLEND;
1798 } 1973 }
1799 1974
1805 glEnable GL_BLEND; 1980 glEnable GL_BLEND;
1806 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1981 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1807 glEnable GL_TEXTURE_2D; 1982 glEnable GL_TEXTURE_2D;
1808 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1983 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1809 1984
1985 $self->{mapmap_texture} =
1810 CFClient::Texture->new ( 1986 new CFClient::Texture
1811 w => $w, 1987 w => $w,
1812 h => $h, 1988 h => $h,
1813 data => $::MAP->mapmap ($w, $h), 1989 data => $::MAP->mapmap ($w, $h),
1814 type => GL_UNSIGNED_INT_8_8_8_8_REV 1990 type => GL_UNSIGNED_INT_8_8_8_8_REV;
1815 )->draw_quad (100, 100); 1991
1992 $self->{mapmap_texture}->draw_quad (100, 100);
1816 1993
1817 glDisable GL_TEXTURE_2D; 1994 glDisable GL_TEXTURE_2D;
1818 glDisable GL_BLEND; 1995 glDisable GL_BLEND;
1819 } 1996 }
1820 # HACK END 1997 # HACK END
1862 2039
1863 my $mod = $ev->key_mod; 2040 my $mod = $ev->key_mod;
1864 my $sym = $ev->key_sym; 2041 my $sym = $ev->key_sym;
1865 2042
1866 if ($sym == SDLK_KP5) { 2043 if ($sym == SDLK_KP5) {
1867 $::CONN->user_send ("command stay fire"); 2044 $::CONN->user_send ("stay fire");
1868 } elsif ($sym == SDLK_a) { 2045 } elsif ($sym == SDLK_a) {
1869 $::CONN->user_send ("command apply"); 2046 $::CONN->user_send ("apply");
1870 } elsif ($sym == SDLK_QUOTE) { 2047 } elsif ($sym == SDLK_QUOTE) {
1871 $self->emit ('activate_console'); 2048 $self->emit ('activate_console');
1872 } elsif ($sym == SDLK_SLASH) { 2049 } elsif ($sym == SDLK_SLASH) {
1873 $self->emit ('activate_console' => '/'); 2050 $self->emit ('activate_console' => '/');
1874 } elsif (exists $DIR{$sym}) { 2051 } elsif (exists $DIR{$sym}) {
1875 if ($mod & KMOD_SHIFT) { 2052 if ($mod & KMOD_SHIFT) {
1876 $self->{shft}++; 2053 $self->{shft}++;
1877 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 2054 $::CONN->user_send ("fire $DIR{$sym}[0]");
1878 } elsif ($mod & KMOD_CTRL) { 2055 } elsif ($mod & KMOD_CTRL) {
1879 $self->{ctrl}++; 2056 $self->{ctrl}++;
1880 $::CONN->user_send ("command run $DIR{$sym}[0]"); 2057 $::CONN->user_send ("run $DIR{$sym}[0]");
1881 } else { 2058 } else {
1882 $::CONN->user_send ("command $DIR{$sym}[1]"); 2059 $::CONN->user_send ("$DIR{$sym}[1]");
1883 } 2060 }
1884 } 2061 }
1885} 2062}
1886 2063
1887sub key_up { 2064sub key_up {
1889 2066
1890 my $mod = $ev->key_mod; 2067 my $mod = $ev->key_mod;
1891 my $sym = $ev->key_sym; 2068 my $sym = $ev->key_sym;
1892 2069
1893 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 2070 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1894 $::CONN->user_send ("command fire_stop"); 2071 $::CONN->user_send ("fire_stop");
1895 } 2072 }
1896 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 2073 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1897 $::CONN->user_send ("command run_stop"); 2074 $::CONN->user_send ("run_stop");
1898 } 2075 }
1899} 2076}
1900 2077
1901############################################################################# 2078#############################################################################
1902 2079
1985 2162
1986our @ISA = CFClient::UI::Container::; 2163our @ISA = CFClient::UI::Container::;
1987 2164
1988use SDL::OpenGL; 2165use SDL::OpenGL;
1989 2166
2167sub check_size {
2168 my ($self) = @_;
2169
2170 $self->size_allocate (0, 0, $::WITH, $::HEIGHT);
2171}
2172
1990sub size_request { 2173sub size_request {
1991 ($::WIDTH, $::HEIGHT) 2174 ($::WIDTH, $::HEIGHT)
1992} 2175}
1993 2176
1994sub size_allocate { 2177sub size_allocate {
2007} 2190}
2008 2191
2009sub update { 2192sub update {
2010 my ($self) = @_; 2193 my ($self) = @_;
2011 2194
2012 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2195 $self->check_size;
2013 ::refresh (); 2196 ::refresh ();
2014} 2197}
2015 2198
2016sub add { 2199sub add {
2017 my ($self, $widget) = @_; 2200 my ($self, $widget) = @_;
2018 2201
2019 $self->SUPER::add ($widget); 2202 $self->SUPER::add ($widget);
2020 2203
2021 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 2204 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2022} 2205}
2023 2206
2024sub on_refresh { 2207sub on_refresh {
2025 my ($self, $id, $cb) = @_; 2208 my ($self, $id, $cb) = @_;
2026 2209

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines