Window.pm (PDL-2.076) | : | Window.pm (PDL-2.077) | ||
---|---|---|---|---|
# | ||||
# The PDL::Graphics::TriD::Window is already partially defined in | # The PDL::Graphics::TriD::Window is already partially defined in | |||
# the appropriate gdriver (GL or VRML) items defined here are common | # the appropriate gdriver (GL or VRML) items defined here are common | |||
# to both | # to both | |||
# | ||||
package PDL::Graphics::TriD::Window; | package PDL::Graphics::TriD::Window; | |||
use strict; | use strict; | |||
use warnings; | use warnings; | |||
use PDL::Graphics::TriD::ViewPort; | use PDL::Graphics::TriD::ViewPort; | |||
use Data::Dumper; | use Data::Dumper; | |||
$PDL::Graphics::TriD::verbose //= 0; | $PDL::Graphics::TriD::verbose //= 0; | |||
sub new { | sub new { | |||
my($arg,$options) = @_; | my($arg,$options) = @_; | |||
print "PDL::Graphics::TriD::Window - calling SUPER::new...\n" if($PDL::Graphic | ||||
print "PDL::Graphics::TriD::Window - calling SUPER::new...\n" if($PDL::debug_t | s::TriD::verbose); | |||
rid); | ||||
my $this = $arg->SUPER::new(); | my $this = $arg->SUPER::new(); | |||
print "PDL::Graphics::TriD::Window - got back $this\n" if($PDL::Graphics::TriD | ||||
print "PDL::Graphics::TriD::Window - got back $this\n" if($PDL::debug_trid); | ::verbose); | |||
# Make sure the Graphics has been initialized | # Make sure the Graphics has been initialized | |||
$options->{width} = 300 unless defined $options->{width}; | $options->{width} = 600 unless defined $options->{width}; | |||
$options->{height} = 300 unless defined $options->{height}; | $options->{height} = 600 unless defined $options->{height}; | |||
$this->{Width} = $options->{width}; | $this->{Width} = $options->{width}; | |||
$this->{Height} = $options->{height}; | $this->{Height} = $options->{height}; | |||
print "PDL::Graphics::TriD::Window: calling gdriver....\n" if($PDL::Graphics:: | ||||
print "PDL::Graphics::TriD::Window: calling gdriver....\n" if($PDL::debug_trid | TriD::verbose); | |||
); | ||||
$this->{Interactive} = $this->gdriver($options); | $this->{Interactive} = $this->gdriver($options); | |||
print "PDL::Graphics::TriD::Window: gdriver gave back $this->{Interactive}.... | print "PDL::Graphics::TriD::Window: gdriver gave back $this->{Interactive}.... | |||
\n" if($PDL::debug_trid); | \n" if($PDL::Graphics::TriD::verbose); | |||
# set default values | # set default values | |||
if($this->{Interactive}){ | if($this->{Interactive}){ | |||
print "\tIt's interactive... calling ev_defaults...\n" if($PDL::debug_trid ); | print "\tIt's interactive... calling ev_defaults...\n" if($PDL::Graphics:: TriD::verbose); | |||
$this->{Ev} = $this->ev_defaults(); | $this->{Ev} = $this->ev_defaults(); | |||
print "\tcalling new_viewport...\n" if($PDL::debug_trid); | print "\tcalling new_viewport...\n" if($PDL::Graphics::TriD::verbose); | |||
$this->new_viewport(0,0,$this->{Width},$this->{Height}); | $this->new_viewport(0,0,$this->{Width},$this->{Height}); | |||
}else{ | }else{ | |||
$this->new_viewport(0,0,1,1); | $this->new_viewport(0,0,1,1); | |||
} | } | |||
$this->current_viewport(0); | $this->current_viewport(0); | |||
return($this); | return($this); | |||
} | } | |||
# | # | |||
# adds to all viewports | # adds to all viewports | |||
# | # | |||
sub add_object { | sub add_object { | |||
my($this,$object) = @_; | my($this,$object) = @_; | |||
# print "add_object ",ref($this),"\n"; | # print "add_object ",ref($this),"\n"; | |||
for(@{$this->{_ViewPorts}}) { | for(@{$this->{_ViewPorts}}) { | |||
$_->add_object($object); | $_->add_object($object); | |||
} | } | |||
} | } | |||
sub new_viewport { | sub new_viewport { | |||
my($this,$x0,$y0,$x1,$y1, $options) = @_; | my($this,$x0,$y0,$x1,$y1, $options) = @_; | |||
my $vp = PDL::Graphics::TriD::ViewPort->new($x0,$y0,$x1,$y1); | my $vp = PDL::Graphics::TriD::ViewPort->new($x0,$y0,$x1,$y1); | |||
# | ||||
print "Adding viewport $x0,$y0,$x1,$y1\n" if($PDL::Graphics::TriD::verbose); | print "Adding viewport $x0,$y0,$x1,$y1\n" if($PDL::Graphics::TriD::verbose); | |||
push @{$this->{_ViewPorts}}, $vp; | push @{$this->{_ViewPorts}}, $vp; | |||
# | ||||
if($this->{Interactive} ){ | if($this->{Interactive} ){ | |||
# set a default controller | # set a default controller | |||
use PDL::Graphics::TriD::ArcBall; | use PDL::Graphics::TriD::ArcBall; | |||
use PDL::Graphics::TriD::SimpleScaler; | use PDL::Graphics::TriD::SimpleScaler; | |||
use PDL::Graphics::TriD::Control3D; | use PDL::Graphics::TriD::Control3D; | |||
if (defined($PDL::Graphics::TriD::offline) and $PDL::Graphics::TriD::of fline==1 ) { | if (defined($PDL::Graphics::TriD::offline) and $PDL::Graphics::TriD::of fline==1 ) { | |||
eval "use PDL::Graphics::TriD::VRML"; | eval "use PDL::Graphics::TriD::VRML"; | |||
} else { | } else { | |||
eval "use PDL::Graphics::TriD::GL"; | eval "use PDL::Graphics::TriD::GL"; | |||
} | } | |||
my $ev = $options->{EHandler}; | my $ev = $options->{EHandler}; | |||
$ev = PDL::Graphics::TriD::EventHandler->new($vp) unless defined($ev); | $ev = PDL::Graphics::TriD::EventHandler->new($vp) unless defined($ev); | |||
my $cont = $options->{Transformer}; | my $cont = $options->{Transformer}; | |||
$cont = PDL::Graphics::TriD::SimpleController->new unless defined($cont) ; | $cont = PDL::Graphics::TriD::SimpleController->new unless defined($cont) ; | |||
$vp->transformer($cont); | $vp->transformer($cont); | |||
if(ref($ev)){ | if(ref($ev)){ | |||
$ev->set_button(0,PDL::Graphics::TriD::ArcCone->new( $vp, 0, $con t->{WRotation})); | $ev->set_button(0,PDL::Graphics::TriD::ArcCone->new( $vp, 0, $con t->{WRotation})); | |||
$ev->set_button(2,PDL::Graphics::TriD::SimpleScaler->new( $vp, \$ cont->{CDistance})); | $ev->set_button(2,PDL::Graphics::TriD::SimpleScaler->new( $vp, \$ cont->{CDistance})); | |||
$vp->eventhandler($ev); | $vp->eventhandler($ev); | |||
} | } | |||
} | } | |||
print "new_viewport: ",ref($vp)," ",$#{$this->{_ViewPorts}},"\n" if($PDL::Grap hics::TriD::verbose); | print "new_viewport: ",ref($vp)," ",$#{$this->{_ViewPorts}},"\n" if($PDL::Grap hics::TriD::verbose); | |||
return $vp; | return $vp; | |||
} | } | |||
sub resize_viewport { | sub resize_viewport { | |||
my($this,$x0,$y0,$x1,$y1,$vpnum) = @_; | my($this,$x0,$y0,$x1,$y1,$vpnum) = @_; | |||
$vpnum = $this->{_CurrentViewPort} unless(defined $vpnum); | $vpnum = $this->{_CurrentViewPort} unless(defined $vpnum); | |||
my $vp; | my $vp; | |||
if(defined($this->{_ViewPorts}[$vpnum])){ | if(defined($this->{_ViewPorts}[$vpnum])){ | |||
$vp = $this->{_ViewPorts}[$vpnum]->resize($x0,$y0,$x1,$y1); | $vp = $this->{_ViewPorts}[$vpnum]->resize($x0,$y0,$x1,$y1); | |||
} | } | |||
return $vp; | return $vp; | |||
} | } | |||
sub current_viewport { | sub current_viewport { | |||
my($this,$num) = @_; | my($this,$num) = @_; | |||
if(defined $num){ | if(defined $num){ | |||
if(ref($num)){ | if(ref($num)){ | |||
my $cnt=0; | my $cnt=0; | |||
foreach (@{$this->{_ViewPorts}}){ | foreach (@{$this->{_ViewPorts}}){ | |||
if($num == $_){ | if($num == $_){ | |||
$this->{_CurrentViewPort} = $cnt; | $this->{_CurrentViewPort} = $cnt; | |||
$_->{Active}=1; | $_->{Active}=1; | |||
}elsif(defined $_){ | }elsif(defined $_){ | |||
$_->{Active}=0; | $_->{Active}=0; | |||
} | } | |||
skipping to change at line 142 | skipping to change at line 123 | |||
return $this->{_ViewPorts}[$this->{_CurrentViewPort}]; | return $this->{_ViewPorts}[$this->{_CurrentViewPort}]; | |||
} | } | |||
sub viewports { | sub viewports { | |||
my ($this) = shift; | my ($this) = shift; | |||
return $this->{_ViewPorts}; | return $this->{_ViewPorts}; | |||
} | } | |||
sub _vp_num_fromref { | sub _vp_num_fromref { | |||
my ($this,$vp) = @_; | my ($this,$vp) = @_; | |||
if(! defined $vp){ | if(! defined $vp){ | |||
$vp = $this->{_CurrentViewPort}; | $vp = $this->{_CurrentViewPort}; | |||
}elsif(ref($vp)){ | }elsif(ref($vp)){ | |||
my $cnt=0; | my $cnt=0; | |||
foreach(@{$this->{_ViewPorts}}){ | foreach(@{$this->{_ViewPorts}}){ | |||
last if($vp == $_); | last if($vp == $_); | |||
$cnt++; | $cnt++; | |||
} | } | |||
$vp = $cnt; | $vp = $cnt; | |||
} | } | |||
skipping to change at line 164 | skipping to change at line 144 | |||
} | } | |||
sub delete_viewport { | sub delete_viewport { | |||
my($this, $vp) = @_; | my($this, $vp) = @_; | |||
my $cnt; | my $cnt; | |||
if(($cnt=$#{$this->{_ViewPorts}})<= 0){ | if(($cnt=$#{$this->{_ViewPorts}})<= 0){ | |||
print "WARNING: Cannot delete final viewport - request ignored\n"; | print "WARNING: Cannot delete final viewport - request ignored\n"; | |||
return; | return; | |||
} | } | |||
$vp = $this->_vp_num_fromref($vp); | $vp = $this->_vp_num_fromref($vp); | |||
$this->{_ViewPorts}[$vp]->DESTROY(); | $this->{_ViewPorts}[$vp]->DESTROY(); | |||
splice(@{$this->{_ViewPorts}},$vp,1); | splice(@{$this->{_ViewPorts}},$vp,1); | |||
if($vp == $cnt){ | if($vp == $cnt){ | |||
$this->current_viewport($vp-1); | $this->current_viewport($vp-1); | |||
} | } | |||
} | } | |||
sub clear_viewports { | sub clear_viewports { | |||
my($this) = @_; | my($this) = @_; | |||
foreach(@{$this->{_ViewPorts}}){ | foreach(@{$this->{_ViewPorts}}){ | |||
$_->clear_objects(); | $_->clear_objects(); | |||
} | } | |||
skipping to change at line 192 | skipping to change at line 169 | |||
my($this, $vp) = @_; | my($this, $vp) = @_; | |||
my $cnt; | my $cnt; | |||
$vp = $this->_vp_num_fromref($vp); | $vp = $this->_vp_num_fromref($vp); | |||
$this->{_ViewPorts}[$vp]->clear_objects(); | $this->{_ViewPorts}[$vp]->clear_objects(); | |||
} | } | |||
sub set_eventhandler { | sub set_eventhandler { | |||
my($this,$handler) = @_; | my($this,$handler) = @_; | |||
$this->{EHandler} = $handler; | $this->{EHandler} = $handler; | |||
# for(@{$this->{_ViewPorts}}) { | # for(@{$this->{_ViewPorts}}) { | |||
# $_->eventhandler($handler); | # $_->eventhandler($handler); | |||
# } | # } | |||
} | } | |||
#sub set_transformer { | #sub set_transformer { | |||
# my($this,$transformer) = @_; | # my($this,$transformer) = @_; | |||
# | # | |||
# for(@{$this->{_ViewPorts}}) { | # for(@{$this->{_ViewPorts}}) { | |||
# $_->transformer($transformer); | # $_->transformer($transformer); | |||
# } | # } | |||
#} | #} | |||
sub AUTOLOAD { | sub AUTOLOAD { | |||
my ($self,@args)=@_; | my ($self,@args)=@_; | |||
use vars qw($AUTOLOAD); | use vars qw($AUTOLOAD); | |||
my $sub = $AUTOLOAD; | my $sub = $AUTOLOAD; | |||
return if $sub =~ /::DESTROY$/; | return if $sub =~ /::DESTROY$/; | |||
# If an unrecognized function is called for window it trys to apply it | # If an unrecognized function is called for window it trys to apply it | |||
# to all of the defined ViewPorts | # to all of the defined ViewPorts | |||
$sub =~ s/.*:://; | $sub =~ s/.*:://; | |||
print "AUTOLOAD: $sub at ",__FILE__," line ", __LINE__ ,".\n" | print "AUTOLOAD: $sub at ",__FILE__," line ", __LINE__ ,".\n" | |||
if($PDL::Graphics::TriD::verbose); | if($PDL::Graphics::TriD::verbose); | |||
print "Window AUTOLOADing '$sub': self=$self, args='".join("','",@args),"'\n" | ||||
print "Window AUTOLOADing '$sub': self=$self, args='".join("','",@args),"'\n" | if($PDL::Graphics::TriD::verbose); | |||
if($PDL::debug_trid); | ||||
if($sub =~ /^gl/ && defined $self->{_GLObject}){ | if($sub =~ /^gl/ && defined $self->{_GLObject}){ | |||
return $self->{_GLObject}->$sub(@args); | return $self->{_GLObject}->$sub(@args); | |||
} | } | |||
for(@{$self->{_ViewPorts}}) { | for(@{$self->{_ViewPorts}}) { | |||
next unless defined $_; | next unless defined $_; | |||
$_->$sub(@args); | $_->$sub(@args); | |||
} | } | |||
} | } | |||
1; | 1; | |||
End of changes. 32 change blocks. | ||||
44 lines changed or deleted | 14 lines changed or added |