picrate 0.0.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.mvn/extensions.xml +9 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE.md +165 -0
- data/README.md +51 -0
- data/Rakefile +59 -0
- data/bin/picrate +8 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +30 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +16 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_includes/navigation.html +24 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2018-05-06-getting_started.md +8 -0
- data/docs/_posts/2018-05-06-install_jruby.md +35 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +10 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/lib/picrate.rb +10 -0
- data/lib/picrate/app.rb +187 -0
- data/lib/picrate/creators/sketch_class.rb +57 -0
- data/lib/picrate/creators/sketch_factory.rb +12 -0
- data/lib/picrate/creators/sketch_writer.rb +21 -0
- data/lib/picrate/helper_methods.rb +214 -0
- data/lib/picrate/helpers/numeric.rb +9 -0
- data/lib/picrate/library.rb +69 -0
- data/lib/picrate/library_loader.rb +53 -0
- data/lib/picrate/native_folder.rb +35 -0
- data/lib/picrate/native_loader.rb +27 -0
- data/lib/picrate/runner.rb +81 -0
- data/lib/picrate/version.rb +4 -0
- data/library/boids/boids.rb +209 -0
- data/library/chooser/chooser.rb +19 -0
- data/library/control_panel/control_panel.rb +182 -0
- data/library/library_proxy/README.md +99 -0
- data/library/library_proxy/library_proxy.rb +14 -0
- data/library/slider/slider.rb +42 -0
- data/library/vector_utils/vector_utils.rb +69 -0
- data/library/video_event/video_event.rb +3 -0
- data/license.txt +508 -0
- data/picrate.gemspec +35 -0
- data/pom.rb +122 -0
- data/pom.xml +214 -0
- data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/main/java/monkstone/ColorUtil.java +115 -0
- data/src/main/java/monkstone/MathToolModule.java +236 -0
- data/src/main/java/monkstone/PicrateLibrary.java +47 -0
- data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
- data/src/main/java/monkstone/fastmath/package-info.java +6 -0
- data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
- data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
- data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
- data/src/main/java/monkstone/slider/Slider.java +67 -0
- data/src/main/java/monkstone/slider/SliderBar.java +277 -0
- data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
- data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
- data/src/main/java/monkstone/vecmath/JRender.java +56 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
- data/src/main/java/monkstone/vecmath/package-info.java +20 -0
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
- data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
- data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
- data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
- data/src/main/java/monkstone/videoevent/package-info.java +20 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
- data/src/main/java/processing/core/PApplet.java +17647 -0
- data/src/main/java/processing/core/PConstants.java +1033 -0
- data/src/main/java/processing/core/PFont.java +1250 -0
- data/src/main/java/processing/core/PGraphics.java +9614 -0
- data/src/main/java/processing/core/PImage.java +3608 -0
- data/src/main/java/processing/core/PMatrix.java +347 -0
- data/src/main/java/processing/core/PMatrix2D.java +694 -0
- data/src/main/java/processing/core/PMatrix3D.java +1153 -0
- data/src/main/java/processing/core/PShape.java +4332 -0
- data/src/main/java/processing/core/PShapeOBJ.java +544 -0
- data/src/main/java/processing/core/PShapeSVG.java +1987 -0
- data/src/main/java/processing/core/PStyle.java +208 -0
- data/src/main/java/processing/core/PSurface.java +242 -0
- data/src/main/java/processing/core/PSurfaceNone.java +479 -0
- data/src/main/java/processing/core/PVector.java +1140 -0
- data/src/main/java/processing/data/FloatDict.java +829 -0
- data/src/main/java/processing/data/FloatList.java +912 -0
- data/src/main/java/processing/data/IntDict.java +796 -0
- data/src/main/java/processing/data/IntList.java +913 -0
- data/src/main/java/processing/data/JSONArray.java +1260 -0
- data/src/main/java/processing/data/JSONObject.java +2282 -0
- data/src/main/java/processing/data/JSONTokener.java +435 -0
- data/src/main/java/processing/data/Sort.java +46 -0
- data/src/main/java/processing/data/StringDict.java +601 -0
- data/src/main/java/processing/data/StringList.java +775 -0
- data/src/main/java/processing/data/Table.java +4923 -0
- data/src/main/java/processing/data/TableRow.java +198 -0
- data/src/main/java/processing/data/XML.java +1149 -0
- data/src/main/java/processing/event/Event.java +108 -0
- data/src/main/java/processing/event/KeyEvent.java +70 -0
- data/src/main/java/processing/event/MouseEvent.java +149 -0
- data/src/main/java/processing/event/TouchEvent.java +57 -0
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
- data/src/main/java/processing/opengl/FontTexture.java +379 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
- data/src/main/java/processing/opengl/LinePath.java +623 -0
- data/src/main/java/processing/opengl/LineStroker.java +685 -0
- data/src/main/java/processing/opengl/PGL.java +3366 -0
- data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
- data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
- data/src/main/java/processing/opengl/PJOGL.java +1966 -0
- data/src/main/java/processing/opengl/PShader.java +1478 -0
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
- data/src/main/java/processing/opengl/Texture.java +1670 -0
- data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +27 -0
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/src/main/resources/license.txt +508 -0
- data/test/create_test.rb +68 -0
- data/test/deglut_spec_test.rb +24 -0
- data/test/helper_methods_test.rb +58 -0
- data/test/math_tool_test.rb +75 -0
- data/test/respond_to_test.rb +215 -0
- data/test/sketches/key_event.rb +37 -0
- data/test/sketches/library/my_library/my_library.rb +32 -0
- data/test/test_helper.rb +3 -0
- data/test/vecmath_spec_test.rb +522 -0
- data/vendors/Rakefile +127 -0
- metadata +289 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2016-18 Martin Prout
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 3.0 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* http://creativecommons.org/licenses/LGPL/2.1/
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
package monkstone.slider;
|
21
|
+
|
22
|
+
import processing.core.PApplet;
|
23
|
+
import processing.core.PConstants;
|
24
|
+
|
25
|
+
/**
|
26
|
+
*
|
27
|
+
* @author tux
|
28
|
+
*/
|
29
|
+
public class CustomHorizontalSlider extends SliderBar {
|
30
|
+
|
31
|
+
/**
|
32
|
+
*
|
33
|
+
* @param outer
|
34
|
+
* @param x top left position x
|
35
|
+
* @param y left top position y
|
36
|
+
* @param length width or height
|
37
|
+
* @param beginRange start range
|
38
|
+
* @param endRange end range
|
39
|
+
* @param label widget label/ID
|
40
|
+
*/
|
41
|
+
public CustomHorizontalSlider(final PApplet outer, int x, int y, int length, float beginRange, float endRange, String label) {
|
42
|
+
this.applet = outer;
|
43
|
+
this.scrollWheelHandler = (short delta) -> {
|
44
|
+
changeWithWheel(delta);
|
45
|
+
};
|
46
|
+
setActive(true);
|
47
|
+
pX = x;
|
48
|
+
pY = y;
|
49
|
+
pW = length;
|
50
|
+
pH = 10;
|
51
|
+
ID = label;
|
52
|
+
limits(beginRange, endRange);
|
53
|
+
}
|
54
|
+
|
55
|
+
@Override
|
56
|
+
boolean mouseOver() {
|
57
|
+
return (applet.mouseX >= pX && applet.mouseX <= pX + pW && applet.mouseY >= pY && applet.mouseY <= pY + pH);
|
58
|
+
}
|
59
|
+
|
60
|
+
private void setActive(boolean active) {
|
61
|
+
if (active) {
|
62
|
+
applet.registerMethod("dispose", this);
|
63
|
+
applet.registerMethod("draw", this);
|
64
|
+
applet.registerMethod("mouseEvent", this);
|
65
|
+
} else {
|
66
|
+
applet.unregisterMethod("draw", this);
|
67
|
+
applet.unregisterMethod("mouseEvent", this);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
@Override
|
72
|
+
void displayText() {
|
73
|
+
String lFormat = "%d";
|
74
|
+
if (displayLabel) {
|
75
|
+
applet.fill(labelColor);
|
76
|
+
applet.textSize(labelSize);
|
77
|
+
applet.textAlign(PConstants.CENTER);
|
78
|
+
applet.text(Integer.toString((int) pValue), pX + pW / 2, pY + pH / 2 + labelSize / 2 - 2);
|
79
|
+
}
|
80
|
+
if (displayValue) {
|
81
|
+
applet.textSize(numberSize);
|
82
|
+
applet.fill(numbersColor);
|
83
|
+
applet.textAlign(PConstants.LEFT);
|
84
|
+
applet.text(String.format(lFormat, (int) vMin), pX, pY - numberSize / 2);
|
85
|
+
applet.textAlign(PConstants.RIGHT);
|
86
|
+
applet.text(String.format(lFormat, (int) vMax), pX + pW, pY - numberSize / 2);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
@Override
|
91
|
+
void drawGui() {
|
92
|
+
if (backgroundVisible) {
|
93
|
+
applet.fill(sliderBack);
|
94
|
+
applet.rect(pX, pY, pW, pH);
|
95
|
+
}
|
96
|
+
applet.fill(sliderFill);
|
97
|
+
applet.rect(pX, pY, pScaled, pH);
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
*
|
102
|
+
* @param value
|
103
|
+
*/
|
104
|
+
@Override
|
105
|
+
public void setValue(float value) {
|
106
|
+
if (value > vMax) {
|
107
|
+
value = vMax;
|
108
|
+
}
|
109
|
+
if (value < vMin) {
|
110
|
+
value = vMin;
|
111
|
+
}
|
112
|
+
pValue = value;
|
113
|
+
pScaled = map(pValue, vMin, vMax, 0, pW);
|
114
|
+
}
|
115
|
+
|
116
|
+
@Override
|
117
|
+
void checkKeyboard() {
|
118
|
+
if (mouseOver()) {
|
119
|
+
if (applet.mousePressed && applet.mouseButton == PConstants.LEFT) {
|
120
|
+
pValue = constrainMap(applet.mouseX - pX, 0, pW, vMin, vMax);
|
121
|
+
}
|
122
|
+
if (applet.keyPressed && pressOnlyOnce) {
|
123
|
+
if (applet.keyCode == PConstants.LEFT || applet.keyCode == PConstants.DOWN) {
|
124
|
+
pValue--;
|
125
|
+
}
|
126
|
+
if (applet.keyCode == PConstants.RIGHT || applet.keyCode == PConstants.UP) {
|
127
|
+
pValue++;
|
128
|
+
}
|
129
|
+
if (pValue > vMax) {
|
130
|
+
pValue = vMax;
|
131
|
+
} else {
|
132
|
+
pValue = (pValue < vMin) ? vMin : pValue;
|
133
|
+
}
|
134
|
+
pressOnlyOnce = false;
|
135
|
+
}
|
136
|
+
deBounce(5);
|
137
|
+
pScaled = map(pValue, vMin, vMax, 0, pW);
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
/**
|
142
|
+
*
|
143
|
+
* @param delta
|
144
|
+
*/
|
145
|
+
@Override
|
146
|
+
public void changeWithWheel(int delta) {
|
147
|
+
if (!mouseOver()) {
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
if (applet.keyPressed && applet.keyCode == PConstants.SHIFT) {
|
151
|
+
delta = delta * (int) (vMax / 10);
|
152
|
+
}
|
153
|
+
if (applet.keyPressed && applet.keyCode == PConstants.CONTROL) {
|
154
|
+
delta = delta * (int) (vMax / 4);
|
155
|
+
}
|
156
|
+
setValue(pValue + delta);
|
157
|
+
}
|
158
|
+
|
159
|
+
/**
|
160
|
+
*
|
161
|
+
* @return
|
162
|
+
*/
|
163
|
+
@Override
|
164
|
+
public String toString() {
|
165
|
+
String geomF = "HorizontalSliderBar.new(%d, %d, %d, %.2f, %.2f, \"%s\")";
|
166
|
+
return String.format(geomF, pX, pY, pW, vMin, vMax, ID);
|
167
|
+
}
|
168
|
+
}
|
@@ -0,0 +1,182 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2016-18 Martin Prout
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 3.0 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* http://creativecommons.org/licenses/LGPL/2.1/
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
package monkstone.slider;
|
21
|
+
|
22
|
+
import processing.core.PApplet;
|
23
|
+
import processing.core.PConstants;
|
24
|
+
import static processing.core.PConstants.*;
|
25
|
+
|
26
|
+
/**
|
27
|
+
*
|
28
|
+
* @author tux
|
29
|
+
*/
|
30
|
+
public class CustomVerticalSlider extends SliderBar {
|
31
|
+
|
32
|
+
/**
|
33
|
+
*
|
34
|
+
* @param outer
|
35
|
+
* @param x top left position x
|
36
|
+
* @param y left top position y
|
37
|
+
* @param length width or height
|
38
|
+
* @param beginRange start range
|
39
|
+
* @param endRange end range
|
40
|
+
* @param label widget label/ID
|
41
|
+
*/
|
42
|
+
public CustomVerticalSlider(final PApplet outer, int x, int y, int length, float beginRange, float endRange, String label) {
|
43
|
+
this.applet = outer;
|
44
|
+
this.scrollWheelHandler = (short delta) -> {
|
45
|
+
changeWithWheel(delta);
|
46
|
+
};
|
47
|
+
setActive(true);
|
48
|
+
pX = x;
|
49
|
+
pY = y;
|
50
|
+
pW = length;
|
51
|
+
pH = 10;
|
52
|
+
ID = label;
|
53
|
+
limits(beginRange, endRange);
|
54
|
+
}
|
55
|
+
|
56
|
+
@Override
|
57
|
+
boolean mouseOver() {
|
58
|
+
return (applet.mouseX >= pX && applet.mouseX <= pX + pH && applet.mouseY >= pY && applet.mouseY <= pY + pW);
|
59
|
+
}
|
60
|
+
|
61
|
+
private void setActive(boolean active) {
|
62
|
+
if (active) {
|
63
|
+
applet.registerMethod("dispose", this);
|
64
|
+
applet.registerMethod("draw", this);
|
65
|
+
applet.registerMethod("mouseEvent", this);
|
66
|
+
} else {
|
67
|
+
applet.unregisterMethod("draw", this);
|
68
|
+
applet.unregisterMethod("mouseEvent", this);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
@Override
|
73
|
+
void displayText() {
|
74
|
+
String lFormat = "%d";
|
75
|
+
if (displayLabel) {
|
76
|
+
applet.fill(labelColor);
|
77
|
+
applet.textSize(labelSize);
|
78
|
+
applet.textAlign(PConstants.CENTER);
|
79
|
+
applet.pushMatrix();
|
80
|
+
applet.translate(pX + pH / 2, pY + pW / 2);
|
81
|
+
applet.rotate(HALF_PI);
|
82
|
+
applet.text(Integer.toString((int) pValue), 0, 0 + labelSize / 2 - 2);
|
83
|
+
applet.popMatrix();
|
84
|
+
}
|
85
|
+
if (displayValue) {
|
86
|
+
applet.textSize(numberSize);
|
87
|
+
applet.fill(numbersColor);
|
88
|
+
applet.pushMatrix();
|
89
|
+
applet.textAlign(PConstants.RIGHT);
|
90
|
+
applet.translate(pX - numberSize / 2, pY);
|
91
|
+
applet.rotate(HALF_PI);
|
92
|
+
applet.text(String.format(lFormat, (int) vMax), 0, 0);
|
93
|
+
applet.popMatrix();
|
94
|
+
applet.pushMatrix();
|
95
|
+
applet.textAlign(PConstants.LEFT);
|
96
|
+
applet.translate(pX - numberSize / 2, pY + pW);
|
97
|
+
applet.rotate(HALF_PI);
|
98
|
+
applet.text(String.format(lFormat, (int) vMin), 0, 0);
|
99
|
+
applet.popMatrix();
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
@Override
|
104
|
+
void drawGui() {
|
105
|
+
if (backgroundVisible) {
|
106
|
+
applet.fill(sliderBack);
|
107
|
+
applet.rect(pX, pY, pH, pW);
|
108
|
+
}
|
109
|
+
applet.fill(sliderFill);
|
110
|
+
applet.rect(pX, pY + pW, pH, pScaled - pW);
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
*
|
115
|
+
* @param value
|
116
|
+
*/
|
117
|
+
@Override
|
118
|
+
public void setValue(float value) {
|
119
|
+
if (value > vMax) {
|
120
|
+
value = vMax;
|
121
|
+
}
|
122
|
+
if (value < vMin) {
|
123
|
+
value = vMin;
|
124
|
+
}
|
125
|
+
pValue = value;
|
126
|
+
pScaled = map(pValue, vMin, vMax, pW, 0);
|
127
|
+
}
|
128
|
+
|
129
|
+
@Override
|
130
|
+
void checkKeyboard() {
|
131
|
+
if (mouseOver()) {
|
132
|
+
if (applet.mousePressed && applet.mouseButton == PConstants.LEFT) {
|
133
|
+
pValue = constrainMap(applet.mouseY - pY, pW, 0, vMin, vMax);
|
134
|
+
}
|
135
|
+
if (applet.keyPressed && pressOnlyOnce) {
|
136
|
+
if (applet.keyCode == PConstants.LEFT || applet.keyCode == PConstants.DOWN) {
|
137
|
+
pValue--;
|
138
|
+
}
|
139
|
+
if (applet.keyCode == PConstants.RIGHT || applet.keyCode == PConstants.UP) {
|
140
|
+
pValue++;
|
141
|
+
}
|
142
|
+
if (pValue > vMax) {
|
143
|
+
pValue = vMax;
|
144
|
+
} else {
|
145
|
+
pValue = (pValue < vMin) ? vMin : pValue;
|
146
|
+
}
|
147
|
+
pressOnlyOnce = false;
|
148
|
+
}
|
149
|
+
deBounce(5);
|
150
|
+
pScaled = map(pValue, vMin, vMax, pW, 0);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
*
|
156
|
+
* @param delta
|
157
|
+
*/
|
158
|
+
@Override
|
159
|
+
public void changeWithWheel(int delta) {
|
160
|
+
if (!mouseOver()) {
|
161
|
+
return;
|
162
|
+
}
|
163
|
+
if (applet.keyPressed && applet.keyCode == PConstants.SHIFT) {
|
164
|
+
delta = delta * (int) (vMax / 10);
|
165
|
+
}
|
166
|
+
if (applet.keyPressed && applet.keyCode == PConstants.CONTROL) {
|
167
|
+
delta = delta * (int) (vMax / 4);
|
168
|
+
}
|
169
|
+
setValue(pValue - delta);
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
*
|
174
|
+
* @return
|
175
|
+
*/
|
176
|
+
@Override
|
177
|
+
public String toString() {
|
178
|
+
String geomF = "VerticalSliderBar.new(%d, %d, %d, %.2f, %.2f, \"%s\")";
|
179
|
+
return String.format(geomF, pX, pY, pW, vMin, vMax, ID);
|
180
|
+
}
|
181
|
+
|
182
|
+
}
|
@@ -0,0 +1,149 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2016-18 Martin Prout
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 3.0 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* http://creativecommons.org/licenses/LGPL/2.1/
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
package monkstone.slider;
|
21
|
+
|
22
|
+
import processing.core.PApplet;
|
23
|
+
import processing.core.PConstants;
|
24
|
+
|
25
|
+
/**
|
26
|
+
*
|
27
|
+
* @author tux
|
28
|
+
*/
|
29
|
+
public class SimpleHorizontalSlider extends SimpleSlider {
|
30
|
+
|
31
|
+
final int SPACING = 20;
|
32
|
+
final int LEFT_SPC = SPACING * 2;
|
33
|
+
final int RIGHT_SPC = SPACING * 4;
|
34
|
+
|
35
|
+
/**
|
36
|
+
*
|
37
|
+
* @param outer
|
38
|
+
* @param beginRange start range
|
39
|
+
* @param endRange end range
|
40
|
+
* @param initial
|
41
|
+
* @param count
|
42
|
+
*/
|
43
|
+
public SimpleHorizontalSlider(final PApplet outer, float beginRange, float endRange, float initial, int count) {
|
44
|
+
this.applet = outer;
|
45
|
+
setActive(true);
|
46
|
+
pX = LEFT_SPC;
|
47
|
+
pY = outer.height - SPACING - (count * SPACING);
|
48
|
+
pW = outer.width - RIGHT_SPC;
|
49
|
+
pH = 10;
|
50
|
+
ID = Integer.toString(count + 1);
|
51
|
+
limits(beginRange, endRange);
|
52
|
+
setValue(initial);
|
53
|
+
}
|
54
|
+
|
55
|
+
@Override
|
56
|
+
boolean mouseOver() {
|
57
|
+
return (applet.mouseX >= pX && applet.mouseX <= pX + pW && applet.mouseY >= pY && applet.mouseY <= pY + pH);
|
58
|
+
}
|
59
|
+
|
60
|
+
private void setActive(boolean active) {
|
61
|
+
if (active) {
|
62
|
+
applet.registerMethod("dispose", this);
|
63
|
+
applet.registerMethod("draw", this);
|
64
|
+
} else {
|
65
|
+
applet.unregisterMethod("draw", this);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
@Override
|
70
|
+
void displayText() {
|
71
|
+
String lFormat = "%d";
|
72
|
+
if (displayLabel) {
|
73
|
+
applet.fill(labelColor);
|
74
|
+
applet.textSize(labelSize);
|
75
|
+
applet.textAlign(PConstants.BOTTOM);
|
76
|
+
applet.text(Integer.toString((int) pValue), pX + pW / 2, pY + pH);
|
77
|
+
}
|
78
|
+
if (displayValue) {
|
79
|
+
applet.textSize(numberSize);
|
80
|
+
applet.fill(numbersColor);
|
81
|
+
applet.textAlign(PConstants.LEFT);
|
82
|
+
applet.text(String.format(lFormat, (int) vMin), pX, pY );
|
83
|
+
applet.textAlign(PConstants.RIGHT);
|
84
|
+
applet.text(String.format(lFormat, (int) vMax), pX + pW, pY );
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
@Override
|
89
|
+
void drawGui() {
|
90
|
+
if (backgroundVisible) {
|
91
|
+
applet.stroke(sliderBack);
|
92
|
+
applet.line(pX, pY + pH / 2, pX + pW, pY + pH / 2);
|
93
|
+
}
|
94
|
+
applet.noStroke();
|
95
|
+
applet.fill(255);
|
96
|
+
applet.ellipse(pX + pScaled, pY + pH / 2, 10, 10);
|
97
|
+
}
|
98
|
+
|
99
|
+
/**
|
100
|
+
*
|
101
|
+
* @param value
|
102
|
+
*/
|
103
|
+
@Override
|
104
|
+
public final void setValue(float value) {
|
105
|
+
if (value > vMax) {
|
106
|
+
value = vMax;
|
107
|
+
}
|
108
|
+
if (value < vMin) {
|
109
|
+
value = vMin;
|
110
|
+
}
|
111
|
+
pValue = value;
|
112
|
+
pScaled = map(pValue, vMin, vMax, 0, pW);
|
113
|
+
}
|
114
|
+
|
115
|
+
@Override
|
116
|
+
void checkKeyboard() {
|
117
|
+
if (mouseOver()) {
|
118
|
+
if (applet.mousePressed && applet.mouseButton == PConstants.LEFT) {
|
119
|
+
pValue = constrainMap(applet.mouseX - pX, 0, pW, vMin, vMax);
|
120
|
+
}
|
121
|
+
if (applet.keyPressed && pressOnlyOnce) {
|
122
|
+
if (applet.keyCode == PConstants.LEFT || applet.keyCode == PConstants.DOWN) {
|
123
|
+
pValue--;
|
124
|
+
}
|
125
|
+
if (applet.keyCode == PConstants.RIGHT || applet.keyCode == PConstants.UP) {
|
126
|
+
pValue++;
|
127
|
+
}
|
128
|
+
if (pValue > vMax) {
|
129
|
+
pValue = vMax;
|
130
|
+
} else {
|
131
|
+
pValue = (pValue < vMin) ? vMin : pValue;
|
132
|
+
}
|
133
|
+
pressOnlyOnce = false;
|
134
|
+
}
|
135
|
+
deBounce(5);
|
136
|
+
pScaled = map(pValue, vMin, vMax, 0, pW);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
*
|
142
|
+
* @return
|
143
|
+
*/
|
144
|
+
@Override
|
145
|
+
public String toString() {
|
146
|
+
String geomF = "SimpleHSliderBar.new(%d, %d, %d, %.2f, %.2f, \"%s\")";
|
147
|
+
return String.format(geomF, pX, pY, pW, vMin, vMax, ID);
|
148
|
+
}
|
149
|
+
}
|