controlp5/reference/controlP5/ControlBehavior.html

502 lines
15 KiB
HTML

<!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>ControlBehavior (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="ControlBehavior (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/ColorWheel.html" title="class in controlP5"><span class="strong">Prev Class</span></a></li>
<li><a href="../controlP5/ControlBroadcaster.html" title="class in controlP5"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../index.html?controlP5/ControlBehavior.html" target="_top">Frames</a></li>
<li><a href="ControlBehavior.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>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</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="Class ControlBehavior" class="title">Class ControlBehavior</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>controlP5.ControlBehavior</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public abstract class <span class="strong">ControlBehavior</span>
extends java.lang.Object</pre>
<div class="block">The abstract class control behavior allows you to add custom behavior to controllers. Since it is
an abstract class it must be extended and method update() must be implemented in your custom
control behavior. how to use ControlBehavior please see the ControlP5behavior example in the
examples folder.</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 Behavior
* ControlBehavior is an abstract class that can be extended using your
* custom control behaviors. What is a control behavior? Control Behaviors
* allow you to automate and dynamically change the state or value of a
* controller. One behavior per controller is currently supported. i case you
* need to use more that one bahavior, the implementation has to happen
* on your side - inside your control behavior.
*
* find a list of public methods available for the ControlBehavior Controller
* at the bottom of this sketch.
*
* by Andreas Schlegel, 2012
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
ControlP5 cp5;
int myColorBackground = color(0, 0, 0);
public int sliderValue = 100;
void setup() {
size(400, 400);
noStroke();
cp5 = new ControlP5(this);
cp5.addSlider("sliderValue")
.setRange(0,255)
.setValue(128)
.setPosition(100, 50 + height/2)
.setSize(40, 100);
cp5.addSlider("slider")
.setRange(100, 255)
.setValue(128)
.setPosition(100, 50)
.setSize(100, 40);
cp5.addBang("bang")
.setPosition(40, 50 + height/2)
.setSize(40, 40);
// add a custom ControlBehavior to controller bang,
// class TimerEvent is included in this sketch at the bottom
// and extends abstract class ControlBehavior.
cp5.getController("bang").setBehavior(new TimedEvent());
// use an anonymous class of type ControlBehavior.
cp5.getController("slider").setBehavior(new ControlBehavior() {
float a = 0;
public void update() {
setValue(sin(a += 0.1) * 50 + 150);
}
}
);
}
void draw() {
background(myColorBackground);
fill(sliderValue);
rect(0, 0, width, height/2);
}
void slider(float theColor) {
myColorBackground = color(theColor);
println("# a slider event. setting background to "+theColor);
}
public void bang() {
println("# an event received from controller bang.");
// a bang will set the value of controller sliderValue
// to a random number between 0 and 255.
cp5.getController("sliderValue").setValue(random(0, 255));
}
// custom ControlBehavior
class TimedEvent extends ControlBehavior {
long myTime;
int interval = 200;
public TimedEvent() {
reset();
}
void reset() {
myTime = millis() + interval;
}
public void update() {
if (millis()>myTime) {
setValue(1);
reset();
}
}
}
/*
a list of all methods available for the ControlBehavior Controller
use ControlP5.printPublicMethodsFor(ControlBehavior.class);
to print the following list into the console.
You can find further details about class ControlBehavior in the javadoc.
Format:
ClassName : returnType methodName(parameter type)
controlP5.ControlBehavior : Controller controller()
controlP5.ControlBehavior : boolean isActive()
controlP5.ControlBehavior : void setActive(boolean)
controlP5.ControlBehavior : void setValue(float)
java.lang.Object : String toString()
java.lang.Object : boolean equals(Object)
*/
</pre></code></dd></dl></div></dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><strong><a href="../controlP5/ControlBehavior.html#ControlBehavior()">ControlBehavior</a></strong>()</code>&nbsp;</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code><a href="../controlP5/Controller.html" title="class in controlP5">Controller</a>&lt;?&gt;</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlBehavior.html#controller()">controller</a></strong>()</code>
<div class="block"><strong>Deprecated.</strong>&nbsp;</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code><a href="../controlP5/Controller.html" title="class in controlP5">Controller</a>&lt;?&gt;</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlBehavior.html#getController()">getController</a></strong>()</code>
<div class="block">Returns the controller this behavior is connected to.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>float</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlBehavior.html#getValue()">getValue</a></strong>()</code>&nbsp;</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlBehavior.html#isActive()">isActive</a></strong>()</code>
<div class="block">check if the behavior is active or not.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlBehavior.html#setActive(boolean)">setActive</a></strong>(boolean&nbsp;theFlag)</code>
<div class="block">(de)activate the behavior.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlBehavior.html#setValue(float)">setValue</a></strong>(float&nbsp;theValue)</code>&nbsp;</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>abstract void</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlBehavior.html#update()">update</a></strong>()</code>
<div class="block">When extending ControlBehavior, update() has to be overridden.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>float</code></td>
<td class="colLast"><code><strong><a href="../controlP5/ControlBehavior.html#value()">value</a></strong>()</code>
<div class="block"><strong>Deprecated.</strong>&nbsp;</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods_inherited_from_class_java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="ControlBehavior()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>ControlBehavior</h4>
<pre>public&nbsp;ControlBehavior()</pre>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="controller()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>controller</h4>
<pre>@Deprecated
public&nbsp;<a href="../controlP5/Controller.html" title="class in controlP5">Controller</a>&lt;?&gt;&nbsp;controller()</pre>
<div class="block"><span class="strong">Deprecated.</span>&nbsp;</div>
</li>
</ul>
<a name="getController()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getController</h4>
<pre>public&nbsp;<a href="../controlP5/Controller.html" title="class in controlP5">Controller</a>&lt;?&gt;&nbsp;getController()</pre>
<div class="block">Returns the controller this behavior is connected to.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>Controller</dd></dl>
</li>
</ul>
<a name="getValue()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getValue</h4>
<pre>public&nbsp;float&nbsp;getValue()</pre>
</li>
</ul>
<a name="isActive()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>isActive</h4>
<pre>public&nbsp;boolean&nbsp;isActive()</pre>
<div class="block">check if the behavior is active or not.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>boolean</dd></dl>
</li>
</ul>
<a name="setActive(boolean)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>setActive</h4>
<pre>public&nbsp;void&nbsp;setActive(boolean&nbsp;theFlag)</pre>
<div class="block">(de)activate the behavior.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>theFlag</code> - boolean</dd></dl>
</li>
</ul>
<a name="setValue(float)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>setValue</h4>
<pre>public&nbsp;void&nbsp;setValue(float&nbsp;theValue)</pre>
</li>
</ul>
<a name="update()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>update</h4>
<pre>public abstract&nbsp;void&nbsp;update()</pre>
<div class="block">When extending ControlBehavior, update() has to be overridden.</div>
</li>
</ul>
<a name="value()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>value</h4>
<pre>@Deprecated
public&nbsp;float&nbsp;value()</pre>
<div class="block"><span class="strong">Deprecated.</span>&nbsp;</div>
<dl><dt><span class="strong">Returns:</span></dt><dd></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/ColorWheel.html" title="class in controlP5"><span class="strong">Prev Class</span></a></li>
<li><a href="../controlP5/ControlBroadcaster.html" title="class in controlP5"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../index.html?controlP5/ControlBehavior.html" target="_top">Frames</a></li>
<li><a href="ControlBehavior.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>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</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>