controlp5/reference/controlP5/CallbackEvent.html

439 lines
12 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>CallbackEvent (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="CallbackEvent (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/Button.html" title="class in controlP5"><span class="strong">Prev Class</span></a></li>
<li><a href="../controlP5/CallbackListener.html" title="interface in controlP5"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../index.html?controlP5/CallbackEvent.html" target="_top">Frames</a></li>
<li><a href="CallbackEvent.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>Constr&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>Constr&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 CallbackEvent" class="title">Class CallbackEvent</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>controlP5.CallbackEvent</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public class <span class="strong">CallbackEvent</span>
extends java.lang.Object</pre>
<div class="block"><p>
A CallbackEvent is send when a controller action such as enter, leave, press, etc has occurs.
</p></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 Callback
*
* The following example demonstrates the CallbackListener and CallbackEvent.
* Here additional information about each available slider will be show when
* hovering the controller with the mouse. The info will fade out when leaving
* the controller.
*
* When hovering a controller, the mouse pointer will change as well.
*
* find a list of public methods available for the CallbackEvent Controller
* at the bottom of this sketch.
*
* by Andreas Schlegel, 2012
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
ControlP5 cp5;
Slider s1, s2;
Info info;
CallbackListener cb;
void setup() {
size(800, 400);
cp5 = new ControlP5(this);
// create a new instance of class Info
// info will be used to display a controller's information and
// will fade in when a CallbackEvent is invoked.
info = new Info();
// add 2 sliders
s1 = cp5.addSlider("hello")
.setRange(0, 100)
.setValue(50)
.setPosition(40, 40)
.setSize(100, 20);
s2 = cp5.addSlider("world")
.setRange(0, 100)
.setValue(10)
.setPosition(40, 70)
.setSize(100, 20);
// the following CallbackListener will listen to any controlP5
// action such as enter, leave, pressed, released, releasedoutside, broadcast
// see static variables starting with ACTION_ inside class controlP5.ControlP5Constants
cb = new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
switch(theEvent.getAction()) {
case(ControlP5.ACTION_ENTER):
info.n = 1;
info.label.setText(theEvent.getController().getInfo());
cursor(HAND);
break;
case(ControlP5.ACTION_LEAVE):
case(ControlP5.ACTION_RELEASEDOUTSIDE):
info.n = 0;
cursor(ARROW);
break;
}
}
};
// add the above callback to controlP5
cp5.addCallback(cb);
// add another callback to slider s1, callback event will only be invoked for this
// particular controller.
s1.addCallback(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
if (theEvent.getAction()==ControlP5.ACTION_BROADCAST) {
s2.setValue(s2.getMax() - s1.getValue());
}
}
}
);
}
void draw() {
background(0);
info.update();
}
void controlEvent(ControlEvent theEvent) {
println("Got a ControlEvent for "+theEvent.name()+" = "+theEvent.value());
info.label.setText(theEvent.getController().getInfo());
}
void keyPressed() {
// uncomment the line below to remove callback cb from controlP5
// when a key is pressed.
//controlP5.removeCallback(cb);
}
// controlEvent(CallbackEvent) is called whenever a callback
// has been triggered. controlEvent(CallbackEvent) is detected by
// controlP5 automatically.
void controlEvent(CallbackEvent theEvent) {
if (theEvent.getController().equals(s2)) {
switch(theEvent.getAction()) {
case(ControlP5.ACTION_ENTER):
println("Action:ENTER");
break;
case(ControlP5.ACTION_LEAVE):
println("Action:LEAVE");
break;
case(ControlP5.ACTION_PRESSED):
println("Action:PRESSED");
break;
case(ControlP5.ACTION_RELEASED):
println("Action:RELEASED");
break;
case(ControlP5.ACTION_RELEASEDOUTSIDE):
println("Action:RELEASED OUTSIDE");
break;
case(ControlP5.ACTION_BROADCAST):
println("Action:BROADCAST");
break;
}
}
}
class Info {
float a;
float n = 0;
String txt = "";
Textarea label;
Info() {
label = cp5.addTextarea("Hello\nWorld")
.setSize(200,200)
.setPosition(300,40)
.setColor(color(255))
.setColorBackground(color(100,0))
.setLineHeight(12);
}
void update() {
a += (n-a)*0.1;
label.setColorBackground(color(100,255*a));
}
}
/*
a list of all methods available for the CallbackEvent Controller
use ControlP5.printPublicMethodsFor(CallbackEvent.class);
to print the following list into the console.
You can find further details about class CallbackEvent in the javadoc.
Format:
ClassName : returnType methodName(parameter type)
controlP5.CallbackEvent : Controller getController()
controlP5.CallbackEvent : int getAction()
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">
<!-- ========== 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>int</code></td>
<td class="colLast"><code><strong><a href="../controlP5/CallbackEvent.html#getAction()">getAction</a></strong>()</code>&nbsp;</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/CallbackEvent.html#getController()">getController</a></strong>()</code>
<div class="block">Returns the Controller that triggered the Callback Event.</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">
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="getAction()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getAction</h4>
<pre>public&nbsp;int&nbsp;getAction()</pre>
<dl><dt><span class="strong">Returns:</span></dt><dd>int Returns an int value of either one of the following static variables
ControlP5.ACTION_PRESSED, ControlP5.ACTION_ENTER, ControlP5.ACTION_LEAVE,
ControlP5.ACTION_RELEASED, ControlP5.ACTION_RELEASEDOUTSIDE,
ControlP5.ACTION_BROADCAST</dd></dl>
</li>
</ul>
<a name="getController()">
<!-- -->
</a>
<ul class="blockListLast">
<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 that triggered the Callback Event.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>Controller</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/Button.html" title="class in controlP5"><span class="strong">Prev Class</span></a></li>
<li><a href="../controlP5/CallbackListener.html" title="interface in controlP5"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../index.html?controlP5/CallbackEvent.html" target="_top">Frames</a></li>
<li><a href="CallbackEvent.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>Constr&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>Constr&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>