AntTweakBar
view release on metacpan or search on metacpan
eg/available-properties.pl view on Meta::CPAN
my ($width, $height) = @_;
glViewport(0, 0, $width, $height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPerspective(40, $width/$height, 1, 10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
gluLookAt(0,0,5, 0,0,0, 0,1,0);
glTranslatef(0, 0.6, -1);
say "window size: ${width} x ${height}";
AntTweakBar::window_size($width, $height);
}
glutInit;
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("[perl] AntTweakBar simple example using GLUT");
AntTweakBar::init(TW_OPENGL);
eg/available-properties.pl view on Meta::CPAN
my $color4f_rw = [0.5, 0.5, 1.0, 0.2];
my $direction_ro = [1.0, 0.0, 0.0];
my $direction_rw = [0.0, 0.0, 1.0];
my $quaternion_ro = [1.0, 0.1, 0.0, 0.0];
my $quaternion_rw = [0.0, 1.0, 1.1, 0.0];
my $custom_ro = "a";
my $custom_rw = undef;
my $magic_var_rw = 1.234;
my $wizzard = wizard(
set => sub { say "set magic to ", ${$_[0]} },
);
cast $magic_var_rw, $wizzard;
# types: bool, integer, number, string, color3f, color4f, direction, quaternion, custom enums
$bar->add_variable(
mode => 'ro',
name => "bool_ro",
type => 'bool',
value => \$bool_ro,
eg/available-properties.pl view on Meta::CPAN
$bar->add_variable(
mode => 'rw',
name => "magic_var_rw",
type => "number",
value => \$magic_var_rw,
);
$bar->add_button(
name => "my-btn-name",
cb => sub {
say "bool_ro=$bool_ro, bool_rw=$bool_rw";
say "int_ro=$int_ro, int_rw=$int_rw";
say "number_ro=$number_ro, number_rw=$number_rw";
say "string_ro=$string_ro, string_rw=$string_rw";
say "color3f_ro=", dump($color3f_ro), ", color3f_rw=", dump($color3f_rw);
say "color4f_ro=", dump($color4f_ro), ", color4f_rw=", dump($color4f_rw);
say "direction_ro=", dump($direction_ro), ", direction_rw=", dump($direction_rw);
say "quaternion_ro=", dump($quaternion_ro), ", quaternion_rw=", dump($quaternion_rw);
say "custom_rw=$custom_rw";
},
definition => "label='dump'",
);
$bar->add_separator("separator2");
$bar->add_button(
name => "remove quaternions & refresh",
cb => sub {
if ($quaternion_ro) {
$bar->remove_variable('quaternion_ro');
$quaternion_ro = undef;
eg/available-properties.pl view on Meta::CPAN
my $color4f = [0.0, 0.2, 0.4, 1.0];
my $direction = [1.0, 0.2, 0.4];
my $quaternion = [0.1, 0.2, 0.4, 1.0];
my $custom_idx = 0;
my $b2 = AntTweakBar->new("Perl callbacks");
$b2->add_variable(
mode => 'ro',
name => "bool_ro_cb",
type => 'bool',
cb_read => sub {
say "hello from bool_ro_cb!, bool = $bool";
return undef;
},
);
$b2->add_variable(
mode => 'rw',
name => "bool_rw_cb",
type => 'bool',
cb_read => sub { $bool; },
cb_write => sub {
$bool = shift;
say "writing value $bool";
}
);
$b2->add_variable(
mode => 'ro',
name => "number_ro_cb",
type => 'number',
cb_read => sub {
say "returning double value $double";
$double;
},
);
$b2->add_variable(
mode => 'rw',
name => "number_rw_cb",
type => 'number',
cb_read => sub { $double },
cb_write => sub { $double = shift; },
);
eg/available-properties.pl view on Meta::CPAN
type => 'color3f',
cb_read => sub { $color3f },
);
$b2->add_variable(
mode => 'rw',
name => "color3f_rw_cb",
type => 'color3f',
cb_read => sub { $color3f },
cb_write => sub {
@$color3f = @{$_[0]};
say "now color3f = " . dump($color3f);
},
);
$b2->add_variable(
mode => 'rw',
name => "color4f_rw_cb",
type => 'color4f',
cb_read => sub { $color4f },
cb_write => sub { @$color4f = @{$_[0]} },
);
$b2->add_variable(
lib/AntTweakBar.pm view on Meta::CPAN
my $value = $d->{$key};
$value =~ s/'/\\'/g;
"$key='$value'";
} sort keys %$d);
}
=head2 add_button
$bar->add_button(
name => 'my_btn',
cb => sub { say "clicked!" },
definition => "label='Click me!'", # optional
);
$bar->add_button(
name => 'my_btn',
cb => sub { say "clicked!" },
definition => { # optional
label => 'Click me!'
}
);
The definition parameters are the same as for variable. See
L<http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:varparamsyntax#parameters>.
=cut
lib/AntTweakBar.pm view on Meta::CPAN
);
my $bool = undef;
$bar->add_variable(
mode => 'rw',
name => "bool_rw_cb",
type => 'bool',
cb_read => sub { $bool; },
cb_write => sub {
$bool = shift;
say "writing value $bool";
}
);
C<mode>, C<name>, C<type> are mandatory. Either C<value> or C<cb_read>
should be specified. The C<definition> and C<cb_write> are optional.
=head3 mode
The B<mode> can be C<rw> (read/write) or C<ro> (read only). The mode
specified whether the variable value could be modified via AntTweakBar.
( run in 1.398 second using v1.01-cache-2.11-cpan-a1f116cd669 )