ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
Revision: 1.13
Committed: Fri Apr 7 20:57:29 2006 UTC (18 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.12: +7 -3 lines
Log Message:
added z ordering

File Contents

# User Rev Content
1 elmex 1.6 package Crossfire::Client::Widget;
2 root 1.8
3 elmex 1.1 use strict;
4 elmex 1.11 use SDL::OpenGL;
5     use SDL::OpenGL::Constants;
6 elmex 1.1
7     our $FOCUS; # the widget with current focus
8 elmex 1.13 our @ACTIVE_WIDGETS;
9 elmex 1.1
10     # class methods for events
11     sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
12     sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS }
13     sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
14     sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS }
15    
16     sub new {
17     my $class = shift;
18 root 1.10
19     bless { @_ }, $class
20 elmex 1.1 }
21    
22 elmex 1.2 sub activate {
23 elmex 1.13 push @ACTIVE_WIDGETS, $_[0];
24 elmex 1.2 }
25 root 1.4
26 elmex 1.2 sub deactivate {
27 elmex 1.13 @ACTIVE_WIDGETS =
28     sort { $a->{z} <=> $b->{z} }
29     grep { $_ != $_[0] }
30     @ACTIVE_WIDGETS;
31 elmex 1.2 }
32    
33 elmex 1.1 sub focus_in {
34     my ($widget) = @_;
35     $FOCUS = $widget;
36     }
37 root 1.4
38 elmex 1.1 sub focus_out {
39     my ($widget) = @_;
40     }
41 root 1.4
42 elmex 1.1 sub key_down {
43     my ($widget, $sdlev) = @_;
44     }
45 root 1.4
46 elmex 1.1 sub key_up {
47     my ($widget, $sdlev) = @_;
48     }
49 root 1.4
50 elmex 1.1 sub button_down {
51     my ($widget, $sdlev) = @_;
52     }
53 root 1.4
54 elmex 1.1 sub button_up {
55     my ($widget, $sdlev) = @_;
56     }
57 root 1.4
58 elmex 1.11 sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} }
59     sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} }
60 elmex 1.13 sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} }
61 elmex 1.11
62 elmex 1.1 sub draw {
63 elmex 1.11 my ($self) = @_;
64    
65     glPushMatrix;
66 root 1.12 glTranslate $self->{x}, $self->{y}, 0;
67 elmex 1.11 $self->_draw;
68     glPopMatrix;
69     }
70    
71     sub _draw {
72 elmex 1.1 my ($widget) = @_;
73     }
74 root 1.4
75 elmex 1.1 sub bbox {
76     my ($widget) = @_;
77     }
78 elmex 1.2
79 root 1.10 package Crossfire::Client::Widget::Label;
80    
81 root 1.12 our @ISA = Crossfire::Client::Widget::;
82    
83 root 1.10 use SDL::OpenGL;
84    
85     sub new {
86 root 1.12 my ($class, $x, $y, $z, $ttf, $text) = @_;
87 root 1.10
88 root 1.12 my $self = $class->SUPER::new (x => $x, y => $y, z => $z);
89 root 1.10
90     $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text;
91    
92     $self
93     }
94    
95 elmex 1.11 sub _draw {
96 root 1.10 my ($self) = @_;
97    
98     my $tex = $self->{texture};
99    
100 root 1.12 $self->{x}--;
101    
102     glEnable GL_BLEND;
103 root 1.10 glEnable GL_TEXTURE_2D;
104 root 1.12 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
105 root 1.10 glBindTexture GL_TEXTURE_2D, $tex->{name};
106    
107 root 1.12 glColor 1, 1, 1;
108    
109 root 1.10 glBegin GL_QUADS;
110     glTexCoord 0, 0; glVertex 0 , 0;
111     glTexCoord 0, 1; glVertex 0 , $tex->{height};
112     glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
113     glTexCoord 1, 0; glVertex $tex->{width}, 0;
114     glEnd;
115    
116 root 1.12 glDisable GL_BLEND;
117 root 1.10 glDisable GL_TEXTURE_2D;
118     }
119    
120 elmex 1.9 package Crossfire::Client::Widget::TextView;
121 root 1.4
122 elmex 1.3 use strict;
123 root 1.10
124 elmex 1.9 our @ISA = qw/Crossfire::Client::Widget/;
125 elmex 1.3
126     use SDL::OpenGL;
127     use SDL::OpenGL::Constants;
128    
129     sub add_line {
130     my ($self, $line) = @_;
131     push @{$self->{lines}}, $line;
132     }
133    
134 elmex 1.11 sub _draw {
135 elmex 1.3 my ($self) = @_;
136    
137     }
138    
139 elmex 1.9 package Crossfire::Client::Widget::MapWidget;
140 root 1.4
141 elmex 1.2 use strict;
142 elmex 1.7
143 elmex 1.9 our @ISA = qw/Crossfire::Client::Widget/;
144 elmex 1.2
145     use SDL::OpenGL;
146     use SDL::OpenGL::Constants;
147    
148     sub key_down {
149     print "MAPKEYDOWN\n";
150     }
151    
152     sub key_up {
153     }
154    
155 elmex 1.11 sub _draw {
156 elmex 1.2 glEnable GL_TEXTURE_2D;
157     glEnable GL_BLEND;
158 root 1.12 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
159 elmex 1.2
160     my $map = $::CONN->{map};
161    
162     for my $x (0 .. $::CONN->{mapw} - 1) {
163     for my $y (0 .. $::CONN->{maph} - 1) {
164    
165     my $cell = $map->[$x][$y]
166     or next;
167    
168     my $darkness = $cell->[3] * (1 / 255);
169     glColor $darkness, $darkness, $darkness;
170    
171     for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
172 root 1.4 my $tex = $::CONN->{face}[$num]{texture} || next;
173 elmex 1.2
174 root 1.4 glBindTexture GL_TEXTURE_2D, $tex->{name};
175 elmex 1.2
176     glBegin GL_QUADS;
177 root 1.10 glTexCoord 0, 0; glVertex $x * 32 , $y * 32;
178     glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32;
179     glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32;
180     glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32;
181 elmex 1.2 glEnd;
182     }
183     }
184     }
185    
186     glDisable GL_TEXTURE_2D;
187     glDisable GL_BLEND;
188     }
189    
190 elmex 1.1 1;
191 root 1.5