1######################################################################
2######################################################################
3## ScaleController -- this is the module that controls 3-D window scaling
4## when you drag the mouse in the display window.
5
6
7
8package PDL::Graphics::TriD::ScaleController;
9use base qw/PDL::Graphics::TriD::ButtonControl/;
10use fields qw/Dist/;
11
12sub new {
13  my($type,$win,$dist) = @_;
14
15  my $this = $type->SUPER::new( $win);
16
17  $this->{Dist} = $dist;
18  $win->add_resizecommand(sub {print "Resized window: ",join(",",@_),"\n" if $PDL::debug_trid;  $this->set_wh(@_); });
19  return $this;
20}
21
22# coordinates normalised relative to center
23sub xy2norm {
24	my($this,$x,$y) = @_;
25	print "xy2norm: this->{W}=$this->{W}; this->{H}=$this->{H}; this->{SC}=$this->{SC}\n" if($PDL::Graphics::TriD::verbose);
26	$x -= $this->{W}/2; $y -= $this->{H}/2;
27	$x /= $this->{SC}; $y /= $this->{SC};
28	return ($x,$y);
29}
30
31sub mouse_moved {
32	my($this,$x0,$y0,$x1,$y1) = @_;
33#	$this->{Dist} *=
34	${$this->{Dist}} *=
35	  $this->xy2fac($this->xy2norm($x0,$y0),$this->xy2norm($x1,$y1));
36}
37
38##############################################################
39#
40# a very simple unsophisticated scaler that
41# takes advantage of the nice infrastructure provided by
42# TJL
43#
44##############################################################
45package PDL::Graphics::TriD::SimpleScaler;
46
47use base qw/PDL::Graphics::TriD::ScaleController/;
48
49# x,y to distance from center
50sub xy2fac {
51	my($this,$x0,$y0,$x1,$y1) = @_;
52	my $dy = $y0-$y1;
53	return $dy>0 ? 1+2*$dy : 1/(1-2*$dy);
54}
55
56
57
58
591;
60