-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddTextObjectHUD.java
More file actions
167 lines (147 loc) · 4.35 KB
/
AddTextObjectHUD.java
File metadata and controls
167 lines (147 loc) · 4.35 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import processing.core.PApplet;
import processing.core.PImage;
public class AddTextObjectHUD extends HUDObject
{
private static final int NO_FOCUS = 0;
private static final int TEXT_FOCUS = 1;
private String txt;
private ObjectProvider objects;
private int mode;
private ColorConfiguration config;
private PImage popupNodeImage;
private Camera cam;
private ClipboardHelper clipboard;
AddTextObjectHUD(PApplet context, ObjectProvider objects, Camera cam)
{
this.context=context;
this.objects = objects;
this.cam = cam;
this.name = "AddTextObject";
this.active = true;
this.setPosition(context.width/2, context.height/2, 0);
this.mode = NO_FOCUS;
txt = "";
this.config = ((NetworkOfThoughts)context).config;
this.popupNodeImage = context.loadImage(config.popupNodeImage);
this.clipboard = new ClipboardHelper();
}
public void focus()
{
mode = TEXT_FOCUS;
this.cam.position.setDestination(new Point(0,-50,3000));
}
public void unfocus()
{
mode = NO_FOCUS;
txt="";
objects.setCurrentSearch("");
objects.deleteAllTemporaryObjects();
}
public boolean inFocus()
{
if(mode == NO_FOCUS)
{
return false;
}
else
{
return true;
}
}
public void charKeyStroke(char key)
{
if(inFocus())
{
NetworkOfThoughts castContext = (NetworkOfThoughts)this.context;
if ((key == 'v' || key == 'V') && castContext.controlKey)
{
txt += this.clipboard.getClipboardContents();
return;
}
if((key >= ' ' && (int)key != 65535))
{
txt += key;
if (key == ' ' || key == '.' || key == ',' || key == '!' || key == '?' || key == ':')
{
objects.setCurrentSearch(txt);
}
}
}
else if(key == 'n' || key == 'N')
{
mode = TEXT_FOCUS;
}
}
public void keyStroke(int keyCode)
{
if(inFocus() && txt != "" && keyCode == 10)
{
objects.addTextObject(txt);
txt = "";
objects.setCurrentSearch(txt);
mode = NO_FOCUS;
//this.objects.unSelectAll(); //WARNING: adds all temp thoughts into the world
//Deletes the temp objects for now
objects.deleteAllTemporaryObjects();
}
if(inFocus() && keyCode == 8)
{
if(txt.length() > 0)
txt = txt.substring(0, txt.length() - 1);
}
if(inFocus() && keyCode == 27)
{
mode = NO_FOCUS;
//this.objects.unSelectAll(); //WARNING: adds all temp thoughts into the world
txt = "";
objects.setCurrentSearch("");
objects.deleteAllTemporaryObjects();
if (objects.size() == 0)
{
objects.activateGlobalMenuMode();
}
}
}
public boolean hit(int x, int y)
{
//Deactivated because of picking.
//We need to be able to pick objects while in insert mode so I deactivate this and add escape key to exit the mode
/*if(inFocus())
{
mode = NO_FOCUS;
objects.setCurrentSearch("");
objects.deleteAllTemporaryObjects();
return true;
}
else
{
return false;
}*/
return false;
}
public void render()
{
if(inFocus())
{
ObjectCleaner cleaner = new ObjectCleaner();
String msg = cleaner.cleanTextObject(txt);
context.textSize(40);
context.textAlign(context.LEFT, context.TOP);
context.noStroke();
//HERE GOES THE IMAGE RENDERING
context.image(this.popupNodeImage, this.position.getPosition().x - 45 - context.textWidth(msg)/2, this.position.getPosition().y - 5, 40, 40);
// context.fill(config.popupNode);
// context.ellipse(this.position.getPosition().x - 20 - context.textWidth(msg)/2, this.position.getPosition().y + 10, 40, 40);
context.fill(config.popupText);
context.text(msg + "|", this.position.getPosition().x - context.textWidth(msg)/2, this.position.getPosition().y);
context.textAlign(context.LEFT);
//context.fill(255, 210);
//context.stroke(0);
//context.rect(context.width/2 - 150, context.height - 30, 300, 30);
//context.stroke(200);
//context.fill(0);
//context.textSize(15);
//context.text("Write your idea. press ENTER to send it.", context.width/2 - 140, context.height - 10); //COMMENT FOR MINIMAL INTERCFACE
}
}
}