1 | package Crossfire::Client::Widget; |
1 | package CFClient::Widget; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
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 | use Crossfire::Client; |
10 | use CFClient; |
11 | |
11 | |
12 | our $FOCUS; # the widget with current focus |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
|
|
13 | |
|
|
14 | our $TOPLEVEL; |
|
|
15 | our $BUTTON_STATE; |
13 | |
16 | |
14 | # class methods for events |
17 | # class methods for events |
15 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
18 | sub feed_sdl_key_down_event { |
16 | 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 | |
17 | 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, $GRAB->translate ($x, $y)) if $GRAB; |
|
|
40 | } |
|
|
41 | |
18 | 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 | $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; |
|
|
51 | |
|
|
52 | if (!$BUTTON_STATE) { |
|
|
53 | my $grab = $GRAB; undef $GRAB; |
|
|
54 | $grab->update if $grab; |
|
|
55 | $GRAB->update if $GRAB; |
|
|
56 | } |
|
|
57 | } |
|
|
58 | |
|
|
59 | sub feed_sdl_motion_event { |
|
|
60 | my ($ev) = @_; |
|
|
61 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
62 | |
|
|
63 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
|
|
64 | |
|
|
65 | if ($widget != $HOVER) { |
|
|
66 | my $hover = $HOVER; $HOVER = $widget; |
|
|
67 | |
|
|
68 | $hover->update if $hover; |
|
|
69 | $HOVER->update if $HOVER; |
|
|
70 | } |
|
|
71 | |
|
|
72 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
|
|
73 | } |
19 | |
74 | |
20 | sub new { |
75 | sub new { |
21 | my $class = shift; |
76 | my $class = shift; |
22 | |
77 | |
23 | bless { @_ }, $class |
78 | bless { |
|
|
79 | x => 0, |
|
|
80 | y => 0, |
|
|
81 | z => 0, |
|
|
82 | @_ |
|
|
83 | }, $class |
24 | } |
84 | } |
25 | |
85 | |
26 | sub move { |
86 | sub move { |
27 | my ($self, $x, $y, $z) = @_; |
87 | my ($self, $x, $y, $z) = @_; |
28 | $self->{x} = $x; |
88 | $self->{x} = $x; |
… | |
… | |
44 | |
104 | |
45 | $self->{w} = $w; |
105 | $self->{w} = $w; |
46 | $self->{h} = $h; |
106 | $self->{h} = $h; |
47 | } |
107 | } |
48 | |
108 | |
|
|
109 | # translate global koordinates to local coordinate system |
|
|
110 | sub translate { |
|
|
111 | my ($self, $x, $y) = @_; |
|
|
112 | |
|
|
113 | $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); |
|
|
114 | } |
|
|
115 | |
49 | sub focus_in { |
116 | sub focus_in { |
50 | my ($widget) = @_; |
117 | my ($self) = @_; |
51 | $FOCUS = $widget; |
118 | |
|
|
119 | my $focus = $FOCUS; $FOCUS = $self; |
|
|
120 | $focus->update if $focus; |
|
|
121 | $FOCUS->update; |
52 | } |
122 | } |
53 | |
123 | |
54 | sub focus_out { |
124 | sub focus_out { |
55 | my ($widget) = @_; |
125 | my ($self) = @_; |
56 | } |
|
|
57 | |
126 | |
58 | sub key_down { |
127 | return unless $FOCUS == $self; |
59 | my ($widget, $sdlev) = @_; |
|
|
60 | } |
|
|
61 | |
128 | |
62 | sub key_up { |
129 | my $focus = $FOCUS; undef $FOCUS; |
63 | my ($widget, $sdlev) = @_; |
130 | $focus->update if $focus; #? |
64 | } |
131 | } |
65 | |
132 | |
|
|
133 | sub mouse_motion { } |
|
|
134 | sub button_up { } |
66 | sub button_down { |
135 | sub button_down { } |
67 | my ($widget, $sdlev) = @_; |
136 | sub key_down { } |
68 | } |
137 | sub key_up { } |
69 | |
138 | |
70 | sub button_up { |
|
|
71 | my ($widget, $sdlev) = @_; |
|
|
72 | } |
|
|
73 | |
|
|
74 | sub w { $_[0]->{w} = $_[1] if $_[1]; $_[0]->{w} } |
139 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
75 | sub h { $_[0]->{h} = $_[1] if $_[1]; $_[0]->{h} } |
140 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
76 | sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } |
141 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
77 | sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } |
142 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
78 | sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} } |
143 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
79 | |
144 | |
80 | sub draw { |
145 | sub draw { |
81 | my ($self) = @_; |
146 | my ($self) = @_; |
82 | |
147 | |
83 | glPushMatrix; |
148 | glPushMatrix; |
84 | glTranslate $self->{x}, $self->{y}, 0; |
149 | glTranslate $self->{x}, $self->{y}, 0; |
85 | $self->_draw; |
150 | $self->_draw; |
|
|
151 | if ($self == $HOVER) { |
|
|
152 | glColor 1, 1, 1, 0.4; |
|
|
153 | glEnable GL_BLEND; |
|
|
154 | glBegin GL_QUADS; |
|
|
155 | glVertex 0 , 0; |
|
|
156 | glVertex $self->{w}, 0; |
|
|
157 | glVertex $self->{w}, $self->{h}; |
|
|
158 | glVertex 0 , $self->{h}; |
|
|
159 | glEnd; |
|
|
160 | glDisable GL_BLEND; |
|
|
161 | } |
86 | glPopMatrix; |
162 | glPopMatrix; |
87 | } |
163 | } |
88 | |
164 | |
89 | sub _draw { |
165 | sub _draw { |
90 | my ($self) = @_; |
166 | my ($self) = @_; |
… | |
… | |
139 | #$self->deactivate; |
215 | #$self->deactivate; |
140 | } |
216 | } |
141 | |
217 | |
142 | ############################################################################# |
218 | ############################################################################# |
143 | |
219 | |
|
|
220 | package CFClient::Widget::Empty; |
|
|
221 | |
|
|
222 | our @ISA = CFClient::Widget::; |
|
|
223 | |
|
|
224 | sub size_request { |
|
|
225 | (0, 0) |
|
|
226 | } |
|
|
227 | |
|
|
228 | sub draw { |
|
|
229 | } |
|
|
230 | |
|
|
231 | ############################################################################# |
|
|
232 | |
144 | package Crossfire::Client::Widget::Container; |
233 | package CFClient::Widget::Container; |
145 | |
234 | |
146 | our @ISA = Crossfire::Client::Widget::; |
235 | our @ISA = CFClient::Widget::; |
147 | |
236 | |
148 | sub new { |
237 | sub new { |
149 | my ($class, @widgets) = @_; |
238 | my ($class, %arg) = @_; |
150 | |
239 | |
|
|
240 | my $children = delete $arg{children} || []; |
|
|
241 | |
151 | my $self = $class->SUPER::new (children => []); |
242 | my $self = $class->SUPER::new (children => [], %arg); |
152 | $self->add ($_) for @widgets; |
243 | $self->add ($_) for @$children; |
153 | |
244 | |
154 | $self |
245 | $self |
155 | } |
246 | } |
156 | |
247 | |
157 | sub add { |
248 | sub add { |
158 | my ($self, $chld, $expand) = @_; |
249 | my ($self, $chld, $expand) = @_; |
159 | |
250 | |
160 | $chld->{expand} = $expand; |
251 | $chld->{expand} = $expand; |
161 | $chld->set_parent ($self); |
252 | $chld->set_parent ($self); |
162 | |
253 | |
163 | @{$self->{children}} = |
254 | $self->{children} = [ |
164 | sort { $a->{z} <=> $b->{z} } |
255 | sort { $a->{z} <=> $b->{z} } |
165 | @{$self->{children}}, $chld; |
256 | @{$self->{children}}, $chld |
|
|
257 | ]; |
166 | |
258 | |
167 | $self->size_allocate ($self->{w}, $self->{h}); |
259 | $self->size_allocate ($self->{w}, $self->{h}) |
|
|
260 | if $self->{w}; #TODO: check for "realised state" |
168 | } |
261 | } |
169 | |
262 | |
170 | sub remove { |
263 | sub remove { |
171 | my ($self, $widget) = @_; |
264 | my ($self, $widget) = @_; |
172 | |
265 | |
… | |
… | |
176 | } |
269 | } |
177 | |
270 | |
178 | sub find_widget { |
271 | sub find_widget { |
179 | my ($self, $x, $y) = @_; |
272 | my ($self, $x, $y) = @_; |
180 | |
273 | |
|
|
274 | $x -= $self->{x}; |
|
|
275 | $y -= $self->{y}; |
|
|
276 | |
181 | my $res; |
277 | my $res; |
182 | |
278 | |
183 | for (@{ $self->{children} }) { |
279 | for (reverse @{ $self->{children} }) { |
184 | $res = $_->find_widget ($x, $y) |
280 | $res = $_->find_widget ($x, $y) |
185 | and return $res; |
281 | and return $res; |
186 | } |
282 | } |
187 | |
283 | |
188 | () |
284 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
189 | } |
|
|
190 | |
|
|
191 | sub size_request { |
|
|
192 | my ($self) = @_; |
|
|
193 | |
|
|
194 | my ($hs, $ws) = (0, 0); |
|
|
195 | for (@{$self->{children} || []}) { |
|
|
196 | my ($w, $h) = $_->size_request; |
|
|
197 | $hs += $h; |
|
|
198 | if ($ws < $w) { $ws = $w } |
|
|
199 | } |
|
|
200 | |
|
|
201 | return ($ws, $hs); |
|
|
202 | } |
285 | } |
203 | |
286 | |
204 | sub _draw { |
287 | sub _draw { |
205 | my ($self) = @_; |
288 | my ($self) = @_; |
206 | |
289 | |
207 | $_->draw for @{$self->{children}}; |
290 | $_->draw for @{$self->{children}}; |
208 | } |
291 | } |
209 | |
292 | |
210 | ############################################################################# |
293 | ############################################################################# |
211 | |
294 | |
212 | package Crossfire::Client::Widget::Bin; |
295 | package CFClient::Widget::Bin; |
213 | |
296 | |
214 | our @ISA = Crossfire::Client::Widget::Container::; |
297 | our @ISA = CFClient::Widget::Container::; |
|
|
298 | |
|
|
299 | sub new { |
|
|
300 | my ($class, %arg) = @_; |
|
|
301 | |
|
|
302 | my $child = (delete $arg{child}) || new CFClient::Widget::Empty::; |
|
|
303 | |
|
|
304 | $class->SUPER::new (children => [$child], %arg) |
|
|
305 | } |
|
|
306 | |
|
|
307 | sub add { |
|
|
308 | my ($self, $widget) = @_; |
|
|
309 | |
|
|
310 | $self->{children} = []; |
|
|
311 | |
|
|
312 | $self->SUPER::add ($widget); |
|
|
313 | } |
|
|
314 | |
|
|
315 | sub remove { |
|
|
316 | my ($self, $widget) = @_; |
|
|
317 | |
|
|
318 | $self->SUPER::remove ($widget); |
|
|
319 | |
|
|
320 | $self->{children} = [new CFClient::Widget::Empty] |
|
|
321 | unless @{$self->{children}}; |
|
|
322 | } |
215 | |
323 | |
216 | sub child { $_[0]->{children}[0] } |
324 | sub child { $_[0]->{children}[0] } |
217 | |
325 | |
218 | sub size_request { |
326 | sub size_request { |
219 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
327 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
220 | } |
328 | } |
221 | |
329 | |
222 | sub size_allocate { |
330 | sub size_allocate { |
223 | my ($self, $w, $h) = @_; |
331 | my ($self, $w, $h) = @_; |
|
|
332 | |
224 | $self->SUPER::size_allocate ($w, $h); |
333 | $self->SUPER::size_allocate ($w, $h); |
225 | $self->{children}[0]->size_allocate ($w, $h) |
334 | $self->{children}[0]->size_allocate ($w, $h) |
226 | if $self->{children}[0] |
335 | if $self->{children}[0] |
227 | } |
336 | } |
228 | |
337 | |
229 | ############################################################################# |
338 | ############################################################################# |
230 | |
339 | |
231 | package Crossfire::Client::Widget::Toplevel; |
340 | package CFClient::Widget::Window; |
232 | |
341 | |
233 | our @ISA = Crossfire::Client::Widget::Container::; |
342 | our @ISA = CFClient::Widget::Bin::; |
|
|
343 | |
|
|
344 | use SDL::OpenGL; |
|
|
345 | |
|
|
346 | sub new { |
|
|
347 | my ($class, %arg) = @_; |
|
|
348 | |
|
|
349 | my $self = $class->SUPER::new (%arg); |
|
|
350 | } |
234 | |
351 | |
235 | sub update { |
352 | sub update { |
236 | my ($self) = @_; |
353 | my ($self) = @_; |
237 | |
354 | |
238 | ::refresh (); |
355 | # we want to do this delayed... |
239 | } |
|
|
240 | |
|
|
241 | ############################################################################# |
|
|
242 | |
|
|
243 | package Crossfire::Client::Widget::Window; |
|
|
244 | |
|
|
245 | our @ISA = Crossfire::Client::Widget::Bin::; |
|
|
246 | |
|
|
247 | use SDL::OpenGL; |
|
|
248 | |
|
|
249 | sub add { |
|
|
250 | my ($self, $chld) = @_; |
|
|
251 | warn "ADD $chld\n"; |
|
|
252 | $self->SUPER::add ($chld); |
|
|
253 | $chld->set_parent ($self); |
|
|
254 | } |
|
|
255 | |
|
|
256 | sub remove { |
|
|
257 | my ($self) = @_; |
|
|
258 | # TODO FIXME: removing a child from a window will crash, see render_chld |
|
|
259 | # $self->update; |
|
|
260 | } |
|
|
261 | |
|
|
262 | sub update { |
|
|
263 | my ($self) = @_; |
|
|
264 | $self->render_chld; |
356 | $self->render_chld; |
|
|
357 | $self->SUPER::update; |
265 | } |
358 | } |
266 | |
359 | |
267 | sub render_chld { |
360 | sub render_chld { |
268 | my ($self) = @_; |
361 | my ($self) = @_; |
269 | my $chld = $self->get; |
|
|
270 | my ($w, $h) = $self->size_request; |
|
|
271 | |
362 | |
272 | require Carp; |
|
|
273 | Carp::cluck "RENDERCHI $w $h"; |
|
|
274 | warn "RENDERCHI $w $h\n"; |
|
|
275 | $self->{texture} = |
363 | $self->{texture} = |
276 | Crossfire::Client::Texture->new_from_opengl ( |
364 | CFClient::Texture->new_from_opengl ( |
277 | $w, $h, sub { $chld->draw } |
365 | $self->{w}, $self->{h}, sub { $self->child->draw } |
278 | ); |
366 | ); |
279 | $self->{texture}->upload; |
|
|
280 | } |
|
|
281 | |
|
|
282 | sub size_request { |
|
|
283 | my ($self) = @_; |
|
|
284 | ($self->w, $self->h) |
|
|
285 | } |
367 | } |
286 | |
368 | |
287 | sub size_allocate { |
369 | sub size_allocate { |
288 | my ($self, $w, $h) = @_; |
370 | my ($self, $w, $h) = @_; |
289 | |
371 | |
290 | $self->w ($w); |
372 | $self->{w} = $w; |
291 | $self->h ($h); |
373 | $self->{h} = $h; |
|
|
374 | |
292 | $self->get->size_allocate ($w, $h); |
375 | $self->child->size_allocate ($w, $h); |
293 | |
376 | |
294 | $self->update; #TODO: Move this to the size_request event propably? |
377 | $self->render_chld; |
295 | } |
378 | } |
296 | |
379 | |
297 | sub _draw { |
380 | sub _draw { |
298 | my ($self) = @_; |
381 | my ($self) = @_; |
299 | |
382 | |
… | |
… | |
303 | or return; |
386 | or return; |
304 | |
387 | |
305 | glEnable GL_BLEND; |
388 | glEnable GL_BLEND; |
306 | glEnable GL_TEXTURE_2D; |
389 | glEnable GL_TEXTURE_2D; |
307 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
390 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
308 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
309 | |
391 | |
310 | glBegin GL_QUADS; |
392 | $tex->draw_quad (0, 0, $w, $h); |
311 | glTexCoord 0, 0; glVertex 0, 0; |
|
|
312 | glTexCoord 0, 1; glVertex 0, $h; |
|
|
313 | glTexCoord 1, 1; glVertex $w, $h; |
|
|
314 | glTexCoord 1, 0; glVertex $w, 0; |
|
|
315 | glEnd; |
|
|
316 | |
393 | |
317 | glDisable GL_BLEND; |
394 | glDisable GL_BLEND; |
318 | glDisable GL_TEXTURE_2D; |
395 | glDisable GL_TEXTURE_2D; |
319 | } |
396 | } |
320 | |
397 | |
321 | ############################################################################# |
398 | ############################################################################# |
322 | |
399 | |
323 | package Crossfire::Client::Widget::Frame; |
400 | package CFClient::Widget::Frame; |
324 | |
401 | |
325 | our @ISA = Crossfire::Client::Widget::Bin::; |
402 | our @ISA = CFClient::Widget::Bin::; |
326 | |
403 | |
327 | use SDL::OpenGL; |
404 | use SDL::OpenGL; |
328 | |
405 | |
329 | sub size_request { |
406 | sub size_request { |
330 | my ($self) = @_; |
407 | my ($self) = @_; |
… | |
… | |
336 | map { $_ + 4 } $chld->size_request; |
413 | map { $_ + 4 } $chld->size_request; |
337 | } |
414 | } |
338 | |
415 | |
339 | sub size_allocate { |
416 | sub size_allocate { |
340 | my ($self, $w, $h) = @_; |
417 | my ($self, $w, $h) = @_; |
341 | |
418 | |
342 | $self->SUPER::size_allocate ($w, $h); |
419 | $self->{w} = $w; |
|
|
420 | $self->{h} = $h; |
343 | |
421 | |
344 | $self->child->size_allocate ($w - 4, $h - 4); |
422 | $self->child->size_allocate ($w - 4, $h - 4); |
345 | $self->child->move (2, 2); |
423 | $self->child->move (2, 2); |
346 | } |
424 | } |
347 | |
425 | |
… | |
… | |
352 | |
430 | |
353 | my ($w, $h) = $chld->size_request; |
431 | my ($w, $h) = $chld->size_request; |
354 | |
432 | |
355 | glBegin GL_QUADS; |
433 | glBegin GL_QUADS; |
356 | glColor 0, 0, 0; |
434 | glColor 0, 0, 0; |
357 | glTexCoord 0, 0; glVertex 0 , 0; |
435 | glVertex 0 , 0; |
358 | glTexCoord 0, 1; glVertex 0 , $h + 4; |
436 | glVertex 0 , $h + 4; |
359 | glTexCoord 1, 1; glVertex $w + 4 , $h + 4; |
437 | glVertex $w + 4 , $h + 4; |
360 | glTexCoord 1, 0; glVertex $w + 4 , 0; |
438 | glVertex $w + 4 , 0; |
361 | glEnd; |
439 | glEnd; |
362 | |
440 | |
363 | $chld->draw; |
441 | $chld->draw; |
364 | } |
442 | } |
365 | |
443 | |
366 | ############################################################################# |
444 | ############################################################################# |
367 | |
445 | |
368 | package Crossfire::Client::Widget::FancyFrame; |
446 | package CFClient::Widget::FancyFrame; |
369 | |
447 | |
370 | our @ISA = Crossfire::Client::Widget::Bin::; |
448 | our @ISA = CFClient::Widget::Bin::; |
371 | |
449 | |
372 | use SDL::OpenGL; |
450 | use SDL::OpenGL; |
373 | |
451 | |
374 | my @tex = |
452 | my @tex = |
375 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
453 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
376 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
454 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
377 | |
455 | |
378 | sub size_request { |
456 | sub size_request { |
379 | my ($self) = @_; |
457 | my ($self) = @_; |
380 | |
458 | |
… | |
… | |
398 | $w -= $tex[2]->{width}; |
476 | $w -= $tex[2]->{width}; |
399 | $w -= $tex[3]->{width}; |
477 | $w -= $tex[3]->{width}; |
400 | |
478 | |
401 | $h = $h < 0 ? 0 : $h; |
479 | $h = $h < 0 ? 0 : $h; |
402 | $w = $w < 0 ? 0 : $w; |
480 | $w = $w < 0 ? 0 : $w; |
403 | warn "CHILD:$w $h\n"; |
481 | |
|
|
482 | my $child = $self->child; |
|
|
483 | |
404 | $self->child->size_allocate ($w, $h); |
484 | $child->size_allocate ($w, $h); |
405 | $self->child->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
485 | $child->move ($tex[3]->{width}, $tex[1]->{height}); |
406 | } |
486 | } |
407 | |
487 | |
408 | sub _draw { |
488 | sub _draw { |
409 | my ($self) = @_; |
489 | my ($self) = @_; |
410 | |
490 | |
411 | my ($w, $h) = ($self->w, $self->h); |
491 | my ($w, $h) = ($self->{w}, $self->{h}); |
412 | my ($cw, $ch) = ($self->child->w, $self->child->h); |
492 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
413 | |
493 | |
414 | glEnable GL_BLEND; |
494 | glEnable GL_BLEND; |
415 | glEnable GL_TEXTURE_2D; |
495 | glEnable GL_TEXTURE_2D; |
416 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
496 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
417 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
497 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
418 | |
498 | |
419 | my $top = $tex[1]; |
499 | my $top = $tex[1]; |
420 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
500 | $top->draw_quad (0, 0, $w, $top->{height}); |
421 | |
|
|
422 | glBegin GL_QUADS; |
|
|
423 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
424 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
|
|
425 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
|
|
426 | glTexCoord 1, 0; glVertex $w , 0; |
|
|
427 | glEnd; |
|
|
428 | |
501 | |
429 | my $left = $tex[3]; |
502 | my $left = $tex[3]; |
430 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
503 | $left->draw_quad (0, $top->{height}, $left->{width}, $ch); |
431 | |
|
|
432 | glBegin GL_QUADS; |
|
|
433 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
|
|
434 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
|
|
435 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
|
|
436 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
|
|
437 | glEnd; |
|
|
438 | |
504 | |
439 | my $right = $tex[2]; |
505 | my $right = $tex[2]; |
440 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
506 | $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch); |
441 | |
|
|
442 | glBegin GL_QUADS; |
|
|
443 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
|
|
444 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
|
|
445 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
|
|
446 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
|
|
447 | glEnd; |
|
|
448 | |
507 | |
449 | my $bottom = $tex[4]; |
508 | my $bottom = $tex[4]; |
450 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
509 | $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height}); |
451 | |
|
|
452 | glBegin GL_QUADS; |
|
|
453 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
|
|
454 | glTexCoord 0, 1; glVertex 0 , $h; |
|
|
455 | glTexCoord 1, 1; glVertex $w , $h; |
|
|
456 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
|
|
457 | glEnd; |
|
|
458 | |
510 | |
459 | my $bg = $tex[0]; |
511 | my $bg = $tex[0]; |
460 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
512 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
461 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
513 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
462 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
514 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
463 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
515 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
464 | |
516 | |
465 | my $rep_x = $cw / $bg->{width}; |
517 | my $rep_x = $cw / $bg->{width}; |
466 | my $rep_y = $ch / $bg->{height}; |
518 | my $rep_y = $ch / $bg->{height}; |
467 | |
519 | |
468 | glBegin GL_QUADS; |
520 | $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch); |
469 | glTexCoord 0, 0; glVertex $left->{width}, $top->{height}; |
|
|
470 | glTexCoord 0, $rep_y; glVertex $left->{width}, $top->{height} + $ch; |
|
|
471 | glTexCoord $rep_x, $rep_y; glVertex $left->{width} + $cw , $top->{height} + $ch; |
|
|
472 | glTexCoord $rep_x, 0; glVertex $left->{width} + $cw , $top->{height}; |
|
|
473 | glEnd; |
|
|
474 | |
521 | |
475 | glDisable GL_BLEND; |
522 | glDisable GL_BLEND; |
476 | glDisable GL_TEXTURE_2D; |
523 | glDisable GL_TEXTURE_2D; |
477 | |
524 | |
478 | $self->child->draw; |
525 | $self->child->draw; |
479 | |
526 | |
480 | } |
527 | } |
481 | |
528 | |
482 | ############################################################################# |
529 | ############################################################################# |
483 | |
530 | |
484 | package Crossfire::Client::Widget::Table; |
531 | package CFClient::Widget::Table; |
485 | |
532 | |
486 | our @ISA = Crossfire::Client::Widget::Bin::; |
533 | our @ISA = CFClient::Widget::Bin::; |
487 | |
534 | |
488 | use SDL::OpenGL; |
535 | use SDL::OpenGL; |
489 | |
536 | |
490 | sub add { |
537 | sub add { |
491 | my ($self, $x, $y, $chld) = @_; |
538 | my ($self, $x, $y, $chld) = @_; |
… | |
… | |
566 | } |
613 | } |
567 | } |
614 | } |
568 | |
615 | |
569 | ############################################################################# |
616 | ############################################################################# |
570 | |
617 | |
571 | package Crossfire::Client::Widget::VBox; |
618 | package CFClient::Widget::VBox; |
572 | |
619 | |
573 | our @ISA = Crossfire::Client::Widget::Container::; |
620 | our @ISA = CFClient::Widget::Container::; |
574 | |
621 | |
575 | use SDL::OpenGL; |
622 | use SDL::OpenGL; |
|
|
623 | |
|
|
624 | sub size_request { |
|
|
625 | my ($self) = @_; |
|
|
626 | |
|
|
627 | my @alloc = map [$_->size_request], @{$self->{children}}; |
|
|
628 | |
|
|
629 | ( |
|
|
630 | (List::Util::max map $_->[0], @alloc), |
|
|
631 | (List::Util::sum map $_->[1], @alloc), |
|
|
632 | ) |
|
|
633 | } |
576 | |
634 | |
577 | sub size_allocate { |
635 | sub size_allocate { |
578 | my ($self, $w, $h) = @_; |
636 | my ($self, $w, $h) = @_; |
579 | |
637 | |
580 | $self->w ($w); |
638 | $self->w ($w); |
… | |
… | |
613 | $y += $h; |
671 | $y += $h; |
614 | } |
672 | } |
615 | } |
673 | } |
616 | } |
674 | } |
617 | |
675 | |
618 | sub _draw { |
|
|
619 | my ($self) = @_; |
|
|
620 | |
|
|
621 | my ($x, $y); |
|
|
622 | for (@{$self->{children} || []}) { |
|
|
623 | $_->draw; |
|
|
624 | $y += $_->h; |
|
|
625 | } |
|
|
626 | } |
|
|
627 | |
|
|
628 | ############################################################################# |
676 | ############################################################################# |
629 | |
677 | |
630 | package Crossfire::Client::Widget::Label; |
678 | package CFClient::Widget::Label; |
631 | |
679 | |
632 | our @ISA = Crossfire::Client::Widget::; |
680 | our @ISA = CFClient::Widget::; |
633 | |
681 | |
634 | use SDL::OpenGL; |
682 | use SDL::OpenGL; |
635 | |
683 | |
636 | sub new { |
684 | sub new { |
637 | my ($class, $x, $y, $z, $height, $text) = @_; |
685 | my ($class, %arg) = @_; |
638 | |
686 | |
639 | # TODO: color, and make height, xyz etc. optional |
687 | # TODO: color, and make height, xyz etc. optional |
640 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
688 | my $self = $class->SUPER::new ( |
|
|
689 | color => [1, 1, 1], |
|
|
690 | height => $::FONTSIZE, |
|
|
691 | text => "", |
|
|
692 | layout => new CFClient::Layout, |
|
|
693 | %arg |
|
|
694 | ); |
641 | |
695 | |
642 | $self->set_text ($text); |
696 | $self->set_text ($self->{text}); |
643 | |
697 | |
644 | $self |
698 | $self |
645 | } |
699 | } |
646 | |
700 | |
647 | sub set_text { |
701 | sub set_text { |
648 | my ($self, $text) = @_; |
702 | my ($self, $text) = @_; |
649 | |
703 | |
650 | $self->{text} = $text; |
704 | $self->{text} = $text; |
651 | $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; |
705 | $self->{layout}->set_markup ($text); |
652 | |
706 | |
653 | $self->update; |
707 | delete $self->{texture}; |
654 | } |
708 | } |
655 | |
709 | |
656 | sub get_text { |
710 | sub get_text { |
657 | my ($self, $text) = @_; |
711 | my ($self, $text) = @_; |
658 | |
712 | |
… | |
… | |
660 | } |
714 | } |
661 | |
715 | |
662 | sub size_request { |
716 | sub size_request { |
663 | my ($self) = @_; |
717 | my ($self) = @_; |
664 | |
718 | |
665 | ( |
719 | $self->{layout}->set_width; |
|
|
720 | $self->{layout}->set_height ($self->{height}); |
|
|
721 | $self->{layout}->size |
|
|
722 | # if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
|
|
723 | # ( |
666 | $self->{texture}{width}, |
724 | # $self->{texture}{width}, |
667 | $self->{texture}{height}, |
725 | # $self->{texture}{height}, |
668 | ) |
726 | # ) |
|
|
727 | # } else { |
|
|
728 | # my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height}; |
|
|
729 | # |
|
|
730 | # ($w, $h) |
|
|
731 | # } |
|
|
732 | } |
|
|
733 | |
|
|
734 | sub size_allocate { |
|
|
735 | my ($self, $w, $h) = @_; |
|
|
736 | |
|
|
737 | $self->SUPER::size_allocate ($w, $h); |
|
|
738 | delete $self->{texture}; |
669 | } |
739 | } |
670 | |
740 | |
671 | sub _draw { |
741 | sub _draw { |
672 | my ($self) = @_; |
742 | my ($self) = @_; |
673 | |
743 | |
674 | my $tex = $self->{texture}; |
744 | my $tex = $self->{texture} ||= do { |
|
|
745 | $self->{layout}->set_width ($self->{w}); |
|
|
746 | new_from_layout CFClient::Texture $self->{layout}; |
|
|
747 | }; |
675 | |
748 | |
676 | glEnable GL_BLEND; |
749 | glEnable GL_BLEND; |
677 | glEnable GL_TEXTURE_2D; |
750 | glEnable GL_TEXTURE_2D; |
678 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
751 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
679 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
752 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
680 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
681 | |
753 | |
682 | glColor 1, 0, 0, 1; # TODO color |
754 | glColor @{$self->{color}}; |
683 | |
755 | |
684 | glBegin GL_QUADS; |
756 | $tex->draw_quad (0, 0); |
685 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
686 | glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
|
|
687 | glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
|
|
688 | glTexCoord 1, 0; glVertex $tex->{width}, 0; |
|
|
689 | glEnd; |
|
|
690 | |
757 | |
691 | glDisable GL_BLEND; |
758 | glDisable GL_BLEND; |
692 | glDisable GL_TEXTURE_2D; |
759 | glDisable GL_TEXTURE_2D; |
693 | } |
760 | } |
694 | |
761 | |
695 | ############################################################################# |
762 | ############################################################################# |
696 | |
763 | |
697 | package Crossfire::Client::Widget::TextEntry; |
764 | package CFClient::Widget::Entry; |
698 | |
765 | |
699 | our @ISA = Crossfire::Client::Widget::Label::; |
766 | our @ISA = CFClient::Widget::Label::; |
700 | |
767 | |
701 | use SDL; |
768 | use SDL; |
702 | use SDL::OpenGL; |
769 | use SDL::OpenGL; |
703 | |
770 | |
704 | sub key_down { |
771 | sub key_down { |
705 | my ($self, $ev) = @_; |
772 | my ($self, $ev) = @_; |
706 | |
773 | |
707 | my $mod = $ev->key_mod; |
774 | my $mod = $ev->key_mod; |
708 | my $sym = $ev->key_sym; |
775 | my $sym = $ev->key_sym; |
709 | |
776 | |
710 | $ev->set_unicode (1); |
|
|
711 | my $uni = $ev->key_unicode; |
777 | my $uni = $ev->key_unicode; |
712 | |
778 | |
713 | my $text = $self->get_text; |
779 | my $text = $self->get_text; |
714 | |
780 | |
715 | if ($sym == SDLK_BACKSPACE) { |
781 | if ($sym == SDLK_BACKSPACE) { |
716 | substr $text, -1, 1, ''; |
782 | substr $text, -1, 1, ''; |
717 | |
|
|
718 | } elsif ($uni) { |
783 | } elsif ($uni) { |
719 | $text .= chr $uni; |
784 | $text .= chr $uni; |
720 | } |
785 | } |
|
|
786 | |
721 | $self->set_text ($text); |
787 | $self->set_text ($text); |
722 | } |
788 | } |
723 | |
789 | |
724 | ############################################################################# |
790 | sub button_down { |
|
|
791 | my ($self, $ev) = @_; |
725 | |
792 | |
|
|
793 | $self->focus_in; |
|
|
794 | } |
|
|
795 | |
|
|
796 | sub mouse_motion { |
|
|
797 | my ($self, $ev, $x, $y) = @_; |
|
|
798 | printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
|
|
799 | } |
|
|
800 | |
|
|
801 | sub _draw { |
|
|
802 | my ($self) = @_; |
|
|
803 | |
|
|
804 | if ($FOCUS == $self) { |
|
|
805 | glColor 1, 1, 1; |
|
|
806 | } else { |
|
|
807 | glColor 0.7, 0.7, 0.7; |
|
|
808 | } |
|
|
809 | |
|
|
810 | glBegin GL_QUADS; |
|
|
811 | glVertex 0 , 0; |
|
|
812 | glVertex 0 , $self->{h} - 1; |
|
|
813 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
814 | glVertex $self->{w} - 1, 0; |
|
|
815 | glEnd; |
|
|
816 | |
|
|
817 | $self->SUPER::_draw; |
|
|
818 | } |
|
|
819 | |
|
|
820 | ############################################################################# |
|
|
821 | |
726 | package Crossfire::Client::Widget::MapWidget; |
822 | package CFClient::Widget::MapWidget; |
727 | |
823 | |
728 | use strict; |
824 | use strict; |
729 | |
825 | |
730 | use List::Util qw(min max); |
826 | use List::Util qw(min max); |
731 | |
827 | |
732 | use SDL; |
828 | use SDL; |
733 | use SDL::OpenGL; |
829 | use SDL::OpenGL; |
734 | use SDL::OpenGL::Constants; |
830 | use SDL::OpenGL::Constants; |
735 | |
831 | |
736 | our @ISA = Crossfire::Client::Widget::; |
832 | our @ISA = CFClient::Widget::; |
|
|
833 | |
|
|
834 | sub new { |
|
|
835 | my $class = shift; |
|
|
836 | |
|
|
837 | $class->SUPER::new ( |
|
|
838 | z => -1, |
|
|
839 | list => (glGenLists 1), |
|
|
840 | @_ |
|
|
841 | ) |
|
|
842 | } |
737 | |
843 | |
738 | sub key_down { |
844 | sub key_down { |
739 | print "MAPKEYDOWN\n"; |
845 | print "MAPKEYDOWN\n"; |
740 | } |
846 | } |
741 | |
847 | |
742 | sub key_up { |
848 | sub key_up { |
743 | } |
849 | } |
744 | |
850 | |
745 | sub size_request { |
851 | sub size_request { |
746 | |
852 | ( |
|
|
853 | 1 + int $::WIDTH / 32, |
|
|
854 | 1 + int $::HEIGHT / 32, |
|
|
855 | ) |
747 | } |
856 | } |
748 | |
857 | |
749 | sub size_allocate { |
858 | sub update { |
|
|
859 | my ($self) = @_; |
|
|
860 | |
|
|
861 | $self->{need_update} = 1; |
750 | } |
862 | } |
751 | |
863 | |
752 | sub _draw { |
864 | sub _draw { |
753 | my ($self) = @_; |
865 | my ($self) = @_; |
754 | |
866 | |
|
|
867 | if (delete $self->{need_update}) { |
|
|
868 | glNewList $self->{list}, GL_COMPILE; |
|
|
869 | |
755 | my $mx = $::CONN->{mapx}; |
870 | my $mx = $::CONN->{mapx}; |
756 | my $my = $::CONN->{mapy}; |
871 | my $my = $::CONN->{mapy}; |
757 | |
872 | |
758 | my $map = $::CONN->{map}; |
873 | my $map = $::CONN->{map}; |
759 | |
874 | |
760 | my ($xofs, $yofs); |
875 | my ($xofs, $yofs); |
761 | |
876 | |
762 | my $sw = 1 + int $::WIDTH / 32; |
877 | my $sw = 1 + int $::WIDTH / 32; |
763 | my $sh = 1 + int $::HEIGHT / 32; |
878 | my $sh = 1 + int $::HEIGHT / 32; |
764 | |
879 | |
765 | if ($::CONN->{mapw} > $sw) { |
880 | if ($::CONN->{mapw} > $sw) { |
766 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
881 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
767 | } else { |
882 | } else { |
768 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
883 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
769 | } |
884 | } |
770 | |
885 | |
771 | if ($::CONN->{maph} > $sh) { |
886 | if ($::CONN->{maph} > $sh) { |
772 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
887 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
773 | } else { |
888 | } else { |
774 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
889 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
775 | } |
890 | } |
776 | |
891 | |
777 | glEnable GL_TEXTURE_2D; |
892 | glEnable GL_TEXTURE_2D; |
778 | glEnable GL_BLEND; |
893 | glEnable GL_BLEND; |
779 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
894 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
780 | |
895 | |
781 | my $sw4 = ($sw + 3) & ~3; |
896 | my $sw4 = ($sw + 3) & ~3; |
782 | my $lighting = "\x00" x ($sw4 * $sh); |
897 | my $darkness = "\x00" x ($sw4 * $sh); |
783 | |
898 | |
784 | for my $x (0 .. $sw - 1) { |
899 | for my $x (0 .. $sw - 1) { |
|
|
900 | my $row = $map->[$x + $xofs]; |
785 | for my $y (0 .. $sh - 1) { |
901 | for my $y (0 .. $sh - 1) { |
786 | |
902 | |
787 | my $cell = $map->[$x + $xofs][$y + $yofs] |
903 | my $cell = $row->[$y + $yofs] |
788 | or next; |
904 | or next; |
789 | |
905 | |
790 | my $darkness = $cell->[0] * (1 / 255); |
906 | my $dark = $cell->[0]; |
791 | if ($darkness < 0) { |
907 | if ($dark < 0) { |
792 | $darkness = 0.15; |
908 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
909 | } else { |
|
|
910 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
793 | } |
911 | } |
794 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
|
|
795 | |
912 | |
796 | for my $num (grep $_, @$cell[1,2,3]) { |
913 | for my $num (grep $_, @$cell[1,2,3]) { |
797 | my $tex = $::CONN->{face}[$num]{texture} || next; |
914 | my $tex = $::CONN->{face}[$num]{texture} || next; |
798 | |
915 | |
799 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
800 | |
|
|
801 | my $w = $tex->{width}; |
916 | my $w = $tex->{width}; |
802 | my $h = $tex->{height}; |
917 | my $h = $tex->{height}; |
803 | |
918 | |
804 | my $px = ($x + 1) * 32 - $w; |
919 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
805 | my $py = ($y + 1) * 32 - $h; |
|
|
806 | |
|
|
807 | glBegin GL_QUADS; |
|
|
808 | glTexCoord 0, 0; glVertex $px , $py; |
|
|
809 | glTexCoord 0, 1; glVertex $px , $py + $h; |
|
|
810 | glTexCoord 1, 1; glVertex $px + $w, $py + $h; |
|
|
811 | glTexCoord 1, 0; glVertex $px + $w, $py; |
|
|
812 | glEnd; |
920 | } |
813 | } |
921 | } |
814 | } |
922 | } |
815 | } |
|
|
816 | |
923 | |
817 | # if (1) { # higher quality darkness |
924 | # if (1) { # higher quality darkness |
818 | # $lighting =~ s/(.)/$1$1$1/gs; |
925 | # $lighting =~ s/(.)/$1$1$1/gs; |
819 | # my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; |
926 | # my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; |
820 | # |
927 | # |
… | |
… | |
822 | # |
929 | # |
823 | # $lighting = $pb->get_pixels; |
930 | # $lighting = $pb->get_pixels; |
824 | # $lighting =~ s/(.)../$1/gs; |
931 | # $lighting =~ s/(.)../$1/gs; |
825 | # } |
932 | # } |
826 | |
933 | |
827 | $lighting = new Crossfire::Client::Texture |
|
|
828 | width => $sw4, |
|
|
829 | height => $sh, |
|
|
830 | data => $lighting, |
|
|
831 | internalformat => GL_ALPHA4, |
|
|
832 | format => GL_ALPHA; |
|
|
833 | |
|
|
834 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
934 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
835 | glColor 0, 0, 0, 0.75; |
|
|
836 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
935 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
837 | glBindTexture GL_TEXTURE_2D, $lighting->{name}; |
|
|
838 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
|
|
839 | glBegin GL_QUADS; |
|
|
840 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
841 | glTexCoord 0, 1; glVertex 0 , $sh * 32; |
|
|
842 | glTexCoord 1, 1; glVertex $sw4 * 32, $sh * 32; |
|
|
843 | glTexCoord 1, 0; glVertex $sw4 * 32, 0; |
|
|
844 | glEnd; |
|
|
845 | |
936 | |
|
|
937 | $darkness = new CFClient::Texture |
|
|
938 | width => $sw4, |
|
|
939 | height => $sh, |
|
|
940 | data => $darkness, |
|
|
941 | internalformat => GL_ALPHA, |
|
|
942 | format => GL_ALPHA; |
|
|
943 | |
|
|
944 | glColor 0.45, 0.45, 0.45, 1; |
|
|
945 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
|
|
946 | |
846 | glDisable GL_TEXTURE_2D; |
947 | glDisable GL_TEXTURE_2D; |
847 | glDisable GL_BLEND; |
948 | glDisable GL_BLEND; |
|
|
949 | |
|
|
950 | glEndList; |
|
|
951 | } |
|
|
952 | |
|
|
953 | glCallList $self->{list}; |
848 | } |
954 | } |
849 | |
955 | |
850 | my %DIR = ( |
956 | my %DIR = ( |
851 | SDLK_KP8, [1, "north"], |
957 | SDLK_KP8, [1, "north"], |
852 | SDLK_KP9, [2, "northeast"], |
958 | SDLK_KP9, [2, "northeast"], |
… | |
… | |
898 | } |
1004 | } |
899 | } |
1005 | } |
900 | |
1006 | |
901 | ############################################################################# |
1007 | ############################################################################# |
902 | |
1008 | |
903 | package Crossfire::Client::Widget::Animator; |
1009 | package CFClient::Widget::Animator; |
904 | |
1010 | |
905 | use SDL::OpenGL; |
1011 | use SDL::OpenGL; |
906 | |
1012 | |
907 | our @ISA = Crossfire::Client::Widget::Bin::; |
1013 | our @ISA = CFClient::Widget::Bin::; |
908 | |
1014 | |
909 | sub moveto { |
1015 | sub moveto { |
910 | my ($self, $x, $y) = @_; |
1016 | my ($self, $x, $y) = @_; |
911 | |
1017 | |
912 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
1018 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
913 | $self->{speed} = 0.2; |
1019 | $self->{speed} = 0.001; |
914 | $self->{time} = 1; |
1020 | $self->{time} = 1; |
915 | |
1021 | |
916 | ::animation_start $self; |
1022 | ::animation_start $self; |
917 | } |
1023 | } |
918 | |
1024 | |
… | |
… | |
933 | |
1039 | |
934 | sub _draw { |
1040 | sub _draw { |
935 | my ($self) = @_; |
1041 | my ($self) = @_; |
936 | |
1042 | |
937 | glPushMatrix; |
1043 | glPushMatrix; |
938 | glRotate $self->{time} * 10000, 0, 1, 0; |
1044 | glRotate $self->{time} * 1000, 0, 1, 0; |
939 | $self->{children}[0]->draw; |
1045 | $self->{children}[0]->draw; |
940 | glPopMatrix; |
1046 | glPopMatrix; |
941 | } |
1047 | } |
942 | |
1048 | |
943 | 1; |
1049 | ############################################################################# |
944 | |
1050 | |
|
|
1051 | package CFClient::Widget::Toplevel; |
|
|
1052 | |
|
|
1053 | our @ISA = CFClient::Widget::Container::; |
|
|
1054 | |
|
|
1055 | sub size_request { |
|
|
1056 | ($::WIDTH, $::HEIGHT) |
|
|
1057 | } |
|
|
1058 | |
|
|
1059 | sub size_allocate { |
|
|
1060 | my ($self, $w, $h) = @_; |
|
|
1061 | |
|
|
1062 | $self->SUPER::size_allocate ($w, $h); |
|
|
1063 | |
|
|
1064 | $_->size_allocate ($_->size_request) |
|
|
1065 | for @{$self->{children}}; |
|
|
1066 | } |
|
|
1067 | |
|
|
1068 | sub translate { |
|
|
1069 | my ($self, $x, $y) = @_; |
|
|
1070 | |
|
|
1071 | ($x, $y) |
|
|
1072 | } |
|
|
1073 | |
|
|
1074 | sub update { |
|
|
1075 | my ($self) = @_; |
|
|
1076 | |
|
|
1077 | $self->size_allocate ($self->size_request); |
|
|
1078 | ::refresh (); |
|
|
1079 | } |
|
|
1080 | |
|
|
1081 | sub add { |
|
|
1082 | my ($self, $widget) = @_; |
|
|
1083 | |
|
|
1084 | $self->SUPER::add ($widget); |
|
|
1085 | |
|
|
1086 | $widget->size_allocate ($widget->size_request); |
|
|
1087 | } |
|
|
1088 | |
|
|
1089 | sub draw { |
|
|
1090 | my ($self) = @_; |
|
|
1091 | |
|
|
1092 | $self->_draw; |
|
|
1093 | } |
|
|
1094 | |
|
|
1095 | ############################################################################# |
|
|
1096 | |
|
|
1097 | package CFClient::Widget; |
|
|
1098 | |
|
|
1099 | $TOPLEVEL = new CFClient::Widget::Toplevel; |
|
|
1100 | |
|
|
1101 | 1 |
|
|
1102 | |