Added multiple windows example.

This commit is contained in:
Branimir Karadžić
2014-09-22 19:34:10 -07:00
parent 892262f419
commit de3d152b9c
14 changed files with 849 additions and 108 deletions

View File

@@ -17,6 +17,7 @@ extern "C" int _main_(int _argc, char** _argv);
namespace entry
{
const uint16_t WindowHandle::invalidHandle = UINT16_MAX;
static uint32_t s_debug = BGFX_DEBUG_NONE;
static uint32_t s_reset = BGFX_RESET_NONE;
static bool s_exit = false;
@@ -254,7 +255,7 @@ namespace entry
return ascii;
}
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse, KeyState* _keyboard)
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse)
{
s_debug = _debug;
s_reset = _reset;
@@ -263,12 +264,6 @@ namespace entry
bool mouseLock = inputIsMouseLocked();
if (NULL != _keyboard)
{
_keyboard->m_modifiers = 0;
memset(_keyboard->m_keysDown, 0, sizeof(_keyboard->m_keysDown) );
}
const Event* ev;
do
{
@@ -319,16 +314,6 @@ namespace entry
handle = key->m_handle;
inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
if (NULL != _keyboard)
{
_keyboard->m_modifiers |= key->m_modifiers;
if (key->m_down)
{
_keyboard->m_keysDown[key->m_key] = true;
}
}
}
break;
@@ -367,6 +352,143 @@ namespace entry
return s_exit;
}
WindowState s_window[ENTRY_CONFIG_MAX_WINDOWS];
bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset)
{
s_debug = _debug;
s_reset = _reset;
WindowHandle handle = { UINT16_MAX };
bool mouseLock = inputIsMouseLocked();
const Event* ev;
do
{
struct SE
{
SE(WindowHandle _handle)
: m_ev(poll(_handle) )
{
}
~SE()
{
if (NULL != m_ev)
{
release(m_ev);
}
}
const Event* m_ev;
} scopeEvent(handle);
ev = scopeEvent.m_ev;
if (NULL != ev)
{
handle = ev->m_handle;
WindowState& win = s_window[handle.idx];
switch (ev->m_type)
{
case Event::Exit:
return true;
case Event::Mouse:
{
const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
win.m_handle = mouse->m_handle;
if (mouse->m_move)
{
inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
}
else
{
inputSetMouseButtonState(mouse->m_button, mouse->m_down);
}
if (!mouseLock)
{
if (mouse->m_move)
{
win.m_mouse.m_mx = mouse->m_mx;
win.m_mouse.m_my = mouse->m_my;
win.m_mouse.m_mz = mouse->m_mz;
}
else
{
win.m_mouse.m_buttons[mouse->m_button] = mouse->m_down;
}
}
}
break;
case Event::Key:
{
const KeyEvent* key = static_cast<const KeyEvent*>(ev);
win.m_handle = key->m_handle;
inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
}
break;
case Event::Size:
{
const SizeEvent* size = static_cast<const SizeEvent*>(ev);
win.m_handle = size->m_handle;
win.m_width = size->m_width;
win.m_height = size->m_height;
_reset = win.m_handle.idx == 0
? !s_reset
: _reset
; // force reset
}
break;
case Event::Window:
{
const WindowEvent* window = static_cast<const WindowEvent*>(ev);
win.m_handle = window->m_handle;
win.m_nwh = window->m_nwh;
ev = NULL;
}
break;
default:
break;
}
}
inputProcess();
} while (NULL != ev);
if (isValid(handle) )
{
const WindowState& win = s_window[handle.idx];
_state = win;
if (handle.idx == 0)
{
inputSetMouseResolution(win.m_width, win.m_height);
}
}
if (_reset != s_reset)
{
_reset = s_reset;
bgfx::reset(s_window[0].m_width, s_window[0].m_height, _reset);
inputSetMouseResolution(s_window[0].m_width, s_window[0].m_height);
}
_debug = s_debug;
return s_exit;
}
bx::FileReaderI* getFileReader()
{
return s_fileReader;