Skip to content

Commit 8b15f34

Browse files
committed
move EventHandler into Window.pm
1 parent 8200388 commit 8b15f34

2 files changed

Lines changed: 59 additions & 59 deletions

File tree

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ sub close {
859859
}
860860

861861
sub display {
862-
my($this) = @_;
862+
my ($this) = @_;
863863
return unless defined($this);
864864
$this->{_GLObject}->set_window; # for multiwindow support
865865
print "display: calling glClear()\n" if $PDL::Graphics::TriD::verbose;
@@ -891,64 +891,13 @@ sub display {
891891

892892
# should this really be in viewport?
893893
sub read_picture {
894-
my($this) = @_;
895-
my($w,$h) = @{$this}{qw/Width Height/};
896-
my $res = PDL->zeroes(PDL::byte,3,$w,$h);
897-
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
898-
glPixelStorei(GL_PACK_ALIGNMENT,1);
899-
glReadPixels_c(0,0,$w,$h,GL_RGB,GL_UNSIGNED_BYTE,$res->make_physical->address_data);
900-
return $res;
901-
}
902-
}
903-
904-
{
905-
package # hide from PAUSE
906-
PDL::Graphics::TriD::EventHandler;
907-
use fields qw/X Y Buttons VP/;
908-
sub new {
909-
my $class = shift;
910-
my $vp = shift;
911-
my $self = fields::new($class);
912-
$self->{X} = -1;
913-
$self->{Y} = -1;
914-
$self->{Buttons} = [];
915-
$self->{VP} = $vp;
916-
$self;
917-
}
918-
sub event {
919-
my($this,$type,@args) = @_;
920-
print "EH: ",ref($this)," $type (",join(",",@args),")\n" if $PDL::Graphics::TriD::verbose;
921-
return if !defined $type;
922-
my $retval;
923-
if ($type eq 'motion') {
924-
return if (my $but = $args[0]) < 0;
925-
print "MOTION $args[0]\n" if $PDL::Graphics::TriD::verbose;
926-
if ($this->{Buttons}[$but] and $this->{VP}{Active}) {
927-
print "calling ".($this->{Buttons}[$but])."->mouse_moved ($this->{X},$this->{Y},$args[1],$args[2])...\n" if $PDL::Graphics::TriD::verbose;
928-
$retval = $this->{Buttons}[$but]->mouse_moved(@$this{qw(X Y)}, @args[1,2]);
929-
}
930-
@$this{qw(X Y)} = @args[1,2];
931-
} elsif ($type eq 'buttonpress') {
932-
my $but = $args[0]-1;
933-
print "BUTTONPRESS $but\n" if $PDL::Graphics::TriD::verbose;
934-
@$this{qw(X Y)} = @args[1,2];
935-
$retval = $this->{Buttons}[$but]->ButtonPress(@args[1,2])
936-
if $this->{Buttons}[$but];
937-
} elsif ($type eq 'buttonrelease') {
938-
my $but = $args[0]-1;
939-
print "BUTTONRELEASE $but\n" if $PDL::Graphics::TriD::verbose;
940-
$retval = $this->{Buttons}[$but]->ButtonRelease($args[1],$args[2])
941-
if $this->{Buttons}[$but];
942-
} elsif ($type eq 'reshape') {
943-
# Kludge to force reshape of the viewport associated with the window -CD
944-
print "ConfigureNotify (".join(",",@args).")\n" if $PDL::Graphics::TriD::verbose;
945-
print "viewport is $this->{VP}\n" if $PDL::Graphics::TriD::verbose;
946-
}
947-
$retval;
948-
}
949-
sub set_button {
950-
my($this,$butno,$act) = @_;
951-
$this->{Buttons}[$butno] = $act;
894+
my ($this) = @_;
895+
my ($w,$h) = @{$this}{qw/Width Height/};
896+
my $res = PDL->zeroes(PDL::byte,3,$w,$h);
897+
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
898+
glPixelStorei(GL_PACK_ALIGNMENT,1);
899+
glReadPixels_c(0,0,$w,$h,GL_RGB,GL_UNSIGNED_BYTE,$res->make_physical->address_data);
900+
return $res;
952901
}
953902
}
954903

lib/PDL/Graphics/TriD/Window.pm

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,55 @@ sub set_material {
180180
$_->set_material(@args) for grep defined, @{$self->{_ViewPorts}};
181181
}
182182

183+
{
184+
package # hide from PAUSE
185+
PDL::Graphics::TriD::EventHandler;
186+
use fields qw/X Y Buttons VP/;
187+
sub new {
188+
my $class = shift;
189+
my $vp = shift;
190+
my $self = fields::new($class);
191+
$self->{X} = -1;
192+
$self->{Y} = -1;
193+
$self->{Buttons} = [];
194+
$self->{VP} = $vp;
195+
$self;
196+
}
197+
sub event {
198+
my ($this,$type,@args) = @_;
199+
print "EH: ",ref($this)," $type (",join(",",@args),")\n" if $PDL::Graphics::TriD::verbose;
200+
return if !defined $type;
201+
my $retval;
202+
if ($type eq 'motion') {
203+
return if (my $but = $args[0]) < 0;
204+
print "MOTION $args[0]\n" if $PDL::Graphics::TriD::verbose;
205+
if ($this->{Buttons}[$but] and $this->{VP}{Active}) {
206+
print "calling ".($this->{Buttons}[$but])."->mouse_moved ($this->{X},$this->{Y},$args[1],$args[2])...\n" if $PDL::Graphics::TriD::verbose;
207+
$retval = $this->{Buttons}[$but]->mouse_moved(@$this{qw(X Y)}, @args[1,2]);
208+
}
209+
@$this{qw(X Y)} = @args[1,2];
210+
} elsif ($type eq 'buttonpress') {
211+
my $but = $args[0]-1;
212+
print "BUTTONPRESS $but\n" if $PDL::Graphics::TriD::verbose;
213+
@$this{qw(X Y)} = @args[1,2];
214+
$retval = $this->{Buttons}[$but]->ButtonPress(@args[1,2])
215+
if $this->{Buttons}[$but];
216+
} elsif ($type eq 'buttonrelease') {
217+
my $but = $args[0]-1;
218+
print "BUTTONRELEASE $but\n" if $PDL::Graphics::TriD::verbose;
219+
$retval = $this->{Buttons}[$but]->ButtonRelease($args[1],$args[2])
220+
if $this->{Buttons}[$but];
221+
} elsif ($type eq 'reshape') {
222+
# Kludge to force reshape of the viewport associated with the window -CD
223+
print "ConfigureNotify (".join(",",@args).")\n" if $PDL::Graphics::TriD::verbose;
224+
print "viewport is $this->{VP}\n" if $PDL::Graphics::TriD::verbose;
225+
}
226+
$retval;
227+
}
228+
sub set_button {
229+
my($this,$butno,$act) = @_;
230+
$this->{Buttons}[$butno] = $act;
231+
}
232+
}
233+
183234
1;

0 commit comments

Comments
 (0)