void SDLMouse::setCursor( MouseCursor* mc ) { pCursor = (SDLMouseCursor*)mc; if ( pCursor != NULL ) { if ( pCursor->isSystem() ) { SDL_SetCursor( pCursor->getSDLCursorObject() ); } else { } } }
static void sdl_hide_cursor(void) { if (!cursor_hide) return; if (kbd_mouse_is_absolute()) { SDL_ShowCursor(1); SDL_SetCursor(sdl_cursor_hidden); } else { SDL_ShowCursor(0); } }
bool Game::MouseDragReset(Entity *object) { //Cursor on Hover if(dragOne == true && object->draggable == false) return false; int mouseX = 0; int mouseY = 0; SDL_GetMouseState(&mouseX, &mouseY); if(object->Hover(mouseX, mouseY) == true) { SDL_SetCursor(Cursor); if(LeftButtonPressed == true) object->draggable = true; } if(LeftButtonPressed == false) object->draggable = false; if(object->draggable == true) { object->XPos = mouseX - object->Width / 2; object->YPos = mouseY - object->Height / 2; SDL_SetCursor(DragCursor); dragOne = true; return true; } else { dragOne = false; object->XPos = object->defaultX; object->YPos = object->defaultY; return false; } }
//------------------------------------------------------------------------------------------------------ //setter function that creates a system mouse cursor //------------------------------------------------------------------------------------------------------ void InputManager::SetMouseCursorType(CursorType cursorType) { //first destroy old cursor object from memory SDL_FreeCursor(m_cursor); //based on type of cursor value passed, create mouse cursor using SDL ID flag value m_cursor = SDL_CreateSystemCursor(SDL_SystemCursor(cursorType)); //use cursor pointer to assign cursor to SDL SDL_SetCursor(m_cursor); }
static void sdl_grab_start(void) { if (guest_cursor) { SDL_SetCursor(guest_sprite); SDL_WarpMouse(guest_x, guest_y); } else sdl_hide_cursor(); SDL_WM_GrabInput(SDL_GRAB_ON); /* dummy read to avoid moving the mouse */ SDL_GetRelativeMouseState(NULL, NULL); gui_grab = 1; sdl_update_caption(); }
void InputDeviceSDL2::setMouseIcon(const std::string& name, const Point& hotSpot) { auto it = m_cursors.find(name); if (it == m_cursors.end()) { auto fullPath = oContentManager->findResourceFile(name); if (!fullPath.empty()) { Point size; auto pngData = onut::loadPNG(fullPath, size); if (!pngData.empty()) { auto pSurface = SDL_CreateRGBSurfaceFrom(pngData.data(), size.x, size.y, 32, size.x * 4, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); if (pSurface) { auto pCursor = SDL_CreateColorCursor(pSurface, hotSpot.x, hotSpot.y); if (pCursor) { m_cursors[name] = pCursor; SDL_SetCursor(pCursor); } SDL_FreeSurface(pSurface); } } } } else { SDL_SetCursor(it->second); } }
void break_computer_throw_cards_animation(void) { /** Computer throw cards animation end function. **/ game_control->GAME_STATUS = CARDS_THROW ; game_control->SAVED_GAME_STATUS = CARDS_THROW ; game_control->is_animation_running = false ; game_control->cursor_type = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW) ; SDL_SetCursor(game_control->cursor_type) ; return ; }
void I_ShutdownGraphics(void) { if (initialized) { SDL_SetCursor(cursors[1]); SDL_ShowCursor(1); SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_QuitSubSystem(SDL_INIT_VIDEO); initialized = false; } }
static void sdl_hide_cursor(void) { if (!cursor_hide) { return; } if (qemu_input_is_absolute()) { SDL_ShowCursor(1); SDL_SetCursor(sdl_cursor_hidden); } else { SDL_SetRelativeMouseMode(SDL_TRUE); } }
void Cursor::enable() { if (mAnimationFrames.size() > 1) { // Animated, set the begin and do everything else in setCurrentFrame() mBeginTimeStamp = timestamp(); mLastFrame = static_cast<size_t>(-1); } else { // Not animated, just set the first frame SDL_SetCursor(mAnimationFrames.front()); } }
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; mouse->scale_accum_x = 0.0f; mouse->scale_accum_y = 0.0f; 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 initmouse(void) { mouse = 1; setmousesens(M_MEDIUM); #ifdef PANDORA Uint8 noData = 0; fakeCursor = SDL_CreateCursor(&noData, &noData, 8, 1, 0, 0); SDL_ShowCursor(SDL_ENABLE); SDL_SetCursor(fakeCursor); #else //SDL_ShowCursor(SDL_DISABLE); #endif }
~sdl_cursor_handler() { m_inited = false; if (m_system_cursor) { SDL_SetCursor(m_system_cursor); m_system_cursor = NULL; } if (m_active_cursor) { SDL_FreeCursor(m_active_cursor); m_active_cursor = NULL; } }
void set_cursor(gameswf::render_handler::cursor_type cursor) { if (!m_inited) { init(); } switch (cursor) { case gameswf::render_handler::SYSTEM_CURSOR: if (m_system_cursor) { SDL_SetCursor(m_system_cursor); } break; case gameswf::render_handler::ACTIVE_CURSOR: if (m_active_cursor) { SDL_SetCursor(m_active_cursor); } break; default: assert(0); } }
void Cursor::ApplyShape() { CursorShapeInfo& info = shapeInfos_[shape_]; texture_ = info.texture_; imageRect_ = info.imageRect_; SetSize(info.imageRect_.Size()); // If the OS cursor is being shown, define/set SDL cursor shape if necessary // Only do this when we are the active UI cursor if (GetSubsystem<Input>()->IsMouseVisible() && GetSubsystem<UI>()->GetCursor() == this) { // Remove existing SDL cursor if is not a system shape while we should be using those, or vice versa if (info.osCursor_ && info.systemDefined_ != useSystemShapes_) { SDL_FreeCursor(info.osCursor_); info.osCursor_ = 0; } // Create SDL cursor now if necessary if (!info.osCursor_) { // Create a system default shape if (useSystemShapes_) { info.osCursor_ = SDL_CreateSystemCursor((SDL_SystemCursor)osCursorLookup[shape_]); info.systemDefined_ = true; if (!info.osCursor_) LOGERROR("Could not create system cursor"); } // Create from image else if (info.image_) { SDL_Surface* surface = info.image_->GetSDLSurface(info.imageRect_); if (surface) { info.osCursor_ = SDL_CreateColorCursor(surface, info.hotSpot_.x_, info.hotSpot_.y_); info.systemDefined_ = false; if (!info.osCursor_) LOGERROR("Could not create cursor from image " + info.image_->GetName()); SDL_FreeSurface(surface); } } } if (info.osCursor_) SDL_SetCursor(info.osCursor_); } }
void Cursor::ApplyOSCursorShape() { // Mobile platforms do not support applying OS cursor shapes: comment out to avoid log error messages #if !defined(ANDROID) && !defined(IOS) if (!osShapeDirty_ || !GetSubsystem<Input>()->IsMouseVisible() || GetSubsystem<SystemUI>()->GetCursor() != this) return; CursorShapeInfo& info = shapeInfos_[shape_]; // Remove existing SDL cursor if is not a system shape while we should be using those, or vice versa if (info.osCursor_ && info.systemDefined_ != useSystemShapes_) { SDL_FreeCursor(info.osCursor_); info.osCursor_ = 0; } // Create SDL cursor now if necessary if (!info.osCursor_) { // Create a system default shape if (useSystemShapes_ && info.systemCursor_ >= 0 && info.systemCursor_ < CS_MAX_SHAPES) { info.osCursor_ = SDL_CreateSystemCursor((SDL_SystemCursor)osCursorLookup[info.systemCursor_]); info.systemDefined_ = true; if (!info.osCursor_) ATOMIC_LOGERROR("Could not create system cursor"); } // Create from image else if (info.image_) { SDL_Surface* surface = info.image_->GetSDLSurface(info.imageRect_); if (surface) { info.osCursor_ = SDL_CreateColorCursor(surface, info.hotSpot_.x_, info.hotSpot_.y_); info.systemDefined_ = false; if (!info.osCursor_) ATOMIC_LOGERROR("Could not create cursor from image " + info.image_->GetName()); SDL_FreeSurface(surface); } } } if (info.osCursor_) SDL_SetCursor(info.osCursor_); osShapeDirty_ = false; #endif }
static void sdlwindow_update_cursor_state(running_machine *machine, sdl_window_info *window) { #if (SDL_VERSION_ATLEAST(1,3,0)) // do not do mouse capture if the debugger's enabled to avoid // the possibility of losing control if (!(machine->debug_flags & DEBUG_FLAG_OSD_ENABLED)) { //FIXME: SDL1.3: really broken: the whole SDL code // will only work correct with relative mouse movements ... //SDL_SetRelativeMouseMode if (!window->fullscreen && !sdlinput_should_hide_mouse(machine)) { SDL_ShowCursor(SDL_ENABLE); if (SDL_GetWindowGrab(window->sdl_window )) SDL_SetWindowGrab(window->sdl_window, 0); } else { SDL_ShowCursor(SDL_DISABLE); if (!SDL_GetWindowGrab(window->sdl_window)) SDL_SetWindowGrab(window->sdl_window, 1); } SDL_SetCursor(NULL); // Force an update in case the underlying driver has changed visibility } #else // do not do mouse capture if the debugger's enabled to avoid // the possibility of losing control if (!(machine->debug_flags & DEBUG_FLAG_OSD_ENABLED)) { if ( window->fullscreen || sdlinput_should_hide_mouse(machine) ) { SDL_ShowCursor(SDL_DISABLE); if (!SDL_WM_GrabInput(SDL_GRAB_QUERY)) { SDL_WM_GrabInput(SDL_GRAB_ON); } } else { SDL_ShowCursor(SDL_ENABLE); if (SDL_WM_GrabInput(SDL_GRAB_QUERY)) { SDL_WM_GrabInput(SDL_GRAB_OFF); } } } #endif }
void Game::MouseDrag(Entity *object, Camera *cam) { //Cursor on Hover if(dragOne == true && object->draggable == false) return; int mouseX = 0; int mouseY = 0; SDL_GetMouseState(&mouseX, &mouseY); mouseX -= cam->camX; mouseY -= cam->camY; if(object->Hover(mouseX, mouseY, cam) == true) { SDL_SetCursor(Cursor); if(LeftButtonPressed == true) object->draggable = true; } if(LeftButtonPressed == false) object->draggable = false; if(object->draggable == true) { object->XPos = mouseX - (object->Width * cam->camZoom) / 2; object->YPos = mouseY - (object->Height * cam->camZoom) / 2; SDL_SetCursor(DragCursor); dragOne = true; } else dragOne = false; }
void PPDisplayDevice::setMouseCursor(MouseCursorTypes type) { currentCursorType = type; switch (type) { case MouseCursorTypeStandard: SDL_SetCursor(cursorStandard); break; case MouseCursorTypeResizeLeft: case MouseCursorTypeResizeRight: SDL_SetCursor(cursorResizeHoriz); break; case MouseCursorTypeHand: SDL_SetCursor(cursorHand); break; case MouseCursorTypeWait: SDL_SetCursor(cursorEggtimer); break; } }
static void sdl_grab_start(void) { if (guest_cursor) { SDL_SetCursor(guest_sprite); if (!kbd_mouse_is_absolute() && !absolute_enabled) SDL_WarpMouse(guest_x, guest_y); } else sdl_hide_cursor(); if (SDL_WM_GrabInput(SDL_GRAB_ON) == SDL_GRAB_ON) { gui_grab = 1; sdl_update_caption(); } else sdl_show_cursor(); }
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 init_win32() { SDL_Cursor *cursor = SDL_GetCursor(); HINSTANCE handle = GetModuleHandle(NULL); //((struct zWMcursor *)cursor->wm_cursor)->curs = (void *)LoadCursorA(NULL, IDC_ARROW); ((struct zWMcursor *)cursor->wm_cursor)->curs = (void *)LoadCursor(NULL, IDC_ARROW); SDL_SetCursor(cursor); icon = LoadIcon(handle, (char *)101); SDL_GetWMInfo(&wminfo); hwnd = wminfo.window; SetClassLong(hwnd, GCL_HICON, (LONG)icon); SDL_putenv("SDL_VIDEO_WINDOW_POS=center"); SDL_putenv("SDL_VIDEO_CENTERED=center"); }
static VALUE sdl_setCursor_imp(VALUE mod,VALUE data,VALUE mask,VALUE w, VALUE h,VALUE hot_x,VALUE hot_y) { SDL_Cursor *newCursor; newCursor=SDL_CreateCursor(GETCSTR(data),GETCSTR(mask),NUM2INT(w), NUM2INT(h),NUM2INT(hot_x),NUM2INT(hot_y)); if( newCursor==NULL ) rb_raise(eSDLError,"cursor creation failed :%s",SDL_GetError()); SDL_SetCursor(newCursor); /* free old cursor */ if( cursor!=NULL ) SDL_FreeCursor(cursor); cursor=newCursor; return Qnil; }
void Game::OnLoop() { //Gets the start ticks OnStartup(); //Set default cursor every frame SDL_SetCursor(SDL_GetDefaultCursor()); if(LeftButtonPressed == true) { Map1.building = true; } //Caps the frame rate depending on the ticks that have past FrameRate(FPS); }
int fs_ml_main_loop() { while (g_fs_ml_running) { fs_ml_event_loop(); process_video_events(); #if defined(WINDOWS) || defined (MACOSX) fs_ml_prevent_power_saving(); #endif fs_ml_render_iteration(); } if (g_fs_emu_video_fullscreen) { if (SDL_getenv("FSGS_RETURN_CURSOR_TO") && SDL_getenv("FSGS_RETURN_CURSOR_TO")[0]) { // we want to improve the transitioning from FS-UAE back to // e.g. FS-UAE Game Center - avoid blinking cursor - so we try // to move it (to the bottom right of the screen). This probably // requires that the cursor is not grabbed (SDL often keeps the // cursor in the center of the screen, then). int x = -1; int y = -1; sscanf(SDL_getenv("FSGS_RETURN_CURSOR_TO"), "%d,%d", &x, &y); if (x != -1 && y != -1) { fs_log("trying to move mouse cursor to x=%d y=%d\n", x, y); Uint8 data[] = "\0"; #ifdef USE_SDL2 SDL_SetWindowGrab(g_fs_ml_window, SDL_FALSE); #else SDL_WM_GrabInput(SDL_GRAB_OFF); #endif // setting invisible cursor so we won't see it when we // enable the cursor in order to move it SDL_Cursor *cursor = SDL_CreateCursor(data, data, 8, 1, 0, 0); SDL_SetCursor(cursor); SDL_ShowCursor(SDL_ENABLE); #ifdef USE_SDL2 SDL_WarpMouseInWindow(g_fs_ml_window, x, y); #else SDL_WarpMouse(x, y); #endif } } } return 0; }
void sdl_window::set_mouse_cursor(mouse_system_cursor aSystemCursor) { SDL_SystemCursor sdlCursor = SDL_SYSTEM_CURSOR_ARROW; switch (aSystemCursor) { case mouse_system_cursor::Arrow: sdlCursor = SDL_SYSTEM_CURSOR_ARROW; break; case mouse_system_cursor::Ibeam: sdlCursor = SDL_SYSTEM_CURSOR_IBEAM; break; case mouse_system_cursor::Wait: sdlCursor = SDL_SYSTEM_CURSOR_WAIT; break; case mouse_system_cursor::Crosshair: sdlCursor = SDL_SYSTEM_CURSOR_CROSSHAIR; break; case mouse_system_cursor::WaitArrow: sdlCursor = SDL_SYSTEM_CURSOR_WAITARROW; break; case mouse_system_cursor::SizeNWSE: sdlCursor = SDL_SYSTEM_CURSOR_SIZENWSE; break; case mouse_system_cursor::SizeNESW: sdlCursor = SDL_SYSTEM_CURSOR_SIZENESW; break; case mouse_system_cursor::SizeWE: sdlCursor = SDL_SYSTEM_CURSOR_SIZEWE; break; case mouse_system_cursor::SizeNS: sdlCursor = SDL_SYSTEM_CURSOR_SIZENS; break; case mouse_system_cursor::SizeAll: sdlCursor = SDL_SYSTEM_CURSOR_SIZEALL; break; case mouse_system_cursor::No: sdlCursor = SDL_SYSTEM_CURSOR_NO; break; case mouse_system_cursor::Hand: sdlCursor = SDL_SYSTEM_CURSOR_HAND; break; } iCurrentCursor = cursor_pointer(cursor_pointer(), SDL_CreateSystemCursor(sdlCursor)); SDL_SetCursor(&*iCurrentCursor); }
void BuyState::update(const float deltaTime) { #ifndef ANDROID_BUILD SDL_Point mousePosRunning; SDL_GetMouseState(&mousePosRunning.x, &mousePosRunning.y); SDL_Rect turretRect = getRect(turret_); if (!SDL_EnclosePoints(&mousePosRunning, 1, &turretRect, NULL)) { SDL_Cursor* cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); SDL_SetCursor(cursor); Game::getInstance().toPop_ = name(); } #else #endif }
void Cursor::setCurrentFrame() { if (mAnimationFrames.size() > 1) { // We are animated, compute the current frame float diffSeconds = i2fl(timestamp() - mBeginTimeStamp) / TIMESTAMP_FREQUENCY; // Use the bmpman function for this. That also ensures that APNG cursors work correctly auto frameIndex = static_cast<size_t>(bm_get_anim_frame(mBitmapHandle, diffSeconds, 0.0f, true)); Assert(frameIndex < mAnimationFrames.size()); if (mLastFrame != frameIndex) { SDL_SetCursor(mAnimationFrames[frameIndex]); mLastFrame = frameIndex; } } }
void break_give_new_cards_animation(void) { if (! game_control->distribute && ! give_order) { give_order=true ; return ; } else if (game_control->distribute && give_order) { give_order=false ; return ; } game_control->GAME_STATUS = NEW_CARDS_GIVEN ; game_control->cursor_type = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW) ; SDL_SetCursor(game_control->cursor_type) ; game_control->is_animation_running = false ; return ; }
static void ImGui_ImplSDL2_UpdateMouseCursor() { ImGuiIO& io = ImGui::GetIO(); if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) return; ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor(); if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None) { // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor SDL_ShowCursor(SDL_FALSE); } else { // Show OS mouse cursor SDL_SetCursor(g_MouseCursors[imgui_cursor] ? g_MouseCursors[imgui_cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]); SDL_ShowCursor(SDL_TRUE); } }