summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/common/entry/entry_sdl.cpp')
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_sdl.cpp57
1 files changed, 43 insertions, 14 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
index e44ebcefddb..c279f0fd2a6 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
@@ -179,6 +179,7 @@ namespace entry
SDL_USER_WINDOW_SET_POS,
SDL_USER_WINDOW_SET_SIZE,
SDL_USER_WINDOW_TOGGLE_FRAME,
+ SDL_USER_WINDOW_TOGGLE_FULL_SCREEN,
SDL_USER_WINDOW_MOUSE_LOCK,
};
@@ -191,7 +192,7 @@ namespace entry
union { void* p; WindowHandle h; } cast;
cast.h = _handle;
uev.data1 = cast.p;
-
+
uev.data2 = _msg;
uev.code = _code;
SDL_PushEvent(&event);
@@ -211,6 +212,7 @@ namespace entry
, m_height(ENTRY_DEFAULT_HEIGHT)
, m_aspectRatio(16.0f/9.0f)
, m_mouseLock(false)
+ , m_fullscreen(false)
{
memset(s_translateKey, 0, sizeof(s_translateKey) );
initTranslateKey(SDL_SCANCODE_ESCAPE, Key::Esc);
@@ -410,6 +412,32 @@ namespace entry
break;
case SDL_KEYDOWN:
+ {
+ const SDL_KeyboardEvent& kev = event.key;
+ WindowHandle handle = findHandle(kev.windowID);
+ if (isValid(handle) )
+ {
+ uint8_t modifiers = translateKeyModifiers(kev.keysym.mod);
+ Key::Enum key = translateKey(kev.keysym.scancode);
+
+ const uint8_t shiftMask = Modifier::LeftShift|Modifier::RightShift;
+ const bool nonShiftModifiers = (0 != (modifiers&(~shiftMask) ) );
+ const bool isCharPressed = (Key::Key0 <= key && key <= Key::KeyZ) || (Key::Esc <= key && key <= Key::Minus);
+ const bool isText = isCharPressed && !nonShiftModifiers;
+
+ if (isText)
+ {
+ uint8_t pressedChar[4];
+ pressedChar[0] = keyToAscii(key, modifiers);
+ m_eventQueue.postCharEvent(handle, 1, pressedChar);
+ }
+ else
+ {
+ m_eventQueue.postKeyEvent(handle, key, modifiers, kev.state == SDL_PRESSED);
+ }
+ }
+ }
+ break;
case SDL_KEYUP:
{
const SDL_KeyboardEvent& kev = event.key;
@@ -615,6 +643,14 @@ namespace entry
}
break;
+ case SDL_USER_WINDOW_TOGGLE_FULL_SCREEN:
+ {
+ WindowHandle handle = getWindowHandle(uev);
+ m_fullscreen = !m_fullscreen;
+ SDL_SetWindowFullscreen(m_window[handle.idx], m_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+ }
+ break;
+
case SDL_USER_WINDOW_MOUSE_LOCK:
{
SDL_SetRelativeMouseMode(!!uev.code ? SDL_TRUE : SDL_FALSE);
@@ -669,19 +705,6 @@ namespace entry
m_width = _width;
m_height = _height;
- if (m_width < m_height)
- {
- float aspectRatio = 1.0f/m_aspectRatio;
- m_width = bx::uint32_max(ENTRY_DEFAULT_WIDTH/4, m_width);
- m_height = uint32_t(float(m_width)*aspectRatio);
- }
- else
- {
- float aspectRatio = m_aspectRatio;
- m_height = bx::uint32_max(ENTRY_DEFAULT_HEIGHT/4, m_height);
- m_width = uint32_t(float(m_height)*aspectRatio);
- }
-
SDL_SetWindowSize(m_window[_handle.idx], m_width, m_height);
m_eventQueue.postSizeEvent(_handle, m_width, m_height);
}
@@ -723,6 +746,7 @@ namespace entry
int32_t m_mx;
int32_t m_my;
bool m_mouseLock;
+ bool m_fullscreen;
};
static Context s_ctx;
@@ -805,6 +829,11 @@ namespace entry
sdlPostEvent(SDL_USER_WINDOW_TOGGLE_FRAME, _handle);
}
+ void toggleFullscreen(WindowHandle _handle)
+ {
+ sdlPostEvent(SDL_USER_WINDOW_TOGGLE_FULL_SCREEN, _handle);
+ }
+
void setMouseLock(WindowHandle _handle, bool _lock)
{
sdlPostEvent(SDL_USER_WINDOW_MOUSE_LOCK, _handle, NULL, _lock);