mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Shuffling entry stuff.
This commit is contained in:
parent
e92eb7504b
commit
24c894ea90
10 changed files with 311 additions and 49 deletions
|
@ -110,6 +110,7 @@ namespace entry
|
|||
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse)
|
||||
{
|
||||
s_debug = _debug;
|
||||
s_reset = _reset;
|
||||
|
||||
bool mouseLock = inputIsMouseLocked();
|
||||
|
||||
|
@ -177,6 +178,8 @@ namespace entry
|
|||
}
|
||||
} while (NULL != ev);
|
||||
|
||||
inputProcess();
|
||||
|
||||
if (_reset != s_reset)
|
||||
{
|
||||
_reset = s_reset;
|
||||
|
@ -184,7 +187,6 @@ namespace entry
|
|||
inputSetMouseResolution(_width, _height);
|
||||
}
|
||||
|
||||
inputProcess();
|
||||
_debug = s_debug;
|
||||
|
||||
return s_exit;
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "entry.h"
|
||||
#include "entry_p.h"
|
||||
|
||||
#if BX_PLATFORM_ANDROID
|
||||
#if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_ANDROID
|
||||
|
||||
#include <bgfxplatform.h>
|
||||
#include "entry_p.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <bx/thread.h>
|
||||
|
@ -230,4 +229,4 @@ extern "C" void android_main(android_app* _app)
|
|||
s_ctx.run(_app);
|
||||
}
|
||||
|
||||
#endif // BX_PLATFORM_ANDROID
|
||||
#endif // ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_ANDROID
|
||||
|
|
|
@ -3,16 +3,15 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "entry.h"
|
||||
#include "entry_p.h"
|
||||
|
||||
#if BX_PLATFORM_IOS
|
||||
#if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_IOS
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <QuartzCore/CAEAGLLayer.h>
|
||||
|
||||
#include <bgfxplatform.h>
|
||||
#include "entry_p.h"
|
||||
|
||||
#include <bx/uint32_t.h>
|
||||
#include <bx/thread.h>
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "entry.h"
|
||||
#include "entry_p.h"
|
||||
|
||||
#if BX_PLATFORM_LINUX
|
||||
#if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_LINUX
|
||||
|
||||
#define XK_MISCELLANY
|
||||
#define XK_LATIN1
|
||||
|
@ -13,14 +13,10 @@
|
|||
#include <bgfxplatform.h> // will include X11 which #defines None... Don't mess with order of includes.
|
||||
|
||||
#undef None
|
||||
#include "entry_p.h"
|
||||
#include <bx/thread.h>
|
||||
#include <bx/os.h>
|
||||
#include <string.h> // memset
|
||||
|
||||
#define DEFAULT_WIDTH 1280
|
||||
#define DEFAULT_HEIGHT 720
|
||||
|
||||
namespace entry
|
||||
{
|
||||
static uint8_t s_translateKey[512];
|
||||
|
@ -157,7 +153,7 @@ namespace entry
|
|||
m_window = XCreateWindow(m_display
|
||||
, root
|
||||
, 0, 0
|
||||
, DEFAULT_WIDTH, DEFAULT_HEIGHT, 0, depth
|
||||
, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT, 0, depth
|
||||
, InputOutput
|
||||
, visual
|
||||
, CWBorderPixel|CWEventMask
|
||||
|
@ -334,4 +330,4 @@ int main(int _argc, char** _argv)
|
|||
return s_ctx.run(_argc, _argv);
|
||||
}
|
||||
|
||||
#endif // BX_PLATFORM_LINUX
|
||||
#endif // ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_LINUX
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "entry.h"
|
||||
#include "entry_p.h"
|
||||
|
||||
#if BX_PLATFORM_NACL
|
||||
#if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_NACL
|
||||
|
||||
#include <bgfxplatform.h>
|
||||
#include "entry_p.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -185,4 +184,4 @@ PP_EXPORT void PPP_ShutdownModule()
|
|||
{
|
||||
}
|
||||
|
||||
#endif // BX_PLATFROM_NACL
|
||||
#endif // ENTRY_CONFIG_USE_NATIVE && BX_PLATFROM_NACL
|
||||
|
|
|
@ -3,14 +3,13 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "entry.h"
|
||||
#include "entry_p.h"
|
||||
|
||||
#if BX_PLATFORM_OSX
|
||||
#if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_OSX
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include <bgfxplatform.h>
|
||||
#include "entry_p.h"
|
||||
|
||||
#include <bx/uint32_t.h>
|
||||
#include <bx/thread.h>
|
||||
|
|
|
@ -10,6 +10,21 @@
|
|||
|
||||
#include "entry.h"
|
||||
|
||||
#ifndef ENTRY_CONFIG_USE_SDL
|
||||
# define ENTRY_CONFIG_USE_SDL BX_PLATFORM_OSX
|
||||
#endif // ENTRY_CONFIG_USE_SDL
|
||||
|
||||
#ifndef ENTRY_CONFIG_USE_NATIVE
|
||||
# define ENTRY_CONFIG_USE_NATIVE !ENTRY_CONFIG_USE_SDL
|
||||
#endif // ENTRY_CONFIG_USE_NATIVE
|
||||
|
||||
#if !defined(ENTRY_DEFAULT_WIDTH) && !defined(ENTRY_DEFAULT_HEIGHT)
|
||||
# define ENTRY_DEFAULT_WIDTH 1280
|
||||
# define ENTRY_DEFAULT_HEIGHT 720
|
||||
#elif !defined(ENTRY_DEFAULT_WIDTH) || !defined(ENTRY_DEFAULT_HEIGHT)
|
||||
# error "Both ENTRY_DEFAULT_WIDTH and ENTRY_DEFAULT_HEIGHT must be defined."
|
||||
#endif // ENTRY_DEFAULT_WIDTH
|
||||
|
||||
namespace entry
|
||||
{
|
||||
int main(int _argc, char** _argv);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include "entry.h"
|
||||
|
||||
#if BX_PLATFORM_QNX
|
||||
#if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_QNX
|
||||
|
||||
#include <stdio.h>
|
||||
#include "entry.h"
|
||||
|
@ -40,4 +40,4 @@ int main(int _argc, char** _argv)
|
|||
entry::main(_argc, _argv);
|
||||
}
|
||||
|
||||
#endif // BX_PLATFORM_QNX
|
||||
#endif // ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_QNX
|
||||
|
|
|
@ -3,19 +3,49 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "entry.h"
|
||||
#include "entry_p.h"
|
||||
|
||||
#if BX_PLATFORM_OSX
|
||||
#if ENTRY_CONFIG_USE_SDL
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
# define SDL_MAIN_HANDLED
|
||||
#endif // BX_PLATFORM_WINDOWS
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <bgfxplatform.h>
|
||||
#include "entry_p.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <bx/thread.h>
|
||||
|
||||
namespace entry
|
||||
{
|
||||
static uint8_t translateKeyModifiers(uint16_t _sdl)
|
||||
{
|
||||
uint8_t modifiers = 0;
|
||||
modifiers |= _sdl & KMOD_LALT ? Modifier::LeftAlt : 0;
|
||||
modifiers |= _sdl & KMOD_RALT ? Modifier::RightAlt : 0;
|
||||
modifiers |= _sdl & KMOD_LCTRL ? Modifier::LeftCtrl : 0;
|
||||
modifiers |= _sdl & KMOD_RCTRL ? Modifier::RightCtrl : 0;
|
||||
modifiers |= _sdl & KMOD_LSHIFT ? Modifier::LeftShift : 0;
|
||||
modifiers |= _sdl & KMOD_RSHIFT ? Modifier::RightShift : 0;
|
||||
modifiers |= _sdl & KMOD_LGUI ? Modifier::LeftMeta : 0;
|
||||
modifiers |= _sdl & KMOD_RGUI ? Modifier::RightMeta : 0;
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
static uint8_t s_translateKey[256];
|
||||
|
||||
static void initTranslateKey(uint16_t _sdl, Key::Enum _key)
|
||||
{
|
||||
BX_CHECK(_sdl < BX_COUNTOF(s_translateKey), "Out of bounds %d.", _sdl);
|
||||
s_translateKey[_sdl&0xff] = (uint8_t)_key;
|
||||
}
|
||||
|
||||
static Key::Enum translateKey(SDL_Scancode _sdl)
|
||||
{
|
||||
return (Key::Enum)s_translateKey[_sdl&0xff];
|
||||
}
|
||||
|
||||
struct MainThreadEntry
|
||||
{
|
||||
int m_argc;
|
||||
|
@ -24,11 +54,96 @@ namespace entry
|
|||
static int32_t threadFunc(void* _userData);
|
||||
};
|
||||
|
||||
static uint32_t s_userEventStart = SDL_USEREVENT;
|
||||
|
||||
#define SDL_USER_SET_WINDOW_SIZE (s_userEventStart+0)
|
||||
#define SDL_USER_TOGGLE_WINDOW_FRAME (s_userEventStart+1)
|
||||
#define SDL_USER_MOUSE_LOCK (s_userEventStart+2)
|
||||
|
||||
struct Context
|
||||
{
|
||||
Context()
|
||||
: m_window(NULL)
|
||||
, m_width(ENTRY_DEFAULT_WIDTH)
|
||||
, m_height(ENTRY_DEFAULT_HEIGHT)
|
||||
, m_aspectRatio(16.0f/9.0f)
|
||||
, m_mouseLock(false)
|
||||
{
|
||||
memset(s_translateKey, 0, sizeof(s_translateKey) );
|
||||
initTranslateKey(SDL_SCANCODE_ESCAPE, Key::Esc);
|
||||
initTranslateKey(SDL_SCANCODE_RETURN, Key::Return);
|
||||
initTranslateKey(SDL_SCANCODE_TAB, Key::Tab);
|
||||
initTranslateKey(SDL_SCANCODE_BACKSPACE, Key::Backspace);
|
||||
initTranslateKey(SDL_SCANCODE_SPACE, Key::Space);
|
||||
initTranslateKey(SDL_SCANCODE_UP, Key::Up);
|
||||
initTranslateKey(SDL_SCANCODE_DOWN, Key::Down);
|
||||
initTranslateKey(SDL_SCANCODE_LEFT, Key::Left);
|
||||
initTranslateKey(SDL_SCANCODE_RIGHT, Key::Right);
|
||||
initTranslateKey(SDL_SCANCODE_PAGEUP, Key::PageUp);
|
||||
initTranslateKey(SDL_SCANCODE_PAGEDOWN, Key::PageDown);
|
||||
initTranslateKey(SDL_SCANCODE_HOME, Key::Home);
|
||||
initTranslateKey(SDL_SCANCODE_END, Key::End);
|
||||
initTranslateKey(SDL_SCANCODE_PRINTSCREEN, Key::Print);
|
||||
initTranslateKey(SDL_SCANCODE_KP_PLUS, Key::Plus);
|
||||
initTranslateKey(SDL_SCANCODE_KP_MINUS, Key::Minus);
|
||||
initTranslateKey(SDL_SCANCODE_F1, Key::F1);
|
||||
initTranslateKey(SDL_SCANCODE_F2, Key::F2);
|
||||
initTranslateKey(SDL_SCANCODE_F3, Key::F3);
|
||||
initTranslateKey(SDL_SCANCODE_F4, Key::F4);
|
||||
initTranslateKey(SDL_SCANCODE_F5, Key::F5);
|
||||
initTranslateKey(SDL_SCANCODE_F6, Key::F6);
|
||||
initTranslateKey(SDL_SCANCODE_F7, Key::F7);
|
||||
initTranslateKey(SDL_SCANCODE_F8, Key::F8);
|
||||
initTranslateKey(SDL_SCANCODE_F9, Key::F9);
|
||||
initTranslateKey(SDL_SCANCODE_F10, Key::F10);
|
||||
initTranslateKey(SDL_SCANCODE_F11, Key::F11);
|
||||
initTranslateKey(SDL_SCANCODE_F12, Key::F12);
|
||||
initTranslateKey(SDL_SCANCODE_KP_0, Key::NumPad0);
|
||||
initTranslateKey(SDL_SCANCODE_KP_1, Key::NumPad1);
|
||||
initTranslateKey(SDL_SCANCODE_KP_2, Key::NumPad2);
|
||||
initTranslateKey(SDL_SCANCODE_KP_3, Key::NumPad3);
|
||||
initTranslateKey(SDL_SCANCODE_KP_4, Key::NumPad4);
|
||||
initTranslateKey(SDL_SCANCODE_KP_5, Key::NumPad5);
|
||||
initTranslateKey(SDL_SCANCODE_KP_6, Key::NumPad6);
|
||||
initTranslateKey(SDL_SCANCODE_KP_7, Key::NumPad7);
|
||||
initTranslateKey(SDL_SCANCODE_KP_8, Key::NumPad8);
|
||||
initTranslateKey(SDL_SCANCODE_KP_9, Key::NumPad9);
|
||||
initTranslateKey(SDL_SCANCODE_0, Key::Key0);
|
||||
initTranslateKey(SDL_SCANCODE_1, Key::Key1);
|
||||
initTranslateKey(SDL_SCANCODE_2, Key::Key2);
|
||||
initTranslateKey(SDL_SCANCODE_3, Key::Key3);
|
||||
initTranslateKey(SDL_SCANCODE_4, Key::Key4);
|
||||
initTranslateKey(SDL_SCANCODE_5, Key::Key5);
|
||||
initTranslateKey(SDL_SCANCODE_6, Key::Key6);
|
||||
initTranslateKey(SDL_SCANCODE_7, Key::Key7);
|
||||
initTranslateKey(SDL_SCANCODE_8, Key::Key8);
|
||||
initTranslateKey(SDL_SCANCODE_9, Key::Key9);
|
||||
initTranslateKey(SDL_SCANCODE_A, Key::KeyA);
|
||||
initTranslateKey(SDL_SCANCODE_B, Key::KeyB);
|
||||
initTranslateKey(SDL_SCANCODE_C, Key::KeyC);
|
||||
initTranslateKey(SDL_SCANCODE_D, Key::KeyD);
|
||||
initTranslateKey(SDL_SCANCODE_E, Key::KeyE);
|
||||
initTranslateKey(SDL_SCANCODE_F, Key::KeyF);
|
||||
initTranslateKey(SDL_SCANCODE_G, Key::KeyG);
|
||||
initTranslateKey(SDL_SCANCODE_H, Key::KeyH);
|
||||
initTranslateKey(SDL_SCANCODE_I, Key::KeyI);
|
||||
initTranslateKey(SDL_SCANCODE_J, Key::KeyJ);
|
||||
initTranslateKey(SDL_SCANCODE_K, Key::KeyK);
|
||||
initTranslateKey(SDL_SCANCODE_L, Key::KeyL);
|
||||
initTranslateKey(SDL_SCANCODE_M, Key::KeyM);
|
||||
initTranslateKey(SDL_SCANCODE_N, Key::KeyN);
|
||||
initTranslateKey(SDL_SCANCODE_O, Key::KeyO);
|
||||
initTranslateKey(SDL_SCANCODE_P, Key::KeyP);
|
||||
initTranslateKey(SDL_SCANCODE_Q, Key::KeyQ);
|
||||
initTranslateKey(SDL_SCANCODE_R, Key::KeyR);
|
||||
initTranslateKey(SDL_SCANCODE_S, Key::KeyS);
|
||||
initTranslateKey(SDL_SCANCODE_T, Key::KeyT);
|
||||
initTranslateKey(SDL_SCANCODE_U, Key::KeyU);
|
||||
initTranslateKey(SDL_SCANCODE_V, Key::KeyV);
|
||||
initTranslateKey(SDL_SCANCODE_W, Key::KeyW);
|
||||
initTranslateKey(SDL_SCANCODE_X, Key::KeyX);
|
||||
initTranslateKey(SDL_SCANCODE_Y, Key::KeyY);
|
||||
initTranslateKey(SDL_SCANCODE_Z, Key::KeyZ);
|
||||
}
|
||||
|
||||
void run()
|
||||
|
@ -42,14 +157,21 @@ namespace entry
|
|||
m_window = SDL_CreateWindow("bgfx"
|
||||
, SDL_WINDOWPOS_UNDEFINED
|
||||
, SDL_WINDOWPOS_UNDEFINED
|
||||
, 1200
|
||||
, 720
|
||||
, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL
|
||||
, m_width
|
||||
, m_height
|
||||
, SDL_WINDOW_SHOWN
|
||||
| SDL_WINDOW_OPENGL
|
||||
| SDL_WINDOW_RESIZABLE
|
||||
);
|
||||
|
||||
s_userEventStart = SDL_RegisterEvents(3);
|
||||
|
||||
bgfx::sdlSetWindow(m_window);
|
||||
m_thread.init(MainThreadEntry::threadFunc, &m_mte);
|
||||
|
||||
// Force window resolution...
|
||||
setWindowSize(m_width, m_height, true);
|
||||
|
||||
bool exit = false;
|
||||
SDL_Event event;
|
||||
while (!exit && SDL_WaitEvent(&event) )
|
||||
|
@ -60,6 +182,82 @@ namespace entry
|
|||
m_eventQueue.postExitEvent();
|
||||
exit = true;
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
const SDL_MouseMotionEvent& mev = event.motion;
|
||||
int32_t mx = mev.xrel;
|
||||
int32_t my = mev.yrel;
|
||||
|
||||
m_eventQueue.postMouseEvent(mx, my);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
const SDL_KeyboardEvent& kev = event.key;
|
||||
uint8_t modifiers = translateKeyModifiers(kev.keysym.mod);
|
||||
Key::Enum key = translateKey(kev.keysym.scancode);
|
||||
m_eventQueue.postKeyEvent(key, modifiers, kev.state == SDL_PRESSED);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
{
|
||||
const SDL_WindowEvent& wev = event.window;
|
||||
switch (wev.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
setWindowSize(wev.data1, wev.data2);
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_SHOWN:
|
||||
case SDL_WINDOWEVENT_HIDDEN:
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
case SDL_WINDOWEVENT_MOVED:
|
||||
case SDL_WINDOWEVENT_MINIMIZED:
|
||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||
case SDL_WINDOWEVENT_RESTORED:
|
||||
case SDL_WINDOWEVENT_ENTER:
|
||||
case SDL_WINDOWEVENT_LEAVE:
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
DBG("SDL_WINDOWEVENT_CLOSE");
|
||||
m_eventQueue.postExitEvent();
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
const SDL_UserEvent uev = event.user;
|
||||
if (SDL_USER_SET_WINDOW_SIZE == event.type)
|
||||
{
|
||||
uint32_t width = (uint32_t)uev.data1;
|
||||
uint32_t height = (uint32_t)uev.data2;
|
||||
setWindowSize(width, height);
|
||||
}
|
||||
else if (SDL_USER_TOGGLE_WINDOW_FRAME == event.type)
|
||||
{
|
||||
DBG("SDL_USER_TOGGLE_WINDOW_FRAME");
|
||||
}
|
||||
else if (SDL_USER_MOUSE_LOCK == event.type)
|
||||
{
|
||||
setMouseLock(!!uev.code);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,12 +267,56 @@ namespace entry
|
|||
SDL_Quit();
|
||||
}
|
||||
|
||||
void setMousePos(int32_t _mx, int32_t _my)
|
||||
{
|
||||
}
|
||||
|
||||
void setMouseLock(bool _lock)
|
||||
{
|
||||
SDL_SetRelativeMouseMode(_lock ? SDL_TRUE : SDL_FALSE);
|
||||
}
|
||||
|
||||
void setWindowSize(uint32_t _width, uint32_t _height, bool _force = false)
|
||||
{
|
||||
if (_width != m_width
|
||||
|| _height != m_height
|
||||
|| _force)
|
||||
{
|
||||
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, m_width, m_height);
|
||||
m_eventQueue.postSizeEvent(m_width, m_height);
|
||||
}
|
||||
}
|
||||
|
||||
MainThreadEntry m_mte;
|
||||
bx::Thread m_thread;
|
||||
|
||||
EventQueue m_eventQueue;
|
||||
|
||||
SDL_Window* m_window;
|
||||
|
||||
uint32_t m_width;
|
||||
uint32_t m_height;
|
||||
float m_aspectRatio;
|
||||
|
||||
int32_t m_mx;
|
||||
int32_t m_my;
|
||||
bool m_mouseLock;
|
||||
};
|
||||
|
||||
static Context s_ctx;
|
||||
|
@ -91,6 +333,12 @@ namespace entry
|
|||
|
||||
void setWindowSize(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
SDL_Event event;
|
||||
SDL_UserEvent& uev = event.user;
|
||||
uev.type = SDL_USER_SET_WINDOW_SIZE;
|
||||
uev.data1 = (void*)_width;
|
||||
uev.data2 = (void*)_height;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
|
||||
void toggleWindowFrame()
|
||||
|
@ -99,6 +347,12 @@ namespace entry
|
|||
|
||||
void setMouseLock(bool _lock)
|
||||
{
|
||||
SDL_Event event;
|
||||
SDL_UserEvent& uev = event.user;
|
||||
uev.type = SDL_USER_MOUSE_LOCK;
|
||||
uev.code = _lock;
|
||||
DBG("setMouseLock %d", event.type);
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
|
||||
int32_t MainThreadEntry::threadFunc(void* _userData)
|
||||
|
@ -107,7 +361,8 @@ namespace entry
|
|||
int32_t result = main(self->m_argc, self->m_argv);
|
||||
|
||||
SDL_Event event;
|
||||
event.type = SDL_QUIT;
|
||||
SDL_QuitEvent& qev = event.quit;
|
||||
qev.type = SDL_QUIT;
|
||||
SDL_PushEvent(&event);
|
||||
return result;
|
||||
}
|
||||
|
@ -118,6 +373,7 @@ int main(int _argc, const char* _argv[])
|
|||
{
|
||||
using namespace entry;
|
||||
s_ctx.run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // BX_PLATFORM_
|
||||
#endif // ENTRY_CONFIG_USE_SDL
|
||||
|
|
|
@ -3,21 +3,17 @@
|
|||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "entry.h"
|
||||
#include "entry_p.h"
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
#if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_WINDOWS
|
||||
|
||||
#include <bgfxplatform.h>
|
||||
#include "entry_p.h"
|
||||
|
||||
#include <bx/uint32_t.h>
|
||||
#include <bx/thread.h>
|
||||
|
||||
#include <windowsx.h>
|
||||
|
||||
#define DEFAULT_WIDTH 1280
|
||||
#define DEFAULT_HEIGHT 720
|
||||
|
||||
#define WM_USER_SET_WINDOW_SIZE (WM_USER+0)
|
||||
#define WM_USER_TOGGLE_WINDOW_FRAME (WM_USER+1)
|
||||
#define WM_USER_MOUSE_LOCK (WM_USER+2)
|
||||
|
@ -74,6 +70,7 @@ namespace entry
|
|||
: m_frame(true)
|
||||
, m_init(false)
|
||||
, m_exit(false)
|
||||
, m_mouseLock(false)
|
||||
{
|
||||
memset(s_translateKey, 0, sizeof(s_translateKey) );
|
||||
s_translateKey[VK_ESCAPE] = Key::Esc;
|
||||
|
@ -197,8 +194,8 @@ namespace entry
|
|||
, WS_OVERLAPPEDWINDOW|WS_VISIBLE
|
||||
, 0
|
||||
, 0
|
||||
, DEFAULT_WIDTH
|
||||
, DEFAULT_HEIGHT
|
||||
, ENTRY_DEFAULT_WIDTH
|
||||
, ENTRY_DEFAULT_HEIGHT
|
||||
, hwnd
|
||||
, NULL
|
||||
, instance
|
||||
|
@ -207,11 +204,11 @@ namespace entry
|
|||
|
||||
bgfx::winSetHwnd(m_hwnd);
|
||||
|
||||
adjust(DEFAULT_WIDTH, DEFAULT_HEIGHT, true);
|
||||
m_width = DEFAULT_WIDTH;
|
||||
m_height = DEFAULT_HEIGHT;
|
||||
m_oldWidth = DEFAULT_WIDTH;
|
||||
m_oldHeight = DEFAULT_HEIGHT;
|
||||
adjust(ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT, true);
|
||||
m_width = ENTRY_DEFAULT_WIDTH;
|
||||
m_height = ENTRY_DEFAULT_HEIGHT;
|
||||
m_oldWidth = ENTRY_DEFAULT_WIDTH;
|
||||
m_oldHeight = ENTRY_DEFAULT_HEIGHT;
|
||||
|
||||
MainThreadEntry mte;
|
||||
mte.m_argc = _argc;
|
||||
|
@ -296,7 +293,7 @@ namespace entry
|
|||
case WMSZ_RIGHT:
|
||||
{
|
||||
float aspectRatio = 1.0f/m_aspectRatio;
|
||||
width = bx::uint32_max(DEFAULT_WIDTH/4, width);
|
||||
width = bx::uint32_max(ENTRY_DEFAULT_WIDTH/4, width);
|
||||
height = uint32_t(float(width)*aspectRatio);
|
||||
}
|
||||
break;
|
||||
|
@ -304,7 +301,7 @@ namespace entry
|
|||
default:
|
||||
{
|
||||
float aspectRatio = m_aspectRatio;
|
||||
height = bx::uint32_max(DEFAULT_HEIGHT/4, height);
|
||||
height = bx::uint32_max(ENTRY_DEFAULT_HEIGHT/4, height);
|
||||
width = uint32_t(float(height)*aspectRatio);
|
||||
}
|
||||
break;
|
||||
|
@ -488,7 +485,7 @@ namespace entry
|
|||
if (!_windowFrame)
|
||||
{
|
||||
float aspectRatio = 1.0f/m_aspectRatio;
|
||||
width = bx::uint32_max(DEFAULT_WIDTH/4, width);
|
||||
width = bx::uint32_max(ENTRY_DEFAULT_WIDTH/4, width);
|
||||
height = uint32_t(float(width)*aspectRatio);
|
||||
|
||||
left = newrect.left+(newrect.right-newrect.left-width)/2;
|
||||
|
|
Loading…
Reference in a new issue