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