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, $HOVER, $GRAB); # various widgets |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
13 | |
13 | |
14 | our $TOPLEVEL; |
14 | our $TOPLEVEL; |
15 | our $BUTTON_STATE; |
15 | our $BUTTON_STATE; |
… | |
… | |
34 | $GRAB->update if $GRAB; |
34 | $GRAB->update if $GRAB; |
35 | } |
35 | } |
36 | |
36 | |
37 | $BUTTON_STATE |= 1 << ($ev->button - 1); |
37 | $BUTTON_STATE |= 1 << ($ev->button - 1); |
38 | |
38 | |
39 | $GRAB->button_down ($ev) if $GRAB; |
39 | $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; |
40 | } |
40 | } |
41 | |
41 | |
42 | sub feed_sdl_button_up_event { |
42 | sub feed_sdl_button_up_event { |
43 | my ($ev) = @_; |
43 | my ($ev) = @_; |
44 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
44 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
45 | |
45 | |
46 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
46 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
47 | |
47 | |
48 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
48 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
|
|
49 | |
|
|
50 | $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; |
49 | |
51 | |
50 | if (!$BUTTON_STATE) { |
52 | if (!$BUTTON_STATE) { |
51 | my $grab = $GRAB; undef $GRAB; |
53 | my $grab = $GRAB; undef $GRAB; |
52 | $grab->update if $grab; |
54 | $grab->update if $grab; |
53 | $GRAB->update if $GRAB; |
55 | $GRAB->update if $GRAB; |
… | |
… | |
65 | |
67 | |
66 | $hover->update if $hover; |
68 | $hover->update if $hover; |
67 | $HOVER->update if $HOVER; |
69 | $HOVER->update if $HOVER; |
68 | } |
70 | } |
69 | |
71 | |
70 | $HOVER->mouse_motion ($ev) if $HOVER; |
72 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
71 | } |
73 | } |
72 | |
74 | |
73 | sub new { |
75 | sub new { |
74 | my $class = shift; |
76 | my $class = shift; |
75 | |
77 | |
76 | bless { @_ }, $class |
78 | bless { |
|
|
79 | x => 0, |
|
|
80 | y => 0, |
|
|
81 | z => 0, |
|
|
82 | @_ |
|
|
83 | }, $class |
77 | } |
84 | } |
78 | |
85 | |
79 | sub move { |
86 | sub move { |
80 | my ($self, $x, $y, $z) = @_; |
87 | my ($self, $x, $y, $z) = @_; |
81 | $self->{x} = $x; |
88 | $self->{x} = $x; |
… | |
… | |
95 | sub size_allocate { |
102 | sub size_allocate { |
96 | my ($self, $w, $h) = @_; |
103 | my ($self, $w, $h) = @_; |
97 | |
104 | |
98 | $self->{w} = $w; |
105 | $self->{w} = $w; |
99 | $self->{h} = $h; |
106 | $self->{h} = $h; |
|
|
107 | } |
|
|
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}); |
100 | } |
114 | } |
101 | |
115 | |
102 | sub focus_in { |
116 | sub focus_in { |
103 | my ($self) = @_; |
117 | my ($self) = @_; |
104 | |
118 | |
… | |
… | |
201 | #$self->deactivate; |
215 | #$self->deactivate; |
202 | } |
216 | } |
203 | |
217 | |
204 | ############################################################################# |
218 | ############################################################################# |
205 | |
219 | |
206 | package Crossfire::Client::Widget::Container; |
220 | package CFClient::Widget::Container; |
207 | |
221 | |
208 | our @ISA = Crossfire::Client::Widget::; |
222 | our @ISA = CFClient::Widget::; |
209 | |
223 | |
210 | sub new { |
224 | sub new { |
211 | my ($class, @widgets) = @_; |
225 | my ($class, %arg) = @_; |
212 | |
226 | |
|
|
227 | my $children = delete $arg{children} || []; |
|
|
228 | |
213 | my $self = $class->SUPER::new (children => []); |
229 | my $self = $class->SUPER::new (children => [], %arg); |
214 | $self->add ($_) for @widgets; |
230 | $self->add ($_) for @$children; |
215 | |
231 | |
216 | $self |
232 | $self |
217 | } |
233 | } |
218 | |
234 | |
219 | sub add { |
235 | sub add { |
… | |
… | |
260 | $_->draw for @{$self->{children}}; |
276 | $_->draw for @{$self->{children}}; |
261 | } |
277 | } |
262 | |
278 | |
263 | ############################################################################# |
279 | ############################################################################# |
264 | |
280 | |
265 | package Crossfire::Client::Widget::Bin; |
281 | package CFClient::Widget::Bin; |
266 | |
282 | |
267 | our @ISA = Crossfire::Client::Widget::Container::; |
283 | our @ISA = CFClient::Widget::Container::; |
268 | |
284 | |
269 | sub child { $_[0]->{children}[0] } |
285 | sub child { $_[0]->{children}[0] } |
270 | |
286 | |
271 | sub size_request { |
287 | sub size_request { |
272 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
288 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
… | |
… | |
280 | if $self->{children}[0] |
296 | if $self->{children}[0] |
281 | } |
297 | } |
282 | |
298 | |
283 | ############################################################################# |
299 | ############################################################################# |
284 | |
300 | |
285 | package Crossfire::Client::Widget::Window; |
301 | package CFClient::Widget::Window; |
286 | |
302 | |
287 | our @ISA = Crossfire::Client::Widget::Bin::; |
303 | our @ISA = CFClient::Widget::Bin::; |
288 | |
304 | |
289 | use SDL::OpenGL; |
305 | use SDL::OpenGL; |
290 | |
306 | |
291 | sub new { |
307 | sub new { |
292 | my ($class, $x, $y, $z, $w, $h) = @_; |
308 | my ($class, %arg) = @_; |
293 | |
309 | |
294 | my $self = $class->SUPER::new; |
310 | my $self = $class->SUPER::new (%arg); |
295 | |
|
|
296 | @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h); |
|
|
297 | } |
311 | } |
298 | |
312 | |
299 | sub update { |
313 | sub update { |
300 | my ($self) = @_; |
314 | my ($self) = @_; |
301 | |
315 | |
|
|
316 | # we want to do this delayed... |
302 | $self->render_chld; |
317 | $self->render_chld; |
303 | $self->SUPER::update; |
318 | $self->SUPER::update; |
304 | } |
319 | } |
305 | |
320 | |
306 | sub render_chld { |
321 | sub render_chld { |
307 | my ($self) = @_; |
322 | my ($self) = @_; |
308 | |
323 | |
309 | $self->{texture} = |
324 | $self->{texture} = |
310 | Crossfire::Client::Texture->new_from_opengl ( |
325 | CFClient::Texture->new_from_opengl ( |
311 | $self->{w}, $self->{h}, sub { $self->child->draw } |
326 | $self->{w}, $self->{h}, sub { $self->child->draw } |
312 | ); |
327 | ); |
313 | } |
328 | } |
314 | |
329 | |
315 | sub size_allocate { |
330 | sub size_allocate { |
… | |
… | |
341 | glDisable GL_TEXTURE_2D; |
356 | glDisable GL_TEXTURE_2D; |
342 | } |
357 | } |
343 | |
358 | |
344 | ############################################################################# |
359 | ############################################################################# |
345 | |
360 | |
346 | package Crossfire::Client::Widget::Frame; |
361 | package CFClient::Widget::Frame; |
347 | |
362 | |
348 | our @ISA = Crossfire::Client::Widget::Bin::; |
363 | our @ISA = CFClient::Widget::Bin::; |
349 | |
364 | |
350 | use SDL::OpenGL; |
365 | use SDL::OpenGL; |
351 | |
366 | |
352 | sub size_request { |
367 | sub size_request { |
353 | my ($self) = @_; |
368 | my ($self) = @_; |
… | |
… | |
387 | $chld->draw; |
402 | $chld->draw; |
388 | } |
403 | } |
389 | |
404 | |
390 | ############################################################################# |
405 | ############################################################################# |
391 | |
406 | |
392 | package Crossfire::Client::Widget::FancyFrame; |
407 | package CFClient::Widget::FancyFrame; |
393 | |
408 | |
394 | our @ISA = Crossfire::Client::Widget::Bin::; |
409 | our @ISA = CFClient::Widget::Bin::; |
395 | |
410 | |
396 | use SDL::OpenGL; |
411 | use SDL::OpenGL; |
397 | |
412 | |
398 | my @tex = |
413 | my @tex = |
399 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
414 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
400 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
415 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
401 | |
416 | |
402 | sub size_request { |
417 | sub size_request { |
403 | my ($self) = @_; |
418 | my ($self) = @_; |
404 | |
419 | |
… | |
… | |
470 | |
485 | |
471 | } |
486 | } |
472 | |
487 | |
473 | ############################################################################# |
488 | ############################################################################# |
474 | |
489 | |
475 | package Crossfire::Client::Widget::Table; |
490 | package CFClient::Widget::Table; |
476 | |
491 | |
477 | our @ISA = Crossfire::Client::Widget::Bin::; |
492 | our @ISA = CFClient::Widget::Bin::; |
478 | |
493 | |
479 | use SDL::OpenGL; |
494 | use SDL::OpenGL; |
480 | |
495 | |
481 | sub add { |
496 | sub add { |
482 | my ($self, $x, $y, $chld) = @_; |
497 | my ($self, $x, $y, $chld) = @_; |
… | |
… | |
557 | } |
572 | } |
558 | } |
573 | } |
559 | |
574 | |
560 | ############################################################################# |
575 | ############################################################################# |
561 | |
576 | |
562 | package Crossfire::Client::Widget::VBox; |
577 | package CFClient::Widget::VBox; |
563 | |
578 | |
564 | our @ISA = Crossfire::Client::Widget::Container::; |
579 | our @ISA = CFClient::Widget::Container::; |
565 | |
580 | |
566 | use SDL::OpenGL; |
581 | use SDL::OpenGL; |
567 | |
582 | |
568 | sub size_request { |
583 | sub size_request { |
569 | my ($self) = @_; |
584 | my ($self) = @_; |
… | |
… | |
617 | } |
632 | } |
618 | } |
633 | } |
619 | |
634 | |
620 | ############################################################################# |
635 | ############################################################################# |
621 | |
636 | |
622 | package Crossfire::Client::Widget::Label; |
637 | package CFClient::Widget::Label; |
623 | |
638 | |
624 | our @ISA = Crossfire::Client::Widget::; |
639 | our @ISA = CFClient::Widget::; |
625 | |
640 | |
626 | use SDL::OpenGL; |
641 | use SDL::OpenGL; |
627 | |
642 | |
628 | sub new { |
643 | sub new { |
629 | my ($class, $x, $y, $z, $height, $text) = @_; |
644 | my ($class, %arg) = @_; |
630 | |
|
|
631 | $height ||= $::FONTSIZE; |
|
|
632 | |
645 | |
633 | # TODO: color, and make height, xyz etc. optional |
646 | # TODO: color, and make height, xyz etc. optional |
634 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
647 | my $self = $class->SUPER::new ( |
|
|
648 | color => [1, 1, 1], |
|
|
649 | height => $::FONTSIZE, |
|
|
650 | text => "", |
|
|
651 | layout => new CFClient::Layout, |
|
|
652 | %arg |
|
|
653 | ); |
635 | |
654 | |
636 | $self->set_text ($text); |
655 | $self->set_text ($self->{text}); |
637 | |
656 | |
638 | $self |
657 | $self |
639 | } |
658 | } |
640 | |
659 | |
641 | sub set_text { |
660 | sub set_text { |
642 | my ($self, $text) = @_; |
661 | my ($self, $text) = @_; |
643 | |
662 | |
644 | $self->{text} = $text; |
663 | $self->{text} = $text; |
645 | $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; |
664 | $self->{layout}->set_markup ($text); |
646 | |
665 | |
647 | $self->update; |
666 | delete $self->{texture}; |
648 | } |
667 | } |
649 | |
668 | |
650 | sub get_text { |
669 | sub get_text { |
651 | my ($self, $text) = @_; |
670 | my ($self, $text) = @_; |
652 | |
671 | |
… | |
… | |
654 | } |
673 | } |
655 | |
674 | |
656 | sub size_request { |
675 | sub size_request { |
657 | my ($self) = @_; |
676 | my ($self) = @_; |
658 | |
677 | |
|
|
678 | $self->{layout}->set_width; |
|
|
679 | $self->{layout}->set_height ($self->{height}); |
|
|
680 | $self->{layout}->size |
659 | if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
681 | # if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
660 | ( |
682 | # ( |
661 | $self->{texture}{width}, |
683 | # $self->{texture}{width}, |
662 | $self->{texture}{height}, |
684 | # $self->{texture}{height}, |
663 | ) |
685 | # ) |
664 | } else { |
686 | # } else { |
665 | my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; |
687 | # my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height}; |
666 | |
688 | # |
667 | ($w, $h) |
689 | # ($w, $h) |
668 | } |
690 | # } |
|
|
691 | } |
669 | |
692 | |
|
|
693 | sub size_allocate { |
|
|
694 | my ($self, $w, $h) = @_; |
|
|
695 | |
|
|
696 | $self->SUPER::size_allocate ($w, $h); |
|
|
697 | delete $self->{texture}; |
670 | } |
698 | } |
671 | |
699 | |
672 | sub _draw { |
700 | sub _draw { |
673 | my ($self) = @_; |
701 | my ($self) = @_; |
674 | |
702 | |
675 | my $tex = $self->{texture}; |
703 | my $tex = $self->{texture} ||= do { |
|
|
704 | $self->{layout}->set_width ($self->{w}); |
|
|
705 | new_from_layout CFClient::Texture $self->{layout}; |
|
|
706 | }; |
676 | |
707 | |
677 | glEnable GL_BLEND; |
708 | glEnable GL_BLEND; |
678 | glEnable GL_TEXTURE_2D; |
709 | glEnable GL_TEXTURE_2D; |
679 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
710 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
680 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
711 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
681 | |
712 | |
682 | glColor 1, 0, 0, 1; # TODO color |
713 | glColor @{$self->{color}}; |
683 | |
714 | |
684 | $tex->draw_quad (0, 0); |
715 | $tex->draw_quad (0, 0); |
685 | |
716 | |
686 | glDisable GL_BLEND; |
717 | glDisable GL_BLEND; |
687 | glDisable GL_TEXTURE_2D; |
718 | glDisable GL_TEXTURE_2D; |
688 | } |
719 | } |
689 | |
720 | |
690 | ############################################################################# |
721 | ############################################################################# |
691 | |
722 | |
692 | package Crossfire::Client::Widget::Entry; |
723 | package CFClient::Widget::Entry; |
693 | |
724 | |
694 | our @ISA = Crossfire::Client::Widget::Label::; |
725 | our @ISA = CFClient::Widget::Label::; |
695 | |
726 | |
696 | use SDL; |
727 | use SDL; |
697 | use SDL::OpenGL; |
728 | use SDL::OpenGL; |
698 | |
729 | |
699 | sub key_down { |
730 | sub key_down { |
… | |
… | |
708 | |
739 | |
709 | if ($sym == SDLK_BACKSPACE) { |
740 | if ($sym == SDLK_BACKSPACE) { |
710 | substr $text, -1, 1, ''; |
741 | substr $text, -1, 1, ''; |
711 | } elsif ($uni) { |
742 | } elsif ($uni) { |
712 | $text .= chr $uni; |
743 | $text .= chr $uni; |
713 | print "$uni <$text>\n";#d# |
|
|
714 | } |
744 | } |
715 | |
745 | |
716 | $self->set_text ($text); |
746 | $self->set_text ($text); |
717 | } |
747 | } |
718 | |
748 | |
719 | sub button_down { |
749 | sub button_down { |
720 | my ($self, $ev) = @_; |
750 | my ($self, $ev) = @_; |
721 | |
751 | |
722 | $self->focus_in; |
752 | $self->focus_in; |
|
|
753 | } |
|
|
754 | |
|
|
755 | sub mouse_motion { |
|
|
756 | my ($self, $ev, $x, $y) = @_; |
|
|
757 | printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
723 | } |
758 | } |
724 | |
759 | |
725 | sub _draw { |
760 | sub _draw { |
726 | my ($self) = @_; |
761 | my ($self) = @_; |
727 | |
762 | |
… | |
… | |
741 | $self->SUPER::_draw; |
776 | $self->SUPER::_draw; |
742 | } |
777 | } |
743 | |
778 | |
744 | ############################################################################# |
779 | ############################################################################# |
745 | |
780 | |
746 | package Crossfire::Client::Widget::MapWidget; |
781 | package CFClient::Widget::MapWidget; |
747 | |
782 | |
748 | use strict; |
783 | use strict; |
749 | |
784 | |
750 | use List::Util qw(min max); |
785 | use List::Util qw(min max); |
751 | |
786 | |
752 | use SDL; |
787 | use SDL; |
753 | use SDL::OpenGL; |
788 | use SDL::OpenGL; |
754 | use SDL::OpenGL::Constants; |
789 | use SDL::OpenGL::Constants; |
755 | |
790 | |
756 | our @ISA = Crossfire::Client::Widget::; |
791 | our @ISA = CFClient::Widget::; |
|
|
792 | |
|
|
793 | sub new { |
|
|
794 | my $class = shift; |
|
|
795 | |
|
|
796 | $class->SUPER::new ( |
|
|
797 | z => -1, |
|
|
798 | list => (glGenLists 1), |
|
|
799 | @_ |
|
|
800 | ) |
|
|
801 | } |
757 | |
802 | |
758 | sub key_down { |
803 | sub key_down { |
759 | print "MAPKEYDOWN\n"; |
804 | print "MAPKEYDOWN\n"; |
760 | } |
805 | } |
761 | |
806 | |
… | |
… | |
767 | 1 + int $::WIDTH / 32, |
812 | 1 + int $::WIDTH / 32, |
768 | 1 + int $::HEIGHT / 32, |
813 | 1 + int $::HEIGHT / 32, |
769 | ) |
814 | ) |
770 | } |
815 | } |
771 | |
816 | |
|
|
817 | sub update { |
|
|
818 | my ($self) = @_; |
|
|
819 | |
|
|
820 | $self->{need_update} = 1; |
|
|
821 | } |
|
|
822 | |
772 | sub _draw { |
823 | sub _draw { |
773 | my ($self) = @_; |
824 | my ($self) = @_; |
774 | |
825 | |
|
|
826 | if (delete $self->{need_update}) { |
|
|
827 | glNewList $self->{list}, GL_COMPILE; |
|
|
828 | |
775 | my $mx = $::CONN->{mapx}; |
829 | my $mx = $::CONN->{mapx}; |
776 | my $my = $::CONN->{mapy}; |
830 | my $my = $::CONN->{mapy}; |
777 | |
831 | |
778 | my $map = $::CONN->{map}; |
832 | my $map = $::CONN->{map}; |
779 | |
833 | |
780 | my ($xofs, $yofs); |
834 | my ($xofs, $yofs); |
781 | |
835 | |
782 | my $sw = 1 + int $::WIDTH / 32; |
836 | my $sw = 1 + int $::WIDTH / 32; |
783 | my $sh = 1 + int $::HEIGHT / 32; |
837 | my $sh = 1 + int $::HEIGHT / 32; |
784 | |
838 | |
785 | if ($::CONN->{mapw} > $sw) { |
839 | if ($::CONN->{mapw} > $sw) { |
786 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
840 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
787 | } else { |
841 | } else { |
788 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
842 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
789 | } |
843 | } |
790 | |
844 | |
791 | if ($::CONN->{maph} > $sh) { |
845 | if ($::CONN->{maph} > $sh) { |
792 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
846 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
793 | } else { |
847 | } else { |
794 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
848 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
795 | } |
849 | } |
796 | |
850 | |
797 | glEnable GL_TEXTURE_2D; |
851 | glEnable GL_TEXTURE_2D; |
798 | glEnable GL_BLEND; |
852 | glEnable GL_BLEND; |
799 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
853 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
800 | |
854 | |
801 | my $sw4 = ($sw + 3) & ~3; |
855 | my $sw4 = ($sw + 3) & ~3; |
802 | my $lighting = "\x00" x ($sw4 * $sh); |
856 | my $darkness = "\x00" x ($sw4 * $sh); |
803 | |
857 | |
804 | for my $x (0 .. $sw - 1) { |
858 | for my $x (0 .. $sw - 1) { |
|
|
859 | my $row = $map->[$x + $xofs]; |
805 | for my $y (0 .. $sh - 1) { |
860 | for my $y (0 .. $sh - 1) { |
806 | |
861 | |
807 | my $cell = $map->[$x + $xofs][$y + $yofs] |
862 | my $cell = $row->[$y + $yofs] |
808 | or next; |
863 | or next; |
809 | |
864 | |
810 | my $darkness = $cell->[0] * (1 / 255); |
865 | my $dark = $cell->[0]; |
811 | if ($darkness < 0) { |
866 | if ($dark < 0) { |
812 | $darkness = $cell->[1] ? 0.1 : 0; |
867 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
868 | } else { |
|
|
869 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
813 | } |
870 | } |
814 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
|
|
815 | |
871 | |
816 | for my $num (grep $_, @$cell[1,2,3]) { |
872 | for my $num (grep $_, @$cell[1,2,3]) { |
817 | my $tex = $::CONN->{face}[$num]{texture} || next; |
873 | my $tex = $::CONN->{face}[$num]{texture} || next; |
|
|
874 | |
|
|
875 | my $w = $tex->{width}; |
|
|
876 | my $h = $tex->{height}; |
|
|
877 | |
|
|
878 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
818 | |
879 | } |
819 | my $w = $tex->{width}; |
|
|
820 | my $h = $tex->{height}; |
|
|
821 | |
|
|
822 | my $px = ($x + 1) * 32 - $w; |
|
|
823 | my $py = ($y + 1) * 32 - $h; |
|
|
824 | |
|
|
825 | $tex->draw_quad ($px, $py, $w, $h); |
|
|
826 | } |
880 | } |
827 | } |
881 | } |
828 | } |
|
|
829 | |
882 | |
830 | # if (1) { # higher quality darkness |
883 | # if (1) { # higher quality darkness |
831 | # $lighting =~ s/(.)/$1$1$1/gs; |
884 | # $lighting =~ s/(.)/$1$1$1/gs; |
832 | # my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; |
885 | # my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; |
833 | # |
886 | # |
… | |
… | |
835 | # |
888 | # |
836 | # $lighting = $pb->get_pixels; |
889 | # $lighting = $pb->get_pixels; |
837 | # $lighting =~ s/(.)../$1/gs; |
890 | # $lighting =~ s/(.)../$1/gs; |
838 | # } |
891 | # } |
839 | |
892 | |
840 | $lighting = new Crossfire::Client::Texture |
|
|
841 | width => $sw4, |
|
|
842 | height => $sh, |
|
|
843 | data => $lighting, |
|
|
844 | internalformat => GL_ALPHA, |
|
|
845 | format => GL_ALPHA; |
|
|
846 | |
|
|
847 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
893 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
848 | glColor 0.45, 0.45, 0.45, 1; |
|
|
849 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
894 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
850 | glBindTexture GL_TEXTURE_2D, $lighting->{name}; |
|
|
851 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
|
|
852 | |
895 | |
|
|
896 | $darkness = new CFClient::Texture |
|
|
897 | width => $sw4, |
|
|
898 | height => $sh, |
|
|
899 | data => $darkness, |
|
|
900 | internalformat => GL_ALPHA, |
|
|
901 | format => GL_ALPHA; |
|
|
902 | |
|
|
903 | glColor 0.45, 0.45, 0.45, 1; |
853 | $lighting->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
904 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
854 | |
905 | |
855 | glDisable GL_TEXTURE_2D; |
906 | glDisable GL_TEXTURE_2D; |
856 | glDisable GL_BLEND; |
907 | glDisable GL_BLEND; |
|
|
908 | |
|
|
909 | glEndList; |
|
|
910 | } |
|
|
911 | |
|
|
912 | glCallList $self->{list}; |
857 | } |
913 | } |
858 | |
914 | |
859 | my %DIR = ( |
915 | my %DIR = ( |
860 | SDLK_KP8, [1, "north"], |
916 | SDLK_KP8, [1, "north"], |
861 | SDLK_KP9, [2, "northeast"], |
917 | SDLK_KP9, [2, "northeast"], |
… | |
… | |
907 | } |
963 | } |
908 | } |
964 | } |
909 | |
965 | |
910 | ############################################################################# |
966 | ############################################################################# |
911 | |
967 | |
912 | package Crossfire::Client::Widget::Animator; |
968 | package CFClient::Widget::Animator; |
913 | |
969 | |
914 | use SDL::OpenGL; |
970 | use SDL::OpenGL; |
915 | |
971 | |
916 | our @ISA = Crossfire::Client::Widget::Bin::; |
972 | our @ISA = CFClient::Widget::Bin::; |
917 | |
973 | |
918 | sub moveto { |
974 | sub moveto { |
919 | my ($self, $x, $y) = @_; |
975 | my ($self, $x, $y) = @_; |
920 | |
976 | |
921 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
977 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
… | |
… | |
926 | } |
982 | } |
927 | |
983 | |
928 | sub animate { |
984 | sub animate { |
929 | my ($self, $interval) = @_; |
985 | my ($self, $interval) = @_; |
930 | |
986 | |
931 | printf "%5.2f\n", 1 / $interval;#d# |
|
|
932 | |
|
|
933 | $self->{time} -= $interval * $self->{speed}; |
987 | $self->{time} -= $interval * $self->{speed}; |
934 | if ($self->{time} <= 0) { |
988 | if ($self->{time} <= 0) { |
935 | $self->{time} = 0; |
989 | $self->{time} = 0; |
936 | ::animation_stop $self; |
990 | ::animation_stop $self; |
937 | } |
991 | } |
… | |
… | |
951 | glPopMatrix; |
1005 | glPopMatrix; |
952 | } |
1006 | } |
953 | |
1007 | |
954 | ############################################################################# |
1008 | ############################################################################# |
955 | |
1009 | |
956 | package Crossfire::Client::Widget::Toplevel; |
1010 | package CFClient::Widget::Toplevel; |
957 | |
1011 | |
958 | our @ISA = Crossfire::Client::Widget::Container::; |
1012 | our @ISA = CFClient::Widget::Container::; |
959 | |
1013 | |
960 | sub size_request { |
1014 | sub size_request { |
961 | ($::WIDTH, $::HEIGHT) |
1015 | ($::WIDTH, $::HEIGHT) |
962 | } |
1016 | } |
963 | |
1017 | |
… | |
… | |
968 | |
1022 | |
969 | $_->size_allocate ($_->size_request) |
1023 | $_->size_allocate ($_->size_request) |
970 | for @{$self->{children}}; |
1024 | for @{$self->{children}}; |
971 | } |
1025 | } |
972 | |
1026 | |
|
|
1027 | sub translate { |
|
|
1028 | my ($self, $x, $y) = @_; |
|
|
1029 | |
|
|
1030 | ($x, $y) |
|
|
1031 | } |
|
|
1032 | |
973 | sub update { |
1033 | sub update { |
974 | my ($self) = @_; |
1034 | my ($self) = @_; |
975 | |
1035 | |
976 | $self->size_allocate ($self->size_request); |
1036 | $self->size_allocate ($self->size_request); |
977 | ::refresh (); |
1037 | ::refresh (); |
… | |
… | |
991 | $self->_draw; |
1051 | $self->_draw; |
992 | } |
1052 | } |
993 | |
1053 | |
994 | ############################################################################# |
1054 | ############################################################################# |
995 | |
1055 | |
996 | package Crossfire::Client::Widget; |
1056 | package CFClient::Widget; |
997 | |
1057 | |
998 | $TOPLEVEL = new Crossfire::Client::Widget::Toplevel; |
1058 | $TOPLEVEL = new CFClient::Widget::Toplevel; |
999 | |
1059 | |
1000 | 1 |
1060 | 1 |
1001 | |
1061 | |