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