2 * sdl.hidd - SDL graphics/sound/keyboard for AROS hosted
3 * Copyright (c) 2007 Robert Norris. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the same terms as AROS itself.
9 #define __OOP_NOATTRBASES__
11 #include <exec/types.h>
12 #include <exec/semaphores.h>
14 #include <proto/exec.h>
15 #include <proto/oop.h>
17 #include <hidd/hidd.h>
18 #include <hidd/mouse.h>
20 #include <aros/symbolsets.h>
22 #include "sdl_intern.h"
24 #include LC_LIBDEFS_FILE
27 #include <aros/debug.h>
29 static OOP_AttrBase HiddMouseAB
;
31 static struct OOP_ABDescr attrbases
[] = {
32 { IID_Hidd_Mouse
, &HiddMouseAB
},
36 static int sdl_mouseclass_init(LIBBASETYPEPTR LIBBASE
) {
37 D(bug("[sdl] sdl_mouseclass_init\n"));
39 return OOP_ObtainAttrBases(attrbases
);
42 static int sdl_mouseclass_expunge(LIBBASETYPEPTR LIBBASE
) {
43 D(bug("[sdl] sdl_mouseclass_expunge\n"));
45 OOP_ReleaseAttrBases(attrbases
);
49 ADD2INITLIB(sdl_mouseclass_init
, 0)
50 ADD2EXPUNGELIB(sdl_mouseclass_expunge
, 0)
52 #define SDLGfxBase ((LIBBASETYPEPTR) cl->UserData)
54 OOP_Object
*SDLMouse__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
) {
55 BOOL has_mouse_hidd
= FALSE
;
56 struct mousedata
*mousedata
;
58 D(bug("[sdl] SDLMouse::New\n"));
60 ObtainSemaphoreShared(&LIBBASE
->lock
);
61 if (LIBBASE
->mousehidd
!= NULL
)
62 has_mouse_hidd
= TRUE
;
63 ReleaseSemaphore(&LIBBASE
->lock
);
66 D(bug("[sdl] mouse hidd already present, can't make another one\n"));
70 if ((o
= (OOP_Object
*) OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
)) == NULL
) {
71 D(bug("[sdl] supermethod failed, bailing out\n"));
75 mousedata
= OOP_INST_DATA(cl
, o
);
77 mousedata
->callback
= GetTagData(aHidd_Mouse_IrqHandler
, NULL
, msg
->attrList
);
78 mousedata
->callbackdata
= GetTagData(aHidd_Mouse_IrqHandlerData
, NULL
, msg
->attrList
);
80 ObtainSemaphore(&LIBBASE
->lock
);
81 LIBBASE
->mousehidd
= o
;
82 ReleaseSemaphore(&LIBBASE
->lock
);
84 D(bug("[sdl] created mouse hidd, callback 0x%08x, data 0x%08x\n", mousedata
->callback
, mousedata
->callbackdata
));
86 return (OOP_Object
*) o
;
89 VOID
SDLMouse__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
) {
90 D(bug("[sdl] SDLMouse::Dispose\n"));
92 ObtainSemaphore(&LIBBASE
->lock
);
93 LIBBASE
->mousehidd
= NULL
;
94 ReleaseSemaphore(&LIBBASE
->lock
);
96 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
99 VOID
SDLMouse__Hidd_SDLMouse__HandleEvent(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_SDLMouse_HandleEvent
*msg
) {
100 struct mousedata
*mousedata
= OOP_INST_DATA(cl
, o
);
101 struct pHidd_Mouse_Event hiddev
;
103 D(bug("[sdl] SDLMouse::HandleEvent\n"));
105 switch (msg
->e
->type
) {
106 case SDL_MOUSEMOTION
:
107 D(bug("[sdl] mouse moved to [%d,%d]\n", msg
->e
->motion
.x
, msg
->e
->motion
.y
));
109 hiddev
.type
= vHidd_Mouse_Motion
;
110 hiddev
.x
= msg
->e
->motion
.x
;
111 hiddev
.y
= msg
->e
->motion
.y
;
112 hiddev
.button
= vHidd_Mouse_NoButton
;
114 if (mousedata
->callback
!= NULL
)
115 mousedata
->callback(mousedata
->callbackdata
, &hiddev
);
119 case SDL_MOUSEBUTTONDOWN
:
120 case SDL_MOUSEBUTTONUP
:
121 D(bug("[sdl] %s event for button %s\n", msg
->e
->button
.state
== SDL_PRESSED
? "PRESS" : "RELEASE",
122 msg
->e
->button
.button
== SDL_BUTTON_LEFT
? "LEFT" :
123 msg
->e
->button
.button
== SDL_BUTTON_RIGHT
? "RIGHT" :
124 msg
->e
->button
.button
== SDL_BUTTON_MIDDLE
? "MIDDLE" :
127 hiddev
.type
= msg
->e
->button
.state
== SDL_PRESSED
? vHidd_Mouse_Press
: vHidd_Mouse_Release
;
128 hiddev
.x
= msg
->e
->button
.x
;
129 hiddev
.y
= msg
->e
->button
.y
;
131 switch (msg
->e
->button
.button
) {
132 case SDL_BUTTON_LEFT
:
133 hiddev
.button
= vHidd_Mouse_Button1
;
136 case SDL_BUTTON_RIGHT
:
137 hiddev
.button
= vHidd_Mouse_Button2
;
140 case SDL_BUTTON_MIDDLE
:
141 hiddev
.button
= vHidd_Mouse_Button3
;
145 hiddev
.button
= vHidd_Mouse_NoButton
;
149 if (mousedata
->callback
!= NULL
)
150 mousedata
->callback(mousedata
->callbackdata
, &hiddev
);
156 VOID
Hidd_SDLMouse_HandleEvent(OOP_Object
*o
, SDL_Event
*e
) {
157 struct pHidd_SDLMouse_HandleEvent msg
;
158 static OOP_MethodID mid
;
161 mid
= OOP_GetMethodID(IID_Hidd_SDLMouse
, moHidd_SDLMouse_HandleEvent
);
166 OOP_DoMethod(o
, (OOP_Msg
) &msg
);