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.76 by root, Tue Apr 11 21:24:09 2006 UTC vs.
Revision 1.77 by root, Tue Apr 11 22:14:13 2006 UTC

43 43
44 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 44 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
45 45
46 $BUTTON_STATE &= ~(1 << ($ev->button - 1)); 46 $BUTTON_STATE &= ~(1 << ($ev->button - 1));
47 47
48 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; 48 $GRAB->button_up ($ev, $GRAB->translate ($x, $y)) if $GRAB;
49 49
50 if (!$BUTTON_STATE) { 50 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 51 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 52 $grab->update if $grab;
53 $GRAB->update if $GRAB; 53 $GRAB->update if $GRAB;
330 330
331 $self 331 $self
332} 332}
333 333
334sub add { 334sub add {
335 my ($self, $chld, $expand) = @_; 335 my ($self, $chld) = @_;
336 336
337 $chld->{expand} = $expand;
338 $chld->set_parent ($self); 337 $chld->set_parent ($self);
339 338
340 $self->{children} = [ 339 $self->{children} = [
341 sort { $a->{z} <=> $b->{z} } 340 sort { $a->{z} <=> $b->{z} }
342 @{$self->{children}}, $chld 341 @{$self->{children}}, $chld
538 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 537 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
539 538
540sub size_request { 539sub size_request {
541 my ($self) = @_; 540 my ($self) = @_;
542 541
542 my ($w, $h) =
543 $self->{user_w} && $self->{user_h}
544 ? ($self->{user_w}, $self->{user_h})
543 my ($w, $h) = $self->SUPER::size_request; 545 : ($self->SUPER::size_request);
544 546
545 $h += $tex[1]->{h}; 547 $h += $tex[1]->{h};
546 $h += $tex[4]->{h}; 548 $h += $tex[4]->{h};
547 $w += $tex[2]->{w}; 549 $w += $tex[2]->{w};
548 $w += $tex[3]->{w}; 550 $w += $tex[3]->{w};
553sub size_allocate { 555sub size_allocate {
554 my ($self, $x, $y, $w, $h) = @_; 556 my ($self, $x, $y, $w, $h) = @_;
555 557
556 $self->_size_allocate ($x, $y, $w, $h) or return; 558 $self->_size_allocate ($x, $y, $w, $h) or return;
557 559
558 $h -= $tex[1]->{h}; 560 $h -= $tex[1]{h};
559 $h -= $tex[4]->{h}; 561 $h -= $tex[4]{h};
560 $w -= $tex[2]->{w}; 562 $w -= $tex[2]{w};
561 $w -= $tex[3]->{w}; 563 $w -= $tex[3]{w};
562 564
563 $h = $h < 0 ? 0 : $h; 565 $h = $h < 0 ? 0 : $h;
564 $w = $w < 0 ? 0 : $w; 566 $w = $w < 0 ? 0 : $w;
565 567
566 my $child = $self->child; 568 my $child = $self->child;
567 569
568 $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h); 570 $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h);
571}
572
573sub button_down {
574 my ($self, $ev, $x, $y) = @_;
575
576 if ($x < $self->{w} && $x >= $self->{w} - $tex[2]{w}
577 && $y < $self->{h} && $y >= $self->{h} - $tex[4]{h}) {
578
579 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
580 my ($bw, $bh) = ($self->{w}, $self->{h});
581
582 $self->{motion} = sub {
583 my ($ev, $x, $y) = @_;
584
585 ($x, $y) = ($ev->motion_x, $ev->motion_y);
586
587 $self->{user_w} = $bw + $x - $ox;
588 $self->{user_h} = $bh + $y - $oy;
589 $self->update;
590 };
591
592 } elsif ($x >= 0 && $x < $self->{w}
593 && $y >= 0 && $y < $tex[1]{h}) {
594
595 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
596 my ($bx, $by) = ($self->{x}, $self->{y});
597
598 $self->{motion} = sub {
599 my ($ev, $x, $y) = @_;
600
601 ($x, $y) = ($ev->motion_x, $ev->motion_y);
602
603 $self->move ($bx + $x - $ox, $by + $y - $oy);
604 $self->update;
605 };
606 }
607}
608
609sub button_up {
610 my ($self, $ev, $x, $y) = @_;
611
612 delete $self->{motion};
613}
614
615sub mouse_motion {
616 my ($self, $ev, $x, $y) = @_;
617
618 $self->{motion}->($ev, $x, $y) if $self->{motion};
569} 619}
570 620
571sub _draw { 621sub _draw {
572 my ($self) = @_; 622 my ($self) = @_;
573 623
672 722
673 my $req_w = List::Util::sum @$ws; 723 my $req_w = List::Util::sum @$ws;
674 my $req_h = List::Util::sum @$hs; 724 my $req_h = List::Util::sum @$hs;
675 725
676 # linearly scale sizes 726 # linearly scale sizes
677 $_ *= $req_w / $w for @$ws; 727 $_ *= $w / $req_w for @$ws;
678 $_ *= $req_h / $h for @$hs; 728 $_ *= $h / $req_h for @$hs;
679 729
680 my $y; 730 my $y;
681 731
682 for my $r (0 .. $#{$self->{children}}) { 732 for my $r (0 .. $#{$self->{children}}) {
683 my $row = $self->{children}[$r] 733 my $row = $self->{children}[$r]
762 812
763 if ($req_h > $h) { 813 if ($req_h > $h) {
764 # ah well, not enough space 814 # ah well, not enough space
765 $_ = $h[$_] * $h / $req_h for @h; 815 $_ = $h[$_] * $h / $req_h for @h;
766 } else { 816 } else {
767 my @exp = grep $_->{expand}, @$children; 817 my $exp = List::Util::sum map $_->{expand}, @$children;
768 @exp = @$children unless @exp; 818 $exp ||= 1;
769 819
770 my %exp = map +($_ => 1), @exp;
771
772 for (0 .. $#$children) { 820 for (0 .. $#$children) {
773 my $child = $children->[$_]; 821 my $child = $children->[$_];
774 822
775 my $alloc_h = $h[$_]; 823 my $alloc_h = $h[$_];
776 $alloc_h += ($h - $req_h) / @exp if $exp{$child}; 824 $alloc_h += ($h - $req_h) * $child->{expand} / $exp;
777 $h[$_] = $alloc_h; 825 $h[$_] = $alloc_h;
778 } 826 }
779 } 827 }
780 828
781 my $y = 0; 829 my $y = 0;
822 870
823 if ($req_h > $h) { 871 if ($req_h > $h) {
824 # ah well, not enough space 872 # ah well, not enough space
825 $_ = $h[$_] * $h / $req_h for @h; 873 $_ = $h[$_] * $h / $req_h for @h;
826 } else { 874 } else {
827 my @exp = grep $_->{expand}, @$children; 875 my $exp = List::Util::sum map $_->{expand}, @$children;
828 @exp = @$children unless @exp; 876 $exp ||= 1;
829 877
830 my %exp = map +($_ => 1), @exp;
831
832 for (0 .. $#$children) { 878 for (0 .. $#$children) {
833 my $child = $children->[$_]; 879 my $child = $children->[$_];
834 880
835 my $alloc_h = $h[$_]; 881 $h[$_] += ($h - $req_h) * $child->{expand} / $exp;
836 $alloc_h += ($h - $req_h) / @exp if $exp{$child};
837 $h[$_] = $alloc_h;
838 } 882 }
839 } 883 }
840 884
841 my $y = 0; 885 my $y = 0;
842 for (0 .. $#$children) { 886 for (0 .. $#$children) {
946 my $x = 990 my $x =
947 $self->{align} < 0 ? $self->{padding} 991 $self->{align} < 0 ? $self->{padding}
948 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 992 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
949 : ($self->{w} - $tex->{w}) * 0.5; 993 : ($self->{w} - $tex->{w}) * 0.5;
950 994
951 $tex->draw_quad ($x, 0); 995 $tex->draw_quad ($x, $self->{padding});
952 996
953 glDisable GL_TEXTURE_2D; 997 glDisable GL_TEXTURE_2D;
954 glDisable GL_BLEND; 998 glDisable GL_BLEND;
955} 999}
956 1000
1257sub key_up { 1301sub key_up {
1258} 1302}
1259 1303
1260sub size_request { 1304sub size_request {
1261 ( 1305 (
1262 1 + int $::WIDTH / 32, 1306 1 + 32 * int $::WIDTH / 32,
1263 1 + int $::HEIGHT / 32, 1307 1 + 32 * int $::HEIGHT / 32,
1264 ) 1308 )
1265} 1309}
1266 1310
1267sub update { 1311sub update {
1268 my ($self) = @_; 1312 my ($self) = @_;
1269 1313
1270 $self->{need_update} = 1; 1314 $self->{need_update} = 1;
1271 $self->SUPER::update; 1315 $self->SUPER::update;
1272} 1316}
1273 1317
1274sub _draw { 1318sub draw {
1275 my ($self) = @_; 1319 my ($self) = @_;
1276 1320
1277 if (delete $self->{need_update}) { 1321 if (delete $self->{need_update}) {
1278 glNewList $self->{list}, GL_COMPILE; 1322 glNewList $self->{list}, GL_COMPILE;
1279 1323

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines