revert commit 56204.
[AROS.git] / rom / usb / classes / arosx / arosx.class.config.gui.c
blob0a372d6bd76e4d5b71c5ff5b0255a04b752704fe
1 /*
2 Copyright © 2018-2019, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Gamepad (XInput) USB class driver
6 Lang: English
7 */
9 #include "debug.h"
10 #include "arosx.class.h"
12 #include "arosx.class.config.gui.h"
14 #include "include/arosx.h"
15 #include <proto/arosx.h>
17 #undef ps
18 #undef MUIMasterBase
19 #define ps PsdBase
20 #define MUIMasterBase MUIBase
22 /* /// "nGUITask()" */
23 AROS_UFH0(void, nGUITask)
25 AROS_USERFUNC_INIT
27 struct Task *thistask;
28 struct AROSXClassBase *arosxb;
29 struct AROSXClassController *arosxc;
31 struct Library *MUIBase;
32 struct Library *PsdBase;
33 struct Library *AROSXBase;
35 struct AROSXClassConfigGUI *gui;
37 thistask = FindTask(NULL);
38 arosxc = thistask->tc_UserData;
39 arosxb = arosxc->arosxb;
41 struct AROSX_GAMEPAD *arosx_gamepad;
42 arosx_gamepad = &arosxc->arosx_gamepad;
45 TODO: Make use of OpenLibrary/CloseLibrary to keep track of lib open count...
47 ++arosxb->Library.lib_OpenCnt;
49 struct AROSX_EventHook *arosx_eventhook;
50 struct MsgPort *arosx_eventport;
52 if(gui = AllocVec(sizeof(struct AROSXClassConfigGUI), MEMF_CLEAR|MEMF_ANY)) {
54 if(AROSXBase = OpenLibrary("arosx.library", 0)) {
55 mybug(-1,("[AROSXClass GUI] arosx.library openened\n"));
57 arosx_eventport = CreateMsgPort();
58 arosx_eventhook = AROSX_AddEventHandler(arosx_eventport, (((1<<arosxc->id))<<28));
60 Set to listen every controller
62 //arosx_eventhook = AROSX_AddEventHandler(arosx_eventport, (0xf<<28));
64 if((MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN)))
66 if((ps = OpenLibrary("poseidon.library", 4)))
69 gui->App = ApplicationObject,
70 MUIA_Application_Title , (IPTR)libname,
71 MUIA_Application_Version , (IPTR)VERSION_STRING,
72 MUIA_Application_Copyright , (IPTR)"©2018-2019 The AROS Development Team",
73 MUIA_Application_Author , (IPTR)"The AROS Development Team",
74 MUIA_Application_Description, (IPTR)"Settings for the arosx.class",
75 MUIA_Application_Base , (IPTR)"AROSX",
76 MUIA_Application_HelpFile , (IPTR)"HELP:Poseidon.guide",
77 MUIA_Application_Menustrip , (IPTR)MenustripObject,
78 Child, (IPTR)MenuObjectT((IPTR)"Project"),
79 Child, (IPTR)(gui->AboutMI = MenuitemObject,
80 MUIA_Menuitem_Title, (IPTR)"About...",
81 MUIA_Menuitem_Shortcut, (IPTR)"?",
82 End),
83 End,
84 Child, (IPTR)MenuObjectT((IPTR)"Settings"),
85 Child, (IPTR)(gui->UseMI = MenuitemObject,
86 MUIA_Menuitem_Title, (IPTR)"Save",
87 MUIA_Menuitem_Shortcut, (IPTR)"S",
88 End),
89 Child, (IPTR)MenuitemObject,
90 MUIA_Menuitem_Title, (IPTR)NM_BARLABEL,
91 End,
92 Child, (IPTR)(gui->MUIPrefsMI = MenuitemObject,
93 MUIA_Menuitem_Title, (IPTR)"MUI Settings",
94 MUIA_Menuitem_Shortcut, (IPTR)"M",
95 End),
96 End,
97 End,
99 SubWindow, (IPTR)(gui->MainWindow = WindowObject,
100 MUIA_Window_ID , MAKE_ID('M','A','I','N'),
101 MUIA_Window_Title, (IPTR)arosxc->name,
102 MUIA_HelpNode, (IPTR)libname,
104 WindowContents, (IPTR)VGroup,
105 Child, (IPTR)(gui->GamepadGroupObject = ColGroup(2),
106 GroupFrameT("Gamepad"),
107 MUIA_Disabled, TRUE,
109 Child, (IPTR)HGroup,
110 Child, (IPTR)(gui->GamepadObject_button_a = ImageObject,
111 MUIA_Image_FontMatch, TRUE,
112 MUIA_Selected, FALSE,
113 MUIA_ShowSelState, FALSE,
114 MUIA_Image_Spec, MUII_RadioButton,
115 MUIA_Frame, MUIV_Frame_None,
116 End),
118 Child, (IPTR)(gui->GamepadObject_button_b = ImageObject,
119 MUIA_Image_FontMatch, TRUE,
120 MUIA_Selected, FALSE,
121 MUIA_ShowSelState, FALSE,
122 MUIA_Image_Spec, MUII_RadioButton,
123 MUIA_Frame, MUIV_Frame_None,
124 End),
126 Child, (IPTR)(gui->GamepadObject_button_x = ImageObject,
127 MUIA_Image_FontMatch, TRUE,
128 MUIA_Selected, FALSE,
129 MUIA_ShowSelState, FALSE,
130 MUIA_Image_Spec, MUII_RadioButton,
131 MUIA_Frame, MUIV_Frame_None,
132 End),
134 Child, (IPTR)(gui->GamepadObject_button_y = ImageObject,
135 MUIA_Image_FontMatch, TRUE,
136 MUIA_Selected, FALSE,
137 MUIA_ShowSelState, FALSE,
138 MUIA_Image_Spec, MUII_RadioButton,
139 MUIA_Frame, MUIV_Frame_None,
140 End),
142 Child, (IPTR)(gui->GamepadObject_button_ls = ImageObject,
143 MUIA_Image_FontMatch, TRUE,
144 MUIA_Selected, FALSE,
145 MUIA_ShowSelState, FALSE,
146 MUIA_Image_Spec, MUII_RadioButton,
147 MUIA_Frame, MUIV_Frame_None,
148 End),
150 Child, (IPTR)(gui->GamepadObject_button_rs = ImageObject,
151 MUIA_Image_FontMatch, TRUE,
152 MUIA_Selected, FALSE,
153 MUIA_ShowSelState, FALSE,
154 MUIA_Image_Spec, MUII_RadioButton,
155 MUIA_Frame, MUIV_Frame_None,
156 End),
158 Child, (IPTR)(gui->GamepadObject_left_thumb = ImageObject,
159 MUIA_Image_FontMatch, TRUE,
160 MUIA_Selected, FALSE,
161 MUIA_ShowSelState, FALSE,
162 MUIA_Image_Spec, MUII_RadioButton,
163 MUIA_Frame, MUIV_Frame_None,
164 End),
166 Child, (IPTR)(gui->GamepadObject_right_thumb = ImageObject,
167 MUIA_Image_FontMatch, TRUE,
168 MUIA_Selected, FALSE,
169 MUIA_ShowSelState, FALSE,
170 MUIA_Image_Spec, MUII_RadioButton,
171 MUIA_Frame, MUIV_Frame_None,
172 End),
174 Child, (IPTR)(gui->GamepadObject_dpad_left = ImageObject,
175 MUIA_Image_FontMatch, TRUE,
176 MUIA_Selected, FALSE,
177 MUIA_ShowSelState, FALSE,
178 MUIA_Image_Spec, MUII_RadioButton,
179 MUIA_Frame, MUIV_Frame_None,
180 End),
182 Child, (IPTR)(gui->GamepadObject_dpad_right = ImageObject,
183 MUIA_Image_FontMatch, TRUE,
184 MUIA_Selected, FALSE,
185 MUIA_ShowSelState, FALSE,
186 MUIA_Image_Spec, MUII_RadioButton,
187 MUIA_Frame, MUIV_Frame_None,
188 End),
190 Child, (IPTR)(gui->GamepadObject_dpad_up = ImageObject,
191 MUIA_Image_FontMatch, TRUE,
192 MUIA_Selected, FALSE,
193 MUIA_ShowSelState, FALSE,
194 MUIA_Image_Spec, MUII_RadioButton,
195 MUIA_Frame, MUIV_Frame_None,
196 End),
198 Child, (IPTR)(gui->GamepadObject_dpad_down = ImageObject,
199 MUIA_Image_FontMatch, TRUE,
200 MUIA_Selected, FALSE,
201 MUIA_ShowSelState, FALSE,
202 MUIA_Image_Spec, MUII_RadioButton,
203 MUIA_Frame, MUIV_Frame_None,
204 End),
206 Child, (IPTR)(gui->GamepadObject_button_back = ImageObject,
207 MUIA_Image_FontMatch, TRUE,
208 MUIA_Selected, FALSE,
209 MUIA_ShowSelState, FALSE,
210 MUIA_Image_Spec, MUII_RadioButton,
211 MUIA_Frame, MUIV_Frame_None,
212 End),
214 Child, (IPTR)(gui->GamepadObject_button_start = ImageObject,
215 MUIA_Image_FontMatch, TRUE,
216 MUIA_Selected, FALSE,
217 MUIA_ShowSelState, FALSE,
218 MUIA_Image_Spec, MUII_RadioButton,
219 MUIA_Frame, MUIV_Frame_None,
220 End),
221 End,
223 Child, (IPTR)(gui->GamepadObject_left_trigger = GaugeObject,
224 GaugeFrame,
225 MUIA_Gauge_Max, 0xff,
226 MUIA_Gauge_InfoText, (IPTR)"%lx",
227 MUIA_Gauge_Horiz, TRUE,
228 MUIA_Gauge_Current, 0,
229 End),
231 Child, (IPTR)(gui->GamepadObject_right_trigger = GaugeObject,
232 GaugeFrame,
233 MUIA_Gauge_Max, 0xff,
234 MUIA_Gauge_InfoText, (IPTR)"%lx",
235 MUIA_Gauge_Horiz, TRUE,
236 MUIA_Gauge_Current, 0,
237 End),
239 Child, (IPTR)(gui->GamepadObject_left_stick_x = GaugeObject,
240 GaugeFrame,
241 MUIA_Gauge_Max, 0xffff,
242 MUIA_Gauge_InfoText, (IPTR)"%lx",
243 MUIA_Gauge_Horiz, TRUE,
244 MUIA_Gauge_Current, 0,
245 End),
247 Child, (IPTR)(gui->GamepadObject_left_stick_y = GaugeObject,
248 GaugeFrame,
249 MUIA_Gauge_Max, 0xffff,
250 MUIA_Gauge_InfoText, (IPTR)"%lx",
251 MUIA_Gauge_Horiz, TRUE,
252 MUIA_Gauge_Current, 0,
253 End),
255 Child, (IPTR)(gui->GamepadObject_right_stick_x = GaugeObject,
256 GaugeFrame,
257 MUIA_Gauge_Max, 0xffff,
258 MUIA_Gauge_InfoText, (IPTR)"%lx",
259 MUIA_Gauge_Horiz, TRUE,
260 MUIA_Gauge_Current, 0,
261 End),
263 Child, (IPTR)(gui->GamepadObject_right_stick_y = GaugeObject,
264 GaugeFrame,
265 MUIA_Gauge_Max, 0xffff,
266 MUIA_Gauge_InfoText, (IPTR)"%lx",
267 MUIA_Gauge_Horiz, TRUE,
268 MUIA_Gauge_Current, 0,
269 End),
271 End),
273 Child, (IPTR)VSpace(0),
274 Child, (IPTR)HGroup,
275 MUIA_Group_SameWidth, TRUE,
276 Child, (IPTR)(gui->UseObj = TextObject, ButtonFrame,
277 MUIA_Background, MUII_ButtonBack,
278 MUIA_CycleChain, 1,
279 MUIA_InputMode, MUIV_InputMode_RelVerify,
280 MUIA_Text_Contents, (IPTR)"\33c Save ",
281 End),
282 Child, (IPTR)(gui->CloseObj = TextObject, ButtonFrame,
283 MUIA_Background, MUII_ButtonBack,
284 MUIA_CycleChain, 1,
285 MUIA_InputMode, MUIV_InputMode_RelVerify,
286 MUIA_Text_Contents, (IPTR)"\33c Use ",
287 End),
288 End,
289 End,
290 End),
291 End;
293 if(gui->App)
295 DoMethod(gui->MainWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
296 gui->App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
297 DoMethod(gui->UseObj, MUIM_Notify, MUIA_Pressed, FALSE,
298 gui->App, 2, MUIM_Application_ReturnID, ID_STORE_CONFIG);
299 DoMethod(gui->CloseObj, MUIM_Notify, MUIA_Pressed, FALSE,
300 gui->App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
302 DoMethod(gui->AboutMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
303 gui->App, 2, MUIM_Application_ReturnID, ID_ABOUT);
304 DoMethod(gui->UseMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
305 gui->App, 2, MUIM_Application_ReturnID, ID_STORE_CONFIG);
306 DoMethod(gui->MUIPrefsMI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
307 gui->App, 2, MUIM_Application_OpenConfigWindow, 0);
309 IPTR isopen = 0;
310 IPTR iconify = 0;
311 ULONG sigs;
312 ULONG sigmask;
313 LONG retid;
315 get(gui->App, MUIA_Application_Iconified, &iconify);
316 set(gui->MainWindow, MUIA_Window_Open, TRUE);
317 get(gui->MainWindow, MUIA_Window_Open, &isopen);
319 if((isopen || (!iconify)))
321 sigmask = (1UL<<arosx_eventport->mp_SigBit);
324 retid = DoMethod(gui->App, MUIM_Application_NewInput, &sigs);
325 switch(retid)
327 case ID_ABOUT:
328 MUI_RequestA(gui->App, gui->MainWindow, 0, NULL, "Fabulous!", VERSION_STRING, NULL);
329 break;
331 if(retid == MUIV_Application_ReturnID_Quit)
333 break;
335 if(sigs)
337 sigs = Wait(sigs | sigmask | SIGBREAKF_CTRL_C);
338 if(sigs & SIGBREAKF_CTRL_C)
340 break;
343 if(sigs & (1UL<<arosx_eventport->mp_SigBit)) {
344 mybug(-1,("(%d) I may have received an event...\n", arosxc->id));
345 struct AROSX_EventNote *en;
346 while((en = (struct AROSX_EventNote *)GetMsg(arosx_eventport))) {
348 mybug(-1,(" event %08lx\n", en->en_Event));
350 /* TODO: GUI is disabled until we get the first message even on wired controllers... */
351 if((arosxc->status.wireless)&&(arosxc->status.signallost)) {
352 set(gui->GamepadGroupObject, MUIA_Disabled, TRUE);
353 } else {
354 set(gui->GamepadGroupObject, MUIA_Disabled, FALSE);
356 set(gui->GamepadObject_button_a, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_A));
357 set(gui->GamepadObject_button_b, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_B));
358 set(gui->GamepadObject_button_x, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_X));
359 set(gui->GamepadObject_button_y, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_Y));
360 set(gui->GamepadObject_button_ls, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_LEFT_SHOULDER));
361 set(gui->GamepadObject_button_rs, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_RIGHT_SHOULDER));
362 set(gui->GamepadObject_left_thumb, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_LEFT_THUMB));
363 set(gui->GamepadObject_right_thumb, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_RIGHT_THUMB));
364 set(gui->GamepadObject_dpad_left, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_DPAD_LEFT));
365 set(gui->GamepadObject_dpad_right, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_DPAD_RIGHT));
366 set(gui->GamepadObject_dpad_up, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_DPAD_UP));
367 set(gui->GamepadObject_dpad_down, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_DPAD_DOWN));
368 set(gui->GamepadObject_button_back, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_BACK));
369 set(gui->GamepadObject_button_start, MUIA_Selected, (arosx_gamepad->Buttons & AROSX_GAMEPAD_START));
371 set(gui->GamepadObject_left_trigger, MUIA_Gauge_Current, (arosx_gamepad->LeftTrigger));
372 set(gui->GamepadObject_right_trigger, MUIA_Gauge_Current, (arosx_gamepad->RightTrigger));
374 if(arosx_gamepad->ThumbLX>=0x8000) {
375 set(gui->GamepadObject_left_stick_x, MUIA_Gauge_Current, (arosx_gamepad->ThumbLX-0x8000));
376 } else {
377 set(gui->GamepadObject_left_stick_x, MUIA_Gauge_Current, (0x8000+arosx_gamepad->ThumbLX));
380 if(arosx_gamepad->ThumbLY>=0x8000) {
381 set(gui->GamepadObject_left_stick_y, MUIA_Gauge_Current, (arosx_gamepad->ThumbLY-0x8000));
382 } else {
383 set(gui->GamepadObject_left_stick_y, MUIA_Gauge_Current, (0x8000+arosx_gamepad->ThumbLY));
386 if(arosx_gamepad->ThumbRX>=0x8000) {
387 set(gui->GamepadObject_right_stick_x, MUIA_Gauge_Current, (arosx_gamepad->ThumbRX-0x8000));
388 } else {
389 set(gui->GamepadObject_right_stick_x, MUIA_Gauge_Current, (0x8000+arosx_gamepad->ThumbRX));
392 if(arosx_gamepad->ThumbRY>=0x8000) {
393 set(gui->GamepadObject_right_stick_y, MUIA_Gauge_Current, (arosx_gamepad->ThumbRY-0x8000));
394 } else {
395 set(gui->GamepadObject_right_stick_y, MUIA_Gauge_Current, (0x8000+arosx_gamepad->ThumbRY));
399 ReplyMsg((struct Message *)en);
403 } while(TRUE);
404 set(gui->MainWindow, MUIA_Window_Open, FALSE);
407 if(gui->App)
409 MUI_DisposeObject(gui->App);
410 gui->App = NULL;
413 if(MUIMasterBase)
415 CloseLibrary(MUIMasterBase);
416 MUIMasterBase = NULL;
419 if(ps)
421 CloseLibrary(ps);
422 ps = NULL;
429 AROSX_RemEventHandler(arosx_eventhook);
430 CloseLibrary(AROSXBase);
432 FreeVec(gui);
434 Forbid();
436 arosxc->GUITask = NULL;
437 --arosxb->Library.lib_OpenCnt;
441 AROS_USERFUNC_EXIT