public void InitNumberBox() { // Initialize number box conf_KP = controlP5 .addNumberbox("KP") .setPosition(550, 50) .setColorBackground(c_red) .setSize(60, 18) .setRange(0, 250) // .setScrollSensitivity(5.1)//? .setMultiplier(1) // set the sensitifity of the numberbox .setDirection(Controller.HORIZONTAL); // change the control direction to left/right conf_KI = controlP5 .addNumberbox("KI") .setPosition(550, 90) .setColorBackground(c_red) .setSize(60, 18) .setRange(0, 250) .setMultiplier(1) // set the sensitifity of the numberbox .setDirection(Controller.HORIZONTAL); // change the control direction to left/right conf_KD = controlP5 .addNumberbox("KD") .setPosition(550, 130) .setColorBackground(c_red) .setSize(60, 18) .setRange(0, 250) .setMultiplier(1) // set the sensitifity of the numberbox .setDirection(Controller.HORIZONTAL); // change the control direction to left/right }
public void setup() { size(800, 600); background(255); // Local variables to set where the components will be int margin = 16; int spacing = 36; int w = 128; int h = 32; // Initialize ControlP5 controlP5 = new ControlP5(this); // Set the color of the labels controlP5.setColorLabel(color(255, 0, 0)); // Add components controlP5.addButton("Clear Screen", 1, margin, spacing, w, h); controlP5.addSlider("Leaf Red", 0, 255, 255, margin, spacing * 2, w, h); controlP5.addSlider("Leaf Green", 0, 255, 64, margin, spacing * 3, w, h); controlP5.addSlider("Leaf Blue", 0, 255, 0, margin, spacing * 4, w, h); controlP5.addSlider("Branch Random", 0, PI, PI / 4, margin, spacing * 5, w, h); controlP5.addSlider("Leaf Random", 0, 32, 16, margin, spacing * 6, w, h); controlP5.addSlider("Leaf Size", 0, 32, 16, margin, spacing * 7, w, h); controlP5.addSlider("Start Size", 0, 128, 64, margin, spacing * 8, w, h); }
public void InitButton() { // Set zero acc e gyro controlP5 .addButton("SET_ZERO") // .setValue(0) .setPosition(450, 50) .setSize(60, 20) .setColorBackground(c_blue); // Read PID parameter controlP5 .addButton("READ_PID") // .setValue(0) .setPosition(450, 90) .setSize(60, 20) .setColorBackground(c_blue); // Write PID parameter controlP5 .addButton("WRITE_PID") // .setValue(0) .setPosition(450, 130) .setSize(60, 20) .setColorBackground(c_blue); // Write PID parameter controlP5 .addButton("SAVE_PID") // .setValue(0) .setPosition(450, 170) .setSize(60, 20) .setColorBackground(c_blue); /* // START controlP5.addButton("START") .setPosition(650,50) .setSize(60,20) .setColorBackground(c_blue) ; // STOP controlP5.addButton("STOP") .setPosition(650,90) .setSize(60,20) .setColorBackground(c_blue) ; */ }
private void invokeField(final Object theObject, final Field theField, final Object theParam) { try { theField.set(theObject, theParam); } catch (IllegalAccessException e) { ControlP5.logger().warning(e.toString()); } }
public Tooltip unregister(String theControllerName) { Controller<?> c = cp5.getController(theControllerName); if (c == null) { return this; } return unregister(c); }
/** @exclude {@inheritDoc} */ @ControlP5.Invisible public void controlEvent(ControlEvent theEvent) { if (theEvent.getController() instanceof Button) { try { _myValue = theEvent.getController().getValue(); ControlEvent myEvent = new ControlEvent(this); if (pulldown) { close(); setLabel(theEvent.getController().getLabel()); } for (ControlListener cl : _myControlListener) { cl.controlEvent(myEvent); } cp5.getControlBroadcaster().broadcast(myEvent, ControlP5Constants.FLOAT); theEvent.getController().onLeave(); theEvent.getController().setIsInside(false); theEvent.getController().setMouseOver(false); } catch (Exception e) { ControlP5.logger().warning("ListBox.controlEvent exception:" + e); } } else { _myScrollValue = -(1 - theEvent.getValue()); scroll(); } }
/* * (non-Javadoc) */ public void windowActivated(WindowEvent e) { isLoop = true; loop(); try { controlP5.deactivateControllers(); } catch (NullPointerException nullPointer) { } }
public Tooltip register(String theControllerName, String theText) { Controller<?> c = cp5.getController(theControllerName); if (c == null) { return this; } map.put(c, theText); c.registerProperty("setTooltipEnabled", "isTooltipEnabled"); return this; }
private void printSecurityWarning(Exception e) { // AccessControlException required for applets. if (e.getClass().equals(AccessControlException.class)) { ControlP5.isApplet = true; ControlP5.logger() .warning( "You are probably running in applet mode.\n" + "make sure fields and methods in your code are public.\n" + e); } }
// hide and show controls public void hideControls() { if (keyPressed && (key == ' ')) { cp5.show(); // stats and controls fill(0, 100); noStroke(); rect(0, 0, 300, 300); fill(255); textSize(25); text("windSpeed: " + String.format("%.2f", wind), 10, 150); text("people: " + peopleLength, 10, 180); text("behaviors: " + physics.behaviors.size(), 10, 210); text("circles: " + circles.size(), 10, 240); text("framerate: " + frameRate, 10, 270); } else { cp5.hide(); } }
private void printMethodError(Method theMethod, Exception theException) { if (!ignoreErrorMessage) { ControlP5.logger() .severe( "An error occured while forwarding a Controller event, please check your code at " + theMethod.getName() + (!setPrintStackTrace ? " " + "exception: " + theException : "")); if (setPrintStackTrace) { theException.printStackTrace(); } } }
// use this function to calibrate force coefficients in real time public void controllers() { cp5 = new ControlP5(this); // slider control for gravity cp5.addSlider("gravY") .setPosition(10, height - 60) .setRange(0.0f, 0.2f) .setSize(200, 10) .setColorCaptionLabel(0) .setCaptionLabel("gravity"); // slider control for drag cp5.addSlider("drag") .setPosition(10, height - 50) .setRange(0.0f, 0.2f) .setSize(200, 10) .setColorCaptionLabel(0); // slider control for attractor strength cp5.addSlider("attStrength") .setPosition(10, height - 35) .setRange(0.0f, 0.2f) .setSize(200, 10) .setColorCaptionLabel(0); // slider control for max wind speed cp5.addSlider("maxWind") .setPosition(10, height - 10) .setRange(0.0f, 0.25f) .setSize(200, 10) .setColorCaptionLabel(0); // background color cp = cp5.addColorPicker("picker") .setPosition(10, 65) .setColorValue(color(0xff40B785, 255)) .hideBar(); }
public void InitSlider() { // Initialize slider plot int posX = 330; int posY = 50; AccSlider = controlP5 .addSlider("Acc_RAW") .setPosition(posX, posY) .setSize(20, 100) .setRange(0, 1023) .setValue(0) .lock() .setColorBackground(c_blue); GyroSlider = controlP5 .addSlider("Gyro_RAW") .setPosition(posX + 50, posY) .setSize(20, 100) .setRange(0, 1023) .setValue(0) .lock() .setColorBackground(c_blue); }
public void setup() { size(1024, 768); background(0); frameRate(30); smooth(); drawVectors = false; paused = true; timeline = new Timeline(); sim = new GravitySimulation(); sun = new Star(5000, 25, new PVector(300, 500), new PVector(0, 0), 0, "sun"); planet = new Planet(10, 10, new PVector(500, 500), new PVector(0, 40), "planet"); planet2 = new Planet(50, 10, new PVector(150, 500), new PVector(0, -40), "planet2"); timeline.registerStatefulObject(sun); timeline.registerStatefulObject(planet); timeline.registerStatefulObject(planet2); controlP5 = new ControlP5(this); btnRewind = controlP5.addButton("btnRewind_OnClick", 0, 800, 20, 50, 20); btnRewind.setLabel("Rewind"); btnPlayPause = controlP5.addButton("btnPlayPause_OnClick", 0, 860, 20, 50, 20); btnPlayPause.setLabel("Play"); btnFastForward = controlP5.addButton("btnFastForward_OnClick", 0, 920, 20, 80, 20); btnFastForward.setLabel("Fast Forward"); sliderTimeline = controlP5.addSlider("sliderTimeline_OnClick", 0, 10000, 0, 20, 720, 900, 10); sliderTimeline.setLabel("Timeline"); }
/** * @exclude * @param theIndex */ public RadioButton toggle(int theIndex) { // TODO // boolean itemState = ((Toggle) // _myRadioToggles.get(theIndex)).getState(); // if (theIndex < _myRadioToggles.size()) { // Toggle t = ((Toggle) _myRadioToggles.get(theIndex)); // if (t.isActive) { // t.deactivate(); // _myValue = -1; // updateValues(true); // } // } ControlP5.logger().info("toggle() not yet implemented, working on it."); return this; }
public void GUISetup() { // set up GUI String[] outputs = MidiBus.availableOutputs(); String[] inputs = MidiBus.availableInputs(); controlP5 = new ControlP5(this); programlabel = controlP5.addTextlabel("programlabel", "Programs", 350, 65); Radio programs = controlP5.addRadio("programs", 350, 80); programs.deactivateAll(); programs.add("on", 1); programs.add("off", 2); programs.add("oscillate", 0); programs.add("fade", 4); programs.add("random", 3); midioutlabel = controlP5.addTextlabel("midioutlabel", "MIDI Outputs", 200, 65); Radio midioutdevices = controlP5.addRadio("midioutdevices", 200, 80); midioutdevices.deactivateAll(); for (int i = 0; i < (outputs.length - 1); i++) { midioutdevices.add(outputs[i], i); } midiinlabel = controlP5.addTextlabel("midiinlabel", "MIDI Inputs", 100, 65); Radio midiindevices = controlP5.addRadio("midiindevices", 100, 80); midiindevices.deactivateAll(); for (int i = 0; i < (inputs.length - 1); i++) { midiindevices.add(inputs[i], i); } options = controlP5.addTextlabel("options", "Options", 10, 65); optionsbox = controlP5.addCheckBox("optionsbox", 10, 80); optionsbox.setItemsPerRow(3); optionsbox.setSpacingColumn(30); optionsbox.setSpacingRow(10); optionsbox.addItem("notes -> cc", 0); heading = controlP5.addTextlabel("heading", "grmnygrmny.lightarray", 200, 20); }
/* * (non-Javadoc) */ public void setup() { try { Thread.sleep(100); } catch (Exception e) { } if (_myRenderer.length() == 0) { size(width, height); } else { size(width, height, _myRenderer); ControlP5.logger().finer("ControlWindow: using renderer " + _myRenderer); } try { Thread.sleep(100); } catch (Exception e) { } frameRate(_myFrameRate); }
public void InitComDropdown() { // Initialize portCommList int posX = 20; int posY = 70; PortsList = controlP5.addDropdownList("portComList", posX, posY, 100, 84); // Set the background color of the list (you wont see this though). PortsList.setBackgroundColor(color(200)); // Set the height of each item when the list is opened. PortsList.setItemHeight(20); // Set the height of the bar itself. PortsList.setBarHeight(15); // Set the lable of the bar when nothing is selected. PortsList.captionLabel().set("Select COM port"); // Set the top margin of the lable. PortsList.captionLabel().style().marginTop = 3; // Set the left margin of the lable. PortsList.captionLabel().style().marginLeft = 3; // Set the top margin of the value selected. PortsList.valueLabel().style().marginTop = 3; // Store the Serial ports in the string comList (char array). comList = serial.list(); // We need to know how many ports there are, to know how many items to add to the list, so we // will convert it to a String object (part of a class). String comlist = join(comList, ","); // We also need how many characters there is in a single port name, we\u00b4ll store the chars // here for counting later. String COMlist = comList[0]; // Here we count the length of each port name. int size2 = COMlist.length(); // Now we can count how many ports there are, well that is count how many chars there are, so we // will divide by the amount of chars per port name. int size1 = comlist.length() / size2; // Now well add the ports to the list, we use a for loop for that. How many items is determined // by the value of size1. for (int i = 0; i < size1; i++) { // This is the line doing the actual adding of items, we use the current loop we are in to // determin what place in the char array to access and what item number to add it as. PortsList.addItem(comList[i], i); } // Set the color of the background of the items and the bar. PortsList.setColorBackground(color(60)); // Set the color of the item your mouse is hovering over. PortsList.setColorActive(color(255, 128)); }
private void invokeMethod( final Object theObject, final Method theMethod, final Object[] theParam) { try { if (theParam[0] == null) { theMethod.invoke(theObject, new Object[0]); } else { theMethod.invoke(theObject, theParam); } } catch (IllegalArgumentException e) { ControlP5.logger().warning(e.toString()); /** TODO thrown when plugging a String method/field. */ } catch (IllegalAccessException e) { printMethodError(theMethod, e); } catch (InvocationTargetException e) { printMethodError(theMethod, e); } catch (NullPointerException e) { printMethodError(theMethod, e); } }
/** * Removes an item from the ListBox using the unique name of the item given when added to the * list. * * @see controlP5.ListBox#addItem(String,int) * @param theItemName String */ public ListBox removeItem(String theItemName) { try { for (int i = items.size() - 1; i >= 0; i--) { if ((items.get(i)).name.equals(theItemName)) { items.remove(i); } } if ((buttons.size()) > items.size()) { String buttonName = ((Button) controllers.get(buttons.size())).getName(); buttons.remove(cp5.getController(buttonName)); controllers.remove(cp5.getController(buttonName)); cp5.remove(buttonName); } updateScroll(); } catch (Exception e) { ControlP5.logger().finer("ScrollList.removeItem exception:" + e); } return this; }
/** removes the group from controlP5. */ public void remove() { _myControlWindow.removeMouseOverFor(this); if (_myParent != null) { _myParent.remove(this); } if (cp5 != null) { cp5.remove(this); } for (int i = controllers.size() - 1; i >= 0; i--) { controllers.get(i).remove(); } controllers.clear(); controllers.clearDrawable(); controllers = new ControllerList(); if (this instanceof Tab) { _myControlWindow.removeTab((Tab) this); } }
public Controller<?> getController(String theController) { return cp5.getController(theController); }
public void set( final Object theObject, final String theName, final int theType, final int theParameterType, final Class<?>[] theAcceptClassList) { _myObject = theObject; _myName = theName; _myType = theType; _myParameterType = theParameterType; _myAcceptClassList = theAcceptClassList; Class<?> myClass = theObject.getClass(); /* check for methods */ if (_myType == ControlP5Constants.METHOD) { try { Method[] myMethods = myClass.getDeclaredMethods(); for (int i = 0; i < myMethods.length; i++) { if ((myMethods[i].getName()).equals(theName)) { if (myMethods[i].getParameterTypes().length == 1) { for (int j = 0; j < _myAcceptClassList.length; j++) { if (myMethods[i].getParameterTypes()[0] == _myAcceptClassList[j]) { _myParameterClass = myMethods[i].getParameterTypes()[0]; break; } } } else if (myMethods[i].getParameterTypes().length == 0) { _myParameterClass = null; break; } break; } } Class<?>[] myArgs = (_myParameterClass == null) ? new Class[] {} : new Class[] {_myParameterClass}; _myMethod = myClass.getDeclaredMethod(_myName, myArgs); _myMethod.setAccessible(true); } catch (SecurityException e) { printSecurityWarning(e); } catch (NoSuchMethodException e) { if (_myParameterClass != CallbackEvent.class) { ControlP5.logger() .warning( " plug() failed. If function " + theName + " does exist, make it public. " + e); } } /* check for controlEvent */ } else if (_myType == ControlP5Constants.EVENT) { try { _myMethod = _myObject.getClass().getMethod(_myName, new Class[] {_myEventMethodParameter}); _myMethod.setAccessible(true); _myParameterClass = _myEventMethodParameter; } catch (SecurityException e) { printSecurityWarning(e); } catch (NoSuchMethodException e) { if (_myEventMethodParameter != CallbackEvent.class) { ControlP5.logger() .warning( " plug() failed " + _myParameterClass + ". If function " + theName + " does exist, make it public. " + e); } } /* check for fields */ } else if (_myType == ControlP5Constants.FIELD) { Field[] myFields = ControlBroadcaster.getFieldsFor(myClass); for (int i = 0; i < myFields.length; i++) { if (myFields[i].getName().equals(_myName)) { _myParameterClass = myFields[i].getType(); } } if (_myParameterClass != null) { /** * note. when running in applet mode. for some reason setAccessible(true) works for methods * but not for fields. theAccessControlException is thrown. therefore, make fields in your * code public. */ try { _myField = myClass.getDeclaredField(_myName); try { _myField.setAccessible(true); } catch (java.security.AccessControlException e) { printSecurityWarning(e); } try { _myValue = (_myField.get(theObject)); } catch (Exception ex) { printSecurityWarning(ex); } } catch (NoSuchFieldException e) { ControlP5.logger().warning(e.toString()); } } } }
/** {@inheritDoc} */ public ControllerProperty getProperty(String theSetter, String theGetter) { return cp5.getProperties().getProperty(this, theSetter, theGetter); }
/** {@inheritDoc} */ public ControllerProperty getProperty(String thePropertyName) { return cp5.getProperties().getProperty(this, thePropertyName); }
public void setup() { size(800, 500); ball = new Ball(width / 2, height / 2, new PVector(5, 5)); rectMode(CENTER); paddles = new Paddle[2]; paddles[0] = new Paddle(width - 40, 20); paddles[1] = new Paddle(40, 20); setupContext(); skeleton = new TSSkeleton(); cp5 = new ControlP5(this); // cp5.addBang("restart").setPosition(350, 10).setSize(10, 10); d1 = cp5.addDropdownList("paddle1").setPosition(width - 150, 20); d2 = cp5.addDropdownList("paddle2").setPosition(50, 20); d3 = cp5.addDropdownList("1_or_2_player").setPosition(150, 20); d4 = cp5.addDropdownList("speed").setPosition(250, 20); jointNames = loadStrings("joints.txt"); d4.addItem("slow", 0); d4.addItem("fast", 1); d4.addItem("Jeez-us", 2); for (int i = 0; i < jointNames.length; i++) { d1.addItem(jointNames[i], i); d2.addItem(jointNames[i], i); } d3.addItem("one player", 0); d3.addItem("two players", 1); smooth(); println("SimpleOpenNI.SKEL_HEAD " + SimpleOpenNI.SKEL_HEAD); println("SimpleOpenNI.SKEL_LEFT_ANKLE " + SimpleOpenNI.SKEL_LEFT_ANKLE); println("SimpleOpenNI.SKEL_LEFT_COLLAR " + SimpleOpenNI.SKEL_LEFT_COLLAR); println("SimpleOpenNI.SKEL_LEFT_ELBOW " + SimpleOpenNI.SKEL_LEFT_ELBOW); println("SimpleOpenNI.SKEL_LEFT_FINGERTIP " + SimpleOpenNI.SKEL_LEFT_FINGERTIP); println("SimpleOpenNI.SKEL_LEFT_FOOT " + SimpleOpenNI.SKEL_LEFT_FOOT); println("SimpleOpenNI.SKEL_LEFT_HAND " + SimpleOpenNI.SKEL_LEFT_HAND); println("SimpleOpenNI.SKEL_LEFT_HIP " + SimpleOpenNI.SKEL_LEFT_HIP); println("SimpleOpenNI.SKEL_LEFT_KNEE " + SimpleOpenNI.SKEL_LEFT_KNEE); println("SimpleOpenNI.SKEL_LEFT_SHOULDER " + SimpleOpenNI.SKEL_LEFT_SHOULDER); println("SimpleOpenNI.SKEL_LEFT_WRIST " + SimpleOpenNI.SKEL_LEFT_WRIST); println("SimpleOpenNI.SKEL_NECK " + SimpleOpenNI.SKEL_NECK); println("SimpleOpenNI.SKEL_RIGHT_ANKLE " + SimpleOpenNI.SKEL_RIGHT_ANKLE); println("SimpleOpenNI.SKEL_RIGHT_COLLAR " + SimpleOpenNI.SKEL_RIGHT_COLLAR); println("SimpleOpenNI.SKEL_RIGHT_ELBOW " + SimpleOpenNI.SKEL_RIGHT_ELBOW); println("SimpleOpenNI.SKEL_RIGHT_FINGERTIP " + SimpleOpenNI.SKEL_RIGHT_FINGERTIP); println("SimpleOpenNI.SKEL_RIGHT_FOOT " + SimpleOpenNI.SKEL_RIGHT_FOOT); println("SimpleOpenNI.SKEL_RIGHT_HAND " + SimpleOpenNI.SKEL_RIGHT_HAND); println("SimpleOpenNI.SKEL_RIGHT_HIP " + SimpleOpenNI.SKEL_RIGHT_HIP); println("SimpleOpenNI.SKEL_RIGHT_KNEE " + SimpleOpenNI.SKEL_RIGHT_KNEE); println("SimpleOpenNI.SKEL_RIGHT_SHOULDER " + SimpleOpenNI.SKEL_RIGHT_SHOULDER); println("SimpleOpenNI.SKEL_RIGHT_WRIST " + SimpleOpenNI.SKEL_RIGHT_WRIST); println("SimpleOpenNI.SKEL_TORSO " + SimpleOpenNI.SKEL_TORSO); println("SimpleOpenNI.SKEL_WAIST " + SimpleOpenNI.SKEL_WAIST); translations = new int[jointNames.length]; translations[0] = 1; translations[1] = 19; translations[2] = 5; translations[3] = 7; translations[4] = 10; translations[5] = 20; translations[6] = 9; translations[7] = 17; translations[8] = 18; translations[9] = 6; translations[10] = 8; translations[11] = 2; translations[12] = 23; translations[13] = 11; translations[14] = 13; translations[15] = 16; translations[16] = 24; translations[17] = 15; translations[18] = 21; translations[19] = 22; translations[20] = 12; translations[21] = 14; translations[22] = 3; translations[23] = 4; font = loadFont("AlBayan-48.vlw"); textFont(font, 48); }
/** * Convenience constructor to extend RadioButton. * * @example use/ControlP5extendController * @param theControlP5 * @param theName */ public RadioButton(ControlP5 theControlP5, String theName) { this(theControlP5, theControlP5.getDefaultTab(), theName, 0, 0); theControlP5.register(theControlP5.papplet, theName, this); }
/** {@inheritDoc} */ public T registerProperty(String thePropertyName) { cp5.getProperties().register(this, thePropertyName); return me; }
/** * Convenience constructor to extend Toggle. * * @example use/ControlP5extendController * @param theControlP5 * @param theName */ public Toggle(ControlP5 theControlP5, String theName) { this(theControlP5, theControlP5.getDefaultTab(), theName, 0, 0, 0, autoWidth, autoHeight); theControlP5.register(theControlP5.papplet, theName, this); }
/** {@inheritDoc} */ public T registerProperty(String theSetter, String theGetter) { cp5.getProperties().register(this, theSetter, theGetter); return me; }