… | |
… | |
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 | |
… | |
… | |
332 | or return; |
341 | or return; |
333 | |
342 | |
334 | glEnable GL_BLEND; |
343 | glEnable GL_BLEND; |
335 | glEnable GL_TEXTURE_2D; |
344 | glEnable GL_TEXTURE_2D; |
336 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
345 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
337 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
338 | |
346 | |
339 | glBegin GL_QUADS; |
347 | $tex->draw_quad (0, 0, $w, $h); |
340 | glTexCoord 0, 0; glVertex 0, 0; |
|
|
341 | glTexCoord 0, 1; glVertex 0, $h; |
|
|
342 | glTexCoord 1, 1; glVertex $w, $h; |
|
|
343 | glTexCoord 1, 0; glVertex $w, 0; |
|
|
344 | glEnd; |
|
|
345 | |
348 | |
346 | glDisable GL_BLEND; |
349 | glDisable GL_BLEND; |
347 | glDisable GL_TEXTURE_2D; |
350 | glDisable GL_TEXTURE_2D; |
348 | } |
351 | } |
349 | |
352 | |
… | |
… | |
382 | |
385 | |
383 | my ($w, $h) = $chld->size_request; |
386 | my ($w, $h) = $chld->size_request; |
384 | |
387 | |
385 | glBegin GL_QUADS; |
388 | glBegin GL_QUADS; |
386 | glColor 0, 0, 0; |
389 | glColor 0, 0, 0; |
387 | glTexCoord 0, 0; glVertex 0 , 0; |
390 | glVertex 0 , 0; |
388 | glTexCoord 0, 1; glVertex 0 , $h + 4; |
391 | glVertex 0 , $h + 4; |
389 | glTexCoord 1, 1; glVertex $w + 4 , $h + 4; |
392 | glVertex $w + 4 , $h + 4; |
390 | glTexCoord 1, 0; glVertex $w + 4 , 0; |
393 | glVertex $w + 4 , 0; |
391 | glEnd; |
394 | glEnd; |
392 | |
395 | |
393 | $chld->draw; |
396 | $chld->draw; |
394 | } |
397 | } |
395 | |
398 | |
… | |
… | |
445 | glEnable GL_TEXTURE_2D; |
448 | glEnable GL_TEXTURE_2D; |
446 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
449 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
447 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
450 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
448 | |
451 | |
449 | my $top = $tex[1]; |
452 | my $top = $tex[1]; |
450 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
453 | $top->draw_quad (0, 0, $w, $top->{height}); |
451 | |
|
|
452 | glBegin GL_QUADS; |
|
|
453 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
454 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
|
|
455 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
|
|
456 | glTexCoord 1, 0; glVertex $w , 0; |
|
|
457 | glEnd; |
|
|
458 | |
454 | |
459 | my $left = $tex[3]; |
455 | my $left = $tex[3]; |
460 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
456 | $left->draw_quad (0, $top->{height}, $left->{width}, $ch); |
461 | |
|
|
462 | glBegin GL_QUADS; |
|
|
463 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
|
|
464 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
|
|
465 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
|
|
466 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
|
|
467 | glEnd; |
|
|
468 | |
457 | |
469 | my $right = $tex[2]; |
458 | my $right = $tex[2]; |
470 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
459 | $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch); |
471 | |
|
|
472 | glBegin GL_QUADS; |
|
|
473 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
|
|
474 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
|
|
475 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
|
|
476 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
|
|
477 | glEnd; |
|
|
478 | |
460 | |
479 | my $bottom = $tex[4]; |
461 | my $bottom = $tex[4]; |
480 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
462 | $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height}); |
481 | |
|
|
482 | glBegin GL_QUADS; |
|
|
483 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
|
|
484 | glTexCoord 0, 1; glVertex 0 , $h; |
|
|
485 | glTexCoord 1, 1; glVertex $w , $h; |
|
|
486 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
|
|
487 | glEnd; |
|
|
488 | |
463 | |
489 | my $bg = $tex[0]; |
464 | my $bg = $tex[0]; |
490 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
465 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
491 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
466 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
492 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
467 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
493 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
468 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
494 | |
469 | |
495 | my $rep_x = $cw / $bg->{width}; |
470 | my $rep_x = $cw / $bg->{width}; |
496 | my $rep_y = $ch / $bg->{height}; |
471 | my $rep_y = $ch / $bg->{height}; |
497 | |
472 | |
498 | glBegin GL_QUADS; |
473 | $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch); |
499 | glTexCoord 0, 0; glVertex $left->{width}, $top->{height}; |
|
|
500 | glTexCoord 0, $rep_y; glVertex $left->{width}, $top->{height} + $ch; |
|
|
501 | glTexCoord $rep_x, $rep_y; glVertex $left->{width} + $cw , $top->{height} + $ch; |
|
|
502 | glTexCoord $rep_x, 0; glVertex $left->{width} + $cw , $top->{height}; |
|
|
503 | glEnd; |
|
|
504 | |
474 | |
505 | glDisable GL_BLEND; |
475 | glDisable GL_BLEND; |
506 | glDisable GL_TEXTURE_2D; |
476 | glDisable GL_TEXTURE_2D; |
507 | |
477 | |
508 | $self->child->draw; |
478 | $self->child->draw; |
… | |
… | |
715 | |
685 | |
716 | glEnable GL_BLEND; |
686 | glEnable GL_BLEND; |
717 | glEnable GL_TEXTURE_2D; |
687 | glEnable GL_TEXTURE_2D; |
718 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
688 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
719 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
689 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
720 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
721 | |
690 | |
722 | glColor 1, 0, 0, 1; # TODO color |
691 | glColor 1, 0, 0, 1; # TODO color |
723 | |
692 | |
724 | glBegin GL_QUADS; |
693 | $tex->draw_quad (0, 0); |
725 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
726 | glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
|
|
727 | glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
|
|
728 | glTexCoord 1, 0; glVertex $tex->{width}, 0; |
|
|
729 | glEnd; |
|
|
730 | |
694 | |
731 | glDisable GL_BLEND; |
695 | glDisable GL_BLEND; |
732 | glDisable GL_TEXTURE_2D; |
696 | glDisable GL_TEXTURE_2D; |
733 | } |
697 | } |
734 | |
698 | |
… | |
… | |
753 | |
717 | |
754 | if ($sym == SDLK_BACKSPACE) { |
718 | if ($sym == SDLK_BACKSPACE) { |
755 | substr $text, -1, 1, ''; |
719 | substr $text, -1, 1, ''; |
756 | } elsif ($uni) { |
720 | } elsif ($uni) { |
757 | $text .= chr $uni; |
721 | $text .= chr $uni; |
758 | print "$uni <$text>\n";#d# |
|
|
759 | } |
722 | } |
760 | |
723 | |
761 | $self->set_text ($text); |
724 | $self->set_text ($text); |
762 | } |
725 | } |
763 | |
726 | |
764 | sub button_down { |
727 | sub button_down { |
765 | my ($self, $ev) = @_; |
728 | my ($self, $ev) = @_; |
766 | |
729 | |
767 | $self->focus_in; |
730 | $self->focus_in; |
|
|
731 | } |
|
|
732 | |
|
|
733 | sub mouse_motion { |
|
|
734 | my ($self, $ev, $x, $y) = @_; |
|
|
735 | printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
768 | } |
736 | } |
769 | |
737 | |
770 | sub _draw { |
738 | sub _draw { |
771 | my ($self) = @_; |
739 | my ($self) = @_; |
772 | |
740 | |
… | |
… | |
842 | glEnable GL_TEXTURE_2D; |
810 | glEnable GL_TEXTURE_2D; |
843 | glEnable GL_BLEND; |
811 | glEnable GL_BLEND; |
844 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
812 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
845 | |
813 | |
846 | my $sw4 = ($sw + 3) & ~3; |
814 | my $sw4 = ($sw + 3) & ~3; |
847 | my $lighting = "\x00" x ($sw4 * $sh); |
815 | my $darkness = "\x00" x ($sw4 * $sh); |
848 | |
816 | |
849 | for my $x (0 .. $sw - 1) { |
817 | for my $x (0 .. $sw - 1) { |
|
|
818 | my $row = $map->[$x + $xofs]; |
850 | for my $y (0 .. $sh - 1) { |
819 | for my $y (0 .. $sh - 1) { |
851 | |
820 | |
852 | my $cell = $map->[$x + $xofs][$y + $yofs] |
821 | my $cell = $row->[$y + $yofs] |
853 | or next; |
822 | or next; |
854 | |
823 | |
855 | my $darkness = $cell->[0] * (1 / 255); |
824 | my $dark = $cell->[0]; |
856 | if ($darkness < 0) { |
825 | if ($dark < 0) { |
857 | $darkness = $cell->[1] ? 0.1 : 0; |
826 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
827 | } else { |
|
|
828 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
858 | } |
829 | } |
859 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
|
|
860 | |
830 | |
861 | for my $num (grep $_, @$cell[1,2,3]) { |
831 | for my $num (grep $_, @$cell[1,2,3]) { |
862 | my $tex = $::CONN->{face}[$num]{texture} || next; |
832 | my $tex = $::CONN->{face}[$num]{texture} || next; |
863 | |
833 | |
864 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
865 | |
|
|
866 | my $w = $tex->{width}; |
834 | my $w = $tex->{width}; |
867 | my $h = $tex->{height}; |
835 | my $h = $tex->{height}; |
868 | |
836 | |
869 | my $px = ($x + 1) * 32 - $w; |
837 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
870 | my $py = ($y + 1) * 32 - $h; |
|
|
871 | |
|
|
872 | glBegin GL_QUADS; |
|
|
873 | glTexCoord 0, 0; glVertex $px , $py; |
|
|
874 | glTexCoord 0, 1; glVertex $px , $py + $h; |
|
|
875 | glTexCoord 1, 1; glVertex $px + $w, $py + $h; |
|
|
876 | glTexCoord 1, 0; glVertex $px + $w, $py; |
|
|
877 | glEnd; |
|
|
878 | } |
838 | } |
879 | } |
839 | } |
880 | } |
840 | } |
881 | |
841 | |
882 | # if (1) { # higher quality darkness |
842 | # if (1) { # higher quality darkness |
… | |
… | |
887 | # |
847 | # |
888 | # $lighting = $pb->get_pixels; |
848 | # $lighting = $pb->get_pixels; |
889 | # $lighting =~ s/(.)../$1/gs; |
849 | # $lighting =~ s/(.)../$1/gs; |
890 | # } |
850 | # } |
891 | |
851 | |
|
|
852 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
853 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
854 | |
892 | $lighting = new Crossfire::Client::Texture |
855 | $darkness = new Crossfire::Client::Texture |
893 | width => $sw4, |
856 | width => $sw4, |
894 | height => $sh, |
857 | height => $sh, |
895 | data => $lighting, |
858 | data => $darkness, |
896 | internalformat => GL_ALPHA, |
859 | internalformat => GL_ALPHA, |
897 | format => GL_ALPHA; |
860 | format => GL_ALPHA; |
898 | |
861 | |
899 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
900 | glColor 0.45, 0.45, 0.45, 1; |
862 | glColor 0.45, 0.45, 0.45, 1; |
901 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
863 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
902 | glBindTexture GL_TEXTURE_2D, $lighting->{name}; |
|
|
903 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
|
|
904 | glBegin GL_QUADS; |
|
|
905 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
906 | glTexCoord 0, 1; glVertex 0 , $sh * 32; |
|
|
907 | glTexCoord 1, 1; glVertex $sw4 * 32, $sh * 32; |
|
|
908 | glTexCoord 1, 0; glVertex $sw4 * 32, 0; |
|
|
909 | glEnd; |
|
|
910 | |
864 | |
911 | glDisable GL_TEXTURE_2D; |
865 | glDisable GL_TEXTURE_2D; |
912 | glDisable GL_BLEND; |
866 | glDisable GL_BLEND; |
913 | } |
867 | } |
914 | |
868 | |
… | |
… | |
973 | |
927 | |
974 | sub moveto { |
928 | sub moveto { |
975 | my ($self, $x, $y) = @_; |
929 | my ($self, $x, $y) = @_; |
976 | |
930 | |
977 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
931 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
978 | $self->{speed} = 2; |
932 | $self->{speed} = 0.001; |
979 | $self->{time} = 1; |
933 | $self->{time} = 1; |
980 | |
934 | |
981 | ::animation_start $self; |
935 | ::animation_start $self; |
982 | } |
936 | } |
983 | |
937 | |
… | |
… | |
1022 | |
976 | |
1023 | $_->size_allocate ($_->size_request) |
977 | $_->size_allocate ($_->size_request) |
1024 | for @{$self->{children}}; |
978 | for @{$self->{children}}; |
1025 | } |
979 | } |
1026 | |
980 | |
|
|
981 | sub translate { |
|
|
982 | my ($self, $x, $y) = @_; |
|
|
983 | |
|
|
984 | ($x, $y) |
|
|
985 | } |
|
|
986 | |
1027 | sub update { |
987 | sub update { |
1028 | my ($self) = @_; |
988 | my ($self) = @_; |
1029 | |
989 | |
1030 | $self->size_allocate ($self->size_request); |
990 | $self->size_allocate ($self->size_request); |
1031 | ::refresh (); |
991 | ::refresh (); |