AntTweakBar

 view release on metacpan or  search on metacpan

lib/AntTweakBar.pm  view on Meta::CPAN


=item color3f

variable must be reference to array, consisted of 3 float values: rgb.

=item color4f

variable must be reference to array, consisted of 4 float values: rgba.

=item direction

3D-vector (direction). The variable must be reference to array, consisted of 3 float values.

=item quaternion

4D-vector (3D-object rotation). The variable must be reference to array, consisted of 4 float values.

=item custom type of L<Anttweakbar::Type>

=back

=head3 value

The B<reference> to the variable value. For complex types (e.g. quaternion) it must
also be an B<reference> to array of 3 numbers.

=head3 cb_read

Closure, that returns the actual value of variable.

=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)



( run in 0.658 second using v1.01-cache-2.11-cpan-d8267643d1d )