… | |
… | |
144 | |
144 | |
145 | sub focus_in { |
145 | sub focus_in { |
146 | my ($self) = @_; |
146 | my ($self) = @_; |
147 | |
147 | |
148 | return if $FOCUS == $self; |
148 | return if $FOCUS == $self; |
|
|
149 | return unless $self->{can_focus}; |
149 | |
150 | |
150 | my $focus = $FOCUS; $FOCUS = $self; |
151 | my $focus = $FOCUS; $FOCUS = $self; |
151 | $focus->update if $focus; |
152 | $focus->update if $focus; |
152 | $FOCUS->update; |
153 | $FOCUS->update; |
153 | } |
154 | } |
… | |
… | |
186 | glPushMatrix; |
187 | glPushMatrix; |
187 | glTranslate $self->{x}, $self->{y}, 0; |
188 | glTranslate $self->{x}, $self->{y}, 0; |
188 | $self->_draw; |
189 | $self->_draw; |
189 | glPopMatrix; |
190 | glPopMatrix; |
190 | |
191 | |
191 | if ($self == $HOVER) { |
192 | if ($self == $HOVER && $self->{can_hover}) { |
192 | my ($x, $y) = @$self{qw(x y)}; |
193 | my ($x, $y) = @$self{qw(x y)}; |
193 | |
194 | |
194 | glColor 0, 0, 1, 0.2; |
195 | glColor 0, 0, 1, 0.2; |
195 | glEnable GL_BLEND; |
196 | glEnable GL_BLEND; |
196 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
197 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
529 | |
530 | |
530 | my @tex = |
531 | my @tex = |
531 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
532 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
532 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
533 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
533 | |
534 | |
|
|
535 | sub new { |
|
|
536 | my $class = shift; |
|
|
537 | |
|
|
538 | # TODO: user_x, user_y, overwrite moveto? |
|
|
539 | |
|
|
540 | $class->SUPER::new ( |
|
|
541 | bg => [1, 1, 1, 1], |
|
|
542 | border_bg => [1, 1, 1, 1], |
|
|
543 | border => $::FONTSIZE * 0.8, |
|
|
544 | @_ |
|
|
545 | ) |
|
|
546 | } |
|
|
547 | |
534 | sub size_request { |
548 | sub size_request { |
535 | my ($self) = @_; |
549 | my ($self) = @_; |
536 | |
550 | |
537 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
551 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
538 | |
552 | |
539 | my ($w, $h) = $self->SUPER::size_request; |
553 | my ($w, $h) = $self->SUPER::size_request; |
540 | |
554 | |
541 | $h += $tex[1]->{h}; |
555 | ( |
542 | $h += $tex[4]->{h}; |
556 | $w + $self->{border} * 2, |
543 | $w += $tex[2]->{w}; |
557 | $h + $self->{border} * 2, |
544 | $w += $tex[3]->{w}; |
558 | ) |
545 | |
|
|
546 | ($w, $h) |
|
|
547 | } |
559 | } |
548 | |
560 | |
549 | sub size_allocate { |
561 | sub size_allocate { |
550 | my ($self, $x, $y, $w, $h) = @_; |
562 | my ($self, $x, $y, $w, $h) = @_; |
551 | |
563 | |
552 | $self->_size_allocate ($x, $y, $w, $h) or return; |
564 | $self->_size_allocate ($x, $y, $w, $h) or return; |
553 | |
565 | |
554 | $h -= $tex[1]{h}; |
566 | $h -= List::Util::max 0, $self->{border} * 2; |
555 | $h -= $tex[4]{h}; |
567 | $w -= List::Util::max 0, $self->{border} * 2; |
556 | $w -= $tex[2]{w}; |
|
|
557 | $w -= $tex[3]{w}; |
|
|
558 | |
568 | |
559 | $h = $h < 0 ? 0 : $h; |
569 | $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); |
560 | $w = $w < 0 ? 0 : $w; |
|
|
561 | |
|
|
562 | my $child = $self->child; |
|
|
563 | |
|
|
564 | $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h); |
|
|
565 | } |
570 | } |
566 | |
571 | |
567 | sub button_down { |
572 | sub button_down { |
568 | my ($self, $ev, $x, $y) = @_; |
573 | my ($self, $ev, $x, $y) = @_; |
569 | |
574 | |
570 | if ($x < $self->{w} && $x >= $self->{w} - $tex[2]{w} |
575 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
571 | && $y < $self->{h} && $y >= $self->{h} - $tex[4]{h}) { |
576 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
572 | |
577 | |
573 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
578 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
574 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
579 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
575 | |
580 | |
576 | $self->{motion} = sub { |
581 | $self->{motion} = sub { |
… | |
… | |
582 | $self->{user_h} = $bh + $y - $oy; |
587 | $self->{user_h} = $bh + $y - $oy; |
583 | $self->update; |
588 | $self->update; |
584 | }; |
589 | }; |
585 | |
590 | |
586 | } elsif ($x >= 0 && $x < $self->{w} |
591 | } elsif ($x >= 0 && $x < $self->{w} |
587 | && $y >= 0 && $y < $tex[1]{h}) { |
592 | && $y >= 0 && $y < $self->{border}) { |
588 | |
593 | |
589 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
594 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
590 | my ($bx, $by) = ($self->{x}, $self->{y}); |
595 | my ($bx, $by) = ($self->{x}, $self->{y}); |
591 | |
596 | |
592 | $self->{motion} = sub { |
597 | $self->{motion} = sub { |
… | |
… | |
613 | } |
618 | } |
614 | |
619 | |
615 | sub _draw { |
620 | sub _draw { |
616 | my ($self) = @_; |
621 | my ($self) = @_; |
617 | |
622 | |
618 | my ($w, $h) = ($self->{w}, $self->{h}); |
623 | my ($w, $h ) = ($self->{w}, $self->{h}); |
619 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
624 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
620 | |
625 | |
621 | glEnable GL_BLEND; |
626 | glEnable GL_BLEND; |
622 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
627 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
623 | glEnable GL_TEXTURE_2D; |
628 | glEnable GL_TEXTURE_2D; |
624 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
629 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
625 | |
630 | |
626 | my $top = $tex[1]; |
631 | glColor @{ $self->{border_bg} }; |
627 | $top->draw_quad (0, 0, $w, $top->{h}); |
632 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
628 | |
633 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
629 | my $left = $tex[3]; |
634 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
630 | $left->draw_quad (0, $top->{h}, $left->{w}, $ch); |
635 | $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); |
631 | |
|
|
632 | my $right = $tex[2]; |
|
|
633 | $right->draw_quad ($w - $right->{w}, $top->{h}, $right->{w}, $ch); |
|
|
634 | |
|
|
635 | my $bottom = $tex[4]; |
|
|
636 | $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h}); |
|
|
637 | |
636 | |
638 | my $bg = $tex[0]; |
637 | my $bg = $tex[0]; |
639 | |
638 | |
640 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
639 | # TODO: repeat texture not scale |
641 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
642 | |
|
|
643 | my $rep_x = $cw / $bg->{w}; |
640 | my $rep_x = $cw / $bg->{w}; |
644 | my $rep_y = $ch / $bg->{h}; |
641 | my $rep_y = $ch / $bg->{h}; |
645 | |
642 | |
|
|
643 | glColor @{ $self->{bg} }; |
|
|
644 | |
|
|
645 | $bg->{s} = $rep_x; |
|
|
646 | $bg->{t} = $rep_y; |
|
|
647 | $bg->{wrap_mode} = 1; |
646 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
648 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
647 | |
649 | |
648 | glDisable GL_TEXTURE_2D; |
650 | glDisable GL_TEXTURE_2D; |
649 | glDisable GL_BLEND; |
651 | glDisable GL_BLEND; |
650 | |
652 | |
651 | $self->child->draw; |
653 | $self->child->draw; |
652 | |
|
|
653 | } |
654 | } |
654 | |
655 | |
655 | ############################################################################# |
656 | ############################################################################# |
656 | |
657 | |
657 | package CFClient::UI::Table; |
658 | package CFClient::UI::Table; |
… | |
… | |
993 | my $x = |
994 | my $x = |
994 | $self->{align} < 0 ? $self->{padding} |
995 | $self->{align} < 0 ? $self->{padding} |
995 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
996 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
996 | : ($self->{w} - $tex->{w}) * 0.5; |
997 | : ($self->{w} - $tex->{w}) * 0.5; |
997 | |
998 | |
998 | glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0; |
999 | glTranslate int $x, int +($self->{h} - $tex->{h}) * 0.5, 0; |
999 | $tex->draw_quad (0, 0); |
1000 | $tex->draw_quad (0, 0); |
1000 | |
1001 | |
1001 | glDisable GL_TEXTURE_2D; |
1002 | glDisable GL_TEXTURE_2D; |
1002 | glDisable GL_BLEND; |
1003 | glDisable GL_BLEND; |
1003 | } |
1004 | } |
… | |
… | |
1017 | $class->SUPER::new ( |
1018 | $class->SUPER::new ( |
1018 | fg => [1, 1, 1], |
1019 | fg => [1, 1, 1], |
1019 | bg => [0, 0, 0, 0.2], |
1020 | bg => [0, 0, 0, 0.2], |
1020 | active_bg => [1, 1, 1, 0.5], |
1021 | active_bg => [1, 1, 1, 0.5], |
1021 | active_fg => [0, 0, 0], |
1022 | active_fg => [0, 0, 0], |
|
|
1023 | can_hover => 1, |
|
|
1024 | can_focus => 1, |
1022 | @_ |
1025 | @_ |
1023 | ) |
1026 | ) |
1024 | } |
1027 | } |
1025 | |
1028 | |
1026 | sub _set_text { |
1029 | sub _set_text { |
1027 | my ($self, $text) = @_; |
1030 | my ($self, $text) = @_; |
|
|
1031 | |
|
|
1032 | my $old_text = $self->{text}; |
1028 | |
1033 | |
1029 | $self->{last_activity} = $::NOW; |
1034 | $self->{last_activity} = $::NOW; |
1030 | |
1035 | |
1031 | $self->{text} = $text; |
1036 | $self->{text} = $text; |
1032 | $self->{layout}->set_width ($self->{w}); |
1037 | $self->{layout}->set_width ($self->{w}); |
… | |
… | |
1038 | |
1043 | |
1039 | $text = substr $text, 0, $self->{cursor}; |
1044 | $text = substr $text, 0, $self->{cursor}; |
1040 | utf8::encode $text; |
1045 | utf8::encode $text; |
1041 | |
1046 | |
1042 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
1047 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
|
|
1048 | |
|
|
1049 | $self->emit (changed => $self->{text}) # XXX: is this the right place to do this? |
|
|
1050 | if $old_text ne $self->{text}; |
1043 | } |
1051 | } |
1044 | |
1052 | |
1045 | sub size_request { |
1053 | sub size_request { |
1046 | my ($self) = @_; |
1054 | my ($self) = @_; |
1047 | |
1055 | |
… | |
… | |
1086 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1094 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1087 | } elsif ($sym == SDLK_HOME) { |
1095 | } elsif ($sym == SDLK_HOME) { |
1088 | $self->{cursor} = 0; |
1096 | $self->{cursor} = 0; |
1089 | } elsif ($sym == SDLK_END) { |
1097 | } elsif ($sym == SDLK_END) { |
1090 | $self->{cursor} = length $text; |
1098 | $self->{cursor} = length $text; |
|
|
1099 | } elsif ($sym == SDLK_ESCAPE) { |
|
|
1100 | $self->emit ('escape'); |
1091 | } elsif ($uni) { |
1101 | } elsif ($uni) { |
1092 | substr $text, $self->{cursor}++, 0, chr $uni; |
1102 | substr $text, $self->{cursor}++, 0, chr $uni; |
1093 | } |
1103 | } |
1094 | |
1104 | |
1095 | $self->_set_text ($text); |
1105 | $self->_set_text ($text); |
… | |
… | |
1157 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1167 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1158 | glEnd; |
1168 | glEnd; |
1159 | } |
1169 | } |
1160 | } |
1170 | } |
1161 | |
1171 | |
|
|
1172 | package CFClient::UI::LineEntry; |
|
|
1173 | |
|
|
1174 | our @ISA = CFClient::UI::Entry::; |
|
|
1175 | |
|
|
1176 | use SDL; |
|
|
1177 | use SDL::OpenGL; |
|
|
1178 | |
|
|
1179 | sub key_down { |
|
|
1180 | my ($self, $ev) = @_; |
|
|
1181 | |
|
|
1182 | my $sym = $ev->key_sym; |
|
|
1183 | |
|
|
1184 | if ($sym == SDLK_RETURN) { |
|
|
1185 | $self->emit (activate => $self->get_text); |
|
|
1186 | $self->update; |
|
|
1187 | |
|
|
1188 | } else { |
|
|
1189 | $self->SUPER::key_down ($ev); |
|
|
1190 | } |
|
|
1191 | |
|
|
1192 | } |
|
|
1193 | |
1162 | ############################################################################# |
1194 | ############################################################################# |
1163 | |
1195 | |
1164 | package CFClient::UI::Button; |
1196 | package CFClient::UI::Button; |
1165 | |
1197 | |
1166 | our @ISA = CFClient::UI::Label::; |
1198 | our @ISA = CFClient::UI::Label::; |
… | |
… | |
1178 | $class->SUPER::new ( |
1210 | $class->SUPER::new ( |
1179 | padding => 4, |
1211 | padding => 4, |
1180 | fg => [1, 1, 1], |
1212 | fg => [1, 1, 1], |
1181 | bg => [1, 1, 1, 0.2], |
1213 | bg => [1, 1, 1, 0.2], |
1182 | active_fg => [1, 1, 0], |
1214 | active_fg => [1, 1, 0], |
1183 | # active_bg => [0, 0, 0, 0.5], |
1215 | can_hover => 1, |
1184 | # border_fg => [1, 1, 0], |
|
|
1185 | @_ |
1216 | @_ |
1186 | ) |
1217 | ) |
1187 | } |
1218 | } |
1188 | |
1219 | |
1189 | sub button_up { |
1220 | sub button_up { |
… | |
… | |
1235 | $class->SUPER::new ( |
1266 | $class->SUPER::new ( |
1236 | padding => 2, |
1267 | padding => 2, |
1237 | fg => [1, 1, 1], |
1268 | fg => [1, 1, 1], |
1238 | active_fg => [1, 1, 0], |
1269 | active_fg => [1, 1, 0], |
1239 | state => 0, |
1270 | state => 0, |
|
|
1271 | can_hover => 1, |
1240 | @_ |
1272 | @_ |
1241 | ) |
1273 | ) |
1242 | } |
1274 | } |
1243 | |
1275 | |
1244 | sub size_request { |
1276 | sub size_request { |
… | |
… | |
1299 | |
1331 | |
1300 | use SDL::OpenGL; |
1332 | use SDL::OpenGL; |
1301 | |
1333 | |
1302 | our @ISA = CFClient::UI::DrawBG::; |
1334 | our @ISA = CFClient::UI::DrawBG::; |
1303 | |
1335 | |
|
|
1336 | my @tex = |
|
|
1337 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1338 | qw(s1_slider.png s1_slider_bg.png); |
|
|
1339 | |
1304 | sub new { |
1340 | sub new { |
1305 | my $class = shift; |
1341 | my $class = shift; |
1306 | |
1342 | |
1307 | # range [value, low, high, page] |
1343 | # range [value, low, high, page] |
1308 | |
1344 | |
|
|
1345 | # TODO: 0-width page |
|
|
1346 | # TODO: req_w/h are wrong with vertical |
|
|
1347 | # TODO: calculations are off |
1309 | my $self = $class->SUPER::new ( |
1348 | my $self = $class->SUPER::new ( |
1310 | fg => [1, 1, 1], |
1349 | fg => [1, 1, 1], |
1311 | active_fg => [0, 0, 0], |
1350 | active_fg => [0, 0, 0], |
1312 | range => [0, 0, 100, 10], |
1351 | range => [0, 0, 100, 10], |
1313 | req_w => 40, |
1352 | req_w => 40, |
1314 | req_h => 10, |
1353 | req_h => 13, |
1315 | vertical => 0, |
1354 | vertical => 0, |
|
|
1355 | can_hover => 1, |
1316 | @_ |
1356 | @_ |
1317 | ); |
1357 | ); |
1318 | |
1358 | |
1319 | $self |
1359 | $self |
1320 | } |
1360 | } |
… | |
… | |
1372 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
1412 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
1373 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
1413 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
1374 | |
1414 | |
1375 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1415 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1376 | |
1416 | |
|
|
1417 | # the inner_* stuff is for generating a padding for the slider handle, |
|
|
1418 | # so that the handle doesn't leave the texture. This calculation isn't 100% |
|
|
1419 | # correct propably, but it does the job for now |
|
|
1420 | my $inner_pad = 5; # 5% of width for slider bg texture border |
|
|
1421 | my $inner_pad_px = ($w / 100) * $inner_pad; # % to pixels |
|
|
1422 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
|
|
1423 | |
1377 | $page = int $page * $w / ($hi - $lo); |
1424 | $page = int $page * $inner_w / ($hi - $lo); |
1378 | $value = int +($value - $lo) * $w / ($hi - $lo); |
1425 | $value = int +($value - $lo) * $inner_w / ($hi - $lo); |
1379 | |
1426 | |
1380 | $w -= $page; |
1427 | $w -= $page; |
1381 | $page &= ~1; |
1428 | $page &= ~1; |
1382 | glTranslate $page * 0.5, 0, 0; |
1429 | glTranslate $page * 0.5, 0, 0; |
1383 | $page ||= 2; |
1430 | $page ||= 2; |
1384 | |
1431 | |
1385 | glColor @$fg; |
|
|
1386 | glBegin GL_LINES; |
|
|
1387 | glVertex 0, 0; glVertex 0, $h; |
|
|
1388 | glVertex $w - 1, 0; glVertex $w - 1, $h; |
|
|
1389 | glVertex 0, $h * 0.5; glVertex $w, $h * 0.5; |
|
|
1390 | glEnd; |
|
|
1391 | |
|
|
1392 | my $knob_a = $value - $page * 0.5; |
1432 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
1393 | my $knob_b = $value + $page * 0.5; |
1433 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
1394 | |
1434 | |
1395 | glBegin GL_QUADS; |
1435 | glEnable GL_BLEND; |
1396 | glColor @$fg; |
1436 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1397 | glVertex $knob_a, 0; |
1437 | glEnable GL_TEXTURE_2D; |
1398 | glVertex $knob_a, $h; |
1438 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1399 | glVertex $knob_b, $h; |
|
|
1400 | glVertex $knob_b, 0; |
|
|
1401 | |
1439 | |
1402 | if ($knob_a < $knob_b - 2) { |
1440 | # draw background |
1403 | glColor @$bg; |
1441 | $tex[1]->draw_quad (0, 0, $w, $h); |
1404 | glVertex $knob_a + 1, 1; |
1442 | |
1405 | glVertex $knob_a + 1, $h - 1; |
1443 | # draw handle |
1406 | glVertex $knob_b - 1, $h - 1; |
1444 | $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); |
1407 | glVertex $knob_b - 1, 1; |
1445 | |
|
|
1446 | glDisable GL_BLEND; |
|
|
1447 | glDisable GL_TEXTURE_2D; |
|
|
1448 | } |
|
|
1449 | |
|
|
1450 | ############################################################################# |
|
|
1451 | |
|
|
1452 | package CFClient::UI::TextView; |
|
|
1453 | |
|
|
1454 | our @ISA = CFClient::UI::HBox::; |
|
|
1455 | |
|
|
1456 | use SDL::OpenGL; |
|
|
1457 | |
|
|
1458 | sub new { |
|
|
1459 | my $class = shift; |
|
|
1460 | |
|
|
1461 | my $self = $class->SUPER::new ( |
|
|
1462 | par => [], |
|
|
1463 | @_, |
|
|
1464 | children => [ |
|
|
1465 | (new CFClient::UI::Empty expand => 1), |
|
|
1466 | (new CFClient::UI::Slider vertical => 1), |
|
|
1467 | ], |
|
|
1468 | ); |
|
|
1469 | |
|
|
1470 | $self |
|
|
1471 | } |
|
|
1472 | |
|
|
1473 | sub add_paragraph { |
|
|
1474 | my ($self, $color, $text) = @_; |
|
|
1475 | |
|
|
1476 | push @{$self->{par}}, [$color, $text]; |
|
|
1477 | my $count = scalar @{$self->{par}}; |
|
|
1478 | $self->{children}[1]{range} = [$count - 1, 0, $count, 1]; |
|
|
1479 | $self->{children}[1]->update; |
|
|
1480 | } |
|
|
1481 | |
|
|
1482 | sub _draw { |
|
|
1483 | my ($self) = @_; |
|
|
1484 | |
|
|
1485 | my $par = $self->{par}; |
|
|
1486 | |
|
|
1487 | my $bottom = (scalar @$par) - 1; |
|
|
1488 | |
|
|
1489 | my $w = $self->{children}[0]{w}; |
|
|
1490 | my $y = $self->{h}; |
|
|
1491 | |
|
|
1492 | glEnable GL_BLEND; |
|
|
1493 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1494 | glEnable GL_TEXTURE_2D; |
|
|
1495 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1496 | |
|
|
1497 | # TODO: everything! |
|
|
1498 | while ($y > 0 && $bottom >= 0) { |
|
|
1499 | my $par = $par->[$bottom--]; |
|
|
1500 | |
|
|
1501 | my $layout = new CFClient::Layout; |
|
|
1502 | |
|
|
1503 | $layout->set_height ($::FONTSIZE); |
|
|
1504 | $layout->set_width ($w); |
|
|
1505 | $layout->set_text ($par->[1]); |
|
|
1506 | my $tex = new_from_layout CFClient::Texture $layout; |
|
|
1507 | $y -= $tex->{h}; |
|
|
1508 | |
|
|
1509 | glColor @{ $par->[0] }; |
|
|
1510 | $tex->draw_quad (0, $y); |
1408 | } |
1511 | } |
1409 | glEnd; |
1512 | |
|
|
1513 | glDisable GL_TEXTURE_2D; |
|
|
1514 | glDisable GL_BLEND; |
1410 | } |
1515 | } |
1411 | |
1516 | |
1412 | ############################################################################# |
1517 | ############################################################################# |
1413 | |
1518 | |
1414 | package CFClient::UI::MapWidget; |
1519 | package CFClient::UI::MapWidget; |
… | |
… | |
1424 | |
1529 | |
1425 | sub new { |
1530 | sub new { |
1426 | my $class = shift; |
1531 | my $class = shift; |
1427 | |
1532 | |
1428 | $class->SUPER::new ( |
1533 | $class->SUPER::new ( |
1429 | z => -1, |
1534 | z => -1, |
|
|
1535 | can_focus => 1, |
1430 | list => (glGenLists 1), |
1536 | list => (glGenLists 1), |
1431 | @_ |
1537 | @_ |
1432 | ) |
1538 | ) |
1433 | } |
1539 | } |
1434 | |
1540 | |
1435 | sub key_down { |
1541 | sub key_down { |
… | |
… | |
1454 | } |
1560 | } |
1455 | |
1561 | |
1456 | sub draw { |
1562 | sub draw { |
1457 | my ($self) = @_; |
1563 | my ($self) = @_; |
1458 | |
1564 | |
|
|
1565 | $self->{need_update}++;#d# |
1459 | if (delete $self->{need_update}) { |
1566 | if (delete $self->{need_update}) { |
1460 | glNewList $self->{list}, GL_COMPILE; |
1567 | glNewList $self->{list}, GL_COMPILE; |
1461 | |
1568 | |
1462 | my $mx = $::CONN->{mapx}; |
|
|
1463 | my $my = $::CONN->{mapy}; |
|
|
1464 | |
|
|
1465 | my $map = $::CONN->{map}; |
|
|
1466 | |
|
|
1467 | my ($xofs, $yofs); |
|
|
1468 | |
|
|
1469 | my $sw = 1 + int $::WIDTH / 32; |
1569 | my $sw = int $::WIDTH / 32; |
1470 | my $sh = 1 + int $::HEIGHT / 32; |
1570 | my $sh = int $::HEIGHT / 32; |
1471 | |
1571 | |
1472 | if ($::CONN->{mapw} > $sw) { |
1572 | if ($::MAP) { |
1473 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
1573 | my ($w, $h, $data) = $::MAP->draw (0, 0, $sw, $sh); |
1474 | } else { |
|
|
1475 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
|
|
1476 | } |
|
|
1477 | |
1574 | |
1478 | if ($::CONN->{maph} > $sh) { |
1575 | if ($::CFG->{fow_enable}) { |
1479 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
1576 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
1480 | } else { |
1577 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
1481 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
1578 | glConvolutionFilter2D |
1482 | } |
1579 | GL_CONVOLUTION_2D, |
1483 | |
1580 | GL_ALPHA, |
1484 | glEnable GL_TEXTURE_2D; |
1581 | 3, 3, |
1485 | glEnable GL_BLEND; |
1582 | GL_ALPHA, GL_FLOAT, |
1486 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1583 | pack "f*", |
1487 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1584 | 0.1, 0.1, 0.1, |
1488 | glColor 1, 1, 1, 1; |
1585 | 0.1, 0.2, 0.1, |
1489 | |
1586 | 0.1, 0.1, 0.1, |
1490 | my $sw4 = ($sw + 3) & ~3; |
|
|
1491 | my $darkness = "\x00" x ($sw4 * $sh); |
|
|
1492 | |
|
|
1493 | for my $x (0 .. $sw - 1) { |
|
|
1494 | my $row = $map->[$x + $xofs]; |
|
|
1495 | for my $y (0 .. $sh - 1) { |
|
|
1496 | |
|
|
1497 | my $cell = $row->[$y + $yofs] |
|
|
1498 | or next; |
1587 | ; |
1499 | |
1588 | glEnable GL_CONVOLUTION_2D; |
1500 | my $dark = $cell->[0]; |
|
|
1501 | if ($dark < 0) { |
|
|
1502 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
1503 | } else { |
|
|
1504 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
|
|
1505 | } |
1589 | } |
1506 | |
1590 | |
1507 | for my $num (grep $_, @$cell[1,2,3]) { |
1591 | my $tex = new CFClient::Texture |
1508 | my $tex = $::CONN->{face}[$num]{texture} || next; |
1592 | w => $w, |
1509 | |
1593 | h => $h, |
1510 | my ($w, $h) = @$tex{qw(w h)}; |
1594 | data => $data, |
|
|
1595 | internalformat => GL_ALPHA, |
|
|
1596 | format => GL_ALPHA; |
1511 | |
1597 | |
1512 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1598 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1513 | } |
1599 | |
|
|
1600 | glEnable GL_BLEND; |
|
|
1601 | glEnable GL_TEXTURE_2D; |
|
|
1602 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1603 | |
|
|
1604 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1605 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1606 | |
|
|
1607 | glDisable GL_TEXTURE_2D; |
|
|
1608 | glDisable GL_BLEND; |
1514 | } |
1609 | } |
1515 | } |
1610 | } |
1516 | |
1611 | |
1517 | # if (1) { # higher quality darkness |
|
|
1518 | # $lighting =~ s/(.)/$1$1$1/gs; |
|
|
1519 | # my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; |
|
|
1520 | # |
|
|
1521 | # $pb = $pb->scale_simple ($sw4 * 0.5, $sh * 0.5, "bilinear"); |
|
|
1522 | # |
|
|
1523 | # $lighting = $pb->get_pixels; |
|
|
1524 | # $lighting =~ s/(.)../$1/gs; |
|
|
1525 | # } |
|
|
1526 | |
|
|
1527 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1528 | |
|
|
1529 | $darkness = new CFClient::Texture |
|
|
1530 | w => $sw4, |
|
|
1531 | h => $sh, |
|
|
1532 | data => $darkness, |
|
|
1533 | internalformat => GL_ALPHA, |
|
|
1534 | format => GL_ALPHA; |
|
|
1535 | |
|
|
1536 | glColor 0.45, 0.45, 0.45, 1; |
|
|
1537 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
|
|
1538 | |
|
|
1539 | glDisable GL_TEXTURE_2D; |
|
|
1540 | glDisable GL_BLEND; |
|
|
1541 | |
|
|
1542 | glEndList; |
1612 | glEndList; |
1543 | } |
1613 | } |
1544 | |
1614 | |
1545 | glCallList $self->{list}; |
1615 | glCallList $self->{list}; |
1546 | |
1616 | |
1547 | if ($FOCUS != $self) { |
1617 | if ($FOCUS != $self) { |
1548 | glEnable GL_BLEND; |
1618 | glColor 64/255, 64/255, 64/255; |
1549 | glColor 0, 0, 1, 0.4; |
1619 | glLogicOp GL_AND; |
|
|
1620 | glEnable GL_COLOR_LOGIC_OP; |
1550 | glBegin GL_QUADS; |
1621 | glBegin GL_QUADS; |
1551 | glVertex 0, 0; |
1622 | glVertex 0, 0; |
1552 | glVertex 0, $::HEIGHT; |
1623 | glVertex 0, $::HEIGHT; |
1553 | glVertex $::WIDTH, $::HEIGHT; |
1624 | glVertex $::WIDTH, $::HEIGHT; |
1554 | glVertex $::WIDTH, 0; |
1625 | glVertex $::WIDTH, 0; |
1555 | glEnd; |
1626 | glEnd; |
1556 | glDisable GL_BLEND; |
1627 | glDisable GL_COLOR_LOGIC_OP; |
1557 | } |
1628 | } |
1558 | } |
1629 | } |
1559 | |
1630 | |
1560 | my %DIR = ( |
1631 | my %DIR = ( |
1561 | SDLK_KP8, [1, "north"], |
1632 | SDLK_KP8, [1, "north"], |
… | |
… | |
1578 | |
1649 | |
1579 | my $mod = $ev->key_mod; |
1650 | my $mod = $ev->key_mod; |
1580 | my $sym = $ev->key_sym; |
1651 | my $sym = $ev->key_sym; |
1581 | |
1652 | |
1582 | if ($sym == SDLK_KP5) { |
1653 | if ($sym == SDLK_KP5) { |
1583 | $::CONN->send ("command stay fire"); |
1654 | $::CONN->user_send ("command stay fire"); |
1584 | } elsif ($sym == SDLK_a) { |
1655 | } elsif ($sym == SDLK_a) { |
1585 | $::CONN->send ("command apply"); |
1656 | $::CONN->user_send ("command apply"); |
|
|
1657 | } elsif ($sym == SDLK_QUOTE) { |
|
|
1658 | $self->emit ('activate_console'); |
1586 | } elsif (exists $DIR{$sym}) { |
1659 | } elsif (exists $DIR{$sym}) { |
1587 | if ($mod & KMOD_SHIFT) { |
1660 | if ($mod & KMOD_SHIFT) { |
1588 | $self->{shft}++; |
1661 | $self->{shft}++; |
1589 | $::CONN->send ("command fire $DIR{$sym}[0]"); |
1662 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1590 | } elsif ($mod & KMOD_CTRL) { |
1663 | } elsif ($mod & KMOD_CTRL) { |
1591 | $self->{ctrl}++; |
1664 | $self->{ctrl}++; |
1592 | $::CONN->send ("command run $DIR{$sym}[0]"); |
1665 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
1593 | } else { |
1666 | } else { |
1594 | $::CONN->send ("command $DIR{$sym}[1]"); |
1667 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
1595 | } |
1668 | } |
1596 | } |
1669 | } |
1597 | } |
1670 | } |
1598 | |
1671 | |
1599 | sub key_up { |
1672 | sub key_up { |
… | |
… | |
1601 | |
1674 | |
1602 | my $mod = $ev->key_mod; |
1675 | my $mod = $ev->key_mod; |
1603 | my $sym = $ev->key_sym; |
1676 | my $sym = $ev->key_sym; |
1604 | |
1677 | |
1605 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1678 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1606 | $::CONN->send ("command fire_stop"); |
1679 | $::CONN->user_send ("command fire_stop"); |
1607 | } |
1680 | } |
1608 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1681 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1609 | $::CONN->send ("command run_stop"); |
1682 | $::CONN->user_send ("command run_stop"); |
1610 | } |
1683 | } |
1611 | } |
1684 | } |
1612 | |
1685 | |
1613 | ############################################################################# |
1686 | ############################################################################# |
1614 | |
1687 | |
… | |
… | |
1652 | glPopMatrix; |
1725 | glPopMatrix; |
1653 | } |
1726 | } |
1654 | |
1727 | |
1655 | ############################################################################# |
1728 | ############################################################################# |
1656 | |
1729 | |
|
|
1730 | package CFClient::UI::Flopper; |
|
|
1731 | |
|
|
1732 | our @ISA = CFClient::UI::Button::; |
|
|
1733 | |
|
|
1734 | sub new { |
|
|
1735 | my $class = shift; |
|
|
1736 | |
|
|
1737 | my $self = $class->SUPER::new ( |
|
|
1738 | state => 0, |
|
|
1739 | connect_activate => \&toggle_flopper, |
|
|
1740 | @_ |
|
|
1741 | ); |
|
|
1742 | |
|
|
1743 | if ($self->{state}) { |
|
|
1744 | $self->{state} = 0; |
|
|
1745 | $self->toggle_flopper; |
|
|
1746 | } |
|
|
1747 | |
|
|
1748 | $self |
|
|
1749 | } |
|
|
1750 | |
|
|
1751 | sub toggle_flopper { |
|
|
1752 | my ($self) = @_; |
|
|
1753 | |
|
|
1754 | # TODO: use animation |
|
|
1755 | if ($self->{state} = !$self->{state}) { |
|
|
1756 | $CFClient::UI::TOPLEVEL->add ($self->{other}); |
|
|
1757 | $self->{other}->move ( |
|
|
1758 | ($::WIDTH - $self->{other}{w}) * 0.5, |
|
|
1759 | ($::HEIGHT - $self->{other}{h}) * 0.5, |
|
|
1760 | ); |
|
|
1761 | } else { |
|
|
1762 | $CFClient::UI::TOPLEVEL->remove ($self->{other}); |
|
|
1763 | } |
|
|
1764 | } |
|
|
1765 | |
|
|
1766 | ############################################################################# |
|
|
1767 | |
1657 | package CFClient::UI::Toplevel; |
1768 | package CFClient::UI::Toplevel; |
1658 | |
1769 | |
1659 | our @ISA = CFClient::UI::Container::; |
1770 | our @ISA = CFClient::UI::Container::; |
1660 | |
1771 | |
1661 | sub size_request { |
1772 | sub size_request { |