… | |
… | |
34 | $GRAB->update if $GRAB; |
34 | $GRAB->update if $GRAB; |
35 | } |
35 | } |
36 | |
36 | |
37 | $BUTTON_STATE |= 1 << ($ev->button - 1); |
37 | $BUTTON_STATE |= 1 << ($ev->button - 1); |
38 | |
38 | |
39 | $GRAB->button_down ($ev) if $GRAB; |
39 | $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; |
40 | } |
40 | } |
41 | |
41 | |
42 | sub feed_sdl_button_up_event { |
42 | sub feed_sdl_button_up_event { |
43 | my ($ev) = @_; |
43 | my ($ev) = @_; |
44 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
44 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
45 | |
45 | |
46 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
46 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
47 | |
47 | |
48 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
48 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
|
|
49 | |
|
|
50 | $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; |
49 | |
51 | |
50 | if (!$BUTTON_STATE) { |
52 | if (!$BUTTON_STATE) { |
51 | my $grab = $GRAB; undef $GRAB; |
53 | my $grab = $GRAB; undef $GRAB; |
52 | $grab->update if $grab; |
54 | $grab->update if $grab; |
53 | $GRAB->update if $GRAB; |
55 | $GRAB->update if $GRAB; |
… | |
… | |
65 | |
67 | |
66 | $hover->update if $hover; |
68 | $hover->update if $hover; |
67 | $HOVER->update if $HOVER; |
69 | $HOVER->update if $HOVER; |
68 | } |
70 | } |
69 | |
71 | |
70 | $HOVER->mouse_motion ($ev) if $HOVER; |
72 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
71 | } |
73 | } |
72 | |
74 | |
73 | sub new { |
75 | sub new { |
74 | my $class = shift; |
76 | my $class = shift; |
75 | |
77 | |
… | |
… | |
95 | sub size_allocate { |
97 | sub size_allocate { |
96 | my ($self, $w, $h) = @_; |
98 | my ($self, $w, $h) = @_; |
97 | |
99 | |
98 | $self->{w} = $w; |
100 | $self->{w} = $w; |
99 | $self->{h} = $h; |
101 | $self->{h} = $h; |
|
|
102 | } |
|
|
103 | |
|
|
104 | # translate global koordinates to local coordinate system |
|
|
105 | sub translate { |
|
|
106 | my ($self, $x, $y) = @_; |
|
|
107 | |
|
|
108 | $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); |
100 | } |
109 | } |
101 | |
110 | |
102 | sub focus_in { |
111 | sub focus_in { |
103 | my ($self) = @_; |
112 | my ($self) = @_; |
104 | |
113 | |
… | |
… | |
629 | my ($class, $x, $y, $z, $height, $text) = @_; |
638 | my ($class, $x, $y, $z, $height, $text) = @_; |
630 | |
639 | |
631 | $height ||= $::FONTSIZE; |
640 | $height ||= $::FONTSIZE; |
632 | |
641 | |
633 | # TODO: color, and make height, xyz etc. optional |
642 | # TODO: color, and make height, xyz etc. optional |
634 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
643 | my $self = $class->SUPER::new ( |
|
|
644 | x => $x, |
|
|
645 | y => $y, |
|
|
646 | z => $z, |
|
|
647 | height => $height, |
|
|
648 | layout => new Crossfire::Client::Layout, |
|
|
649 | ); |
635 | |
650 | |
636 | $self->set_text ($text); |
651 | $self->set_text ($text); |
637 | |
652 | |
638 | $self |
653 | $self |
639 | } |
654 | } |
640 | |
655 | |
641 | sub set_text { |
656 | sub set_text { |
642 | my ($self, $text) = @_; |
657 | my ($self, $text) = @_; |
643 | |
658 | |
644 | $self->{text} = $text; |
659 | $self->{text} = $text; |
645 | $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; |
660 | $self->{layout}->set_markup ($text); |
646 | |
661 | |
647 | $self->update; |
662 | delete $self->{texture}; |
648 | } |
663 | } |
649 | |
664 | |
650 | sub get_text { |
665 | sub get_text { |
651 | my ($self, $text) = @_; |
666 | my ($self, $text) = @_; |
652 | |
667 | |
… | |
… | |
654 | } |
669 | } |
655 | |
670 | |
656 | sub size_request { |
671 | sub size_request { |
657 | my ($self) = @_; |
672 | my ($self) = @_; |
658 | |
673 | |
|
|
674 | $self->{layout}->set_width; |
|
|
675 | $self->{layout}->size |
659 | if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
676 | # if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
660 | ( |
677 | # ( |
661 | $self->{texture}{width}, |
678 | # $self->{texture}{width}, |
662 | $self->{texture}{height}, |
679 | # $self->{texture}{height}, |
663 | ) |
680 | # ) |
664 | } else { |
681 | # } else { |
665 | my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; |
682 | # my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; |
666 | |
683 | # |
667 | ($w, $h) |
684 | # ($w, $h) |
668 | } |
685 | # } |
|
|
686 | } |
669 | |
687 | |
|
|
688 | sub size_allocate { |
|
|
689 | my ($self, $w, $h) = @_; |
|
|
690 | |
|
|
691 | $self->SUPER::size_allocate ($w, $h); |
|
|
692 | delete $self->{texture}; |
670 | } |
693 | } |
671 | |
694 | |
672 | sub _draw { |
695 | sub _draw { |
673 | my ($self) = @_; |
696 | my ($self) = @_; |
674 | |
697 | |
675 | my $tex = $self->{texture}; |
698 | my $tex = $self->{texture} ||= do { |
|
|
699 | $self->{layout}->set_width ($self->{w}); |
|
|
700 | new_from_layout Crossfire::Client::Texture $self->{layout}; |
|
|
701 | }; |
676 | |
702 | |
677 | glEnable GL_BLEND; |
703 | glEnable GL_BLEND; |
678 | glEnable GL_TEXTURE_2D; |
704 | glEnable GL_TEXTURE_2D; |
679 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
705 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
680 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
706 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
… | |
… | |
708 | |
734 | |
709 | if ($sym == SDLK_BACKSPACE) { |
735 | if ($sym == SDLK_BACKSPACE) { |
710 | substr $text, -1, 1, ''; |
736 | substr $text, -1, 1, ''; |
711 | } elsif ($uni) { |
737 | } elsif ($uni) { |
712 | $text .= chr $uni; |
738 | $text .= chr $uni; |
713 | print "$uni <$text>\n";#d# |
|
|
714 | } |
739 | } |
715 | |
740 | |
716 | $self->set_text ($text); |
741 | $self->set_text ($text); |
717 | } |
742 | } |
718 | |
743 | |
719 | sub button_down { |
744 | sub button_down { |
720 | my ($self, $ev) = @_; |
745 | my ($self, $ev) = @_; |
721 | |
746 | |
722 | $self->focus_in; |
747 | $self->focus_in; |
|
|
748 | } |
|
|
749 | |
|
|
750 | sub mouse_motion { |
|
|
751 | my ($self, $ev, $x, $y) = @_; |
|
|
752 | printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
723 | } |
753 | } |
724 | |
754 | |
725 | sub _draw { |
755 | sub _draw { |
726 | my ($self) = @_; |
756 | my ($self) = @_; |
727 | |
757 | |
… | |
… | |
797 | glEnable GL_TEXTURE_2D; |
827 | glEnable GL_TEXTURE_2D; |
798 | glEnable GL_BLEND; |
828 | glEnable GL_BLEND; |
799 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
829 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
800 | |
830 | |
801 | my $sw4 = ($sw + 3) & ~3; |
831 | my $sw4 = ($sw + 3) & ~3; |
802 | my $lighting = "\x00" x ($sw4 * $sh); |
832 | my $darkness = "\x00" x ($sw4 * $sh); |
803 | |
833 | |
804 | for my $x (0 .. $sw - 1) { |
834 | for my $x (0 .. $sw - 1) { |
|
|
835 | my $row = $map->[$x + $xofs]; |
805 | for my $y (0 .. $sh - 1) { |
836 | for my $y (0 .. $sh - 1) { |
806 | |
837 | |
807 | my $cell = $map->[$x + $xofs][$y + $yofs] |
838 | my $cell = $row->[$y + $yofs] |
808 | or next; |
839 | or next; |
809 | |
840 | |
810 | my $darkness = $cell->[0] * (1 / 255); |
841 | my $dark = $cell->[0]; |
811 | if ($darkness < 0) { |
842 | if ($dark < 0) { |
812 | $darkness = $cell->[1] ? 0.1 : 0; |
843 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
844 | } else { |
|
|
845 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
813 | } |
846 | } |
814 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
|
|
815 | |
847 | |
816 | for my $num (grep $_, @$cell[1,2,3]) { |
848 | for my $num (grep $_, @$cell[1,2,3]) { |
817 | my $tex = $::CONN->{face}[$num]{texture} || next; |
849 | my $tex = $::CONN->{face}[$num]{texture} || next; |
818 | |
850 | |
819 | my $w = $tex->{width}; |
851 | my $w = $tex->{width}; |
820 | my $h = $tex->{height}; |
852 | my $h = $tex->{height}; |
821 | |
853 | |
822 | my $px = ($x + 1) * 32 - $w; |
854 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
823 | my $py = ($y + 1) * 32 - $h; |
|
|
824 | |
|
|
825 | $tex->draw_quad ($px, $py, $w, $h); |
|
|
826 | } |
855 | } |
827 | } |
856 | } |
828 | } |
857 | } |
829 | |
858 | |
830 | # if (1) { # higher quality darkness |
859 | # if (1) { # higher quality darkness |
… | |
… | |
835 | # |
864 | # |
836 | # $lighting = $pb->get_pixels; |
865 | # $lighting = $pb->get_pixels; |
837 | # $lighting =~ s/(.)../$1/gs; |
866 | # $lighting =~ s/(.)../$1/gs; |
838 | # } |
867 | # } |
839 | |
868 | |
|
|
869 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
870 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
871 | |
840 | $lighting = new Crossfire::Client::Texture |
872 | $darkness = new Crossfire::Client::Texture |
841 | width => $sw4, |
873 | width => $sw4, |
842 | height => $sh, |
874 | height => $sh, |
843 | data => $lighting, |
875 | data => $darkness, |
844 | internalformat => GL_ALPHA, |
876 | internalformat => GL_ALPHA, |
845 | format => GL_ALPHA; |
877 | format => GL_ALPHA; |
846 | |
878 | |
847 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
848 | glColor 0.45, 0.45, 0.45, 1; |
879 | glColor 0.45, 0.45, 0.45, 1; |
849 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
850 | glBindTexture GL_TEXTURE_2D, $lighting->{name}; |
|
|
851 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
|
|
852 | |
|
|
853 | $lighting->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
880 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
854 | |
881 | |
855 | glDisable GL_TEXTURE_2D; |
882 | glDisable GL_TEXTURE_2D; |
856 | glDisable GL_BLEND; |
883 | glDisable GL_BLEND; |
857 | } |
884 | } |
858 | |
885 | |
… | |
… | |
926 | } |
953 | } |
927 | |
954 | |
928 | sub animate { |
955 | sub animate { |
929 | my ($self, $interval) = @_; |
956 | my ($self, $interval) = @_; |
930 | |
957 | |
931 | printf "%5.2f\n", 1 / $interval;#d# |
|
|
932 | |
|
|
933 | $self->{time} -= $interval * $self->{speed}; |
958 | $self->{time} -= $interval * $self->{speed}; |
934 | if ($self->{time} <= 0) { |
959 | if ($self->{time} <= 0) { |
935 | $self->{time} = 0; |
960 | $self->{time} = 0; |
936 | ::animation_stop $self; |
961 | ::animation_stop $self; |
937 | } |
962 | } |
… | |
… | |
968 | |
993 | |
969 | $_->size_allocate ($_->size_request) |
994 | $_->size_allocate ($_->size_request) |
970 | for @{$self->{children}}; |
995 | for @{$self->{children}}; |
971 | } |
996 | } |
972 | |
997 | |
|
|
998 | sub translate { |
|
|
999 | my ($self, $x, $y) = @_; |
|
|
1000 | |
|
|
1001 | ($x, $y) |
|
|
1002 | } |
|
|
1003 | |
973 | sub update { |
1004 | sub update { |
974 | my ($self) = @_; |
1005 | my ($self) = @_; |
975 | |
1006 | |
976 | $self->size_allocate ($self->size_request); |
1007 | $self->size_allocate ($self->size_request); |
977 | ::refresh (); |
1008 | ::refresh (); |