This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINPUTW.CPP
executable file
·365 lines (305 loc) · 7.66 KB
/
INPUTW.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
355
356
357
358
359
360
361
362
363
364
365
//allows for changing of input devices
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "gui.h"
#include "input.h"
#include "dd.h"
#include "r2img.h"
#include "font.h"
//#include "object.h"
//#include "objdef.h"
#include "keyb.h"
#include "config.h"
//input device settings.
extern inputdevicesettings *ids;
#define NUMINPUTTYPES 6
char *inputnames[]=
{
"None",
"Gravis Gamepad",
"Keyboard 1",
"Keyboard 2",
"Joystick 1",
"Joystick 2",
"GrIP Slot 1",
"GrIP Slot 2",
};
class keyedit:public GUIedit
{
char *keyname;
char &keyscan; //scancode to be modified
public:
keyedit(GUIrect *p,char *pmpt,int x2,int y,char &scan)
:GUIedit(p,pmpt,x2,y,70),keyscan(scan)
{
moverel(-width(),0);
keyname=getkeyname(keyscan);
};
virtual GUIrect *click(mouse &m)
{
if (modal) setmodal(0); else setmodal(this);
setfocus(this);
return 0;
};
virtual int release(mouse &m) {return 1;}
virtual int keyhit(char kbscan,char key)
{
if (modal!=this)
{
if (kbscan==KB_ENTER) {setmodal(this); return 1;}
setmodal(0);
return 0;
}
if (kbscan!=KB_ESC)
{
keyscan=kbscan;
keyname=getkeyname(keyscan);
parent->cyclefocus(0);
}
setmodal(0); //parent->parent);
return 1;
}
virtual void drawdata(char *dest,int x,int y,int xw)
{
if (modal==this && (uu&16)) drawrect(dest,2,x,y,xw,10);
font[1]->draw(keyname,dest,x,y);
}
virtual char *getname() {return "keyedit";}
};
char *mapnames[]={
"Up-left", //0
"Up",
"Up-right",
"Left",
"Right",
"Down-left", //5
"Down",
"Down-Right",
"B", //8
"A",
"Select",
"Start", //11
};
class redefinekeys:public GUIcontents
{
keymap &km;
public:
redefinekeys(keymap &tkm):GUIcontents(150,150),km(tkm)
{
for (int i=0; i<=11; i++)
{
char s[30];
strcpy(s,mapnames[i]);
strcat(s,": ");
new keyedit(this,s,width()-5,i*12+3,((char *)&km)[i]);
}
};
virtual ~redefinekeys()
{
pos.close((GUIbox *)parent);
losefocus();
}
virtual int acceptfocus() {return 1;}
virtual void draw(char *dest)
{
fill(1);
GUIrect::draw(dest);
}
virtual char *getname() {return "redefinekeys";}
//open functions
static DLGPOS pos; //saved last position of dialog
static void open(keymap *km)
{
pos.open(new GUIbox(guiroot,"Redefine keys",new redefinekeys(*km),0,0));
// setmodal(pos.opened);
};
};
DLGPOS redefinekeys::pos;
typedef input *INPUTPTR;
class inputtestbutton:public GUIrect
{
input *in;
int button; //button number
public:
void setinput(input *tin) {in=tin;}
void setbutton(int tbut) {button=1<<(tbut+4);}
inputtestbutton(GUIrect *p,int x1,int y1,int xw,int yw,input *tin,int tbut)
:GUIrect(p,x1,y1,x1+xw,y1+yw)
{
setinput(tin); setbutton(tbut);
}
virtual void draw(char *dest)
{
if (in && in->but&button) fill(4);
else fill(9*16+14);
outline(4);
}
virtual char *getname() {return "inputtestbutton";}
};
class inputtestarea:public GUIrect
{
input *in; //input to test
public:
void setinput(input *tin) {in=tin;}
inputtestarea(GUIrect *p,int x1,int y1,int width,input *tin):
GUIrect(p,x1,y1,x1+width,y1+width)
{
setinput(tin);
}
virtual void draw(char *dest)
{
//drawbox(dest,4,x1-1,y1-1,x2+1,y2+1);
fill(9*16+14);
outline(4);
if (!in) return;
int x,y;
if (in->stat&ID_RIGHT) x=width()-10; else
if (in->stat&ID_LEFT) x=0; else x=width()/2-5;
if (in->stat&ID_DOWN) y=height()-10; else
if (in->stat&ID_UP) y=0; else y=height()/2-5;
drawrect(dest,2,x1+x,y1+y,10,10);
}
virtual char *getname() {return "inputtestarea";}
};
#include "message.h"
class changeinputdevice:public GUIcontents
{
protected:
int lastintype;
int inputnum;
INPUTPTR ∈ //pointer to input device being changed
GUIstringlistbox *list;
inputtestarea *test;
inputtestbutton *b[4];
GUItextbutton *edit,*save;
object *lasto; //object that was bound to input
public:
changeinputdevice(int num,INPUTPTR &tin)
:GUIcontents(220,135),in(tin),inputnum(num)
{
new GUIstatictext(this,1,"Input type:",5,3);
list=new GUIstringlistbox(this,5,15,110,NUMINPUTTYPES,10);
edit=save=0;
//fill list box
ITEMPTR *a=list->resizeitems(NUMINPUTTYPES);
for (int i=0; i<NUMINPUTTYPES; i++) a[i]=(ITEMPTR)inputnames[i];
new GUIstatictext(this,1,"Test area:",125,3);
test=new inputtestarea(this,125,15,91,in);
for (i=0; i<4; i++) b[i]=new inputtestbutton(this,127+i*23,110,18,10,in,i);
lasto=0;
// msg.printf(2,"in=%p in->o=%p",in,in ? in->o : 0);
if (in)
{
lasto=in->o;
list->setsel(in->type);
lastintype=in->type;
// in->bind(0);
}
// msg.printf(2,"in=%p in->o=%p lasto=%p",in,in ? in->o : 0,lasto);
}
void changedevice(int type)
{
disable();
if (in) delete in;
in=newinputdevice(type);
in->bind(lasto);
enable();
}
virtual ~changeinputdevice()
{
pos.close((GUIbox *)parent);
if (in)
{
changedevice(lastintype); //reset input device from last settings
// in->bind(lasto);
}
}
virtual void losefocus()
{
GUIrect::losefocus();
}
virtual void receivefocus()
{
if (in) in->testing=1;
GUIrect::receivefocus();
}
virtual int sendmessage(GUIrect *c,int guimsg)
{
if (c==edit)
if (guimsg==GUIMSG_PUSHED)
if (in)
{
if (in->getkeymap())
{
redefinekeys::open(in->getkeymap());
}
//else if (in->getjoythreshold()) calibratejoy::open(in->getjoythreshold());
in->testing=0;
}
if (c==save)
if (guimsg==GUIMSG_PUSHED)
{
if (in)
{
in->savesettings(); //save settings to ids
lastintype=in->type;
cfg->pinput[inputnum]=in->type;
cfg->save(configfile);
}
delete parent;
return 1;
}
if (guimsg==GUIMSG_LISTBOXSELCHANGED) //they changed input devices
{
int x=list->getselnum();
if (x<0) return 1;
changedevice(x);
if (in) in->testing=1;
if (test)
{
test->setinput(in);
for (int i=0; i<4; i++) b[i]->setinput(in);
}
if (edit) {delete edit; edit=0;}
if (save) {delete save; save=0;}
if (in)
{
if (in->getjoythreshold()) edit=new GUItextbutton(this,"Calibrate...",60,90); else
if (in->getkeymap()) edit=new GUItextbutton(this,"Redefine keys...",60,90);
}
//if (edit)
save=new GUItextbutton(this,"Save settings",60,105);
}
return 1;
};
virtual int acceptfocus() {return 1;}
virtual char *getname() {return "changeinputdevice";}
virtual void draw(char *dest)
{
fill(1);
/* if (lasto) //is bound?
{
char s[80];
sprintf(s,"Bound to: %s",lasto->od->name);
font[3]->drawcentered(s,dest,x1+width()/2,y1+125);
}*/
font[3]->draw("B",dest,x1+133,y1+122);
font[3]->draw("A",dest,x1+134+23,y1+122);
font[3]->draw("Sl",dest,x1+132+23*2,y1+122);
font[3]->draw("St",dest,x1+132+23*3,y1+122);
GUIrect::draw(dest);
};
//open functions
static DLGPOS pos; //saved last position of dialog
static void open(int inputdevicenum)
{
if (pos.opened) return;
char s[80];
sprintf(s,"Input device %d",inputdevicenum+1);
pos.open(new GUIbox(guiroot,s,new changeinputdevice(inputdevicenum,inputdevice[inputdevicenum]),0,0));
};
};
DLGPOS changeinputdevice::pos;
void editinputdevice0() {changeinputdevice::open(0);}
void editinputdevice1() {changeinputdevice::open(1);}