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.113 by root, Sat Apr 15 12:46:48 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 {
707 757
708 $self->{w} = $self->{h} = -1; 758 $self->{w} = $self->{h} = -1;
709 $self->update; 759 $self->update;
710} 760}
711 761
762# TODO: move to container class maybe? send childs a signal on removal?
763sub clear {
764 my ($self) = @_;
765
766 delete $self->{children};
767 $self->update;
768}
769
712sub get_wh { 770sub get_wh {
713 my ($self) = @_; 771 my ($self) = @_;
714 772
715 my (@w, @h); 773 my (@w, @h);
716 774
832} 890}
833 891
834sub size_allocate { 892sub size_allocate {
835 my ($self, $x, $y, $w, $h) = @_; 893 my ($self, $x, $y, $w, $h) = @_;
836 894
837 $self->_size_allocate ($x, $y, $w, $h); 895 $self->_size_allocate ($x, $y, $w, $h) or return;
838 896
839 ($h, $w) = ($w, $h); 897 ($h, $w) = ($w, $h);
840 898
841 my $children = $self->{children}; 899 my $children = $self->{children};
842 900
868 my $h = $h[$_]; 926 my $h = $h[$_];
869 $child->size_allocate ($y, 0, $h, $w); 927 $child->size_allocate ($y, 0, $h, $w);
870 928
871 $y += $h; 929 $y += $h;
872 } 930 }
931
932 1
873} 933}
874 934
875############################################################################# 935#############################################################################
876 936
877package CFClient::UI::VBox; 937package CFClient::UI::VBox;
892} 952}
893 953
894sub size_allocate { 954sub size_allocate {
895 my ($self, $x, $y, $w, $h) = @_; 955 my ($self, $x, $y, $w, $h) = @_;
896 956
897 $self->_size_allocate ($x, $y, $w, $h); 957 $self->_size_allocate ($x, $y, $w, $h) or return;
898 958
899 my $children = $self->{children}; 959 my $children = $self->{children};
900 960
901 my @h = map +($_->size_request)[1], @$children; 961 my @h = map +($_->size_request)[1], @$children;
902 962
924 my $h = $h[$_]; 984 my $h = $h[$_];
925 $child->size_allocate (0, $y, $w, $h); 985 $child->size_allocate (0, $y, $w, $h);
926 986
927 $y += $h; 987 $y += $h;
928 } 988 }
989
990 1
929} 991}
930 992
931############################################################################# 993#############################################################################
932 994
933package CFClient::UI::Label; 995package CFClient::UI::Label;
942 my $self = $class->SUPER::new ( 1004 my $self = $class->SUPER::new (
943 fg => [1, 1, 1], 1005 fg => [1, 1, 1],
944 fontsize => $::FONTSIZE, 1006 fontsize => $::FONTSIZE,
945 text => "", 1007 text => "",
946 align => -1, 1008 align => -1,
1009 valign => -1,
947 padding => 2, 1010 padding => 2,
948 layout => new CFClient::Layout, 1011 layout => new CFClient::Layout,
949 %arg 1012 %arg
950 ); 1013 );
951 1014
952 $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};
953 1019
954 $self 1020 $self
955} 1021}
956 1022
957sub escape_text { 1023sub escape_text {
965} 1031}
966 1032
967sub set_text { 1033sub set_text {
968 my ($self, $text) = @_; 1034 my ($self, $text) = @_;
969 1035
970 $self->{text} = $text;
971 $self->{layout}->set_markup ($text); 1036 $self->{layout}->set_text ($text);
972 1037
973 delete $self->{texture}; 1038 delete $self->{texture};
974# $self->{w} = $self->{h} = -1;
975 $self->update; 1039 $self->update;
976} 1040}
977 1041
978sub get_text { 1042sub set_markup {
979 my ($self, $text) = @_; 1043 my ($self, $markup) = @_;
980 1044
981 $self->{text} 1045 $self->{layout}->set_markup ($markup);
1046
1047 delete $self->{texture};
1048 $self->update;
982} 1049}
983 1050
984sub size_request { 1051sub size_request {
985 my ($self) = @_; 1052 my ($self) = @_;
986 1053
987 $self->{layout}->set_width; 1054 $self->{layout}->set_width;
988 $self->{layout}->set_height ($self->{fontsize}); 1055 $self->{layout}->set_height ($self->{fontsize});
1056
989 my ($w, $h) = $self->{layout}->size; 1057 my ($w, $h) = $self->{layout}->size;
990 1058
991 ( 1059 (
992 $w + $self->{padding} * 2, 1060 $w + $self->{padding} * 2,
993 $h + $self->{padding} * 2, 1061 $h + $self->{padding} * 2,
1012sub _draw { 1080sub _draw {
1013 my ($self) = @_; 1081 my ($self) = @_;
1014 1082
1015 my $tex = $self->{texture} ||= do { 1083 my $tex = $self->{texture} ||= do {
1016 $self->{layout}->set_width ($self->{w}); 1084 $self->{layout}->set_width ($self->{w});
1017 $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});
1018 new_from_layout CFClient::Texture $self->{layout} 1086 new_from_layout CFClient::Texture $self->{layout}
1019 }; 1087 };
1020 1088
1021 glEnable GL_BLEND; 1089 glEnable GL_BLEND;
1022 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1090 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1023 glEnable GL_TEXTURE_2D; 1091 glEnable GL_TEXTURE_2D;
1024 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1092 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1025 1093
1026 glColor @{$self->{fg}}; 1094 glColor @{$self->{fg}};
1027 1095
1028 my $x = 1096 $self->{ox} = int (
1029 $self->{align} < 0 ? $self->{padding} 1097 $self->{align} < 0 ? $self->{padding}
1030 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1098 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1031 : ($self->{w} - $tex->{w}) * 0.5; 1099 : ($self->{w} - $tex->{w}) * 0.5
1100 );
1032 1101
1033 $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});
1034 1109
1035 glDisable GL_TEXTURE_2D; 1110 glDisable GL_TEXTURE_2D;
1036 glDisable GL_BLEND; 1111 glDisable GL_BLEND;
1037} 1112}
1038 1113
1039############################################################################# 1114#############################################################################
1040 1115
1041package CFClient::UI::Entry; 1116package CFClient::UI::EntryBase;
1042 1117
1043our @ISA = CFClient::UI::Label::; 1118our @ISA = CFClient::UI::Label::;
1044 1119
1045use SDL; 1120use SDL;
1046use SDL::OpenGL; 1121use SDL::OpenGL;
1053 bg => [0, 0, 0, 0.2], 1128 bg => [0, 0, 0, 0.2],
1054 active_bg => [1, 1, 1, 0.5], 1129 active_bg => [1, 1, 1, 0.5],
1055 active_fg => [0, 0, 0], 1130 active_fg => [0, 0, 0],
1056 can_hover => 1, 1131 can_hover => 1,
1057 can_focus => 1, 1132 can_focus => 1,
1133 valign => 0,
1058 @_ 1134 @_
1059 ) 1135 )
1060} 1136}
1061 1137
1062sub _set_text { 1138sub _set_text {
1063 my ($self, $text) = @_; 1139 my ($self, $text) = @_;
1064 1140
1065 my $old_text = $self->{text}; 1141 delete $self->{cur_h};
1142
1143 return if $self->{text} eq $text;
1066 1144
1067 $self->{last_activity} = $::NOW; 1145 $self->{last_activity} = $::NOW;
1068
1069 $self->{text} = $text; 1146 $self->{text} = $text;
1070 $self->{layout}->set_width ($self->{w});
1071 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1072 1147
1073 $text =~ s/./*/g if $self->{hidden}; 1148 $text =~ s/./*/g if $self->{hidden};
1149 $self->{layout}->set_text ("$text ");
1074 1150
1075 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1151 $self->emit (changed => $self->{text});
1152}
1076 1153
1077 $text = substr $text, 0, $self->{cursor}; 1154sub get_text {
1078 utf8::encode $text; 1155 $_[0]{text}
1079
1080 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
1081
1082 $self->emit (changed => $self->{text}) # XXX: is this the right place to do this?
1083 if $old_text ne $self->{text};
1084} 1156}
1085 1157
1086sub size_request { 1158sub size_request {
1087 my ($self) = @_; 1159 my ($self) = @_;
1088 1160
1092} 1164}
1093 1165
1094sub size_allocate { 1166sub size_allocate {
1095 my ($self, $x, $y, $w, $h) = @_; 1167 my ($self, $x, $y, $w, $h) = @_;
1096 1168
1097 $self->SUPER::size_allocate ($x, $y, $w, $h); 1169 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1098 1170
1099 $self->_set_text ($self->{text}); 1171 $self->_set_text ($self->{text});
1100} 1172}
1101 1173
1102sub set_text { 1174sub set_text {
1192 1264
1193 $self->SUPER::_draw; 1265 $self->SUPER::_draw;
1194 1266
1195 #TODO: force update every cursor change :( 1267 #TODO: force update every cursor change :(
1196 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
1197 glColor @{$self->{fg}}; 1277 glColor @{$self->{fg}};
1198 glBegin GL_LINES; 1278 glBegin GL_LINES;
1199 glVertex $self->{cur_x}, $self->{cur_y};
1200 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};
1201 glEnd; 1281 glEnd;
1202 } 1282 }
1203} 1283}
1204 1284
1205package CFClient::UI::LineEntry; 1285package CFClient::UI::Entry;
1206 1286
1207our @ISA = CFClient::UI::Entry::; 1287our @ISA = CFClient::UI::EntryBase::;
1208 1288
1209use SDL; 1289use SDL;
1210use SDL::OpenGL; 1290use SDL::OpenGL;
1211 1291
1212sub key_down { 1292sub key_down {
1242 1322
1243 $class->SUPER::new ( 1323 $class->SUPER::new (
1244 padding => 4, 1324 padding => 4,
1245 fg => [1, 1, 1], 1325 fg => [1, 1, 1],
1246 bg => [1, 1, 1, 0.2], 1326 bg => [1, 1, 1, 0.2],
1247 active_fg => [1, 1, 0], 1327 active_fg => [0, 0, 1],
1248 can_hover => 1, 1328 can_hover => 1,
1249 @_ 1329 @_
1250 ) 1330 )
1251} 1331}
1252 1332
1261 1341
1262sub _draw { 1342sub _draw {
1263 my ($self) = @_; 1343 my ($self) = @_;
1264 1344
1265 local $self->{fg} = $self->{fg}; 1345 local $self->{fg} = $self->{fg};
1266 my $tex = $tex[0];
1267
1268 glEnable GL_BLEND;
1269 glEnable GL_TEXTURE_2D;
1270 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1271 1346
1272 if ($GRAB == $self) { 1347 if ($GRAB == $self) {
1273 $self->{fg} = $self->{active_fg}; 1348 $self->{fg} = $self->{active_fg};
1274 } 1349 }
1275 1350
1276 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;
1277 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;
1278 1356
1279 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 1357 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h});
1280 1358
1281 glDisable GL_TEXTURE_2D; 1359 glDisable GL_TEXTURE_2D;
1282 glDisable GL_BLEND; 1360 glDisable GL_BLEND;
1283 1361
1284 $self->SUPER::_draw; 1362 $self->SUPER::_draw;
1317} 1395}
1318 1396
1319sub size_allocate { 1397sub size_allocate {
1320 my ($self, $x, $y, $w, $h) = @_; 1398 my ($self, $x, $y, $w, $h) = @_;
1321 1399
1322 $self->_size_allocate ($x, $y, $w, $h); 1400 $self->_size_allocate ($x, $y, $w, $h) or return;
1323} 1401}
1324 1402
1325sub button_down { 1403sub button_down {
1326 my ($self, $ev, $x, $y) = @_; 1404 my ($self, $ev, $x, $y) = @_;
1327 1405
1351 1429
1352 $tex->draw_quad (0, 0, $s, $s); 1430 $tex->draw_quad (0, 0, $s, $s);
1353 1431
1354 glDisable GL_TEXTURE_2D; 1432 glDisable GL_TEXTURE_2D;
1355 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;
1356} 1538}
1357 1539
1358############################################################################# 1540#############################################################################
1359 1541
1360package CFClient::UI::Slider; 1542package CFClient::UI::Slider;
1556} 1738}
1557 1739
1558sub size_allocate { 1740sub size_allocate {
1559 my ($self, $x, $y, $w, $h) = @_; 1741 my ($self, $x, $y, $w, $h) = @_;
1560 1742
1561 $self->SUPER::size_allocate ($x, $y, $w, $h); 1743 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1562 1744
1563 $self->{layout}->set_height ($self->{fontsize}); 1745 $self->{layout}->set_height ($self->{fontsize});
1564 $self->{layout}->set_width ($self->{w}); 1746 $self->{layout}->set_width ($self->{w});
1565 1747
1566 $self->reflow; 1748 $self->reflow;
1749 $self->update;
1567} 1750}
1568 1751
1569sub add_paragraph { 1752sub add_paragraph {
1570 my ($self, $color, $text) = @_; 1753 my ($self, $color, $text) = @_;
1571 1754
1766 0.1, 0.1, 0.1, 1949 0.1, 0.1, 0.1,
1767 ; 1950 ;
1768 glEnable GL_CONVOLUTION_2D; 1951 glEnable GL_CONVOLUTION_2D;
1769 } 1952 }
1770 1953
1771 my $tex = new CFClient::Texture 1954 $self->{fow_texture} = new CFClient::Texture
1772 w => $w, 1955 w => $w,
1773 h => $h, 1956 h => $h,
1774 data => $data, 1957 data => $data,
1775 internalformat => GL_ALPHA, 1958 internalformat => GL_ALPHA,
1776 format => GL_ALPHA; 1959 format => GL_ALPHA;
1781 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1964 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1782 glEnable GL_TEXTURE_2D; 1965 glEnable GL_TEXTURE_2D;
1783 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1966 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1784 1967
1785 glColor +($::CFG->{fow_intensity}) x 3, 1; 1968 glColor +($::CFG->{fow_intensity}) x 3, 1;
1786 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1969 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1787 1970
1788 glDisable GL_TEXTURE_2D; 1971 glDisable GL_TEXTURE_2D;
1789 glDisable GL_BLEND; 1972 glDisable GL_BLEND;
1790 } 1973 }
1791 1974
1797 glEnable GL_BLEND; 1980 glEnable GL_BLEND;
1798 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1981 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1799 glEnable GL_TEXTURE_2D; 1982 glEnable GL_TEXTURE_2D;
1800 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1983 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1801 1984
1985 $self->{mapmap_texture} =
1802 CFClient::Texture->new ( 1986 new CFClient::Texture
1803 w => $w, 1987 w => $w,
1804 h => $h, 1988 h => $h,
1805 data => $::MAP->mapmap ($w, $h), 1989 data => $::MAP->mapmap ($w, $h),
1806 type => GL_UNSIGNED_INT_8_8_8_8_REV 1990 type => GL_UNSIGNED_INT_8_8_8_8_REV;
1807 )->draw_quad (100, 100); 1991
1992 $self->{mapmap_texture}->draw_quad (100, 100);
1808 1993
1809 glDisable GL_TEXTURE_2D; 1994 glDisable GL_TEXTURE_2D;
1810 glDisable GL_BLEND; 1995 glDisable GL_BLEND;
1811 } 1996 }
1812 # HACK END 1997 # HACK END
1854 2039
1855 my $mod = $ev->key_mod; 2040 my $mod = $ev->key_mod;
1856 my $sym = $ev->key_sym; 2041 my $sym = $ev->key_sym;
1857 2042
1858 if ($sym == SDLK_KP5) { 2043 if ($sym == SDLK_KP5) {
1859 $::CONN->user_send ("command stay fire"); 2044 $::CONN->user_send ("stay fire");
1860 } elsif ($sym == SDLK_a) { 2045 } elsif ($sym == SDLK_a) {
1861 $::CONN->user_send ("command apply"); 2046 $::CONN->user_send ("apply");
1862 } elsif ($sym == SDLK_QUOTE) { 2047 } elsif ($sym == SDLK_QUOTE) {
1863 $self->emit ('activate_console'); 2048 $self->emit ('activate_console');
1864 } elsif ($sym == SDLK_SLASH) { 2049 } elsif ($sym == SDLK_SLASH) {
1865 $self->emit ('activate_console' => '/'); 2050 $self->emit ('activate_console' => '/');
1866 } elsif (exists $DIR{$sym}) { 2051 } elsif (exists $DIR{$sym}) {
1867 if ($mod & KMOD_SHIFT) { 2052 if ($mod & KMOD_SHIFT) {
1868 $self->{shft}++; 2053 $self->{shft}++;
1869 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 2054 $::CONN->user_send ("fire $DIR{$sym}[0]");
1870 } elsif ($mod & KMOD_CTRL) { 2055 } elsif ($mod & KMOD_CTRL) {
1871 $self->{ctrl}++; 2056 $self->{ctrl}++;
1872 $::CONN->user_send ("command run $DIR{$sym}[0]"); 2057 $::CONN->user_send ("run $DIR{$sym}[0]");
1873 } else { 2058 } else {
1874 $::CONN->user_send ("command $DIR{$sym}[1]"); 2059 $::CONN->user_send ("$DIR{$sym}[1]");
1875 } 2060 }
1876 } 2061 }
1877} 2062}
1878 2063
1879sub key_up { 2064sub key_up {
1881 2066
1882 my $mod = $ev->key_mod; 2067 my $mod = $ev->key_mod;
1883 my $sym = $ev->key_sym; 2068 my $sym = $ev->key_sym;
1884 2069
1885 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 2070 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1886 $::CONN->user_send ("command fire_stop"); 2071 $::CONN->user_send ("fire_stop");
1887 } 2072 }
1888 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 2073 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1889 $::CONN->user_send ("command run_stop"); 2074 $::CONN->user_send ("run_stop");
1890 } 2075 }
1891} 2076}
1892 2077
1893############################################################################# 2078#############################################################################
1894 2079
1960 2145
1961 # TODO: use animation 2146 # TODO: use animation
1962 if ($self->{state} = !$self->{state}) { 2147 if ($self->{state} = !$self->{state}) {
1963 $CFClient::UI::ROOT->add ($self->{other}); 2148 $CFClient::UI::ROOT->add ($self->{other});
1964 $self->{other}->move ($self->coord2global (0, $self->{h})); 2149 $self->{other}->move ($self->coord2global (0, $self->{h}));
2150 $self->emit ("open");
1965 } else { 2151 } else {
1966 $CFClient::UI::ROOT->remove ($self->{other}); 2152 $CFClient::UI::ROOT->remove ($self->{other});
2153 $self->emit ("close");
1967 } 2154 }
2155
2156 $self->emit (changed => $self->{state});
1968} 2157}
1969 2158
1970############################################################################# 2159#############################################################################
1971 2160
1972package CFClient::UI::Root; 2161package CFClient::UI::Root;
1973 2162
1974our @ISA = CFClient::UI::Container::; 2163our @ISA = CFClient::UI::Container::;
1975 2164
1976use SDL::OpenGL; 2165use SDL::OpenGL;
2166
2167sub check_size {
2168 my ($self) = @_;
2169
2170 $self->size_allocate (0, 0, $::WITH, $::HEIGHT);
2171}
1977 2172
1978sub size_request { 2173sub size_request {
1979 ($::WIDTH, $::HEIGHT) 2174 ($::WIDTH, $::HEIGHT)
1980} 2175}
1981 2176
1995} 2190}
1996 2191
1997sub update { 2192sub update {
1998 my ($self) = @_; 2193 my ($self) = @_;
1999 2194
2000 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2195 $self->check_size;
2001 ::refresh (); 2196 ::refresh ();
2002} 2197}
2003 2198
2004sub add { 2199sub add {
2005 my ($self, $widget) = @_; 2200 my ($self, $widget) = @_;
2006 2201
2007 $self->SUPER::add ($widget); 2202 $self->SUPER::add ($widget);
2008 2203
2009 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 2204 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2010} 2205}
2011 2206
2012sub on_refresh { 2207sub on_refresh {
2013 my ($self, $id, $cb) = @_; 2208 my ($self, $id, $cb) = @_;
2014 2209

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines