1#!/usr/local/bin/perl
2#
3#  PDL::Graphics::TriD::ButtonControl - This package simply defines
4#  default event handler subroutines.      $Revision$
5#
6#  James P. Edwards
7#  Instituto Nacional de Meteorologia
8#  Brasilia, DF, Brasil
9#  jedwards@inmet.gov.br
10#
11#  This distribution is free software; you can
12#  redistribute it and/or modify it under the same terms as Perl itself.
13#
14
15=head1 NAME
16
17PDL::Graphics::TriD::ButtonControl - default event handler subroutines
18
19=head1 FUNCTIONS
20
21=head2 new()
22
23=for ref
24
25Bless an oject into the class ButtonControl, expects the associated
26Window object to be supplied as an argument.
27
28=for usage
29
30The ButtonControl class is a base class which all TriD event
31controllers should inherit from.  By itself it does not do much.  It
32defines ButtonPressed and ButtonRelease functions which are expected by
33the Event loop.
34
35
36
37=cut
38
39package PDL::Graphics::TriD::ButtonControl;
40use strict;
41use fields qw/Win W H SC/;
42
43sub new {
44  my ($class,$win) = @_;
45
46  my $self = fields::new($class);
47  $self->{Win} = $win;
48
49  $self;
50}
51
52
53=head2 mouse_moved
54
55=for ref
56  A do nothing function to prevent errors if not defined in a subclass
57
58=cut
59
60sub mouse_moved{
61  print "mouse_moved @_\n" if $PDL::Graphics::TriD::verbose;
62}
63
64=head2 ButtonRelease
65
66=for ref
67  A do nothing function to prevent errors if not defined in a subclass
68
69=cut
70
71sub ButtonRelease{
72  my ($this,$x,$y) = @_;
73  $this->{Win}{Active} = 0;
74  print "ButtonRelease @_\n"  if $PDL::Graphics::TriD::verbose;
75}
76
77=head2 ButtonPressed
78
79=for ref
80
81  Activates the viewport the mouse is inside when pressed
82
83=cut
84
85sub ButtonPress{
86  my ($this,$x,$y) = @_;
87
88
89#
90# GL (0,0) point is Lower left X and Tk is upper left.
91#
92  $y = $PDL::Graphics::TriD::cur->{Height}-$y;
93
94#  print "$x $y ",$this->{Win}{X0}," ",$this->{Win}{Y0}," ",$this->{Win}{W}," ",$this->{Win}{H},"\n";
95
96  if($this->{Win}{X0} <= $x && $this->{Win}{X0}+$this->{Win}{W}>=$x
97	  && $this->{Win}{Y0} <= $y && $this->{Win}{Y0}+$this->{Win}{H}>=$y ){
98	 $this->{Win}{Active} = 1;
99  }
100  print "ButtonPress @_ ",ref($this->{Win}),"\n" if $PDL::Graphics::TriD::verbose;
101}
102
103=head2 set_wh
104
105=for ref
106
107  Define the width and Height of the window for button control
108
109=cut
110
111sub set_wh {
112  my($this,$w,$h) = @_;
113  print ref($this)," $w,$h\n" if $PDL::Graphics::TriD::verbose;
114  $this->{W} = $w;
115  $this->{H} = $h;
116  $w = 0 unless defined $w;
117  $h = 0 unless defined $h;
118  if($w > $h) {
119	 $this->{SC} = $h/2;
120  } else {
121	 $this->{SC} = $w/2;
122  }
123}
124
125
1261;
127