ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.56 by root, Mon Apr 10 22:16:34 2006 UTC vs.
Revision 1.58 by root, Tue Apr 11 12:21:29 2006 UTC

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
42sub feed_sdl_button_up_event { 42sub 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
73sub new { 75sub new {
74 my $class = shift; 76 my $class = shift;
75 77
95sub size_allocate { 97sub 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
105sub translate {
106 my ($self, $x, $y) = @_;
107
108 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y});
100} 109}
101 110
102sub focus_in { 111sub focus_in {
103 my ($self) = @_; 112 my ($self) = @_;
104 113
708 717
709 if ($sym == SDLK_BACKSPACE) { 718 if ($sym == SDLK_BACKSPACE) {
710 substr $text, -1, 1, ''; 719 substr $text, -1, 1, '';
711 } elsif ($uni) { 720 } elsif ($uni) {
712 $text .= chr $uni; 721 $text .= chr $uni;
713 print "$uni <$text>\n";#d#
714 } 722 }
715 723
716 $self->set_text ($text); 724 $self->set_text ($text);
717} 725}
718 726
719sub button_down { 727sub button_down {
720 my ($self, $ev) = @_; 728 my ($self, $ev) = @_;
721 729
722 $self->focus_in; 730 $self->focus_in;
731}
732
733sub 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#
723} 736}
724 737
725sub _draw { 738sub _draw {
726 my ($self) = @_; 739 my ($self) = @_;
727 740
797 glEnable GL_TEXTURE_2D; 810 glEnable GL_TEXTURE_2D;
798 glEnable GL_BLEND; 811 glEnable GL_BLEND;
799 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 812 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
800 813
801 my $sw4 = ($sw + 3) & ~3; 814 my $sw4 = ($sw + 3) & ~3;
802 my $lighting = "\x00" x ($sw4 * $sh); 815 my $darkness = "\x00" x ($sw4 * $sh);
803 816
804 for my $x (0 .. $sw - 1) { 817 for my $x (0 .. $sw - 1) {
818 my $row = $map->[$x + $xofs];
805 for my $y (0 .. $sh - 1) { 819 for my $y (0 .. $sh - 1) {
806 820
807 my $cell = $map->[$x + $xofs][$y + $yofs] 821 my $cell = $row->[$y + $yofs]
808 or next; 822 or next;
809 823
810 my $darkness = $cell->[0] * (1 / 255); 824 my $dark = $cell->[0];
811 if ($darkness < 0) { 825 if ($dark < 0) {
812 $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;
813 } 829 }
814 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255;
815 830
816 for my $num (grep $_, @$cell[1,2,3]) { 831 for my $num (grep $_, @$cell[1,2,3]) {
817 my $tex = $::CONN->{face}[$num]{texture} || next; 832 my $tex = $::CONN->{face}[$num]{texture} || next;
818 833
819 my $w = $tex->{width}; 834 my $w = $tex->{width};
820 my $h = $tex->{height}; 835 my $h = $tex->{height};
821 836
822 my $px = ($x + 1) * 32 - $w; 837 $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 } 838 }
827 } 839 }
828 } 840 }
829 841
830# if (1) { # higher quality darkness 842# if (1) { # higher quality darkness
835# 847#
836# $lighting = $pb->get_pixels; 848# $lighting = $pb->get_pixels;
837# $lighting =~ s/(.)../$1/gs; 849# $lighting =~ s/(.)../$1/gs;
838# } 850# }
839 851
852 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
853 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
854
840 $lighting = new Crossfire::Client::Texture 855 $darkness = new Crossfire::Client::Texture
841 width => $sw4, 856 width => $sw4,
842 height => $sh, 857 height => $sh,
843 data => $lighting, 858 data => $darkness,
844 internalformat => GL_ALPHA, 859 internalformat => GL_ALPHA,
845 format => GL_ALPHA; 860 format => GL_ALPHA;
846 861
847 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
848 glColor 0.45, 0.45, 0.45, 1; 862 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); 863 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
854 864
855 glDisable GL_TEXTURE_2D; 865 glDisable GL_TEXTURE_2D;
856 glDisable GL_BLEND; 866 glDisable GL_BLEND;
857} 867}
858 868
926} 936}
927 937
928sub animate { 938sub animate {
929 my ($self, $interval) = @_; 939 my ($self, $interval) = @_;
930 940
931 printf "%5.2f\n", 1 / $interval;#d#
932
933 $self->{time} -= $interval * $self->{speed}; 941 $self->{time} -= $interval * $self->{speed};
934 if ($self->{time} <= 0) { 942 if ($self->{time} <= 0) {
935 $self->{time} = 0; 943 $self->{time} = 0;
936 ::animation_stop $self; 944 ::animation_stop $self;
937 } 945 }
968 976
969 $_->size_allocate ($_->size_request) 977 $_->size_allocate ($_->size_request)
970 for @{$self->{children}}; 978 for @{$self->{children}};
971} 979}
972 980
981sub translate {
982 my ($self, $x, $y) = @_;
983
984 ($x, $y)
985}
986
973sub update { 987sub update {
974 my ($self) = @_; 988 my ($self) = @_;
975 989
976 $self->size_allocate ($self->size_request); 990 $self->size_allocate ($self->size_request);
977 ::refresh (); 991 ::refresh ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines