ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.45 by root, Sun Apr 9 22:19:03 2006 UTC vs.
Revision 1.57 by root, Mon Apr 10 22:53:49 2006 UTC

7use SDL::OpenGL; 7use SDL::OpenGL;
8use SDL::OpenGL::Constants; 8use SDL::OpenGL::Constants;
9 9
10use Crossfire::Client; 10use Crossfire::Client;
11 11
12our $FOCUS; # the widget with current focus 12our ($FOCUS, $HOVER, $GRAB); # various widgets
13
14our $TOPLEVEL;
15our $BUTTON_STATE;
13 16
14# class methods for events 17# class methods for events
15sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 18sub feed_sdl_key_down_event {
16sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } 19 $FOCUS->key_down ($_[0]) if $FOCUS;
20}
21
22sub feed_sdl_key_up_event {
23 $FOCUS->key_up ($_[0]) if $FOCUS;
24}
25
17sub feed_sdl_button_down_event { } 26sub 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) if $GRAB;
40}
41
18sub feed_sdl_button_up_event { } 42sub 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 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab;
53 $GRAB->update if $GRAB;
54 }
55}
56
57sub feed_sdl_motion_event {
58 my ($ev) = @_;
59 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
60
61 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
62
63 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget;
65
66 $hover->update if $hover;
67 $HOVER->update if $HOVER;
68 }
69
70 $HOVER->mouse_motion ($ev) if $HOVER;
71}
19 72
20sub new { 73sub new {
21 my $class = shift; 74 my $class = shift;
22 75
23 bless { @_ }, $class 76 bless { @_ }, $class
45 $self->{w} = $w; 98 $self->{w} = $w;
46 $self->{h} = $h; 99 $self->{h} = $h;
47} 100}
48 101
49sub focus_in { 102sub focus_in {
50 my ($widget) = @_; 103 my ($self) = @_;
51 $FOCUS = $widget; 104
105 my $focus = $FOCUS; $FOCUS = $self;
106 $focus->update if $focus;
107 $FOCUS->update;
52} 108}
53 109
54sub focus_out { 110sub focus_out {
55 my ($widget) = @_; 111 my ($self) = @_;
56}
57 112
58sub key_down { 113 return unless $FOCUS == $self;
59 my ($widget, $sdlev) = @_;
60}
61 114
62sub key_up { 115 my $focus = $FOCUS; undef $FOCUS;
63 my ($widget, $sdlev) = @_; 116 $focus->update if $focus; #?
64} 117}
65 118
119sub mouse_motion { }
120sub button_up { }
66sub button_down { 121sub button_down { }
67 my ($widget, $sdlev) = @_; 122sub key_down { }
68} 123sub key_up { }
69 124
70sub button_up {
71 my ($widget, $sdlev) = @_;
72}
73
74sub w { $_[0]->{w} = $_[1] if $_[1]; $_[0]->{w} } 125sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} }
75sub h { $_[0]->{h} = $_[1] if $_[1]; $_[0]->{h} } 126sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} }
76sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } 127sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
77sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } 128sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
78sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} } 129sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
79 130
80sub draw { 131sub draw {
81 my ($self) = @_; 132 my ($self) = @_;
82 133
83 glPushMatrix; 134 glPushMatrix;
84 glTranslate $self->{x}, $self->{y}, 0; 135 glTranslate $self->{x}, $self->{y}, 0;
85 $self->_draw; 136 $self->_draw;
137 if ($self == $HOVER) {
138 glColor 1, 1, 1, 0.4;
139 glEnable GL_BLEND;
140 glBegin GL_QUADS;
141 glVertex 0 , 0;
142 glVertex $self->{w}, 0;
143 glVertex $self->{w}, $self->{h};
144 glVertex 0 , $self->{h};
145 glEnd;
146 glDisable GL_BLEND;
147 }
86 glPopMatrix; 148 glPopMatrix;
87} 149}
88 150
89sub _draw { 151sub _draw {
90 my ($self) = @_; 152 my ($self) = @_;
182 $x -= $self->{x}; 244 $x -= $self->{x};
183 $y -= $self->{y}; 245 $y -= $self->{y};
184 246
185 my $res; 247 my $res;
186 248
187 for (@{ $self->{children} }) { 249 for (reverse @{ $self->{children} }) {
188 $res = $_->find_widget ($x, $y) 250 $res = $_->find_widget ($x, $y)
189 and return $res; 251 and return $res;
190 } 252 }
191 253
192 () 254 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
193} 255}
194 256
195sub _draw { 257sub _draw {
196 my ($self) = @_; 258 my ($self) = @_;
197 259
214 my ($self, $w, $h) = @_; 276 my ($self, $w, $h) = @_;
215 277
216 $self->SUPER::size_allocate ($w, $h); 278 $self->SUPER::size_allocate ($w, $h);
217 $self->{children}[0]->size_allocate ($w, $h) 279 $self->{children}[0]->size_allocate ($w, $h)
218 if $self->{children}[0] 280 if $self->{children}[0]
219}
220
221#############################################################################
222
223package Crossfire::Client::Widget::Toplevel;
224
225our @ISA = Crossfire::Client::Widget::Container::;
226
227sub update {
228 my ($self) = @_;
229
230 ::refresh ();
231}
232
233sub add {
234 my ($self, $widget) = @_;
235
236 $self->SUPER::add ($widget);
237
238 $widget->size_allocate ($widget->size_request);
239} 281}
240 282
241############################################################################# 283#############################################################################
242 284
243package Crossfire::Client::Widget::Window; 285package Crossfire::Client::Widget::Window;
290 or return; 332 or return;
291 333
292 glEnable GL_BLEND; 334 glEnable GL_BLEND;
293 glEnable GL_TEXTURE_2D; 335 glEnable GL_TEXTURE_2D;
294 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 336 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
295 glBindTexture GL_TEXTURE_2D, $tex->{name};
296 337
297 glBegin GL_QUADS; 338 $tex->draw_quad (0, 0, $w, $h);
298 glTexCoord 0, 0; glVertex 0, 0;
299 glTexCoord 0, 1; glVertex 0, $h;
300 glTexCoord 1, 1; glVertex $w, $h;
301 glTexCoord 1, 0; glVertex $w, 0;
302 glEnd;
303 339
304 glDisable GL_BLEND; 340 glDisable GL_BLEND;
305 glDisable GL_TEXTURE_2D; 341 glDisable GL_TEXTURE_2D;
306} 342}
307 343
340 376
341 my ($w, $h) = $chld->size_request; 377 my ($w, $h) = $chld->size_request;
342 378
343 glBegin GL_QUADS; 379 glBegin GL_QUADS;
344 glColor 0, 0, 0; 380 glColor 0, 0, 0;
345 glTexCoord 0, 0; glVertex 0 , 0; 381 glVertex 0 , 0;
346 glTexCoord 0, 1; glVertex 0 , $h + 4; 382 glVertex 0 , $h + 4;
347 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 383 glVertex $w + 4 , $h + 4;
348 glTexCoord 1, 0; glVertex $w + 4 , 0; 384 glVertex $w + 4 , 0;
349 glEnd; 385 glEnd;
350 386
351 $chld->draw; 387 $chld->draw;
352} 388}
353 389
403 glEnable GL_TEXTURE_2D; 439 glEnable GL_TEXTURE_2D;
404 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 440 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
405 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 441 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
406 442
407 my $top = $tex[1]; 443 my $top = $tex[1];
408 glBindTexture GL_TEXTURE_2D, $top->{name}; 444 $top->draw_quad (0, 0, $w, $top->{height});
409
410 glBegin GL_QUADS;
411 glTexCoord 0, 0; glVertex 0 , 0;
412 glTexCoord 0, 1; glVertex 0 , $top->{height};
413 glTexCoord 1, 1; glVertex $w , $top->{height};
414 glTexCoord 1, 0; glVertex $w , 0;
415 glEnd;
416 445
417 my $left = $tex[3]; 446 my $left = $tex[3];
418 glBindTexture GL_TEXTURE_2D, $left->{name}; 447 $left->draw_quad (0, $top->{height}, $left->{width}, $ch);
419
420 glBegin GL_QUADS;
421 glTexCoord 0, 0; glVertex 0 , $top->{height};
422 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch;
423 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch;
424 glTexCoord 1, 0; glVertex $left->{width}, $top->{height};
425 glEnd;
426 448
427 my $right = $tex[2]; 449 my $right = $tex[2];
428 glBindTexture GL_TEXTURE_2D, $right->{name}; 450 $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch);
429
430 glBegin GL_QUADS;
431 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height};
432 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch;
433 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch;
434 glTexCoord 1, 0; glVertex $w , $top->{height};
435 glEnd;
436 451
437 my $bottom = $tex[4]; 452 my $bottom = $tex[4];
438 glBindTexture GL_TEXTURE_2D, $bottom->{name}; 453 $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height});
439
440 glBegin GL_QUADS;
441 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height};
442 glTexCoord 0, 1; glVertex 0 , $h;
443 glTexCoord 1, 1; glVertex $w , $h;
444 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height};
445 glEnd;
446 454
447 my $bg = $tex[0]; 455 my $bg = $tex[0];
448 glBindTexture GL_TEXTURE_2D, $bg->{name}; 456 glBindTexture GL_TEXTURE_2D, $bg->{name};
449 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 457 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
450 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 458 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
451 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 459 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
452 460
453 my $rep_x = $cw / $bg->{width}; 461 my $rep_x = $cw / $bg->{width};
454 my $rep_y = $ch / $bg->{height}; 462 my $rep_y = $ch / $bg->{height};
455 463
456 glBegin GL_QUADS; 464 $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch);
457 glTexCoord 0, 0; glVertex $left->{width}, $top->{height};
458 glTexCoord 0, $rep_y; glVertex $left->{width}, $top->{height} + $ch;
459 glTexCoord $rep_x, $rep_y; glVertex $left->{width} + $cw , $top->{height} + $ch;
460 glTexCoord $rep_x, 0; glVertex $left->{width} + $cw , $top->{height};
461 glEnd;
462 465
463 glDisable GL_BLEND; 466 glDisable GL_BLEND;
464 glDisable GL_TEXTURE_2D; 467 glDisable GL_TEXTURE_2D;
465 468
466 $self->child->draw; 469 $self->child->draw;
623use SDL::OpenGL; 626use SDL::OpenGL;
624 627
625sub new { 628sub new {
626 my ($class, $x, $y, $z, $height, $text) = @_; 629 my ($class, $x, $y, $z, $height, $text) = @_;
627 630
631 $height ||= $::FONTSIZE;
632
628 # TODO: color, and make height, xyz etc. optional 633 # TODO: color, and make height, xyz etc. optional
629 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); 634 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height);
630 635
631 $self->set_text ($text); 636 $self->set_text ($text);
632 637
649} 654}
650 655
651sub size_request { 656sub size_request {
652 my ($self) = @_; 657 my ($self) = @_;
653 658
654 ( 659 if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
660 (
655 $self->{texture}{width}, 661 $self->{texture}{width},
656 $self->{texture}{height}, 662 $self->{texture}{height},
663 )
664 } else {
665 my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height};
666
667 ($w, $h)
657 ) 668 }
669
658} 670}
659 671
660sub _draw { 672sub _draw {
661 my ($self) = @_; 673 my ($self) = @_;
662 674
664 676
665 glEnable GL_BLEND; 677 glEnable GL_BLEND;
666 glEnable GL_TEXTURE_2D; 678 glEnable GL_TEXTURE_2D;
667 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 679 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
668 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 680 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
669 glBindTexture GL_TEXTURE_2D, $tex->{name};
670 681
671 glColor 1, 0, 0, 1; # TODO color 682 glColor 1, 0, 0, 1; # TODO color
672 683
673 glBegin GL_QUADS; 684 $tex->draw_quad (0, 0);
674 glTexCoord 0, 0; glVertex 0 , 0;
675 glTexCoord 0, 1; glVertex 0 , $tex->{height};
676 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
677 glTexCoord 1, 0; glVertex $tex->{width}, 0;
678 glEnd;
679 685
680 glDisable GL_BLEND; 686 glDisable GL_BLEND;
681 glDisable GL_TEXTURE_2D; 687 glDisable GL_TEXTURE_2D;
682} 688}
683 689
684############################################################################# 690#############################################################################
685 691
686package Crossfire::Client::Widget::TextEntry; 692package Crossfire::Client::Widget::Entry;
687 693
688our @ISA = Crossfire::Client::Widget::Label::; 694our @ISA = Crossfire::Client::Widget::Label::;
689 695
690use SDL; 696use SDL;
691use SDL::OpenGL; 697use SDL::OpenGL;
694 my ($self, $ev) = @_; 700 my ($self, $ev) = @_;
695 701
696 my $mod = $ev->key_mod; 702 my $mod = $ev->key_mod;
697 my $sym = $ev->key_sym; 703 my $sym = $ev->key_sym;
698 704
699 $ev->set_unicode (1);
700 my $uni = $ev->key_unicode; 705 my $uni = $ev->key_unicode;
701 706
702 my $text = $self->get_text; 707 my $text = $self->get_text;
703 708
704 if ($sym == SDLK_BACKSPACE) { 709 if ($sym == SDLK_BACKSPACE) {
705 substr $text, -1, 1, ''; 710 substr $text, -1, 1, '';
706
707 } elsif ($uni) { 711 } elsif ($uni) {
708 $text .= chr $uni; 712 $text .= chr $uni;
713 print "$uni <$text>\n";#d#
709 } 714 }
715
710 $self->set_text ($text); 716 $self->set_text ($text);
717}
718
719sub button_down {
720 my ($self, $ev) = @_;
721
722 $self->focus_in;
723}
724
725sub _draw {
726 my ($self) = @_;
727
728 if ($FOCUS == $self) {
729 glColor 1, 1, 1;
730 } else {
731 glColor 0.7, 0.7, 0.7;
732 }
733
734 glBegin GL_QUADS;
735 glVertex 0 , 0;
736 glVertex 0 , $self->{h} - 1;
737 glVertex $self->{w} - 1, $self->{h} - 1;
738 glVertex $self->{w} - 1, 0;
739 glEnd;
740
741 $self->SUPER::_draw;
711} 742}
712 743
713############################################################################# 744#############################################################################
714 745
715package Crossfire::Client::Widget::MapWidget; 746package Crossfire::Client::Widget::MapWidget;
730 761
731sub key_up { 762sub key_up {
732} 763}
733 764
734sub size_request { 765sub size_request {
735 766 (
736} 767 1 + int $::WIDTH / 32,
737 768 1 + int $::HEIGHT / 32,
738sub size_allocate { 769 )
739} 770}
740 771
741sub _draw { 772sub _draw {
742 my ($self) = @_; 773 my ($self) = @_;
743 774
766 glEnable GL_TEXTURE_2D; 797 glEnable GL_TEXTURE_2D;
767 glEnable GL_BLEND; 798 glEnable GL_BLEND;
768 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 799 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
769 800
770 my $sw4 = ($sw + 3) & ~3; 801 my $sw4 = ($sw + 3) & ~3;
771 my $lighting = "\x00" x ($sw4 * $sh); 802 my $darkness = "\x00" x ($sw4 * $sh);
772 803
773 for my $x (0 .. $sw - 1) { 804 for my $x (0 .. $sw - 1) {
805 my $row = $map->[$x + $xofs];
774 for my $y (0 .. $sh - 1) { 806 for my $y (0 .. $sh - 1) {
775 807
776 my $cell = $map->[$x + $xofs][$y + $yofs] 808 my $cell = $row->[$y + $yofs]
777 or next; 809 or next;
778 810
779 my $darkness = $cell->[0] * (1 / 255); 811 my $dark = $cell->[0];
780 if ($darkness < 0) { 812 if ($dark < 0) {
781 $darkness = 0.15; 813 substr $darkness, $y * $sw4 + $x, 1, chr 224;
814 } else {
815 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
782 } 816 }
783 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255;
784 817
785 for my $num (grep $_, @$cell[1,2,3]) { 818 for my $num (grep $_, @$cell[1,2,3]) {
786 my $tex = $::CONN->{face}[$num]{texture} || next; 819 my $tex = $::CONN->{face}[$num]{texture} || next;
787 820
788 glBindTexture GL_TEXTURE_2D, $tex->{name};
789
790 my $w = $tex->{width}; 821 my $w = $tex->{width};
791 my $h = $tex->{height}; 822 my $h = $tex->{height};
792 823
793 my $px = ($x + 1) * 32 - $w; 824 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
794 my $py = ($y + 1) * 32 - $h;
795
796 glBegin GL_QUADS;
797 glTexCoord 0, 0; glVertex $px , $py;
798 glTexCoord 0, 1; glVertex $px , $py + $h;
799 glTexCoord 1, 1; glVertex $px + $w, $py + $h;
800 glTexCoord 1, 0; glVertex $px + $w, $py;
801 glEnd;
802 } 825 }
803 } 826 }
804 } 827 }
805 828
806# if (1) { # higher quality darkness 829# if (1) { # higher quality darkness
811# 834#
812# $lighting = $pb->get_pixels; 835# $lighting = $pb->get_pixels;
813# $lighting =~ s/(.)../$1/gs; 836# $lighting =~ s/(.)../$1/gs;
814# } 837# }
815 838
839 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
840 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
841
816 $lighting = new Crossfire::Client::Texture 842 $darkness = new Crossfire::Client::Texture
817 width => $sw4, 843 width => $sw4,
818 height => $sh, 844 height => $sh,
819 data => $lighting, 845 data => $darkness,
820 internalformat => GL_ALPHA4, 846 internalformat => GL_ALPHA,
821 format => GL_ALPHA; 847 format => GL_ALPHA;
822 848
823 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 849 glColor 0.45, 0.45, 0.45, 1;
824 glColor 0, 0, 0, 0.75; 850 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
825 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
826 glBindTexture GL_TEXTURE_2D, $lighting->{name};
827 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
828 glBegin GL_QUADS;
829 glTexCoord 0, 0; glVertex 0 , 0;
830 glTexCoord 0, 1; glVertex 0 , $sh * 32;
831 glTexCoord 1, 1; glVertex $sw4 * 32, $sh * 32;
832 glTexCoord 1, 0; glVertex $sw4 * 32, 0;
833 glEnd;
834 851
835 glDisable GL_TEXTURE_2D; 852 glDisable GL_TEXTURE_2D;
836 glDisable GL_BLEND; 853 glDisable GL_BLEND;
837} 854}
838 855
897 914
898sub moveto { 915sub moveto {
899 my ($self, $x, $y) = @_; 916 my ($self, $x, $y) = @_;
900 917
901 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 918 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
902 $self->{speed} = 0.2; 919 $self->{speed} = 0.001;
903 $self->{time} = 1; 920 $self->{time} = 1;
904 921
905 ::animation_start $self; 922 ::animation_start $self;
906} 923}
907 924
908sub animate { 925sub animate {
909 my ($self, $interval) = @_; 926 my ($self, $interval) = @_;
927
928 printf "%5.2f\n", 1 / $interval if $interval;#d#
910 929
911 $self->{time} -= $interval * $self->{speed}; 930 $self->{time} -= $interval * $self->{speed};
912 if ($self->{time} <= 0) { 931 if ($self->{time} <= 0) {
913 $self->{time} = 0; 932 $self->{time} = 0;
914 ::animation_stop $self; 933 ::animation_stop $self;
922 941
923sub _draw { 942sub _draw {
924 my ($self) = @_; 943 my ($self) = @_;
925 944
926 glPushMatrix; 945 glPushMatrix;
927 glRotate $self->{time} * 10000, 0, 1, 0; 946 glRotate $self->{time} * 1000, 0, 1, 0;
928 $self->{children}[0]->draw; 947 $self->{children}[0]->draw;
929 glPopMatrix; 948 glPopMatrix;
930} 949}
931 950
9321; 951#############################################################################
933 952
953package Crossfire::Client::Widget::Toplevel;
954
955our @ISA = Crossfire::Client::Widget::Container::;
956
957sub size_request {
958 ($::WIDTH, $::HEIGHT)
959}
960
961sub size_allocate {
962 my ($self, $w, $h) = @_;
963
964 $self->SUPER::size_allocate ($w, $h);
965
966 $_->size_allocate ($_->size_request)
967 for @{$self->{children}};
968}
969
970sub update {
971 my ($self) = @_;
972
973 $self->size_allocate ($self->size_request);
974 ::refresh ();
975}
976
977sub add {
978 my ($self, $widget) = @_;
979
980 $self->SUPER::add ($widget);
981
982 $widget->size_allocate ($widget->size_request);
983}
984
985sub draw {
986 my ($self) = @_;
987
988 $self->_draw;
989}
990
991#############################################################################
992
993package Crossfire::Client::Widget;
994
995$TOPLEVEL = new Crossfire::Client::Widget::Toplevel;
996
9971
998

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines