-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuItem.java
More file actions
152 lines (133 loc) · 3.66 KB
/
MenuItem.java
File metadata and controls
152 lines (133 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import processing.core.PApplet;
import processing.core.PImage;
import picking.*;
class MenuItem extends Thing
{
protected String title;
protected PImage nodeImage;
protected PImage nodeHitImage;
protected ColorConfiguration config;
protected int tintColor;
protected MenuAction action;
protected Camera cam;
protected ThoughtMenu parent;
protected boolean hitState;
MenuItem(PApplet context, ThoughtMenu parent, String title, Camera cam)
{
this.context = context;
this.activate();
this.title = title;
this.config = ((NetworkOfThoughts)context).config;
this.nodeImage = context.loadImage(config.nodeMenuImage);
this.nodeHitImage = context.loadImage(config.nodeHitImage);
this.position = new PhysicalParameter(0,0,0,0,0,0);
this.resetPhysicsToDefault();
this.setAlpha(255);
//this.tintColor = context.color(context.random(0,255),context.random(0,255),context.random(0,255));
this.tintColor = context.color(255);
this.action = null;
this.cam = cam;
this.parent = parent;
this.hitState = false;
}
public void render(float x, float y, float z)
{
}
public void render(float x, float y)
{
}
public void setAction(MenuAction action)
{
this.action = action;
}
public void hitOn()
{
context.cursor(context.HAND);
this.hitState = true;
}
public void hitOff()
{
context.cursor(context.ARROW);
this.hitState = false;
}
public void setCurrentObject(Thing ob)
{
if (this.action != null)
{
this.action.setCurrentObject(ob);
}
}
public void unsetCurrentObject()
{
if (this.action != null)
{
this.action.unsetCurrentObject();
}
}
public void run()
{
if (this.action != null)
{
if(this.action.runAction())
{
parent.deactivate();
}
}
else
{
parent.deactivate();
}
}
public boolean isActive()
{
return true;
}
public void render()
{
if(this.active)
{
context.pushMatrix();
context.translate(0,0,this.position.getPosition().z);
context.tint(tintColor);
if(!this.hitState)
{
context.image(this.nodeImage, this.position.getPosition().x, this.position.getPosition().y, 7, 7);
}
else
{
context.image(this.nodeHitImage, this.position.getPosition().x, this.position.getPosition().y, 7, 7);
}
context.tint(255);
context.popMatrix();
this.context.textSize(6);
context.fill(context.red(config.text),context.green(config.text),context.blue(config.text),this.getAlpha());
this.context.text(title, this.position.getPosition().x - (context.textWidth(title) + 3), this.position.getPosition().y + 5, this.position.getPosition().z);
}
}
public void renderHitArea()
{
int height = 7;
int width = (int)context.textWidth(title) + 10;
context.fill(0,0,0,80);
context.pushMatrix();
context.translate(0,0,this.position.getPosition().z);
context.rect(this.position.getPosition().x - width + 7, this.position.getPosition().y, width, height);
context.popMatrix();
}
public void resetPhysicsToDefault()
{
this.position.setMaxSpeed((float)20);
this.position.setSpring((float)0);
this.position.setDrag((float)3);
}
public void renderHitArea(Buffer buffer)
{
cam.render(buffer);
int height = 7;
int width = (int)context.textWidth(title) + 10;
buffer.pushMatrix();
buffer.translate(0,0,this.position.getPosition().z);
buffer.rect(this.position.getPosition().x - width + 7, this.position.getPosition().y, width, height);
buffer.popMatrix();
}
}