propane 3.9.0-java → 3.10.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +2 -2
  4. data/README.md +3 -3
  5. data/Rakefile +6 -6
  6. data/lib/java/japplemenubar/JAppleMenuBar.java +88 -0
  7. data/lib/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  8. data/lib/java/monkstone/ColorUtil.java +127 -0
  9. data/lib/java/monkstone/MathToolModule.java +287 -0
  10. data/lib/java/monkstone/PropaneLibrary.java +46 -0
  11. data/lib/java/monkstone/core/LibraryProxy.java +136 -0
  12. data/lib/java/monkstone/fastmath/DegLutTables.java +111 -0
  13. data/lib/java/monkstone/fastmath/Deglut.java +71 -0
  14. data/lib/java/monkstone/fastmath/package-info.java +6 -0
  15. data/lib/java/monkstone/filechooser/Chooser.java +39 -0
  16. data/{src/main → lib}/java/monkstone/noise/FastTerrain.java +0 -0
  17. data/{src/main → lib}/java/monkstone/noise/Noise.java +0 -0
  18. data/{src/main → lib}/java/monkstone/noise/NoiseGenerator.java +0 -0
  19. data/{src/main → lib}/java/monkstone/noise/NoiseMode.java +0 -0
  20. data/lib/java/monkstone/noise/OpenSimplex2F.java +881 -0
  21. data/lib/java/monkstone/noise/OpenSimplex2S.java +1106 -0
  22. data/{src/main → lib}/java/monkstone/noise/SmoothTerrain.java +0 -0
  23. data/lib/java/monkstone/slider/CustomHorizontalSlider.java +164 -0
  24. data/lib/java/monkstone/slider/CustomVerticalSlider.java +178 -0
  25. data/lib/java/monkstone/slider/SimpleHorizontalSlider.java +145 -0
  26. data/lib/java/monkstone/slider/SimpleSlider.java +166 -0
  27. data/lib/java/monkstone/slider/SimpleVerticalSlider.java +157 -0
  28. data/lib/java/monkstone/slider/Slider.java +61 -0
  29. data/lib/java/monkstone/slider/SliderBar.java +245 -0
  30. data/lib/java/monkstone/slider/SliderGroup.java +56 -0
  31. data/lib/java/monkstone/slider/WheelHandler.java +35 -0
  32. data/lib/java/monkstone/vecmath/GfxRender.java +86 -0
  33. data/lib/java/monkstone/vecmath/JRender.java +56 -0
  34. data/lib/java/monkstone/vecmath/ShapeRender.java +87 -0
  35. data/lib/java/monkstone/vecmath/package-info.java +20 -0
  36. data/lib/java/monkstone/vecmath/vec2/Vec2.java +802 -0
  37. data/lib/java/monkstone/vecmath/vec2/package-info.java +6 -0
  38. data/lib/java/monkstone/vecmath/vec3/Vec3.java +727 -0
  39. data/lib/java/monkstone/vecmath/vec3/package-info.java +6 -0
  40. data/lib/java/monkstone/videoevent/CaptureEvent.java +27 -0
  41. data/lib/java/monkstone/videoevent/MovieEvent.java +32 -0
  42. data/lib/java/monkstone/videoevent/package-info.java +20 -0
  43. data/lib/java/processing/awt/PGraphicsJava2D.java +3040 -0
  44. data/lib/java/processing/awt/PImageAWT.java +377 -0
  45. data/lib/java/processing/awt/PShapeJava2D.java +387 -0
  46. data/lib/java/processing/awt/PSurfaceAWT.java +1581 -0
  47. data/lib/java/processing/awt/ShimAWT.java +581 -0
  48. data/lib/java/processing/core/PApplet.java +15156 -0
  49. data/lib/java/processing/core/PConstants.java +523 -0
  50. data/lib/java/processing/core/PFont.java +1126 -0
  51. data/lib/java/processing/core/PGraphics.java +8600 -0
  52. data/lib/java/processing/core/PImage.java +3377 -0
  53. data/lib/java/processing/core/PMatrix.java +208 -0
  54. data/lib/java/processing/core/PMatrix2D.java +562 -0
  55. data/lib/java/processing/core/PMatrix3D.java +890 -0
  56. data/lib/java/processing/core/PShape.java +3561 -0
  57. data/lib/java/processing/core/PShapeOBJ.java +483 -0
  58. data/lib/java/processing/core/PShapeSVG.java +2016 -0
  59. data/lib/java/processing/core/PStyle.java +63 -0
  60. data/lib/java/processing/core/PSurface.java +198 -0
  61. data/lib/java/processing/core/PSurfaceNone.java +431 -0
  62. data/lib/java/processing/core/PVector.java +1066 -0
  63. data/lib/java/processing/core/ThinkDifferent.java +115 -0
  64. data/lib/java/processing/data/DoubleDict.java +850 -0
  65. data/lib/java/processing/data/DoubleList.java +928 -0
  66. data/lib/java/processing/data/FloatDict.java +847 -0
  67. data/lib/java/processing/data/FloatList.java +936 -0
  68. data/lib/java/processing/data/IntDict.java +807 -0
  69. data/lib/java/processing/data/IntList.java +936 -0
  70. data/lib/java/processing/data/JSONArray.java +1260 -0
  71. data/lib/java/processing/data/JSONObject.java +2282 -0
  72. data/lib/java/processing/data/JSONTokener.java +435 -0
  73. data/lib/java/processing/data/LongDict.java +802 -0
  74. data/lib/java/processing/data/LongList.java +937 -0
  75. data/lib/java/processing/data/Sort.java +46 -0
  76. data/lib/java/processing/data/StringDict.java +613 -0
  77. data/lib/java/processing/data/StringList.java +800 -0
  78. data/lib/java/processing/data/Table.java +4936 -0
  79. data/lib/java/processing/data/TableRow.java +198 -0
  80. data/lib/java/processing/data/XML.java +1156 -0
  81. data/lib/java/processing/dxf/RawDXF.java +404 -0
  82. data/lib/java/processing/event/Event.java +125 -0
  83. data/lib/java/processing/event/KeyEvent.java +70 -0
  84. data/lib/java/processing/event/MouseEvent.java +114 -0
  85. data/lib/java/processing/event/TouchEvent.java +57 -0
  86. data/lib/java/processing/javafx/PGraphicsFX2D.java +32 -0
  87. data/lib/java/processing/javafx/PSurfaceFX.java +173 -0
  88. data/lib/java/processing/net/Client.java +744 -0
  89. data/lib/java/processing/net/Server.java +388 -0
  90. data/lib/java/processing/opengl/FontTexture.java +378 -0
  91. data/lib/java/processing/opengl/FrameBuffer.java +513 -0
  92. data/lib/java/processing/opengl/LinePath.java +627 -0
  93. data/lib/java/processing/opengl/LineStroker.java +681 -0
  94. data/lib/java/processing/opengl/PGL.java +3483 -0
  95. data/lib/java/processing/opengl/PGraphics2D.java +615 -0
  96. data/lib/java/processing/opengl/PGraphics3D.java +281 -0
  97. data/lib/java/processing/opengl/PGraphicsOpenGL.java +13753 -0
  98. data/lib/java/processing/opengl/PJOGL.java +2008 -0
  99. data/lib/java/processing/opengl/PShader.java +1484 -0
  100. data/lib/java/processing/opengl/PShapeOpenGL.java +5269 -0
  101. data/lib/java/processing/opengl/PSurfaceJOGL.java +1385 -0
  102. data/lib/java/processing/opengl/Texture.java +1696 -0
  103. data/lib/java/processing/opengl/VertexBuffer.java +88 -0
  104. data/lib/java/processing/opengl/cursors/arrow.png +0 -0
  105. data/lib/java/processing/opengl/cursors/cross.png +0 -0
  106. data/lib/java/processing/opengl/cursors/hand.png +0 -0
  107. data/lib/java/processing/opengl/cursors/license.txt +27 -0
  108. data/lib/java/processing/opengl/cursors/move.png +0 -0
  109. data/lib/java/processing/opengl/cursors/text.png +0 -0
  110. data/lib/java/processing/opengl/cursors/wait.png +0 -0
  111. data/lib/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
  112. data/lib/java/processing/opengl/shaders/ColorVert.glsl +34 -0
  113. data/lib/java/processing/opengl/shaders/LightFrag.glsl +33 -0
  114. data/lib/java/processing/opengl/shaders/LightVert.glsl +151 -0
  115. data/lib/java/processing/opengl/shaders/LineFrag.glsl +32 -0
  116. data/lib/java/processing/opengl/shaders/LineVert.glsl +100 -0
  117. data/lib/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
  118. data/lib/java/processing/opengl/shaders/PointFrag.glsl +32 -0
  119. data/lib/java/processing/opengl/shaders/PointVert.glsl +56 -0
  120. data/lib/java/processing/opengl/shaders/TexFrag.glsl +37 -0
  121. data/lib/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
  122. data/lib/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
  123. data/lib/java/processing/opengl/shaders/TexVert.glsl +38 -0
  124. data/lib/java/processing/pdf/PGraphicsPDF.java +581 -0
  125. data/lib/java/processing/svg/PGraphicsSVG.java +378 -0
  126. data/lib/propane/app.rb +8 -13
  127. data/lib/propane/version.rb +1 -1
  128. data/mvnw +3 -3
  129. data/mvnw.cmd +2 -2
  130. data/pom.rb +7 -2
  131. data/pom.xml +14 -2
  132. data/propane.gemspec +2 -2
  133. data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
  134. data/src/main/java/monkstone/MathToolModule.java +30 -30
  135. data/src/main/java/monkstone/PropaneLibrary.java +2 -0
  136. data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
  137. data/src/main/java/monkstone/fastmath/DegLutTables.java +15 -15
  138. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  139. data/src/main/java/monkstone/noise/OpenSimplex2F.java +752 -820
  140. data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -1106
  141. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  142. data/src/main/java/monkstone/vecmath/JRender.java +6 -6
  143. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +20 -19
  144. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +12 -12
  145. data/src/main/java/processing/awt/PGraphicsJava2D.java +11 -3
  146. data/src/main/java/processing/core/PApplet.java +89 -89
  147. data/src/main/java/processing/core/PConstants.java +155 -163
  148. data/src/main/java/processing/opengl/PJOGL.java +6 -5
  149. data/vendors/Rakefile +1 -1
  150. metadata +136 -19
