AntTweakBar
view release on metacpan or search on metacpan
lib/AntTweakBar.pm view on Meta::CPAN
=head3 cb_write($value)
Closure, that is been invoked when user sets new value to the variable.
If C<cb_write> is undefined, then the variable considered B<readonly>.
=head3 definition
An string or hashref of values that allows additional tuning of
variable in Anttweakbar.
See L<http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:varparamsyntax#parameters>
for possible values.
=cut
sub add_variable {
my ($self, %args) = @_;
for (qw/mode name type/) {
croak "'$_' is mandatory argument for add_variable"
unless exists $args{$_};
}
my $mode = $args{mode };
my $name = $args{name };
my $type = $args{type };
my $value = $args{value };
my $cb_read = $args{cb_read };
my $cb_write = $args{cb_write };
my $definition = $args{definition} // "";
croak "Either value or callbacks should be specified"
if ($value && ($cb_read || $cb_write));
croak "cb_read is mandatory when value isn't specied"
if (!$value && !$cb_read);
croak "value should be a reference"
if ($value && !ref($value));
$type = $type->name if(ref($type) eq 'AntTweakBar::Type');
$definition = _as_definition_string($definition)
if ($definition && ref($definition) eq 'HASH');
_add_variable($self->{_bar_ptr}, $mode, $name, $type, $value,
$cb_read, $cb_write, $definition);
}
=head2 remove_variable($name)
$bar->remove_variable('Zoom');
=cut
sub remove_variable {
my ($self, $name) = @_;
_remove_variable($self->{_bar_ptr}, $name);
}
=head2 refresh
$bar->refresh;
Tells Anttweakbar that variable values are possibly changed and
should be updated.
=cut
sub refresh {
my $self = shift;
_refresh($self->{_bar_ptr});
}
=head2 set_bar_params(%values)
$bar->set_bar_params(
size => '350 700,
valueswidth => '200'
visible => 'false',
);
Updates bar definition at runtime. See
L<http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:twbarparamsyntax>.
=cut
sub set_bar_params {
my ($self, %params) = @_;
while (my ($k, $v) = each(%params)) {
_set_bar_parameter($self->{_bar_ptr}, $k, $v);
}
}
=head2 set_variable_params($var_name, $var_definition)
$bar->set_variable_params('ObjRotation', readonly => 'true');
Updates variable definition at runtime. See
L<http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:varparamsyntax#parameters>
=cut
sub set_variable_params {
my ($self, $variable, %params) = @_;
while (my ($k, $v) = each(%params)) {
_set_variable_parameter($self->{_bar_ptr}, $variable, $k, $v);
}
}
=head1 INITIALIZATION AND DRAW FUNCTIONS
=head2 init
AntTweakBar::init(TW_OPENGL);
Initializes AntTweakBar
=head2 terminate
AntTweakBar::terminate
Uninitializes AntTweakBar
( run in 1.112 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )