IUP
view release on metacpan or search on metacpan
examples/1-apps/app-plot-demo.pl view on Meta::CPAN
use strict;
use warnings;
use IUP ':all';
my $mainplot;
my $mainfunc;
my ($dial1, $dial2); # dials for zooming
my ($tgg1, $tgg2); # auto scale on|off toggles
my ($tgg3, $tgg4); # grid show|hide toggles
my $tgg5; # legend show|hide toggle
sub delete_cb {
my ($self, $index, $sample_index, $x, $y) = @_;
printf STDERR "DELETE_CB(%d, %d, %g, %g)\n", $index, $sample_index, $x, $y;
return IUP_DEFAULT;
}
sub select_cb {
my ($self, $index, $sample_index, $x, $y, $select) = @_;
printf STDERR "SELECT_CB(%d, %d, %g, %g, %d)\n", $index, $sample_index, $x, $y, $select;
return IUP_DEFAULT;
}
sub edit_cb {
# xxxTODO: references
# perhaps - return (IUP_DEFAULT, $new_x, $new_y);
my ($self, $index, $sample_index, $x, $y, $new_x, $new_y) = @_;
printf STDERR "EDIT_CB(%d, %d, %g, %g, %g, %g)\n", $index, $sample_index, $x, $y, $new_x, $new_y;
return IUP_DEFAULT;
}
sub postdraw_cb {
my ($self, $cnv) = @_;
#my ($ix, $iy) = $self->PlotTransform(0.003, 0.02);
#$cnv->cdFont(undef, CD_BOLD, 10);
#$cnv->cdTextAlignment(CD_SOUTH);
#$cnv->cdText($ix, $iy, "My Inline Legend");
return IUP_DEFAULT;
}
sub predraw_cb {
my ($self, $cnv) = @_;
#printf STDERR "PREDRAW_CB()\n";
return IUP_DEFAULT;
}
sub InitPlot {
my $theFac;
$mainplot->SetAttribute(
TITLE => "Sample Plot",
AXS_XORIGIN=>0,
AXS_YORIGIN=>0,
#TITLEFONTSIZE => 1.2,
TITLEFONTSTYLE => 'BOLD',
MARGINTOP => "40",
OPENGL=>"YES",
);
$theFac = 100.0/(100*100*100);
my (@x, @y);
for (my $theI=-10; $theI<=10; $theI++) {
push @x, (0.001*$theI);
push @y, (0.01+$theFac*$theI*$theI*$theI);
}
$mainplot->PlotBegin(2)->PlotAdd2D(\@x, \@y)->PlotEnd;
#$mainplot->SetAttribute("DS_COLOR", "100 100 200");
#$mainplot->SetAttribute("DS_EDIT", "YES");
$mainplot->SetCallback("DELETE_CB", \&delete_cb);
$mainplot->SetCallback("SELECT_CB", \&select_cb);
$mainplot->SetCallback("POSTDRAW_CB", \&postdraw_cb);
$mainplot->SetCallback("PREDRAW_CB", \&predraw_cb);
$mainplot->SetCallback("EDIT_CB", \&edit_cb);
}
# show/hide V grid
sub tgg3_cb {
my ($self, $v) = @_;
if ($v) {
#checked
$mainplot->GRID( ($tgg4->VALUE eq 'ON') ? "YES" : "VERTICAL" );
}
else {
#unchecked
$mainplot->GRID( ($tgg4->VALUE eq 'OFF') ? "NO" : "HORIZONTAL" );
}
$mainplot->REDRAW(1);
return IUP_DEFAULT;
}
# show/hide H grid
sub tgg4_cb {
my ($self, $v) = @_;
if ($v) {
#checked
$mainplot->GRID( ($tgg3->VALUE eq 'ON') ? "YES" : "HORIZONTAL" );
}
else {
#unchecked
$mainplot->GRID( ($tgg3->VALUE eq 'OFF') ? "NO" : "VERTICAL" );
}
$mainplot->REDRAW(1);
return IUP_DEFAULT;
}
# show/hide legend
sub tgg5_cb {
my ($self, $v) = @_;
$mainplot->LEGENDSHOW($v ? "YES" : "NO");
$mainplot->REDRAW(1);
return IUP_DEFAULT;
}
# autoscale Y
sub tgg1_cb {
my ($self, $v) = @_;
if ($v) {
$dial1->SetAttribute("ACTIVE", "NO");
$mainplot->SetAttribute("AXS_YAUTOMIN", "YES");
$mainplot->SetAttribute("AXS_YAUTOMAX", "YES");
}
else {
$dial1->SetAttribute("ACTIVE", "YES");
$mainplot->SetAttribute("AXS_YAUTOMIN", "NO");
$mainplot->SetAttribute("AXS_YAUTOMAX", "NO");
}
$mainplot->REDRAW(1);
return IUP_DEFAULT;
}
# autoscale X
sub tgg2_cb {
my ($self, $v) = @_;
if ($v) {
$dial2->SetAttribute("ACTIVE", "NO");
$mainplot->SetAttribute("AXS_XAUTOMIN", "YES");
$mainplot->SetAttribute("AXS_XAUTOMAX", "YES");
}
else {
$dial2->SetAttribute("ACTIVE", "YES");
$mainplot->SetAttribute("AXS_XAUTOMIN", "NO");
$mainplot->SetAttribute("AXS_XAUTOMAX", "NO");
}
$mainplot->REDRAW(1);
return IUP_DEFAULT;
}
# Y zoom
sub dial1_btndown_cb {
my ($self, $angle) = @_;
warn "***DEBUG*** dial1_btndown_cb: ", $mainplot->GetAttribute("AXS_YMIN"), ":", $mainplot->GetAttribute("AXS_YMAX"), "\n";
$mainplot->SetAttribute("OLD_YMIN", $mainplot->GetAttribute("AXS_YMIN"));
$mainplot->SetAttribute("OLD_YMAX", $mainplot->GetAttribute("AXS_YMAX"));
return IUP_DEFAULT;
}
sub dial1_btnup_cb {
my ($self, $angle) = @_;
my ($x1, $x2, $xm);
my $ss;
$x1 = $mainplot->GetAttribute("OLD_YMIN");
$x2 = $mainplot->GetAttribute("OLD_YMAX");
( run in 1.303 second using v1.01-cache-2.11-cpan-98e64b0badf )