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.373 by root, Sun Jul 15 22:39:30 2007 UTC vs.
Revision 1.374 by root, Mon Jul 16 12:36:48 2007 UTC

1078 scroll_x => $self->{scroll_x}, 1078 scroll_x => $self->{scroll_x},
1079 scroll_y => $self->{scroll_y}, 1079 scroll_y => $self->{scroll_y},
1080 ; 1080 ;
1081 1081
1082 $self->SUPER::add (0, 0, $self->{vp}); 1082 $self->SUPER::add (0, 0, $self->{vp});
1083 $self->SUPER::add (1, 0, $self->{vslider}) if $self->{scroll_y};
1084 $self->SUPER::add (0, 1, $self->{hslider}) if $self->{scroll_x};
1085 1083
1086 $self->add ($child) if $child; 1084 $self->add ($child) if $child;
1087 1085
1088 $self 1086 $self
1089} 1087}
1097} 1095}
1098 1096
1099sub invoke_mouse_wheel { 1097sub invoke_mouse_wheel {
1100 my ($self, $ev) = @_; 1098 my ($self, $ev) = @_;
1101 1099
1102 return 0 unless $ev->{dy}; # only vertical movements 1100 return 0 unless $ev->{dy}; # only vertical movements for now
1103 1101
1104 $self->{vslider}->emit (mouse_wheel => $ev); 1102 $self->{vslider}->emit (mouse_wheel => $ev);
1105 1103
1106 1 1104 1
1107} 1105}
1111 1109
1112 my $child = ($self->{vp} or return)->child; 1110 my $child = ($self->{vp} or return)->child;
1113 1111
1114 my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); 1112 my ($w1, $w2) = ($child->{w}, $self->{vp}{w});
1115 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); 1113 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]);
1116 #$self->{hslider}->set_visibility ($w1 != $w2); 1114
1115 my $visible = $w1 > $w2;
1116 if ($visible != $self->{hslider}{visible}) {
1117 $visible ? $self->SUPER::add (0, 1, $self->{hslider})
1118 : $self->{hslider}->hide;
1119 }
1117 1120
1118 my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); 1121 my ($h1, $h2) = ($child->{h}, $self->{vp}{h});
1119 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); 1122 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]);
1120 #$self->{vslider}->set_visibility ($h1 != $h2); 1123
1124 my $visible = $h1 > $h2;
1125 if ($visible != $self->{vslider}{visible}) {
1126 $visible ? $self->SUPER::add (1, 0, $self->{vslider})
1127 : $self->{vslider}->hide;
1128 }
1121} 1129}
1122 1130
1123sub update { 1131sub update {
1124 my ($self) = @_; 1132 my ($self) = @_;
1125 1133
1509 1517
1510sub new { 1518sub new {
1511 my $class = shift; 1519 my $class = shift;
1512 1520
1513 $class->SUPER::new ( 1521 $class->SUPER::new (
1522 children => [],
1514 col_expand => [], 1523 col_expand => [],
1515 row_expand => [], 1524 row_expand => [],
1516 @_, 1525 @_,
1517 ) 1526 )
1518} 1527}
1519 1528
1520sub children { 1529sub children {
1521 grep $_, map @$_, grep $_, @{ $_[0]{children} } 1530 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1522} 1531}
1523 1532
1533# TODO: store row/col info in child widget and use standard add/del
1524sub add { 1534sub add {
1525 my ($self) = shift; 1535 my ($self) = shift;
1526 1536
1527 while (@_) { 1537 while (@_) {
1528 my ($x, $y, $child) = splice @_, 0, 3, (); 1538 my ($x, $y, $child) = splice @_, 0, 3, ();
1529 $child->set_parent ($self); 1539 $child->set_parent ($self);
1530 $self->{children}[$y][$x] = $child; 1540 $self->{children}[$y][$x] = $child;
1531 } 1541 }
1532 1542
1533 $self->{force_realloc} = 1; 1543 $self->{force_realloc} = 1;
1534 $self->{force_size_alloc} = 1; 1544 $self->{force_size_alloc} = 1;
1535 $self->realloc; 1545 $self->realloc;
1536} 1546}
1537 1547
1538sub remove { 1548sub remove {
1539 my ($self, $child) = @_; 1549 my ($self, $child) = @_;
1540 1550
1541 # TODO: not yet implemented 1551 for (@{ $self->{children} }) {
1552 for (@{ $_ || [] }) {
1553 $_ = undef if $_ == $child;
1554 }
1555 }
1542} 1556}
1543 1557
1544# TODO: move to container class maybe? send children a signal on removal? 1558# TODO: move to container class maybe? send children a signal on removal?
1545sub clear { 1559sub clear {
1546 my ($self) = @_; 1560 my ($self) = @_;
1659 my ($self) = @_; 1673 my ($self) = @_;
1660 1674
1661 for (grep $_, @{$self->{children}}) { 1675 for (grep $_, @{$self->{children}}) {
1662 $_->draw for grep $_, @$_; 1676 $_->draw for grep $_, @$_;
1663 } 1677 }
1678}
1679
1680#############################################################################
1681
1682package CFPlus::UI::Fixed;
1683
1684use List::Util qw(min max);
1685
1686our @ISA = CFPlus::UI::Container::;
1687
1688sub add {
1689 my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_;
1690
1691 $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h];
1692 $self->SUPER::add ($child);
1693}
1694
1695sub _scale($$$) {
1696 my ($mode, $val, $max) = @_;
1697
1698 $mode eq "abs" ? $val
1699 : $mode eq "rel" ? $val * $max
1700 : 0
1701}
1702
1703sub size_request {
1704 my ($self) = @_;
1705
1706 my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0);
1707
1708 # determine overall size by querying abs widgets
1709 for my $child ($self->visible_children) {
1710 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} };
1711
1712 if ($pos eq "abs") {
1713 $w = _scale $size, $w, $child->{req_w};
1714 $h = _scale $size, $h, $child->{req_h};
1715
1716 $x1 = min $x1, $x; $x2 = max $x2, $x + $w;
1717 $y1 = min $y1, $y; $y2 = max $y2, $y + $h;
1718 }
1719 }
1720
1721 my $W = $x2 - $x1;
1722 my $H = $y2 - $y1;
1723
1724 # now layout remaining widgets
1725 for my $child ($self->visible_children) {
1726 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} };
1727
1728 if ($pos ne "abs") {
1729 $x = _scale $pos, $x, $W;
1730 $y = _scale $pos, $x, $H;
1731 $w = _scale $size, $w, $child->{req_w};
1732 $h = _scale $size, $h, $child->{req_h};
1733
1734 $x1 = min $x1, $x; $x2 = max $x2, $x + $w;
1735 $y1 = min $y1, $y; $y2 = max $y2, $y + $h;
1736 }
1737 }
1738
1739 my $W = $x2 - $x1;
1740 my $H = $y2 - $y1;
1741
1742 ($W, $H)
1743}
1744
1745sub invoke_size_allocate {
1746 my ($self, $W, $H) = @_;
1747
1748 for my $child ($self->visible_children) {
1749 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} };
1750
1751 $x = _scale $pos, $x, $W;
1752 $y = _scale $pos, $x, $H;
1753 $w = _scale $size, $w, $child->{req_w};
1754 $h = _scale $size, $h, $child->{req_h};
1755
1756 $child->configure ($x, $y, $w, $h);
1757 }
1758
1759 1
1664} 1760}
1665 1761
1666############################################################################# 1762#############################################################################
1667 1763
1668package CFPlus::UI::Box; 1764package CFPlus::UI::Box;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines