picrate 0.0.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +47 -0
  3. data/.mvn/extensions.xml +9 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +1 -0
  5. data/.travis.yml +10 -0
  6. data/CHANGELOG.md +4 -0
  7. data/LICENSE.md +165 -0
  8. data/README.md +51 -0
  9. data/Rakefile +59 -0
  10. data/bin/picrate +8 -0
  11. data/docs/.gitignore +6 -0
  12. data/docs/_config.yml +30 -0
  13. data/docs/_includes/footer.html +38 -0
  14. data/docs/_includes/head.html +16 -0
  15. data/docs/_includes/header.html +27 -0
  16. data/docs/_includes/icon-github.html +1 -0
  17. data/docs/_includes/icon-github.svg +1 -0
  18. data/docs/_includes/icon-twitter.html +1 -0
  19. data/docs/_includes/icon-twitter.svg +1 -0
  20. data/docs/_includes/navigation.html +24 -0
  21. data/docs/_layouts/default.html +20 -0
  22. data/docs/_layouts/page.html +14 -0
  23. data/docs/_layouts/post.html +15 -0
  24. data/docs/_posts/2018-05-06-getting_started.md +8 -0
  25. data/docs/_posts/2018-05-06-install_jruby.md +35 -0
  26. data/docs/_sass/_base.scss +206 -0
  27. data/docs/_sass/_layout.scss +242 -0
  28. data/docs/_sass/_syntax-highlighting.scss +71 -0
  29. data/docs/about.md +10 -0
  30. data/docs/css/main.scss +38 -0
  31. data/docs/favicon.ico +0 -0
  32. data/docs/feed.xml +30 -0
  33. data/docs/index.html +38 -0
  34. data/lib/picrate.rb +10 -0
  35. data/lib/picrate/app.rb +187 -0
  36. data/lib/picrate/creators/sketch_class.rb +57 -0
  37. data/lib/picrate/creators/sketch_factory.rb +12 -0
  38. data/lib/picrate/creators/sketch_writer.rb +21 -0
  39. data/lib/picrate/helper_methods.rb +214 -0
  40. data/lib/picrate/helpers/numeric.rb +9 -0
  41. data/lib/picrate/library.rb +69 -0
  42. data/lib/picrate/library_loader.rb +53 -0
  43. data/lib/picrate/native_folder.rb +35 -0
  44. data/lib/picrate/native_loader.rb +27 -0
  45. data/lib/picrate/runner.rb +81 -0
  46. data/lib/picrate/version.rb +4 -0
  47. data/library/boids/boids.rb +209 -0
  48. data/library/chooser/chooser.rb +19 -0
  49. data/library/control_panel/control_panel.rb +182 -0
  50. data/library/library_proxy/README.md +99 -0
  51. data/library/library_proxy/library_proxy.rb +14 -0
  52. data/library/slider/slider.rb +42 -0
  53. data/library/vector_utils/vector_utils.rb +69 -0
  54. data/library/video_event/video_event.rb +3 -0
  55. data/license.txt +508 -0
  56. data/picrate.gemspec +35 -0
  57. data/pom.rb +122 -0
  58. data/pom.xml +214 -0
  59. data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
  60. data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  61. data/src/main/java/monkstone/ColorUtil.java +115 -0
  62. data/src/main/java/monkstone/MathToolModule.java +236 -0
  63. data/src/main/java/monkstone/PicrateLibrary.java +47 -0
  64. data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
  65. data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
  66. data/src/main/java/monkstone/fastmath/package-info.java +6 -0
  67. data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
  68. data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
  69. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
  70. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
  71. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
  72. data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
  73. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
  74. data/src/main/java/monkstone/slider/Slider.java +67 -0
  75. data/src/main/java/monkstone/slider/SliderBar.java +277 -0
  76. data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
  77. data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
  78. data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
  79. data/src/main/java/monkstone/vecmath/JRender.java +56 -0
  80. data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
  81. data/src/main/java/monkstone/vecmath/package-info.java +20 -0
  82. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
  83. data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
  84. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
  85. data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
  86. data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
  87. data/src/main/java/monkstone/videoevent/package-info.java +20 -0
  88. data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
  89. data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
  90. data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
  91. data/src/main/java/processing/core/PApplet.java +17647 -0
  92. data/src/main/java/processing/core/PConstants.java +1033 -0
  93. data/src/main/java/processing/core/PFont.java +1250 -0
  94. data/src/main/java/processing/core/PGraphics.java +9614 -0
  95. data/src/main/java/processing/core/PImage.java +3608 -0
  96. data/src/main/java/processing/core/PMatrix.java +347 -0
  97. data/src/main/java/processing/core/PMatrix2D.java +694 -0
  98. data/src/main/java/processing/core/PMatrix3D.java +1153 -0
  99. data/src/main/java/processing/core/PShape.java +4332 -0
  100. data/src/main/java/processing/core/PShapeOBJ.java +544 -0
  101. data/src/main/java/processing/core/PShapeSVG.java +1987 -0
  102. data/src/main/java/processing/core/PStyle.java +208 -0
  103. data/src/main/java/processing/core/PSurface.java +242 -0
  104. data/src/main/java/processing/core/PSurfaceNone.java +479 -0
  105. data/src/main/java/processing/core/PVector.java +1140 -0
  106. data/src/main/java/processing/data/FloatDict.java +829 -0
  107. data/src/main/java/processing/data/FloatList.java +912 -0
  108. data/src/main/java/processing/data/IntDict.java +796 -0
  109. data/src/main/java/processing/data/IntList.java +913 -0
  110. data/src/main/java/processing/data/JSONArray.java +1260 -0
  111. data/src/main/java/processing/data/JSONObject.java +2282 -0
  112. data/src/main/java/processing/data/JSONTokener.java +435 -0
  113. data/src/main/java/processing/data/Sort.java +46 -0
  114. data/src/main/java/processing/data/StringDict.java +601 -0
  115. data/src/main/java/processing/data/StringList.java +775 -0
  116. data/src/main/java/processing/data/Table.java +4923 -0
  117. data/src/main/java/processing/data/TableRow.java +198 -0
  118. data/src/main/java/processing/data/XML.java +1149 -0
  119. data/src/main/java/processing/event/Event.java +108 -0
  120. data/src/main/java/processing/event/KeyEvent.java +70 -0
  121. data/src/main/java/processing/event/MouseEvent.java +149 -0
  122. data/src/main/java/processing/event/TouchEvent.java +57 -0
  123. data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
  124. data/src/main/java/processing/opengl/FontTexture.java +379 -0
  125. data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
  126. data/src/main/java/processing/opengl/LinePath.java +623 -0
  127. data/src/main/java/processing/opengl/LineStroker.java +685 -0
  128. data/src/main/java/processing/opengl/PGL.java +3366 -0
  129. data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
  130. data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
  131. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
  132. data/src/main/java/processing/opengl/PJOGL.java +1966 -0
  133. data/src/main/java/processing/opengl/PShader.java +1478 -0
  134. data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
  135. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
  136. data/src/main/java/processing/opengl/Texture.java +1670 -0
  137. data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
  138. data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
  139. data/src/main/java/processing/opengl/cursors/cross.png +0 -0
  140. data/src/main/java/processing/opengl/cursors/hand.png +0 -0
  141. data/src/main/java/processing/opengl/cursors/license.txt +27 -0
  142. data/src/main/java/processing/opengl/cursors/move.png +0 -0
  143. data/src/main/java/processing/opengl/cursors/text.png +0 -0
  144. data/src/main/java/processing/opengl/cursors/wait.png +0 -0
  145. data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
  146. data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
  147. data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
  148. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
  149. data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
  150. data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
  151. data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
  152. data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
  153. data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
  154. data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
  155. data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
  156. data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
  157. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
  158. data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
  159. data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
  160. data/src/main/resources/icon/icon-1024.png +0 -0
  161. data/src/main/resources/icon/icon-128.png +0 -0
  162. data/src/main/resources/icon/icon-16.png +0 -0
  163. data/src/main/resources/icon/icon-256.png +0 -0
  164. data/src/main/resources/icon/icon-32.png +0 -0
  165. data/src/main/resources/icon/icon-48.png +0 -0
  166. data/src/main/resources/icon/icon-512.png +0 -0
  167. data/src/main/resources/icon/icon-64.png +0 -0
  168. data/src/main/resources/license.txt +508 -0
  169. data/test/create_test.rb +68 -0
  170. data/test/deglut_spec_test.rb +24 -0
  171. data/test/helper_methods_test.rb +58 -0
  172. data/test/math_tool_test.rb +75 -0
  173. data/test/respond_to_test.rb +215 -0
  174. data/test/sketches/key_event.rb +37 -0
  175. data/test/sketches/library/my_library/my_library.rb +32 -0
  176. data/test/test_helper.rb +3 -0
  177. data/test/vecmath_spec_test.rb +522 -0
  178. data/vendors/Rakefile +127 -0
  179. metadata +289 -0
