-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathclipboardhandler.cpp
More file actions
262 lines (218 loc) · 6.12 KB
/
clipboardhandler.cpp
File metadata and controls
262 lines (218 loc) · 6.12 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
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
#include "prism/clipboardhandler.h"
#include <string.h>
#include <cstdarg>
#include "prism/mugentexthandler.h"
#include "prism/log.h"
#include "prism/system.h"
#include "prism/geometry.h"
namespace prism {
#define CLIPBOARD_LINE_AMOUNT 10
static struct {
int mLineAmount;
char mLines[CLIPBOARD_LINE_AMOUNT][1024];
int mTextIDs[CLIPBOARD_LINE_AMOUNT];
int mIsVisible;
} gPrismClipboardHandlerData;
void initClipboardForGame() {
memset(gPrismClipboardHandlerData.mLines, 0, sizeof gPrismClipboardHandlerData.mLines);
gPrismClipboardHandlerData.mLineAmount = 0;
gPrismClipboardHandlerData.mIsVisible = 0;
}
static void initClipboardLines() {
static const auto CLIPBOARD_FONT = -1;
double deltaY = getMugenFontSizeY(CLIPBOARD_FONT) + getMugenFontSpacingY(CLIPBOARD_FONT);
Position pos = Vector3D(20, 20, 90);
int i;
for (i = 0; i < CLIPBOARD_LINE_AMOUNT; i++) {
gPrismClipboardHandlerData.mTextIDs[i] = addMugenText("", pos, CLIPBOARD_FONT);
pos.y += deltaY;
}
}
static void setClipboardLineTexts() {
int i;
for (i = 0; i < gPrismClipboardHandlerData.mLineAmount; i++) {
if (gPrismClipboardHandlerData.mIsVisible) {
changeMugenText(gPrismClipboardHandlerData.mTextIDs[i], gPrismClipboardHandlerData.mLines[i]);
}
else {
changeMugenText(gPrismClipboardHandlerData.mTextIDs[i], "");
}
}
}
static void loadClipboardHandler(void* tData) {
(void)tData;
setProfilingSectionMarkerCurrentFunction();
initClipboardLines();
setClipboardLineTexts();
}
ActorBlueprint getClipboardHandler() {
return makeActorBlueprint(loadClipboardHandler);
}
static void moveClipboardLinesDown() {
int i;
for (i = 1; i < gPrismClipboardHandlerData.mLineAmount; i++) {
strcpy(gPrismClipboardHandlerData.mLines[i - 1], gPrismClipboardHandlerData.mLines[i]);
}
gPrismClipboardHandlerData.mLineAmount--;
}
void addClipboardLine(char* tLine) {
if (gPrismClipboardHandlerData.mLineAmount == CLIPBOARD_LINE_AMOUNT) {
moveClipboardLinesDown();
}
strcpy(gPrismClipboardHandlerData.mLines[gPrismClipboardHandlerData.mLineAmount], tLine);
gPrismClipboardHandlerData.mLineAmount++;
setClipboardLineTexts();
}
static void getArgumentTextAndAdvanceParams(char* tArgumentText, char** tParams) {
if (*tParams == NULL) {
tArgumentText[0] = '\0';
return;
}
char* nextComma = strchr(*tParams, ',');
if (nextComma) *nextComma = '\0';
sprintf(tArgumentText, "%s", *tParams);
*tParams = nextComma + 1;
}
static void parseParameterInput(const char* tFormatString, int* i, char** tDst, char** tParams) {
(*i)++;
while (isdigit(tFormatString[*i]) || tFormatString[*i] == '.') { // don't care about precision
(*i)++;
}
char identifier = tFormatString[*i];
char argumentText[300];
char parsedValue[300];
if (identifier == '%') {
**tDst = '%';
(*tDst)++;
return;
}
else if (identifier == 'd' || identifier == 'i') {
getArgumentTextAndAdvanceParams(argumentText, tParams);
int val = atoi(argumentText);
sprintf(parsedValue, "%d", val);
auto len = strlen(parsedValue);
memcpy(*tDst, parsedValue, len);
*tDst += len;
}
else if (identifier == 'f' || identifier == 'F') {
getArgumentTextAndAdvanceParams(argumentText, tParams);
double val = atof(argumentText);
sprintf(parsedValue, "%f", val);
auto len = strlen(parsedValue);
memcpy(*tDst, parsedValue, len);
*tDst += len;
}
else if (identifier == 'e' || identifier == 'E') {
getArgumentTextAndAdvanceParams(argumentText, tParams);
double val = atof(argumentText);
sprintf(parsedValue, "%e", val);
auto len = strlen(parsedValue);
memcpy(*tDst, parsedValue, len);
*tDst += len;
}
else if (identifier == 'g' || identifier == 'G') {
getArgumentTextAndAdvanceParams(argumentText, tParams);
double val = atof(argumentText);
sprintf(parsedValue, "%g", val);
auto len = strlen(parsedValue);
memcpy(*tDst, parsedValue, len);
*tDst += len;
}
else {
logWarning("Unrecognized parsing parameter");
logWarningString(&tFormatString[*i - 1]);
return;
}
}
static void parseLinebreak(char** tDst, char* tTextBuffer) {
**tDst = '\0';
addClipboardLine(tTextBuffer);
*tDst = tTextBuffer;
}
static void parseTab(char** tDst) {
int j;
for (j = 0; j < 4; j++) {
**tDst = ' ';
(*tDst)++;
}
}
static void parseFormatInput(const char* tFormatString, int* i, char** tDst, char* tTextBuffer) {
(*i)++;
char identifier = tFormatString[*i];
if (identifier == '\\') {
**tDst = '\\';
(*tDst)++;
}
else if (identifier == 't') {
parseTab(tDst);
}
else if (identifier == 'n') {
parseLinebreak(tDst, tTextBuffer);
}
else {
logError("Unrecognized format parameter");
logErrorString(&tFormatString[*i - 1]);
recoverFromError();
}
}
void addClipboardLineFormatString(const char* tFormatString, const char* tParameterString)
{
char text[1024];
char* dst;
char paramBuffer[200];
strcpy(paramBuffer, tParameterString);
char* param = paramBuffer;
dst = text;
auto len = int(strlen(tFormatString));
int i;
for (i = 0; i < len; i++) {
if (tFormatString[i] == '%') {
parseParameterInput(tFormatString, &i, &dst, ¶m);
}
else if (tFormatString[i] == '\\') {
parseFormatInput(tFormatString, &i, &dst, text);
}
else if (tFormatString[i] == '\n') {
parseLinebreak(&dst, text);
}
else if (tFormatString[i] == '\t') {
parseTab(&dst);
}
else {
*dst = tFormatString[i];
dst++;
}
}
*dst = '\0';
if (dst != text) {
addClipboardLine(text);
}
}
void clipf(char* tFormatString, ...) {
char text[1024];
va_list args;
va_start(args, tFormatString);
vsprintf(text, tFormatString, args);
va_end(args);
addClipboardLine(text);
}
void clearClipboard()
{
int i;
for (i = 0; i < gPrismClipboardHandlerData.mLineAmount; i++) {
gPrismClipboardHandlerData.mLines[i][0] = '\0';
}
setClipboardLineTexts();
gPrismClipboardHandlerData.mLineAmount = 0;
}
void setClipboardInvisible()
{
gPrismClipboardHandlerData.mIsVisible = 0;
setClipboardLineTexts();
}
void setClipboardVisible()
{
gPrismClipboardHandlerData.mIsVisible = 1;
setClipboardLineTexts();
}
}