Added a test for MUIA_Listview_SelectChange.
[AROS.git] / arch / all-hosted / hidd / sdl / mouseclass.c
blob15382770f19cc80a3c152d3808360525907c6a59
1 /*
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.
8 */
10 #include <exec/types.h>
11 #include <exec/semaphores.h>
12 #include <oop/oop.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>
22 #ifdef __THROW
23 #undef __THROW
24 #endif
25 #ifdef __CONCAT
26 #undef __CONCAT
27 #endif
29 #include "sdl_intern.h"
31 #define DEBUG 0
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"));
39 if (xsd.mousehidd)
40 return NULL;
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));
50 xsd.mousehidd = o;
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) {
63 case SDL_MOUSEMOTION:
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);
74 break;
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" :
82 "UNKNOWN"));
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) {
89 case SDL_BUTTON_LEFT:
90 hiddev.button = vHidd_Mouse_Button1;
91 break;
93 case SDL_BUTTON_RIGHT:
94 hiddev.button = vHidd_Mouse_Button2;
95 break;
97 case SDL_BUTTON_MIDDLE:
98 hiddev.button = vHidd_Mouse_Button3;
99 break;
101 default:
102 hiddev.button = vHidd_Mouse_NoButton;
103 break;
106 if (mousedata->callback != NULL)
107 mousedata->callback(mousedata->callbackdata, &hiddev);
109 break;
113 VOID Hidd_SDLMouse_HandleEvent(OOP_Object *o, SDL_Event *e) {
114 struct pHidd_SDLMouse_HandleEvent msg;
115 static OOP_MethodID mid;
117 if (!mid)
118 mid = OOP_GetMethodID(IID_Hidd_SDLMouse, moHidd_SDLMouse_HandleEvent);
120 msg.mID = mid;
121 msg.e = e;
123 OOP_DoMethod(o, (OOP_Msg) &msg);
126 static struct OOP_MethodDescr SDLMouse_Root_descr[] = {
127 {(OOP_MethodFunc)SDLMouse__Root__New, moRoot_New},
128 {NULL , 0 }
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},
134 {NULL, 0}
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},
141 {NULL , NULL }