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.77 by root, Tue Apr 11 22:14:13 2006 UTC vs.
Revision 1.78 by root, Tue Apr 11 22:49:13 2006 UTC

200 my ($self) = @_; 200 my ($self) = @_;
201 201
202 warn "no draw defined for $self\n"; 202 warn "no draw defined for $self\n";
203} 203}
204 204
205sub bbox {
206 my ($self) = @_;
207 my ($w, $h) = $self->size_request;
208 (
209 $self->{x},
210 $self->{y},
211 $self->{x} = $w,
212 $self->{y} = $h
213 )
214}
215
216sub find_widget { 205sub find_widget {
217 my ($self, $x, $y) = @_; 206 my ($self, $x, $y) = @_;
218 207
219 return $self 208 return $self
220 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 209 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
221 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 210 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
222 211
223 () 212 ()
224} 213}
225
226sub del_parent { $_[0]->{parent} = undef }
227 214
228sub set_parent { 215sub set_parent {
229 my ($self, $par) = @_; 216 my ($self, $par) = @_;
230 217
231 $self->{parent} = $par; 218 $self->{parent} = $par;
537 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 524 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
538 525
539sub size_request { 526sub size_request {
540 my ($self) = @_; 527 my ($self) = @_;
541 528
542 my ($w, $h) = 529 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
543 $self->{user_w} && $self->{user_h} 530
544 ? ($self->{user_w}, $self->{user_h})
545 : ($self->SUPER::size_request); 531 my ($w, $h) = $self->SUPER::size_request;
546 532
547 $h += $tex[1]->{h}; 533 $h += $tex[1]->{h};
548 $h += $tex[4]->{h}; 534 $h += $tex[4]->{h};
549 $w += $tex[2]->{w}; 535 $w += $tex[2]->{w};
550 $w += $tex[3]->{w}; 536 $w += $tex[3]->{w};
668 654
669use List::Util qw(max sum); 655use List::Util qw(max sum);
670 656
671use SDL::OpenGL; 657use SDL::OpenGL;
672 658
659sub new {
660 my $class = shift;
661
662 $class->SUPER::new (
663 col_expand => [],
664 @_
665 )
666}
667
673sub add { 668sub add {
674 my ($self, $x, $y, $chld) = @_; 669 my ($self, $x, $y, $chld) = @_;
675 670
676 $self->{children}[$y][$x] = $chld; 671 $self->{children}[$y][$x] = $chld;
677 $chld->set_parent ($self); 672 $chld->set_parent ($self);
706 my ($self) = @_; 701 my ($self) = @_;
707 702
708 my ($ws, $hs) = $self->get_wh; 703 my ($ws, $hs) = $self->get_wh;
709 704
710 ( 705 (
711 (List::Util::sum @$ws), 706 (sum @$ws),
712 (List::Util::sum @$hs), 707 (sum @$hs),
713 ) 708 )
714} 709}
715 710
716sub size_allocate { 711sub size_allocate {
717 my ($self, $x, $y, $w, $h) = @_; 712 my ($self, $x, $y, $w, $h) = @_;
718 713
719 $self->_size_allocate ($x, $y, $w, $h) or return; 714 $self->_size_allocate ($x, $y, $w, $h) or return;
720 715
721 my ($ws, $hs) = $self->get_wh; 716 my ($ws, $hs) = $self->get_wh;
722 717
723 my $req_w = List::Util::sum @$ws; 718 my $req_w = sum @$ws;
724 my $req_h = List::Util::sum @$hs; 719 my $req_h = sum @$hs;
720
721 # TODO: nicer code && do row_expand
722 my @col_expand = @{$self->{col_expand}};
723 @col_expand = (1) x @$ws unless @col_expand;
724 my $col_expand = (sum @col_expand) || 1;
725 725
726 # linearly scale sizes 726 # linearly scale sizes
727 $_ *= $w / $req_w for @$ws; 727 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
728 $_ *= $h / $req_h for @$hs; 728 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
729 729
730 my $y; 730 my $y;
731 731
732 for my $r (0 .. $#{$self->{children}}) { 732 for my $r (0 .. $#{$self->{children}}) {
733 my $row = $self->{children}[$r] 733 my $row = $self->{children}[$r]
810 810
811 my $req_h = List::Util::sum @h; 811 my $req_h = List::Util::sum @h;
812 812
813 if ($req_h > $h) { 813 if ($req_h > $h) {
814 # ah well, not enough space 814 # ah well, not enough space
815 $_ = $h[$_] * $h / $req_h for @h; 815 $_ *= $h / $req_h for @h;
816 } else { 816 } else {
817 my $exp = List::Util::sum map $_->{expand}, @$children; 817 my $exp = List::Util::sum map $_->{expand}, @$children;
818 $exp ||= 1; 818 $exp ||= 1;
819 819
820 for (0 .. $#$children) { 820 for (0 .. $#$children) {
868 868
869 my $req_h = List::Util::sum @h; 869 my $req_h = List::Util::sum @h;
870 870
871 if ($req_h > $h) { 871 if ($req_h > $h) {
872 # ah well, not enough space 872 # ah well, not enough space
873 $_ = $h[$_] * $h / $req_h for @h; 873 $_ *= $h / $req_h for @h;
874 } else { 874 } else {
875 my $exp = List::Util::sum map $_->{expand}, @$children; 875 my $exp = List::Util::sum map $_->{expand}, @$children;
876 $exp ||= 1; 876 $exp ||= 1;
877 877
878 for (0 .. $#$children) { 878 for (0 .. $#$children) {
975sub _draw { 975sub _draw {
976 my ($self) = @_; 976 my ($self) = @_;
977 977
978 my $tex = $self->{texture} ||= do { 978 my $tex = $self->{texture} ||= do {
979 $self->{layout}->set_width ($self->{w}); 979 $self->{layout}->set_width ($self->{w});
980 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{height});
980 new_from_layout CFClient::Texture $self->{layout} 981 new_from_layout CFClient::Texture $self->{layout}
981 }; 982 };
982 983
983 glEnable GL_BLEND; 984 glEnable GL_BLEND;
984 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 985 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines