void WIN_InitMouse(_THIS) { SDL_Mouse *mouse = SDL_GetMouse(); mouse->CreateCursor = WIN_CreateCursor; mouse->CreateSystemCursor = WIN_CreateSystemCursor; mouse->ShowCursor = WIN_ShowCursor; mouse->FreeCursor = WIN_FreeCursor; mouse->WarpMouse = WIN_WarpMouse; mouse->SetRelativeMouseMode = WIN_SetRelativeMouseMode; SDL_SetDefaultCursor(WIN_CreateDefaultCursor()); }
/* TODO Actually implement the cursor, need to wait for mir support */ void MIR_InitMouse() { SDL_Mouse* mouse = SDL_GetMouse(); mouse->CreateCursor = MIR_CreateCursor; mouse->ShowCursor = MIR_ShowCursor; mouse->FreeCursor = MIR_FreeCursor; mouse->WarpMouse = MIR_WarpMouse; mouse->CreateSystemCursor = MIR_CreateSystemCursor; mouse->SetRelativeMouseMode = MIR_SetRelativeMouseMode; SDL_SetDefaultCursor(MIR_CreateDefaultCursor()); }
void MIR_FiniMouse() { SDL_Mouse* mouse = SDL_GetMouse(); MIR_FreeCursor(mouse->def_cursor); mouse->def_cursor = NULL; mouse->CreateCursor = NULL; mouse->ShowCursor = NULL; mouse->FreeCursor = NULL; mouse->WarpMouse = NULL; mouse->CreateSystemCursor = NULL; mouse->SetRelativeMouseMode = NULL; }
Uint32 SDL_GetRelativeMouseState(int *x, int *y) { SDL_Mouse *mouse = SDL_GetMouse(); if (x) { *x = mouse->xdelta; } if (y) { *y = mouse->ydelta; } mouse->xdelta = 0; mouse->ydelta = 0; return mouse->buttonstate; }
static void MotionAllMice(_THIS, int x, int y) { #if USE_MULTI_API SDL_DFB_DEVICEDATA(_this); int index; for (index = 0; index < devdata->num_mice; index++) { SDL_Mouse *mouse = SDL_GetMouse(index); mouse->x = mouse->last_x = x; mouse->y = mouse->last_y = y; //SDL_SendMouseMotion(devdata->mouse_id[index], 0, x, y, 0); } #endif }
int SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button) { SDL_Mouse *mouse = SDL_GetMouse(); int posted; Uint32 type; if (window) { SDL_SetMouseFocus(window); } /* Figure out which event to perform */ switch (state) { case SDL_PRESSED: if (mouse->buttonstate & SDL_BUTTON(button)) { /* Ignore this event, no state change */ return 0; } type = SDL_MOUSEBUTTONDOWN; mouse->buttonstate |= SDL_BUTTON(button); break; case SDL_RELEASED: if (!(mouse->buttonstate & SDL_BUTTON(button))) { /* Ignore this event, no state change */ return 0; } type = SDL_MOUSEBUTTONUP; mouse->buttonstate &= ~SDL_BUTTON(button); break; default: /* Invalid state -- bail */ return 0; } /* Post the event, if desired */ posted = 0; if (SDL_GetEventState(type) == SDL_ENABLE) { SDL_Event event; event.type = type; event.button.state = state; event.button.button = button; event.button.x = mouse->x; event.button.y = mouse->y; event.button.windowID = mouse->focus ? mouse->focus->id : 0; posted = (SDL_PushEvent(&event) > 0); } return posted; }
int SDL_SetRelativeMouseMode(SDL_bool enabled) { SDL_Mouse *mouse = SDL_GetMouse(); SDL_Window *focusWindow = SDL_GetKeyboardFocus(); if (enabled == mouse->relative_mode) { return 0; } if (enabled && focusWindow) { /* Center it in the focused window to prevent clicks from going through * to background windows. */ SDL_SetMouseFocus(focusWindow); SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2); } /* Set the relative mode */ if (!enabled && mouse->relative_mode_warp) { mouse->relative_mode_warp = SDL_FALSE; } else if (enabled && ShouldUseRelativeModeWarp(mouse)) { mouse->relative_mode_warp = SDL_TRUE; } else if (mouse->SetRelativeMouseMode(enabled) < 0) { if (enabled) { /* Fall back to warp mode if native relative mode failed */ mouse->relative_mode_warp = SDL_TRUE; } } mouse->relative_mode = enabled; if (mouse->focus) { SDL_UpdateWindowGrab(mouse->focus); /* Put the cursor back to where the application expects it */ if (!enabled) { SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y); } } /* Flush pending mouse motion - ideally we would pump events, but that's not always safe */ SDL_FlushEvent(SDL_MOUSEMOTION); /* Update cursor visibility */ SDL_SetCursor(NULL); return 0; }
void SDL_WarpMouseInWindow(SDL_Window * window, int x, int y) { SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse); if (!mouse) { return; } if (mouse->WarpMouse) { mouse->WarpMouse(mouse, window, x, y); } else { SDL_SetMouseFocus(SDL_current_mouse, window); SDL_SendMouseMotion(SDL_current_mouse, 0, x, y, 0); } }
void SDL_ResetMouse(void) { SDL_Mouse *mouse = SDL_GetMouse(); Uint8 i; #ifdef DEBUG_MOUSE printf("Resetting mouse\n"); #endif for (i = 1; i <= sizeof(mouse->buttonstate)*8; ++i) { if (mouse->buttonstate & SDL_BUTTON(i)) { SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, i); } } SDL_assert(mouse->buttonstate == 0); }
void SDL_WarpMouseInWindow(SDL_Window * window, int x, int y) { SDL_Mouse *mouse = SDL_GetMouse(); if (mouse->WarpMouse) { mouse->WarpMouse(window, x, y); // Urho3D: update the internal position mouse->x = x; mouse->y = y; mouse->last_x = x; mouse->last_y = y; } else { SDL_SendMouseMotion(window, 0, x, y); } }
void DirectFB_InitMouse(_THIS) { SDL_DFB_DEVICEDATA(_this); SDL_Mouse *mouse = SDL_GetMouse(); mouse->CreateCursor = DirectFB_CreateCursor; mouse->ShowCursor = DirectFB_ShowCursor; mouse->WarpMouse = DirectFB_WarpMouse; mouse->FreeCursor = DirectFB_FreeCursor; SDL_SetDefaultCursor(DirectFB_CreateDefaultCursor()); devdata->num_mice = 1; }
int SDL_SetRelativeMouseMode(SDL_bool enabled) { SDL_Mouse *mouse = SDL_GetMouse(); SDL_Window *focusWindow = SDL_GetKeyboardFocus(); int original_x = mouse->x, original_y = mouse->y; if (enabled == mouse->relative_mode) { return 0; } if (!mouse->SetRelativeMouseMode) { return SDL_Unsupported(); } if (enabled && focusWindow) { /* Center it in the focused window to prevent clicks from going through * to background windows. */ SDL_SetMouseFocus(focusWindow); SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2); } if (mouse->SetRelativeMouseMode(enabled) < 0) { return -1; } /* Set the relative mode */ mouse->relative_mode = enabled; if (enabled) { /* Save the expected mouse position */ mouse->original_x = original_x; mouse->original_y = original_y; } else if (mouse->focus) { /* Restore the expected mouse position */ SDL_WarpMouseInWindow(mouse->focus, mouse->original_x, mouse->original_y); } /* Flush pending mouse motion */ SDL_FlushEvent(SDL_MOUSEMOTION); /* Update cursor visibility */ SDL_SetCursor(NULL); return 0; }
void X11_InitMouse(_THIS) { SDL_Mouse *mouse = SDL_GetMouse(); mouse->CreateCursor = X11_CreateCursor; mouse->CreateSystemCursor = X11_CreateSystemCursor; mouse->ShowCursor = X11_ShowCursor; mouse->FreeCursor = X11_FreeCursor; mouse->WarpMouse = X11_WarpMouse; mouse->WarpMouseGlobal = X11_WarpMouseGlobal; mouse->SetRelativeMouseMode = X11_SetRelativeMouseMode; mouse->CaptureMouse = X11_CaptureMouse; mouse->GetGlobalMouseState = X11_GetGlobalMouseState; SDL_SetDefaultCursor(X11_CreateDefaultCursor()); }
void RPI_InitMouse(_THIS) { /* FIXME: Using UDEV it should be possible to scan all mice * but there's no point in doing so as there's no multimice support...yet! */ SDL_Mouse *mouse = SDL_GetMouse(); mouse->CreateCursor = RPI_CreateCursor; mouse->ShowCursor = RPI_ShowCursor; mouse->MoveCursor = RPI_MoveCursor; mouse->FreeCursor = RPI_FreeCursor; mouse->WarpMouse = RPI_WarpMouse; mouse->WarpMouseGlobal = RPI_WarpMouseGlobal; SDL_SetDefaultCursor(RPI_CreateDefaultCursor()); }
void SDL_WarpMouseInWindow(SDL_Window * window, int x, int y) { SDL_Mouse *mouse = SDL_GetMouse(); if ( window == NULL ) window = mouse->focus; if ( window == NULL ) return; if (mouse->WarpMouse) { mouse->WarpMouse(window, x, y); } else { SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y); } }
/* Public functions */ int SDL_MouseInit(void) { SDL_Mouse *mouse = SDL_GetMouse(); SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE, SDL_MouseNormalSpeedScaleChanged, mouse); SDL_AddHintCallback(SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE, SDL_MouseRelativeSpeedScaleChanged, mouse); SDL_AddHintCallback(SDL_HINT_TOUCH_MOUSE_EVENTS, SDL_TouchMouseEventsChanged, mouse); mouse->cursor_shown = SDL_TRUE; return (0); }
static void HandleMouseEvent(MirPointerEvent const* pointer, SDL_Window* sdl_window) { SDL_SetMouseFocus(sdl_window); switch (MIR_mir_pointer_event_action(pointer)) { case mir_pointer_action_button_down: HandleMouseButton(sdl_window, SDL_PRESSED, pointer); break; case mir_pointer_action_button_up: HandleMouseButton(sdl_window, SDL_RELEASED, pointer); break; case mir_pointer_action_motion: { int x, y; int hscroll, vscroll; SDL_Mouse* mouse = SDL_GetMouse(); x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_x); y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_y); if (mouse) { if (mouse->relative_mode) { int relative_x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_relative_x); int relative_y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_relative_y); HandleMouseMotion(sdl_window, relative_x, relative_y); } else if (mouse->x != x || mouse->y != y) { HandleMouseMotion(sdl_window, x, y); } } hscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_hscroll); vscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_vscroll); if (vscroll != 0 || hscroll != 0) HandleMouseScroll(sdl_window, hscroll, vscroll); } break; case mir_pointer_action_leave: SDL_SetMouseFocus(NULL); break; case mir_pointer_action_enter: default: break; } }
SDL_Cursor * SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y) { SDL_Mouse *mouse = SDL_GetMouse(); SDL_Surface *temp = NULL; SDL_Cursor *cursor; if (!surface) { SDL_SetError("Passed NULL cursor surface"); return NULL; } if (!mouse->CreateCursor) { SDL_SetError("Cursors are not currently supported"); return NULL; } /* Sanity check the hot spot */ if ((hot_x < 0) || (hot_y < 0) || (hot_x >= surface->w) || (hot_y >= surface->h)) { SDL_SetError("Cursor hot spot doesn't lie within cursor"); return NULL; } if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) { temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0); if (!temp) { return NULL; } surface = temp; } cursor = mouse->CreateCursor(surface, hot_x, hot_y); if (cursor) { cursor->next = mouse->cursors; mouse->cursors = cursor; } if (temp) { SDL_FreeSurface(temp); } return cursor; }
SDL_Cursor * SDL_CreateSystemCursor(SDL_SystemCursor id) { SDL_Mouse *mouse = SDL_GetMouse(); SDL_Cursor *cursor; if (!mouse->CreateSystemCursor) { SDL_SetError("CreateSystemCursor is not currently supported"); return NULL; } cursor = mouse->CreateSystemCursor(id); if (cursor) { cursor->next = mouse->cursors; mouse->cursors = cursor; } return cursor; }
void WIN_UpdateClipCursor(SDL_Window *window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_Mouse *mouse = SDL_GetMouse(); RECT rect; if (data->focus_click_pending) { return; } if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) && (window->flags & SDL_WINDOW_INPUT_FOCUS)) { if (mouse->relative_mode && !mouse->relative_mode_warp) { LONG cx, cy; GetWindowRect(data->hwnd, &rect); cx = (rect.left + rect.right) / 2; cy = (rect.top + rect.bottom) / 2; /* Make an absurdly small clip rect */ rect.left = cx - 1; rect.right = cx + 1; rect.top = cy - 1; rect.bottom = cy + 1; if (ClipCursor(&rect)) { data->cursor_clipped_rect = rect; } } else { if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) { ClientToScreen(data->hwnd, (LPPOINT) & rect); ClientToScreen(data->hwnd, (LPPOINT) & rect + 1); if (ClipCursor(&rect)) { data->cursor_clipped_rect = rect; } } } } else if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) { ClipCursor(NULL); SDL_zero(data->cursor_clipped_rect); } }
void SDL_SetMouseFocus(SDL_Window * window) { SDL_Mouse *mouse = SDL_GetMouse(); if (mouse->focus == window) { return; } /* See if the current window has lost focus */ if (mouse->focus) { SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0); } mouse->focus = window; if (mouse->focus) { SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0); } }
void WIN_UpdateClipCursor(SDL_Window *window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_Mouse *mouse = SDL_GetMouse(); /* Don't clip the cursor while we're in the modal resize or move loop */ if (data->in_title_click || data->in_modal_loop) { ClipCursor(NULL); return; } if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) && (window->flags & SDL_WINDOW_INPUT_FOCUS)) { if (mouse->relative_mode && !mouse->relative_mode_warp) { LONG cx, cy; RECT rect; GetWindowRect(data->hwnd, &rect); cx = (rect.left + rect.right) / 2; cy = (rect.top + rect.bottom) / 2; /* Make an absurdly small clip rect */ rect.left = cx - 1; rect.right = cx + 1; rect.top = cy - 1; rect.bottom = cy + 1; ClipCursor(&rect); } else { RECT rect; if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) { ClientToScreen(data->hwnd, (LPPOINT) & rect); ClientToScreen(data->hwnd, (LPPOINT) & rect + 1); ClipCursor(&rect); } } } else { ClipCursor(NULL); } }
void SDL_MouseQuit(void) { SDL_Cursor *cursor, *next; SDL_Mouse *mouse = SDL_GetMouse(); SDL_ShowCursor(1); cursor = mouse->cursors; while (cursor) { next = cursor->next; SDL_FreeCursor(cursor); cursor = next; } if (mouse->def_cursor && mouse->FreeCursor) { mouse->FreeCursor(mouse->def_cursor); } SDL_zerop(mouse); }
void SDL_WarpMouseInWindow(SDL_Window * window, int x, int y) { SDL_Mouse *mouse = SDL_GetMouse(); if ( window == NULL ) window = mouse->focus; if ( window == NULL ) return; if (mouse->WarpMouse) { mouse->WarpMouse(window, x, y); } else { SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y); } // Urho3D: update mouse internal state immediately mouse->last_x = mouse->x = x; mouse->last_y = mouse->y = y; }
void SDL_MouseQuit(void) { // Urho3D: free default cursor on exit SDL_Mouse *mouse = SDL_GetMouse(); if (!mouse) { return; } if(!mouse->def_cursor) { return; } if(!mouse->FreeCursor) { return; } mouse->FreeCursor(mouse->def_cursor); mouse->def_cursor = 0; }
void SDL_DelMouse(int index) { SDL_Mouse *mouse = SDL_GetMouse(index); if (!mouse) { return; } mouse->def_cursor = NULL; SDL_free(mouse->name); while (mouse->cursors) { SDL_FreeCursor(mouse->cursors); } if (mouse->FreeMouse) { mouse->FreeMouse(mouse); } SDL_free(mouse); SDL_mice[index] = NULL; }
/* SDL_SetCursor(NULL) can be used to force the cursor redraw, if this is desired for any reason. This is used when setting the video mode and when the SDL window gains the mouse focus. */ void SDL_SetCursor(SDL_Cursor * cursor) { SDL_Mouse *mouse = SDL_GetMouse(); /* Set the new cursor */ if (cursor) { /* Make sure the cursor is still valid for this mouse */ if (cursor != mouse->def_cursor) { SDL_Cursor *found; for (found = mouse->cursors; found; found = found->next) { if (found == cursor) { break; } } if (!found) { SDL_SetError("Cursor not associated with the current mouse"); return; } } mouse->cur_cursor = cursor; } else { if (mouse->focus) { cursor = mouse->cur_cursor; } else { cursor = mouse->def_cursor; } } if (cursor && mouse->cursor_shown && !mouse->relative_mode) { if (mouse->ShowCursor) { mouse->ShowCursor(cursor); } } else { if (mouse->ShowCursor) { mouse->ShowCursor(NULL); } } }
Uint32 SDL_GetGlobalMouseState(int *x, int *y) { SDL_Mouse *mouse = SDL_GetMouse(); int tmpx, tmpy; /* make sure these are never NULL for the backend implementations... */ if (!x) { x = &tmpx; } if (!y) { y = &tmpy; } *x = *y = 0; if (!mouse->GetGlobalMouseState) { return 0; } return mouse->GetGlobalMouseState(x, y); }
int SDL_SetRelativeMouseMode(SDL_bool enabled) { SDL_Mouse *mouse = SDL_GetMouse(); if (enabled == mouse->relative_mode) { return 0; } if (!mouse->SetRelativeMouseMode) { SDL_Unsupported(); return -1; } if (mouse->SetRelativeMouseMode(enabled) < 0) { return -1; } /* Set the relative mode */ mouse->relative_mode = enabled; if (enabled) { /* Save the expected mouse position */ mouse->original_x = mouse->x; mouse->original_y = mouse->y; } else if (mouse->focus) { /* Restore the expected mouse position */ SDL_WarpMouseInWindow(mouse->focus, mouse->original_x, mouse->original_y); } /* Flush pending mouse motion */ SDL_FlushEvent(SDL_MOUSEMOTION); /* Update cursor visibility */ SDL_SetCursor(NULL); return 0; }
int SDL_ShowCursor(int toggle) { SDL_Mouse *mouse = SDL_GetMouse(); SDL_bool shown; if (!mouse) { return 0; } shown = mouse->cursor_shown; if (toggle >= 0) { if (toggle) { mouse->cursor_shown = SDL_TRUE; } else { mouse->cursor_shown = SDL_FALSE; } if (mouse->cursor_shown != shown) { SDL_SetCursor(NULL); } } return shown; }