File: SimpleScaler.pm

package info (click to toggle)
libpdl-graphics-trid-perl 2.102-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 476 kB
  • sloc: perl: 5,082; ansic: 683; makefile: 8
file content (46 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# a very simple unsophisticated scaler that
# takes advantage of the nice infrastructure provided by TJL
# controls 3-D window scaling
# when you drag the mouse in the display window.
package PDL::Graphics::TriD::SimpleScaler;

use strict;
use warnings;
use base qw/PDL::Graphics::TriD::ButtonControl/;
use fields qw/DistRef/;

$PDL::Graphics::TriD::verbose //= 0;

sub new {
  my($type,$win,$dist) = @_;

  my $this = $type->SUPER::new( $win);

  $this->{DistRef} = $dist;
  $win->add_resizecommand(sub {print "Resized window: ",join(",",@_),"\n" if $PDL::Graphics::TriD::verbose;  $this->set_wh(@_); });
  return $this;
}

# coordinates normalised relative to center
sub xy2norm {
	my($this,$x,$y) = @_;
	print "xy2norm: this->{W}=$this->{W}; this->{H}=$this->{H}; this->{SC}=$this->{SC}\n" if($PDL::Graphics::TriD::verbose);
	$x -= $this->{W}/2; $y -= $this->{H}/2;
	$x /= $this->{SC}; $y /= $this->{SC};
	return ($x,$y);
}

sub mouse_moved {
	my($this,$x0,$y0,$x1,$y1) = @_;
	${$this->{DistRef}} *=
	  $this->xy2fac($this->xy2norm($x0,$y0),$this->xy2norm($x1,$y1));
}

# x,y to distance from center
sub xy2fac {
	my($this,$x0,$y0,$x1,$y1) = @_;
	my $dy = $y0-$y1;
	return $dy>0 ? 1+2*$dy : 1/(1-2*$dy);
}

1;