2 * sdl.hidd - SDL graphics/sound/keyboard for AROS hosted
3 * Copyright (c) 2007 Robert Norris. All rights reserved.
4 * Copyright (c) 2010 The AROS Development Team. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
10 #include <exec/types.h>
11 #include <exec/semaphores.h>
13 #include <proto/exec.h>
14 #include <proto/utility.h>
15 #include <proto/oop.h>
17 #include <hidd/hidd.h>
18 #include <hidd/mouse.h>
20 #include <aros/symbolsets.h>
29 #include "sdl_intern.h"
32 #include <aros/debug.h>
34 OOP_Object
*SDLMouse__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
) {
35 struct mousedata
*mousedata
;
37 D(bug("[sdl] SDLMouse::New\n"));
42 if ((o
= (OOP_Object
*) OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
)) != NULL
)
44 mousedata
= OOP_INST_DATA(cl
, o
);
46 mousedata
->callback
= (APTR
)GetTagData(aHidd_Mouse_IrqHandler
, 0, msg
->attrList
);
47 mousedata
->callbackdata
= (APTR
)GetTagData(aHidd_Mouse_IrqHandlerData
, 0, msg
->attrList
);
49 D(bug("[sdl] created mouse hidd, callback 0x%08x, data 0x%08x\n", mousedata
->callback
, mousedata
->callbackdata
));
53 return (OOP_Object
*) o
;
56 VOID
SDLMouse__Hidd_SDLMouse__HandleEvent(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_SDLMouse_HandleEvent
*msg
) {
57 struct mousedata
*mousedata
= OOP_INST_DATA(cl
, o
);
58 struct pHidd_Mouse_Event hiddev
;
60 D(bug("[sdl] SDLMouse::HandleEvent\n"));
62 switch (msg
->e
->type
) {
64 D(bug("[sdl] mouse moved to [%d,%d]\n", msg
->e
->motion
.x
, msg
->e
->motion
.y
));
66 hiddev
.type
= vHidd_Mouse_Motion
;
67 hiddev
.x
= msg
->e
->motion
.x
;
68 hiddev
.y
= msg
->e
->motion
.y
;
69 hiddev
.button
= vHidd_Mouse_NoButton
;
71 if (mousedata
->callback
!= NULL
)
72 mousedata
->callback(mousedata
->callbackdata
, &hiddev
);
76 case SDL_MOUSEBUTTONDOWN
:
77 case SDL_MOUSEBUTTONUP
:
78 D(bug("[sdl] %s event for button %s\n", msg
->e
->button
.state
== SDL_PRESSED
? "PRESS" : "RELEASE",
79 msg
->e
->button
.button
== SDL_BUTTON_LEFT
? "LEFT" :
80 msg
->e
->button
.button
== SDL_BUTTON_RIGHT
? "RIGHT" :
81 msg
->e
->button
.button
== SDL_BUTTON_MIDDLE
? "MIDDLE" :
84 hiddev
.type
= msg
->e
->button
.state
== SDL_PRESSED
? vHidd_Mouse_Press
: vHidd_Mouse_Release
;
85 hiddev
.x
= msg
->e
->button
.x
;
86 hiddev
.y
= msg
->e
->button
.y
;
88 switch (msg
->e
->button
.button
) {
90 hiddev
.button
= vHidd_Mouse_Button1
;
93 case SDL_BUTTON_RIGHT
:
94 hiddev
.button
= vHidd_Mouse_Button2
;
97 case SDL_BUTTON_MIDDLE
:
98 hiddev
.button
= vHidd_Mouse_Button3
;
102 hiddev
.button
= vHidd_Mouse_NoButton
;
106 if (mousedata
->callback
!= NULL
)
107 mousedata
->callback(mousedata
->callbackdata
, &hiddev
);
113 VOID
Hidd_SDLMouse_HandleEvent(OOP_Object
*o
, SDL_Event
*e
) {
114 struct pHidd_SDLMouse_HandleEvent msg
;
115 static OOP_MethodID mid
;
118 mid
= OOP_GetMethodID(IID_Hidd_SDLMouse
, moHidd_SDLMouse_HandleEvent
);
123 OOP_DoMethod(o
, (OOP_Msg
) &msg
);
126 static struct OOP_MethodDescr SDLMouse_Root_descr
[] = {
127 {(OOP_MethodFunc
)SDLMouse__Root__New
, moRoot_New
},
130 #define NUM_SDLMouse_Root_METHODS 1
132 static struct OOP_MethodDescr SDLMouse_Hidd_SDLMouse_descr
[] = {
133 {(OOP_MethodFunc
)SDLMouse__Hidd_SDLMouse__HandleEvent
, moHidd_SDLMouse_HandleEvent
},
136 #define NUM_SDLMouse_Hidd_SDLMouse_METHODS 1
138 struct OOP_InterfaceDescr SDLMouse_ifdescr
[] = {
139 {SDLMouse_Root_descr
, IID_Root
, NUM_SDLMouse_Root_METHODS
},
140 {SDLMouse_Hidd_SDLMouse_descr
, IID_Hidd_SDLMouse
, NUM_SDLMouse_Hidd_SDLMouse_METHODS
},