@@ -0,0 +1,196 @@
1
+ /*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+ package monkstone.slider;
7
+
8
+ import processing.core.PApplet;
9
+
10
+ /**
11
+ *
12
+ * @author tux
13
+ */
14
+ public abstract class SimpleSlider implements Slider {//implements Slider {
15
+
16
+ int MIN_BAR_WIDTH = 10;
17
+ int MAX_BAR_WIDTH = 30;
18
+ int sliderBack = 0xff909090;
19
+ int sliderFill = 0xff696969;
20
+ int borderColor = 0;
21
+ int numbersColor = 0;
22
+ int labelColor = 0;
23
+ int externalBorder = 0;
24
+ boolean backgroundVisible = true;
25
+ int labelSize = 18;
26
+ int numberSize = 14;
27
+ boolean displayLabel = false;
28
+ boolean displayValue = true;
29
+ int pX;
30
+ int pY;
31
+ int pW;
32
+ int pH;
33
+ float pScaled = 0;
34
+ float pValue = 0;
35
+ String ID;
36
+ boolean pressOnlyOnce = true;
37
+ int deb = 0;
38
+ short wheelCount = 0;
39
+ float vMin = 0;
40
+ float vMax = 15;
41
+ PApplet applet;
42
+
43
+ abstract void displayText();
44
+
45
+ abstract void drawGui();
46
+
47
+ /**
48
+ *
49
+ */
50
+ @Override
51
+ public void draw() {
52
+ applet.pushStyle();
53
+ applet.noStroke();
54
+ drawGui();
55
+ displayText();
56
+ applet.popStyle();
57
+ change();
58
+ }
59
+
60
+ /**
61
+ *
62
+ */
63
+
64
+ @Override
65
+ public void showLabel() {
66
+ displayLabel = true;
67
+ }
68
+
69
+ /**
70
+ *
71
+ */
72
+
73
+ @Override
74
+ public void hideLabel() {
75
+ displayLabel = false;
76
+ }
77
+
78
+ /**
79
+ *
80
+ */
81
+
82
+ @Override
83
+ public void showNumbers() {
84
+ displayValue = true;
85
+ }
86
+
87
+ /**
88
+ *
89
+ */
90
+ @Override
91
+ public void hideNumbers() {
92
+ displayValue = false;
93
+ }
94
+
95
+ void change() {
96
+ checkKeyboard();
97
+ }
98
+
99
+ /**
100
+ *
101
+ */
102
+
103
+ @Override
104
+ public void hideBackground() {
105
+ backgroundVisible = false;
106
+ }
107
+
108
+ /**
109
+ *
110
+ * @return
111
+ */
112
+
113
+ @Override
114
+ public float readValue() {
115
+ return pValue;
116
+ }
117
+
118
+ abstract boolean mouseOver();
119
+
120
+ /**
121
+ *
122
+ * @param val
123
+ * @param begIn
124
+ * @param endIn
125
+ * @param beginOut
126
+ * @param endOut
127
+ * @return
128
+ */
129
+ protected float map(float val, float begIn, float endIn, float beginOut, float endOut) {
130
+ return (beginOut + (endOut - beginOut) * ((val - begIn) / (endIn - begIn)));
131
+ }
132
+
133
+ final void limits(float iv, float fv) {
134
+ vMin = iv;
135
+ vMax = fv;
136
+ setValue(iv);
137
+ }
138
+
139
+ /**
140
+ *
141
+ * @param s
142
+ */
143
+
144
+ @Override
145
+ public void labelSize(int s) {
146
+ labelSize = (s < 4) ? 4 : s;
147
+ }
148
+
149
+ void deBounce(int n) {
150
+ if (pressOnlyOnce) {
151
+ } else if (deb++ > n) {
152
+ deb = 0;
153
+ pressOnlyOnce = true;
154
+ }
155
+ }
156
+
157
+ abstract void checkKeyboard();
158
+
159
+ /**
160
+ *
161
+ * @param val
162
+ * @param begIn
163
+ * @param endIn
164
+ * @param beginOut
165
+ * @param endOut
166
+ * @return
167
+ */
168
+ protected int constrainMap(double val, double begIn, double endIn, double beginOut, double endOut) {
169
+ double max = Math.max(begIn, endIn);
170
+ double min = Math.min(begIn, endIn);
171
+ if (val < min) {
172
+ val = min;
173
+ }
174
+ if (val > max) {
175
+ val = max;
176
+ }
177
+ return (int) ((beginOut + (endOut - beginOut) * ((val - begIn) / (endIn - begIn))));
178
+ }
179
+
180
+ private void setActive(boolean active) {
181
+ if (active) {
182
+ applet.registerMethod("dispose", this);
183
+ applet.registerMethod("draw", this);
184
+ } else {
185
+ applet.unregisterMethod("draw", this);
186
+ }
187
+ }
188
+
189
+ /**
190
+ *
191
+ */
192
+ @Override
193
+ public void dispose() {
194
+ setActive(false);
195
+ }
196
+ }
@@ -0,0 +1,163 @@
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.HALF_PI;
25
+
26
+ /**
27
+ *
28
+ * @author tux
29
+ */
30
+ public class SimpleVerticalSlider extends SimpleSlider {
31
+
32
+ final int SPACING = 20;
33
+ final int TOP_SPC = SPACING * 2;
34
+ final int BOTTOM_SPC = SPACING * 4;
35
+
36
+ /**
37
+ *
38
+ * @param outer
39
+ * @param beginRange start range
40
+ * @param endRange end range
41
+ * @param initial
42
+ * @param count
43
+ */
44
+ public SimpleVerticalSlider(final PApplet outer, float beginRange, float endRange, float initial, int count) {
45
+ this.applet = outer;
46
+ setActive(true);
47
+ pX = outer.width - (TOP_SPC + count * SPACING);
48
+ pY = TOP_SPC;
49
+ pW = outer.height - BOTTOM_SPC;
50
+ pH = 10;
51
+ ID = Integer.toString(count + 1);
52
+ limits(beginRange, endRange);
53
+
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
+ } else {
66
+ applet.unregisterMethod("draw", this);
67
+ }
68
+ }
69
+
70
+ @Override
71
+ void displayText() {
72
+ String lFormat = "%d";
73
+ if (displayLabel) {
74
+ applet.fill(labelColor);
75
+ applet.textSize(labelSize);
76
+ applet.textAlign(PConstants.CENTER);
77
+ applet.pushMatrix();
78
+ applet.translate(pX + pH / 2, pY + pW / 2);
79
+ applet.rotate(HALF_PI);
80
+ applet.text(Integer.toString((int) pValue), 0, 0 + labelSize / 2 - 2);
81
+ applet.popMatrix();
82
+ }
83
+ if (displayValue) {
84
+ applet.textSize(numberSize);
85
+ applet.fill(numbersColor);
86
+ applet.pushMatrix();
87
+ applet.textAlign(PConstants.RIGHT);
88
+ applet.translate(pX - numberSize / 2, pY);
89
+ applet.rotate(HALF_PI);
90
+ applet.text(String.format(lFormat, (int) vMax), 0, 0);
91
+ applet.popMatrix();
92
+ applet.pushMatrix();
93
+ applet.textAlign(PConstants.LEFT);
94
+ applet.translate(pX - numberSize / 2, pY + pW);
95
+ applet.rotate(HALF_PI);
96
+ applet.text(String.format(lFormat, (int) vMin), 0, 0);
97
+ applet.popMatrix();
98
+ }
99
+ }
100
+
101
+ @Override
102
+ void drawGui() {
103
+ if (backgroundVisible) {
104
+ applet.fill(sliderBack);
105
+ applet.rect(pX, pY, pH, pW);
106
+ }
107
+ applet.fill(sliderFill);
108
+ applet.ellipse(pX + pH / 2, pY + pScaled, 10, 10);
109
+ }
110
+
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
+ * @return
157
+ */
158
+ @Override
159
+ public String toString() {
160
+ String geomF = "SimpleHSliderBar.new(%d, %d, %d, %.2f, %.2f, \"%s\")";
161
+ return String.format(geomF, pX, pY, pW, vMin, vMax, ID);
162
+ }
163
+ }
@@ -0,0 +1,67 @@
1
+ /*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+ package monkstone.slider;
7
+
8
+ /**
9
+ *
10
+ * @author tux
11
+ */
12
+ public interface Slider {
13
+
14
+ /**
15
+ *
16
+ */
17
+ void dispose();
18
+
19
+ /**
20
+ *
21
+ */
22
+ void draw();
23
+
24
+ /**
25
+ *
26
+ */
27
+ void hideBackground();
28
+
29
+ /**
30
+ *
31
+ */
32
+ void hideLabel();
33
+
34
+ /**
35
+ *
36
+ */
37
+ void hideNumbers();
38
+
39
+ /**
40
+ *
41
+ * @param s
42
+ */
43
+ void labelSize(int s);
44
+
45
+ /**
46
+ *
47
+ * @return
48
+ */
49
+ float readValue();
50
+
51
+ /**
52
+ *
53
+ * @param value
54
+ */
55
+ void setValue(float value);
56
+
57
+ /**
58
+ *
59
+ */
60
+ void showLabel();
61
+
62
+ /**
63
+ *
64
+ */
65
+ void showNumbers();
66
+
67
+ }
@@ -0,0 +1,277 @@
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.event.MouseEvent;
24
+
25
+ /**
26
+ *
27
+ * @author tux
28
+ */
29
+ public abstract class SliderBar implements Slider {
30
+
31
+ int MIN_BAR_WIDTH = 10;
32
+ int MAX_BAR_WIDTH = 30;
33
+ int sliderBack = 0xff909090;
34
+ int sliderFill = 0xff696969;
35
+ int borderColor = 0;
36
+ int numbersColor = 0;
37
+ int labelColor = 0;
38
+ int externalBorder = 0;
39
+ boolean backgroundVisible = true;
40
+ int labelSize = 18;
41
+ int numberSize = 14;
42
+ boolean displayLabel = false;
43
+ boolean displayValue = true;
44
+ int pX;
45
+ int pY;
46
+ int pW;
47
+ int pH;
48
+ float pScaled = 0;
49
+ float pValue = 0;
50
+ String ID;
51
+ boolean pressOnlyOnce = true;
52
+ int deb = 0;
53
+ short wheelCount = 0;
54
+ float vMin = 0;
55
+ float vMax = 15;
56
+ PApplet applet;
57
+ WheelHandler scrollWheelHandler;
58
+
59
+ /**
60
+ *
61
+ * @return
62
+ */
63
+ public float value() {
64
+ return pValue;
65
+ }
66
+
67
+ /**
68
+ *
69
+ * @param w
70
+ */
71
+ public void barWidth(int w) {
72
+ if (w < MIN_BAR_WIDTH) {
73
+ pH = MIN_BAR_WIDTH;
74
+ } else {
75
+ pH = (w > MAX_BAR_WIDTH) ? MAX_BAR_WIDTH : w;
76
+ }
77
+ }
78
+
79
+ final void limits(float iv, float fv) {
80
+ vMin = iv;
81
+ vMax = fv;
82
+ SliderBar.this.setValue(iv);
83
+ }
84
+
85
+ /**
86
+ *
87
+ */
88
+ @Override
89
+ public void showLabel() {
90
+ displayLabel = true;
91
+ }
92
+
93
+ /**
94
+ *
95
+ */
96
+ @Override
97
+ public void hideLabel() {
98
+ displayLabel = false;
99
+ }
100
+
101
+ /**
102
+ *
103
+ */
104
+ @Override
105
+ public void showNumbers() {
106
+ displayValue = true;
107
+ }
108
+
109
+ /**
110
+ *
111
+ */
112
+ @Override
113
+ public void hideNumbers() {
114
+ displayValue = false;
115
+ }
116
+
117
+ /**
118
+ *
119
+ * @param b
120
+ */
121
+ public void externalBorder(int b) {
122
+ externalBorder = b;
123
+ }
124
+
125
+ /**
126
+ *
127
+ */
128
+ @Override
129
+ public void hideBackground() {
130
+ backgroundVisible = false;
131
+ }
132
+
133
+ /**
134
+ *
135
+ */
136
+ public void showBackground() {
137
+ backgroundVisible = true;
138
+ }
139
+
140
+ /**
141
+ *
142
+ * @param s
143
+ */
144
+ @Override
145
+ public void labelSize(int s) {
146
+ labelSize = (s < 4) ? 4 : s;
147
+ }
148
+
149
+ /**
150
+ * @param back color of the bar
151
+ * @param fill background color of the slider
152
+ */
153
+ public void widgetColors(int back, int fill) {
154
+ sliderBack = back;
155
+ sliderFill = fill;
156
+ }
157
+
158
+ abstract boolean mouseOver();
159
+
160
+ private void setActive(boolean active) {
161
+ if (active) {
162
+ applet.registerMethod("dispose", this);
163
+ applet.registerMethod("draw", this);
164
+ applet.registerMethod("mouseEvent", this);
165
+ } else {
166
+ applet.unregisterMethod("draw", this);
167
+ applet.unregisterMethod("mouseEvent", this);
168
+ }
169
+ }
170
+
171
+ abstract void displayText();
172
+
173
+ abstract void drawGui();
174
+
175
+ /**
176
+ *
177
+ */
178
+ @Override
179
+ public void draw() {
180
+ applet.pushStyle();
181
+ applet.noStroke();
182
+ drawGui();
183
+ displayText();
184
+ applet.popStyle();
185
+ change();
186
+ }
187
+
188
+ /**
189
+ *
190
+ * @param evt
191
+ */
192
+ public void mouseEvent(MouseEvent evt) {
193
+ if (evt.getAction() == MouseEvent.WHEEL) {
194
+ if (scrollWheelHandler != null) {
195
+ scrollWheelHandler.handleWheel((short) evt.getCount());
196
+ }
197
+ }
198
+ }
199
+
200
+ /**
201
+ *
202
+ * @param value
203
+ */
204
+ @Override
205
+ public abstract void setValue(float value);
206
+
207
+ abstract void checkKeyboard();
208
+
209
+ void change() {
210
+ checkKeyboard();
211
+ }
212
+
213
+ /**
214
+ *
215
+ * @return
216
+ */
217
+ @Override
218
+ public float readValue() {
219
+ return pValue;
220
+ }
221
+
222
+ /**
223
+ *
224
+ * @param delta
225
+ */
226
+ abstract void changeWithWheel(int delta);
227
+
228
+ void deBounce(int n) {
229
+ if (pressOnlyOnce) {
230
+ } else if (deb++ > n) {
231
+ deb = 0;
232
+ pressOnlyOnce = true;
233
+ }
234
+ }
235
+
236
+ /**
237
+ *
238
+ * @param val
239
+ * @param begIn
240
+ * @param endIn
241
+ * @param beginOut
242
+ * @param endOut
243
+ * @return
244
+ */
245
+ protected float map(float val, float begIn, float endIn, float beginOut, float endOut) {
246
+ return (beginOut + (endOut - beginOut) * ((val - begIn) / (endIn - begIn)));
247
+ }
248
+
249
+ /**
250
+ *
251
+ * @param val
252
+ * @param begIn
253
+ * @param endIn
254
+ * @param beginOut
255
+ * @param endOut
256
+ * @return
257
+ */
258
+ protected int constrainMap(double val, double begIn, double endIn, double beginOut, double endOut) {
259
+ double max = Math.max(begIn, endIn);
260
+ double min = Math.min(begIn, endIn);
261
+ if (val < min) {
262
+ val = min;
263
+ }
264
+ if (val > max) {
265
+ val = max;
266
+ }
267
+ return (int) ((beginOut + (endOut - beginOut) * ((val - begIn) / (endIn - begIn))));
268
+ }
269
+
270
+ /**
271
+ *
272
+ */
273
+ @Override
274
+ public void dispose() {
275
+ setActive(false);
276
+ }
277
+ }