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.60 by root, Tue Apr 11 13:14:36 2006 UTC vs.
Revision 1.66 by root, Tue Apr 11 14:36:02 2006 UTC

73} 73}
74 74
75sub new { 75sub new {
76 my $class = shift; 76 my $class = shift;
77 77
78 bless { @_ }, $class 78 bless {
79 x => 0,
80 y => 0,
81 z => 0,
82 @_
83 }, $class
79} 84}
80 85
81sub move { 86sub move {
82 my ($self, $x, $y, $z) = @_; 87 my ($self, $x, $y, $z) = @_;
83 $self->{x} = $x; 88 $self->{x} = $x;
210 #$self->deactivate; 215 #$self->deactivate;
211} 216}
212 217
213############################################################################# 218#############################################################################
214 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
215package CFClient::Widget::Container; 233package CFClient::Widget::Container;
216 234
217our @ISA = CFClient::Widget::; 235our @ISA = CFClient::Widget::;
218 236
219sub new { 237sub new {
220 my ($class, @widgets) = @_; 238 my ($class, %arg) = @_;
221 239
240 my $children = delete $arg{children} || [];
241
222 my $self = $class->SUPER::new (children => []); 242 my $self = $class->SUPER::new (children => [], %arg);
223 $self->add ($_) for @widgets; 243 $self->add ($_) for @$children;
224 244
225 $self 245 $self
226} 246}
227 247
228sub add { 248sub add {
229 my ($self, $chld, $expand) = @_; 249 my ($self, $chld, $expand) = @_;
230 250
231 $chld->{expand} = $expand; 251 $chld->{expand} = $expand;
232 $chld->set_parent ($self); 252 $chld->set_parent ($self);
233 253
234 @{$self->{children}} = 254 $self->{children} = [
235 sort { $a->{z} <=> $b->{z} } 255 sort { $a->{z} <=> $b->{z} }
236 @{$self->{children}}, $chld; 256 @{$self->{children}}, $chld
257 ];
237 258
238 $self->size_allocate ($self->{w}, $self->{h}) 259 $self->size_allocate ($self->{w}, $self->{h})
239 if $self->{w}; #TODO: check for "realised state" 260 if $self->{w}; #TODO: check for "realised state"
240} 261}
241 262
273 294
274package CFClient::Widget::Bin; 295package CFClient::Widget::Bin;
275 296
276our @ISA = CFClient::Widget::Container::; 297our @ISA = CFClient::Widget::Container::;
277 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}
323
278sub child { $_[0]->{children}[0] } 324sub child { $_[0]->{children}[0] }
279 325
280sub size_request { 326sub size_request {
281 $_[0]{children}[0]->size_request if $_[0]{children}[0]; 327 $_[0]{children}[0]->size_request if $_[0]{children}[0];
282} 328}
296our @ISA = CFClient::Widget::Bin::; 342our @ISA = CFClient::Widget::Bin::;
297 343
298use SDL::OpenGL; 344use SDL::OpenGL;
299 345
300sub new { 346sub new {
301 my ($class, $x, $y, $z, $w, $h) = @_; 347 my ($class, %arg) = @_;
302 348
303 my $self = $class->SUPER::new; 349 my $self = $class->SUPER::new (%arg);
304
305 @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h);
306} 350}
307 351
308sub update { 352sub update {
309 my ($self) = @_; 353 my ($self) = @_;
310 354
355 # we want to do this delayed...
311 $self->render_chld; 356 $self->render_chld;
312 $self->SUPER::update; 357 $self->SUPER::update;
313} 358}
314 359
315sub render_chld { 360sub render_chld {
432 $w -= $tex[3]->{width}; 477 $w -= $tex[3]->{width};
433 478
434 $h = $h < 0 ? 0 : $h; 479 $h = $h < 0 ? 0 : $h;
435 $w = $w < 0 ? 0 : $w; 480 $w = $w < 0 ? 0 : $w;
436 481
482 my $child = $self->child;
483
437 $self->child->size_allocate ($w, $h); 484 $child->size_allocate ($w, $h);
438 $self->child->move ($tex[3]->{width}, $tex[1]->{height}); 485 $child->move ($tex[3]->{width}, $tex[1]->{height});
439} 486}
440 487
441sub _draw { 488sub _draw {
442 my ($self) = @_; 489 my ($self) = @_;
443 490
633our @ISA = CFClient::Widget::; 680our @ISA = CFClient::Widget::;
634 681
635use SDL::OpenGL; 682use SDL::OpenGL;
636 683
637sub new { 684sub new {
638 my ($class, $x, $y, $z, $height, $text) = @_; 685 my ($class, %arg) = @_;
639
640 $height ||= $::FONTSIZE;
641 686
642 # TODO: color, and make height, xyz etc. optional 687 # TODO: color, and make height, xyz etc. optional
643 my $self = $class->SUPER::new ( 688 my $self = $class->SUPER::new (
644 x => $x, 689 color => [1, 1, 1],
645 y => $y, 690 height => $::FONTSIZE,
646 z => $z, 691 text => "",
647 height => $height,
648 layout => new CFClient::Layout, 692 layout => new CFClient::Layout,
693 %arg
649 ); 694 );
650 695
651 $self->set_text ($text); 696 $self->set_text ($self->{text});
652 697
653 $self 698 $self
654} 699}
655 700
656sub set_text { 701sub set_text {
670 715
671sub size_request { 716sub size_request {
672 my ($self) = @_; 717 my ($self) = @_;
673 718
674 $self->{layout}->set_width; 719 $self->{layout}->set_width;
720 $self->{layout}->set_height ($self->{height});
675 $self->{layout}->size 721 $self->{layout}->size
676# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 722# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
677# ( 723# (
678# $self->{texture}{width}, 724# $self->{texture}{width},
679# $self->{texture}{height}, 725# $self->{texture}{height},
703 glEnable GL_BLEND; 749 glEnable GL_BLEND;
704 glEnable GL_TEXTURE_2D; 750 glEnable GL_TEXTURE_2D;
705 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 751 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
706 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 752 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
707 753
708 glColor 1, 0, 0, 1; # TODO color 754 glColor @{$self->{color}};
709 755
710 $tex->draw_quad (0, 0); 756 $tex->draw_quad (0, 0);
711 757
712 glDisable GL_BLEND; 758 glDisable GL_BLEND;
713 glDisable GL_TEXTURE_2D; 759 glDisable GL_TEXTURE_2D;
783use SDL::OpenGL; 829use SDL::OpenGL;
784use SDL::OpenGL::Constants; 830use SDL::OpenGL::Constants;
785 831
786our @ISA = CFClient::Widget::; 832our @ISA = CFClient::Widget::;
787 833
834sub new {
835 my $class = shift;
836
837 $class->SUPER::new (
838 z => -1,
839 list => (glGenLists 1),
840 @_
841 )
842}
843
788sub key_down { 844sub key_down {
789 print "MAPKEYDOWN\n"; 845 print "MAPKEYDOWN\n";
790} 846}
791 847
792sub key_up { 848sub key_up {
797 1 + int $::WIDTH / 32, 853 1 + int $::WIDTH / 32,
798 1 + int $::HEIGHT / 32, 854 1 + int $::HEIGHT / 32,
799 ) 855 )
800} 856}
801 857
858sub update {
859 my ($self) = @_;
860
861 $self->{need_update} = 1;
862}
863
802sub _draw { 864sub _draw {
803 my ($self) = @_; 865 my ($self) = @_;
804 866
867 if (delete $self->{need_update}) {
868 glNewList $self->{list}, GL_COMPILE;
869
805 my $mx = $::CONN->{mapx}; 870 my $mx = $::CONN->{mapx};
806 my $my = $::CONN->{mapy}; 871 my $my = $::CONN->{mapy};
807 872
808 my $map = $::CONN->{map}; 873 my $map = $::CONN->{map};
809 874
810 my ($xofs, $yofs); 875 my ($xofs, $yofs);
811 876
812 my $sw = 1 + int $::WIDTH / 32; 877 my $sw = 1 + int $::WIDTH / 32;
813 my $sh = 1 + int $::HEIGHT / 32; 878 my $sh = 1 + int $::HEIGHT / 32;
814 879
815 if ($::CONN->{mapw} > $sw) { 880 if ($::CONN->{mapw} > $sw) {
816 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; 881 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
817 } else { 882 } else {
818 $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};
819 } 884 }
820 885
821 if ($::CONN->{maph} > $sh) { 886 if ($::CONN->{maph} > $sh) {
822 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; 887 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
823 } else { 888 } else {
824 $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};
825 } 890 }
826 891
827 glEnable GL_TEXTURE_2D; 892 glEnable GL_TEXTURE_2D;
828 glEnable GL_BLEND; 893 glEnable GL_BLEND;
829 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 894 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
830 895
831 my $sw4 = ($sw + 3) & ~3; 896 my $sw4 = ($sw + 3) & ~3;
832 my $darkness = "\x00" x ($sw4 * $sh); 897 my $darkness = "\x00" x ($sw4 * $sh);
833 898
834 for my $x (0 .. $sw - 1) { 899 for my $x (0 .. $sw - 1) {
835 my $row = $map->[$x + $xofs]; 900 my $row = $map->[$x + $xofs];
836 for my $y (0 .. $sh - 1) { 901 for my $y (0 .. $sh - 1) {
837 902
838 my $cell = $row->[$y + $yofs] 903 my $cell = $row->[$y + $yofs]
839 or next; 904 or next;
840 905
841 my $dark = $cell->[0]; 906 my $dark = $cell->[0];
842 if ($dark < 0) { 907 if ($dark < 0) {
843 substr $darkness, $y * $sw4 + $x, 1, chr 224; 908 substr $darkness, $y * $sw4 + $x, 1, chr 224;
844 } else { 909 } else {
845 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; 910 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
846 } 911 }
847 912
848 for my $num (grep $_, @$cell[1,2,3]) { 913 for my $num (grep $_, @$cell[1,2,3]) {
849 my $tex = $::CONN->{face}[$num]{texture} || next; 914 my $tex = $::CONN->{face}[$num]{texture} || next;
850 915
851 my $w = $tex->{width}; 916 my $w = $tex->{width};
852 my $h = $tex->{height}; 917 my $h = $tex->{height};
853 918
854 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); 919 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
920 }
855 } 921 }
856 } 922 }
857 }
858 923
859# if (1) { # higher quality darkness 924# if (1) { # higher quality darkness
860# $lighting =~ s/(.)/$1$1$1/gs; 925# $lighting =~ s/(.)/$1$1$1/gs;
861# 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;
862# 927#
864# 929#
865# $lighting = $pb->get_pixels; 930# $lighting = $pb->get_pixels;
866# $lighting =~ s/(.)../$1/gs; 931# $lighting =~ s/(.)../$1/gs;
867# } 932# }
868 933
869 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 934 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
870 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 935 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
871 936
872 $darkness = new CFClient::Texture 937 $darkness = new CFClient::Texture
873 width => $sw4, 938 width => $sw4,
874 height => $sh, 939 height => $sh,
875 data => $darkness, 940 data => $darkness,
876 internalformat => GL_ALPHA, 941 internalformat => GL_ALPHA,
877 format => GL_ALPHA; 942 format => GL_ALPHA;
878 943
879 glColor 0.45, 0.45, 0.45, 1; 944 glColor 0.45, 0.45, 0.45, 1;
880 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); 945 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
881 946
882 glDisable GL_TEXTURE_2D; 947 glDisable GL_TEXTURE_2D;
883 glDisable GL_BLEND; 948 glDisable GL_BLEND;
949
950 glEndList;
951 }
952
953 glCallList $self->{list};
884} 954}
885 955
886my %DIR = ( 956my %DIR = (
887 SDLK_KP8, [1, "north"], 957 SDLK_KP8, [1, "north"],
888 SDLK_KP9, [2, "northeast"], 958 SDLK_KP9, [2, "northeast"],

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines