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.65 by root, Tue Apr 11 14:04:27 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;
215package CFClient::Widget::Container; 220package CFClient::Widget::Container;
216 221
217our @ISA = CFClient::Widget::; 222our @ISA = CFClient::Widget::;
218 223
219sub new { 224sub new {
220 my ($class, @widgets) = @_; 225 my ($class, %arg) = @_;
221 226
227 my $children = delete $arg{children} || [];
228
222 my $self = $class->SUPER::new (children => []); 229 my $self = $class->SUPER::new (children => [], %arg);
223 $self->add ($_) for @widgets; 230 $self->add ($_) for @$children;
224 231
225 $self 232 $self
226} 233}
227 234
228sub add { 235sub add {
296our @ISA = CFClient::Widget::Bin::; 303our @ISA = CFClient::Widget::Bin::;
297 304
298use SDL::OpenGL; 305use SDL::OpenGL;
299 306
300sub new { 307sub new {
301 my ($class, $x, $y, $z, $w, $h) = @_; 308 my ($class, %arg) = @_;
302 309
303 my $self = $class->SUPER::new; 310 my $self = $class->SUPER::new (%arg);
304
305 @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h);
306} 311}
307 312
308sub update { 313sub update {
309 my ($self) = @_; 314 my ($self) = @_;
310 315
316 # we want to do this delayed...
311 $self->render_chld; 317 $self->render_chld;
312 $self->SUPER::update; 318 $self->SUPER::update;
313} 319}
314 320
315sub render_chld { 321sub render_chld {
633our @ISA = CFClient::Widget::; 639our @ISA = CFClient::Widget::;
634 640
635use SDL::OpenGL; 641use SDL::OpenGL;
636 642
637sub new { 643sub new {
638 my ($class, $x, $y, $z, $height, $text) = @_; 644 my ($class, %arg) = @_;
639
640 $height ||= $::FONTSIZE;
641 645
642 # TODO: color, and make height, xyz etc. optional 646 # TODO: color, and make height, xyz etc. optional
643 my $self = $class->SUPER::new ( 647 my $self = $class->SUPER::new (
644 x => $x, 648 color => [1, 1, 1],
645 y => $y, 649 height => $::FONTSIZE,
646 z => $z, 650 text => "",
647 height => $height,
648 layout => new CFClient::Layout, 651 layout => new CFClient::Layout,
652 %arg
649 ); 653 );
650 654
651 $self->set_text ($text); 655 $self->set_text ($self->{text});
652 656
653 $self 657 $self
654} 658}
655 659
656sub set_text { 660sub set_text {
670 674
671sub size_request { 675sub size_request {
672 my ($self) = @_; 676 my ($self) = @_;
673 677
674 $self->{layout}->set_width; 678 $self->{layout}->set_width;
679 $self->{layout}->set_height ($self->{height});
675 $self->{layout}->size 680 $self->{layout}->size
676# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 681# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
677# ( 682# (
678# $self->{texture}{width}, 683# $self->{texture}{width},
679# $self->{texture}{height}, 684# $self->{texture}{height},
703 glEnable GL_BLEND; 708 glEnable GL_BLEND;
704 glEnable GL_TEXTURE_2D; 709 glEnable GL_TEXTURE_2D;
705 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 710 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
706 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 711 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
707 712
708 glColor 1, 0, 0, 1; # TODO color 713 glColor @{$self->{color}};
709 714
710 $tex->draw_quad (0, 0); 715 $tex->draw_quad (0, 0);
711 716
712 glDisable GL_BLEND; 717 glDisable GL_BLEND;
713 glDisable GL_TEXTURE_2D; 718 glDisable GL_TEXTURE_2D;
783use SDL::OpenGL; 788use SDL::OpenGL;
784use SDL::OpenGL::Constants; 789use SDL::OpenGL::Constants;
785 790
786our @ISA = CFClient::Widget::; 791our @ISA = CFClient::Widget::;
787 792
793sub new {
794 my $class = shift;
795
796 $class->SUPER::new (
797 z => -1,
798 list => (glGenLists 1),
799 @_
800 )
801}
802
788sub key_down { 803sub key_down {
789 print "MAPKEYDOWN\n"; 804 print "MAPKEYDOWN\n";
790} 805}
791 806
792sub key_up { 807sub key_up {
797 1 + int $::WIDTH / 32, 812 1 + int $::WIDTH / 32,
798 1 + int $::HEIGHT / 32, 813 1 + int $::HEIGHT / 32,
799 ) 814 )
800} 815}
801 816
817sub update {
818 my ($self) = @_;
819
820 $self->{need_update} = 1;
821}
822
802sub _draw { 823sub _draw {
803 my ($self) = @_; 824 my ($self) = @_;
804 825
826 if (delete $self->{need_update}) {
827 glNewList $self->{list}, GL_COMPILE;
828
805 my $mx = $::CONN->{mapx}; 829 my $mx = $::CONN->{mapx};
806 my $my = $::CONN->{mapy}; 830 my $my = $::CONN->{mapy};
807 831
808 my $map = $::CONN->{map}; 832 my $map = $::CONN->{map};
809 833
810 my ($xofs, $yofs); 834 my ($xofs, $yofs);
811 835
812 my $sw = 1 + int $::WIDTH / 32; 836 my $sw = 1 + int $::WIDTH / 32;
813 my $sh = 1 + int $::HEIGHT / 32; 837 my $sh = 1 + int $::HEIGHT / 32;
814 838
815 if ($::CONN->{mapw} > $sw) { 839 if ($::CONN->{mapw} > $sw) {
816 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; 840 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
817 } else { 841 } else {
818 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; 842 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
819 } 843 }
820 844
821 if ($::CONN->{maph} > $sh) { 845 if ($::CONN->{maph} > $sh) {
822 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; 846 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
823 } else { 847 } else {
824 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 848 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
825 } 849 }
826 850
827 glEnable GL_TEXTURE_2D; 851 glEnable GL_TEXTURE_2D;
828 glEnable GL_BLEND; 852 glEnable GL_BLEND;
829 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 853 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
830 854
831 my $sw4 = ($sw + 3) & ~3; 855 my $sw4 = ($sw + 3) & ~3;
832 my $darkness = "\x00" x ($sw4 * $sh); 856 my $darkness = "\x00" x ($sw4 * $sh);
833 857
834 for my $x (0 .. $sw - 1) { 858 for my $x (0 .. $sw - 1) {
835 my $row = $map->[$x + $xofs]; 859 my $row = $map->[$x + $xofs];
836 for my $y (0 .. $sh - 1) { 860 for my $y (0 .. $sh - 1) {
837 861
838 my $cell = $row->[$y + $yofs] 862 my $cell = $row->[$y + $yofs]
839 or next; 863 or next;
840 864
841 my $dark = $cell->[0]; 865 my $dark = $cell->[0];
842 if ($dark < 0) { 866 if ($dark < 0) {
843 substr $darkness, $y * $sw4 + $x, 1, chr 224; 867 substr $darkness, $y * $sw4 + $x, 1, chr 224;
844 } else { 868 } else {
845 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; 869 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
846 } 870 }
847 871
848 for my $num (grep $_, @$cell[1,2,3]) { 872 for my $num (grep $_, @$cell[1,2,3]) {
849 my $tex = $::CONN->{face}[$num]{texture} || next; 873 my $tex = $::CONN->{face}[$num]{texture} || next;
850 874
851 my $w = $tex->{width}; 875 my $w = $tex->{width};
852 my $h = $tex->{height}; 876 my $h = $tex->{height};
853 877
854 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); 878 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
879 }
855 } 880 }
856 } 881 }
857 }
858 882
859# if (1) { # higher quality darkness 883# if (1) { # higher quality darkness
860# $lighting =~ s/(.)/$1$1$1/gs; 884# $lighting =~ s/(.)/$1$1$1/gs;
861# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; 885# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3;
862# 886#
864# 888#
865# $lighting = $pb->get_pixels; 889# $lighting = $pb->get_pixels;
866# $lighting =~ s/(.)../$1/gs; 890# $lighting =~ s/(.)../$1/gs;
867# } 891# }
868 892
869 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 893 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
870 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 894 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
871 895
872 $darkness = new CFClient::Texture 896 $darkness = new CFClient::Texture
873 width => $sw4, 897 width => $sw4,
874 height => $sh, 898 height => $sh,
875 data => $darkness, 899 data => $darkness,
876 internalformat => GL_ALPHA, 900 internalformat => GL_ALPHA,
877 format => GL_ALPHA; 901 format => GL_ALPHA;
878 902
879 glColor 0.45, 0.45, 0.45, 1; 903 glColor 0.45, 0.45, 0.45, 1;
880 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); 904 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
881 905
882 glDisable GL_TEXTURE_2D; 906 glDisable GL_TEXTURE_2D;
883 glDisable GL_BLEND; 907 glDisable GL_BLEND;
908
909 glEndList;
910 }
911
912 glCallList $self->{list};
884} 913}
885 914
886my %DIR = ( 915my %DIR = (
887 SDLK_KP8, [1, "north"], 916 SDLK_KP8, [1, "north"],
888 SDLK_KP9, [2, "northeast"], 917 SDLK_KP9, [2, "northeast"],

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines