… | |
… | |
61 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
61 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
62 | |
62 | |
63 | if ($widget != $HOVER) { |
63 | if ($widget != $HOVER) { |
64 | my $hover = $HOVER; $HOVER = $widget; |
64 | my $hover = $HOVER; $HOVER = $widget; |
65 | |
65 | |
66 | $hover->update if $hover; |
66 | $hover->update if $hover && $hover->{can_hover}; |
67 | $HOVER->update if $HOVER; |
67 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
68 | } |
68 | } |
69 | |
69 | |
70 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
70 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
71 | } |
71 | } |
72 | |
72 | |
… | |
… | |
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; |
… | |
… | |
438 | } |
439 | } |
439 | |
440 | |
440 | sub render_chld { |
441 | sub render_chld { |
441 | my ($self) = @_; |
442 | my ($self) = @_; |
442 | |
443 | |
443 | $self->{texture} = |
444 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
444 | CFClient::Texture->new_from_opengl ( |
445 | glClearColor 0, 0, 0, 1; |
445 | $self->{w}, $self->{h}, sub { $self->child->draw } |
446 | glClear GL_COLOR_BUFFER_BIT; |
446 | ); |
447 | $self->child->draw; |
|
|
448 | }; |
447 | } |
449 | } |
448 | |
450 | |
449 | sub size_allocate { |
451 | sub size_allocate { |
450 | my ($self, $x, $y, $w, $h) = @_; |
452 | my ($self, $x, $y, $w, $h) = @_; |
451 | |
453 | |
… | |
… | |
529 | |
531 | |
530 | my @tex = |
532 | my @tex = |
531 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
533 | 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); |
534 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
533 | |
535 | |
|
|
536 | sub new { |
|
|
537 | my $class = shift; |
|
|
538 | |
|
|
539 | # TODO: user_x, user_y, overwrite moveto? |
|
|
540 | |
|
|
541 | $class->SUPER::new ( |
|
|
542 | bg => [1, 1, 1, 1], |
|
|
543 | border_bg => [1, 1, 1, 1], |
|
|
544 | border => $::FONTSIZE * 0.8, |
|
|
545 | @_ |
|
|
546 | ) |
|
|
547 | } |
|
|
548 | |
534 | sub size_request { |
549 | sub size_request { |
535 | my ($self) = @_; |
550 | my ($self) = @_; |
536 | |
551 | |
537 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
552 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
538 | |
553 | |
539 | my ($w, $h) = $self->SUPER::size_request; |
554 | my ($w, $h) = $self->SUPER::size_request; |
540 | |
555 | |
541 | $h += $tex[1]->{h}; |
556 | ( |
542 | $h += $tex[4]->{h}; |
557 | $w + $self->{border} * 2, |
543 | $w += $tex[2]->{w}; |
558 | $h + $self->{border} * 2, |
544 | $w += $tex[3]->{w}; |
559 | ) |
545 | |
|
|
546 | ($w, $h) |
|
|
547 | } |
560 | } |
548 | |
561 | |
549 | sub size_allocate { |
562 | sub size_allocate { |
550 | my ($self, $x, $y, $w, $h) = @_; |
563 | my ($self, $x, $y, $w, $h) = @_; |
551 | |
564 | |
552 | $self->_size_allocate ($x, $y, $w, $h) or return; |
565 | $self->_size_allocate ($x, $y, $w, $h) or return; |
553 | |
566 | |
554 | $h -= $tex[1]{h}; |
567 | $h -= List::Util::max 0, $self->{border} * 2; |
555 | $h -= $tex[4]{h}; |
568 | $w -= List::Util::max 0, $self->{border} * 2; |
556 | $w -= $tex[2]{w}; |
|
|
557 | $w -= $tex[3]{w}; |
|
|
558 | |
569 | |
559 | $h = $h < 0 ? 0 : $h; |
570 | $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 | } |
571 | } |
566 | |
572 | |
567 | sub button_down { |
573 | sub button_down { |
568 | my ($self, $ev, $x, $y) = @_; |
574 | my ($self, $ev, $x, $y) = @_; |
569 | |
575 | |
570 | if ($x < $self->{w} && $x >= $self->{w} - $tex[2]{w} |
576 | if ($x < $self->{w} && $x >= $self->{w} - $self->{border} |
571 | && $y < $self->{h} && $y >= $self->{h} - $tex[4]{h}) { |
577 | && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { |
572 | |
578 | |
573 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
579 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
574 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
580 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
575 | |
581 | |
576 | $self->{motion} = sub { |
582 | $self->{motion} = sub { |
… | |
… | |
582 | $self->{user_h} = $bh + $y - $oy; |
588 | $self->{user_h} = $bh + $y - $oy; |
583 | $self->update; |
589 | $self->update; |
584 | }; |
590 | }; |
585 | |
591 | |
586 | } elsif ($x >= 0 && $x < $self->{w} |
592 | } elsif ($x >= 0 && $x < $self->{w} |
587 | && $y >= 0 && $y < $tex[1]{h}) { |
593 | && $y >= 0 && $y < $self->{border}) { |
588 | |
594 | |
589 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
595 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
590 | my ($bx, $by) = ($self->{x}, $self->{y}); |
596 | my ($bx, $by) = ($self->{x}, $self->{y}); |
591 | |
597 | |
592 | $self->{motion} = sub { |
598 | $self->{motion} = sub { |
… | |
… | |
613 | } |
619 | } |
614 | |
620 | |
615 | sub _draw { |
621 | sub _draw { |
616 | my ($self) = @_; |
622 | my ($self) = @_; |
617 | |
623 | |
618 | my ($w, $h) = ($self->{w}, $self->{h}); |
624 | my ($w, $h ) = ($self->{w}, $self->{h}); |
619 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
625 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
620 | |
626 | |
621 | glEnable GL_BLEND; |
627 | glEnable GL_BLEND; |
622 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
628 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
623 | glEnable GL_TEXTURE_2D; |
629 | glEnable GL_TEXTURE_2D; |
624 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
630 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
625 | |
631 | |
626 | my $top = $tex[1]; |
632 | glColor @{ $self->{border_bg} }; |
627 | $top->draw_quad (0, 0, $w, $top->{h}); |
633 | $tex[1]->draw_quad (0, 0, $w, $self->{border}); |
628 | |
634 | $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); |
629 | my $left = $tex[3]; |
635 | $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); |
630 | $left->draw_quad (0, $top->{h}, $left->{w}, $ch); |
636 | $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 | |
637 | |
638 | my $bg = $tex[0]; |
638 | my $bg = $tex[0]; |
639 | |
639 | |
640 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
640 | # TODO: repeat texture not scale |
641 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
642 | |
|
|
643 | my $rep_x = $cw / $bg->{w}; |
641 | my $rep_x = $cw / $bg->{w}; |
644 | my $rep_y = $ch / $bg->{h}; |
642 | my $rep_y = $ch / $bg->{h}; |
645 | |
643 | |
|
|
644 | glColor @{ $self->{bg} }; |
|
|
645 | |
|
|
646 | $bg->{s} = $rep_x; |
|
|
647 | $bg->{t} = $rep_y; |
|
|
648 | $bg->{wrap_mode} = 1; |
646 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
649 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
647 | |
650 | |
648 | glDisable GL_TEXTURE_2D; |
651 | glDisable GL_TEXTURE_2D; |
649 | glDisable GL_BLEND; |
652 | glDisable GL_BLEND; |
650 | |
653 | |
651 | $self->child->draw; |
654 | $self->child->draw; |
652 | |
|
|
653 | } |
655 | } |
654 | |
656 | |
655 | ############################################################################# |
657 | ############################################################################# |
656 | |
658 | |
657 | package CFClient::UI::Table; |
659 | package CFClient::UI::Table; |
… | |
… | |
730 | my $col_expand = (sum @col_expand) || 1; |
732 | my $col_expand = (sum @col_expand) || 1; |
731 | |
733 | |
732 | # linearly scale sizes |
734 | # linearly scale sizes |
733 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
735 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
734 | $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; |
736 | $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; |
|
|
737 | |
|
|
738 | $_ = int $_ for @$ws; #TODO: avoid rounding problems |
|
|
739 | $_ = int $_ for @$hs; #TODO: avoid rounding problems |
735 | |
740 | |
736 | my $y; |
741 | my $y; |
737 | |
742 | |
738 | for my $r (0 .. $#{$self->{children}}) { |
743 | for my $r (0 .. $#{$self->{children}}) { |
739 | my $row = $self->{children}[$r] |
744 | my $row = $self->{children}[$r] |
… | |
… | |
830 | } |
835 | } |
831 | |
836 | |
832 | my $y = 0; |
837 | my $y = 0; |
833 | for (0 .. $#$children) { |
838 | for (0 .. $#$children) { |
834 | my $child = $children->[$_]; |
839 | my $child = $children->[$_]; |
835 | my $h = $h[$_]; |
840 | my $h = int $h[$_]; |
836 | $child->size_allocate ($y, 0, $h, $w); |
841 | $child->size_allocate ($y, 0, $h, $w); |
837 | |
842 | |
838 | $y += $h; |
843 | $y += $h; |
839 | } |
844 | } |
840 | } |
845 | } |
… | |
… | |
884 | } |
889 | } |
885 | |
890 | |
886 | my $y = 0; |
891 | my $y = 0; |
887 | for (0 .. $#$children) { |
892 | for (0 .. $#$children) { |
888 | my $child = $children->[$_]; |
893 | my $child = $children->[$_]; |
889 | my $h = $h[$_]; |
894 | my $h = int $h[$_]; |
890 | $child->size_allocate (0, $y, $w, $h); |
895 | $child->size_allocate (0, $y, $w, $h); |
891 | |
896 | |
892 | $y += $h; |
897 | $y += $h; |
893 | } |
898 | } |
894 | } |
899 | } |
… | |
… | |
903 | |
908 | |
904 | sub new { |
909 | sub new { |
905 | my ($class, %arg) = @_; |
910 | my ($class, %arg) = @_; |
906 | |
911 | |
907 | my $self = $class->SUPER::new ( |
912 | my $self = $class->SUPER::new ( |
908 | fg => [1, 1, 1], |
913 | fg => [1, 1, 1], |
909 | height => $::FONTSIZE, |
914 | fontsize => $::FONTSIZE, |
910 | text => "", |
915 | text => "", |
911 | align => -1, |
916 | align => -1, |
912 | padding => 2, |
917 | padding => 2, |
913 | layout => new CFClient::Layout, |
918 | layout => new CFClient::Layout, |
914 | %arg |
919 | %arg |
915 | ); |
920 | ); |
916 | |
921 | |
917 | $self->set_text ($self->{text}); |
922 | $self->set_text ($self->{text}); |
918 | |
923 | |
… | |
… | |
948 | |
953 | |
949 | sub size_request { |
954 | sub size_request { |
950 | my ($self) = @_; |
955 | my ($self) = @_; |
951 | |
956 | |
952 | $self->{layout}->set_width; |
957 | $self->{layout}->set_width; |
953 | $self->{layout}->set_height ($self->{height}); |
958 | $self->{layout}->set_height ($self->{fontsize}); |
954 | my ($w, $h) = $self->{layout}->size; |
959 | my ($w, $h) = $self->{layout}->size; |
955 | |
960 | |
956 | ( |
961 | ( |
957 | $w + $self->{padding} * 2, |
962 | $w + $self->{padding} * 2, |
958 | $h + $self->{padding} * 2, |
963 | $h + $self->{padding} * 2, |
… | |
… | |
977 | sub _draw { |
982 | sub _draw { |
978 | my ($self) = @_; |
983 | my ($self) = @_; |
979 | |
984 | |
980 | my $tex = $self->{texture} ||= do { |
985 | my $tex = $self->{texture} ||= do { |
981 | $self->{layout}->set_width ($self->{w}); |
986 | $self->{layout}->set_width ($self->{w}); |
982 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
987 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
983 | new_from_layout CFClient::Texture $self->{layout} |
988 | new_from_layout CFClient::Texture $self->{layout} |
984 | }; |
989 | }; |
985 | |
990 | |
986 | glEnable GL_BLEND; |
991 | glEnable GL_BLEND; |
987 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
992 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
988 | glEnable GL_TEXTURE_2D; |
993 | glEnable GL_TEXTURE_2D; |
989 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
994 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
990 | |
995 | |
991 | glColor @{$self->{fg}}; |
996 | glColor @{$self->{fg}}; |
992 | |
997 | |
993 | my $x = |
998 | my $x = |
994 | $self->{align} < 0 ? $self->{padding} |
999 | $self->{align} < 0 ? $self->{padding} |
995 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1000 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
996 | : ($self->{w} - $tex->{w}) * 0.5; |
1001 | : ($self->{w} - $tex->{w}) * 0.5; |
997 | |
1002 | |
998 | glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0; |
1003 | $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); |
999 | $tex->draw_quad (0, 0); |
|
|
1000 | |
1004 | |
1001 | glDisable GL_TEXTURE_2D; |
1005 | glDisable GL_TEXTURE_2D; |
1002 | glDisable GL_BLEND; |
1006 | glDisable GL_BLEND; |
1003 | } |
1007 | } |
1004 | |
1008 | |
… | |
… | |
1017 | $class->SUPER::new ( |
1021 | $class->SUPER::new ( |
1018 | fg => [1, 1, 1], |
1022 | fg => [1, 1, 1], |
1019 | bg => [0, 0, 0, 0.2], |
1023 | bg => [0, 0, 0, 0.2], |
1020 | active_bg => [1, 1, 1, 0.5], |
1024 | active_bg => [1, 1, 1, 0.5], |
1021 | active_fg => [0, 0, 0], |
1025 | active_fg => [0, 0, 0], |
|
|
1026 | can_hover => 1, |
|
|
1027 | can_focus => 1, |
1022 | @_ |
1028 | @_ |
1023 | ) |
1029 | ) |
1024 | } |
1030 | } |
1025 | |
1031 | |
1026 | sub _set_text { |
1032 | sub _set_text { |
1027 | my ($self, $text) = @_; |
1033 | my ($self, $text) = @_; |
1028 | |
1034 | |
|
|
1035 | my $old_text = $self->{text}; |
|
|
1036 | |
1029 | $self->{last_activity} = $::NOW; |
1037 | $self->{last_activity} = $::NOW; |
1030 | |
1038 | |
1031 | $self->{text} = $text; |
1039 | $self->{text} = $text; |
1032 | $self->{layout}->set_width ($self->{w}); |
1040 | $self->{layout}->set_width ($self->{w}); |
1033 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
1041 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
1034 | |
1042 | |
1035 | $text =~ s/./*/g if $self->{hidden}; |
1043 | $text =~ s/./*/g if $self->{hidden}; |
1036 | |
1044 | |
1037 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1045 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1038 | |
1046 | |
1039 | $text = substr $text, 0, $self->{cursor}; |
1047 | $text = substr $text, 0, $self->{cursor}; |
1040 | utf8::encode $text; |
1048 | utf8::encode $text; |
1041 | |
1049 | |
1042 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
1050 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
|
|
1051 | |
|
|
1052 | $self->emit (changed => $self->{text}) # XXX: is this the right place to do this? |
|
|
1053 | if $old_text ne $self->{text}; |
1043 | } |
1054 | } |
1044 | |
1055 | |
1045 | sub size_request { |
1056 | sub size_request { |
1046 | my ($self) = @_; |
1057 | my ($self) = @_; |
1047 | |
1058 | |
… | |
… | |
1086 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1097 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1087 | } elsif ($sym == SDLK_HOME) { |
1098 | } elsif ($sym == SDLK_HOME) { |
1088 | $self->{cursor} = 0; |
1099 | $self->{cursor} = 0; |
1089 | } elsif ($sym == SDLK_END) { |
1100 | } elsif ($sym == SDLK_END) { |
1090 | $self->{cursor} = length $text; |
1101 | $self->{cursor} = length $text; |
|
|
1102 | } elsif ($sym == SDLK_ESCAPE) { |
|
|
1103 | $self->emit ('escape'); |
1091 | } elsif ($uni) { |
1104 | } elsif ($uni) { |
1092 | substr $text, $self->{cursor}++, 0, chr $uni; |
1105 | substr $text, $self->{cursor}++, 0, chr $uni; |
1093 | } |
1106 | } |
1094 | |
1107 | |
1095 | $self->_set_text ($text); |
1108 | $self->_set_text ($text); |
… | |
… | |
1157 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1170 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1158 | glEnd; |
1171 | glEnd; |
1159 | } |
1172 | } |
1160 | } |
1173 | } |
1161 | |
1174 | |
|
|
1175 | package CFClient::UI::LineEntry; |
|
|
1176 | |
|
|
1177 | our @ISA = CFClient::UI::Entry::; |
|
|
1178 | |
|
|
1179 | use SDL; |
|
|
1180 | use SDL::OpenGL; |
|
|
1181 | |
|
|
1182 | sub key_down { |
|
|
1183 | my ($self, $ev) = @_; |
|
|
1184 | |
|
|
1185 | my $sym = $ev->key_sym; |
|
|
1186 | |
|
|
1187 | if ($sym == SDLK_RETURN) { |
|
|
1188 | $self->emit (activate => $self->get_text); |
|
|
1189 | $self->update; |
|
|
1190 | |
|
|
1191 | } else { |
|
|
1192 | $self->SUPER::key_down ($ev); |
|
|
1193 | } |
|
|
1194 | |
|
|
1195 | } |
|
|
1196 | |
1162 | ############################################################################# |
1197 | ############################################################################# |
1163 | |
1198 | |
1164 | package CFClient::UI::Button; |
1199 | package CFClient::UI::Button; |
1165 | |
1200 | |
1166 | our @ISA = CFClient::UI::Label::; |
1201 | our @ISA = CFClient::UI::Label::; |
… | |
… | |
1178 | $class->SUPER::new ( |
1213 | $class->SUPER::new ( |
1179 | padding => 4, |
1214 | padding => 4, |
1180 | fg => [1, 1, 1], |
1215 | fg => [1, 1, 1], |
1181 | bg => [1, 1, 1, 0.2], |
1216 | bg => [1, 1, 1, 0.2], |
1182 | active_fg => [1, 1, 0], |
1217 | active_fg => [1, 1, 0], |
1183 | # active_bg => [0, 0, 0, 0.5], |
1218 | can_hover => 1, |
1184 | # border_fg => [1, 1, 0], |
|
|
1185 | @_ |
1219 | @_ |
1186 | ) |
1220 | ) |
1187 | } |
1221 | } |
1188 | |
1222 | |
1189 | sub button_up { |
1223 | sub button_up { |
… | |
… | |
1223 | ############################################################################# |
1257 | ############################################################################# |
1224 | |
1258 | |
1225 | package CFClient::UI::CheckBox; |
1259 | package CFClient::UI::CheckBox; |
1226 | |
1260 | |
1227 | our @ISA = CFClient::UI::DrawBG::; |
1261 | our @ISA = CFClient::UI::DrawBG::; |
|
|
1262 | |
|
|
1263 | my @tex = |
|
|
1264 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1265 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1228 | |
1266 | |
1229 | use SDL; |
1267 | use SDL; |
1230 | use SDL::OpenGL; |
1268 | use SDL::OpenGL; |
1231 | |
1269 | |
1232 | sub new { |
1270 | sub new { |
… | |
… | |
1235 | $class->SUPER::new ( |
1273 | $class->SUPER::new ( |
1236 | padding => 2, |
1274 | padding => 2, |
1237 | fg => [1, 1, 1], |
1275 | fg => [1, 1, 1], |
1238 | active_fg => [1, 1, 0], |
1276 | active_fg => [1, 1, 0], |
1239 | state => 0, |
1277 | state => 0, |
|
|
1278 | can_hover => 1, |
1240 | @_ |
1279 | @_ |
1241 | ) |
1280 | ) |
1242 | } |
1281 | } |
1243 | |
1282 | |
1244 | sub size_request { |
1283 | sub size_request { |
… | |
… | |
1269 | $self->SUPER::_draw; |
1308 | $self->SUPER::_draw; |
1270 | |
1309 | |
1271 | glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; |
1310 | glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; |
1272 | |
1311 | |
1273 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1312 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1274 | |
1313 | |
1275 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1314 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1276 | |
1315 | |
1277 | glBegin GL_LINE_LOOP; |
1316 | glEnable GL_BLEND; |
1278 | glVertex 0 , 0; |
1317 | glEnable GL_TEXTURE_2D; |
1279 | glVertex 0 , $s; |
1318 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1280 | glVertex $s, $s; |
|
|
1281 | glVertex $s, 0; |
|
|
1282 | glEnd; |
|
|
1283 | |
1319 | |
1284 | if ($self->{state}) { |
1320 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
1285 | glBegin GL_LINES; |
1321 | |
1286 | glVertex 0 , 0; |
1322 | $tex->draw_quad (0, 0, $s, $s); |
1287 | glVertex $s, $s; |
1323 | |
1288 | glVertex $s, 0; |
1324 | glDisable GL_TEXTURE_2D; |
1289 | glVertex 0 , $s; |
1325 | glDisable GL_BLEND; |
1290 | glEnd; |
|
|
1291 | } |
|
|
1292 | } |
1326 | } |
1293 | |
1327 | |
1294 | ############################################################################# |
1328 | ############################################################################# |
1295 | |
1329 | |
1296 | package CFClient::UI::Slider; |
1330 | package CFClient::UI::Slider; |
… | |
… | |
1298 | use strict; |
1332 | use strict; |
1299 | |
1333 | |
1300 | use SDL::OpenGL; |
1334 | use SDL::OpenGL; |
1301 | |
1335 | |
1302 | our @ISA = CFClient::UI::DrawBG::; |
1336 | our @ISA = CFClient::UI::DrawBG::; |
|
|
1337 | |
|
|
1338 | my @tex = |
|
|
1339 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1340 | qw(s1_slider.png s1_slider_bg.png); |
1303 | |
1341 | |
1304 | sub new { |
1342 | sub new { |
1305 | my $class = shift; |
1343 | my $class = shift; |
1306 | |
1344 | |
1307 | # range [value, low, high, page] |
1345 | # range [value, low, high, page] |
1308 | |
1346 | |
|
|
1347 | # TODO: 0-width page |
|
|
1348 | # TODO: req_w/h are wrong with vertical |
|
|
1349 | # TODO: calculations are off |
1309 | my $self = $class->SUPER::new ( |
1350 | my $self = $class->SUPER::new ( |
1310 | fg => [1, 1, 1], |
1351 | fg => [1, 1, 1], |
1311 | active_fg => [0, 0, 0], |
1352 | active_fg => [0, 0, 0], |
1312 | range => [0, 0, 100, 10], |
1353 | range => [0, 0, 100, 10], |
1313 | req_w => 40, |
1354 | req_w => 40, |
1314 | req_h => 10, |
1355 | req_h => 13, |
1315 | vertical => 0, |
1356 | vertical => 0, |
|
|
1357 | can_hover => 1, |
|
|
1358 | inner_pad => 5, |
1316 | @_ |
1359 | @_ |
1317 | ); |
1360 | ); |
1318 | |
1361 | |
1319 | $self |
1362 | $self |
1320 | } |
1363 | } |
… | |
… | |
1341 | if ($GRAB == $self) { |
1384 | if ($GRAB == $self) { |
1342 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1385 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1343 | |
1386 | |
1344 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
1387 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
1345 | |
1388 | |
|
|
1389 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
|
|
1390 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
|
|
1391 | |
|
|
1392 | $x -= $inner_pad_px; # substract the padding |
1346 | $x = $x * ($hi - $lo) / $w + $lo; |
1393 | $x = $x * ($hi - $lo) / $inner_w + $lo; |
1347 | $x = $lo if $x < $lo; |
1394 | $x = $lo if $x < $lo; |
1348 | $x = $hi - $page if $x > $hi - $page; |
1395 | $x = $hi - $page if $x > $hi - $page; |
1349 | $self->{range}[0] = $x; |
1396 | $self->{range}[0] = $x; |
1350 | |
1397 | |
1351 | $self->emit (changed => $x); |
1398 | $self->emit (changed => $x); |
1352 | $self->update; |
1399 | $self->update; |
1353 | } |
1400 | } |
|
|
1401 | } |
|
|
1402 | |
|
|
1403 | # the inner_* stuff is for generating a padding for the slider handle, |
|
|
1404 | # so that the handle doesn't leave the texture. This calculation isn't 100% |
|
|
1405 | # correct propably, but it does the job for now |
|
|
1406 | sub _calc_inner_pad_px { |
|
|
1407 | my ($self, $w) = @_; |
|
|
1408 | ($w / 100) * $self->{inner_pad} # % to pixels |
1354 | } |
1409 | } |
1355 | |
1410 | |
1356 | sub _draw { |
1411 | sub _draw { |
1357 | my ($self) = @_; |
1412 | my ($self) = @_; |
1358 | |
1413 | |
… | |
… | |
1372 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
1427 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
1373 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
1428 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
1374 | |
1429 | |
1375 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1430 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1376 | |
1431 | |
|
|
1432 | $hi = $value + 1 if $lo == $hi; |
|
|
1433 | |
|
|
1434 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
|
|
1435 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
|
|
1436 | |
1377 | $page = int $page * $w / ($hi - $lo); |
1437 | $page = int $page * $inner_w / ($hi - $lo); |
1378 | $value = int +($value - $lo) * $w / ($hi - $lo); |
1438 | $value = int +($value - $lo) * $inner_w / ($hi - $lo); |
1379 | |
1439 | |
1380 | $w -= $page; |
1440 | $w -= $page; |
1381 | $page &= ~1; |
1441 | $page &= ~1; |
1382 | glTranslate $page * 0.5, 0, 0; |
1442 | glTranslate $page * 0.5, 0, 0; |
1383 | $page ||= 2; |
1443 | $page ||= 2; |
1384 | |
1444 | |
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; |
1445 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
1393 | my $knob_b = $value + $page * 0.5; |
1446 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
1394 | |
1447 | |
1395 | glBegin GL_QUADS; |
1448 | glEnable GL_BLEND; |
1396 | glColor @$fg; |
1449 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1397 | glVertex $knob_a, 0; |
1450 | glEnable GL_TEXTURE_2D; |
1398 | glVertex $knob_a, $h; |
1451 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1399 | glVertex $knob_b, $h; |
|
|
1400 | glVertex $knob_b, 0; |
|
|
1401 | |
1452 | |
1402 | if ($knob_a < $knob_b - 2) { |
1453 | # draw background |
1403 | glColor @$bg; |
1454 | $tex[1]->draw_quad (0, 0, $w, $h); |
1404 | glVertex $knob_a + 1, 1; |
1455 | |
1405 | glVertex $knob_a + 1, $h - 1; |
1456 | # draw handle |
1406 | glVertex $knob_b - 1, $h - 1; |
1457 | $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); |
1407 | glVertex $knob_b - 1, 1; |
1458 | |
|
|
1459 | glDisable GL_BLEND; |
|
|
1460 | glDisable GL_TEXTURE_2D; |
|
|
1461 | } |
|
|
1462 | |
|
|
1463 | ############################################################################# |
|
|
1464 | |
|
|
1465 | package CFClient::UI::TextView; |
|
|
1466 | |
|
|
1467 | our @ISA = CFClient::UI::HBox::; |
|
|
1468 | |
|
|
1469 | use SDL::OpenGL; |
|
|
1470 | |
|
|
1471 | sub new { |
|
|
1472 | my $class = shift; |
|
|
1473 | |
|
|
1474 | my $self = $class->SUPER::new ( |
|
|
1475 | req_w => $::WIDTH / 6, |
|
|
1476 | req_h => $::HEIGHT / 6, |
|
|
1477 | fontsize => $::FONTSIZE, |
|
|
1478 | @_, |
|
|
1479 | |
|
|
1480 | layout => (new CFClient::Layout), |
|
|
1481 | par => [], |
|
|
1482 | height => 0, |
|
|
1483 | children => [ |
|
|
1484 | (new CFClient::UI::Empty expand => 1), |
|
|
1485 | (new CFClient::UI::Slider vertical => 1), |
|
|
1486 | ], |
|
|
1487 | ); |
|
|
1488 | |
|
|
1489 | $self->{children}[1]->connect (changed => sub { |
|
|
1490 | $self->update; |
|
|
1491 | }); |
|
|
1492 | |
|
|
1493 | $self |
|
|
1494 | } |
|
|
1495 | |
|
|
1496 | sub set_fontsize { |
|
|
1497 | my ($self, $fontsize) = @_; |
|
|
1498 | |
|
|
1499 | $self->{fontsize} = $fontsize; |
|
|
1500 | $self->reflow; |
|
|
1501 | } |
|
|
1502 | |
|
|
1503 | sub text_height { |
|
|
1504 | my ($self, $text) = @_; |
|
|
1505 | |
|
|
1506 | my $layout = $self->{layout}; |
|
|
1507 | |
|
|
1508 | $layout->set_height ($self->{fontsize}); |
|
|
1509 | $layout->set_width ($self->{w}); |
|
|
1510 | $layout->set_text ($text); |
1408 | } |
1511 | |
1409 | glEnd; |
1512 | ($layout->size)[1] |
|
|
1513 | } |
|
|
1514 | |
|
|
1515 | sub reflow { |
|
|
1516 | my ($self) = @_; |
|
|
1517 | |
|
|
1518 | $self->{need_reflow}++; |
|
|
1519 | $self->update; |
|
|
1520 | } |
|
|
1521 | |
|
|
1522 | sub size_request { |
|
|
1523 | my ($self) = @_; |
|
|
1524 | |
|
|
1525 | ($self->{req_w}, $self->{req_h}) |
|
|
1526 | } |
|
|
1527 | |
|
|
1528 | sub size_allocate { |
|
|
1529 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1530 | |
|
|
1531 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
|
|
1532 | |
|
|
1533 | $self->{layout}->set_height ($self->{fontsize}); |
|
|
1534 | $self->{layout}->set_width ($self->{w}); |
|
|
1535 | |
|
|
1536 | $self->reflow; |
|
|
1537 | } |
|
|
1538 | |
|
|
1539 | sub add_paragraph { |
|
|
1540 | my ($self, $color, $text) = @_; |
|
|
1541 | |
|
|
1542 | #TODO: intelligently "reformat" paragraph |
|
|
1543 | |
|
|
1544 | my $height = $self->text_height ($text); |
|
|
1545 | |
|
|
1546 | $self->{height} += $height; |
|
|
1547 | |
|
|
1548 | push @{$self->{par}}, [$height, $color, $text]; |
|
|
1549 | |
|
|
1550 | $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; |
|
|
1551 | $self->{children}[1]->update; |
|
|
1552 | } |
|
|
1553 | |
|
|
1554 | sub update { |
|
|
1555 | my ($self) = @_; |
|
|
1556 | |
|
|
1557 | $self->SUPER::update; |
|
|
1558 | |
|
|
1559 | return unless $self->{h} > 0; |
|
|
1560 | |
|
|
1561 | delete $self->{texture}; |
|
|
1562 | |
|
|
1563 | $TOPLEVEL->on_refresh ($self, sub { |
|
|
1564 | if (delete $self->{need_reflow}) { |
|
|
1565 | my $height = 0; |
|
|
1566 | |
|
|
1567 | $height += $_->[0] = $self->text_height ($_->[2]) |
|
|
1568 | for @{$self->{par}}; |
|
|
1569 | |
|
|
1570 | $self->{height} = $height; |
|
|
1571 | |
|
|
1572 | $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
|
|
1573 | |
|
|
1574 | delete $self->{texture}; |
|
|
1575 | } |
|
|
1576 | |
|
|
1577 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
|
|
1578 | glClearColor 0, 0, 0, 1; |
|
|
1579 | glClear GL_COLOR_BUFFER_BIT; |
|
|
1580 | |
|
|
1581 | glEnable GL_BLEND; |
|
|
1582 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1583 | glEnable GL_TEXTURE_2D; |
|
|
1584 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1585 | |
|
|
1586 | my $top = int $self->{children}[1]{range}[0]; |
|
|
1587 | |
|
|
1588 | my $y0 = $top; |
|
|
1589 | my $y1 = $top + $self->{h}; |
|
|
1590 | |
|
|
1591 | my $y = 0; |
|
|
1592 | |
|
|
1593 | my $layout = $self->{layout}; |
|
|
1594 | |
|
|
1595 | for my $par (@{$self->{par}}) { |
|
|
1596 | my $h = $par->[0]; |
|
|
1597 | |
|
|
1598 | if ($y0 < $y + $h && $y < $y1) { |
|
|
1599 | $layout->set_text ($par->[2]); |
|
|
1600 | |
|
|
1601 | glColor @{ $par->[1] }; |
|
|
1602 | my ($W, $H) = $layout->size; |
|
|
1603 | CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); |
|
|
1604 | } |
|
|
1605 | |
|
|
1606 | $y += $h; |
|
|
1607 | } |
|
|
1608 | |
|
|
1609 | glDisable GL_TEXTURE_2D; |
|
|
1610 | glDisable GL_BLEND; |
|
|
1611 | }; |
|
|
1612 | }); |
|
|
1613 | } |
|
|
1614 | |
|
|
1615 | sub _draw { |
|
|
1616 | my ($self) = @_; |
|
|
1617 | |
|
|
1618 | if ($self->{texture}) { |
|
|
1619 | glEnable GL_TEXTURE_2D; |
|
|
1620 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1621 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
|
|
1622 | glDisable GL_TEXTURE_2D; |
|
|
1623 | } |
|
|
1624 | |
|
|
1625 | $self->{children}[1]->draw; |
|
|
1626 | |
1410 | } |
1627 | } |
1411 | |
1628 | |
1412 | ############################################################################# |
1629 | ############################################################################# |
1413 | |
1630 | |
1414 | package CFClient::UI::MapWidget; |
1631 | package CFClient::UI::MapWidget; |
… | |
… | |
1424 | |
1641 | |
1425 | sub new { |
1642 | sub new { |
1426 | my $class = shift; |
1643 | my $class = shift; |
1427 | |
1644 | |
1428 | $class->SUPER::new ( |
1645 | $class->SUPER::new ( |
1429 | z => -1, |
1646 | z => -1, |
|
|
1647 | can_focus => 1, |
1430 | list => (glGenLists 1), |
1648 | list => (glGenLists 1), |
1431 | @_ |
1649 | @_ |
1432 | ) |
1650 | ) |
1433 | } |
1651 | } |
1434 | |
1652 | |
1435 | sub key_down { |
1653 | sub key_down { |
1436 | print "MAPKEYDOWN\n"; |
1654 | print "MAPKEYDOWN\n"; |
1437 | } |
1655 | } |
1438 | |
1656 | |
1439 | sub key_up { |
1657 | sub key_up { |
|
|
1658 | } |
|
|
1659 | |
|
|
1660 | sub button_down { |
|
|
1661 | my ($self, $ev, $x, $y) = @_; |
|
|
1662 | |
|
|
1663 | $self->focus_in; |
|
|
1664 | |
|
|
1665 | if ($ev->button == 2) { |
|
|
1666 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
1667 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
|
|
1668 | |
|
|
1669 | $self->{motion} = sub { |
|
|
1670 | my ($ev, $x, $y) = @_; |
|
|
1671 | |
|
|
1672 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
1673 | |
|
|
1674 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
|
|
1675 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
|
|
1676 | |
|
|
1677 | $self->update; |
|
|
1678 | }; |
|
|
1679 | } |
|
|
1680 | } |
|
|
1681 | |
|
|
1682 | sub button_up { |
|
|
1683 | my ($self, $ev, $x, $y) = @_; |
|
|
1684 | |
|
|
1685 | delete $self->{motion}; |
|
|
1686 | } |
|
|
1687 | |
|
|
1688 | sub mouse_motion { |
|
|
1689 | my ($self, $ev, $x, $y) = @_; |
|
|
1690 | |
|
|
1691 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
1440 | } |
1692 | } |
1441 | |
1693 | |
1442 | sub size_request { |
1694 | sub size_request { |
1443 | ( |
1695 | ( |
1444 | 1 + 32 * int $::WIDTH / 32, |
1696 | 1 + 32 * int $::WIDTH / 32, |
… | |
… | |
1454 | } |
1706 | } |
1455 | |
1707 | |
1456 | sub draw { |
1708 | sub draw { |
1457 | my ($self) = @_; |
1709 | my ($self) = @_; |
1458 | |
1710 | |
1459 | $self->{need_update}++;#d# |
|
|
1460 | if (delete $self->{need_update}) { |
1711 | if (delete $self->{need_update}) { |
1461 | glNewList $self->{list}, GL_COMPILE; |
1712 | glNewList $self->{list}, GL_COMPILE; |
1462 | |
1713 | |
1463 | my $sw = int $::WIDTH / 32; |
|
|
1464 | my $sh = int $::HEIGHT / 32; |
|
|
1465 | |
|
|
1466 | if ($::MAP) { |
1714 | if ($::MAP) { |
|
|
1715 | my $sw = int $::WIDTH / 32; |
|
|
1716 | my $sh = int $::HEIGHT / 32; |
|
|
1717 | |
|
|
1718 | my $sx = $::CFG->{map_shift_x}; |
|
|
1719 | my $sy = $::CFG->{map_shift_y}; |
|
|
1720 | |
|
|
1721 | glTranslate +($sx & 31) - 32, ($sy & 31) - 32, 0; |
|
|
1722 | |
1467 | my ($w, $h, $data) = $::MAP->draw (0, 0, $sw, $sh); |
1723 | my ($w, $h, $data) = $::MAP->draw ($sx >> 5, $sy >> 5, 0, 0, $sw + 1, $sh + 1); |
1468 | |
1724 | |
1469 | if ($::CFG->{fow_enable}) { |
1725 | if ($::CFG->{fow_enable}) { |
1470 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
1726 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
1471 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
1727 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
1472 | glConvolutionFilter2D |
1728 | glConvolutionFilter2D |
… | |
… | |
1490 | format => GL_ALPHA; |
1746 | format => GL_ALPHA; |
1491 | |
1747 | |
1492 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1748 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1493 | |
1749 | |
1494 | glEnable GL_BLEND; |
1750 | glEnable GL_BLEND; |
|
|
1751 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1495 | glEnable GL_TEXTURE_2D; |
1752 | glEnable GL_TEXTURE_2D; |
1496 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1753 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1497 | |
1754 | |
1498 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1755 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1499 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
1756 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
1500 | |
1757 | |
1501 | glDisable GL_TEXTURE_2D; |
1758 | glDisable GL_TEXTURE_2D; |
1502 | glDisable GL_BLEND; |
1759 | glDisable GL_BLEND; |
1503 | } |
1760 | } |
|
|
1761 | |
|
|
1762 | # HACK BEGIN |
|
|
1763 | { |
|
|
1764 | glTranslate -(($sx & 31) - 32), -(($sy & 31) - 32), 0;#remove |
|
|
1765 | my ($w, $h) = (250, 250); |
|
|
1766 | |
|
|
1767 | glEnable GL_BLEND; |
|
|
1768 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1769 | glEnable GL_TEXTURE_2D; |
|
|
1770 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1771 | |
|
|
1772 | CFClient::Texture->new ( |
|
|
1773 | w => $w, |
|
|
1774 | h => $h, |
|
|
1775 | data => $::MAP->mapmap ($w, $h), |
|
|
1776 | type => GL_UNSIGNED_INT_8_8_8_8_REV |
|
|
1777 | )->draw_quad (100, 100); |
|
|
1778 | |
|
|
1779 | glDisable GL_TEXTURE_2D; |
|
|
1780 | glDisable GL_BLEND; |
|
|
1781 | } |
|
|
1782 | # HACK END |
1504 | } |
1783 | } |
1505 | |
1784 | |
1506 | glEndList; |
1785 | glEndList; |
1507 | } |
1786 | } |
1508 | |
1787 | |
|
|
1788 | glPushMatrix; |
1509 | glCallList $self->{list}; |
1789 | glCallList $self->{list}; |
|
|
1790 | glPopMatrix; |
1510 | |
1791 | |
1511 | if ($FOCUS != $self) { |
1792 | if ($FOCUS != $self) { |
1512 | glEnable GL_BLEND; |
1793 | glColor 64/255, 64/255, 64/255; |
1513 | glColor 0, 0, 1, 0.4; |
1794 | glLogicOp GL_AND; |
|
|
1795 | glEnable GL_COLOR_LOGIC_OP; |
1514 | glBegin GL_QUADS; |
1796 | glBegin GL_QUADS; |
1515 | glVertex 0, 0; |
1797 | glVertex 0, 0; |
1516 | glVertex 0, $::HEIGHT; |
1798 | glVertex 0, $::HEIGHT; |
1517 | glVertex $::WIDTH, $::HEIGHT; |
1799 | glVertex $::WIDTH, $::HEIGHT; |
1518 | glVertex $::WIDTH, 0; |
1800 | glVertex $::WIDTH, 0; |
1519 | glEnd; |
1801 | glEnd; |
1520 | glDisable GL_BLEND; |
1802 | glDisable GL_COLOR_LOGIC_OP; |
1521 | } |
1803 | } |
1522 | } |
1804 | } |
1523 | |
1805 | |
1524 | my %DIR = ( |
1806 | my %DIR = ( |
1525 | SDLK_KP8, [1, "north"], |
1807 | SDLK_KP8, [1, "north"], |
… | |
… | |
1545 | |
1827 | |
1546 | if ($sym == SDLK_KP5) { |
1828 | if ($sym == SDLK_KP5) { |
1547 | $::CONN->user_send ("command stay fire"); |
1829 | $::CONN->user_send ("command stay fire"); |
1548 | } elsif ($sym == SDLK_a) { |
1830 | } elsif ($sym == SDLK_a) { |
1549 | $::CONN->user_send ("command apply"); |
1831 | $::CONN->user_send ("command apply"); |
|
|
1832 | } elsif ($sym == SDLK_QUOTE) { |
|
|
1833 | $self->emit ('activate_console'); |
|
|
1834 | } elsif ($sym == SDLK_SLASH) { |
|
|
1835 | $self->emit ('activate_console' => '/'); |
1550 | } elsif (exists $DIR{$sym}) { |
1836 | } elsif (exists $DIR{$sym}) { |
1551 | if ($mod & KMOD_SHIFT) { |
1837 | if ($mod & KMOD_SHIFT) { |
1552 | $self->{shft}++; |
1838 | $self->{shft}++; |
1553 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1839 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1554 | } elsif ($mod & KMOD_CTRL) { |
1840 | } elsif ($mod & KMOD_CTRL) { |
… | |
… | |
1616 | glPopMatrix; |
1902 | glPopMatrix; |
1617 | } |
1903 | } |
1618 | |
1904 | |
1619 | ############################################################################# |
1905 | ############################################################################# |
1620 | |
1906 | |
|
|
1907 | package CFClient::UI::Flopper; |
|
|
1908 | |
|
|
1909 | our @ISA = CFClient::UI::Button::; |
|
|
1910 | |
|
|
1911 | sub new { |
|
|
1912 | my $class = shift; |
|
|
1913 | |
|
|
1914 | my $self = $class->SUPER::new ( |
|
|
1915 | state => 0, |
|
|
1916 | connect_activate => \&toggle_flopper, |
|
|
1917 | @_ |
|
|
1918 | ); |
|
|
1919 | |
|
|
1920 | if ($self->{state}) { |
|
|
1921 | $self->{state} = 0; |
|
|
1922 | $self->toggle_flopper; |
|
|
1923 | } |
|
|
1924 | |
|
|
1925 | $self |
|
|
1926 | } |
|
|
1927 | |
|
|
1928 | sub toggle_flopper { |
|
|
1929 | my ($self) = @_; |
|
|
1930 | |
|
|
1931 | # TODO: use animation |
|
|
1932 | if ($self->{state} = !$self->{state}) { |
|
|
1933 | $CFClient::UI::TOPLEVEL->add ($self->{other}); |
|
|
1934 | $self->{other}->move ( |
|
|
1935 | ($::WIDTH - $self->{other}{w}) * 0.5, |
|
|
1936 | ($::HEIGHT - $self->{other}{h}) * 0.5, |
|
|
1937 | ); |
|
|
1938 | } else { |
|
|
1939 | $CFClient::UI::TOPLEVEL->remove ($self->{other}); |
|
|
1940 | } |
|
|
1941 | } |
|
|
1942 | |
|
|
1943 | ############################################################################# |
|
|
1944 | |
1621 | package CFClient::UI::Toplevel; |
1945 | package CFClient::UI::Toplevel; |
1622 | |
1946 | |
1623 | our @ISA = CFClient::UI::Container::; |
1947 | our @ISA = CFClient::UI::Container::; |
|
|
1948 | |
|
|
1949 | use SDL::OpenGL; |
1624 | |
1950 | |
1625 | sub size_request { |
1951 | sub size_request { |
1626 | ($::WIDTH, $::HEIGHT) |
1952 | ($::WIDTH, $::HEIGHT) |
1627 | } |
1953 | } |
1628 | |
1954 | |
… | |
… | |
1654 | $self->SUPER::add ($widget); |
1980 | $self->SUPER::add ($widget); |
1655 | |
1981 | |
1656 | $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); |
1982 | $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); |
1657 | } |
1983 | } |
1658 | |
1984 | |
|
|
1985 | sub on_refresh { |
|
|
1986 | my ($self, $id, $cb) = @_; |
|
|
1987 | |
|
|
1988 | $self->{refresh_hook}{$id} = $cb; |
|
|
1989 | } |
|
|
1990 | |
1659 | sub draw { |
1991 | sub draw { |
1660 | my ($self) = @_; |
1992 | my ($self) = @_; |
1661 | |
1993 | |
|
|
1994 | while (my $rcb = delete $self->{refresh_hook}) { |
|
|
1995 | $_->() for values %$rcb; |
|
|
1996 | } |
|
|
1997 | |
|
|
1998 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
|
|
1999 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
2000 | glClear GL_COLOR_BUFFER_BIT; |
|
|
2001 | |
|
|
2002 | glMatrixMode GL_PROJECTION; |
|
|
2003 | glLoadIdentity; |
|
|
2004 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; |
|
|
2005 | glMatrixMode GL_MODELVIEW; |
|
|
2006 | glLoadIdentity; |
|
|
2007 | |
1662 | $self->_draw; |
2008 | $self->_draw; |
1663 | } |
2009 | } |
1664 | |
2010 | |
1665 | ############################################################################# |
2011 | ############################################################################# |
1666 | |
2012 | |