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.64 by root, Tue Apr 11 13:38:22 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, %arg) = @_; 238 my ($class, %arg) = @_;
221 239
222 my $children = delete $arg{children} || []; 240 my $children = delete $arg{children} || [];
223 241
224 my $self = $class->SUPER::new (children => []); 242 my $self = $class->SUPER::new (children => [], %arg);
225 $self->add ($_) for @$children; 243 $self->add ($_) for @$children;
226 244
227 $self 245 $self
228} 246}
229 247
231 my ($self, $chld, $expand) = @_; 249 my ($self, $chld, $expand) = @_;
232 250
233 $chld->{expand} = $expand; 251 $chld->{expand} = $expand;
234 $chld->set_parent ($self); 252 $chld->set_parent ($self);
235 253
236 @{$self->{children}} = 254 $self->{children} = [
237 sort { $a->{z} <=> $b->{z} } 255 sort { $a->{z} <=> $b->{z} }
238 @{$self->{children}}, $chld; 256 @{$self->{children}}, $chld
257 ];
239 258
240 $self->size_allocate ($self->{w}, $self->{h}) 259 $self->size_allocate ($self->{w}, $self->{h})
241 if $self->{w}; #TODO: check for "realised state" 260 if $self->{w}; #TODO: check for "realised state"
242} 261}
243 262
274############################################################################# 293#############################################################################
275 294
276package CFClient::Widget::Bin; 295package CFClient::Widget::Bin;
277 296
278our @ISA = CFClient::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}
279 323
280sub child { $_[0]->{children}[0] } 324sub child { $_[0]->{children}[0] }
281 325
282sub size_request { 326sub size_request {
283 $_[0]{children}[0]->size_request if $_[0]{children}[0]; 327 $_[0]{children}[0]->size_request if $_[0]{children}[0];
433 $w -= $tex[3]->{width}; 477 $w -= $tex[3]->{width};
434 478
435 $h = $h < 0 ? 0 : $h; 479 $h = $h < 0 ? 0 : $h;
436 $w = $w < 0 ? 0 : $w; 480 $w = $w < 0 ? 0 : $w;
437 481
482 my $child = $self->child;
483
438 $self->child->size_allocate ($w, $h); 484 $child->size_allocate ($w, $h);
439 $self->child->move ($tex[3]->{width}, $tex[1]->{height}); 485 $child->move ($tex[3]->{width}, $tex[1]->{height});
440} 486}
441 487
442sub _draw { 488sub _draw {
443 my ($self) = @_; 489 my ($self) = @_;
444 490
786our @ISA = CFClient::Widget::; 832our @ISA = CFClient::Widget::;
787 833
788sub new { 834sub new {
789 my $class = shift; 835 my $class = shift;
790 836
791 $class->SUPER::new (z => -1, @_) 837 $class->SUPER::new (
838 z => -1,
839 list => (glGenLists 1),
840 @_
841 )
792} 842}
793 843
794sub key_down { 844sub key_down {
795 print "MAPKEYDOWN\n"; 845 print "MAPKEYDOWN\n";
796} 846}
803 1 + int $::WIDTH / 32, 853 1 + int $::WIDTH / 32,
804 1 + int $::HEIGHT / 32, 854 1 + int $::HEIGHT / 32,
805 ) 855 )
806} 856}
807 857
858sub update {
859 my ($self) = @_;
860
861 $self->{need_update} = 1;
862}
863
808sub _draw { 864sub _draw {
809 my ($self) = @_; 865 my ($self) = @_;
810 866
867 if (delete $self->{need_update}) {
868 glNewList $self->{list}, GL_COMPILE;
869
811 my $mx = $::CONN->{mapx}; 870 my $mx = $::CONN->{mapx};
812 my $my = $::CONN->{mapy}; 871 my $my = $::CONN->{mapy};
813 872
814 my $map = $::CONN->{map}; 873 my $map = $::CONN->{map};
815 874
816 my ($xofs, $yofs); 875 my ($xofs, $yofs);
817 876
818 my $sw = 1 + int $::WIDTH / 32; 877 my $sw = 1 + int $::WIDTH / 32;
819 my $sh = 1 + int $::HEIGHT / 32; 878 my $sh = 1 + int $::HEIGHT / 32;
820 879
821 if ($::CONN->{mapw} > $sw) { 880 if ($::CONN->{mapw} > $sw) {
822 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; 881 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
823 } else { 882 } else {
824 $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};
825 } 884 }
826 885
827 if ($::CONN->{maph} > $sh) { 886 if ($::CONN->{maph} > $sh) {
828 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; 887 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
829 } else { 888 } else {
830 $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};
831 } 890 }
832 891
833 glEnable GL_TEXTURE_2D; 892 glEnable GL_TEXTURE_2D;
834 glEnable GL_BLEND; 893 glEnable GL_BLEND;
835 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 894 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
836 895
837 my $sw4 = ($sw + 3) & ~3; 896 my $sw4 = ($sw + 3) & ~3;
838 my $darkness = "\x00" x ($sw4 * $sh); 897 my $darkness = "\x00" x ($sw4 * $sh);
839 898
840 for my $x (0 .. $sw - 1) { 899 for my $x (0 .. $sw - 1) {
841 my $row = $map->[$x + $xofs]; 900 my $row = $map->[$x + $xofs];
842 for my $y (0 .. $sh - 1) { 901 for my $y (0 .. $sh - 1) {
843 902
844 my $cell = $row->[$y + $yofs] 903 my $cell = $row->[$y + $yofs]
845 or next; 904 or next;
846 905
847 my $dark = $cell->[0]; 906 my $dark = $cell->[0];
848 if ($dark < 0) { 907 if ($dark < 0) {
849 substr $darkness, $y * $sw4 + $x, 1, chr 224; 908 substr $darkness, $y * $sw4 + $x, 1, chr 224;
850 } else { 909 } else {
851 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; 910 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
852 } 911 }
853 912
854 for my $num (grep $_, @$cell[1,2,3]) { 913 for my $num (grep $_, @$cell[1,2,3]) {
855 my $tex = $::CONN->{face}[$num]{texture} || next; 914 my $tex = $::CONN->{face}[$num]{texture} || next;
856 915
857 my $w = $tex->{width}; 916 my $w = $tex->{width};
858 my $h = $tex->{height}; 917 my $h = $tex->{height};
859 918
860 $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 }
861 } 921 }
862 } 922 }
863 }
864 923
865# if (1) { # higher quality darkness 924# if (1) { # higher quality darkness
866# $lighting =~ s/(.)/$1$1$1/gs; 925# $lighting =~ s/(.)/$1$1$1/gs;
867# 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;
868# 927#
870# 929#
871# $lighting = $pb->get_pixels; 930# $lighting = $pb->get_pixels;
872# $lighting =~ s/(.)../$1/gs; 931# $lighting =~ s/(.)../$1/gs;
873# } 932# }
874 933
875 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 934 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
876 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 935 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
877 936
878 $darkness = new CFClient::Texture 937 $darkness = new CFClient::Texture
879 width => $sw4, 938 width => $sw4,
880 height => $sh, 939 height => $sh,
881 data => $darkness, 940 data => $darkness,
882 internalformat => GL_ALPHA, 941 internalformat => GL_ALPHA,
883 format => GL_ALPHA; 942 format => GL_ALPHA;
884 943
885 glColor 0.45, 0.45, 0.45, 1; 944 glColor 0.45, 0.45, 0.45, 1;
886 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); 945 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
887 946
888 glDisable GL_TEXTURE_2D; 947 glDisable GL_TEXTURE_2D;
889 glDisable GL_BLEND; 948 glDisable GL_BLEND;
949
950 glEndList;
951 }
952
953 glCallList $self->{list};
890} 954}
891 955
892my %DIR = ( 956my %DIR = (
893 SDLK_KP8, [1, "north"], 957 SDLK_KP8, [1, "north"],
894 SDLK_KP9, [2, "northeast"], 958 SDLK_KP9, [2, "northeast"],

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines