25 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
26 throw std::runtime_error(SDL_GetError());
29 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
30 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
31 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
32 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
33 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
41GHOST_IWindow *GHOST_SystemSDL::createWindow(
const char *title,
73 SDL_SetWindowDisplayMode(sdl_win, &mode);
74 SDL_ShowWindow(sdl_win);
75 SDL_SetWindowFullscreen(sdl_win, SDL_TRUE);
111 SDL_DisplayMode mode;
112 const int display_index = 0;
113 if (SDL_GetDesktopDisplayMode(display_index, &mode) < 0) {
122 SDL_DisplayMode mode;
123 const int display_index = 0;
124 if (SDL_GetCurrentDisplayMode(display_index, &mode) < 0) {
133 return SDL_GetNumVideoDisplays();
139#ifdef WITH_OPENGL_BACKEND
140 case GHOST_kDrawingContextTypeOpenGL: {
141 for (
int minor = 6; minor >= 3; --minor) {
151 if (context->initializeDrawingContext()) {
175 SDL_Keymod
mod = SDL_GetModState();
189#define GXMAP(k, x, y) \
198 if ((key >= SDL_SCANCODE_A) && (key <= SDL_SCANCODE_Z)) {
201 else if ((key >= SDL_SCANCODE_1) && (key <= SDL_SCANCODE_0)) {
205 else if ((key >= SDL_SCANCODE_F1) && (key <= SDL_SCANCODE_F12)) {
208 else if ((key >= SDL_SCANCODE_F13) && (key <= SDL_SCANCODE_F24)) {
309 SDL_Keycode sym = sdl_sub_evt.keysym.sym;
315 case SDLK_KP_MULTIPLY:
363 if (sdl_sub_evt.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) {
365 if (sym >=
'a' && sym <= (
'a' + 32)) {
448 SDL_Window *sdl_win = SDL_GetWindowFromID(
id);
449 if (sdl_win ==
nullptr) {
450 sdl_win = SDL_GL_GetCurrentWindow();
455void GHOST_SystemSDL::processEvent(SDL_Event *sdl_event)
459 switch (sdl_event->type) {
460 case SDL_WINDOWEVENT: {
461 const SDL_WindowEvent &sdl_sub_evt = sdl_event->window;
462 const uint64_t event_ms = sdl_sub_evt.timestamp;
467 assert(window !=
nullptr);
470 switch (sdl_sub_evt.event) {
471 case SDL_WINDOWEVENT_EXPOSED:
474 case SDL_WINDOWEVENT_RESIZED:
477 case SDL_WINDOWEVENT_MOVED:
480 case SDL_WINDOWEVENT_FOCUS_GAINED:
483 case SDL_WINDOWEVENT_FOCUS_LOST:
486 case SDL_WINDOWEVENT_CLOSE:
495 const SDL_QuitEvent &sdl_sub_evt = sdl_event->quit;
496 const uint64_t event_ms = sdl_sub_evt.timestamp;
502 case SDL_MOUSEMOTION: {
503 const SDL_MouseMotionEvent &sdl_sub_evt = sdl_event->motion;
504 const uint64_t event_ms = sdl_sub_evt.timestamp;
507 assert(window !=
nullptr);
510 SDL_GetWindowPosition(sdl_win, &x_win, &y_win);
512 int32_t x_root = sdl_sub_evt.x + x_win;
513 int32_t y_root = sdl_sub_evt.y + y_win;
533 if (x_new != x_root || y_new != y_root) {
537 SDL_WarpMouseInWindow(sdl_win, x_new - x_win, y_new - y_win);
543 SDL_WarpMouseInWindow(sdl_win, x_new - x_win, y_new - y_win);
570 case SDL_MOUSEBUTTONUP:
571 case SDL_MOUSEBUTTONDOWN: {
572 const SDL_MouseButtonEvent &sdl_sub_evt = sdl_event->button;
573 const uint64_t event_ms = sdl_sub_evt.timestamp;
580 assert(window !=
nullptr);
583 if (sdl_sub_evt.button == SDL_BUTTON_LEFT) {
586 else if (sdl_sub_evt.button == SDL_BUTTON_MIDDLE) {
589 else if (sdl_sub_evt.button == SDL_BUTTON_RIGHT) {
593 else if (sdl_sub_evt.button == SDL_BUTTON_X1) {
596 else if (sdl_sub_evt.button == SDL_BUTTON_X2) {
606 case SDL_MOUSEWHEEL: {
607 const SDL_MouseWheelEvent &sdl_sub_evt = sdl_event->wheel;
608 const uint64_t event_ms = sdl_sub_evt.timestamp;
611 assert(window !=
nullptr);
617 const SDL_KeyboardEvent &sdl_sub_evt = sdl_event->key;
618 const uint64_t event_ms = sdl_sub_evt.timestamp;
621 const bool is_repeat = sdl_sub_evt.repeat != 0;
625 assert(window !=
nullptr);
638 g_event =
new GHOST_EventKey(event_ms, type, window, gkey, is_repeat, utf8_buf);
651 SDL_Window *win = SDL_GetMouseFocus();
652 SDL_GetWindowPosition(win, &x_win, &y_win);
655 SDL_GetMouseState(&xi, &yi);
665 SDL_Window *win = SDL_GetMouseFocus();
666 SDL_GetWindowPosition(win, &x_win, &y_win);
668 SDL_WarpMouseInWindow(win, x - x_win, y - y_win);
672bool GHOST_SystemSDL::generateWindowExposeEvents()
674 std::vector<GHOST_WindowSDL *>::iterator w_start = m_dirty_windows.begin();
675 std::vector<GHOST_WindowSDL *>::const_iterator w_end = m_dirty_windows.end();
676 bool anyProcessed =
false;
678 for (; w_start != w_end; ++w_start) {
683 (*w_start)->validate();
692 m_dirty_windows.clear();
701 bool anyProcessed =
false;
706 if (waitForEvent && m_dirty_windows.empty() && !SDL_HasEvents(SDL_FIRSTEVENT, SDL_LASTEVENT)) {
710 SDL_WaitEventTimeout(
nullptr, -1);
728 while (SDL_PollEvent(&sdl_event)) {
729 processEvent(&sdl_event);
733 if (generateWindowExposeEvents()) {
736 }
while (waitForEvent && !anyProcessed);
743 if (sdl_win ==
nullptr) {
753 std::vector<GHOST_IWindow *>::const_iterator win_it = win_vec.begin();
754 std::vector<GHOST_IWindow *>::const_iterator win_end = win_vec.end();
756 for (; win_it != win_end; ++win_it) {
767 GHOST_ASSERT((bad_wind !=
nullptr),
"addDirtyWindow() nullptr ptr trapped (window)");
769 m_dirty_windows.push_back(bad_wind);
774 Uint8
state = SDL_GetMouseState(
nullptr,
nullptr);
799 return (
char *)SDL_GetClipboardText();
804 SDL_SetClipboardText(buffer);
809 return SDL_GetTicks64();
#define GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY
#define GHOST_OPENGL_SDL_CONTEXT_FLAGS
#define GHOST_ASSERT(x, info)
static char convert_keyboard_event_to_ascii(const SDL_KeyboardEvent &sdl_sub_evt)
static GHOST_TKey convertSDLKey(SDL_Scancode key)
static SDL_Window * SDL_GetWindowFromID_fallback(Uint32 id)
@ GHOST_kWindowStateFullScreen
@ GHOST_kEventWindowClose
@ GHOST_kEventWindowActivate
@ GHOST_kEventWindowUpdate
@ GHOST_kEventWindowDeactivate
@ GHOST_kEventQuitRequest
static const GHOST_TabletData GHOST_TABLET_DATA_NONE
@ GHOST_kCapabilityInputIME
@ GHOST_kCapabilityClipboardImages
@ GHOST_kCapabilityPrimaryClipboard
@ GHOST_kCapabilityDesktopSample
#define GHOST_CAPABILITY_FLAG_ALL
@ GHOST_kKeyNumpadAsterisk
@ GHOST_kModifierKeyRightControl
@ GHOST_kModifierKeyLeftControl
@ GHOST_kModifierKeyRightAlt
@ GHOST_kModifierKeyRightShift
@ GHOST_kModifierKeyLeftAlt
@ GHOST_kModifierKeyLeftShift
@ GHOST_kModifierKeyLeftOS
@ GHOST_kModifierKeyRightOS
@ GHOST_kButtonMaskButton4
@ GHOST_kButtonMaskButton5
@ GHOST_kButtonMaskMiddle
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
GHOST_IContext * createOffscreenContext(GHOST_GPUSettings gpuSettings) override
GHOST_TSuccess getCursorPosition(int32_t &x, int32_t &y) const override
GHOST_TSuccess setCursorPosition(int32_t x, int32_t y) override
char * getClipboard(bool selection) const override
void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const override
GHOST_TCapabilityFlag getCapabilities() const override
void addDirtyWindow(GHOST_WindowSDL *bad_wind)
void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const override
uint8_t getNumDisplays() const override
GHOST_TSuccess disposeContext(GHOST_IContext *context) override
void putClipboard(const char *buffer, bool selection) const override
GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const override
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &keys) const override
uint64_t getMilliSeconds() const override
bool processEvents(bool waitForEvent) override
virtual GHOST_TSuccess init()
GHOST_TimerManager * getTimerManager() const
GHOST_WindowManager * m_windowManager
GHOST_DisplayManager * m_displayManager
bool fireTimers(uint64_t time)
GHOST_TSuccess addWindow(GHOST_IWindow *window)
const std::vector< GHOST_IWindow * > & getWindows() const
GHOST_IWindow * getActiveWindow() const
SDL_Window * getSDLWindow()
void getClientBounds(GHOST_Rect &bounds) const override
bool getValid() const override
GHOST_TSuccess getCursorGrabBounds(GHOST_Rect &bounds) const override
void setCursorGrabAccum(int32_t x, int32_t y)
GHOST_TAxisFlag getCursorGrabAxis() const
GHOST_TGrabCursorMode getCursorGrabMode() const
void getCursorGrabAccum(int32_t &x, int32_t &y) const
unsigned __int64 uint64_t
GHOST_TDrawingContextType context_type
void set(GHOST_TModifierKey mask, bool down)
ccl_device_inline int mod(int x, int m)