@@ -0,0 +1,164 @@
1
+ /*
2
+ * Copyright (c) 2015-20 Martin Prout
3
+ *
4
+ * This library is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 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 Lesser 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
+ public class CustomHorizontalSlider extends SliderBar {
26
+
27
+ /**
28
+ *
29
+ * @param outer
30
+ * @param x top left position x
31
+ * @param y left top position y
32
+ * @param length width or height
33
+ * @param beginRange start range
34
+ * @param endRange end range
35
+ * @param label widget label/ID
36
+ */
37
+ public CustomHorizontalSlider(final PApplet outer, int x, int y, int length, float beginRange, float endRange, String label) {
38
+ this.applet = outer;
39
+ this.scrollWheelHandler = (short delta) -> {
40
+ changeWithWheel(delta);
41
+ };
42
+ setActive(true);
43
+ pX = x;
44
+ pY = y;
45
+ pW = length;
46
+ pH = 10;
47
+ ID = label;
48
+ limits(beginRange, endRange);
49
+ }
50
+
51
+ @Override
52
+ boolean mouseOver() {
53
+ return (applet.mouseX >= pX && applet.mouseX <= pX + pW && applet.mouseY >= pY && applet.mouseY <= pY + pH);
54
+ }
55
+
56
+ private void setActive(boolean active) {
57
+ if (active) {
58
+ applet.registerMethod("dispose", this);
59
+ applet.registerMethod("draw", this);
60
+ applet.registerMethod("mouseEvent", this);
61
+ } else {
62
+ applet.unregisterMethod("draw", this);
63
+ applet.unregisterMethod("mouseEvent", this);
64
+ }
65
+ }
66
+
67
+ @Override
68
+ void displayText() {
69
+ String lFormat = "%d";
70
+ if (displayLabel) {
71
+ applet.fill(labelColor);
72
+ applet.textSize(labelSize);
73
+ applet.textAlign(PConstants.CENTER);
74
+ applet.text(Integer.toString((int) pValue), pX + pW / 2, pY + pH / 2 + labelSize / 2 - 2);
75
+ }
76
+ if (displayValue) {
77
+ applet.textSize(numberSize);
78
+ applet.fill(numbersColor);
79
+ applet.textAlign(PConstants.LEFT);
80
+ applet.text(String.format(lFormat, (int) vMin), pX, pY - numberSize / 2);
81
+ applet.textAlign(PConstants.RIGHT);
82
+ applet.text(String.format(lFormat, (int) vMax), pX + pW, pY - numberSize / 2);
83
+ }
84
+ }
85
+
86
+ @Override
87
+ void drawGui() {
88
+ if (backgroundVisible) {
89
+ applet.fill(sliderBack);
90
+ applet.rect(pX, pY, pW, pH);
91
+ }
92
+ applet.fill(sliderFill);
93
+ applet.rect(pX, pY, pScaled, pH);
94
+ }
95
+
96
+ /**
97
+ *
98
+ * @param value
99
+ */
100
+ @Override
101
+ public void setValue(float value) {
102
+ if (value > vMax) {
103
+ value = vMax;
104
+ }
105
+ if (value < vMin) {
106
+ value = vMin;
107
+ }
108
+ pValue = value;
109
+ pScaled = map(pValue, vMin, vMax, 0, pW);
110
+ }
111
+
112
+ @Override
113
+ void checkKeyboard() {
114
+ if (mouseOver()) {
115
+ if (applet.mousePressed && applet.mouseButton == PConstants.LEFT) {
116
+ pValue = constrainMap(applet.mouseX - pX, 0, pW, vMin, vMax);
117
+ }
118
+ if (applet.keyPressed && pressOnlyOnce) {
119
+ if (applet.keyCode == PConstants.LEFT || applet.keyCode == PConstants.DOWN) {
120
+ pValue--;
121
+ }
122
+ if (applet.keyCode == PConstants.RIGHT || applet.keyCode == PConstants.UP) {
123
+ pValue++;
124
+ }
125
+ if (pValue > vMax) {
126
+ pValue = vMax;
127
+ } else {
128
+ pValue = (pValue < vMin) ? vMin : pValue;
129
+ }
130
+ pressOnlyOnce = false;
131
+ }
132
+ deBounce(5);
133
+ pScaled = map(pValue, vMin, vMax, 0, pW);
134
+ }
135
+ }
136
+
137
+ /**
138
+ *
139
+ * @param delta
140
+ */
141
+ @Override
142
+ public void changeWithWheel(int delta) {
143
+ if (!mouseOver()) {
144
+ return;
145
+ }
146
+ if (applet.keyPressed && applet.keyCode == PConstants.SHIFT) {
147
+ delta = delta * (int) (vMax / 10);
148
+ }
149
+ if (applet.keyPressed && applet.keyCode == PConstants.CONTROL) {
150
+ delta = delta * (int) (vMax / 4);
151
+ }
152
+ setValue(pValue + delta);
153
+ }
154
+
155
+ /**
156
+ *
157
+ * @return
158
+ */
159
+ @Override
160
+ public String toString() {
161
+ String geomF = "HorizontalSliderBar.new(%d, %d, %d, %.2f, %.2f, \"%s\")";
162
+ return String.format(geomF, pX, pY, pW, vMin, vMax, ID);
163
+ }
164
+ }
@@ -0,0 +1,178 @@
1
+ /*
2
+ * Copyright (c) 2015-20 Martin Prout
3
+ *
4
+ * This library is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 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 Lesser 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
+ public class CustomVerticalSlider extends SliderBar {
27
+
28
+ /**
29
+ *
30
+ * @param outer
31
+ * @param x top left position x
32
+ * @param y left top position y
33
+ * @param length width or height
34
+ * @param beginRange start range
35
+ * @param endRange end range
36
+ * @param label widget label/ID
37
+ */
38
+ public CustomVerticalSlider(final PApplet outer, int x, int y, int length, float beginRange, float endRange, String label) {
39
+ this.applet = outer;
40
+ this.scrollWheelHandler = (short delta) -> {
41
+ changeWithWheel(delta);
42
+ };
43
+ setActive(true);
44
+ pX = x;
45
+ pY = y;
46
+ pW = length;
47
+ pH = 10;
48
+ ID = label;
49
+ limits(beginRange, endRange);
50
+ }
51
+
52
+ @Override
53
+ boolean mouseOver() {
54
+ return (applet.mouseX >= pX && applet.mouseX <= pX + pH && applet.mouseY >= pY && applet.mouseY <= pY + pW);
55
+ }
56
+
57
+ private void setActive(boolean active) {
58
+ if (active) {
59
+ applet.registerMethod("dispose", this);
60
+ applet.registerMethod("draw", this);
61
+ applet.registerMethod("mouseEvent", this);
62
+ } else {
63
+ applet.unregisterMethod("draw", this);
64
+ applet.unregisterMethod("mouseEvent", this);
65
+ }
66
+ }
67
+
68
+ @Override
69
+ void displayText() {
70
+ String lFormat = "%d";
71
+ if (displayLabel) {
72
+ applet.fill(labelColor);
73
+ applet.textSize(labelSize);
74
+ applet.textAlign(PConstants.CENTER);
75
+ applet.pushMatrix();
76
+ applet.translate(pX + pH / 2, pY + pW / 2);
77
+ applet.rotate(HALF_PI);
78
+ applet.text(Integer.toString((int) pValue), 0, 0 + labelSize / 2 - 2);
79
+ applet.popMatrix();
80
+ }
81
+ if (displayValue) {
82
+ applet.textSize(numberSize);
83
+ applet.fill(numbersColor);
84
+ applet.pushMatrix();
85
+ applet.textAlign(PConstants.RIGHT);
86
+ applet.translate(pX - numberSize / 2, pY);
87
+ applet.rotate(HALF_PI);
88
+ applet.text(String.format(lFormat, (int) vMax), 0, 0);
89
+ applet.popMatrix();
90
+ applet.pushMatrix();
91
+ applet.textAlign(PConstants.LEFT);
92
+ applet.translate(pX - numberSize / 2, pY + pW);
93
+ applet.rotate(HALF_PI);
94
+ applet.text(String.format(lFormat, (int) vMin), 0, 0);
95
+ applet.popMatrix();
96
+ }
97
+ }
98
+
99
+ @Override
100
+ void drawGui() {
101
+ if (backgroundVisible) {
102
+ applet.fill(sliderBack);
103
+ applet.rect(pX, pY, pH, pW);
104
+ }
105
+ applet.fill(sliderFill);
106
+ applet.rect(pX, pY + pW, pH, pScaled - pW);
107
+ }
108
+
109
+ /**
110
+ *
111
+ * @param value
112
+ */
113
+ @Override
114
+ public void setValue(float value) {
115
+ if (value > vMax) {
116
+ value = vMax;
117
+ }
118
+ if (value < vMin) {
119
+ value = vMin;
120
+ }
121
+ pValue = value;
122
+ pScaled = map(pValue, vMin, vMax, pW, 0);
123
+ }
124
+
125
+ @Override
126
+ void checkKeyboard() {
127
+ if (mouseOver()) {
128
+ if (applet.mousePressed && applet.mouseButton == PConstants.LEFT) {
129
+ pValue = constrainMap(applet.mouseY - pY, pW, 0, vMin, vMax);
130
+ }
131
+ if (applet.keyPressed && pressOnlyOnce) {
132
+ if (applet.keyCode == PConstants.LEFT || applet.keyCode == PConstants.DOWN) {
133
+ pValue--;
134
+ }
135
+ if (applet.keyCode == PConstants.RIGHT || applet.keyCode == PConstants.UP) {
136
+ pValue++;
137
+ }
138
+ if (pValue > vMax) {
139
+ pValue = vMax;
140
+ } else {
141
+ pValue = (pValue < vMin) ? vMin : pValue;
142
+ }
143
+ pressOnlyOnce = false;
144
+ }
145
+ deBounce(5);
146
+ pScaled = map(pValue, vMin, vMax, pW, 0);
147
+ }
148
+ }
149
+
150
+ /**
151
+ *
152
+ * @param delta
153
+ */
154
+ @Override
155
+ public void changeWithWheel(int delta) {
156
+ if (!mouseOver()) {
157
+ return;
158
+ }
159
+ if (applet.keyPressed && applet.keyCode == PConstants.SHIFT) {
160
+ delta = delta * (int) (vMax / 10);
161
+ }
162
+ if (applet.keyPressed && applet.keyCode == PConstants.CONTROL) {
163
+ delta = delta * (int) (vMax / 4);
164
+ }
165
+ setValue(pValue - delta);
166
+ }
167
+
168
+ /**
169
+ *
170
+ * @return
171
+ */
172
+ @Override
173
+ public String toString() {
174
+ String geomF = "VerticalSliderBar.new(%d, %d, %d, %.2f, %.2f, \"%s\")";
175
+ return String.format(geomF, pX, pY, pW, vMin, vMax, ID);
176
+ }
177
+
178
+ }
@@ -0,0 +1,145 @@
1
+ /*
2
+ * Copyright (c) 2015-20 Martin Prout
3
+ *
4
+ * This library is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 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 Lesser 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
+ public class SimpleHorizontalSlider extends SimpleSlider {
26
+
27
+ final int SPACING = 20;
28
+ final int LEFT_SPC = SPACING * 2;
29
+ final int RIGHT_SPC = SPACING * 4;
30
+
31
+ /**
32
+ *
33
+ * @param outer
34
+ * @param beginRange start range
35
+ * @param endRange end range
36
+ * @param initial
37
+ * @param count
38
+ */
39
+ public SimpleHorizontalSlider(final PApplet outer, float beginRange, float endRange, float initial, int count) {
40
+ this.applet = outer;
41
+ setActive(true);
42
+ pX = LEFT_SPC;
43
+ pY = outer.height - SPACING - (count * SPACING);
44
+ pW = outer.width - RIGHT_SPC;
45
+ pH = 10;
46
+ ID = Integer.toString(count + 1);
47
+ limits(beginRange, endRange);
48
+ setValue(initial);
49
+ }
50
+
51
+ @Override
52
+ boolean mouseOver() {
53
+ return (applet.mouseX >= pX && applet.mouseX <= pX + pW && applet.mouseY >= pY && applet.mouseY <= pY + pH);
54
+ }
55
+
56
+ private void setActive(boolean active) {
57
+ if (active) {
58
+ applet.registerMethod("dispose", this);
59
+ applet.registerMethod("draw", this);
60
+ } else {
61
+ applet.unregisterMethod("draw", this);
62
+ }
63
+ }
64
+
65
+ @Override
66
+ void displayText() {
67
+ String lFormat = "%d";
68
+ if (displayLabel) {
69
+ applet.fill(labelColor);
70
+ applet.textSize(labelSize);
71
+ applet.textAlign(PConstants.BOTTOM);
72
+ applet.text(Integer.toString((int) pValue), pX + pW / 2, pY + pH);
73
+ }
74
+ if (displayValue) {
75
+ applet.textSize(numberSize);
76
+ applet.fill(numbersColor);
77
+ applet.textAlign(PConstants.LEFT);
78
+ applet.text(String.format(lFormat, (int) vMin), pX, pY);
79
+ applet.textAlign(PConstants.RIGHT);
80
+ applet.text(String.format(lFormat, (int) vMax), pX + pW, pY);
81
+ }
82
+ }
83
+
84
+ @Override
85
+ void drawGui() {
86
+ if (backgroundVisible) {
87
+ applet.stroke(sliderBack);
88
+ applet.line(pX, pY + pH / 2, pX + pW, pY + pH / 2);
89
+ }
90
+ applet.noStroke();
91
+ applet.fill(255);
92
+ applet.ellipse(pX + pScaled, pY + pH / 2, 10, 10);
93
+ }
94
+
95
+ /**
96
+ *
97
+ * @param value
98
+ */
99
+ @Override
100
+ public final void setValue(float value) {
101
+ if (value > vMax) {
102
+ value = vMax;
103
+ }
104
+ if (value < vMin) {
105
+ value = vMin;
106
+ }
107
+ pValue = value;
108
+ pScaled = map(pValue, vMin, vMax, 0, pW);
109
+ }
110
+
111
+ @Override
112
+ void checkKeyboard() {
113
+ if (mouseOver()) {
114
+ if (applet.mousePressed && applet.mouseButton == PConstants.LEFT) {
115
+ pValue = constrainMap(applet.mouseX - pX, 0, pW, vMin, vMax);
116
+ }
117
+ if (applet.keyPressed && pressOnlyOnce) {
118
+ if (applet.keyCode == PConstants.LEFT || applet.keyCode == PConstants.DOWN) {
119
+ pValue--;
120
+ }
121
+ if (applet.keyCode == PConstants.RIGHT || applet.keyCode == PConstants.UP) {
122
+ pValue++;
123
+ }
124
+ if (pValue > vMax) {
125
+ pValue = vMax;
126
+ } else {
127
+ pValue = (pValue < vMin) ? vMin : pValue;
128
+ }
129
+ pressOnlyOnce = false;
130
+ }
131
+ deBounce(5);
132
+ pScaled = map(pValue, vMin, vMax, 0, pW);
133
+ }
134
+ }
135
+
136
+ /**
137
+ *
138
+ * @return
139
+ */
140
+ @Override
141
+ public String toString() {
142
+ String geomF = "SimpleHSliderBar.new(%d, %d, %d, %.2f, %.2f, \"%s\")";
143
+ return String.format(geomF, pX, pY, pW, vMin, vMax, ID);
144
+ }
145
+ }