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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines