mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Added SDL2_DIR when using --with-sdl GENie config.
This commit is contained in:
parent
4ba9212d35
commit
8abed27c0c
3 changed files with 127 additions and 85 deletions
|
@ -57,15 +57,37 @@ namespace entry
|
||||||
static int32_t threadFunc(void* _userData);
|
static int32_t threadFunc(void* _userData);
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint32_t s_userEventStart = SDL_USEREVENT;
|
///
|
||||||
|
inline void* sdlNativeWindowHandle(SDL_Window* _window)
|
||||||
|
{
|
||||||
|
SDL_SysWMinfo wmi;
|
||||||
|
SDL_VERSION(&wmi.version);
|
||||||
|
if (!SDL_GetWindowWMInfo(_window, &wmi) )
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#define SDL_USER_WINDOW_CREATE (s_userEventStart+0)
|
# if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
|
||||||
#define SDL_USER_WINDOW_DESTROY (s_userEventStart+1)
|
return wmi.info.x11.window;
|
||||||
#define SDL_USER_WINDOW_SET_TITLE (s_userEventStart+2)
|
# elif BX_PLATFORM_OSX
|
||||||
#define SDL_USER_WINDOW_SET_POS (s_userEventStart+3)
|
return wmi.info.cocoa.window;
|
||||||
#define SDL_USER_WINDOW_SET_SIZE (s_userEventStart+4)
|
# elif BX_PLATFORM_WINDOWS
|
||||||
#define SDL_USER_WINDOW_TOGGLE_FRAME (s_userEventStart+5)
|
return wmi.info.win.window;
|
||||||
#define SDL_USER_WINDOW_MOUSE_LOCK (s_userEventStart+6)
|
# endif // BX_PLATFORM_
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t s_userEventStart;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
SDL_USER_WINDOW_CREATE,
|
||||||
|
SDL_USER_WINDOW_DESTROY,
|
||||||
|
SDL_USER_WINDOW_SET_TITLE,
|
||||||
|
SDL_USER_WINDOW_SET_POS,
|
||||||
|
SDL_USER_WINDOW_SET_SIZE,
|
||||||
|
SDL_USER_WINDOW_TOGGLE_FRAME,
|
||||||
|
SDL_USER_WINDOW_MOUSE_LOCK,
|
||||||
|
};
|
||||||
|
|
||||||
struct Msg
|
struct Msg
|
||||||
{
|
{
|
||||||
|
@ -186,7 +208,6 @@ namespace entry
|
||||||
, m_width
|
, m_width
|
||||||
, m_height
|
, m_height
|
||||||
, SDL_WINDOW_SHOWN
|
, SDL_WINDOW_SHOWN
|
||||||
// | SDL_WINDOW_OPENGL
|
|
||||||
| SDL_WINDOW_RESIZABLE
|
| SDL_WINDOW_RESIZABLE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -279,78 +300,88 @@ namespace entry
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
const SDL_UserEvent uev = event.user;
|
const SDL_UserEvent& uev = event.user;
|
||||||
if (uev.type == SDL_USER_WINDOW_CREATE)
|
switch (uev.type - s_userEventStart)
|
||||||
{
|
{
|
||||||
WindowHandle handle = { *reinterpret_cast<const uint16_t*>(&uev.data1) };
|
case SDL_USER_WINDOW_CREATE:
|
||||||
Msg* msg = (Msg*)uev.data2;
|
|
||||||
|
|
||||||
m_window[handle.idx] = SDL_CreateWindow(msg->m_title.c_str()
|
|
||||||
, msg->m_x
|
|
||||||
, msg->m_y
|
|
||||||
, msg->m_width
|
|
||||||
, msg->m_height
|
|
||||||
, SDL_WINDOW_SHOWN
|
|
||||||
| SDL_WINDOW_OPENGL
|
|
||||||
| SDL_WINDOW_RESIZABLE
|
|
||||||
);
|
|
||||||
|
|
||||||
m_flags[handle.idx] = msg->m_flags;
|
|
||||||
|
|
||||||
SDL_SysWMinfo wmi;
|
|
||||||
SDL_VERSION(&wmi.version);
|
|
||||||
if (SDL_GetWindowWMInfo(m_window[handle.idx], &wmi) )
|
|
||||||
{
|
{
|
||||||
# if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
|
WindowHandle handle = { *reinterpret_cast<const uint16_t*>(&uev.data1) };
|
||||||
void* nwh = wmi.info.x11.window;
|
Msg* msg = (Msg*)uev.data2;
|
||||||
# elif BX_PLATFORM_OSX
|
|
||||||
void* nwh = wmi.info.cocoa.window;
|
|
||||||
# elif BX_PLATFORM_WINDOWS
|
|
||||||
void* nwh = wmi.info.win.window;
|
|
||||||
# endif // BX_PLATFORM_
|
|
||||||
m_eventQueue.postWindowEvent(handle, nwh);
|
|
||||||
m_eventQueue.postSizeEvent(handle, msg->m_width, msg->m_height);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete msg;
|
m_window[handle.idx] = SDL_CreateWindow(msg->m_title.c_str()
|
||||||
}
|
, msg->m_x
|
||||||
else if (uev.type == SDL_USER_WINDOW_DESTROY)
|
, msg->m_y
|
||||||
{
|
, msg->m_width
|
||||||
WindowHandle handle = { *reinterpret_cast<const uint16_t*>(&uev.data1) };
|
, msg->m_height
|
||||||
m_eventQueue.postWindowEvent(handle);
|
, SDL_WINDOW_SHOWN
|
||||||
SDL_DestroyWindow(m_window[handle.idx]);
|
| SDL_WINDOW_RESIZABLE
|
||||||
m_window[handle.idx] = NULL;
|
);
|
||||||
}
|
|
||||||
else if (uev.type == SDL_USER_WINDOW_SET_TITLE)
|
m_flags[handle.idx] = msg->m_flags;
|
||||||
{
|
|
||||||
WindowHandle handle = { *reinterpret_cast<const uint16_t*>(&uev.data1) };
|
void* nwh = sdlNativeWindowHandle(m_window[handle.idx]);
|
||||||
Msg* msg = (Msg*)uev.data2;
|
if (NULL != nwh)
|
||||||
SDL_SetWindowTitle(m_window[handle.idx], msg->m_title.c_str());
|
{
|
||||||
delete msg;
|
m_eventQueue.postWindowEvent(handle, nwh);
|
||||||
}
|
m_eventQueue.postSizeEvent(handle, msg->m_width, msg->m_height);
|
||||||
else if (uev.type == SDL_USER_WINDOW_SET_POS)
|
}
|
||||||
{
|
|
||||||
WindowHandle handle = { *reinterpret_cast<const uint16_t*>(&uev.data1) };
|
delete msg;
|
||||||
Msg* msg = (Msg*)uev.data2;
|
}
|
||||||
SDL_SetWindowPosition(m_window[handle.idx], msg->m_x, msg->m_y);
|
break;
|
||||||
delete msg;
|
|
||||||
}
|
case SDL_USER_WINDOW_DESTROY:
|
||||||
else if (uev.type == SDL_USER_WINDOW_SET_SIZE)
|
{
|
||||||
{
|
WindowHandle handle = { *reinterpret_cast<const uint16_t*>(&uev.data1) };
|
||||||
WindowHandle handle = findHandle(uev.windowID);
|
m_eventQueue.postWindowEvent(handle);
|
||||||
uint32_t width = *(uint32_t*)&uev.data1;
|
SDL_DestroyWindow(m_window[handle.idx]);
|
||||||
uint32_t height = *(uint32_t*)&uev.data2;
|
m_window[handle.idx] = NULL;
|
||||||
setWindowSize(handle, width, height);
|
}
|
||||||
}
|
break;
|
||||||
else if (SDL_USER_WINDOW_TOGGLE_FRAME == uev.type)
|
|
||||||
{
|
case SDL_USER_WINDOW_SET_TITLE:
|
||||||
WindowHandle handle = { *reinterpret_cast<const uint16_t*>(&uev.data1) };
|
{
|
||||||
m_flags[handle.idx] ^= ENTRY_WINDOW_FLAG_FRAME;
|
WindowHandle handle = { *reinterpret_cast<const uint16_t*>(&uev.data1) };
|
||||||
SDL_SetWindowBordered(m_window[handle.idx], (SDL_bool)!!(m_flags[handle.idx] & ENTRY_WINDOW_FLAG_FRAME) );
|
Msg* msg = (Msg*)uev.data2;
|
||||||
}
|
SDL_SetWindowTitle(m_window[handle.idx], msg->m_title.c_str());
|
||||||
else if (SDL_USER_WINDOW_MOUSE_LOCK == uev.type)
|
delete msg;
|
||||||
{
|
}
|
||||||
SDL_SetRelativeMouseMode(!!uev.code ? SDL_TRUE : SDL_FALSE);
|
break;
|
||||||
|
|
||||||
|
case SDL_USER_WINDOW_SET_POS:
|
||||||
|
{
|
||||||
|
WindowHandle handle = { *reinterpret_cast<const uint16_t*>(&uev.data1) };
|
||||||
|
Msg* msg = (Msg*)uev.data2;
|
||||||
|
SDL_SetWindowPosition(m_window[handle.idx], msg->m_x, msg->m_y);
|
||||||
|
delete msg;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_USER_WINDOW_SET_SIZE:
|
||||||
|
{
|
||||||
|
WindowHandle handle = findHandle(uev.windowID);
|
||||||
|
uint32_t width = *(uint32_t*)&uev.data1;
|
||||||
|
uint32_t height = *(uint32_t*)&uev.data2;
|
||||||
|
setWindowSize(handle, width, height);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_USER_WINDOW_TOGGLE_FRAME:
|
||||||
|
{
|
||||||
|
WindowHandle handle = { *reinterpret_cast<const uint16_t*>(&uev.data1) };
|
||||||
|
m_flags[handle.idx] ^= ENTRY_WINDOW_FLAG_FRAME;
|
||||||
|
SDL_SetWindowBordered(m_window[handle.idx], (SDL_bool)!!(m_flags[handle.idx] & ENTRY_WINDOW_FLAG_FRAME) );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_USER_WINDOW_MOUSE_LOCK:
|
||||||
|
{
|
||||||
|
SDL_SetRelativeMouseMode(!!uev.code ? SDL_TRUE : SDL_FALSE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -468,7 +499,7 @@ namespace entry
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_UserEvent& uev = event.user;
|
SDL_UserEvent& uev = event.user;
|
||||||
uev.type = SDL_USER_WINDOW_CREATE;
|
uev.type = s_userEventStart + SDL_USER_WINDOW_CREATE;
|
||||||
uev.data1 = reinterpret_cast<void*>(handle.idx);
|
uev.data1 = reinterpret_cast<void*>(handle.idx);
|
||||||
uev.data2 = msg;
|
uev.data2 = msg;
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
|
@ -483,7 +514,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_UserEvent& uev = event.user;
|
SDL_UserEvent& uev = event.user;
|
||||||
uev.type = SDL_USER_WINDOW_DESTROY;
|
uev.type = s_userEventStart + SDL_USER_WINDOW_DESTROY;
|
||||||
uev.data1 = reinterpret_cast<void*>(_handle.idx);
|
uev.data1 = reinterpret_cast<void*>(_handle.idx);
|
||||||
uev.data2 = NULL;
|
uev.data2 = NULL;
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
|
@ -501,7 +532,7 @@ namespace entry
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_UserEvent& uev = event.user;
|
SDL_UserEvent& uev = event.user;
|
||||||
uev.type = SDL_USER_WINDOW_SET_POS;
|
uev.type = s_userEventStart + SDL_USER_WINDOW_SET_POS;
|
||||||
uev.data1 = reinterpret_cast<void*>(_handle.idx);
|
uev.data1 = reinterpret_cast<void*>(_handle.idx);
|
||||||
uev.data2 = msg;
|
uev.data2 = msg;
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
|
@ -513,7 +544,7 @@ namespace entry
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_UserEvent& uev = event.user;
|
SDL_UserEvent& uev = event.user;
|
||||||
uev.type = SDL_USER_WINDOW_SET_SIZE;
|
uev.type = s_userEventStart + SDL_USER_WINDOW_SET_SIZE;
|
||||||
uev.data1 = reinterpret_cast<void*>(_width);
|
uev.data1 = reinterpret_cast<void*>(_width);
|
||||||
uev.data2 = reinterpret_cast<void*>(_height);
|
uev.data2 = reinterpret_cast<void*>(_height);
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
|
@ -526,7 +557,7 @@ namespace entry
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_UserEvent& uev = event.user;
|
SDL_UserEvent& uev = event.user;
|
||||||
uev.type = SDL_USER_WINDOW_SET_TITLE;
|
uev.type = s_userEventStart + SDL_USER_WINDOW_SET_TITLE;
|
||||||
uev.data1 = reinterpret_cast<void*>(_handle.idx);
|
uev.data1 = reinterpret_cast<void*>(_handle.idx);
|
||||||
uev.data2 = msg;
|
uev.data2 = msg;
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
|
@ -536,7 +567,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_UserEvent& uev = event.user;
|
SDL_UserEvent& uev = event.user;
|
||||||
uev.type = SDL_USER_WINDOW_TOGGLE_FRAME;
|
uev.type = s_userEventStart + SDL_USER_WINDOW_TOGGLE_FRAME;
|
||||||
uev.data1 = reinterpret_cast<void*>(_handle.idx);
|
uev.data1 = reinterpret_cast<void*>(_handle.idx);
|
||||||
uev.data2 = NULL;
|
uev.data2 = NULL;
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
|
@ -547,7 +578,7 @@ namespace entry
|
||||||
BX_UNUSED(_handle);
|
BX_UNUSED(_handle);
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_UserEvent& uev = event.user;
|
SDL_UserEvent& uev = event.user;
|
||||||
uev.type = SDL_USER_WINDOW_MOUSE_LOCK;
|
uev.type = s_userEventStart + SDL_USER_WINDOW_MOUSE_LOCK;
|
||||||
uev.code = _lock;
|
uev.code = _lock;
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,9 @@ project ("example-common")
|
||||||
defines {
|
defines {
|
||||||
"ENTRY_CONFIG_USE_SDL=1",
|
"ENTRY_CONFIG_USE_SDL=1",
|
||||||
}
|
}
|
||||||
|
includedirs {
|
||||||
|
"$(SDL2_DIR)/include",
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
configuration { "xcode4" }
|
configuration { "xcode4" }
|
||||||
|
|
|
@ -79,6 +79,14 @@ function exampleProject(_name)
|
||||||
if _OPTIONS["with-sdl"] then
|
if _OPTIONS["with-sdl"] then
|
||||||
defines { "ENTRY_CONFIG_USE_SDL=1" }
|
defines { "ENTRY_CONFIG_USE_SDL=1" }
|
||||||
links { "SDL2" }
|
links { "SDL2" }
|
||||||
|
|
||||||
|
configuration { "x32", "windows" }
|
||||||
|
libdirs { "$(SDL2_DIR)/lib/x86" }
|
||||||
|
|
||||||
|
configuration { "x64", "windows" }
|
||||||
|
libdirs { "$(SDL2_DIR)/lib/x64" }
|
||||||
|
|
||||||
|
configuration {}
|
||||||
end
|
end
|
||||||
|
|
||||||
configuration { "vs*" }
|
configuration { "vs*" }
|
||||||
|
|
Loading…
Reference in a new issue