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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines