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 | |
… | |
… | |
95 | sub size_allocate { |
97 | sub size_allocate { |
96 | my ($self, $w, $h) = @_; |
98 | my ($self, $w, $h) = @_; |
97 | |
99 | |
98 | $self->{w} = $w; |
100 | $self->{w} = $w; |
99 | $self->{h} = $h; |
101 | $self->{h} = $h; |
|
|
102 | } |
|
|
103 | |
|
|
104 | # translate global koordinates to local coordinate system |
|
|
105 | sub translate { |
|
|
106 | my ($self, $x, $y) = @_; |
|
|
107 | |
|
|
108 | $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); |
100 | } |
109 | } |
101 | |
110 | |
102 | sub focus_in { |
111 | sub focus_in { |
103 | my ($self) = @_; |
112 | my ($self) = @_; |
104 | |
113 | |
… | |
… | |
201 | #$self->deactivate; |
210 | #$self->deactivate; |
202 | } |
211 | } |
203 | |
212 | |
204 | ############################################################################# |
213 | ############################################################################# |
205 | |
214 | |
206 | package Crossfire::Client::Widget::Container; |
215 | package CFClient::Widget::Container; |
207 | |
216 | |
208 | our @ISA = Crossfire::Client::Widget::; |
217 | our @ISA = CFClient::Widget::; |
209 | |
218 | |
210 | sub new { |
219 | sub new { |
211 | my ($class, @widgets) = @_; |
220 | my ($class, %arg) = @_; |
|
|
221 | |
|
|
222 | my $children = delete $arg{children} || []; |
212 | |
223 | |
213 | my $self = $class->SUPER::new (children => []); |
224 | my $self = $class->SUPER::new (children => []); |
214 | $self->add ($_) for @widgets; |
225 | $self->add ($_) for @$children; |
215 | |
226 | |
216 | $self |
227 | $self |
217 | } |
228 | } |
218 | |
229 | |
219 | sub add { |
230 | sub add { |
… | |
… | |
260 | $_->draw for @{$self->{children}}; |
271 | $_->draw for @{$self->{children}}; |
261 | } |
272 | } |
262 | |
273 | |
263 | ############################################################################# |
274 | ############################################################################# |
264 | |
275 | |
265 | package Crossfire::Client::Widget::Bin; |
276 | package CFClient::Widget::Bin; |
266 | |
277 | |
267 | our @ISA = Crossfire::Client::Widget::Container::; |
278 | our @ISA = CFClient::Widget::Container::; |
268 | |
279 | |
269 | sub child { $_[0]->{children}[0] } |
280 | sub child { $_[0]->{children}[0] } |
270 | |
281 | |
271 | sub size_request { |
282 | sub size_request { |
272 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
283 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
… | |
… | |
280 | if $self->{children}[0] |
291 | if $self->{children}[0] |
281 | } |
292 | } |
282 | |
293 | |
283 | ############################################################################# |
294 | ############################################################################# |
284 | |
295 | |
285 | package Crossfire::Client::Widget::Window; |
296 | package CFClient::Widget::Window; |
286 | |
297 | |
287 | our @ISA = Crossfire::Client::Widget::Bin::; |
298 | our @ISA = CFClient::Widget::Bin::; |
288 | |
299 | |
289 | use SDL::OpenGL; |
300 | use SDL::OpenGL; |
290 | |
301 | |
291 | sub new { |
302 | sub new { |
292 | my ($class, $x, $y, $z, $w, $h) = @_; |
303 | my ($class, %arg) = @_; |
293 | |
304 | |
294 | my $self = $class->SUPER::new; |
305 | my $self = $class->SUPER::new (%arg); |
295 | |
|
|
296 | @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h); |
|
|
297 | } |
306 | } |
298 | |
307 | |
299 | sub update { |
308 | sub update { |
300 | my ($self) = @_; |
309 | my ($self) = @_; |
301 | |
310 | |
|
|
311 | # we want to do this delayed... |
302 | $self->render_chld; |
312 | $self->render_chld; |
303 | $self->SUPER::update; |
313 | $self->SUPER::update; |
304 | } |
314 | } |
305 | |
315 | |
306 | sub render_chld { |
316 | sub render_chld { |
307 | my ($self) = @_; |
317 | my ($self) = @_; |
308 | |
318 | |
309 | $self->{texture} = |
319 | $self->{texture} = |
310 | Crossfire::Client::Texture->new_from_opengl ( |
320 | CFClient::Texture->new_from_opengl ( |
311 | $self->{w}, $self->{h}, sub { $self->child->draw } |
321 | $self->{w}, $self->{h}, sub { $self->child->draw } |
312 | ); |
322 | ); |
313 | } |
323 | } |
314 | |
324 | |
315 | sub size_allocate { |
325 | sub size_allocate { |
… | |
… | |
341 | glDisable GL_TEXTURE_2D; |
351 | glDisable GL_TEXTURE_2D; |
342 | } |
352 | } |
343 | |
353 | |
344 | ############################################################################# |
354 | ############################################################################# |
345 | |
355 | |
346 | package Crossfire::Client::Widget::Frame; |
356 | package CFClient::Widget::Frame; |
347 | |
357 | |
348 | our @ISA = Crossfire::Client::Widget::Bin::; |
358 | our @ISA = CFClient::Widget::Bin::; |
349 | |
359 | |
350 | use SDL::OpenGL; |
360 | use SDL::OpenGL; |
351 | |
361 | |
352 | sub size_request { |
362 | sub size_request { |
353 | my ($self) = @_; |
363 | my ($self) = @_; |
… | |
… | |
387 | $chld->draw; |
397 | $chld->draw; |
388 | } |
398 | } |
389 | |
399 | |
390 | ############################################################################# |
400 | ############################################################################# |
391 | |
401 | |
392 | package Crossfire::Client::Widget::FancyFrame; |
402 | package CFClient::Widget::FancyFrame; |
393 | |
403 | |
394 | our @ISA = Crossfire::Client::Widget::Bin::; |
404 | our @ISA = CFClient::Widget::Bin::; |
395 | |
405 | |
396 | use SDL::OpenGL; |
406 | use SDL::OpenGL; |
397 | |
407 | |
398 | my @tex = |
408 | my @tex = |
399 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
409 | 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); |
410 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
401 | |
411 | |
402 | sub size_request { |
412 | sub size_request { |
403 | my ($self) = @_; |
413 | my ($self) = @_; |
404 | |
414 | |
… | |
… | |
470 | |
480 | |
471 | } |
481 | } |
472 | |
482 | |
473 | ############################################################################# |
483 | ############################################################################# |
474 | |
484 | |
475 | package Crossfire::Client::Widget::Table; |
485 | package CFClient::Widget::Table; |
476 | |
486 | |
477 | our @ISA = Crossfire::Client::Widget::Bin::; |
487 | our @ISA = CFClient::Widget::Bin::; |
478 | |
488 | |
479 | use SDL::OpenGL; |
489 | use SDL::OpenGL; |
480 | |
490 | |
481 | sub add { |
491 | sub add { |
482 | my ($self, $x, $y, $chld) = @_; |
492 | my ($self, $x, $y, $chld) = @_; |
… | |
… | |
557 | } |
567 | } |
558 | } |
568 | } |
559 | |
569 | |
560 | ############################################################################# |
570 | ############################################################################# |
561 | |
571 | |
562 | package Crossfire::Client::Widget::VBox; |
572 | package CFClient::Widget::VBox; |
563 | |
573 | |
564 | our @ISA = Crossfire::Client::Widget::Container::; |
574 | our @ISA = CFClient::Widget::Container::; |
565 | |
575 | |
566 | use SDL::OpenGL; |
576 | use SDL::OpenGL; |
567 | |
577 | |
568 | sub size_request { |
578 | sub size_request { |
569 | my ($self) = @_; |
579 | my ($self) = @_; |
… | |
… | |
617 | } |
627 | } |
618 | } |
628 | } |
619 | |
629 | |
620 | ############################################################################# |
630 | ############################################################################# |
621 | |
631 | |
622 | package Crossfire::Client::Widget::Label; |
632 | package CFClient::Widget::Label; |
623 | |
633 | |
624 | our @ISA = Crossfire::Client::Widget::; |
634 | our @ISA = CFClient::Widget::; |
625 | |
635 | |
626 | use SDL::OpenGL; |
636 | use SDL::OpenGL; |
627 | |
637 | |
628 | sub new { |
638 | sub new { |
629 | my ($class, $x, $y, $z, $height, $text) = @_; |
639 | my ($class, %arg) = @_; |
630 | |
|
|
631 | $height ||= $::FONTSIZE; |
|
|
632 | |
640 | |
633 | # TODO: color, and make height, xyz etc. optional |
641 | # TODO: color, and make height, xyz etc. optional |
634 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
642 | my $self = $class->SUPER::new ( |
|
|
643 | color => [1, 1, 1], |
|
|
644 | height => $::FONTSIZE, |
|
|
645 | text => "", |
|
|
646 | layout => new CFClient::Layout, |
|
|
647 | %arg |
|
|
648 | ); |
635 | |
649 | |
636 | $self->set_text ($text); |
650 | $self->set_text ($self->{text}); |
637 | |
651 | |
638 | $self |
652 | $self |
639 | } |
653 | } |
640 | |
654 | |
641 | sub set_text { |
655 | sub set_text { |
642 | my ($self, $text) = @_; |
656 | my ($self, $text) = @_; |
643 | |
657 | |
644 | $self->{text} = $text; |
658 | $self->{text} = $text; |
645 | $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; |
659 | $self->{layout}->set_markup ($text); |
646 | |
660 | |
647 | $self->update; |
661 | delete $self->{texture}; |
648 | } |
662 | } |
649 | |
663 | |
650 | sub get_text { |
664 | sub get_text { |
651 | my ($self, $text) = @_; |
665 | my ($self, $text) = @_; |
652 | |
666 | |
… | |
… | |
654 | } |
668 | } |
655 | |
669 | |
656 | sub size_request { |
670 | sub size_request { |
657 | my ($self) = @_; |
671 | my ($self) = @_; |
658 | |
672 | |
|
|
673 | $self->{layout}->set_width; |
|
|
674 | $self->{layout}->set_height ($self->{height}); |
|
|
675 | $self->{layout}->size |
659 | if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
676 | # if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
660 | ( |
677 | # ( |
661 | $self->{texture}{width}, |
678 | # $self->{texture}{width}, |
662 | $self->{texture}{height}, |
679 | # $self->{texture}{height}, |
663 | ) |
680 | # ) |
664 | } else { |
681 | # } else { |
665 | my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; |
682 | # my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height}; |
666 | |
683 | # |
667 | ($w, $h) |
684 | # ($w, $h) |
668 | } |
685 | # } |
|
|
686 | } |
669 | |
687 | |
|
|
688 | sub size_allocate { |
|
|
689 | my ($self, $w, $h) = @_; |
|
|
690 | |
|
|
691 | $self->SUPER::size_allocate ($w, $h); |
|
|
692 | delete $self->{texture}; |
670 | } |
693 | } |
671 | |
694 | |
672 | sub _draw { |
695 | sub _draw { |
673 | my ($self) = @_; |
696 | my ($self) = @_; |
674 | |
697 | |
675 | my $tex = $self->{texture}; |
698 | my $tex = $self->{texture} ||= do { |
|
|
699 | $self->{layout}->set_width ($self->{w}); |
|
|
700 | new_from_layout CFClient::Texture $self->{layout}; |
|
|
701 | }; |
676 | |
702 | |
677 | glEnable GL_BLEND; |
703 | glEnable GL_BLEND; |
678 | glEnable GL_TEXTURE_2D; |
704 | glEnable GL_TEXTURE_2D; |
679 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
705 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
680 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
706 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
681 | |
707 | |
682 | glColor 1, 0, 0, 1; # TODO color |
708 | glColor @{$self->{color}}; |
683 | |
709 | |
684 | $tex->draw_quad (0, 0); |
710 | $tex->draw_quad (0, 0); |
685 | |
711 | |
686 | glDisable GL_BLEND; |
712 | glDisable GL_BLEND; |
687 | glDisable GL_TEXTURE_2D; |
713 | glDisable GL_TEXTURE_2D; |
688 | } |
714 | } |
689 | |
715 | |
690 | ############################################################################# |
716 | ############################################################################# |
691 | |
717 | |
692 | package Crossfire::Client::Widget::Entry; |
718 | package CFClient::Widget::Entry; |
693 | |
719 | |
694 | our @ISA = Crossfire::Client::Widget::Label::; |
720 | our @ISA = CFClient::Widget::Label::; |
695 | |
721 | |
696 | use SDL; |
722 | use SDL; |
697 | use SDL::OpenGL; |
723 | use SDL::OpenGL; |
698 | |
724 | |
699 | sub key_down { |
725 | sub key_down { |
… | |
… | |
708 | |
734 | |
709 | if ($sym == SDLK_BACKSPACE) { |
735 | if ($sym == SDLK_BACKSPACE) { |
710 | substr $text, -1, 1, ''; |
736 | substr $text, -1, 1, ''; |
711 | } elsif ($uni) { |
737 | } elsif ($uni) { |
712 | $text .= chr $uni; |
738 | $text .= chr $uni; |
713 | print "$uni <$text>\n";#d# |
|
|
714 | } |
739 | } |
715 | |
740 | |
716 | $self->set_text ($text); |
741 | $self->set_text ($text); |
717 | } |
742 | } |
718 | |
743 | |
719 | sub button_down { |
744 | sub button_down { |
720 | my ($self, $ev) = @_; |
745 | my ($self, $ev) = @_; |
721 | |
746 | |
722 | $self->focus_in; |
747 | $self->focus_in; |
|
|
748 | } |
|
|
749 | |
|
|
750 | sub mouse_motion { |
|
|
751 | my ($self, $ev, $x, $y) = @_; |
|
|
752 | printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
723 | } |
753 | } |
724 | |
754 | |
725 | sub _draw { |
755 | sub _draw { |
726 | my ($self) = @_; |
756 | my ($self) = @_; |
727 | |
757 | |
… | |
… | |
741 | $self->SUPER::_draw; |
771 | $self->SUPER::_draw; |
742 | } |
772 | } |
743 | |
773 | |
744 | ############################################################################# |
774 | ############################################################################# |
745 | |
775 | |
746 | package Crossfire::Client::Widget::MapWidget; |
776 | package CFClient::Widget::MapWidget; |
747 | |
777 | |
748 | use strict; |
778 | use strict; |
749 | |
779 | |
750 | use List::Util qw(min max); |
780 | use List::Util qw(min max); |
751 | |
781 | |
752 | use SDL; |
782 | use SDL; |
753 | use SDL::OpenGL; |
783 | use SDL::OpenGL; |
754 | use SDL::OpenGL::Constants; |
784 | use SDL::OpenGL::Constants; |
755 | |
785 | |
756 | our @ISA = Crossfire::Client::Widget::; |
786 | our @ISA = CFClient::Widget::; |
|
|
787 | |
|
|
788 | sub new { |
|
|
789 | my $class = shift; |
|
|
790 | |
|
|
791 | $class->SUPER::new (z => -1, @_) |
|
|
792 | } |
757 | |
793 | |
758 | sub key_down { |
794 | sub key_down { |
759 | print "MAPKEYDOWN\n"; |
795 | print "MAPKEYDOWN\n"; |
760 | } |
796 | } |
761 | |
797 | |
… | |
… | |
797 | glEnable GL_TEXTURE_2D; |
833 | glEnable GL_TEXTURE_2D; |
798 | glEnable GL_BLEND; |
834 | glEnable GL_BLEND; |
799 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
835 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
800 | |
836 | |
801 | my $sw4 = ($sw + 3) & ~3; |
837 | my $sw4 = ($sw + 3) & ~3; |
802 | my $lighting = "\x00" x ($sw4 * $sh); |
838 | my $darkness = "\x00" x ($sw4 * $sh); |
803 | |
839 | |
804 | for my $x (0 .. $sw - 1) { |
840 | for my $x (0 .. $sw - 1) { |
|
|
841 | my $row = $map->[$x + $xofs]; |
805 | for my $y (0 .. $sh - 1) { |
842 | for my $y (0 .. $sh - 1) { |
806 | |
843 | |
807 | my $cell = $map->[$x + $xofs][$y + $yofs] |
844 | my $cell = $row->[$y + $yofs] |
808 | or next; |
845 | or next; |
809 | |
846 | |
810 | my $darkness = $cell->[0] * (1 / 255); |
847 | my $dark = $cell->[0]; |
811 | if ($darkness < 0) { |
848 | if ($dark < 0) { |
812 | $darkness = $cell->[1] ? 0.1 : 0; |
849 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
850 | } else { |
|
|
851 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
813 | } |
852 | } |
814 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
|
|
815 | |
853 | |
816 | for my $num (grep $_, @$cell[1,2,3]) { |
854 | for my $num (grep $_, @$cell[1,2,3]) { |
817 | my $tex = $::CONN->{face}[$num]{texture} || next; |
855 | my $tex = $::CONN->{face}[$num]{texture} || next; |
818 | |
856 | |
819 | my $w = $tex->{width}; |
857 | my $w = $tex->{width}; |
820 | my $h = $tex->{height}; |
858 | my $h = $tex->{height}; |
821 | |
859 | |
822 | my $px = ($x + 1) * 32 - $w; |
860 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
823 | my $py = ($y + 1) * 32 - $h; |
|
|
824 | |
|
|
825 | $tex->draw_quad ($px, $py, $w, $h); |
|
|
826 | } |
861 | } |
827 | } |
862 | } |
828 | } |
863 | } |
829 | |
864 | |
830 | # if (1) { # higher quality darkness |
865 | # if (1) { # higher quality darkness |
… | |
… | |
835 | # |
870 | # |
836 | # $lighting = $pb->get_pixels; |
871 | # $lighting = $pb->get_pixels; |
837 | # $lighting =~ s/(.)../$1/gs; |
872 | # $lighting =~ s/(.)../$1/gs; |
838 | # } |
873 | # } |
839 | |
874 | |
840 | $lighting = new Crossfire::Client::Texture |
875 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
876 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
877 | |
|
|
878 | $darkness = new CFClient::Texture |
841 | width => $sw4, |
879 | width => $sw4, |
842 | height => $sh, |
880 | height => $sh, |
843 | data => $lighting, |
881 | data => $darkness, |
844 | internalformat => GL_ALPHA, |
882 | internalformat => GL_ALPHA, |
845 | format => GL_ALPHA; |
883 | format => GL_ALPHA; |
846 | |
884 | |
847 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
848 | glColor 0.45, 0.45, 0.45, 1; |
885 | glColor 0.45, 0.45, 0.45, 1; |
849 | 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 | |
|
|
853 | $lighting->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
886 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
854 | |
887 | |
855 | glDisable GL_TEXTURE_2D; |
888 | glDisable GL_TEXTURE_2D; |
856 | glDisable GL_BLEND; |
889 | glDisable GL_BLEND; |
857 | } |
890 | } |
858 | |
891 | |
… | |
… | |
907 | } |
940 | } |
908 | } |
941 | } |
909 | |
942 | |
910 | ############################################################################# |
943 | ############################################################################# |
911 | |
944 | |
912 | package Crossfire::Client::Widget::Animator; |
945 | package CFClient::Widget::Animator; |
913 | |
946 | |
914 | use SDL::OpenGL; |
947 | use SDL::OpenGL; |
915 | |
948 | |
916 | our @ISA = Crossfire::Client::Widget::Bin::; |
949 | our @ISA = CFClient::Widget::Bin::; |
917 | |
950 | |
918 | sub moveto { |
951 | sub moveto { |
919 | my ($self, $x, $y) = @_; |
952 | my ($self, $x, $y) = @_; |
920 | |
953 | |
921 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
954 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
… | |
… | |
926 | } |
959 | } |
927 | |
960 | |
928 | sub animate { |
961 | sub animate { |
929 | my ($self, $interval) = @_; |
962 | my ($self, $interval) = @_; |
930 | |
963 | |
931 | printf "%5.2f\n", 1 / $interval;#d# |
|
|
932 | |
|
|
933 | $self->{time} -= $interval * $self->{speed}; |
964 | $self->{time} -= $interval * $self->{speed}; |
934 | if ($self->{time} <= 0) { |
965 | if ($self->{time} <= 0) { |
935 | $self->{time} = 0; |
966 | $self->{time} = 0; |
936 | ::animation_stop $self; |
967 | ::animation_stop $self; |
937 | } |
968 | } |
… | |
… | |
951 | glPopMatrix; |
982 | glPopMatrix; |
952 | } |
983 | } |
953 | |
984 | |
954 | ############################################################################# |
985 | ############################################################################# |
955 | |
986 | |
956 | package Crossfire::Client::Widget::Toplevel; |
987 | package CFClient::Widget::Toplevel; |
957 | |
988 | |
958 | our @ISA = Crossfire::Client::Widget::Container::; |
989 | our @ISA = CFClient::Widget::Container::; |
959 | |
990 | |
960 | sub size_request { |
991 | sub size_request { |
961 | ($::WIDTH, $::HEIGHT) |
992 | ($::WIDTH, $::HEIGHT) |
962 | } |
993 | } |
963 | |
994 | |
… | |
… | |
968 | |
999 | |
969 | $_->size_allocate ($_->size_request) |
1000 | $_->size_allocate ($_->size_request) |
970 | for @{$self->{children}}; |
1001 | for @{$self->{children}}; |
971 | } |
1002 | } |
972 | |
1003 | |
|
|
1004 | sub translate { |
|
|
1005 | my ($self, $x, $y) = @_; |
|
|
1006 | |
|
|
1007 | ($x, $y) |
|
|
1008 | } |
|
|
1009 | |
973 | sub update { |
1010 | sub update { |
974 | my ($self) = @_; |
1011 | my ($self) = @_; |
975 | |
1012 | |
976 | $self->size_allocate ($self->size_request); |
1013 | $self->size_allocate ($self->size_request); |
977 | ::refresh (); |
1014 | ::refresh (); |
… | |
… | |
991 | $self->_draw; |
1028 | $self->_draw; |
992 | } |
1029 | } |
993 | |
1030 | |
994 | ############################################################################# |
1031 | ############################################################################# |
995 | |
1032 | |
996 | package Crossfire::Client::Widget; |
1033 | package CFClient::Widget; |
997 | |
1034 | |
998 | $TOPLEVEL = new Crossfire::Client::Widget::Toplevel; |
1035 | $TOPLEVEL = new CFClient::Widget::Toplevel; |
999 | |
1036 | |
1000 | 1 |
1037 | 1 |
1001 | |
1038 | |