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.47 by root, Sun Apr 9 22:24:43 2006 UTC vs.
Revision 1.59 by root, Tue Apr 11 13:05:12 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, $HOVER, $GRAB); # various widgets
13
14our $TOPLEVEL;
15our $BUTTON_STATE;
16
12# class methods for events 17# class methods for events
13sub feed_sdl_key_down_event { $::FOCUS->key_down ($_[0]) if $::FOCUS } 18sub feed_sdl_key_down_event {
14sub 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
15sub 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, $GRAB->translate ($x, $y)) if $GRAB;
40}
41
16sub 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 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB;
51
52 if (!$BUTTON_STATE) {
53 my $grab = $GRAB; undef $GRAB;
54 $grab->update if $grab;
55 $GRAB->update if $GRAB;
56 }
57}
58
59sub feed_sdl_motion_event {
60 my ($ev) = @_;
61 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
62
63 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
64
65 if ($widget != $HOVER) {
66 my $hover = $HOVER; $HOVER = $widget;
67
68 $hover->update if $hover;
69 $HOVER->update if $HOVER;
70 }
71
72 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER;
73}
17 74
18sub new { 75sub new {
19 my $class = shift; 76 my $class = shift;
20 77
21 bless { @_ }, $class 78 bless { @_ }, $class
42 99
43 $self->{w} = $w; 100 $self->{w} = $w;
44 $self->{h} = $h; 101 $self->{h} = $h;
45} 102}
46 103
104# translate global koordinates to local coordinate system
105sub translate {
106 my ($self, $x, $y) = @_;
107
108 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y});
109}
110
47sub focus_in { 111sub focus_in {
48 my ($widget) = @_; 112 my ($self) = @_;
49 $::FOCUS = $widget; 113
114 my $focus = $FOCUS; $FOCUS = $self;
115 $focus->update if $focus;
116 $FOCUS->update;
50} 117}
51 118
52sub focus_out { 119sub focus_out {
53 my ($widget) = @_; 120 my ($self) = @_;
54}
55 121
56sub key_down { 122 return unless $FOCUS == $self;
57 my ($widget, $sdlev) = @_;
58}
59 123
60sub key_up { 124 my $focus = $FOCUS; undef $FOCUS;
61 my ($widget, $sdlev) = @_; 125 $focus->update if $focus; #?
62} 126}
63 127
128sub mouse_motion { }
129sub button_up { }
64sub button_down { 130sub button_down { }
65 my ($widget, $sdlev) = @_; 131sub key_down { }
66} 132sub key_up { }
67 133
68sub button_up {
69 my ($widget, $sdlev) = @_;
70}
71
72sub w { $_[0]->{w} = $_[1] if $_[1]; $_[0]->{w} } 134sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} }
73sub h { $_[0]->{h} = $_[1] if $_[1]; $_[0]->{h} } 135sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} }
74sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } 136sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
75sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } 137sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
76sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} } 138sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
77 139
78sub draw { 140sub draw {
79 my ($self) = @_; 141 my ($self) = @_;
80 142
81 glPushMatrix; 143 glPushMatrix;
82 glTranslate $self->{x}, $self->{y}, 0; 144 glTranslate $self->{x}, $self->{y}, 0;
83 $self->_draw; 145 $self->_draw;
84 if ($self == $::HOVER) { 146 if ($self == $HOVER) {
85 glColor 1, 1, 1, 1; 147 glColor 1, 1, 1, 0.4;
148 glEnable GL_BLEND;
86 glBegin GL_LINES; 149 glBegin GL_QUADS;
87 glVertex 0, 0; 150 glVertex 0 , 0;
88 glVertex $self->{w} - 1, 0; 151 glVertex $self->{w}, 0;
89 glVertex $self->{w} - 1, $self->{h} - 1; 152 glVertex $self->{w}, $self->{h};
90 glVertex 0, $self->{h} - 1; 153 glVertex 0 , $self->{h};
91 glVertex 0, 0;
92 glEnd; 154 glEnd;
155 glDisable GL_BLEND;
93 } 156 }
94 glPopMatrix; 157 glPopMatrix;
95} 158}
96 159
97sub _draw { 160sub _draw {
226 if $self->{children}[0] 289 if $self->{children}[0]
227} 290}
228 291
229############################################################################# 292#############################################################################
230 293
231package Crossfire::Client::Widget::Toplevel;
232
233our @ISA = Crossfire::Client::Widget::Container::;
234
235sub update {
236 my ($self) = @_;
237
238 ::refresh ();
239}
240
241sub add {
242 my ($self, $widget) = @_;
243
244 $self->SUPER::add ($widget);
245
246 $widget->size_allocate ($widget->size_request);
247}
248
249#############################################################################
250
251package Crossfire::Client::Widget::Window; 294package Crossfire::Client::Widget::Window;
252 295
253our @ISA = Crossfire::Client::Widget::Bin::; 296our @ISA = Crossfire::Client::Widget::Bin::;
254 297
255use SDL::OpenGL; 298use SDL::OpenGL;
298 or return; 341 or return;
299 342
300 glEnable GL_BLEND; 343 glEnable GL_BLEND;
301 glEnable GL_TEXTURE_2D; 344 glEnable GL_TEXTURE_2D;
302 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 345 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
303 glBindTexture GL_TEXTURE_2D, $tex->{name};
304 346
305 glBegin GL_QUADS; 347 $tex->draw_quad (0, 0, $w, $h);
306 glTexCoord 0, 0; glVertex 0, 0;
307 glTexCoord 0, 1; glVertex 0, $h;
308 glTexCoord 1, 1; glVertex $w, $h;
309 glTexCoord 1, 0; glVertex $w, 0;
310 glEnd;
311 348
312 glDisable GL_BLEND; 349 glDisable GL_BLEND;
313 glDisable GL_TEXTURE_2D; 350 glDisable GL_TEXTURE_2D;
314} 351}
315 352
348 385
349 my ($w, $h) = $chld->size_request; 386 my ($w, $h) = $chld->size_request;
350 387
351 glBegin GL_QUADS; 388 glBegin GL_QUADS;
352 glColor 0, 0, 0; 389 glColor 0, 0, 0;
353 glTexCoord 0, 0; glVertex 0 , 0; 390 glVertex 0 , 0;
354 glTexCoord 0, 1; glVertex 0 , $h + 4; 391 glVertex 0 , $h + 4;
355 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 392 glVertex $w + 4 , $h + 4;
356 glTexCoord 1, 0; glVertex $w + 4 , 0; 393 glVertex $w + 4 , 0;
357 glEnd; 394 glEnd;
358 395
359 $chld->draw; 396 $chld->draw;
360} 397}
361 398
411 glEnable GL_TEXTURE_2D; 448 glEnable GL_TEXTURE_2D;
412 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 449 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
413 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 450 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
414 451
415 my $top = $tex[1]; 452 my $top = $tex[1];
416 glBindTexture GL_TEXTURE_2D, $top->{name}; 453 $top->draw_quad (0, 0, $w, $top->{height});
417
418 glBegin GL_QUADS;
419 glTexCoord 0, 0; glVertex 0 , 0;
420 glTexCoord 0, 1; glVertex 0 , $top->{height};
421 glTexCoord 1, 1; glVertex $w , $top->{height};
422 glTexCoord 1, 0; glVertex $w , 0;
423 glEnd;
424 454
425 my $left = $tex[3]; 455 my $left = $tex[3];
426 glBindTexture GL_TEXTURE_2D, $left->{name}; 456 $left->draw_quad (0, $top->{height}, $left->{width}, $ch);
427
428 glBegin GL_QUADS;
429 glTexCoord 0, 0; glVertex 0 , $top->{height};
430 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch;
431 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch;
432 glTexCoord 1, 0; glVertex $left->{width}, $top->{height};
433 glEnd;
434 457
435 my $right = $tex[2]; 458 my $right = $tex[2];
436 glBindTexture GL_TEXTURE_2D, $right->{name}; 459 $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch);
437
438 glBegin GL_QUADS;
439 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height};
440 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch;
441 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch;
442 glTexCoord 1, 0; glVertex $w , $top->{height};
443 glEnd;
444 460
445 my $bottom = $tex[4]; 461 my $bottom = $tex[4];
446 glBindTexture GL_TEXTURE_2D, $bottom->{name}; 462 $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height});
447
448 glBegin GL_QUADS;
449 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height};
450 glTexCoord 0, 1; glVertex 0 , $h;
451 glTexCoord 1, 1; glVertex $w , $h;
452 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height};
453 glEnd;
454 463
455 my $bg = $tex[0]; 464 my $bg = $tex[0];
456 glBindTexture GL_TEXTURE_2D, $bg->{name}; 465 glBindTexture GL_TEXTURE_2D, $bg->{name};
457 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 466 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
458 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 467 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
459 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 468 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
460 469
461 my $rep_x = $cw / $bg->{width}; 470 my $rep_x = $cw / $bg->{width};
462 my $rep_y = $ch / $bg->{height}; 471 my $rep_y = $ch / $bg->{height};
463 472
464 glBegin GL_QUADS; 473 $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch);
465 glTexCoord 0, 0; glVertex $left->{width}, $top->{height};
466 glTexCoord 0, $rep_y; glVertex $left->{width}, $top->{height} + $ch;
467 glTexCoord $rep_x, $rep_y; glVertex $left->{width} + $cw , $top->{height} + $ch;
468 glTexCoord $rep_x, 0; glVertex $left->{width} + $cw , $top->{height};
469 glEnd;
470 474
471 glDisable GL_BLEND; 475 glDisable GL_BLEND;
472 glDisable GL_TEXTURE_2D; 476 glDisable GL_TEXTURE_2D;
473 477
474 $self->child->draw; 478 $self->child->draw;
631use SDL::OpenGL; 635use SDL::OpenGL;
632 636
633sub new { 637sub new {
634 my ($class, $x, $y, $z, $height, $text) = @_; 638 my ($class, $x, $y, $z, $height, $text) = @_;
635 639
640 $height ||= $::FONTSIZE;
641
636 # TODO: color, and make height, xyz etc. optional 642 # TODO: color, and make height, xyz etc. optional
637 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); 643 my $self = $class->SUPER::new (
644 x => $x,
645 y => $y,
646 z => $z,
647 height => $height,
648 layout => new Crossfire::Client::Layout,
649 );
638 650
639 $self->set_text ($text); 651 $self->set_text ($text);
640 652
641 $self 653 $self
642} 654}
643 655
644sub set_text { 656sub set_text {
645 my ($self, $text) = @_; 657 my ($self, $text) = @_;
646 658
647 $self->{text} = $text; 659 $self->{text} = $text;
648 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; 660 $self->{layout}->set_markup ($text);
649 661
650 $self->update; 662 delete $self->{texture};
651} 663}
652 664
653sub get_text { 665sub get_text {
654 my ($self, $text) = @_; 666 my ($self, $text) = @_;
655 667
657} 669}
658 670
659sub size_request { 671sub size_request {
660 my ($self) = @_; 672 my ($self) = @_;
661 673
662 ( 674 $self->{layout}->set_width;
675 $self->{layout}->size
676# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
677# (
663 $self->{texture}{width}, 678# $self->{texture}{width},
664 $self->{texture}{height}, 679# $self->{texture}{height},
665 ) 680# )
681# } else {
682# my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height};
683#
684# ($w, $h)
685# }
686}
687
688sub size_allocate {
689 my ($self, $w, $h) = @_;
690
691 $self->SUPER::size_allocate ($w, $h);
692 delete $self->{texture};
666} 693}
667 694
668sub _draw { 695sub _draw {
669 my ($self) = @_; 696 my ($self) = @_;
670 697
671 my $tex = $self->{texture}; 698 my $tex = $self->{texture} ||= do {
699 $self->{layout}->set_width ($self->{w});
700 new_from_layout Crossfire::Client::Texture $self->{layout};
701 };
672 702
673 glEnable GL_BLEND; 703 glEnable GL_BLEND;
674 glEnable GL_TEXTURE_2D; 704 glEnable GL_TEXTURE_2D;
675 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 705 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
676 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 706 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
677 glBindTexture GL_TEXTURE_2D, $tex->{name};
678 707
679 glColor 1, 0, 0, 1; # TODO color 708 glColor 1, 0, 0, 1; # TODO color
680 709
681 glBegin GL_QUADS; 710 $tex->draw_quad (0, 0);
682 glTexCoord 0, 0; glVertex 0 , 0;
683 glTexCoord 0, 1; glVertex 0 , $tex->{height};
684 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
685 glTexCoord 1, 0; glVertex $tex->{width}, 0;
686 glEnd;
687 711
688 glDisable GL_BLEND; 712 glDisable GL_BLEND;
689 glDisable GL_TEXTURE_2D; 713 glDisable GL_TEXTURE_2D;
690} 714}
691 715
692############################################################################# 716#############################################################################
693 717
694package Crossfire::Client::Widget::TextEntry; 718package Crossfire::Client::Widget::Entry;
695 719
696our @ISA = Crossfire::Client::Widget::Label::; 720our @ISA = Crossfire::Client::Widget::Label::;
697 721
698use SDL; 722use SDL;
699use SDL::OpenGL; 723use SDL::OpenGL;
702 my ($self, $ev) = @_; 726 my ($self, $ev) = @_;
703 727
704 my $mod = $ev->key_mod; 728 my $mod = $ev->key_mod;
705 my $sym = $ev->key_sym; 729 my $sym = $ev->key_sym;
706 730
707 $ev->set_unicode (1);
708 my $uni = $ev->key_unicode; 731 my $uni = $ev->key_unicode;
709 732
710 my $text = $self->get_text; 733 my $text = $self->get_text;
711 734
712 if ($sym == SDLK_BACKSPACE) { 735 if ($sym == SDLK_BACKSPACE) {
713 substr $text, -1, 1, ''; 736 substr $text, -1, 1, '';
714
715 } elsif ($uni) { 737 } elsif ($uni) {
716 $text .= chr $uni; 738 $text .= chr $uni;
717 } 739 }
740
718 $self->set_text ($text); 741 $self->set_text ($text);
742}
743
744sub button_down {
745 my ($self, $ev) = @_;
746
747 $self->focus_in;
748}
749
750sub 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#
753}
754
755sub _draw {
756 my ($self) = @_;
757
758 if ($FOCUS == $self) {
759 glColor 1, 1, 1;
760 } else {
761 glColor 0.7, 0.7, 0.7;
762 }
763
764 glBegin GL_QUADS;
765 glVertex 0 , 0;
766 glVertex 0 , $self->{h} - 1;
767 glVertex $self->{w} - 1, $self->{h} - 1;
768 glVertex $self->{w} - 1, 0;
769 glEnd;
770
771 $self->SUPER::_draw;
719} 772}
720 773
721############################################################################# 774#############################################################################
722 775
723package Crossfire::Client::Widget::MapWidget; 776package Crossfire::Client::Widget::MapWidget;
738 791
739sub key_up { 792sub key_up {
740} 793}
741 794
742sub size_request { 795sub size_request {
743 796 (
744} 797 1 + int $::WIDTH / 32,
745 798 1 + int $::HEIGHT / 32,
746sub size_allocate { 799 )
747} 800}
748 801
749sub _draw { 802sub _draw {
750 my ($self) = @_; 803 my ($self) = @_;
751 804
774 glEnable GL_TEXTURE_2D; 827 glEnable GL_TEXTURE_2D;
775 glEnable GL_BLEND; 828 glEnable GL_BLEND;
776 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 829 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
777 830
778 my $sw4 = ($sw + 3) & ~3; 831 my $sw4 = ($sw + 3) & ~3;
779 my $lighting = "\x00" x ($sw4 * $sh); 832 my $darkness = "\x00" x ($sw4 * $sh);
780 833
781 for my $x (0 .. $sw - 1) { 834 for my $x (0 .. $sw - 1) {
835 my $row = $map->[$x + $xofs];
782 for my $y (0 .. $sh - 1) { 836 for my $y (0 .. $sh - 1) {
783 837
784 my $cell = $map->[$x + $xofs][$y + $yofs] 838 my $cell = $row->[$y + $yofs]
785 or next; 839 or next;
786 840
787 my $darkness = $cell->[0] * (1 / 255); 841 my $dark = $cell->[0];
788 if ($darkness < 0) { 842 if ($dark < 0) {
789 $darkness = 0.15; 843 substr $darkness, $y * $sw4 + $x, 1, chr 224;
844 } else {
845 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
790 } 846 }
791 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255;
792 847
793 for my $num (grep $_, @$cell[1,2,3]) { 848 for my $num (grep $_, @$cell[1,2,3]) {
794 my $tex = $::CONN->{face}[$num]{texture} || next; 849 my $tex = $::CONN->{face}[$num]{texture} || next;
795 850
796 glBindTexture GL_TEXTURE_2D, $tex->{name};
797
798 my $w = $tex->{width}; 851 my $w = $tex->{width};
799 my $h = $tex->{height}; 852 my $h = $tex->{height};
800 853
801 my $px = ($x + 1) * 32 - $w; 854 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
802 my $py = ($y + 1) * 32 - $h;
803
804 glBegin GL_QUADS;
805 glTexCoord 0, 0; glVertex $px , $py;
806 glTexCoord 0, 1; glVertex $px , $py + $h;
807 glTexCoord 1, 1; glVertex $px + $w, $py + $h;
808 glTexCoord 1, 0; glVertex $px + $w, $py;
809 glEnd;
810 } 855 }
811 } 856 }
812 } 857 }
813 858
814# if (1) { # higher quality darkness 859# if (1) { # higher quality darkness
819# 864#
820# $lighting = $pb->get_pixels; 865# $lighting = $pb->get_pixels;
821# $lighting =~ s/(.)../$1/gs; 866# $lighting =~ s/(.)../$1/gs;
822# } 867# }
823 868
869 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
870 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
871
824 $lighting = new Crossfire::Client::Texture 872 $darkness = new Crossfire::Client::Texture
825 width => $sw4, 873 width => $sw4,
826 height => $sh, 874 height => $sh,
827 data => $lighting, 875 data => $darkness,
828 internalformat => GL_ALPHA4, 876 internalformat => GL_ALPHA,
829 format => GL_ALPHA; 877 format => GL_ALPHA;
830 878
831 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 879 glColor 0.45, 0.45, 0.45, 1;
832 glColor 0, 0, 0, 0.75; 880 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
833 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
834 glBindTexture GL_TEXTURE_2D, $lighting->{name};
835 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
836 glBegin GL_QUADS;
837 glTexCoord 0, 0; glVertex 0 , 0;
838 glTexCoord 0, 1; glVertex 0 , $sh * 32;
839 glTexCoord 1, 1; glVertex $sw4 * 32, $sh * 32;
840 glTexCoord 1, 0; glVertex $sw4 * 32, 0;
841 glEnd;
842 881
843 glDisable GL_TEXTURE_2D; 882 glDisable GL_TEXTURE_2D;
844 glDisable GL_BLEND; 883 glDisable GL_BLEND;
845} 884}
846 885
905 944
906sub moveto { 945sub moveto {
907 my ($self, $x, $y) = @_; 946 my ($self, $x, $y) = @_;
908 947
909 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 948 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
910 $self->{speed} = 0.2; 949 $self->{speed} = 0.001;
911 $self->{time} = 1; 950 $self->{time} = 1;
912 951
913 ::animation_start $self; 952 ::animation_start $self;
914} 953}
915 954
930 969
931sub _draw { 970sub _draw {
932 my ($self) = @_; 971 my ($self) = @_;
933 972
934 glPushMatrix; 973 glPushMatrix;
935 glRotate $self->{time} * 10000, 0, 1, 0; 974 glRotate $self->{time} * 1000, 0, 1, 0;
936 $self->{children}[0]->draw; 975 $self->{children}[0]->draw;
937 glPopMatrix; 976 glPopMatrix;
938} 977}
939 978
9401; 979#############################################################################
941 980
981package Crossfire::Client::Widget::Toplevel;
982
983our @ISA = Crossfire::Client::Widget::Container::;
984
985sub size_request {
986 ($::WIDTH, $::HEIGHT)
987}
988
989sub size_allocate {
990 my ($self, $w, $h) = @_;
991
992 $self->SUPER::size_allocate ($w, $h);
993
994 $_->size_allocate ($_->size_request)
995 for @{$self->{children}};
996}
997
998sub translate {
999 my ($self, $x, $y) = @_;
1000
1001 ($x, $y)
1002}
1003
1004sub update {
1005 my ($self) = @_;
1006
1007 $self->size_allocate ($self->size_request);
1008 ::refresh ();
1009}
1010
1011sub add {
1012 my ($self, $widget) = @_;
1013
1014 $self->SUPER::add ($widget);
1015
1016 $widget->size_allocate ($widget->size_request);
1017}
1018
1019sub draw {
1020 my ($self) = @_;
1021
1022 $self->_draw;
1023}
1024
1025#############################################################################
1026
1027package Crossfire::Client::Widget;
1028
1029$TOPLEVEL = new Crossfire::Client::Widget::Toplevel;
1030
10311
1032

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines