/
QtUI.cpp
executable file
·356 lines (287 loc) · 9.67 KB
/
QtUI.cpp
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#include <iostream>
#include <stdarg.h>
#include "oma2UiIndependent/UI.h"
#include "qtoma2.h"
extern QtOma2* wPointer;
extern char reply[1024]; // buffer for sending messages to be typed out by the user interface
extern Image iBuffer; // the image buffer
extern ImageBitmap iBitmap; // the bitmap buffer
extern oma2UIData UIData;
// update the User Interface
//
// This is a way to update user interface values after a command
void update_UI(){
int* specs = iBuffer.getspecs();
DATAWORD* values= iBuffer.getvalues();
UIData.max = values[MAX];
UIData.min = values[MIN];
UIData.iscolor = specs[IS_COLOR];
UIData.rows = specs[ROWS];
UIData.cols = specs[COLS];
UIData.dx = specs[DX];
UIData.dy = specs[DY];
UIData.x0 = specs[X0];
UIData.y0 = specs[Y0];
static int current_pal = -1;
if (current_pal != UIData.thepalette) {
//[statusController updatePaletteBox];
current_pal = UIData.thepalette;
}
wPointer->updateStatus();
delete[] specs;
delete[] values;
}
void displayData(char* name){
wPointer->newData(name);
}
void labelDataMinMax(){
wPointer->addDataWindowMinMax();
}
void setWindowAlpha(float newAlpha){
wPointer->setWindowAlpha(newAlpha);
}
void labelData(char* args){
int line=0;
if(args[0] != '"'){ // doesn't start with quote, so goes in line 0
wPointer->addDataWindowLabel(args,line);
return;
}
char label[PREFIX_CHPERLN];
int i;
for(i=1; i<PREFIX_CHPERLN && args[i] != '"' && args[i] != 0; i++){
label[i-1]=args[i]; // find second quote OR end of string OR end of buffer
}
if(args[i] == 0 || i == PREFIX_CHPERLN)
wPointer->addDataWindowLabel(label,line);
else {
sscanf(&args[i+1],"%d",&line);
label[i-1]=0;
}
wPointer->addDataWindowLabel(label,line);
}
void eraseWindow(int n){
wPointer->eraseWindow(n);
}
BOOL dropped_file(char* extension, char* name){
int i;
/*
//printf("File ext is: %s\n",extension);
printf("File name is: %s\n",name);
for(int i=0; i<strlen(extension); i++)
extension[i] = toupper(extension[i]);
if(strcmp(extension, "DAT")==0 || strcmp(extension, "NEF")==0 || strcmp(extension, "JPG")==0
|| strcmp(extension, "TIF")==0 || strcmp(extension, "TIFF")==0 || strcmp(extension, "HDR")==0
|| strcmp(extension, "O2D")==0){
Image new_im(name,LONG_NAME);
if(new_im.err()){
beep();
printf("Could not load %s\n",name);
//[appController appendText: @"OMA2>"];
wPointer->addCString((char*)"OMA2>");
return NO;
}
iBuffer.free(); // release the old data
iBuffer = new_im; // this is the new data
iBuffer.getmaxx(PRINT_RESULT);
update_UI();
display(0,(char*)"");
//[appController appendText: @"OMA2>"];
wPointer->addCString((char*)"OMA2>");
return YES;
}
*/
extern int windowNameMemory;
extern char windowName[];
extern char binaryExtension[];
char upperCaseBinExt[256];
extern FileDecoderExtensions fileDecoderExtensions[];
// extension and name seem to have the same value (MacOS anyway)
// check for ending in "/"
#ifdef Qt_UI_Win
// windows doesn't include the / after the folder
// check for a . in the last 5 characters
int isFolder = 1;
for(i=strlen(name)-1; i>=0 && i>strlen(name)-6; i--){
if( name[i] == '.') isFolder=0;
}
if( isFolder ){
strcat(name,"/");
#else
if( extension[strlen(extension)-1] == '/' ){
#endif
// assume this is a directory and reset the preferences accordingly.
printf("File prefixes set to: %s\n",name);
strcpy(UIData.saveprefixbuf,name);
strcpy(UIData.getprefixbuf,name);
strcpy(UIData.graphicsprefixbuf,name);
strcat(name,"macros/");
strcpy(UIData.macroprefixbuf,name);
printf("OMA2>",name);
return NO;
}
//printf("File ext is: %s\n",extension);
printf("File name is: %s\n",name);
for(i=0; i<strlen(extension); i++){
extension[i] = toupper(extension[i]);
upperCaseBinExt[i] = toupper(binaryExtension[i]);
}
upperCaseBinExt[i]=0;
for(i=0; fileDecoderExtensions[i].ext[0]; i++ ){
int extLength = (int)strlen(fileDecoderExtensions[i].ext) - 1 ;
if(strncmp(extension,&fileDecoderExtensions[i].ext[1],extLength) == 0){
Image new_im(name,LONG_NAME);
if(new_im.err()){
beep();
printf("Could not load %s\n",name);
//[appController appendText: @"OMA2>"];
wPointer->addCString((char*)"OMA2>");
return NO;
}
iBuffer.free(); // release the old data
iBuffer = new_im; // this is the new data
iBuffer.getmaxx(PRINT_RESULT);
update_UI();
display(0,(char*)"");
//[appController appendText: @"OMA2>"];
//[[appController theWindow] makeKeyAndOrderFront:NULL];
//[[NSApplication sharedApplication] activateIgnoringOtherApps : YES]; // make oma active
wPointer->addCString((char*)"OMA2>");
return YES;
}
}
if(strcmp(extension, "MAC")==0 || strcmp(extension, "O2M")==0){
extern char macbuf[];
int fd,nread,i;
fd = open(name,O_RDONLY);
if(fd == -1) {
beep();
printf("Macro File '%s' Not Found.\n",name);
return NO;
}
for(i=0; i<MBUFLEN; i++) *(macbuf+i) = 0; // clear the buffer
nread = (int)read(fd,macbuf,MBUFLEN); // read the largest buffer
printf("%d Bytes Read.\n",nread);
// the format of macro files has changed -- now they are formatted text files
// previously, they were constant length files containing C strings
// this code should read both formats
for(i=0; i<nread ; i++) {
if( *(macbuf+i) == 0x0D || *(macbuf+i) == 0x0A)
*(macbuf+i) = 0x00; // change CR or LF to null
}
*(macbuf+nread) = 0; // one extra to signify end of buffer
*(macbuf+nread+1) = 0;
close(fd);
clear_buffer_to_end(macbuf); // insert trailing zeros after the macro
//[appController appendText: @"OMA2>"];
wPointer->addCString((char*)"OMA2>");
return YES;
}
if(strcmp(extension, "O2S")==0){
printf("Loading Settings...\n");
int err = loadprefs(name);
//[appController appendText: @"OMA2>"];
wPointer->addCString((char*)"OMA2>");
if (err == NO_ERR) return YES;
}
if(strcmp(extension, "PA1")==0){
printf("Loading Custom Palette...\n");
int err = getpalettefile(name);
update_UI();
wPointer->addCString((char*)"OMA2>");
if (err == NO_ERR) return YES;
}
return NO;
}
// update the User Interface
//
// This is a way to update user interface values after a command
int omaprintf(const char* format, ...)
{
va_list args;
va_start(args,format);
extern unsigned char printall,no_print;
if(!printall) return NO_ERR;
if(no_print) return NO_ERR;
int return_status = NO_ERR;
return_status = vsprintf(reply,format, args);
//[appController appendCText: reply];
/*
dispatch_queue_t theQueue = dispatch_get_current_queue();
dispatch_queue_t mainQueue = dispatch_get_main_queue();
if (theQueue == mainQueue) {
[appController appendCText: reply];
} else {
dispatch_sync(mainQueue,^{[appController appendCText: reply];});
}
*/
//fprintf(stderr,"%s",reply);
wPointer->addCString((char*)reply);
va_end(args);
return return_status;
}
// these C++ functions are called by C functions
int cprintf(const char* format, ...)
{
va_list args;
va_start(args,format);
extern unsigned char printall,no_print;
if(!printall) return NO_ERR;
if(no_print) return NO_ERR;
int return_status = NO_ERR;
return_status = vsprintf(reply,format, args);
//[appController appendCText: reply];
/*
dispatch_queue_t theQueue = dispatch_get_current_queue();
dispatch_queue_t mainQueue = dispatch_get_main_queue();
if (theQueue == mainQueue) {
[appController appendCText: reply];
} else {
dispatch_sync(mainQueue,^{[appController appendCText: reply];});
}
*/
//fprintf(stderr,"%s",reply);
wPointer->addCString((char*)reply);
va_end(args);
return return_status;
}
/*
int pprintf(const char* format, ...) // priority printing!
{
va_list args;
va_start(args,format);
extern unsigned char no_print;
//if(!printall) return NO_ERR;
if(no_print) return NO_ERR;
int return_status = NO_ERR;
return_status = vsprintf(reply,format, args);
//[appController appendCText: reply];
dispatch_queue_t theQueue = dispatch_get_current_queue();
dispatch_queue_t mainQueue = dispatch_get_main_queue();
if (theQueue == mainQueue) {
[appController appendCText: reply];
} else {
dispatch_sync(mainQueue,^{[appController appendCText: reply];});
}
va_end(args);
return return_status;
}
*/
void cbeep(){
beep();
}
// end of UI functions to be called by C functions
void beep(){
extern int stop_on_error,macflag,exflag,isErrorText;
isErrorText = 1;
//NSBeep();
QApplication::beep();
if(stop_on_error && (macflag || exflag))
//stopMacroNow = 1;
stopmacro();
}
void alertSound(char* sayString){
//NSSpeechSynthesizer* talker = [[NSSpeechSynthesizer alloc] init];
//[talker startSpeakingString: [NSString stringWithCString:sayString encoding:NSASCIIStringEncoding]];
//NSBeep();
QApplication::beep();
}