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.56 by root, Mon Apr 10 22:16:34 2006 UTC vs.
Revision 1.66 by root, Tue Apr 11 14:36:02 2006 UTC

1package Crossfire::Client::Widget; 1package CFClient::Widget;
2 2
3use strict; 3use strict;
4 4
5use Scalar::Util; 5use Scalar::Util;
6 6
7use SDL::OpenGL; 7use SDL::OpenGL;
8use SDL::OpenGL::Constants; 8use SDL::OpenGL::Constants;
9 9
10use Crossfire::Client; 10use CFClient;
11 11
12our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
13 13
14our $TOPLEVEL; 14our $TOPLEVEL;
15our $BUTTON_STATE; 15our $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
42sub feed_sdl_button_up_event { 42sub 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
73sub new { 75sub 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
79sub move { 86sub move {
80 my ($self, $x, $y, $z) = @_; 87 my ($self, $x, $y, $z) = @_;
81 $self->{x} = $x; 88 $self->{x} = $x;
95sub size_allocate { 102sub 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
110sub translate {
111 my ($self, $x, $y) = @_;
112
113 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y});
100} 114}
101 115
102sub focus_in { 116sub focus_in {
103 my ($self) = @_; 117 my ($self) = @_;
104 118
201 #$self->deactivate; 215 #$self->deactivate;
202} 216}
203 217
204############################################################################# 218#############################################################################
205 219
220package CFClient::Widget::Empty;
221
222our @ISA = CFClient::Widget::;
223
224sub size_request {
225 (0, 0)
226}
227
228sub draw {
229}
230
231#############################################################################
232
206package Crossfire::Client::Widget::Container; 233package CFClient::Widget::Container;
207 234
208our @ISA = Crossfire::Client::Widget::; 235our @ISA = CFClient::Widget::;
209 236
210sub new { 237sub new {
211 my ($class, @widgets) = @_; 238 my ($class, %arg) = @_;
212 239
240 my $children = delete $arg{children} || [];
241
213 my $self = $class->SUPER::new (children => []); 242 my $self = $class->SUPER::new (children => [], %arg);
214 $self->add ($_) for @widgets; 243 $self->add ($_) for @$children;
215 244
216 $self 245 $self
217} 246}
218 247
219sub add { 248sub add {
220 my ($self, $chld, $expand) = @_; 249 my ($self, $chld, $expand) = @_;
221 250
222 $chld->{expand} = $expand; 251 $chld->{expand} = $expand;
223 $chld->set_parent ($self); 252 $chld->set_parent ($self);
224 253
225 @{$self->{children}} = 254 $self->{children} = [
226 sort { $a->{z} <=> $b->{z} } 255 sort { $a->{z} <=> $b->{z} }
227 @{$self->{children}}, $chld; 256 @{$self->{children}}, $chld
257 ];
228 258
229 $self->size_allocate ($self->{w}, $self->{h}) 259 $self->size_allocate ($self->{w}, $self->{h})
230 if $self->{w}; #TODO: check for "realised state" 260 if $self->{w}; #TODO: check for "realised state"
231} 261}
232 262
260 $_->draw for @{$self->{children}}; 290 $_->draw for @{$self->{children}};
261} 291}
262 292
263############################################################################# 293#############################################################################
264 294
265package Crossfire::Client::Widget::Bin; 295package CFClient::Widget::Bin;
266 296
267our @ISA = Crossfire::Client::Widget::Container::; 297our @ISA = CFClient::Widget::Container::;
298
299sub new {
300 my ($class, %arg) = @_;
301
302 my $child = (delete $arg{child}) || new CFClient::Widget::Empty::;
303
304 $class->SUPER::new (children => [$child], %arg)
305}
306
307sub add {
308 my ($self, $widget) = @_;
309
310 $self->{children} = [];
311
312 $self->SUPER::add ($widget);
313}
314
315sub remove {
316 my ($self, $widget) = @_;
317
318 $self->SUPER::remove ($widget);
319
320 $self->{children} = [new CFClient::Widget::Empty]
321 unless @{$self->{children}};
322}
268 323
269sub child { $_[0]->{children}[0] } 324sub child { $_[0]->{children}[0] }
270 325
271sub size_request { 326sub size_request {
272 $_[0]{children}[0]->size_request if $_[0]{children}[0]; 327 $_[0]{children}[0]->size_request if $_[0]{children}[0];
280 if $self->{children}[0] 335 if $self->{children}[0]
281} 336}
282 337
283############################################################################# 338#############################################################################
284 339
285package Crossfire::Client::Widget::Window; 340package CFClient::Widget::Window;
286 341
287our @ISA = Crossfire::Client::Widget::Bin::; 342our @ISA = CFClient::Widget::Bin::;
288 343
289use SDL::OpenGL; 344use SDL::OpenGL;
290 345
291sub new { 346sub new {
292 my ($class, $x, $y, $z, $w, $h) = @_; 347 my ($class, %arg) = @_;
293 348
294 my $self = $class->SUPER::new; 349 my $self = $class->SUPER::new (%arg);
295
296 @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h);
297} 350}
298 351
299sub update { 352sub update {
300 my ($self) = @_; 353 my ($self) = @_;
301 354
355 # we want to do this delayed...
302 $self->render_chld; 356 $self->render_chld;
303 $self->SUPER::update; 357 $self->SUPER::update;
304} 358}
305 359
306sub render_chld { 360sub render_chld {
307 my ($self) = @_; 361 my ($self) = @_;
308 362
309 $self->{texture} = 363 $self->{texture} =
310 Crossfire::Client::Texture->new_from_opengl ( 364 CFClient::Texture->new_from_opengl (
311 $self->{w}, $self->{h}, sub { $self->child->draw } 365 $self->{w}, $self->{h}, sub { $self->child->draw }
312 ); 366 );
313} 367}
314 368
315sub size_allocate { 369sub size_allocate {
341 glDisable GL_TEXTURE_2D; 395 glDisable GL_TEXTURE_2D;
342} 396}
343 397
344############################################################################# 398#############################################################################
345 399
346package Crossfire::Client::Widget::Frame; 400package CFClient::Widget::Frame;
347 401
348our @ISA = Crossfire::Client::Widget::Bin::; 402our @ISA = CFClient::Widget::Bin::;
349 403
350use SDL::OpenGL; 404use SDL::OpenGL;
351 405
352sub size_request { 406sub size_request {
353 my ($self) = @_; 407 my ($self) = @_;
387 $chld->draw; 441 $chld->draw;
388} 442}
389 443
390############################################################################# 444#############################################################################
391 445
392package Crossfire::Client::Widget::FancyFrame; 446package CFClient::Widget::FancyFrame;
393 447
394our @ISA = Crossfire::Client::Widget::Bin::; 448our @ISA = CFClient::Widget::Bin::;
395 449
396use SDL::OpenGL; 450use SDL::OpenGL;
397 451
398my @tex = 452my @tex =
399 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } 453 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); 454 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
401 455
402sub size_request { 456sub size_request {
403 my ($self) = @_; 457 my ($self) = @_;
404 458
423 $w -= $tex[3]->{width}; 477 $w -= $tex[3]->{width};
424 478
425 $h = $h < 0 ? 0 : $h; 479 $h = $h < 0 ? 0 : $h;
426 $w = $w < 0 ? 0 : $w; 480 $w = $w < 0 ? 0 : $w;
427 481
482 my $child = $self->child;
483
428 $self->child->size_allocate ($w, $h); 484 $child->size_allocate ($w, $h);
429 $self->child->move ($tex[3]->{width}, $tex[1]->{height}); 485 $child->move ($tex[3]->{width}, $tex[1]->{height});
430} 486}
431 487
432sub _draw { 488sub _draw {
433 my ($self) = @_; 489 my ($self) = @_;
434 490
470 526
471} 527}
472 528
473############################################################################# 529#############################################################################
474 530
475package Crossfire::Client::Widget::Table; 531package CFClient::Widget::Table;
476 532
477our @ISA = Crossfire::Client::Widget::Bin::; 533our @ISA = CFClient::Widget::Bin::;
478 534
479use SDL::OpenGL; 535use SDL::OpenGL;
480 536
481sub add { 537sub add {
482 my ($self, $x, $y, $chld) = @_; 538 my ($self, $x, $y, $chld) = @_;
557 } 613 }
558} 614}
559 615
560############################################################################# 616#############################################################################
561 617
562package Crossfire::Client::Widget::VBox; 618package CFClient::Widget::VBox;
563 619
564our @ISA = Crossfire::Client::Widget::Container::; 620our @ISA = CFClient::Widget::Container::;
565 621
566use SDL::OpenGL; 622use SDL::OpenGL;
567 623
568sub size_request { 624sub size_request {
569 my ($self) = @_; 625 my ($self) = @_;
617 } 673 }
618} 674}
619 675
620############################################################################# 676#############################################################################
621 677
622package Crossfire::Client::Widget::Label; 678package CFClient::Widget::Label;
623 679
624our @ISA = Crossfire::Client::Widget::; 680our @ISA = CFClient::Widget::;
625 681
626use SDL::OpenGL; 682use SDL::OpenGL;
627 683
628sub new { 684sub new {
629 my ($class, $x, $y, $z, $height, $text) = @_; 685 my ($class, %arg) = @_;
630
631 $height ||= $::FONTSIZE;
632 686
633 # TODO: color, and make height, xyz etc. optional 687 # TODO: color, and make height, xyz etc. optional
634 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); 688 my $self = $class->SUPER::new (
689 color => [1, 1, 1],
690 height => $::FONTSIZE,
691 text => "",
692 layout => new CFClient::Layout,
693 %arg
694 );
635 695
636 $self->set_text ($text); 696 $self->set_text ($self->{text});
637 697
638 $self 698 $self
639} 699}
640 700
641sub set_text { 701sub set_text {
642 my ($self, $text) = @_; 702 my ($self, $text) = @_;
643 703
644 $self->{text} = $text; 704 $self->{text} = $text;
645 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; 705 $self->{layout}->set_markup ($text);
646 706
647 $self->update; 707 delete $self->{texture};
648} 708}
649 709
650sub get_text { 710sub get_text {
651 my ($self, $text) = @_; 711 my ($self, $text) = @_;
652 712
654} 714}
655 715
656sub size_request { 716sub size_request {
657 my ($self) = @_; 717 my ($self) = @_;
658 718
719 $self->{layout}->set_width;
720 $self->{layout}->set_height ($self->{height});
721 $self->{layout}->size
659 if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 722# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
660 ( 723# (
661 $self->{texture}{width}, 724# $self->{texture}{width},
662 $self->{texture}{height}, 725# $self->{texture}{height},
663 ) 726# )
664 } else { 727# } else {
665 my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; 728# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height};
666 729#
667 ($w, $h) 730# ($w, $h)
668 } 731# }
732}
669 733
734sub size_allocate {
735 my ($self, $w, $h) = @_;
736
737 $self->SUPER::size_allocate ($w, $h);
738 delete $self->{texture};
670} 739}
671 740
672sub _draw { 741sub _draw {
673 my ($self) = @_; 742 my ($self) = @_;
674 743
675 my $tex = $self->{texture}; 744 my $tex = $self->{texture} ||= do {
745 $self->{layout}->set_width ($self->{w});
746 new_from_layout CFClient::Texture $self->{layout};
747 };
676 748
677 glEnable GL_BLEND; 749 glEnable GL_BLEND;
678 glEnable GL_TEXTURE_2D; 750 glEnable GL_TEXTURE_2D;
679 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 751 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
680 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 752 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
681 753
682 glColor 1, 0, 0, 1; # TODO color 754 glColor @{$self->{color}};
683 755
684 $tex->draw_quad (0, 0); 756 $tex->draw_quad (0, 0);
685 757
686 glDisable GL_BLEND; 758 glDisable GL_BLEND;
687 glDisable GL_TEXTURE_2D; 759 glDisable GL_TEXTURE_2D;
688} 760}
689 761
690############################################################################# 762#############################################################################
691 763
692package Crossfire::Client::Widget::Entry; 764package CFClient::Widget::Entry;
693 765
694our @ISA = Crossfire::Client::Widget::Label::; 766our @ISA = CFClient::Widget::Label::;
695 767
696use SDL; 768use SDL;
697use SDL::OpenGL; 769use SDL::OpenGL;
698 770
699sub key_down { 771sub key_down {
708 780
709 if ($sym == SDLK_BACKSPACE) { 781 if ($sym == SDLK_BACKSPACE) {
710 substr $text, -1, 1, ''; 782 substr $text, -1, 1, '';
711 } elsif ($uni) { 783 } elsif ($uni) {
712 $text .= chr $uni; 784 $text .= chr $uni;
713 print "$uni <$text>\n";#d#
714 } 785 }
715 786
716 $self->set_text ($text); 787 $self->set_text ($text);
717} 788}
718 789
719sub button_down { 790sub button_down {
720 my ($self, $ev) = @_; 791 my ($self, $ev) = @_;
721 792
722 $self->focus_in; 793 $self->focus_in;
794}
795
796sub mouse_motion {
797 my ($self, $ev, $x, $y) = @_;
798 printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
723} 799}
724 800
725sub _draw { 801sub _draw {
726 my ($self) = @_; 802 my ($self) = @_;
727 803
741 $self->SUPER::_draw; 817 $self->SUPER::_draw;
742} 818}
743 819
744############################################################################# 820#############################################################################
745 821
746package Crossfire::Client::Widget::MapWidget; 822package CFClient::Widget::MapWidget;
747 823
748use strict; 824use strict;
749 825
750use List::Util qw(min max); 826use List::Util qw(min max);
751 827
752use SDL; 828use SDL;
753use SDL::OpenGL; 829use SDL::OpenGL;
754use SDL::OpenGL::Constants; 830use SDL::OpenGL::Constants;
755 831
756our @ISA = Crossfire::Client::Widget::; 832our @ISA = CFClient::Widget::;
833
834sub new {
835 my $class = shift;
836
837 $class->SUPER::new (
838 z => -1,
839 list => (glGenLists 1),
840 @_
841 )
842}
757 843
758sub key_down { 844sub key_down {
759 print "MAPKEYDOWN\n"; 845 print "MAPKEYDOWN\n";
760} 846}
761 847
767 1 + int $::WIDTH / 32, 853 1 + int $::WIDTH / 32,
768 1 + int $::HEIGHT / 32, 854 1 + int $::HEIGHT / 32,
769 ) 855 )
770} 856}
771 857
858sub update {
859 my ($self) = @_;
860
861 $self->{need_update} = 1;
862}
863
772sub _draw { 864sub _draw {
773 my ($self) = @_; 865 my ($self) = @_;
774 866
867 if (delete $self->{need_update}) {
868 glNewList $self->{list}, GL_COMPILE;
869
775 my $mx = $::CONN->{mapx}; 870 my $mx = $::CONN->{mapx};
776 my $my = $::CONN->{mapy}; 871 my $my = $::CONN->{mapy};
777 872
778 my $map = $::CONN->{map}; 873 my $map = $::CONN->{map};
779 874
780 my ($xofs, $yofs); 875 my ($xofs, $yofs);
781 876
782 my $sw = 1 + int $::WIDTH / 32; 877 my $sw = 1 + int $::WIDTH / 32;
783 my $sh = 1 + int $::HEIGHT / 32; 878 my $sh = 1 + int $::HEIGHT / 32;
784 879
785 if ($::CONN->{mapw} > $sw) { 880 if ($::CONN->{mapw} > $sw) {
786 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; 881 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
787 } else { 882 } else {
788 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; 883 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
789 } 884 }
790 885
791 if ($::CONN->{maph} > $sh) { 886 if ($::CONN->{maph} > $sh) {
792 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; 887 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
793 } else { 888 } else {
794 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 889 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
795 } 890 }
796 891
797 glEnable GL_TEXTURE_2D; 892 glEnable GL_TEXTURE_2D;
798 glEnable GL_BLEND; 893 glEnable GL_BLEND;
799 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 894 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
800 895
801 my $sw4 = ($sw + 3) & ~3; 896 my $sw4 = ($sw + 3) & ~3;
802 my $lighting = "\x00" x ($sw4 * $sh); 897 my $darkness = "\x00" x ($sw4 * $sh);
803 898
804 for my $x (0 .. $sw - 1) { 899 for my $x (0 .. $sw - 1) {
900 my $row = $map->[$x + $xofs];
805 for my $y (0 .. $sh - 1) { 901 for my $y (0 .. $sh - 1) {
806 902
807 my $cell = $map->[$x + $xofs][$y + $yofs] 903 my $cell = $row->[$y + $yofs]
808 or next; 904 or next;
809 905
810 my $darkness = $cell->[0] * (1 / 255); 906 my $dark = $cell->[0];
811 if ($darkness < 0) { 907 if ($dark < 0) {
812 $darkness = $cell->[1] ? 0.1 : 0; 908 substr $darkness, $y * $sw4 + $x, 1, chr 224;
909 } else {
910 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
813 } 911 }
814 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255;
815 912
816 for my $num (grep $_, @$cell[1,2,3]) { 913 for my $num (grep $_, @$cell[1,2,3]) {
817 my $tex = $::CONN->{face}[$num]{texture} || next; 914 my $tex = $::CONN->{face}[$num]{texture} || next;
915
916 my $w = $tex->{width};
917 my $h = $tex->{height};
918
919 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
818 920 }
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 } 921 }
827 } 922 }
828 }
829 923
830# if (1) { # higher quality darkness 924# if (1) { # higher quality darkness
831# $lighting =~ s/(.)/$1$1$1/gs; 925# $lighting =~ s/(.)/$1$1$1/gs;
832# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; 926# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3;
833# 927#
835# 929#
836# $lighting = $pb->get_pixels; 930# $lighting = $pb->get_pixels;
837# $lighting =~ s/(.)../$1/gs; 931# $lighting =~ s/(.)../$1/gs;
838# } 932# }
839 933
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; 934 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; 935 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 936
937 $darkness = new CFClient::Texture
938 width => $sw4,
939 height => $sh,
940 data => $darkness,
941 internalformat => GL_ALPHA,
942 format => GL_ALPHA;
943
944 glColor 0.45, 0.45, 0.45, 1;
853 $lighting->draw_quad (0, 0, $sw4 * 32, $sh * 32); 945 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
854 946
855 glDisable GL_TEXTURE_2D; 947 glDisable GL_TEXTURE_2D;
856 glDisable GL_BLEND; 948 glDisable GL_BLEND;
949
950 glEndList;
951 }
952
953 glCallList $self->{list};
857} 954}
858 955
859my %DIR = ( 956my %DIR = (
860 SDLK_KP8, [1, "north"], 957 SDLK_KP8, [1, "north"],
861 SDLK_KP9, [2, "northeast"], 958 SDLK_KP9, [2, "northeast"],
907 } 1004 }
908} 1005}
909 1006
910############################################################################# 1007#############################################################################
911 1008
912package Crossfire::Client::Widget::Animator; 1009package CFClient::Widget::Animator;
913 1010
914use SDL::OpenGL; 1011use SDL::OpenGL;
915 1012
916our @ISA = Crossfire::Client::Widget::Bin::; 1013our @ISA = CFClient::Widget::Bin::;
917 1014
918sub moveto { 1015sub moveto {
919 my ($self, $x, $y) = @_; 1016 my ($self, $x, $y) = @_;
920 1017
921 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 1018 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
926} 1023}
927 1024
928sub animate { 1025sub animate {
929 my ($self, $interval) = @_; 1026 my ($self, $interval) = @_;
930 1027
931 printf "%5.2f\n", 1 / $interval;#d#
932
933 $self->{time} -= $interval * $self->{speed}; 1028 $self->{time} -= $interval * $self->{speed};
934 if ($self->{time} <= 0) { 1029 if ($self->{time} <= 0) {
935 $self->{time} = 0; 1030 $self->{time} = 0;
936 ::animation_stop $self; 1031 ::animation_stop $self;
937 } 1032 }
951 glPopMatrix; 1046 glPopMatrix;
952} 1047}
953 1048
954############################################################################# 1049#############################################################################
955 1050
956package Crossfire::Client::Widget::Toplevel; 1051package CFClient::Widget::Toplevel;
957 1052
958our @ISA = Crossfire::Client::Widget::Container::; 1053our @ISA = CFClient::Widget::Container::;
959 1054
960sub size_request { 1055sub size_request {
961 ($::WIDTH, $::HEIGHT) 1056 ($::WIDTH, $::HEIGHT)
962} 1057}
963 1058
968 1063
969 $_->size_allocate ($_->size_request) 1064 $_->size_allocate ($_->size_request)
970 for @{$self->{children}}; 1065 for @{$self->{children}};
971} 1066}
972 1067
1068sub translate {
1069 my ($self, $x, $y) = @_;
1070
1071 ($x, $y)
1072}
1073
973sub update { 1074sub update {
974 my ($self) = @_; 1075 my ($self) = @_;
975 1076
976 $self->size_allocate ($self->size_request); 1077 $self->size_allocate ($self->size_request);
977 ::refresh (); 1078 ::refresh ();
991 $self->_draw; 1092 $self->_draw;
992} 1093}
993 1094
994############################################################################# 1095#############################################################################
995 1096
996package Crossfire::Client::Widget; 1097package CFClient::Widget;
997 1098
998$TOPLEVEL = new Crossfire::Client::Widget::Toplevel; 1099$TOPLEVEL = new CFClient::Widget::Toplevel;
999 1100
10001 11011
1001 1102

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines