-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzDesktop.pde
277 lines (228 loc) · 7.44 KB
/
zDesktop.pde
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// How to enable Desktop mode in your code:
// ctrl+a
// ctrl+/
// Yes. That's really now you do it.
// Make sure to do it to zAndroid too.
import com.jogamp.newt.opengl.GLWindow;
import java.awt.Toolkit;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.datatransfer.StringSelection;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.image.BufferedImage;
import java.awt.Desktop;
import javax.swing.JOptionPane;
import processing.soundde.*;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
// Sometimes it can be called if it's exclusive to android, and no action happens in Java mode.
// If calling said funciton affects how things work in Java mode, this should be used to warn,
// but not if it only does nothing.
private void shouldNotBeCalled(String funcitonName) {
timewayEngine.console.bugWarnOnce(funcitonName+": You should not call this in Java/Desktop mode!");
}
public boolean isLinux() {
return (platform == LINUX);
}
public boolean isWindows() {
return (platform == WINDOWS);
}
public boolean isMacOS() {
return (platform == MACOS);
}
public boolean isAndroid() {
return false;
}
public void setDesktopIcon(String iconPath) {
PJOGL.setIcon(iconPath);
}
public String sketchPath() {
return super.sketchPath();
}
protected PSurface initSurface() {
PSurface s = super.initSurface();
// Windows is annoying with maximised screens
// So let's do this hack to make the screen maximised.
boolean maximise = sketch_MAXIMISE;
if (maximise) {
if (platform == WINDOWS) {
try {
// Set maximised.
Object o = surface.getNative();
if (o instanceof GLWindow) {
GLWindow window = (GLWindow)o;
window.setMaximized(true, true);
}
}
catch (Exception e) {
sketch_openErrorLog(
"Maximise error. This is a bug."
);
}
}
}
s.setResizable(true);
return s;
}
protected void selectOutputSketch(String promptMessage, String outputFileSelected) {
// TODO: implement file selector.
super.selectOutput(promptMessage, outputFileSelected);
}
public Object getFromClipboardStringFlavour() {
return getFromClipboard(DataFlavor.stringFlavor);
}
public Object getFromClipboardImageFlavour() {
return getFromClipboard(DataFlavor.imageFlavor);
}
public Object getFromClipboard(DataFlavor flavor)
{
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents;
try {
contents = clipboard.getContents(null);
}
catch (IllegalStateException e) {
contents = null;
}
Object obj = null;
if (contents != null && contents.isDataFlavorSupported(flavor))
{
try
{
obj = contents.getTransferData(flavor);
}
catch (UnsupportedFlavorException exu) // Unlikely but we must catch it
{
timewayEngine.console.warn("(Copy/paste) Unsupported flavor");
//~ exu.printStackTrace();
}
catch (java.io.IOException exi)
{
timewayEngine.console.warn("(Copy/paste) Unavailable data: " + exi);
//~ exi.printStackTrace();
}
}
return obj;
}
@SuppressWarnings("deprecation")
public PImage getPImageFromClipboard()
{
PImage img = null;
java.awt.Image image = (java.awt.Image) getFromClipboard(DataFlavor.imageFlavor);
if (image != null)
{
img = new PImage(image);
}
return img;
}
public void copyStringToClipboard(String s) {
StringSelection stringSelection = new StringSelection(s);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
}
public void desktopOpen(String file) {
if (Desktop.isDesktopSupported()) {
// Open desktop app with this snippet of code that I stole.
try {
Desktop desktop = Desktop.getDesktop();
File myFile = new File(file);
try {
desktop.open(myFile);
}
catch (IllegalArgumentException fileNotFound) {
//timewayEngine.console.log("This file or dir no longer exists!");
timewayEngine.console.warn(fileNotFound.getMessage());
timewayEngine.file.refreshDir();
}
}
catch (IOException ex) {
timewayEngine.console.warn("Couldn't open file IOException");
}
} else {
timewayEngine.console.warn("Couldn't open file, isDesktopSupported=false.");
}
}
public void openErrorLog() {
if (Desktop.isDesktopSupported()) {
// Open desktop app with this snippet of code that I stole.
try {
Desktop desktop = Desktop.getDesktop();
File myFile = new File(sketch_ERR_LOG_PATH);
desktop.open(myFile);
}
catch (IOException ex) {
}
}
}
public void minimalErrorDialog(String mssg) {
JOptionPane.showMessageDialog(null,mssg,"Timeway" ,1);
}
public void requestAndroidPermissions() {
}
void openTouchKeyboard() {
}
void closeTouchKeyboard() {
}
public String getAndroidCacheDir() {
shouldNotBeCalled("getAndroidCacheDir");
return "";
}
public String getAndroidWriteableDir() {
shouldNotBeCalled("getAndroidWriteableDir");
return "";
}
//public PImage getDCaptureImage(DSCapture capture) {
//PImage img = createImage(capture.getDisplaySize().width, capture.getDisplaySize().height, RGB);
//BufferedImage bimg = capture.getImage();
//bimg.getRGB(0, 0, img.width, img.height, img.pixels, 0, img.width);
//img.updatePixels();
//return img;
// timewayEngine.console.bugWarn("getDCaptureImage just returns null");
// return null;
//}
//public int getDCaptureWidth(DSCapture capture) {
// return capture.getDisplaySize().width;
//}
//public int getDCaptureHeight(DSCapture capture) {
// return capture.getDisplaySize().height;
//}
public void openAndroidCamera() {
}
public void saveByteArrayAsWAV(byte[] audioData, int sampleRate, int bitDepth, int numChannels, String path) {
AudioFormat audioFormat = new AudioFormat(sampleRate, bitDepth, numChannels, true, false);
try {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(audioData);
AudioInputStream audioInputStream = new AudioInputStream(byteArrayInputStream, audioFormat, (audioData.length / 4) / numChannels);
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, new File(path));
} catch (IOException e) {
e.printStackTrace();
}
}
// In Java/Desktop mode, this class remains completely unused, we just
// have it here to keep Java complaining "WAHH MAH CLASSES ARE MISSENG";
public class AndroidMedia {
@SuppressWarnings("unused")
public AndroidMedia(String path) {
}
public void play() {
}
public void loop() {
}
public void pause() {
}
public void stop() {
}
@SuppressWarnings("unused")
public void volume(float vol) {
}
public boolean isPlaying() {
return false;
}
}