… | |
… | |
5 | use Scalar::Util; |
5 | use Scalar::Util; |
6 | |
6 | |
7 | use SDL::OpenGL; |
7 | use SDL::OpenGL; |
8 | use SDL::OpenGL::Constants; |
8 | use SDL::OpenGL::Constants; |
9 | |
9 | |
10 | our $FOCUS; # the widget with current focus |
10 | use Crossfire::Client; |
|
|
11 | |
|
|
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
|
|
13 | |
|
|
14 | our $TOPLEVEL; |
|
|
15 | our $BUTTON_STATE; |
11 | |
16 | |
12 | # class methods for events |
17 | # class methods for events |
13 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
18 | sub feed_sdl_key_down_event { |
14 | sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
19 | $FOCUS->key_down ($_[0]) if $FOCUS; |
|
|
20 | } |
|
|
21 | |
|
|
22 | sub feed_sdl_key_up_event { |
|
|
23 | $FOCUS->key_up ($_[0]) if $FOCUS; |
|
|
24 | } |
|
|
25 | |
15 | sub feed_sdl_button_down_event { } |
26 | sub feed_sdl_button_down_event { |
|
|
27 | my ($ev) = @_; |
|
|
28 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
29 | |
|
|
30 | if (!$BUTTON_STATE) { |
|
|
31 | my $widget = $TOPLEVEL->find_widget ($x, $y); |
|
|
32 | |
|
|
33 | $GRAB = $widget; |
|
|
34 | $GRAB->update if $GRAB; |
|
|
35 | } |
|
|
36 | |
|
|
37 | $BUTTON_STATE |= 1 << ($ev->button - 1); |
|
|
38 | |
|
|
39 | $GRAB->button_down ($ev) if $GRAB; |
|
|
40 | } |
|
|
41 | |
16 | sub feed_sdl_button_up_event { } |
42 | sub feed_sdl_button_up_event { |
|
|
43 | my ($ev) = @_; |
|
|
44 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
45 | |
|
|
46 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
|
|
47 | |
|
|
48 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
|
|
49 | |
|
|
50 | if (!$BUTTON_STATE) { |
|
|
51 | my $grab = $GRAB; undef $GRAB; |
|
|
52 | $grab->update if $grab; |
|
|
53 | $GRAB->update if $GRAB; |
|
|
54 | } |
|
|
55 | } |
|
|
56 | |
|
|
57 | sub feed_sdl_motion_event { |
|
|
58 | my ($ev) = @_; |
|
|
59 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
60 | |
|
|
61 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
|
|
62 | |
|
|
63 | if ($widget != $HOVER) { |
|
|
64 | my $hover = $HOVER; $HOVER = $widget; |
|
|
65 | |
|
|
66 | $hover->update if $hover; |
|
|
67 | $HOVER->update if $HOVER; |
|
|
68 | } |
|
|
69 | |
|
|
70 | $HOVER->mouse_motion ($ev) if $HOVER; |
|
|
71 | } |
17 | |
72 | |
18 | sub new { |
73 | sub new { |
19 | my $class = shift; |
74 | my $class = shift; |
20 | |
75 | |
21 | bless { @_ }, $class |
76 | bless { @_ }, $class |
… | |
… | |
37 | Carp::confess "size_request is abtract"; |
92 | Carp::confess "size_request is abtract"; |
38 | } |
93 | } |
39 | |
94 | |
40 | sub size_allocate { |
95 | sub size_allocate { |
41 | my ($self, $w, $h) = @_; |
96 | my ($self, $w, $h) = @_; |
|
|
97 | |
42 | $self->w ($w); |
98 | $self->{w} = $w; |
43 | $self->h ($h); |
99 | $self->{h} = $h; |
44 | } |
100 | } |
45 | |
101 | |
46 | sub focus_in { |
102 | sub focus_in { |
47 | my ($widget) = @_; |
103 | my ($self) = @_; |
48 | $FOCUS = $widget; |
104 | |
|
|
105 | my $focus = $FOCUS; $FOCUS = $self; |
|
|
106 | $focus->update if $focus; |
|
|
107 | $FOCUS->update; |
49 | } |
108 | } |
50 | |
109 | |
51 | sub focus_out { |
110 | sub focus_out { |
52 | my ($widget) = @_; |
111 | my ($self) = @_; |
53 | } |
|
|
54 | |
112 | |
55 | sub key_down { |
113 | return unless $FOCUS == $self; |
56 | my ($widget, $sdlev) = @_; |
|
|
57 | } |
|
|
58 | |
114 | |
59 | sub key_up { |
115 | my $focus = $FOCUS; undef $FOCUS; |
60 | my ($widget, $sdlev) = @_; |
116 | $focus->update if $focus; #? |
61 | } |
117 | } |
62 | |
118 | |
|
|
119 | sub mouse_motion { } |
|
|
120 | sub button_up { } |
63 | sub button_down { |
121 | sub button_down { } |
64 | my ($widget, $sdlev) = @_; |
122 | sub key_down { } |
65 | } |
123 | sub key_up { } |
66 | |
124 | |
67 | sub button_up { |
|
|
68 | my ($widget, $sdlev) = @_; |
|
|
69 | } |
|
|
70 | |
|
|
71 | sub w { $_[0]->{w} = $_[1] if $_[1]; $_[0]->{w} } |
125 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
72 | sub h { $_[0]->{h} = $_[1] if $_[1]; $_[0]->{h} } |
126 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
73 | sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } |
127 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
74 | sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } |
128 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
75 | sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} } |
129 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
76 | |
130 | |
77 | sub draw { |
131 | sub draw { |
78 | my ($self) = @_; |
132 | my ($self) = @_; |
79 | |
133 | |
80 | glPushMatrix; |
134 | glPushMatrix; |
81 | glTranslate $self->{x}, $self->{y}, 0; |
135 | glTranslate $self->{x}, $self->{y}, 0; |
82 | $self->_draw; |
136 | $self->_draw; |
|
|
137 | if ($self == $HOVER) { |
|
|
138 | glColor 1, 1, 1, 0.4; |
|
|
139 | glEnable GL_BLEND; |
|
|
140 | glBegin GL_QUADS; |
|
|
141 | glVertex 0 , 0; |
|
|
142 | glVertex $self->{w}, 0; |
|
|
143 | glVertex $self->{w}, $self->{h}; |
|
|
144 | glVertex 0 , $self->{h}; |
|
|
145 | glEnd; |
|
|
146 | glDisable GL_BLEND; |
|
|
147 | } |
83 | glPopMatrix; |
148 | glPopMatrix; |
84 | } |
149 | } |
85 | |
150 | |
86 | sub _draw { |
151 | sub _draw { |
87 | my ($widget) = @_; |
152 | my ($self) = @_; |
|
|
153 | |
|
|
154 | warn "no draw defined for $self\n"; |
88 | } |
155 | } |
89 | |
156 | |
90 | sub bbox { |
157 | sub bbox { |
91 | my ($self) = @_; |
158 | my ($self) = @_; |
92 | my ($w, $h) = $self->size_request; |
159 | my ($w, $h) = $self->size_request; |
… | |
… | |
96 | $self->{x} = $w, |
163 | $self->{x} = $w, |
97 | $self->{y} = $h |
164 | $self->{y} = $h |
98 | ) |
165 | ) |
99 | } |
166 | } |
100 | |
167 | |
|
|
168 | sub find_widget { |
|
|
169 | my ($self, $x, $y) = @_; |
|
|
170 | |
|
|
171 | return $self |
|
|
172 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
173 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
174 | |
|
|
175 | () |
|
|
176 | } |
|
|
177 | |
101 | sub del_parent { $_[0]->{parent} = undef } |
178 | sub del_parent { $_[0]->{parent} = undef } |
102 | |
179 | |
103 | sub set_parent { |
180 | sub set_parent { |
104 | my ($self, $par) = @_; |
181 | my ($self, $par) = @_; |
105 | |
182 | |
… | |
… | |
122 | my ($self) = @_; |
199 | my ($self) = @_; |
123 | |
200 | |
124 | #$self->deactivate; |
201 | #$self->deactivate; |
125 | } |
202 | } |
126 | |
203 | |
|
|
204 | ############################################################################# |
|
|
205 | |
|
|
206 | package Crossfire::Client::Widget::Container; |
|
|
207 | |
|
|
208 | our @ISA = Crossfire::Client::Widget::; |
|
|
209 | |
|
|
210 | sub new { |
|
|
211 | my ($class, @widgets) = @_; |
|
|
212 | |
|
|
213 | my $self = $class->SUPER::new (children => []); |
|
|
214 | $self->add ($_) for @widgets; |
|
|
215 | |
|
|
216 | $self |
|
|
217 | } |
|
|
218 | |
|
|
219 | sub add { |
|
|
220 | my ($self, $chld, $expand) = @_; |
|
|
221 | |
|
|
222 | $chld->{expand} = $expand; |
|
|
223 | $chld->set_parent ($self); |
|
|
224 | |
|
|
225 | @{$self->{children}} = |
|
|
226 | sort { $a->{z} <=> $b->{z} } |
|
|
227 | @{$self->{children}}, $chld; |
|
|
228 | |
|
|
229 | $self->size_allocate ($self->{w}, $self->{h}) |
|
|
230 | if $self->{w}; #TODO: check for "realised state" |
|
|
231 | } |
|
|
232 | |
|
|
233 | sub remove { |
|
|
234 | my ($self, $widget) = @_; |
|
|
235 | |
|
|
236 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
|
|
237 | |
|
|
238 | $self->size_allocate ($self->{w}, $self->{h}); |
|
|
239 | } |
|
|
240 | |
|
|
241 | sub find_widget { |
|
|
242 | my ($self, $x, $y) = @_; |
|
|
243 | |
|
|
244 | $x -= $self->{x}; |
|
|
245 | $y -= $self->{y}; |
|
|
246 | |
|
|
247 | my $res; |
|
|
248 | |
|
|
249 | for (reverse @{ $self->{children} }) { |
|
|
250 | $res = $_->find_widget ($x, $y) |
|
|
251 | and return $res; |
|
|
252 | } |
|
|
253 | |
|
|
254 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
|
|
255 | } |
|
|
256 | |
|
|
257 | sub _draw { |
|
|
258 | my ($self) = @_; |
|
|
259 | |
|
|
260 | $_->draw for @{$self->{children}}; |
|
|
261 | } |
|
|
262 | |
|
|
263 | ############################################################################# |
|
|
264 | |
127 | package Crossfire::Client::Widget::Bin; |
265 | package Crossfire::Client::Widget::Bin; |
128 | |
266 | |
129 | our @ISA = Crossfire::Client::Widget::; |
267 | our @ISA = Crossfire::Client::Widget::Container::; |
130 | |
268 | |
131 | sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->{expand} = $_[2] } |
|
|
132 | sub get { $_[0]->{child} } |
269 | sub child { $_[0]->{children}[0] } |
133 | |
|
|
134 | sub remove { |
|
|
135 | my ($self, $chld) = @_; |
|
|
136 | delete $self->{child} |
|
|
137 | if $self->{child} == $chld; |
|
|
138 | } |
|
|
139 | |
270 | |
140 | sub size_request { |
271 | sub size_request { |
141 | $_[0]->{child}->size_request if $_[0]->{child} |
272 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
142 | } |
273 | } |
|
|
274 | |
143 | sub size_allocate { |
275 | sub size_allocate { |
144 | my ($self, $w, $h) = @_; |
276 | my ($self, $w, $h) = @_; |
|
|
277 | |
145 | $self->SUPER::size_allocate ($w, $h); |
278 | $self->SUPER::size_allocate ($w, $h); |
146 | $self->{child}->size_allocate ($w, $h) |
279 | $self->{children}[0]->size_allocate ($w, $h) |
147 | if $self->{child} |
280 | if $self->{children}[0] |
148 | } |
281 | } |
149 | |
282 | |
150 | sub _draw { |
283 | ############################################################################# |
151 | my ($self) = @_; |
|
|
152 | |
284 | |
153 | $self->{child}->draw; |
|
|
154 | } |
|
|
155 | |
|
|
156 | package Crossfire::Client::Widget::Toplevel; |
285 | package Crossfire::Client::Widget::Window; |
157 | |
286 | |
158 | our @ISA = Crossfire::Client::Widget::; |
287 | our @ISA = Crossfire::Client::Widget::Bin::; |
159 | |
288 | |
160 | use SDL::OpenGL; |
289 | use SDL::OpenGL; |
161 | |
290 | |
162 | sub add { |
291 | sub new { |
163 | my ($self, $chld) = @_; |
292 | my ($class, $x, $y, $z, $w, $h) = @_; |
164 | |
293 | |
165 | push @{$self->{childs}}, $chld; |
294 | my $self = $class->SUPER::new; |
166 | @{$self->{childs}} = |
|
|
167 | sort { $a->{z} <=> $b->{z} } |
|
|
168 | @{$self->{childs}}; |
|
|
169 | |
295 | |
170 | $chld->set_parent ($self); |
296 | @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h); |
171 | $chld->size_allocate ($chld->size_request); |
|
|
172 | } |
|
|
173 | |
|
|
174 | sub remove { |
|
|
175 | my ($self, $chld) = @_; |
|
|
176 | @{$self->{childs}} = |
|
|
177 | sort { $a->{z} <=> $b->{z} } |
|
|
178 | grep { $_ && $_ != $_[0] } |
|
|
179 | @{$self->{childs}} |
|
|
180 | } |
297 | } |
181 | |
298 | |
182 | sub update { |
299 | sub update { |
183 | my ($self) = @_; |
300 | my ($self) = @_; |
184 | ::refresh (); |
|
|
185 | } |
|
|
186 | |
301 | |
187 | sub _draw { |
|
|
188 | my ($self) = @_; |
|
|
189 | |
|
|
190 | $_->draw for @{$self->{childs}}; |
|
|
191 | } |
|
|
192 | |
|
|
193 | package Crossfire::Client::Widget::Window; |
|
|
194 | |
|
|
195 | our @ISA = Crossfire::Client::Widget::Bin::; |
|
|
196 | |
|
|
197 | use SDL::OpenGL; |
|
|
198 | |
|
|
199 | sub add { |
|
|
200 | my ($self, $chld) = @_; |
|
|
201 | warn "ADD $chld\n"; |
|
|
202 | $self->SUPER::add ($chld); |
|
|
203 | $chld->set_parent ($self); |
|
|
204 | } |
|
|
205 | |
|
|
206 | sub remove { |
|
|
207 | my ($self) = @_; |
|
|
208 | # TODO FIXME: removing a child from a window will crash, see render_chld |
|
|
209 | # $self->update; |
|
|
210 | } |
|
|
211 | |
|
|
212 | sub update { |
|
|
213 | my ($self) = @_; |
|
|
214 | $self->render_chld; |
302 | $self->render_chld; |
|
|
303 | $self->SUPER::update; |
215 | } |
304 | } |
216 | |
305 | |
217 | sub render_chld { |
306 | sub render_chld { |
218 | my ($self) = @_; |
307 | my ($self) = @_; |
219 | my $chld = $self->get; |
|
|
220 | my ($w, $h) = $self->size_request; |
|
|
221 | |
308 | |
222 | require Carp; |
|
|
223 | Carp::cluck "RENDERCHI $w $h"; |
|
|
224 | warn "RENDERCHI $w $h\n"; |
|
|
225 | $self->{texture} = |
309 | $self->{texture} = |
226 | Crossfire::Client::Texture->new_from_opengl ( |
310 | Crossfire::Client::Texture->new_from_opengl ( |
227 | $w, $h, sub { $chld->draw } |
311 | $self->{w}, $self->{h}, sub { $self->child->draw } |
228 | ); |
312 | ); |
229 | $self->{texture}->upload; |
|
|
230 | } |
|
|
231 | |
|
|
232 | sub size_request { |
|
|
233 | my ($self) = @_; |
|
|
234 | ($self->w, $self->h) |
|
|
235 | } |
313 | } |
236 | |
314 | |
237 | sub size_allocate { |
315 | sub size_allocate { |
238 | my ($self, $w, $h) = @_; |
316 | my ($self, $w, $h) = @_; |
239 | |
317 | |
240 | $self->w ($w); |
318 | $self->{w} = $w; |
241 | $self->h ($h); |
319 | $self->{h} = $h; |
|
|
320 | |
242 | $self->get->size_allocate ($w, $h); |
321 | $self->child->size_allocate ($w, $h); |
243 | |
322 | |
244 | $self->update; #TODO: Move this to the size_request event propably? |
323 | $self->render_chld; |
245 | } |
324 | } |
246 | |
325 | |
247 | sub _draw { |
326 | sub _draw { |
248 | my ($self) = @_; |
327 | my ($self) = @_; |
249 | |
328 | |
… | |
… | |
266 | |
345 | |
267 | glDisable GL_BLEND; |
346 | glDisable GL_BLEND; |
268 | glDisable GL_TEXTURE_2D; |
347 | glDisable GL_TEXTURE_2D; |
269 | } |
348 | } |
270 | |
349 | |
|
|
350 | ############################################################################# |
|
|
351 | |
271 | package Crossfire::Client::Widget::Frame; |
352 | package Crossfire::Client::Widget::Frame; |
272 | |
353 | |
273 | our @ISA = Crossfire::Client::Widget::Bin::; |
354 | our @ISA = Crossfire::Client::Widget::Bin::; |
274 | |
355 | |
275 | use SDL::OpenGL; |
356 | use SDL::OpenGL; |
276 | |
357 | |
277 | sub size_request { |
358 | sub size_request { |
278 | my ($self) = @_; |
359 | my ($self) = @_; |
279 | my $chld = $self->get |
360 | my $chld = $self->child |
280 | or return (0, 0); |
361 | or return (0, 0); |
281 | |
362 | |
282 | $chld->move (2, 2); |
363 | $chld->move (2, 2); |
283 | |
364 | |
284 | map { $_ + 4 } $chld->size_request; |
365 | map { $_ + 4 } $chld->size_request; |
285 | } |
366 | } |
286 | |
367 | |
287 | sub size_allocate { |
368 | sub size_allocate { |
288 | my ($self, $w, $h) = @_; |
369 | my ($self, $w, $h) = @_; |
289 | |
370 | |
290 | $self->w ($w); |
371 | $self->{w} = $w; |
291 | $self->h ($h); |
372 | $self->{h} = $h; |
292 | |
373 | |
293 | $self->get->size_allocate ($w - 4, $h - 4); |
374 | $self->child->size_allocate ($w - 4, $h - 4); |
294 | $self->get->move (2, 2); |
375 | $self->child->move (2, 2); |
295 | } |
376 | } |
296 | |
377 | |
297 | sub _draw { |
378 | sub _draw { |
298 | my ($self) = @_; |
379 | my ($self) = @_; |
299 | |
380 | |
300 | my $chld = $self->get; |
381 | my $chld = $self->child; |
301 | |
382 | |
302 | my ($w, $h) = $chld->size_request; |
383 | my ($w, $h) = $chld->size_request; |
303 | |
384 | |
304 | glBegin GL_QUADS; |
385 | glBegin GL_QUADS; |
305 | glColor 0, 0, 0; |
386 | glColor 0, 0, 0; |
… | |
… | |
310 | glEnd; |
391 | glEnd; |
311 | |
392 | |
312 | $chld->draw; |
393 | $chld->draw; |
313 | } |
394 | } |
314 | |
395 | |
|
|
396 | ############################################################################# |
|
|
397 | |
315 | package Crossfire::Client::Widget::FancyFrame; |
398 | package Crossfire::Client::Widget::FancyFrame; |
316 | |
399 | |
317 | our @ISA = Crossfire::Client::Widget::Frame::; |
400 | our @ISA = Crossfire::Client::Widget::Bin::; |
318 | |
401 | |
319 | use SDL::OpenGL; |
402 | use SDL::OpenGL; |
320 | |
403 | |
321 | sub new { |
404 | my @tex = |
322 | my ($self, $theme) = @_; |
|
|
323 | $self = $self->SUPER::new; |
|
|
324 | |
|
|
325 | $self->{txts} = [ |
|
|
326 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
405 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
327 | qw/d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png/ |
406 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
328 | ]; |
|
|
329 | $self |
|
|
330 | } |
|
|
331 | |
407 | |
332 | sub size_request { |
408 | sub size_request { |
333 | my ($self) = @_; |
409 | my ($self) = @_; |
|
|
410 | |
334 | my ($w, $h) = $self->get->size_request; |
411 | my ($w, $h) = $self->SUPER::size_request; |
335 | |
412 | |
336 | $h += $self->{txts}->[1]->{height}; |
413 | $h += $tex[1]->{height}; |
337 | $h += $self->{txts}->[4]->{height}; |
414 | $h += $tex[4]->{height}; |
338 | $w += $self->{txts}->[2]->{width}; |
415 | $w += $tex[2]->{width}; |
339 | $w += $self->{txts}->[3]->{width}; |
416 | $w += $tex[3]->{width}; |
340 | |
417 | |
341 | ($w, $h) |
418 | ($w, $h) |
342 | } |
419 | } |
343 | |
420 | |
344 | sub size_allocate { |
421 | sub size_allocate { |
345 | my ($self, $w, $h) = @_; |
422 | my ($self, $w, $h) = @_; |
346 | |
423 | |
347 | $self->w ($w); |
424 | $self->SUPER::size_allocate ($w, $h); |
348 | $self->h ($h); |
425 | |
349 | $h -= $self->{txts}->[1]->{height}; |
426 | $h -= $tex[1]->{height}; |
350 | $h -= $self->{txts}->[4]->{height}; |
427 | $h -= $tex[4]->{height}; |
351 | $w -= $self->{txts}->[2]->{width}; |
428 | $w -= $tex[2]->{width}; |
352 | $w -= $self->{txts}->[3]->{width}; |
429 | $w -= $tex[3]->{width}; |
353 | |
430 | |
354 | $h = $h < 0 ? 0 : $h; |
431 | $h = $h < 0 ? 0 : $h; |
355 | $w = $w < 0 ? 0 : $w; |
432 | $w = $w < 0 ? 0 : $w; |
356 | warn "CHILD:$w $h\n"; |
433 | |
357 | $self->get->size_allocate ($w, $h); |
434 | $self->child->size_allocate ($w, $h); |
358 | $self->get->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
435 | $self->child->move ($tex[3]->{width}, $tex[1]->{height}); |
359 | } |
436 | } |
360 | |
437 | |
361 | sub _draw { |
438 | sub _draw { |
362 | my ($self) = @_; |
439 | my ($self) = @_; |
363 | |
440 | |
364 | my ($w, $h) = ($self->w, $self->h); |
441 | my ($w, $h) = ($self->{w}, $self->{h}); |
365 | my ($cw, $ch) = ($self->get->w, $self->get->h); |
442 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
366 | |
443 | |
367 | glEnable GL_BLEND; |
444 | glEnable GL_BLEND; |
368 | glEnable GL_TEXTURE_2D; |
445 | glEnable GL_TEXTURE_2D; |
369 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
446 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
370 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
447 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
371 | |
448 | |
372 | my $top = $self->{txts}->[1]; |
449 | my $top = $tex[1]; |
373 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
450 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
374 | |
451 | |
375 | glBegin GL_QUADS; |
452 | glBegin GL_QUADS; |
376 | glTexCoord 0, 0; glVertex 0 , 0; |
453 | glTexCoord 0, 0; glVertex 0 , 0; |
377 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
454 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
378 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
455 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
379 | glTexCoord 1, 0; glVertex $w , 0; |
456 | glTexCoord 1, 0; glVertex $w , 0; |
380 | glEnd; |
457 | glEnd; |
381 | |
458 | |
382 | my $left = $self->{txts}->[3]; |
459 | my $left = $tex[3]; |
383 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
460 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
384 | |
461 | |
385 | glBegin GL_QUADS; |
462 | glBegin GL_QUADS; |
386 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
463 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
387 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
464 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
388 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
465 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
389 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
466 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
390 | glEnd; |
467 | glEnd; |
391 | |
468 | |
392 | my $right = $self->{txts}->[2]; |
469 | my $right = $tex[2]; |
393 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
470 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
394 | |
471 | |
395 | glBegin GL_QUADS; |
472 | glBegin GL_QUADS; |
396 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
473 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
397 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
474 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
398 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
475 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
399 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
476 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
400 | glEnd; |
477 | glEnd; |
401 | |
478 | |
402 | my $bottom = $self->{txts}->[4]; |
479 | my $bottom = $tex[4]; |
403 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
480 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
404 | |
481 | |
405 | glBegin GL_QUADS; |
482 | glBegin GL_QUADS; |
406 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
483 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
407 | glTexCoord 0, 1; glVertex 0 , $h; |
484 | glTexCoord 0, 1; glVertex 0 , $h; |
408 | glTexCoord 1, 1; glVertex $w , $h; |
485 | glTexCoord 1, 1; glVertex $w , $h; |
409 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
486 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
410 | glEnd; |
487 | glEnd; |
411 | |
488 | |
412 | my $bg = $self->{txts}->[0]; |
489 | my $bg = $tex[0]; |
413 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
490 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
414 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
491 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
415 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
492 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
416 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
493 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
417 | |
494 | |
… | |
… | |
426 | glEnd; |
503 | glEnd; |
427 | |
504 | |
428 | glDisable GL_BLEND; |
505 | glDisable GL_BLEND; |
429 | glDisable GL_TEXTURE_2D; |
506 | glDisable GL_TEXTURE_2D; |
430 | |
507 | |
431 | $self->get->draw; |
508 | $self->child->draw; |
432 | |
509 | |
433 | } |
510 | } |
|
|
511 | |
|
|
512 | ############################################################################# |
434 | |
513 | |
435 | package Crossfire::Client::Widget::Table; |
514 | package Crossfire::Client::Widget::Table; |
436 | |
515 | |
437 | our @ISA = Crossfire::Client::Widget::Bin::; |
516 | our @ISA = Crossfire::Client::Widget::Bin::; |
438 | |
517 | |
439 | use SDL::OpenGL; |
518 | use SDL::OpenGL; |
440 | |
519 | |
441 | sub add { |
520 | sub add { |
442 | my ($self, $x, $y, $chld) = @_; |
521 | my ($self, $x, $y, $chld) = @_; |
443 | my $old_chld = $self->{childs}[$y][$x]; |
522 | my $old_chld = $self->{children}[$y][$x]; |
444 | |
523 | |
445 | $self->{childs}[$y][$x] = $chld; |
524 | $self->{children}[$y][$x] = $chld; |
446 | $chld->set_parent ($self); |
525 | $chld->set_parent ($self); |
447 | $self->update; |
526 | $self->update; |
448 | } |
527 | } |
449 | |
528 | |
450 | sub max_row_height { |
529 | sub max_row_height { |
451 | my ($self, $row) = @_; |
530 | my ($self, $row) = @_; |
452 | |
531 | |
453 | my $hs = 0; |
532 | my $hs = 0; |
454 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) { |
533 | for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) { |
455 | my $c = $self->{childs}->[$row]->[$xi]; |
534 | my $c = $self->{children}->[$row]->[$xi]; |
456 | if ($c) { |
535 | if ($c) { |
457 | my ($w, $h) = $c->size_request; |
536 | my ($w, $h) = $c->size_request; |
458 | if ($hs < $h) { $hs = $h } |
537 | if ($hs < $h) { $hs = $h } |
459 | } |
538 | } |
460 | } |
539 | } |
… | |
… | |
463 | |
542 | |
464 | sub max_col_width { |
543 | sub max_col_width { |
465 | my ($self, $col) = @_; |
544 | my ($self, $col) = @_; |
466 | |
545 | |
467 | my $ws = 0; |
546 | my $ws = 0; |
468 | for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) { |
547 | for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) { |
469 | my $c = ($self->{childs}->[$yi] || [])->[$col]; |
548 | my $c = ($self->{children}->[$yi] || [])->[$col]; |
470 | if ($c) { |
549 | if ($c) { |
471 | my ($w, $h) = $c->size_request; |
550 | my ($w, $h) = $c->size_request; |
472 | if ($ws < $w) { $ws = $w } |
551 | if ($ws < $w) { $ws = $w } |
473 | } |
552 | } |
474 | } |
553 | } |
… | |
… | |
478 | sub size_request { |
557 | sub size_request { |
479 | my ($self) = @_; |
558 | my ($self) = @_; |
480 | |
559 | |
481 | my ($hs, $ws) = (0, 0); |
560 | my ($hs, $ws) = (0, 0); |
482 | |
561 | |
483 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
562 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
484 | $hs += $self->max_row_height ($yi); |
563 | $hs += $self->max_row_height ($yi); |
485 | } |
564 | } |
486 | |
565 | |
487 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
566 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
488 | my $wm = 0; |
567 | my $wm = 0; |
489 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { |
568 | for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { |
490 | $wm += $self->max_col_width ($xi) |
569 | $wm += $self->max_col_width ($xi) |
491 | } |
570 | } |
492 | if ($ws < $wm) { $ws = $wm } |
571 | if ($ws < $wm) { $ws = $wm } |
493 | } |
572 | } |
494 | |
573 | |
… | |
… | |
497 | |
576 | |
498 | sub _draw { |
577 | sub _draw { |
499 | my ($self) = @_; |
578 | my ($self) = @_; |
500 | |
579 | |
501 | my $y = 0; |
580 | my $y = 0; |
502 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
581 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
503 | my $x = 0; |
582 | my $x = 0; |
504 | |
583 | |
505 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { |
584 | for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { |
506 | |
585 | |
507 | my $c = $self->{childs}->[$yi]->[$xi]; |
586 | my $c = $self->{children}->[$yi]->[$xi]; |
508 | if ($c) { |
587 | if ($c) { |
509 | $c->move ($x, $y, 0); #TODO: Move to size_request |
588 | $c->move ($x, $y, 0); #TODO: Move to size_request |
510 | $c->draw if $c; |
589 | $c->draw if $c; |
511 | } |
590 | } |
512 | |
591 | |
… | |
… | |
515 | |
594 | |
516 | $y += $self->max_row_height ($yi); |
595 | $y += $self->max_row_height ($yi); |
517 | } |
596 | } |
518 | } |
597 | } |
519 | |
598 | |
|
|
599 | ############################################################################# |
|
|
600 | |
520 | package Crossfire::Client::Widget::VBox; |
601 | package Crossfire::Client::Widget::VBox; |
521 | |
602 | |
522 | our @ISA = Crossfire::Client::Widget::Bin::; |
603 | our @ISA = Crossfire::Client::Widget::Container::; |
523 | |
604 | |
524 | use SDL::OpenGL; |
605 | use SDL::OpenGL; |
525 | |
606 | |
526 | sub add { |
|
|
527 | my ($self, $chld, $expand) = @_; |
|
|
528 | push @{$self->{childs}}, $chld; |
|
|
529 | $chld->{expand} = $expand; |
|
|
530 | $chld->set_parent ($self); |
|
|
531 | $self->update; |
|
|
532 | } |
|
|
533 | |
|
|
534 | sub size_request { |
607 | sub size_request { |
535 | my ($self) = @_; |
608 | my ($self) = @_; |
536 | |
609 | |
537 | my ($hs, $ws) = (0, 0); |
610 | my @alloc = map [$_->size_request], @{$self->{children}}; |
538 | for (@{$self->{childs} || []}) { |
611 | |
539 | my ($w, $h) = $_->size_request; |
|
|
540 | $hs += $h; |
|
|
541 | if ($ws < $w) { $ws = $w } |
|
|
542 | } |
612 | ( |
543 | |
613 | (List::Util::max map $_->[0], @alloc), |
544 | return ($ws, $hs); |
614 | (List::Util::sum map $_->[1], @alloc), |
|
|
615 | ) |
545 | } |
616 | } |
546 | |
617 | |
547 | sub size_allocate { |
618 | sub size_allocate { |
548 | my ($self, $w, $h) = @_; |
619 | my ($self, $w, $h) = @_; |
549 | |
620 | |
… | |
… | |
551 | $self->h ($h); |
622 | $self->h ($h); |
552 | |
623 | |
553 | my $exp; |
624 | my $exp; |
554 | my @oth; |
625 | my @oth; |
555 | # find expand widget |
626 | # find expand widget |
556 | for (@{$self->{childs}}) { |
627 | for (@{$self->{children}}) { |
557 | if ($_->{expand}) { |
628 | if ($_->{expand}) { |
558 | $exp = $_; |
629 | $exp = $_; |
559 | last; |
630 | last; |
560 | } |
631 | } |
561 | push @oth, $_; |
632 | push @oth, $_; |
… | |
… | |
569 | $oh += $h; |
640 | $oh += $h; |
570 | if ($ow < $w) { $ow = $w } |
641 | if ($ow < $w) { $ow = $w } |
571 | } |
642 | } |
572 | |
643 | |
573 | my $y = 0; |
644 | my $y = 0; |
574 | for (@{$self->{childs}}) { |
645 | for (@{$self->{children}}) { |
575 | $_->move (0, $y); |
646 | $_->move (0, $y); |
576 | |
647 | |
577 | if ($_ == $exp) { |
648 | if ($_ == $exp) { |
578 | $_->size_allocate ($w, $h - $oh); |
649 | $_->size_allocate ($w, $h - $oh); |
579 | $y += $h - $oh; |
650 | $y += $h - $oh; |
… | |
… | |
583 | $y += $h; |
654 | $y += $h; |
584 | } |
655 | } |
585 | } |
656 | } |
586 | } |
657 | } |
587 | |
658 | |
588 | sub _draw { |
659 | ############################################################################# |
589 | my ($self) = @_; |
|
|
590 | |
|
|
591 | my ($x, $y); |
|
|
592 | for (@{$self->{childs} || []}) { |
|
|
593 | $_->draw; |
|
|
594 | $y += $_->h; |
|
|
595 | } |
|
|
596 | } |
|
|
597 | |
660 | |
598 | package Crossfire::Client::Widget::Label; |
661 | package Crossfire::Client::Widget::Label; |
599 | |
662 | |
600 | our @ISA = Crossfire::Client::Widget::; |
663 | our @ISA = Crossfire::Client::Widget::; |
601 | |
664 | |
602 | use SDL::OpenGL; |
665 | use SDL::OpenGL; |
603 | |
666 | |
604 | sub new { |
667 | sub new { |
605 | my ($class, $x, $y, $z, $height, $text) = @_; |
668 | my ($class, $x, $y, $z, $height, $text) = @_; |
606 | |
669 | |
|
|
670 | $height ||= $::FONTSIZE; |
|
|
671 | |
607 | # TODO: color, and make height, xyz etc. optional |
672 | # TODO: color, and make height, xyz etc. optional |
608 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
673 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
609 | |
674 | |
610 | $self->set_text ($text); |
675 | $self->set_text ($text); |
611 | |
676 | |
… | |
… | |
628 | } |
693 | } |
629 | |
694 | |
630 | sub size_request { |
695 | sub size_request { |
631 | my ($self) = @_; |
696 | my ($self) = @_; |
632 | |
697 | |
633 | ( |
698 | if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
|
|
699 | ( |
634 | $self->{texture}{width}, |
700 | $self->{texture}{width}, |
635 | $self->{texture}{height}, |
701 | $self->{texture}{height}, |
|
|
702 | ) |
|
|
703 | } else { |
|
|
704 | my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; |
|
|
705 | |
|
|
706 | ($w, $h) |
636 | ) |
707 | } |
|
|
708 | |
637 | } |
709 | } |
638 | |
710 | |
639 | sub _draw { |
711 | sub _draw { |
640 | my ($self) = @_; |
712 | my ($self) = @_; |
641 | |
713 | |
… | |
… | |
658 | |
730 | |
659 | glDisable GL_BLEND; |
731 | glDisable GL_BLEND; |
660 | glDisable GL_TEXTURE_2D; |
732 | glDisable GL_TEXTURE_2D; |
661 | } |
733 | } |
662 | |
734 | |
|
|
735 | ############################################################################# |
|
|
736 | |
663 | package Crossfire::Client::Widget::TextEntry; |
737 | package Crossfire::Client::Widget::Entry; |
664 | |
738 | |
665 | our @ISA = Crossfire::Client::Widget::Label::; |
739 | our @ISA = Crossfire::Client::Widget::Label::; |
666 | |
740 | |
667 | use SDL; |
741 | use SDL; |
668 | use SDL::OpenGL; |
742 | use SDL::OpenGL; |
… | |
… | |
671 | my ($self, $ev) = @_; |
745 | my ($self, $ev) = @_; |
672 | |
746 | |
673 | my $mod = $ev->key_mod; |
747 | my $mod = $ev->key_mod; |
674 | my $sym = $ev->key_sym; |
748 | my $sym = $ev->key_sym; |
675 | |
749 | |
676 | $ev->set_unicode (1); |
|
|
677 | my $uni = $ev->key_unicode; |
750 | my $uni = $ev->key_unicode; |
678 | |
751 | |
679 | my $text = $self->get_text; |
752 | my $text = $self->get_text; |
680 | |
753 | |
681 | if ($sym == SDLK_BACKSPACE) { |
754 | if ($sym == SDLK_BACKSPACE) { |
682 | substr $text, -1, 1, ''; |
755 | substr $text, -1, 1, ''; |
683 | |
|
|
684 | } elsif ($uni) { |
756 | } elsif ($uni) { |
685 | $text .= chr $uni; |
757 | $text .= chr $uni; |
|
|
758 | print "$uni <$text>\n";#d# |
686 | } |
759 | } |
|
|
760 | |
687 | $self->set_text ($text); |
761 | $self->set_text ($text); |
688 | } |
762 | } |
|
|
763 | |
|
|
764 | sub button_down { |
|
|
765 | my ($self, $ev) = @_; |
|
|
766 | |
|
|
767 | $self->focus_in; |
|
|
768 | } |
|
|
769 | |
|
|
770 | sub _draw { |
|
|
771 | my ($self) = @_; |
|
|
772 | |
|
|
773 | if ($FOCUS == $self) { |
|
|
774 | glColor 1, 1, 1; |
|
|
775 | } else { |
|
|
776 | glColor 0.7, 0.7, 0.7; |
|
|
777 | } |
|
|
778 | |
|
|
779 | glBegin GL_QUADS; |
|
|
780 | glVertex 0 , 0; |
|
|
781 | glVertex 0 , $self->{h} - 1; |
|
|
782 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
783 | glVertex $self->{w} - 1, 0; |
|
|
784 | glEnd; |
|
|
785 | |
|
|
786 | $self->SUPER::_draw; |
|
|
787 | } |
|
|
788 | |
|
|
789 | ############################################################################# |
689 | |
790 | |
690 | package Crossfire::Client::Widget::MapWidget; |
791 | package Crossfire::Client::Widget::MapWidget; |
691 | |
792 | |
692 | use strict; |
793 | use strict; |
693 | |
794 | |
… | |
… | |
705 | |
806 | |
706 | sub key_up { |
807 | sub key_up { |
707 | } |
808 | } |
708 | |
809 | |
709 | sub size_request { |
810 | sub size_request { |
710 | |
811 | ( |
711 | } |
812 | 1 + int $::WIDTH / 32, |
712 | |
813 | 1 + int $::HEIGHT / 32, |
713 | sub size_allocate { |
814 | ) |
714 | } |
815 | } |
715 | |
816 | |
716 | sub _draw { |
817 | sub _draw { |
717 | my ($self) = @_; |
818 | my ($self) = @_; |
718 | |
819 | |
… | |
… | |
751 | my $cell = $map->[$x + $xofs][$y + $yofs] |
852 | my $cell = $map->[$x + $xofs][$y + $yofs] |
752 | or next; |
853 | or next; |
753 | |
854 | |
754 | my $darkness = $cell->[0] * (1 / 255); |
855 | my $darkness = $cell->[0] * (1 / 255); |
755 | if ($darkness < 0) { |
856 | if ($darkness < 0) { |
756 | $darkness = 0.15; |
857 | $darkness = $cell->[1] ? 0.2 : 0; |
757 | } |
858 | } |
758 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
859 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
759 | |
860 | |
760 | for my $num (grep $_, @$cell[1,2,3]) { |
861 | for my $num (grep $_, @$cell[1,2,3]) { |
761 | my $tex = $::CONN->{face}[$num]{texture} || next; |
862 | my $tex = $::CONN->{face}[$num]{texture} || next; |
… | |
… | |
790 | |
891 | |
791 | $lighting = new Crossfire::Client::Texture |
892 | $lighting = new Crossfire::Client::Texture |
792 | width => $sw4, |
893 | width => $sw4, |
793 | height => $sh, |
894 | height => $sh, |
794 | data => $lighting, |
895 | data => $lighting, |
795 | internalformat => GL_ALPHA4, |
896 | internalformat => GL_ALPHA, |
796 | format => GL_ALPHA; |
897 | format => GL_ALPHA; |
797 | |
898 | |
798 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
899 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
799 | glColor 0, 0, 0, 0.75; |
900 | glColor 0.5, 0.5, 0.5, 1; |
800 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
901 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
801 | glBindTexture GL_TEXTURE_2D, $lighting->{name}; |
902 | glBindTexture GL_TEXTURE_2D, $lighting->{name}; |
802 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
903 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
803 | glBegin GL_QUADS; |
904 | glBegin GL_QUADS; |
804 | glTexCoord 0, 0; glVertex 0 , 0; |
905 | glTexCoord 0, 0; glVertex 0 , 0; |
… | |
… | |
860 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
961 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
861 | $::CONN->send ("command run_stop"); |
962 | $::CONN->send ("command run_stop"); |
862 | } |
963 | } |
863 | } |
964 | } |
864 | |
965 | |
|
|
966 | ############################################################################# |
|
|
967 | |
865 | package Crossfire::Client::Widget::Animator; |
968 | package Crossfire::Client::Widget::Animator; |
866 | |
969 | |
867 | use SDL::OpenGL; |
970 | use SDL::OpenGL; |
868 | |
971 | |
869 | our @ISA = Crossfire::Client::Widget::Bin::; |
972 | our @ISA = Crossfire::Client::Widget::Bin::; |
870 | |
973 | |
871 | sub moveto { |
974 | sub moveto { |
872 | my ($self, $x, $y) = @_; |
975 | my ($self, $x, $y) = @_; |
873 | |
976 | |
874 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
977 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
875 | $self->{speed} = 0.2; |
978 | $self->{speed} = 2; |
876 | $self->{time} = 1; |
979 | $self->{time} = 1; |
877 | |
980 | |
878 | ::animation_start $self; |
981 | ::animation_start $self; |
879 | } |
982 | } |
880 | |
983 | |
… | |
… | |
895 | |
998 | |
896 | sub _draw { |
999 | sub _draw { |
897 | my ($self) = @_; |
1000 | my ($self) = @_; |
898 | |
1001 | |
899 | glPushMatrix; |
1002 | glPushMatrix; |
900 | glRotate $self->{time} * 10000, 0, 1, 0; |
1003 | glRotate $self->{time} * 1000, 0, 1, 0; |
901 | $self->{child}->draw; |
1004 | $self->{children}[0]->draw; |
902 | glPopMatrix; |
1005 | glPopMatrix; |
903 | } |
1006 | } |
904 | |
1007 | |
905 | 1; |
1008 | ############################################################################# |
906 | |
1009 | |
|
|
1010 | package Crossfire::Client::Widget::Toplevel; |
|
|
1011 | |
|
|
1012 | our @ISA = Crossfire::Client::Widget::Container::; |
|
|
1013 | |
|
|
1014 | sub size_request { |
|
|
1015 | ($::WIDTH, $::HEIGHT) |
|
|
1016 | } |
|
|
1017 | |
|
|
1018 | sub size_allocate { |
|
|
1019 | my ($self, $w, $h) = @_; |
|
|
1020 | |
|
|
1021 | $self->SUPER::size_allocate ($w, $h); |
|
|
1022 | |
|
|
1023 | $_->size_allocate ($_->size_request) |
|
|
1024 | for @{$self->{children}}; |
|
|
1025 | } |
|
|
1026 | |
|
|
1027 | sub update { |
|
|
1028 | my ($self) = @_; |
|
|
1029 | |
|
|
1030 | $self->size_allocate ($self->size_request); |
|
|
1031 | ::refresh (); |
|
|
1032 | } |
|
|
1033 | |
|
|
1034 | sub add { |
|
|
1035 | my ($self, $widget) = @_; |
|
|
1036 | |
|
|
1037 | $self->SUPER::add ($widget); |
|
|
1038 | |
|
|
1039 | $widget->size_allocate ($widget->size_request); |
|
|
1040 | } |
|
|
1041 | |
|
|
1042 | sub draw { |
|
|
1043 | my ($self) = @_; |
|
|
1044 | |
|
|
1045 | $self->_draw; |
|
|
1046 | } |
|
|
1047 | |
|
|
1048 | ############################################################################# |
|
|
1049 | |
|
|
1050 | package Crossfire::Client::Widget; |
|
|
1051 | |
|
|
1052 | $TOPLEVEL = new Crossfire::Client::Widget::Toplevel; |
|
|
1053 | |
|
|
1054 | 1 |
|
|
1055 | |