… | |
… | |
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 | our $FOCUS; # the widget with current focus |
11 | our @ACTIVE_WIDGETS; |
11 | #our @ACTIVE_WIDGETS; |
12 | |
12 | |
13 | # class methods for events |
13 | # class methods for events |
14 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
14 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
15 | sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
15 | sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
16 | sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } |
16 | sub feed_sdl_button_down_event { } |
17 | sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } |
17 | sub feed_sdl_button_up_event { } |
18 | |
18 | |
19 | sub new { |
19 | sub new { |
20 | my $class = shift; |
20 | my $class = shift; |
21 | |
21 | |
22 | bless { @_ }, $class |
22 | bless { @_ }, $class |
23 | } |
23 | } |
24 | |
24 | |
25 | sub activate { |
25 | #sub activate { |
26 | push @ACTIVE_WIDGETS, $_[0]; |
26 | # push @ACTIVE_WIDGETS, $_[0]; |
27 | Scalar::Util::weaken $ACTIVE_WIDGETS[-1]; |
27 | # Scalar::Util::weaken $ACTIVE_WIDGETS[-1]; |
28 | } |
28 | #} |
29 | |
29 | |
30 | sub deactivate { |
30 | #sub deactivate { |
31 | @ACTIVE_WIDGETS = |
31 | # @ACTIVE_WIDGETS = |
32 | sort { $a->{z} <=> $b->{z} } |
32 | # sort { $a->{z} <=> $b->{z} } |
33 | grep { $_ && $_ != $_[0] } |
33 | # grep { $_ && $_ != $_[0] } |
34 | @ACTIVE_WIDGETS; |
34 | # @ACTIVE_WIDGETS; |
35 | } |
35 | #} |
36 | |
36 | |
37 | sub move { |
37 | sub move { |
38 | my ($self, $x, $y, $z) = @_; |
38 | my ($self, $x, $y, $z) = @_; |
39 | $self->{x} = $x; |
39 | $self->{x} = $x; |
40 | $self->{y} = $y; |
40 | $self->{y} = $y; |
… | |
… | |
92 | sub _draw { |
92 | sub _draw { |
93 | my ($widget) = @_; |
93 | my ($widget) = @_; |
94 | } |
94 | } |
95 | |
95 | |
96 | sub bbox { |
96 | sub bbox { |
97 | my ($widget) = @_; |
97 | my ($self) = @_; |
|
|
98 | my ($w, $h) = $self->size_request; |
|
|
99 | ( |
|
|
100 | $self->{x}, |
|
|
101 | $self->{y}, |
|
|
102 | $self->{x} = $w, |
|
|
103 | $self->{y} = $h |
|
|
104 | ) |
|
|
105 | } |
|
|
106 | |
|
|
107 | sub del_parent { $_[0]->{parent} = undef } |
|
|
108 | |
|
|
109 | sub set_parent { |
|
|
110 | my ($self, $par) = @_; |
|
|
111 | |
|
|
112 | $self->{parent} = $par; |
|
|
113 | Scalar::Util::weaken $self->{parent}; |
|
|
114 | } |
|
|
115 | |
|
|
116 | sub get_parent { |
|
|
117 | $_[0]->{parent} |
|
|
118 | } |
|
|
119 | |
|
|
120 | sub update { |
|
|
121 | my ($self) = @_; |
|
|
122 | |
|
|
123 | $self->{parent}->update |
|
|
124 | if $self->{parent}; |
98 | } |
125 | } |
99 | |
126 | |
100 | sub DESTROY { |
127 | sub DESTROY { |
101 | my ($self) = @_; |
128 | my ($self) = @_; |
102 | |
129 | |
103 | $self->deactivate; |
130 | #$self->deactivate; |
104 | } |
131 | } |
105 | |
132 | |
106 | package Crossfire::Client::Widget::Container; |
133 | package Crossfire::Client::Widget::Container; |
107 | |
134 | |
108 | our @ISA = Crossfire::Client::Widget::; |
135 | our @ISA = Crossfire::Client::Widget::; |
109 | |
136 | |
110 | use SDL::OpenGL; |
137 | use SDL::OpenGL; |
111 | |
138 | |
112 | sub add { $_[0]->{child} = $_[1] } |
139 | sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->update } |
113 | sub get { $_[0]->{child} } |
140 | sub get { $_[0]->{child} } |
|
|
141 | sub remove { |
|
|
142 | my ($self, $chld) = @_; |
|
|
143 | delete $self->{child} |
|
|
144 | if $self->{child} == $chld; |
|
|
145 | } |
114 | |
146 | |
115 | sub size_request { $_[0]->{child}->size_request if $_[0]->{child} } |
147 | sub size_request { $_[0]->{child}->size_request if $_[0]->{child} } |
116 | |
148 | |
117 | sub _draw { die "Containers can't be drawn!" } |
149 | sub _draw { die "Containers can't be drawn!" } |
|
|
150 | |
|
|
151 | package Crossfire::Client::Widget::Toplevel; |
|
|
152 | |
|
|
153 | our @ISA = Crossfire::Client::Widget::; |
|
|
154 | |
|
|
155 | use SDL::OpenGL; |
|
|
156 | |
|
|
157 | sub add { |
|
|
158 | my ($self, $chld) = @_; |
|
|
159 | |
|
|
160 | push @{$self->{childs}}, $chld; |
|
|
161 | @{$self->{childs}} = |
|
|
162 | sort { $a->{z} <=> $b->{z} } |
|
|
163 | @{$self->{childs}}; |
|
|
164 | |
|
|
165 | $chld->set_parent ($self); |
|
|
166 | } |
|
|
167 | |
|
|
168 | sub remove { |
|
|
169 | my ($self, $chld) = @_; |
|
|
170 | @{$self->{childs}} = |
|
|
171 | sort { $a->{z} <=> $b->{z} } |
|
|
172 | grep { $_ && $_ != $_[0] } |
|
|
173 | @{$self->{childs}} |
|
|
174 | } |
|
|
175 | |
|
|
176 | sub update { |
|
|
177 | my ($self) = @_; |
|
|
178 | ::refresh (); |
|
|
179 | } |
|
|
180 | |
|
|
181 | sub _draw { |
|
|
182 | my ($self) = @_; |
|
|
183 | |
|
|
184 | $_->draw for @{$self->{childs}}; |
|
|
185 | } |
118 | |
186 | |
119 | package Crossfire::Client::Widget::Window; |
187 | package Crossfire::Client::Widget::Window; |
120 | |
188 | |
121 | our @ISA = Crossfire::Client::Widget::Container::; |
189 | our @ISA = Crossfire::Client::Widget::Container::; |
122 | |
190 | |
123 | use SDL::OpenGL; |
191 | use SDL::OpenGL; |
124 | |
192 | |
125 | sub add { |
193 | sub add { |
126 | my ($self, $chld) = @_; |
194 | my ($self, $chld) = @_; |
127 | $self->SUPER::add ($chld); |
195 | $self->SUPER::add ($chld); |
|
|
196 | $chld->set_parent ($self); |
|
|
197 | $self->update; #TODO: Move this to the size_request event propably? |
|
|
198 | } |
|
|
199 | |
|
|
200 | sub remove { |
|
|
201 | my ($self) = @_; |
|
|
202 | # TODO FIXME: removing a child from a window will crash, see render_chld |
|
|
203 | $self->update; |
|
|
204 | } |
|
|
205 | |
|
|
206 | sub update { |
|
|
207 | my ($self) = @_; |
128 | $self->render_chld; |
208 | $self->render_chld; |
129 | } |
209 | } |
130 | |
210 | |
131 | sub render_chld { |
211 | sub render_chld { |
132 | my ($self) = @_; |
212 | my ($self) = @_; |
… | |
… | |
148 | } |
228 | } |
149 | |
229 | |
150 | sub _draw { |
230 | sub _draw { |
151 | my ($self) = @_; |
231 | my ($self) = @_; |
152 | |
232 | |
153 | my ($w, $h) = $self->size_request;#TODO# use widht/height of texture |
233 | my ($w, $h) = $self->size_request;#TODO# use width/height of texture |
|
|
234 | |
154 | my $tex = $self->{texture} |
235 | my $tex = $self->{texture} |
155 | or return; |
236 | or return; |
156 | |
237 | |
157 | glEnable GL_BLEND; |
238 | glEnable GL_BLEND; |
158 | glEnable GL_TEXTURE_2D; |
239 | glEnable GL_TEXTURE_2D; |
159 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
240 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
160 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
241 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
161 | |
242 | |
162 | glColor 1, 1, 1; |
243 | glColor 1, 0, 1; |
163 | |
244 | |
164 | glBegin GL_QUADS; |
245 | glBegin GL_QUADS; |
165 | glTexCoord 0, 0; glVertex 0, 0; |
246 | glTexCoord 0, 0; glVertex 0, 0; |
166 | glTexCoord 0, 1; glVertex 0, $h; |
247 | glTexCoord 0, 1; glVertex 0, $h; |
167 | glTexCoord 1, 1; glVertex $w, $h; |
248 | glTexCoord 1, 1; glVertex $w, $h; |
… | |
… | |
180 | |
261 | |
181 | sub size_request { |
262 | sub size_request { |
182 | my ($self) = @_; |
263 | my ($self) = @_; |
183 | my $chld = $self->get |
264 | my $chld = $self->get |
184 | or return (0, 0); |
265 | or return (0, 0); |
|
|
266 | |
|
|
267 | $chld->move (2, 2); |
|
|
268 | |
185 | map { $_ + 4 } $chld->size_request; |
269 | map { $_ + 4 } $chld->size_request; |
186 | } |
270 | } |
187 | |
271 | |
188 | sub _draw { |
272 | sub _draw { |
189 | my ($self) = @_; |
273 | my ($self) = @_; |
190 | |
274 | |
191 | my $chld = $self->get; |
275 | my $chld = $self->get; |
192 | |
276 | |
193 | my ($w, $h) = $chld->size_request; |
277 | my ($w, $h) = $chld->size_request; |
194 | |
278 | |
195 | glColor 1, 0, 0; |
|
|
196 | glBegin GL_QUADS; |
279 | glBegin GL_QUADS; |
|
|
280 | glColor 0, 0, 0; |
197 | glTexCoord 0, 0; glVertex 0 , 0; |
281 | glTexCoord 0, 0; glVertex 0 , 0; |
198 | glTexCoord 0, 1; glVertex 0 , $h + 4; |
282 | glTexCoord 0, 1; glVertex 0 , $h + 4; |
199 | glTexCoord 1, 1; glVertex $w + 4 , $h + 4; |
283 | glTexCoord 1, 1; glVertex $w + 4 , $h + 4; |
200 | glTexCoord 1, 0; glVertex $w + 4 , 0; |
284 | glTexCoord 1, 0; glVertex $w + 4 , 0; |
201 | glEnd; |
285 | glEnd; |
202 | |
286 | |
203 | glPushMatrix; |
|
|
204 | glTranslate (2, 2, 0); |
|
|
205 | $chld->draw; |
287 | $chld->draw; |
206 | glPopMatrix; |
|
|
207 | } |
288 | } |
|
|
289 | |
|
|
290 | package Crossfire::Client::Widget::FancyFrame; |
|
|
291 | |
|
|
292 | our @ISA = Crossfire::Client::Widget::Frame::; |
|
|
293 | |
|
|
294 | use SDL::OpenGL; |
|
|
295 | |
|
|
296 | #TODO: implement themed frame |
208 | |
297 | |
209 | package Crossfire::Client::Widget::Table; |
298 | package Crossfire::Client::Widget::Table; |
210 | |
299 | |
211 | our @ISA = Crossfire::Client::Widget::Container::; |
300 | our @ISA = Crossfire::Client::Widget::Container::; |
212 | |
301 | |
213 | use SDL::OpenGL; |
302 | use SDL::OpenGL; |
214 | |
303 | |
215 | sub add { |
304 | sub add { |
216 | my ($self, $x, $y, $chld) = @_; |
305 | my ($self, $x, $y, $chld) = @_; |
|
|
306 | my $old_chld = $self->{childs}[$y][$x]; |
|
|
307 | |
217 | $self->{childs}[$y][$x] = $chld; |
308 | $self->{childs}[$y][$x] = $chld; |
|
|
309 | $chld->set_parent ($self); |
|
|
310 | $self->update; |
218 | } |
311 | } |
219 | |
312 | |
220 | sub max_row_height { |
313 | sub max_row_height { |
221 | my ($self, $row) = @_; |
314 | my ($self, $row) = @_; |
222 | |
315 | |
… | |
… | |
272 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
365 | for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { |
273 | my $x = 0; |
366 | my $x = 0; |
274 | |
367 | |
275 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { |
368 | for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { |
276 | |
369 | |
277 | glPushMatrix; |
|
|
278 | glTranslate ($x, $y, 0);#TODO#there must be no translate here, instead the widget must be moved |
|
|
279 | my $c = $self->{childs}->[$yi]->[$xi]; |
370 | my $c = $self->{childs}->[$yi]->[$xi]; |
|
|
371 | if ($c) { |
|
|
372 | $c->move ($x, $y, 0); #TODO: Move to size_request |
280 | $c->draw if $c; |
373 | $c->draw if $c; |
281 | glPopMatrix; |
374 | } |
282 | |
375 | |
283 | $x += $self->max_col_width ($xi); |
376 | $x += $self->max_col_width ($xi); |
284 | } |
377 | } |
285 | |
378 | |
286 | $y += $self->max_row_height ($yi); |
379 | $y += $self->max_row_height ($yi); |
… | |
… | |
294 | use SDL::OpenGL; |
387 | use SDL::OpenGL; |
295 | |
388 | |
296 | sub add { |
389 | sub add { |
297 | my ($self, $chld) = @_; |
390 | my ($self, $chld) = @_; |
298 | push @{$self->{childs}}, $chld; |
391 | push @{$self->{childs}}, $chld; |
|
|
392 | $chld->set_parent ($self); |
|
|
393 | $self->update; |
299 | } |
394 | } |
300 | |
395 | |
301 | sub size_request { |
396 | sub size_request { |
302 | my ($self) = @_; |
397 | my ($self) = @_; |
303 | |
398 | |
… | |
… | |
314 | sub _draw { |
409 | sub _draw { |
315 | my ($self) = @_; |
410 | my ($self) = @_; |
316 | |
411 | |
317 | my ($x, $y); |
412 | my ($x, $y); |
318 | for (@{$self->{childs} || []}) { |
413 | for (@{$self->{childs} || []}) { |
319 | glPushMatrix; |
414 | $_->move (0, $y, 0); #TODO: move to size_request |
320 | glTranslate (0, $y, 0);# see above TODO |
|
|
321 | $_->draw; |
415 | $_->draw; |
322 | glPopMatrix; |
|
|
323 | my ($w, $h) = $_->size_request; |
416 | my ($w, $h) = $_->size_request; |
324 | $y += $h; |
417 | $y += $h; |
325 | } |
418 | } |
326 | } |
419 | } |
327 | |
420 | |
… | |
… | |
330 | our @ISA = Crossfire::Client::Widget::; |
423 | our @ISA = Crossfire::Client::Widget::; |
331 | |
424 | |
332 | use SDL::OpenGL; |
425 | use SDL::OpenGL; |
333 | |
426 | |
334 | sub new { |
427 | sub new { |
335 | my ($class, $x, $y, $z, $ttf, $text) = @_; |
428 | my ($class, $x, $y, $z, $height, $text) = @_; |
336 | |
429 | |
337 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, ttf => $ttf); |
430 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
338 | |
431 | |
339 | $self->set_text ($text); |
432 | $self->set_text ($text); |
340 | |
433 | |
341 | $self |
434 | $self |
342 | } |
435 | } |
343 | |
436 | |
344 | sub set_text { |
437 | sub set_text { |
345 | my ($self, $text) = @_; |
438 | my ($self, $text) = @_; |
|
|
439 | |
|
|
440 | $self->{text} = $text; |
346 | $self->{texture} = new_from_ttf Crossfire::Client::Texture $self->{ttf}, $self->{text} = $text; |
441 | $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; |
|
|
442 | |
|
|
443 | $self->update; |
347 | } |
444 | } |
348 | |
445 | |
349 | sub get_text { |
446 | sub get_text { |
350 | my ($self, $text) = @_; |
447 | my ($self, $text) = @_; |
|
|
448 | |
351 | $self->{text} |
449 | $self->{text} |
352 | } |
450 | } |
353 | |
451 | |
354 | sub size_request { |
452 | sub size_request { |
355 | my ($self) = @_; |
453 | my ($self) = @_; |
… | |
… | |
365 | |
463 | |
366 | my $tex = $self->{texture}; |
464 | my $tex = $self->{texture}; |
367 | |
465 | |
368 | glEnable GL_BLEND; |
466 | glEnable GL_BLEND; |
369 | glEnable GL_TEXTURE_2D; |
467 | glEnable GL_TEXTURE_2D; |
|
|
468 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
370 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
469 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
371 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
470 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
372 | |
471 | |
373 | glColor 1, 1, 1; |
472 | glColor 1, 1, 1, 0.8; |
374 | |
473 | |
375 | glBegin GL_QUADS; |
474 | glBegin GL_QUADS; |
376 | glTexCoord 0, 0; glVertex 0 , 0; |
475 | glTexCoord 0, 0; glVertex 0 , 0; |
377 | glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
476 | glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
378 | glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
477 | glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
… | |
… | |
381 | |
480 | |
382 | glDisable GL_BLEND; |
481 | glDisable GL_BLEND; |
383 | glDisable GL_TEXTURE_2D; |
482 | glDisable GL_TEXTURE_2D; |
384 | } |
483 | } |
385 | |
484 | |
|
|
485 | package Crossfire::Client::Widget::TextEntry; |
|
|
486 | |
|
|
487 | our @ISA = Crossfire::Client::Widget::Label::; |
|
|
488 | |
|
|
489 | use SDL; |
|
|
490 | use SDL::OpenGL; |
|
|
491 | |
|
|
492 | sub key_down { |
|
|
493 | my ($self, $ev) = @_; |
|
|
494 | |
|
|
495 | my $mod = $ev->key_mod; |
|
|
496 | my $sym = $ev->key_sym; |
|
|
497 | |
|
|
498 | $ev->set_unicode (1); |
|
|
499 | my $uni = $ev->key_unicode; |
|
|
500 | |
|
|
501 | my $text = $self->get_text; |
|
|
502 | |
|
|
503 | if ($sym == SDLK_BACKSPACE) { |
|
|
504 | substr $text, -1, 1, ''; |
|
|
505 | |
|
|
506 | } elsif ($uni) { |
|
|
507 | $text .= chr $uni; |
|
|
508 | } |
|
|
509 | $self->set_text ($text); |
|
|
510 | } |
|
|
511 | |
|
|
512 | |
|
|
513 | # XXX: TextView isn't neccessary with pango multiline text rendering |
386 | package Crossfire::Client::Widget::TextView; |
514 | package Crossfire::Client::Widget::TextView; |
387 | |
515 | |
388 | use strict; |
516 | use strict; |
389 | |
517 | |
390 | our @ISA = qw/Crossfire::Client::Widget/; |
518 | our @ISA = qw/Crossfire::Client::Widget/; |
391 | |
519 | |
392 | use SDL::OpenGL; |
520 | use SDL::OpenGL; |
393 | use SDL::OpenGL::Constants; |
521 | use SDL::OpenGL::Constants; |
|
|
522 | |
|
|
523 | sub new { |
|
|
524 | my ($class, $text, $h) = @_; |
|
|
525 | my $self = $class->SUPER::new (); |
|
|
526 | |
|
|
527 | $self->{txt_height} = $h; |
|
|
528 | @{$self->{lines}} = split /\r?\n/, $text; |
|
|
529 | |
|
|
530 | for (split /\r?\n/, $text) { |
|
|
531 | $self->add_line ($_); |
|
|
532 | } |
|
|
533 | $self |
|
|
534 | } |
|
|
535 | |
|
|
536 | #sub render_lines { |
|
|
537 | # my ($self) = @_; |
|
|
538 | # |
|
|
539 | # $self->{txt_lines} = []; |
|
|
540 | # |
|
|
541 | # for (@{$self->{lines}}) { |
|
|
542 | # push @{$self->{txt_lines}}, |
|
|
543 | # new_from_ttf Crossfire::Client::Texture $self->{ttf}, $_; |
|
|
544 | # } |
|
|
545 | #} |
394 | |
546 | |
395 | sub add_line { |
547 | sub add_line { |
396 | my ($self, $line) = @_; |
548 | my ($self, $line) = @_; |
397 | push @{$self->{lines}}, $line; |
549 | push @{$self->{lines}}, $line; |
398 | } |
|
|
399 | |
550 | |
|
|
551 | push @{$self->{txt_lines}}, |
|
|
552 | new_from_text Crossfire::Client::Texture $line, $self->{txt_height}; |
|
|
553 | } |
|
|
554 | |
|
|
555 | sub size_request { |
|
|
556 | my ($self) = @_; |
|
|
557 | |
|
|
558 | my $w = 0; |
|
|
559 | my $h = 0; |
|
|
560 | |
|
|
561 | for (@{$self->{txt_lines}}) { |
|
|
562 | if ($w < $_->{width}) { $w = $_->{width} } |
|
|
563 | $h += $_->{height}; |
|
|
564 | } |
|
|
565 | |
|
|
566 | return ($w, $h); |
|
|
567 | } |
|
|
568 | |
400 | sub _draw { |
569 | sub draw_line { |
401 | my ($self) = @_; |
570 | my ($self, $tex, $y) = @_; |
402 | |
571 | |
|
|
572 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
573 | |
|
|
574 | glColor 1, 0, 1; |
|
|
575 | |
|
|
576 | glBegin GL_QUADS; |
|
|
577 | glTexCoord 0, 0; glVertex 0 , $y; |
|
|
578 | glTexCoord 0, 1; glVertex 0 , $y + $tex->{height}; |
|
|
579 | glTexCoord 1, 1; glVertex $tex->{width}, $y + $tex->{height}; |
|
|
580 | glTexCoord 1, 0; glVertex $tex->{width}, $y; |
|
|
581 | glEnd; |
|
|
582 | } |
|
|
583 | |
|
|
584 | sub _draw { |
|
|
585 | my ($self) = @_; |
|
|
586 | |
|
|
587 | glEnable GL_BLEND; |
|
|
588 | glEnable GL_TEXTURE_2D; |
|
|
589 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;#DECAL; |
|
|
590 | |
|
|
591 | my $l = 0; |
|
|
592 | for (@{$self->{txt_lines}}) { |
|
|
593 | $self->draw_line ($_, $l); |
|
|
594 | $l += $_->{height}; |
|
|
595 | } |
|
|
596 | |
|
|
597 | glDisable GL_BLEND; |
|
|
598 | glDisable GL_TEXTURE_2D; |
403 | } |
599 | } |
404 | |
600 | |
405 | package Crossfire::Client::Widget::MapWidget; |
601 | package Crossfire::Client::Widget::MapWidget; |
406 | |
602 | |
407 | use strict; |
603 | use strict; |
408 | |
604 | |
409 | our @ISA = qw/Crossfire::Client::Widget/; |
605 | use List::Util qw(min max); |
410 | |
606 | |
411 | use SDL; |
607 | use SDL; |
412 | use SDL::OpenGL; |
608 | use SDL::OpenGL; |
413 | use SDL::OpenGL::Constants; |
609 | use SDL::OpenGL::Constants; |
|
|
610 | |
|
|
611 | our @ISA = Crossfire::Client::Widget::; |
414 | |
612 | |
415 | sub key_down { |
613 | sub key_down { |
416 | print "MAPKEYDOWN\n"; |
614 | print "MAPKEYDOWN\n"; |
417 | } |
615 | } |
418 | |
616 | |
419 | sub key_up { |
617 | sub key_up { |
420 | } |
618 | } |
421 | |
619 | |
422 | sub _draw { |
620 | sub _draw { |
423 | my ($self) = @_; |
621 | my ($self) = @_; |
|
|
622 | |
|
|
623 | my $mx = $::CONN->{mapx}; |
|
|
624 | my $my = $::CONN->{mapy}; |
|
|
625 | |
|
|
626 | my $map = $::CONN->{map}; |
|
|
627 | |
|
|
628 | my ($xofs, $yofs); |
|
|
629 | |
|
|
630 | my $sw = 1 + int $::WIDTH / 32; |
|
|
631 | my $sh = 1 + int $::HEIGHT / 32; |
|
|
632 | |
|
|
633 | if ($::CONN->{mapw} > $sw) { |
|
|
634 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
|
|
635 | } else { |
|
|
636 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
|
|
637 | } |
|
|
638 | |
|
|
639 | if ($::CONN->{maph} > $sh) { |
|
|
640 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
|
|
641 | } else { |
|
|
642 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
|
|
643 | } |
424 | |
644 | |
425 | glEnable GL_TEXTURE_2D; |
645 | glEnable GL_TEXTURE_2D; |
426 | glEnable GL_BLEND; |
646 | glEnable GL_BLEND; |
427 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
647 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
428 | |
648 | |
429 | my $map = $::CONN->{map}; |
649 | for my $x (0 .. $sw - 1) { |
|
|
650 | for my $y (0 .. $sh - 1) { |
430 | |
651 | |
431 | for my $x (0 .. int $::WIDTH / 32) { |
652 | my $cell = $map->[$x + $xofs][$y + $yofs] |
432 | for my $y (0 .. int $::HEIGHT / 32) { |
|
|
433 | |
|
|
434 | my $cell = $map->[$x + $::CONN->{mapx}] |
|
|
435 | [$y + $::CONN->{mapy}] |
|
|
436 | or next; |
653 | or next; |
437 | |
654 | |
438 | my $darkness = $cell->[0] * (1 / 255); |
655 | my $darkness = $cell->[0] * (1 / 255); |
439 | if ($darkness < 0) { |
656 | if ($darkness < 0) { |
440 | glColor 0.3, 0.3, 0.3; |
657 | glColor 0.3, 0.3, 0.3; |