|
| 1 | +load_library :controlP5 |
| 2 | +java_import 'controlP5.ControlP5' |
| 3 | +java_import 'controlP5.ControlListener' |
| 4 | +java_import 'controlP5.ScrollableList' |
| 5 | + |
| 6 | +include ControlListener |
| 7 | +VALUES = ('a'..'h').to_a |
| 8 | + |
| 9 | +# |
| 10 | +# ControlP5 ScrollableList |
| 11 | +# |
| 12 | +# replaces DropdownList and and ListBox. |
| 13 | +# List can be scrolled by dragging the list or using the scroll-wheel. |
| 14 | +# |
| 15 | +# by Andreas Schlegel, 2014 |
| 16 | +# www.sojamo.de/libraries/controlp5 |
| 17 | +# |
| 18 | +# |
| 19 | +attr_reader :cp5 |
| 20 | + |
| 21 | +def setup |
| 22 | + @cp5 = ControlP5.new(self) |
| 23 | + # add a ScrollableList, by default it behaves like a DropdownList |
| 24 | + cp5.addScrollableList("dropdown") |
| 25 | + .setPosition(100, 100) |
| 26 | + .setSize(200, 100) |
| 27 | + .setBarHeight(20) |
| 28 | + .setItemHeight(20) |
| 29 | + .addItems(VALUES) |
| 30 | + # .setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST |
| 31 | +end |
| 32 | + |
| 33 | +def draw |
| 34 | + background(240) |
| 35 | +end |
| 36 | + |
| 37 | +# def dropdown(n) |
| 38 | +# # request the selected item based on index n */ |
| 39 | +# puts("#{n}, #{cp5.get(ScrollableList.class, 'dropdown').getItem(n)}") |
| 40 | +# # here an item is stored as a Map with the following key-value pairs: |
| 41 | +# # name, the given name of the item |
| 42 | +# # text, the given text of the item by default the same as name |
| 43 | +# # value, the given value of the item, can be changed by using .getItem(n).put("value abc") a value here is of type Object therefore can be anything |
| 44 | +# # color, the given color of the item, how to change, see below |
| 45 | +# # view, a customizable view, is of type CDrawable |
| 46 | +# #/ |
| 47 | +# |
| 48 | +# c = CColor.new |
| 49 | +# c.setBackground(color(255,0,0)) |
| 50 | +# cp5.get(ScrollableList.class, "dropdown").getItem(n).put("color", c) |
| 51 | +# |
| 52 | +# end |
| 53 | +# |
| 54 | +# def key_pressed |
| 55 | +# case(key) |
| 56 | +# when '1' |
| 57 | +# # make the ScrollableList behave like a ListBox */ |
| 58 | +# cp5.get(ScrollableList.class, "dropdown").setType(ControlP5::LIST) |
| 59 | +# when '2' |
| 60 | +# # make the ScrollableList behave like a DropdownList */ |
| 61 | +# cp5.get(ScrollableList.class, "dropdown").setType(ControlP5::DROPDOWN) |
| 62 | +# when '3' |
| 63 | +# #change content of the ScrollableList */ |
| 64 | +# list = %w[a-1 b-1 c-1 d-1 e-1 f-1 g-1 h-1 i-1 j-1 k-1] |
| 65 | +# cp5.get(ScrollableList.class, "dropdown").setItems(list) |
| 66 | +# |
| 67 | +# when '4' |
| 68 | +# # remove an item from the ScrollableList */ |
| 69 | +# cp5.get(ScrollableList.class, "dropdown").removeItem("k-1") |
| 70 | +# |
| 71 | +# when '5' |
| 72 | +# # clear the ScrollableList */ |
| 73 | +# cp5.get(ScrollableList.class, "dropdown").clear() |
| 74 | +# |
| 75 | +# end |
| 76 | +# end |
| 77 | + |
| 78 | +# a list of all methods available for the ScrollableList Controller |
| 79 | +# use ControlP5.printPublicMethodsFor(ScrollableList.class) |
| 80 | +# to print the following list into the console. |
| 81 | +# |
| 82 | +# You can find further details about class ScrollableList in the javadoc. |
| 83 | +# |
| 84 | +# Format: |
| 85 | +# ClassName : returnType methodName(parameter type) |
| 86 | +# |
| 87 | +# |
| 88 | +# controlP5.Controller : CColor getColor() |
| 89 | +# controlP5.Controller : ControlBehavior getBehavior() |
| 90 | +# controlP5.Controller : ControlWindow getControlWindow() |
| 91 | +# controlP5.Controller : ControlWindow getWindow() |
| 92 | +# controlP5.Controller : ControllerProperty getProperty(String) |
| 93 | +# controlP5.Controller : ControllerProperty getProperty(String, String) |
| 94 | +# controlP5.Controller : ControllerView getView() |
| 95 | +# controlP5.Controller : Label getCaptionLabel() |
| 96 | +# controlP5.Controller : Label getValueLabel() |
| 97 | +# controlP5.Controller : List getControllerPlugList() |
| 98 | +# controlP5.Controller : Pointer getPointer() |
| 99 | +# controlP5.Controller : ScrollableList addCallback(CallbackListener) |
| 100 | +# controlP5.Controller : ScrollableList addListener(ControlListener) |
| 101 | +# controlP5.Controller : ScrollableList addListenerFor(int, CallbackListener) |
| 102 | +# controlP5.Controller : ScrollableList align(int, int, int, int) |
| 103 | +# controlP5.Controller : ScrollableList bringToFront() |
| 104 | +# controlP5.Controller : ScrollableList bringToFront(ControllerInterface) |
| 105 | +# controlP5.Controller : ScrollableList hide() |
| 106 | +# controlP5.Controller : ScrollableList linebreak() |
| 107 | +# controlP5.Controller : ScrollableList listen(boolean) |
| 108 | +# controlP5.Controller : ScrollableList lock() |
| 109 | +# controlP5.Controller : ScrollableList onChange(CallbackListener) |
| 110 | +# controlP5.Controller : ScrollableList onClick(CallbackListener) |
| 111 | +# controlP5.Controller : ScrollableList onDoublePress(CallbackListener) |
| 112 | +# controlP5.Controller : ScrollableList onDrag(CallbackListener) |
| 113 | +# controlP5.Controller : ScrollableList onDraw(ControllerView) |
| 114 | +# controlP5.Controller : ScrollableList onEndDrag(CallbackListener) |
| 115 | +# controlP5.Controller : ScrollableList onEnter(CallbackListener) |
| 116 | +# controlP5.Controller : ScrollableList onLeave(CallbackListener) |
| 117 | +# controlP5.Controller : ScrollableList onMove(CallbackListener) |
| 118 | +# controlP5.Controller : ScrollableList onPress(CallbackListener) |
| 119 | +# controlP5.Controller : ScrollableList onRelease(CallbackListener) |
| 120 | +# controlP5.Controller : ScrollableList onReleaseOutside(CallbackListener) |
| 121 | +# controlP5.Controller : ScrollableList onStartDrag(CallbackListener) |
| 122 | +# controlP5.Controller : ScrollableList onWheel(CallbackListener) |
| 123 | +# controlP5.Controller : ScrollableList plugTo(Object) |
| 124 | +# controlP5.Controller : ScrollableList plugTo(Object, String) |
| 125 | +# controlP5.Controller : ScrollableList plugTo(Object[]) |
| 126 | +# controlP5.Controller : ScrollableList plugTo(Object[], String) |
| 127 | +# controlP5.Controller : ScrollableList registerProperty(String) |
| 128 | +# controlP5.Controller : ScrollableList registerProperty(String, String) |
| 129 | +# controlP5.Controller : ScrollableList registerTooltip(String) |
| 130 | +# controlP5.Controller : ScrollableList removeBehavior() |
| 131 | +# controlP5.Controller : ScrollableList removeCallback() |
| 132 | +# controlP5.Controller : ScrollableList removeCallback(CallbackListener) |
| 133 | +# controlP5.Controller : ScrollableList removeListener(ControlListener) |
| 134 | +# controlP5.Controller : ScrollableList removeListenerFor(int, CallbackListener) |
| 135 | +# controlP5.Controller : ScrollableList removeListenersFor(int) |
| 136 | +# controlP5.Controller : ScrollableList removeProperty(String) |
| 137 | +# controlP5.Controller : ScrollableList removeProperty(String, String) |
| 138 | +# controlP5.Controller : ScrollableList setArrayValue(float[]) |
| 139 | +# controlP5.Controller : ScrollableList setArrayValue(int, float) |
| 140 | +# controlP5.Controller : ScrollableList setBehavior(ControlBehavior) |
| 141 | +# controlP5.Controller : ScrollableList setBroadcast(boolean) |
| 142 | +# controlP5.Controller : ScrollableList setCaptionLabel(String) |
| 143 | +# controlP5.Controller : ScrollableList setColor(CColor) |
| 144 | +# controlP5.Controller : ScrollableList setColorActive(int) |
| 145 | +# controlP5.Controller : ScrollableList setColorBackground(int) |
| 146 | +# controlP5.Controller : ScrollableList setColorCaptionLabel(int) |
| 147 | +# controlP5.Controller : ScrollableList setColorForeground(int) |
| 148 | +# controlP5.Controller : ScrollableList setColorLabel(int) |
| 149 | +# controlP5.Controller : ScrollableList setColorValue(int) |
| 150 | +# controlP5.Controller : ScrollableList setColorValueLabel(int) |
| 151 | +# controlP5.Controller : ScrollableList setDecimalPrecision(int) |
| 152 | +# controlP5.Controller : ScrollableList setDefaultValue(float) |
| 153 | +# controlP5.Controller : ScrollableList setHeight(int) |
| 154 | +# controlP5.Controller : ScrollableList setId(int) |
| 155 | +# controlP5.Controller : ScrollableList setImage(PImage) |
| 156 | +# controlP5.Controller : ScrollableList setImage(PImage, int) |
| 157 | +# controlP5.Controller : ScrollableList setImages(PImage, PImage, PImage) |
| 158 | +# controlP5.Controller : ScrollableList setImages(PImage, PImage, PImage, PImage) |
| 159 | +# controlP5.Controller : ScrollableList setLabel(String) |
| 160 | +# controlP5.Controller : ScrollableList setLabelVisible(boolean) |
| 161 | +# controlP5.Controller : ScrollableList setLock(boolean) |
| 162 | +# controlP5.Controller : ScrollableList setMax(float) |
| 163 | +# controlP5.Controller : ScrollableList setMin(float) |
| 164 | +# controlP5.Controller : ScrollableList setMouseOver(boolean) |
| 165 | +# controlP5.Controller : ScrollableList setMoveable(boolean) |
| 166 | +# controlP5.Controller : ScrollableList setPosition(float, float) |
| 167 | +# controlP5.Controller : ScrollableList setPosition(float[]) |
| 168 | +# controlP5.Controller : ScrollableList setSize(PImage) |
| 169 | +# controlP5.Controller : ScrollableList setSize(int, int) |
| 170 | +# controlP5.Controller : ScrollableList setStringValue(String) |
| 171 | +# controlP5.Controller : ScrollableList setUpdate(boolean) |
| 172 | +# controlP5.Controller : ScrollableList setValue(float) |
| 173 | +# controlP5.Controller : ScrollableList setValueLabel(String) |
| 174 | +# controlP5.Controller : ScrollableList setValueSelf(float) |
| 175 | +# controlP5.Controller : ScrollableList setView(ControllerView) |
| 176 | +# controlP5.Controller : ScrollableList setVisible(boolean) |
| 177 | +# controlP5.Controller : ScrollableList setWidth(int) |
| 178 | +# controlP5.Controller : ScrollableList show() |
| 179 | +# controlP5.Controller : ScrollableList unlock() |
| 180 | +# controlP5.Controller : ScrollableList unplugFrom(Object) |
| 181 | +# controlP5.Controller : ScrollableList unplugFrom(Object[]) |
| 182 | +# controlP5.Controller : ScrollableList unregisterTooltip() |
| 183 | +# controlP5.Controller : ScrollableList update() |
| 184 | +# controlP5.Controller : ScrollableList updateSize() |
| 185 | +# controlP5.Controller : String getAddress() |
| 186 | +# controlP5.Controller : String getInfo() |
| 187 | +# controlP5.Controller : String getName() |
| 188 | +# controlP5.Controller : String getStringValue() |
| 189 | +# controlP5.Controller : String toString() |
| 190 | +# controlP5.Controller : Tab getTab() |
| 191 | +# controlP5.Controller : boolean isActive() |
| 192 | +# controlP5.Controller : boolean isBroadcast() |
| 193 | +# controlP5.Controller : boolean isInside() |
| 194 | +# controlP5.Controller : boolean isLabelVisible() |
| 195 | +# controlP5.Controller : boolean isListening() |
| 196 | +# controlP5.Controller : boolean isLock() |
| 197 | +# controlP5.Controller : boolean isMouseOver() |
| 198 | +# controlP5.Controller : boolean isMousePressed() |
| 199 | +# controlP5.Controller : boolean isMoveable() |
| 200 | +# controlP5.Controller : boolean isUpdate() |
| 201 | +# controlP5.Controller : boolean isVisible() |
| 202 | +# controlP5.Controller : float getArrayValue(int) |
| 203 | +# controlP5.Controller : float getDefaultValue() |
| 204 | +# controlP5.Controller : float getMax() |
| 205 | +# controlP5.Controller : float getMin() |
| 206 | +# controlP5.Controller : float getValue() |
| 207 | +# controlP5.Controller : float[] getAbsolutePosition() |
| 208 | +# controlP5.Controller : float[] getArrayValue() |
| 209 | +# controlP5.Controller : float[] getPosition() |
| 210 | +# controlP5.Controller : int getDecimalPrecision() |
| 211 | +# controlP5.Controller : int getHeight() |
| 212 | +# controlP5.Controller : int getId() |
| 213 | +# controlP5.Controller : int getWidth() |
| 214 | +# controlP5.Controller : int listenerSize() |
| 215 | +# controlP5.Controller : void remove() |
| 216 | +# controlP5.Controller : void setView(ControllerView, int) |
| 217 | +# controlP5.ScrollableList : List getItems() |
| 218 | +# controlP5.ScrollableList : Map getItem(String) |
| 219 | +# controlP5.ScrollableList : Map getItem(int) |
| 220 | +# controlP5.ScrollableList : ScrollableList addItem(String, Object) |
| 221 | +# controlP5.ScrollableList : ScrollableList addItems(List) |
| 222 | +# controlP5.ScrollableList : ScrollableList addItems(Map) |
| 223 | +# controlP5.ScrollableList : ScrollableList addItems(String[]) |
| 224 | +# controlP5.ScrollableList : ScrollableList clear() |
| 225 | +# controlP5.ScrollableList : ScrollableList close() |
| 226 | +# controlP5.ScrollableList : ScrollableList open() |
| 227 | +# controlP5.ScrollableList : ScrollableList removeItem(String) |
| 228 | +# controlP5.ScrollableList : ScrollableList removeItems(List) |
| 229 | +# controlP5.ScrollableList : ScrollableList setBackgroundColor(int) |
| 230 | +# controlP5.ScrollableList : ScrollableList setBarHeight(int) |
| 231 | +# controlP5.ScrollableList : ScrollableList setBarVisible(boolean) |
| 232 | +# controlP5.ScrollableList : ScrollableList setItemHeight(int) |
| 233 | +# controlP5.ScrollableList : ScrollableList setItems(List) |
| 234 | +# controlP5.ScrollableList : ScrollableList setItems(Map) |
| 235 | +# controlP5.ScrollableList : ScrollableList setItems(String[]) |
| 236 | +# controlP5.ScrollableList : ScrollableList setOpen(boolean) |
| 237 | +# controlP5.ScrollableList : ScrollableList setScrollSensitivity(float) |
| 238 | +# controlP5.ScrollableList : ScrollableList setType(int) |
| 239 | +# controlP5.ScrollableList : boolean isBarVisible() |
| 240 | +# controlP5.ScrollableList : boolean isOpen() |
| 241 | +# controlP5.ScrollableList : int getBackgroundColor() |
| 242 | +# controlP5.ScrollableList : int getBarHeight() |
| 243 | +# controlP5.ScrollableList : int getHeight() |
| 244 | +# controlP5.ScrollableList : void controlEvent(ControlEvent) |
| 245 | +# controlP5.ScrollableList : void keyEvent(KeyEvent) |
| 246 | +# controlP5.ScrollableList : void setDirection(int) |
| 247 | +# controlP5.ScrollableList : void updateItemIndexOffset() |
| 248 | +# java.lang.Object : String toString() |
| 249 | +# java.lang.Object : boolean equals(Object) |
| 250 | +# |
| 251 | +# created: 2015/03/24 12:21:22 |
| 252 | +def listen(e) |
| 253 | + puts e |
| 254 | +end |
| 255 | + |
| 256 | +def controlEvent(event) |
| 257 | + if event.controller? |
| 258 | + if event.getController.getName =~ /dropdown/ |
| 259 | + puts event.getController.getName |
| 260 | + end |
| 261 | + end |
| 262 | +end |
| 263 | + |
| 264 | +def settings |
| 265 | + size(400, 400) |
| 266 | +end |
0 commit comments