Mercurial > sdl-ios-xcode
comparison src/video/directfb/SDL_DirectFB_mouse.c @ 2737:140a7edcf2bd
Date: Sun, 31 Aug 2008 17:53:59 +0200
From: Couriersud
Subject: Re: Updated DirectFB driver for SDL1.3
attached is a patch which brings the directfb driver in line with
current svn. In addition:
* driver now is in line with the structure of the X11 driver.
This adds a couple of files.
* driver now supports relative mouse movements
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 31 Aug 2008 16:04:32 +0000 |
parents | 204be4fc2726 |
children | 483f85e35a1a |
comparison
equal
deleted
inserted
replaced
2736:ae653575d4af | 2737:140a7edcf2bd |
---|---|
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 | 23 |
24 #include "SDL_DirectFB_video.h" | 24 #include "SDL_DirectFB_video.h" |
25 #include "SDL_DirectFB_mouse.h" | |
26 | 25 |
27 #include "../SDL_sysvideo.h" | 26 #include "../SDL_sysvideo.h" |
28 #include "../../events/SDL_mouse_c.h" | 27 #include "../../events/SDL_mouse_c.h" |
29 | 28 |
30 static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, | 29 static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, |
47 mouse.ShowCursor = DirectFB_ShowCursor; | 46 mouse.ShowCursor = DirectFB_ShowCursor; |
48 mouse.MoveCursor = DirectFB_MoveCursor; | 47 mouse.MoveCursor = DirectFB_MoveCursor; |
49 mouse.FreeCursor = DirectFB_FreeCursor; | 48 mouse.FreeCursor = DirectFB_FreeCursor; |
50 mouse.WarpMouse = DirectFB_WarpMouse; | 49 mouse.WarpMouse = DirectFB_WarpMouse; |
51 mouse.FreeMouse = DirectFB_FreeMouse; | 50 mouse.FreeMouse = DirectFB_FreeMouse; |
52 devdata->mouse = SDL_AddMouse(&mouse, -1); | 51 mouse.cursor_shown = 1; |
52 devdata->mouse = SDL_AddMouse(&mouse, -1, "Mouse", 0, 0, 1); | |
53 } | 53 } |
54 | 54 |
55 void | 55 void |
56 DirectFB_QuitMouse(_THIS) | 56 DirectFB_QuitMouse(_THIS) |
57 { | 57 { |
83 dsc.caps = DSCAPS_VIDEOONLY; | 83 dsc.caps = DSCAPS_VIDEOONLY; |
84 dsc.width = surface->w; | 84 dsc.width = surface->w; |
85 dsc.height = surface->h; | 85 dsc.height = surface->h; |
86 dsc.pixelformat = DSPF_ARGB; | 86 dsc.pixelformat = DSPF_ARGB; |
87 | 87 |
88 SDL_DFB_CHECKERR(devdata-> | 88 SDL_DFB_CHECKERR(devdata->dfb-> |
89 dfb->CreateSurface(devdata->dfb, &dsc, &curdata->surf)); | 89 CreateSurface(devdata->dfb, &dsc, &curdata->surf)); |
90 curdata->hotx = hot_x; | 90 curdata->hotx = hot_x; |
91 curdata->hoty = hot_y; | 91 curdata->hoty = hot_y; |
92 cursor->driverdata = curdata; | 92 cursor->driverdata = curdata; |
93 | 93 |
94 SDL_DFB_CHECKERR(curdata-> | 94 SDL_DFB_CHECKERR(curdata->surf-> |
95 surf->Lock(curdata->surf, DSLF_WRITE, (void *) &dest, | 95 Lock(curdata->surf, DSLF_WRITE, (void *) &dest, &pitch)); |
96 &pitch)); | |
97 | 96 |
98 //FIXME: Implies a lot of things, e.g. rgba format for SDL_SURFACE .... | 97 /* Relies on the fact that this is only called with ARGB surface. */ |
99 p = surface->pixels; | 98 p = surface->pixels; |
100 for (i = 0; i < surface->w * surface->h; i++) | 99 for (i = 0; i < surface->h; i++) |
101 if (p[i] == 0x00000000) | 100 memcpy((char *) dest + i * pitch, (char *) p + i * surface->pitch, |
102 dest[i] = 0x00000000; | 101 4 * surface->w); |
103 else | 102 |
104 dest[i] = p[i]; | |
105 curdata->surf->Unlock(curdata->surf); | 103 curdata->surf->Unlock(curdata->surf); |
106 return cursor; | 104 return cursor; |
107 error: | 105 error: |
108 return NULL; | 106 return NULL; |
109 } | 107 } |
111 /* Show the specified cursor, or hide if cursor is NULL */ | 109 /* Show the specified cursor, or hide if cursor is NULL */ |
112 static int | 110 static int |
113 DirectFB_ShowCursor(SDL_Cursor * cursor) | 111 DirectFB_ShowCursor(SDL_Cursor * cursor) |
114 { | 112 { |
115 SDL_DFB_CURSORDATA(cursor); | 113 SDL_DFB_CURSORDATA(cursor); |
116 SDL_VideoDevice *dev = SDL_GetVideoDevice(); | |
117 SDL_DFB_DEVICEDATA(dev); | |
118 #if 0 | |
119 DFB_DisplayData *dispdata = | |
120 (DFB_DisplayData *) dev->displays[dev->current_display].driverdata; | |
121 #endif | |
122 DFBResult ret; | 114 DFBResult ret; |
123 SDL_WindowID wid; | 115 SDL_WindowID wid; |
124 | 116 |
125 wid = SDL_GetFocusWindow(); | 117 wid = SDL_GetFocusWindow(); |
126 if (!wid) | 118 if (wid < 0) |
127 return -1; | 119 return -1; |
128 else { | 120 else { |
129 SDL_Window *window = SDL_GetWindowFromID(wid); | 121 SDL_Window *window = SDL_GetWindowFromID(wid); |
130 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 122 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
131 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; | |
132 DFB_WindowData *windata = (DFB_WindowData *) window->driverdata; | |
133 | 123 |
134 if (cursor) | 124 if (display) { |
135 SDL_DFB_CHECKERR(windata->window->SetCursorShape(windata->window, | 125 DFB_DisplayData *dispdata = |
136 curdata->surf, | 126 (DFB_DisplayData *) display->driverdata; |
137 curdata->hotx, | 127 DFB_WindowData *windata = (DFB_WindowData *) window->driverdata; |
138 curdata->hoty)); | 128 |
139 //TODO: Check administrative | 129 if (cursor) |
140 SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer, | 130 SDL_DFB_CHECKERR(windata->window-> |
141 DLSCL_ADMINISTRATIVE)); | 131 SetCursorShape(windata->window, |
142 SDL_DFB_CHECKERR(dispdata->layer->SetCursorOpacity(dispdata->layer, | 132 curdata->surf, curdata->hotx, |
143 cursor ? 0xC0 : | 133 curdata->hoty)); |
144 0x00)); | 134 |
145 SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer, | 135 /* fprintf(stdout, "Cursor is %s\n", cursor ? "on" : "off"); */ |
146 DLSCL_SHARED)); | 136 SDL_DFB_CHECKERR(dispdata->layer-> |
137 SetCooperativeLevel(dispdata->layer, | |
138 DLSCL_ADMINISTRATIVE)); | |
139 SDL_DFB_CHECKERR(dispdata->layer-> | |
140 SetCursorOpacity(dispdata->layer, | |
141 cursor ? 0xC0 : 0x00)); | |
142 SDL_DFB_CHECKERR(dispdata->layer-> | |
143 SetCooperativeLevel(dispdata->layer, | |
144 DLSCL_SHARED)); | |
145 } | |
147 } | 146 } |
148 | 147 |
149 return 0; | 148 return 0; |
150 error: | 149 error: |
151 return -1; | 150 return -1; |
153 | 152 |
154 /* This is called when a mouse motion event occurs */ | 153 /* This is called when a mouse motion event occurs */ |
155 static void | 154 static void |
156 DirectFB_MoveCursor(SDL_Cursor * cursor) | 155 DirectFB_MoveCursor(SDL_Cursor * cursor) |
157 { | 156 { |
158 SDL_DFB_CURSORDATA(cursor); | 157 |
159 /* Do we need to do something here ? */ | |
160 } | 158 } |
161 | 159 |
162 /* Free a window manager cursor */ | 160 /* Free a window manager cursor */ |
163 static void | 161 static void |
164 DirectFB_FreeCursor(SDL_Cursor * cursor) | 162 DirectFB_FreeCursor(SDL_Cursor * cursor) |
180 DFB_WindowData *windata = (DFB_WindowData *) window->driverdata; | 178 DFB_WindowData *windata = (DFB_WindowData *) window->driverdata; |
181 DFBResult ret; | 179 DFBResult ret; |
182 int cx, cy; | 180 int cx, cy; |
183 | 181 |
184 SDL_DFB_CHECKERR(windata->window->GetPosition(windata->window, &cx, &cy)); | 182 SDL_DFB_CHECKERR(windata->window->GetPosition(windata->window, &cx, &cy)); |
185 SDL_DFB_CHECKERR(dispdata-> | 183 SDL_DFB_CHECKERR(dispdata->layer-> |
186 layer->WarpCursor(dispdata->layer, cx + x, cy + y)); | 184 WarpCursor(dispdata->layer, cx + x, cy + y)); |
187 | 185 |
188 error: | 186 error: |
189 return; | 187 return; |
190 } | 188 } |
191 | 189 |
192 /* Free the mouse when it's time */ | 190 /* Free the mouse when it's time */ |
193 static void | 191 static void |
194 DirectFB_FreeMouse(SDL_Mouse * mouse) | 192 DirectFB_FreeMouse(SDL_Mouse * mouse) |
195 { | 193 { |
196 // nothing yet | 194 /* nothing yet */ |
197 | |
198 } | 195 } |
199 | 196 |
200 /* vi: set ts=4 sw=4 expandtab: */ | 197 /* vi: set ts=4 sw=4 expandtab: */ |