AntTweakBar - Perl bindings for AntTweakBar
use AntTweakBar qw/:all/; use SDL::Events; # Setup part: link AntTweakBar with your OpenGL/SDL system AntTweakBar::init(TW_OPENGL); AntTweakBar::window_size($width, $height); # in your main rendering routine sub display { AntTweakBar::draw; } sub process_events { SDL::Events::pump_events; my $event = $self->sdl_event; while (SDL::Events::poll_event($event)) { ...; AntTweakBar::eventSDL($event); } } # define bars with variables my $bar = AntTweakBar->new( "TweakBar & Perl", size => '200 400', color => '96 216 224' ); my $enabled = 0; $bar->add_variable( mode => 'rw', name => "Enabled", type => 'bool', value => \$enabled );
AntTweakBar (see http://anttweakbar.sourceforge.net/) is nice tiny GUI library for OpenGL/SDL/DirectX applications.
If you are in hurry to evaluate it then intall AntTweakBar and try examples from eg directory within the distribution.
eg
To display AntTweakBar in your OpenGL/SDL application you should do the following:
AntTweakBar::init(TW_OPENGL); AntTweakBar::window_size($width, $height);
AntTweakBar::draw;
AntTweakBar::eventSDL($event);
my $bar = AntTweakBar->new("TweakBar");
my $value = 3.14; $bar->add_variable( mode => 'rw', name => "Enabled", type => 'integer', value => \$value );
See working examples in the eg directoctory within the distribution.
Constants only
The following constants let AntTweakBar know which graphic system do you use, to know how to render itself
Render using plain old OpenGL
Render AntTweakBar using OpenGL core profile, which excludes deprecated OpenGL functions. See: https://en.wikipedia.org/wiki/OpenGL_4#OpenGL_3.2
my $bar = AntTweakBar->new( "TweakBar & Perl", size => '200 400', color => '96 216 224' ); my $another_bar = AntTweakBar->new( "Misc.", );
Creates new AntTweakBar instance. Optionally the list of strings of bar-related parameters can be provided. See the list of available at http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:twbarparamsyntax.
$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 http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:varparamsyntax#parameters.
$bar->add_separator('separator-name');
my $zoom = 1.0; $bar->add_variable( mode => 'rw', name => "Zoom", type => 'number', value => \$zoom, definition => " min=0.01 max=2.5 step=0.01 help='Bla-bla-bla.' ", ); # the same, but with more perlish style in definition $bar->add_variable( mode => 'rw', name => "Zoom", type => 'number', value => \$zoom, definition => { min => "0.01", max => "2.5", step => "0.01", keyIncr => 'z', keyDecr => 'Z', help => 'Scale the object (1=original size).' }, ); 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"; } );
mode, name, type are mandatory. Either value or cb_read should be specified. The definition and cb_write are optional.
mode
name
type
value
cb_read
definition
cb_write
The mode can be rw (read/write) or ro (read only). The mode specified whether the variable value could be modified via AntTweakBar.
rw
ro
Defines the unique variable name at tweakbar. Unless label is specified via defintion, then name also defines the visual label. for the variable.
label
defintion
Defines the type of variable. Original types http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:twtype were reduced to:
variable must be reference to array, consisted of 3 float values: rgb.
variable must be reference to array, consisted of 4 float values: rgba.
3D-vector (direction). The variable must be reference to array, consisted of 3 float values.
4D-vector (3D-object rotation). The variable must be reference to array, consisted of 4 float values.
The reference to the variable value. For complex types (e.g. quaternion) it must also be an reference to array of 3 numbers.
Closure, that returns the actual value of variable.
Closure, that is been invoked when user sets new value to the variable. If cb_write is undefined, then the variable considered readonly.
An string or hashref of values that allows additional tuning of variable in Anttweakbar. See http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:varparamsyntax#parameters for possible values.
$bar->remove_variable('Zoom');
$bar->refresh;
Tells Anttweakbar that variable values are possibly changed and should be updated.
$bar->set_bar_params( size => '350 700, valueswidth => '200' visible => 'false', );
Updates bar definition at runtime. See http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:twbarparamsyntax.
$bar->set_variable_params('ObjRotation', readonly => 'true');
Updates variable definition at runtime. See http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:varparamsyntax#parameters
AntTweakBar::init(TW_OPENGL);
Initializes AntTweakBar
AntTweakBar::terminate
Uninitializes AntTweakBar
AntTweakBar::window_size(640, 480);
Tell AntTweakBar the actual size of your window
Draw AntTweakBar just before the frame buffer is presented (swapped).
glutMouseFunc(\&AntTweakBar::eventMouseButtonGLUT);
Let AntTweakBar handles mouse button clicks
glutMotionFunc(\&AntTweakBar::eventMouseMotionGLUT); glutPassiveMotionFunc(\&AntTweakBar::eventMouseMotionGLUT);
Let AntTweakBar handles mouse movements with pressed button(s) and passive mouse movements
glutKeyboardFunc(\&AntTweakBar::eventKeyboardGLUT);
Let AntTweakBar handles key presses
glutSpecialFunc(\&AntTweakBar::eventSpecialGLUT);
AntTweakBar::GLUTModifiersFunc(\&glutGetModifiers);
If you use SDL than it is more simple to let AntTweakBar process all input-related events via single call:
AntTweakBar::eventSDL($sdl_event);
Alien::AntTweakBar, SDL, OpenGL, http://anttweakbar.sourceforge.net/
Ivan Baidakou <dmol@(gmx.com)>
David Horner
Copyright (C) 2014 by Ivan Baidakou
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.20.0 or, at your option, any later version of Perl 5 you may have available.
To install AntTweakBar, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AntTweakBar
CPAN shell
perl -MCPAN -e shell install AntTweakBar
For more information on module installation, please visit the detailed CPAN module installation guide.