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.63 by root, Tue Apr 11 13:29:24 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
634our @ISA = CFClient::Widget::; 639our @ISA = CFClient::Widget::;
635 640
636use SDL::OpenGL; 641use SDL::OpenGL;
637 642
638sub new { 643sub new {
639 my ($class, $x, $y, $z, $height, $text) = @_; 644 my ($class, %arg) = @_;
640
641 $height ||= $::FONTSIZE;
642 645
643 # TODO: color, and make height, xyz etc. optional 646 # TODO: color, and make height, xyz etc. optional
644 my $self = $class->SUPER::new ( 647 my $self = $class->SUPER::new (
645 color => [1, 1, 1], 648 color => [1, 1, 1],
646 x => $x, 649 height => $::FONTSIZE,
647 y => $y, 650 text => "",
648 z => $z,
649 height => $height,
650 layout => new CFClient::Layout $height, 651 layout => new CFClient::Layout,
652 %arg
651 ); 653 );
652 654
653 $self->set_text ($text); 655 $self->set_text ($self->{text});
654 656
655 $self 657 $self
656} 658}
657 659
658sub set_text { 660sub set_text {
672 674
673sub size_request { 675sub size_request {
674 my ($self) = @_; 676 my ($self) = @_;
675 677
676 $self->{layout}->set_width; 678 $self->{layout}->set_width;
679 $self->{layout}->set_height ($self->{height});
677 $self->{layout}->size 680 $self->{layout}->size
678# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 681# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
679# ( 682# (
680# $self->{texture}{width}, 683# $self->{texture}{width},
681# $self->{texture}{height}, 684# $self->{texture}{height},
785use SDL::OpenGL; 788use SDL::OpenGL;
786use SDL::OpenGL::Constants; 789use SDL::OpenGL::Constants;
787 790
788our @ISA = CFClient::Widget::; 791our @ISA = CFClient::Widget::;
789 792
793sub new {
794 my $class = shift;
795
796 $class->SUPER::new (
797 z => -1,
798 list => (glGenLists 1),
799 @_
800 )
801}
802
790sub key_down { 803sub key_down {
791 print "MAPKEYDOWN\n"; 804 print "MAPKEYDOWN\n";
792} 805}
793 806
794sub key_up { 807sub key_up {
799 1 + int $::WIDTH / 32, 812 1 + int $::WIDTH / 32,
800 1 + int $::HEIGHT / 32, 813 1 + int $::HEIGHT / 32,
801 ) 814 )
802} 815}
803 816
817sub update {
818 my ($self) = @_;
819
820 $self->{need_update} = 1;
821}
822
804sub _draw { 823sub _draw {
805 my ($self) = @_; 824 my ($self) = @_;
806 825
826 if (delete $self->{need_update}) {
827 glNewList $self->{list}, GL_COMPILE;
828
807 my $mx = $::CONN->{mapx}; 829 my $mx = $::CONN->{mapx};
808 my $my = $::CONN->{mapy}; 830 my $my = $::CONN->{mapy};
809 831
810 my $map = $::CONN->{map}; 832 my $map = $::CONN->{map};
811 833
812 my ($xofs, $yofs); 834 my ($xofs, $yofs);
813 835
814 my $sw = 1 + int $::WIDTH / 32; 836 my $sw = 1 + int $::WIDTH / 32;
815 my $sh = 1 + int $::HEIGHT / 32; 837 my $sh = 1 + int $::HEIGHT / 32;
816 838
817 if ($::CONN->{mapw} > $sw) { 839 if ($::CONN->{mapw} > $sw) {
818 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; 840 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
819 } else { 841 } else {
820 $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};
821 } 843 }
822 844
823 if ($::CONN->{maph} > $sh) { 845 if ($::CONN->{maph} > $sh) {
824 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; 846 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
825 } else { 847 } else {
826 $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};
827 } 849 }
828 850
829 glEnable GL_TEXTURE_2D; 851 glEnable GL_TEXTURE_2D;
830 glEnable GL_BLEND; 852 glEnable GL_BLEND;
831 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 853 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
832 854
833 my $sw4 = ($sw + 3) & ~3; 855 my $sw4 = ($sw + 3) & ~3;
834 my $darkness = "\x00" x ($sw4 * $sh); 856 my $darkness = "\x00" x ($sw4 * $sh);
835 857
836 for my $x (0 .. $sw - 1) { 858 for my $x (0 .. $sw - 1) {
837 my $row = $map->[$x + $xofs]; 859 my $row = $map->[$x + $xofs];
838 for my $y (0 .. $sh - 1) { 860 for my $y (0 .. $sh - 1) {
839 861
840 my $cell = $row->[$y + $yofs] 862 my $cell = $row->[$y + $yofs]
841 or next; 863 or next;
842 864
843 my $dark = $cell->[0]; 865 my $dark = $cell->[0];
844 if ($dark < 0) { 866 if ($dark < 0) {
845 substr $darkness, $y * $sw4 + $x, 1, chr 224; 867 substr $darkness, $y * $sw4 + $x, 1, chr 224;
846 } else { 868 } else {
847 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; 869 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
848 } 870 }
849 871
850 for my $num (grep $_, @$cell[1,2,3]) { 872 for my $num (grep $_, @$cell[1,2,3]) {
851 my $tex = $::CONN->{face}[$num]{texture} || next; 873 my $tex = $::CONN->{face}[$num]{texture} || next;
852 874
853 my $w = $tex->{width}; 875 my $w = $tex->{width};
854 my $h = $tex->{height}; 876 my $h = $tex->{height};
855 877
856 $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 }
857 } 880 }
858 } 881 }
859 }
860 882
861# if (1) { # higher quality darkness 883# if (1) { # higher quality darkness
862# $lighting =~ s/(.)/$1$1$1/gs; 884# $lighting =~ s/(.)/$1$1$1/gs;
863# 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;
864# 886#
866# 888#
867# $lighting = $pb->get_pixels; 889# $lighting = $pb->get_pixels;
868# $lighting =~ s/(.)../$1/gs; 890# $lighting =~ s/(.)../$1/gs;
869# } 891# }
870 892
871 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 893 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
872 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 894 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
873 895
874 $darkness = new CFClient::Texture 896 $darkness = new CFClient::Texture
875 width => $sw4, 897 width => $sw4,
876 height => $sh, 898 height => $sh,
877 data => $darkness, 899 data => $darkness,
878 internalformat => GL_ALPHA, 900 internalformat => GL_ALPHA,
879 format => GL_ALPHA; 901 format => GL_ALPHA;
880 902
881 glColor 0.45, 0.45, 0.45, 1; 903 glColor 0.45, 0.45, 0.45, 1;
882 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); 904 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
883 905
884 glDisable GL_TEXTURE_2D; 906 glDisable GL_TEXTURE_2D;
885 glDisable GL_BLEND; 907 glDisable GL_BLEND;
908
909 glEndList;
910 }
911
912 glCallList $self->{list};
886} 913}
887 914
888my %DIR = ( 915my %DIR = (
889 SDLK_KP8, [1, "north"], 916 SDLK_KP8, [1, "north"],
890 SDLK_KP9, [2, "northeast"], 917 SDLK_KP9, [2, "northeast"],

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines