int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch) { SDL_Surface *surface; const Uint32 surface_format = SDL_PIXELFORMAT_RGB888; int w, h; int bpp; Uint32 Rmask, Gmask, Bmask, Amask; /* Free the old framebuffer surface */ surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE); SDL_FreeSurface(surface); /* Create a new one */ SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); SDL_GetWindowSize(window, &w, &h); surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask); if (!surface) { return -1; } /* Save the info and return! */ SDL_SetWindowData(window, DUMMY_SURFACE, surface); *format = surface_format; *pixels = surface->pixels; *pitch = surface->pitch; return 0; }
ZWindow* ZWindowFromId(uint32_t id) { SDL_Window* wnd=SDL_GetWindowFromID(id); if(wnd) return (ZWindow*)SDL_GetWindowData(wnd,WND_USER_DATA); else return NULL; }
int inline Window::getWindowData(State & state, SDL_Window * window){ Stack * stack = state.stack; if (stack->is<LUA_TSTRING>(1)){ const std::string name = stack->to<const std::string>(1); stack->push<void*>(SDL_GetWindowData(window, name.c_str())); return 1; } return 0; }
static cg_filter_return_t sdl_window_event_filter(SDL_WindowEvent *event, cg_device_t *dev) { SDL_Window *window; cg_framebuffer_t *framebuffer; window = SDL_GetWindowFromID(event->windowID); if (window == NULL) return CG_FILTER_CONTINUE; framebuffer = SDL_GetWindowData(window, CG_SDL_WINDOW_DATA_KEY); if (framebuffer == NULL || framebuffer->dev != dev) return CG_FILTER_CONTINUE; if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) { cg_display_t *display = dev->display; cg_renderer_t *renderer = display->renderer; cg_renderer_sdl2_t *sdl_renderer = renderer->winsys; float width = event->data1; float height = event->data2; cg_onscreen_sdl2_t *sdl_onscreen; _cg_framebuffer_winsys_update_size(framebuffer, width, height); /* We only want to notify that a resize happened when the * application calls cg_device_dispatch so instead of * immediately notifying we queue an idle callback */ if (!sdl_renderer->resize_notify_idle) { sdl_renderer->resize_notify_idle = _cg_loop_add_idle( renderer, flush_pending_resize_notifications_idle, dev, NULL); } sdl_onscreen = CG_ONSCREEN(framebuffer)->winsys; sdl_onscreen->pending_resize_notify = true; } else if (event->event == SDL_WINDOWEVENT_EXPOSED) { cg_onscreen_dirty_info_t info; /* Sadly SDL doesn't seem to report the rectangle of the expose * event so we'll just queue the whole window */ info.x = 0; info.y = 0; info.width = framebuffer->width; info.height = framebuffer->height; _cg_onscreen_queue_dirty(CG_ONSCREEN(framebuffer), &info); } return CG_FILTER_CONTINUE; }
int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects) { static int frame_number; SDL_Surface *surface; surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE); if (!surface) { return SDL_SetError("Couldn't find dummy surface for window"); } /* Send the data to the display */ if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) { char file[128]; SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp", SDL_GetWindowID(window), ++frame_number); SDL_SaveBMP(surface, file); } return 0; }
static CoglFilterReturn sdl_event_filter_cb (SDL_Event *event, void *data) { if (event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { CoglContext *context = data; CoglDisplay *display = context->display; CoglDisplaySdl2 *sdl_display = display->winsys; float width = event->window.data1; float height = event->window.data2; CoglFramebuffer *framebuffer; CoglOnscreenSdl2 *sdl_onscreen; SDL_Window *window; window = SDL_GetWindowFromID (event->window.windowID); if (window == NULL) return COGL_FILTER_CONTINUE; framebuffer = SDL_GetWindowData (window, COGL_SDL_WINDOW_DATA_KEY); if (framebuffer == NULL || framebuffer->context != context) return COGL_FILTER_CONTINUE; _cogl_framebuffer_winsys_update_size (framebuffer, width, height); sdl_onscreen = COGL_ONSCREEN (framebuffer)->winsys; /* We only want to notify that a resize happened when the application calls cogl_context_dispatch so instead of immediately notifying we'll set a flag to remember to notify later */ sdl_display->pending_resize_notify = TRUE; sdl_onscreen->pending_resize_notify = TRUE; return COGL_FILTER_CONTINUE; } return COGL_FILTER_CONTINUE; }
SDL_Renderer * SDL_GetRenderer(SDL_Window * window) { return (SDL_Renderer *)SDL_GetWindowData(window, SDL_WINDOWRENDERDATA); }
void SDL_handleEvent(SDL_Event &event, bool &done) { Input *input = &Input::instance; #ifndef EMSCRIPTEN SDL_Window *wnd = SDL_GetWindowFromID(event.window.windowID); void *data = SDL_GetWindowData(wnd, "_"); spStage stage = (Stage*)data; #else spStage stage = getStage(); #endif if (!stage) stage = getStage(); Event ev(Input::event_platform); ev.userData = &event; Input::instance.dispatchEvent(&ev); switch (event.type) { case SDL_QUIT: done = true; break; case SDL_WINDOWEVENT: { /* if (event.window.event == SDL_WINDOWEVENT_ENTER) active = false; if (event.window.event == SDL_WINDOWEVENT_LEAVE) active = true; */ if (event.window.event == SDL_WINDOWEVENT_MINIMIZED) active = false; if (event.window.event == SDL_WINDOWEVENT_RESTORED) active = true; bool newFocus = focus; if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) newFocus = false; if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) newFocus = true; if (focus != newFocus) { focus = newFocus; #if HANDLE_FOCUS_LOST if (focus) focusAcquired(); log::messageln("focus: %d", (int)focus); Event ev(focus ? Stage::ACTIVATE : Stage::DEACTIVATE); if (stage) stage->dispatchEvent(&ev); if (!focus) focusLost(); #endif } //log::messageln("SDL_SYSWMEVENT %d", (int)event.window.event); break; } case SDL_MOUSEWHEEL: input->sendPointerWheelEvent(stage, event.wheel.y, &input->_pointerMouse); break; case SDL_KEYDOWN: { KeyEvent ev(KeyEvent::KEY_DOWN, &event.key); stage->dispatchEvent(&ev); } break; case SDL_KEYUP: { KeyEvent ev(KeyEvent::KEY_UP, &event.key); stage->dispatchEvent(&ev); } break; #if SDL_VIDEO_OPENGL case SDL_MOUSEMOTION: input->sendPointerMotionEvent(stage, (float)event.motion.x, (float)event.motion.y, 1.0f, &input->_pointerMouse); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { MouseButton b = MouseButton_Left; switch (event.button.button) { case 1: b = MouseButton_Left; break; case 2: b = MouseButton_Middle; break; case 3: b = MouseButton_Right; break; } input->sendPointerButtonEvent(stage, b, (float)event.button.x, (float)event.button.y, 1.0f, event.type == SDL_MOUSEBUTTONDOWN ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP, &input->_pointerMouse); } break; #else case SDL_FINGERMOTION: { //log::messageln("SDL_FINGERMOTION"); Vector2 pos = convertTouch(event); input->sendPointerMotionEvent(stage, pos.x, pos.y, event.tfinger.pressure, input->getTouchByID((int)event.tfinger.fingerId)); } break; case SDL_FINGERDOWN: case SDL_FINGERUP: { //log::messageln("SDL_FINGER"); Vector2 pos = convertTouch(event); input->sendPointerButtonEvent(stage, MouseButton_Touch, pos.x, pos.y, event.tfinger.pressure, event.type == SDL_FINGERDOWN ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP, input->getTouchByID((int)event.tfinger.fingerId)); } break; #endif } }
static Ecore_Evas * _ecore_evas_sdl_match(unsigned int windowID) { return SDL_GetWindowData(SDL_GetWindowFromID(windowID), "_Ecore_Evas"); }
ZWindow* ZWindowFromWindow(SDL_Window* wnd) { return (ZWindow*)SDL_GetWindowData(wnd,WND_USER_DATA); }