|
1 | 1 | // Processing_api.h |
2 | 2 | // Included in user-defined classes that don't inherit from PApplet. |
3 | | -// Provides access to sketch state via g_papplet singleton. |
4 | | -// Most free functions (fill, stroke, rect, sin, cos, etc.) come from Processing.h. |
| 3 | +// Most free functions come from Processing.h (included below). |
| 4 | +// This file only adds sketch state accessors that require g_papplet. |
5 | 5 | #pragma once |
6 | 6 | #include "Processing.h" |
7 | 7 | #include <string> |
8 | 8 |
|
9 | | -// ── Sketch state accessors (require g_papplet) ──────────────────────────────── |
10 | | -inline int width() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->logicalW : 0; } |
11 | | -inline int height() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->logicalH : 0; } |
12 | | -inline float mouseX() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->mouseX : 0.f; } |
13 | | -inline float mouseY() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->mouseY : 0.f; } |
14 | | -inline float pmouseX() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->pmouseX : 0.f; } |
15 | | -inline float pmouseY() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->pmouseY : 0.f; } |
16 | | -inline int frameCount() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->frameCount : 0; } |
17 | | -inline char key() { return ::Processing::PApplet::g_papplet ? (char)::Processing::PApplet::g_papplet->key : 0; } |
18 | | -inline int keyCode() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->keyCode : 0; } |
19 | | -inline int mouseButton() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->mouseButton : 0; } |
20 | | -inline bool mousePressed() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->_mousePressed : false; } |
21 | | -inline bool keyPressed() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->_keyPressed : false; } |
22 | | -inline float frameRate() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->_frameRate : 0.f; } |
23 | | -inline float mouseDX() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->mouseDX : 0.f; } |
24 | | -inline float mouseDY() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->mouseDY : 0.f; } |
25 | | -inline bool* getKeysDown() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->keysDown : nullptr; } |
26 | | -inline bool* getMouseDown() { return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->mouseDown : nullptr; } |
| 9 | +using namespace ::Processing; |
| 10 | + |
| 11 | +// ── Sketch state accessors ──────────────────────────────────────────────────── |
| 12 | +inline int width() { return PApplet::g_papplet ? PApplet::g_papplet->logicalW : 0; } |
| 13 | +inline int height() { return PApplet::g_papplet ? PApplet::g_papplet->logicalH : 0; } |
| 14 | +inline float mouseX() { return PApplet::g_papplet ? PApplet::g_papplet->mouseX : 0.f; } |
| 15 | +inline float mouseY() { return PApplet::g_papplet ? PApplet::g_papplet->mouseY : 0.f; } |
| 16 | +inline float pmouseX() { return PApplet::g_papplet ? PApplet::g_papplet->pmouseX : 0.f; } |
| 17 | +inline float pmouseY() { return PApplet::g_papplet ? PApplet::g_papplet->pmouseY : 0.f; } |
| 18 | +inline int frameCount() { return PApplet::g_papplet ? PApplet::g_papplet->frameCount : 0; } |
| 19 | +inline char key() { return PApplet::g_papplet ? (char)PApplet::g_papplet->key : 0; } |
| 20 | +inline int keyCode() { return PApplet::g_papplet ? PApplet::g_papplet->keyCode : 0; } |
| 21 | +inline int mouseButton() { return PApplet::g_papplet ? PApplet::g_papplet->mouseButton : 0; } |
| 22 | +inline bool mousePressed() { return PApplet::g_papplet ? PApplet::g_papplet->_mousePressed : false; } |
| 23 | +inline bool keyPressed() { return PApplet::g_papplet ? PApplet::g_papplet->_keyPressed : false; } |
| 24 | +inline float frameRate() { return PApplet::g_papplet ? PApplet::g_papplet->_frameRate : 0.f; } |
| 25 | +inline float mouseDX() { return PApplet::g_papplet ? PApplet::g_papplet->mouseDX : 0.f; } |
| 26 | +inline float mouseDY() { return PApplet::g_papplet ? PApplet::g_papplet->mouseDY : 0.f; } |
| 27 | +inline bool* getKeysDown() { return PApplet::g_papplet ? PApplet::g_papplet->keysDown : nullptr; } |
| 28 | +inline bool* getMouseDown() { return PApplet::g_papplet ? PApplet::g_papplet->mouseDown : nullptr; } |
27 | 29 | inline bool isKeyDown(int k) { |
28 | | - if(!::Processing::PApplet::g_papplet||k<0||k>=256) return false; |
29 | | - return ::Processing::PApplet::g_papplet->keysDown[k]; |
30 | | -} |
31 | | -inline ::std::vector<::std::string> loadStrings(const ::std::string& p) { |
32 | | - return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->loadStrings(p) : ::std::vector<::std::string>{}; |
33 | | -} |
34 | | -inline ::std::vector<unsigned char> loadBytes(const ::std::string& p) { |
35 | | - return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->loadBytes(p) : ::std::vector<unsigned char>{}; |
36 | | -} |
37 | | -inline JSONValue loadJSON(const ::std::string& p) { |
38 | | - static JSONValue e; return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->loadJSON(p) : e; |
39 | | -} |
40 | | -inline Table* loadTable(const ::std::string& p, const ::std::string& opts="") { |
41 | | - return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->loadTable(p,opts) : nullptr; |
42 | | -} |
43 | | -inline XML loadXML(const ::std::string& p) { |
44 | | - return ::Processing::PApplet::g_papplet ? ::Processing::PApplet::g_papplet->loadXML(p) : XML(); |
| 30 | + if(!PApplet::g_papplet||k<0||k>=256) return false; |
| 31 | + return PApplet::g_papplet->keysDown[k]; |
45 | 32 | } |
0 commit comments