controlp5/reference/controlP5/ControlElement.html

424 lines
12 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (version 1.7.0_51) on Sun Apr 27 21:39:46 SGT 2014 -->
<title>ControlElement (Javadocs: controlP5)</title>
<meta name="date" content="2014-04-27">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="ControlElement (Javadocs: controlP5)";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!-- -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../controlP5/package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../index-all.html">Index</a></li>
<li><a href="../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../controlP5/ControlBroadcaster.html" title="class in controlP5"><span class="strong">Prev Class</span></a></li>
<li><a href="../controlP5/ControlEvent.html" title="class in controlP5"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../index.html?controlP5/ControlElement.html" target="_top">Frames</a></li>
<li><a href="ControlElement.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation_type_optional_element_summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#annotation_type_element_detail">Element</a></li>
</ul>
</div>
<a name="skip-navbar_top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">controlP5</div>
<h2 title="Annotation Type ControlElement" class="title">Annotation Type ControlElement</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>@Retention(value=RUNTIME)
public @interface <span class="strong">ControlElement</span></pre>
<div class="block">Used for automated controller creation using annotations. Very much inspired by Karsten Schmidt's
(toxi) cp5magic</div>
<dl><script type="text/javascript">
<!--
document.getElementsByTagName('html')[0].className = 'isjs';function toggle(dt) { var display, dd=dt; do{ dd = dd.nextSibling } while(dd.tagName!='DD'); toOpen =!dd.style.display;dd.style.display = toOpen? 'block':''; dt.getElementsByTagName('span')[0].innerHTML = toOpen? '-':'+' ; }
-->
</script>
<div id="test" class="toggleList"><dl><dt onclick="toggle(this);"><span>+</span>Example</dt><dd><code><pre>/**
* ControlP5 Annotation
*
* Lately annotation support has been added to processing.
* Making use of annotations to create controllers is a great strategy i learned
* from Karsten Schmidt's (toxi) cp5magic library.
* Loving the simplicity of annotations and how it is aplied with cp5magic,
* i had to include it into controlp5 and the following example
* shows how to use annotations with controlp5.
*
* Annotations can be applied to variables and functions of the main program
* as well as individual classes. More details are included in the comments below.
*
* by Andreas Schlegel, 2012
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
ControlP5 cp5;
TestControl tc1, tc2;
Tab extraTab;
// create controllers using the ControlElement annotation
// by default a slider is created for int and float
// values will range from 0-100 by default
// default attributes are x,y and label
@ControlElement (x=10, y=80)
int n = 20;
// to customize a controller with a CoontrolElement use the
// properties attribute. values passed using properties have a key and a value
// here the key corresponds with a function found within a controller which
// starts with set followed by the name of the key. the value is then applied accordingly.
// e.g. min=10 will translate to controller.setMin(10)
@ControlElement (properties = { "min=0", "max=255", "type=numberbox", "height=10", "width=50"} , x=10, y=40, label="Change Background")
float m = 40;
void setup() {
size(600, 400);
noStroke();
cp5 = new ControlP5(this);
// Annotations:
// addControllersFor(PApplet) checks the main sketch for
// annotations and adds controllers accordingly.
cp5.addControllersFor(this);
extraTab = cp5.addTab("extra");
// create an instance of class testControl
tc1 = new TestControl();
// addControllersFor cycles throught object tc1
// and assigns controllers according to available annotations.
// an address will be assigned to these controllers, in the example
// below the address is /world and the individual controllers can be
// accessed adding a / and the controller's name
// e.g. variable x
// /world/x
cp5.addControllersFor("world", tc1);
// set the Position of controllers contained within object tc1
cp5.setPosition(10, 150, tc1);
// a more advanced example of using functions with ControllerObjects
tc2 = new TestControl();
CColor col = new CColor();
col.setActive(color(0, 200, 100));
cp5.addControllersFor("hello", tc2)
.setPosition(200, 150, tc2)
.moveTo(extraTab, tc2)
.setColor(col, tc2);
cp5.getController("s", tc2)
.setStringValue("Second Control");
// with listening turned on, a controller can listen to changes made to its connected variable
// here the controller will listen to variable x of object tc2
cp5.getController("x", tc2).listen(true);
// (uncomment line below) print the a map of all available controller addresses
// cp5.printControllerMap();
// (uncomment line below) access a controller via its address:
// println(cp5.getController("/world/x").getInfo());
}
void draw() {
background(m);
pushMatrix();
if (tc1.b) {
fill(tc1.x);
translate(10, tc1.y);
rect(0, 300, 100, 20);
}
popMatrix();
fill(255);
text(tc1.in,400,100,150,300);
pushMatrix();
if (tc2.b) {
fill(tc2.x);
translate(200, tc2.y);
for (int i=0;i<1;i++) {
rect(0, 300, 100, 20);
}
}
popMatrix();
fill(255);
text(tc2.in,400,300,150,300);
// the variable x of object tt is controlled by the main program,
// the matching controller will update accordingly since it is
// listening for changes.
tc2.x = (int)random(100);
}
public class TestControl {
@ControlElement (properties = { "min=0", "max=255" }, x=0, y=0, label="Brightness")
public int x = 100;
@ControlElement (x=0, y=14, label="Y-Position")
public float y = 0;
@ControlElement (x=0, y=40, label="show")
public boolean b = true;
@ControlElement (x=50, y=40)
public void toggle(boolean b) {
println("hello world");
}
@ControlElement (x=0, y=-20, label="Control", properties = { "type=textlabel"})
String s;
@ControlElement (x=0, y=100, label="Type here")
String in = "";
@ControlElement (x=200, y=25, properties = {"type=list", "items=hello, world, how are you"}, label="Sample-list")
public void a(int val) {
println(val);
}
}
</pre></code></dd></dl></div></dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation_type_optional_element_summary">
<!-- -->
</a>
<h3>Optional Element Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Optional Element Summary table, listing optional elements, and an explanation">
<caption><span>Optional Elements</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Optional Element and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlElement.html#label()">label</a></strong></code>&nbsp;</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>java.lang.String[]</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlElement.html#properties()">properties</a></strong></code>&nbsp;</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlElement.html#x()">x</a></strong></code>&nbsp;</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlElement.html#y()">y</a></strong></code>&nbsp;</td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation_type_element_detail">
<!-- -->
</a>
<h3>Element Detail</h3>
<a name="label()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>label</h4>
<pre>public abstract&nbsp;java.lang.String&nbsp;label</pre>
<dl>
<dt>Default:</dt>
<dd>""</dd>
</dl>
</li>
</ul>
<a name="properties()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>properties</h4>
<pre>public abstract&nbsp;java.lang.String[]&nbsp;properties</pre>
<dl>
<dt>Default:</dt>
<dd>{}</dd>
</dl>
</li>
</ul>
<a name="x()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>x</h4>
<pre>public abstract&nbsp;int&nbsp;x</pre>
<dl>
<dt>Default:</dt>
<dd>-1</dd>
</dl>
</li>
</ul>
<a name="y()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>y</h4>
<pre>public abstract&nbsp;int&nbsp;y</pre>
<dl>
<dt>Default:</dt>
<dd>-1</dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!-- -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../controlP5/package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../index-all.html">Index</a></li>
<li><a href="../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../controlP5/ControlBroadcaster.html" title="class in controlP5"><span class="strong">Prev Class</span></a></li>
<li><a href="../controlP5/ControlEvent.html" title="class in controlP5"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../index.html?controlP5/ControlElement.html" target="_top">Frames</a></li>
<li><a href="ControlElement.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation_type_optional_element_summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#annotation_type_element_detail">Element</a></li>
</ul>
</div>
<a name="skip-navbar_bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>processing library controlP5 by Andreas Schlegel. (c) 2006-2014</small></p>
</body>
</html>