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.383 by root, Fri Jul 20 16:32:04 2007 UTC vs.
Revision 1.389 by root, Sat Jul 21 13:02:05 2007 UTC

113 } 113 }
114 114
115 if ($GRAB) { 115 if ($GRAB) {
116 if ($ev->{button} == 4 || $ev->{button} == 5) { 116 if ($ev->{button} == 4 || $ev->{button} == 5) {
117 # mousewheel 117 # mousewheel
118 $ev->{dx} = 0;
119 $ev->{dy} = $ev->{button} * 2 - 9; 118 my $delta = $ev->{button} * 2 - 9;
119 my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT;
120
121 $ev->{dx} = $shift ? $delta : 0;
122 $ev->{dy} = $shift ? 0 : $delta;
123
120 $GRAB->emit (mouse_wheel => $ev); 124 $GRAB->emit (mouse_wheel => $ev);
121 } else { 125 } else {
122 $GRAB->emit (button_down => $ev) 126 $GRAB->emit (button_down => $ev)
123 } 127 }
124 } 128 }
547 551
548 # parent 552 # parent
549 $self->{parent} && $self->{parent}->emit ($signal, @args) 553 $self->{parent} && $self->{parent}->emit ($signal, @args)
550} 554}
551 555
552sub find_widget { 556#sub find_widget {
553 my ($self, $x, $y) = @_; 557# in .xs
554
555 return () unless $self->{can_events};
556
557 return $self
558 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
559 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
560
561 ()
562}
563 558
564sub set_parent { 559sub set_parent {
565 my ($self, $parent) = @_; 560 my ($self, $parent) = @_;
566 561
567 CFPlus::weaken ($self->{parent} = $parent); 562 CFPlus::weaken ($self->{parent} = $parent);
963sub size_request { 958sub size_request {
964 my ($self) = @_; 959 my ($self) = @_;
965 960
966 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 961 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
967 962
968 $w = 10 if $self->{scroll_x}; 963 $w = 1 if $self->{scroll_x};
969 $h = 10 if $self->{scroll_y}; 964 $h = 1 if $self->{scroll_y};
970 965
971 ($w, $h) 966 ($w, $h)
972} 967}
973 968
974sub invoke_size_allocate { 969sub invoke_size_allocate {
1020 my ($self, $x, $y) = @_; 1015 my ($self, $x, $y) = @_;
1021 1016
1022 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} 1017 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
1023 && $y >= $self->{y} && $y < $self->{y} + $self->{h} 1018 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
1024 ) { 1019 ) {
1025 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) 1020 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
1026 } else { 1021 } else {
1027 $self->CFPlus::UI::Base::find_widget ($x, $y) 1022 $self->CFPlus::UI::Base::find_widget ($x, $y)
1028 } 1023 }
1029} 1024}
1030 1025
1135} 1130}
1136 1131
1137sub update { 1132sub update {
1138 my ($self) = @_; 1133 my ($self) = @_;
1139 1134
1135 $self->update_slider;
1140 $self->SUPER::update; 1136 $self->SUPER::update;
1141 $self->update_slider;
1142} 1137}
1143 1138
1144sub invoke_mouse_wheel { 1139sub invoke_mouse_wheel {
1145 my ($self, $ev) = @_; 1140 my ($self, $ev) = @_;
1146 1141
1147 return 0 unless $ev->{dy}; # only vertical movements for now
1148
1149 $self->{vslider}->emit (mouse_wheel => $ev); 1142 $self->{vslider}->emit (mouse_wheel => $ev)
1143 if $ev->{dy};
1144
1145 $self->{hslider}->emit (mouse_wheel => $ev)
1146 if $ev->{dx};
1150 1147
1151 1 1148 1
1152} 1149}
1153 1150
1154sub invoke_button_down { 1151sub invoke_button_down {
1619 my $self = shift; 1616 my $self = shift;
1620 1617
1621 while (@_) { 1618 while (@_) {
1622 my ($col, $row, $child) = splice @_, 0, 3, (); 1619 my ($col, $row, $child) = splice @_, 0, 3, ();
1623 1620
1621 $child->{row} = $row;
1622 $child->{col} = $col;
1623
1624 $child->{rowspan} ||= 1;
1625 $child->{colspan} ||= 1;
1626
1624 $child->set_parent ($self); 1627 $child->set_parent ($self);
1625 $self->{children}[$row][$col] = $child; 1628 $self->{children}[$row][$col] = $child;
1626 } 1629 }
1627 1630
1628 $self->{force_realloc} = 1; 1631 $self->{force_realloc} = 1;
1658sub get_wh { 1661sub get_wh {
1659 my ($self) = @_; 1662 my ($self) = @_;
1660 1663
1661 my (@w, @h); 1664 my (@w, @h);
1662 1665
1663 for my $y (0 .. $#{$self->{children}}) { 1666 my @children = $self->children;
1664 my $row = $self->{children}[$y]
1665 or next;
1666 1667
1667 for my $x (0 .. $#$row) { 1668 for my $widget (sort { $b->{rowspan} * $b->{colspan} <=> $a->{rowspan} * $a->{colspan} } @children) {
1668 my $widget = $row->[$x] 1669 my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)};
1669 or next;
1670 my ($w, $h) = @$widget{qw(req_w req_h)};
1671 1670
1672 $w[$x] = max $w[$x], $w; 1671 my $sw = sum @w[$c .. $c + $cs - 1];
1673 $h[$y] = max $h[$y], $h; 1672 my $sh = sum @h[$r .. $r + $rs - 1];
1673
1674 if ($w > $sw) {
1675 $_ += ($w - $sw) / $cs for @w[$c .. $c + $cs - 1];
1676 }
1677
1678 if ($h > $sh) {
1679 $_ += ($h - $sh) / $rs for @h[$r .. $r + $rs - 1];
1674 } 1680 }
1675 } 1681 }
1676 1682
1677 (\@w, \@h) 1683 (\@w, \@h)
1678} 1684}
1694 my ($ws, $hs) = $self->get_wh; 1700 my ($ws, $hs) = $self->get_wh;
1695 1701
1696 my $req_w = (sum @$ws) || 1; 1702 my $req_w = (sum @$ws) || 1;
1697 my $req_h = (sum @$hs) || 1; 1703 my $req_h = (sum @$hs) || 1;
1698 1704
1699 # TODO: nicer code 1705 # now linearly scale the rows/columns to the allocated size
1700 my @col_expand = @{$self->{col_expand}}; 1706 my @col_expand = @{$self->{col_expand}};
1701 @col_expand = (1) x @$ws unless @col_expand; 1707 @col_expand = (1) x @$ws unless @col_expand;
1702 my $col_expand = (sum @col_expand) || 1; 1708 my $col_expand = (sum @col_expand) || 1;
1703 1709
1704 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 1710 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
1711 1717
1712 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; 1718 $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs;
1713 1719
1714 CFPlus::UI::harmonize $hs; 1720 CFPlus::UI::harmonize $hs;
1715 1721
1716 my $y; 1722 my (@x, @y);
1717 1723
1724 for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] }
1725 for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] }
1726
1718 for my $r (0 .. $#{$self->{children}}) { 1727 for my $widget ($self->children) {
1719 my $row = $self->{children}[$r] 1728 my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)};
1720 or next;
1721 1729
1722 my $x = 0; 1730 $widget->configure (
1723 my $row_h = $hs->[$r]; 1731 $x[$c], $y[$r],
1732 $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r],
1724 1733 );
1725 for my $c (0 .. $#$row) {
1726 my $col_w = $ws->[$c];
1727
1728 if (my $widget = $row->[$c]) {
1729 $widget->configure ($x, $y, $col_w, $row_h);
1730 }
1731
1732 $x += $col_w;
1733 }
1734
1735 $y += $row_h;
1736 } 1734 }
1737 1735
1738 1 1736 1
1739} 1737}
1740 1738

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines