Skip to content

Commit bdb46b7

Browse files
committed
Commit: 1.0
1 parent e4310de commit bdb46b7

File tree

4 files changed

+459
-0
lines changed

4 files changed

+459
-0
lines changed

src/processing/Button.java

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package processing;
2+
3+
import processing.core.PVector;
4+
import processing.core.PApplet;
5+
6+
public class Button extends PApplet {
7+
public Button(PApplet pApplet) {
8+
this.text = text;
9+
this.width = 10;
10+
this.height = 10;
11+
this.backgroundColor = color(255, 255, 255);
12+
this.backgroundSelected = color(150);
13+
this.borderColor = color(0, 0, 0);
14+
this.pos = new PVector(0, 0);
15+
this.pApplet = pApplet;
16+
}
17+
18+
private PApplet pApplet;
19+
private PVector pos;
20+
private String text;
21+
private String id;
22+
private float width;
23+
private float height;
24+
private int backgroundColor;
25+
private int borderColor;
26+
private int backgroundSelected;
27+
28+
boolean pressed;
29+
boolean clicked;
30+
31+
public void setText(String text) {
32+
this.text = text;
33+
}
34+
35+
public String getText() {
36+
return this.text;
37+
}
38+
39+
public void setId(String id) {
40+
this.id = id;
41+
}
42+
43+
public String getId() {
44+
return this.id;
45+
}
46+
47+
public void setWidth(float width) {
48+
this.width = width;
49+
}
50+
51+
public float getWidth() {
52+
return this.width;
53+
}
54+
55+
public void setHeight(float height) {
56+
this.height = height;
57+
}
58+
59+
public float getHeight() {
60+
return this.height;
61+
}
62+
63+
public void setSize(float width, float height) {
64+
this.width = width;
65+
this.height = height;
66+
}
67+
68+
public void setX(float x) {
69+
this.pos.x = x;
70+
}
71+
72+
public float getX() {
73+
return this.pos.x;
74+
}
75+
76+
public void setY(float y) {
77+
this.pos.y = y;
78+
}
79+
80+
public float getY() {
81+
return this.pos.y;
82+
}
83+
84+
public void setBackgroundColor(int r, int g, int b) {
85+
backgroundColor = color(r, g, b);
86+
}
87+
88+
public void setBorderColor(int r, int g, int b) {
89+
borderColor = color(r, g, b);
90+
}
91+
92+
public void render() {
93+
pApplet.stroke(borderColor);
94+
95+
if (hovering()) {
96+
pApplet.fill(backgroundSelected);
97+
}
98+
99+
else {
100+
pApplet.fill(backgroundColor);
101+
}
102+
103+
pApplet.rect(pos.x, pos.y, width, height);
104+
105+
pApplet.textAlign(CENTER, CENTER);
106+
pApplet.fill(0);
107+
pApplet.text(text, pos.x + (width / 2), pos.y + (height / 2));
108+
109+
}
110+
111+
public void setPadding(float top, float left, float bottom, float right) {
112+
pos.x += left;
113+
pos.x -= right;
114+
pos.y += top;
115+
pos.y -= bottom;
116+
}
117+
118+
public void cursorTouched() {
119+
if (hovering()) {
120+
mouseOver();
121+
}
122+
123+
render();
124+
}
125+
126+
private boolean hovering() {
127+
return pApplet.mouseX >= pos.x && pApplet.mouseX <= (pos.x + this.width)
128+
&& pApplet.mouseY >= pos.y && pApplet.mouseY <= (pos.y + this.height);
129+
}
130+
131+
private void mouseOver() {
132+
pApplet.cursor(HAND);
133+
}
134+
135+
public void setOnClickedAction() {
136+
137+
};
138+
}

src/processing/TextBox.java

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
package processing;
2+
3+
import processing.core.PApplet;
4+
import processing.core.PVector;
5+
6+
public class TextBox extends PApplet {
7+
public TextBox(PApplet pApplet) {
8+
this.pApplet = pApplet;
9+
10+
text = "";
11+
id = "textbox";
12+
pos = new PVector(0, 0);
13+
backgroundColor = color(255);
14+
width = 10;
15+
height = 10;
16+
borderColor = color(255, 255, 255);
17+
backgroundSelected = color(150);
18+
textLength = 0;
19+
}
20+
21+
private PApplet pApplet;
22+
private PVector pos;
23+
private String text;
24+
private String id;
25+
private float width;
26+
private float height;
27+
private int backgroundColor;
28+
private int textLength;
29+
private int backgroundSelected;
30+
private int borderColor;
31+
32+
private boolean selected;
33+
34+
public String getText() {
35+
return text;
36+
}
37+
38+
public void setText(String text) {
39+
this.text = text;
40+
}
41+
42+
public String getId() {
43+
return id;
44+
}
45+
46+
public void setId(String id) {
47+
this.id = id;
48+
}
49+
50+
public float getWidth() {
51+
return width;
52+
}
53+
54+
public void setWidth(float width) {
55+
this.width = width;
56+
}
57+
58+
public float getHeight() {
59+
return height;
60+
}
61+
62+
public void setHeight(float height) {
63+
this.height = height;
64+
}
65+
66+
public void setBackgroundColor(int r, int g, int b) {
67+
backgroundColor = color(r, g, b);
68+
}
69+
70+
public void setBorderColor(int r, int g, int b) {
71+
borderColor = color(r, g, b);
72+
}
73+
74+
public void setX(float x) {
75+
this.pos.x = x;
76+
}
77+
78+
public float getX() {
79+
return pos.x;
80+
}
81+
82+
public void setY(float y) {
83+
this.pos.y = y;
84+
}
85+
86+
public float getY() {
87+
return pos.y;
88+
}
89+
90+
public void setPadding(float top, float left, float bottom, float right) {
91+
pos.x += left;
92+
pos.x -= right;
93+
pos.y += top;
94+
pos.y -= bottom;
95+
}
96+
97+
public void render() {
98+
if (selected || hovering()) {
99+
pApplet.fill(backgroundSelected);
100+
}
101+
102+
else {
103+
pApplet.fill(backgroundColor);
104+
}
105+
106+
pApplet.rect(pos.x, pos.y, width, height);
107+
108+
pApplet.fill(0);
109+
pApplet.text(text, pos.x + width / 2, pos.y + height / 2);
110+
}
111+
112+
public boolean keyPressed(char key, int keycode) {
113+
if (selected) {
114+
if (keycode == (int) BACKSPACE) {
115+
backspace();
116+
}
117+
118+
else if (keycode == 32) {
119+
addText(' ');
120+
}
121+
122+
else if (keycode == (int) ENTER) {
123+
return true;
124+
}
125+
126+
else {
127+
boolean isKeyCapitalLetter = (key >= 'A' && key <= 'Z');
128+
boolean isKeySmallLetter = (key >= 'a' && key <= 'z');
129+
boolean isKeyNumber = (key >= '0' && key <= '9');
130+
131+
if (isKeyCapitalLetter || isKeySmallLetter || isKeyNumber) {
132+
addText(key);
133+
}
134+
}
135+
136+
render();
137+
}
138+
139+
return false;
140+
}
141+
142+
private void addText(char text) {
143+
if (pApplet.textWidth(this.text + text) < width) {
144+
this.text += text;
145+
textLength++;
146+
}
147+
}
148+
149+
private void backspace() {
150+
if (textLength - 1 >= 0) {
151+
text = text.substring(0, textLength - 1);
152+
textLength--;
153+
}
154+
}
155+
156+
private boolean overBox(float x, float y) {
157+
return x >= pos.x && x <= (pos.x + this.width)
158+
&& y >= pos.y && y <= (pos.y + this.height);
159+
}
160+
161+
public void pressed(float x, float y) {
162+
selected = overBox(x, y);
163+
render();
164+
}
165+
166+
public void cursorTouched() {
167+
if (hovering()) {
168+
mouseOver();
169+
}
170+
171+
render();
172+
}
173+
174+
private boolean hovering() {
175+
return pApplet.mouseX >= pos.x && pApplet.mouseX <= (pos.x + this.width)
176+
&& pApplet.mouseY >= pos.y && pApplet.mouseY <= (pos.y + this.height);
177+
}
178+
179+
private void mouseOver() {
180+
pApplet.cursor(HAND);
181+
}
182+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package processing.tree;
2+
3+
4+
import processing.core.PApplet;
5+
6+
public class BinarySearchTree<T extends Comparable<T>> extends PApplet {
7+
public BinarySearchTree() {
8+
this.root = null;
9+
}
10+
11+
TreeNode<T> root;
12+
13+
public void add(T data) {
14+
root = add(root, data, width / 2, 25);
15+
}
16+
17+
private TreeNode<T> add(TreeNode<T> node, T data, float x, float y) {
18+
if (root == null) {
19+
return new TreeNode<T> (data, x, y);
20+
}
21+
22+
if (node == null) {
23+
return new TreeNode<T> (data, x, y);
24+
}
25+
26+
if (data.compareTo(node.getData()) < 0) {
27+
line(x, y, node.getX() - 50, node.getY() + 40);
28+
node.setLeft(add(node.getLeft(), data, node.getX() - 50, node.getY() + 40));
29+
}
30+
31+
else if (data.compareTo(node.getData()) > 0) {
32+
line(x, y, node.getX() + 50, node.getY() + 40);
33+
node.setRight(add(node.getRight(), data, node.getX() + 50, node.getY() + 40));
34+
}
35+
36+
return node;
37+
}
38+
39+
public void delete(T data) {
40+
root = delete(root, data);
41+
}
42+
43+
private TreeNode<T> delete(TreeNode<T> node, T data) {
44+
if (node == null) {
45+
return node;
46+
}
47+
48+
if (data.compareTo(node.getData()) < 0) {
49+
node.setLeft(delete(node.getLeft(), data));
50+
}
51+
52+
else if (data.compareTo(node.getData()) > 0) {
53+
node.setRight(delete(node.getRight(), data));
54+
}
55+
56+
else {
57+
if (node.getLeft() == null && node.getRight() == null) {
58+
return null;
59+
}
60+
61+
else if (node.getLeft() != null && node.getRight() != null) {
62+
63+
}
64+
65+
else if (node.getLeft() == null) {
66+
return node.getRight();
67+
}
68+
69+
else if (node.getRight() == null) {
70+
return node.getLeft();
71+
}
72+
}
73+
74+
return node;
75+
}
76+
}

0 commit comments

Comments
 (0)