IUP

 view release on metacpan or  search on metacpan

examples/0-basic/plot_advanced.pl  view on Meta::CPAN

use strict;
use warnings;

use IUP ':all';

my $MAXPLOT = 6;
my @plot = ();        # Plot controls
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
my $tabs;             # tabbed control

sub delete_cb {
  my ($self, $index, $sample_index, $x, $y) = @_;
  printf("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("SELECT_CB(%d, %d, %g, %g, %d)\n", $index, $sample_index, $x, $y, $select);
  return IUP_DEFAULT;
}

sub edit_cb {
  #(Ihandle* ih, int index, int sample_index, float x, float y, float *new_x, float *new_y)
  # xxxTODO: references
  # perhaps - return (IUP_DEFAULT, $new_x, $new_y);
  my ($self, $index, $sample_index, $x, $y) = @_;
  printf STDERR "EDIT_CB(%d, %d, %g, %g)\n", $index, $sample_index, $x, $y;  
  return (IUP_DEFAULT, $x, $y+0.001);
}

sub postdraw_cb {
  #(Ihandle* ih, cdCanvas* cnv)
  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 {
  #(Ihandle* ih, cdCanvas* cnv)
  my ($self, $cnv) = @_;
  #printf("PREDRAW_CB()\n");
  return IUP_DEFAULT;
}

sub InitPlots {
  my $theFac;

  # PLOT 0 - MakeExamplePlot1
  $plot[0]->SetAttribute("TITLE", "AutoScale");
  $plot[0]->SetAttribute("MARGINTOP", "40");
  $plot[0]->SetAttribute("MARGINLEFT", "40");
  $plot[0]->SetAttribute("MARGINBOTTOM", "50");
  $plot[0]->SetAttribute("TITLEFONTSIZE", "16");
  $plot[0]->SetAttribute("AXS_XLABEL", "gnu (Foo)");
  $plot[0]->SetAttribute("AXS_YLABEL", "Space (m^3)");
  $plot[0]->SetAttribute("AXS_YFONTSIZE", "7");
  $plot[0]->SetAttribute("AXS_YTICKFONTSIZE", "7");
  $plot[0]->SetAttribute("LEGENDSHOW", "YES");
  $plot[0]->SetAttribute("AXS_XFONTSIZE", "10");
  $plot[0]->SetAttribute("AXS_YFONTSIZE", "10");
  $plot[0]->SetAttribute("AXS_XLABELCENTERED", "NO");
  $plot[0]->SetAttribute("AXS_YLABELCENTERED", "NO");
  
#  IupSetAttribute(plot[0], "USE_IMAGERGB", "YES");

examples/0-basic/plot_advanced.pl  view on Meta::CPAN

  my $curr_tab = IUP->GetByName($tabs->GetAttribute("VALUE"));
  my $ss = $curr_tab->GetAttribute("TABTITLE");
  $ss = int(substr($ss, 5)); # Skip "Plot "
  return $ss;
}

# Some processing required by current tab change: the controls at left
# will be updated according to current plot props
sub tabs_tabchange_cb {
  #(Ihandle* self, Ihandle* new_tab)
  my ($self, $new_tab) = @_;
  my $ii = 0;

  my $ss = $new_tab->GetAttribute("TABTITLE");
  $ss = substr($ss, 5); # Skip "Plot "
  $ii = int($ss);  

  # autoscaling
  # X axis
  if ($plot[$ii]->GetAttribute("AXS_XAUTOMIN") && $plot[$ii]->GetAttribute("AXS_XAUTOMAX")) {
    $tgg2->VALUE("ON");
    $dial2->ACTIVE("NO");
  }
  else {
    $tgg2->VALUE("OFF");
    $dial2->ACTIVE("YES");
  }
  # Y axis
  if ($plot[$ii]->GetAttribute("AXS_YAUTOMIN") && $plot[$ii]->GetAttribute("AXS_YAUTOMAX")) {
    $tgg1->VALUE("ON");
    $dial1->ACTIVE("NO");
  }
  else {
    $tgg1->VALUE("OFF");
    $dial1->ACTIVE("YES");
  }

  # grid
  if ($plot[$ii]->GetAttribute("GRID")) {
    $tgg3->VALUE("ON");
    $tgg4->VALUE("ON");
  }
  else
  {
    # X axis
    if ($plot[$ii]->GetAttribute("GRID") eq 'V') {
      $tgg3->VALUE("ON");
    }
    else {
      $tgg3->VALUE("OFF");
    }
    # Y axis
    if ($plot[$ii]->GetAttribute("GRID") eq 'H') {
      $tgg4->VALUE("ON");
    }
    else {
      $tgg4->VALUE("OFF");
    }
  }

  # legend
  if ($plot[$ii]->GetAttribute("LEGENDSHOW")) {
    $tgg5->VALUE("ON");
  }
  else {
    $tgg5->VALUE("OFF");
  }

  return IUP_DEFAULT;
}

# show/hide V grid
sub tgg3_cb {
  my ($self, $v) = @_;
  my $ii = tabs_get_index();

  if ($v) {
    if ($tgg4->GetAttribute("VALUE")) {
      $plot[$ii]->SetAttribute("GRID", "YES");
    }
    else {
      $plot[$ii]->SetAttribute("GRID", "VERTICAL");
    }
  }
  else {
    if (!$tgg4->GetAttribute("VALUE")) {
      $plot[$ii]->SetAttribute("GRID", "NO");
    }
    else {
      $plot[$ii]->SetAttribute("GRID", "HORIZONTAL");
    }
  }

  $plot[$ii]->SetAttribute("REDRAW", undef);

  return IUP_DEFAULT;
}


# show/hide H grid
sub tgg4_cb {
  my ($self, $v) = @_;
  my $ii = tabs_get_index();

  if ($v) {
    if ($tgg3->GetAttribute("VALUE")) {
      $plot[$ii]->SetAttribute("GRID", "YES");
    }
    else {
      $plot[$ii]->SetAttribute("GRID", "HORIZONTAL");
    }
  }
  else
  {
    if (!$tgg3->GetAttribute("VALUE")) {
      $plot[$ii]->SetAttribute("GRID", "NO");
    }
    else {
      $plot[$ii]->SetAttribute("GRID", "VERTICAL");
    }
  }

  $plot[$ii]->SetAttribute("REDRAW", undef);

  return IUP_DEFAULT;
}


# show/hide legend
sub tgg5_cb {
  my ($self, $v) = @_;
  my $ii = tabs_get_index();

  $plot[$ii]->SetAttribute("LEGENDSHOW", $v ? "YES" : "NO");
  $plot[$ii]->SetAttribute("REDRAW", undef);

  return IUP_DEFAULT;
}


# autoscale Y
sub tgg1_cb {
  my ($self, $v) = @_;
  my $ii = tabs_get_index();

  if ($v) {
    $dial1->SetAttribute("ACTIVE", "NO");
    $plot[$ii]->SetAttribute("AXS_YAUTOMIN", "YES");
    $plot[$ii]->SetAttribute("AXS_YAUTOMAX", "YES");
  }
  else {
    $dial1->SetAttribute("ACTIVE", "YES");
    $plot[$ii]->SetAttribute("AXS_YAUTOMIN", "NO");
    $plot[$ii]->SetAttribute("AXS_YAUTOMAX", "NO");
  }

  $plot[$ii]->SetAttribute("REDRAW", undef);

  return IUP_DEFAULT;
}


# autoscale X
sub tgg2_cb {
  my ($self, $v) = @_;
  my $ii = tabs_get_index();

  if ($v) {
    $dial2->SetAttribute("ACTIVE", "NO");
    $plot[$ii]->SetAttribute("AXS_XAUTOMIN", "YES");
    $plot[$ii]->SetAttribute("AXS_XAUTOMAX", "YES");
  }
  else {
    $dial2->SetAttribute("ACTIVE", "YES");
    $plot[$ii]->SetAttribute("AXS_XAUTOMIN", "NO");
    $plot[$ii]->SetAttribute("AXS_XAUTOMAX", "NO");
  }

  $plot[$ii]->SetAttribute("REDRAW", undef);

  return IUP_DEFAULT;
}


# Y zoom
sub dial1_btndown_cb {
  my ($self, $angle) = @_;
  my $ii = tabs_get_index();



( run in 0.707 second using v1.01-cache-2.11-cpan-98e64b0badf )