propane 0.5.0-java → 0.6.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +3 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/examples/complete/bw_shader.rb +46 -0
- data/examples/complete/data/bwfrag.glsl +23 -0
- data/examples/complete/data/lachoy.jpg +0 -0
- data/examples/complete/data/landscape.glsl +352 -0
- data/examples/complete/data/monjori.glsl +30 -0
- data/examples/complete/data/moon.jpg +0 -0
- data/examples/complete/data/sea.jpg +0 -0
- data/examples/complete/edge_detection.rb +49 -0
- data/examples/complete/landscape.rb +32 -0
- data/examples/complete/linear_image.rb +51 -0
- data/examples/complete/monjori.rb +33 -0
- data/examples/regular/arcball_box.rb +3 -1
- data/examples/regular/arcball_constrain.rb +38 -0
- data/examples/regular/bezier_playground.rb +205 -0
- data/examples/regular/colors_two.rb +61 -0
- data/examples/regular/creating_colors.rb +10 -3
- data/examples/regular/elegant_ball.rb +1 -1
- data/examples/regular/fibonacci_sphere.rb +90 -0
- data/examples/regular/grapher.rb +39 -0
- data/examples/regular/gravity.rb +120 -0
- data/examples/regular/slider_demo.rb +60 -0
- data/examples/regular/slider_example.rb +53 -0
- data/examples/regular/slider_simple.rb +47 -0
- data/examples/regular/tree.rb +76 -0
- data/lib/propane/app.rb +1 -6
- data/lib/propane/helper_methods.rb +39 -10
- data/lib/propane/version.rb +1 -1
- data/library/slider/slider.rb +43 -0
- data/pom.rb +4 -4
- data/pom.xml +4 -4
- data/propane.gemspec +1 -1
- data/src/monkstone/ColorUtil.java +42 -9
- data/src/monkstone/slider/CustomHorizontalSlider.java +164 -0
- data/src/monkstone/slider/CustomVerticalSlider.java +178 -0
- data/src/monkstone/slider/SimpleHorizontalSlider.java +145 -0
- data/src/monkstone/slider/SimpleSlider.java +175 -0
- data/src/monkstone/slider/SimpleVerticalSlider.java +159 -0
- data/src/monkstone/slider/Slider.java +61 -0
- data/src/monkstone/slider/SliderBar.java +245 -0
- data/src/monkstone/slider/SliderGroup.java +56 -0
- data/src/monkstone/slider/WheelHandler.java +35 -0
- data/src/monkstone/vecmath/vec2/Vec2.java +3 -8
- data/src/monkstone/vecmath/vec3/Vec3.java +8 -13
- data/vendors/Rakefile +2 -2
- metadata +36 -6
- data/VERSION.txt +0 -4
@@ -0,0 +1,178 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2016 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) 2016 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
|
+
}
|
@@ -0,0 +1,175 @@
|
|
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
|
+
@Override
|
49
|
+
public void draw() {
|
50
|
+
applet.pushStyle();
|
51
|
+
applet.noStroke();
|
52
|
+
drawGui();
|
53
|
+
displayText();
|
54
|
+
applet.popStyle();
|
55
|
+
change();
|
56
|
+
}
|
57
|
+
|
58
|
+
/**
|
59
|
+
*
|
60
|
+
*/
|
61
|
+
|
62
|
+
@Override
|
63
|
+
public void showLabel() {
|
64
|
+
displayLabel = true;
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
*
|
69
|
+
*/
|
70
|
+
|
71
|
+
@Override
|
72
|
+
public void hideLabel() {
|
73
|
+
displayLabel = false;
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
*
|
78
|
+
*/
|
79
|
+
|
80
|
+
@Override
|
81
|
+
public void showNumbers() {
|
82
|
+
displayValue = true;
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
*
|
87
|
+
*/
|
88
|
+
@Override
|
89
|
+
public void hideNumbers() {
|
90
|
+
displayValue = false;
|
91
|
+
}
|
92
|
+
|
93
|
+
void change() {
|
94
|
+
checkKeyboard();
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
*
|
99
|
+
*/
|
100
|
+
|
101
|
+
@Override
|
102
|
+
public void hideBackground() {
|
103
|
+
backgroundVisible = false;
|
104
|
+
}
|
105
|
+
|
106
|
+
/**
|
107
|
+
*
|
108
|
+
* @return
|
109
|
+
*/
|
110
|
+
|
111
|
+
@Override
|
112
|
+
public float readValue() {
|
113
|
+
return pValue;
|
114
|
+
}
|
115
|
+
|
116
|
+
abstract boolean mouseOver();
|
117
|
+
|
118
|
+
protected float map(float val, float begIn, float endIn, float beginOut, float endOut) {
|
119
|
+
return (beginOut + (endOut - beginOut) * ((val - begIn) / (endIn - begIn)));
|
120
|
+
}
|
121
|
+
|
122
|
+
final void limits(float iv, float fv) {
|
123
|
+
vMin = iv;
|
124
|
+
vMax = fv;
|
125
|
+
setValue(iv);
|
126
|
+
}
|
127
|
+
|
128
|
+
/**
|
129
|
+
*
|
130
|
+
* @param s
|
131
|
+
*/
|
132
|
+
|
133
|
+
@Override
|
134
|
+
public void labelSize(int s) {
|
135
|
+
labelSize = (s < 4) ? 4 : s;
|
136
|
+
}
|
137
|
+
|
138
|
+
void deBounce(int n) {
|
139
|
+
if (pressOnlyOnce) {
|
140
|
+
} else if (deb++ > n) {
|
141
|
+
deb = 0;
|
142
|
+
pressOnlyOnce = true;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
abstract void checkKeyboard();
|
147
|
+
|
148
|
+
|
149
|
+
protected int constrainMap(double val, double begIn, double endIn, double beginOut, double endOut) {
|
150
|
+
double max = Math.max(begIn, endIn);
|
151
|
+
double min = Math.min(begIn, endIn);
|
152
|
+
if (val < min) {
|
153
|
+
val = min;
|
154
|
+
}
|
155
|
+
if (val > max) {
|
156
|
+
val = max;
|
157
|
+
}
|
158
|
+
return (int) ((beginOut + (endOut - beginOut) * ((val - begIn) / (endIn - begIn))));
|
159
|
+
}
|
160
|
+
|
161
|
+
private void setActive(boolean active) {
|
162
|
+
if (active) {
|
163
|
+
applet.registerMethod("dispose", this);
|
164
|
+
applet.registerMethod("draw", this);
|
165
|
+
} else {
|
166
|
+
applet.unregisterMethod("draw", this);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
@Override
|
172
|
+
public void dispose() {
|
173
|
+
setActive(false);
|
174
|
+
}
|
175
|
+
}
|