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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines