mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
commit
debfef1477
2 changed files with 52 additions and 39 deletions
|
@ -77,7 +77,10 @@ namespace entry
|
||||||
struct Context
|
struct Context
|
||||||
{
|
{
|
||||||
Context()
|
Context()
|
||||||
: m_scroll(0)
|
: m_scrollf(0.0f)
|
||||||
|
, m_mx(0)
|
||||||
|
, m_my(0)
|
||||||
|
, m_scroll(0)
|
||||||
, m_exit(false)
|
, m_exit(false)
|
||||||
{
|
{
|
||||||
s_translateKey[27] = Key::Esc;
|
s_translateKey[27] = Key::Esc;
|
||||||
|
@ -170,20 +173,19 @@ namespace entry
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Enum handleKeyEvent(NSEvent* event, uint8_t* specialKeys)
|
Key::Enum handleKeyEvent(NSEvent* event, uint8_t* specialKeys, uint8_t* _pressedChar)
|
||||||
{
|
{
|
||||||
NSString* key = [event charactersIgnoringModifiers];
|
NSString* key = [event charactersIgnoringModifiers];
|
||||||
unichar keyChar = 0;
|
unichar keyChar = 0;
|
||||||
//DBG("keyChar %d", keyChar);
|
|
||||||
if ([key length] == 0)
|
if ([key length] == 0)
|
||||||
{
|
{
|
||||||
return Key::None;
|
return Key::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
keyChar = [key characterAtIndex:0];
|
keyChar = [key characterAtIndex:0];
|
||||||
|
*_pressedChar = (uint8_t)keyChar;
|
||||||
|
|
||||||
int keyCode = keyChar;
|
int keyCode = keyChar;
|
||||||
//DBG("keyCode %d", keyCode);
|
|
||||||
*specialKeys = translateModifiers([event modifierFlags]);
|
*specialKeys = translateModifiers([event modifierFlags]);
|
||||||
|
|
||||||
// if this is a unhandled key just return None
|
// if this is a unhandled key just return None
|
||||||
|
@ -236,80 +238,81 @@ namespace entry
|
||||||
case NSRightMouseDragged:
|
case NSRightMouseDragged:
|
||||||
case NSOtherMouseDragged:
|
case NSOtherMouseDragged:
|
||||||
{
|
{
|
||||||
int x, y;
|
getMousePos(&m_mx, &m_my);
|
||||||
getMousePos(&x, &y);
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll);
|
||||||
m_eventQueue.postMouseEvent(s_defaultWindow, x, y, m_scroll);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NSLeftMouseDown:
|
case NSLeftMouseDown:
|
||||||
{
|
{
|
||||||
int x, y;
|
// TODO: remove!
|
||||||
getMousePos(&x, &y);
|
// Shift + Left Mouse Button acts as middle! This just a temporary solution!
|
||||||
m_eventQueue.postMouseEvent(s_defaultWindow, x, y, m_scroll, MouseButton::Left, true);
|
// This is becase the average OSX user doesn't have middle mouse click.
|
||||||
|
MouseButton::Enum mb = ([event modifierFlags] & NSShiftKeyMask) ? MouseButton::Middle : MouseButton::Left;
|
||||||
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, mb, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NSLeftMouseUp:
|
case NSLeftMouseUp:
|
||||||
{
|
{
|
||||||
int x, y;
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Left, false);
|
||||||
getMousePos(&x, &y);
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, false); // TODO: remove!
|
||||||
m_eventQueue.postMouseEvent(s_defaultWindow, x, y, m_scroll, MouseButton::Left, false);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NSRightMouseDown:
|
case NSRightMouseDown:
|
||||||
{
|
{
|
||||||
int x, y;
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, true);
|
||||||
getMousePos(&x, &y);
|
|
||||||
m_eventQueue.postMouseEvent(s_defaultWindow, x, y, m_scroll, MouseButton::Right, true);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NSRightMouseUp:
|
case NSRightMouseUp:
|
||||||
{
|
{
|
||||||
int x, y;
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, false);
|
||||||
getMousePos(&x, &y);
|
|
||||||
m_eventQueue.postMouseEvent(s_defaultWindow, x, y, m_scroll, MouseButton::Right, false);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NSOtherMouseDown:
|
case NSOtherMouseDown:
|
||||||
{
|
{
|
||||||
int x, y;
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, true);
|
||||||
getMousePos(&x, &y);
|
|
||||||
m_eventQueue.postMouseEvent(s_defaultWindow, x, y, m_scroll, MouseButton::Middle, true);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NSOtherMouseUp:
|
case NSOtherMouseUp:
|
||||||
{
|
{
|
||||||
int x, y;
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, false);
|
||||||
getMousePos(&x, &y);
|
|
||||||
m_eventQueue.postMouseEvent(s_defaultWindow, x, y, m_scroll, MouseButton::Middle, false);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NSScrollWheel:
|
case NSScrollWheel:
|
||||||
{
|
{
|
||||||
int x, y;
|
m_scrollf += [event deltaY];
|
||||||
getMousePos(&x, &y);
|
|
||||||
m_scroll += ([event deltaY] > 0.0f) ? 1 : -1;
|
m_scroll = (int32_t)m_scrollf;
|
||||||
m_eventQueue.postMouseEvent(s_defaultWindow, x, y, m_scroll);
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NSKeyDown:
|
case NSKeyDown:
|
||||||
{
|
{
|
||||||
uint8_t modifiers = 0;
|
uint8_t modifiers = 0;
|
||||||
Key::Enum key = handleKeyEvent(event, &modifiers);
|
uint8_t pressedChar[4];
|
||||||
|
Key::Enum key = handleKeyEvent(event, &modifiers, &pressedChar[0]);
|
||||||
|
|
||||||
// If KeyCode is none we don't don't handle the key and special case for cmd+q (quit)
|
// Returning false means that we take care of the key (instead of the default behavior)
|
||||||
// Note that return false here means that we take care of the key (instead of the default behavior)
|
|
||||||
if (key != Key::None)
|
if (key != Key::None)
|
||||||
{
|
{
|
||||||
if (key != Key::KeyQ
|
if (key == Key::KeyQ && (modifiers & Modifier::RightMeta) )
|
||||||
&& !(modifiers & Modifier::RightMeta) )
|
{
|
||||||
|
m_eventQueue.postExitEvent();
|
||||||
|
}
|
||||||
|
else if ( (Key::Key0 <= key && key <= Key::KeyZ)
|
||||||
|
|| (Key::Esc <= key && key <= Key::Minus) )
|
||||||
|
{
|
||||||
|
m_eventQueue.postCharEvent(s_defaultWindow, 1, pressedChar);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
m_eventQueue.postKeyEvent(s_defaultWindow, key, modifiers, true);
|
m_eventQueue.postKeyEvent(s_defaultWindow, key, modifiers, true);
|
||||||
return false;
|
return false;
|
||||||
|
@ -322,7 +325,10 @@ namespace entry
|
||||||
case NSKeyUp:
|
case NSKeyUp:
|
||||||
{
|
{
|
||||||
uint8_t modifiers = 0;
|
uint8_t modifiers = 0;
|
||||||
Key::Enum key = handleKeyEvent(event, &modifiers);
|
uint8_t pressedChar[4];
|
||||||
|
Key::Enum key = handleKeyEvent(event, &modifiers, &pressedChar[0]);
|
||||||
|
|
||||||
|
BX_UNUSED(pressedChar);
|
||||||
|
|
||||||
if (key != Key::None)
|
if (key != Key::None)
|
||||||
{
|
{
|
||||||
|
@ -347,10 +353,15 @@ namespace entry
|
||||||
{
|
{
|
||||||
WindowHandle handle = { 0 };
|
WindowHandle handle = { 0 };
|
||||||
NSWindow* window = m_window[handle.idx];
|
NSWindow* window = m_window[handle.idx];
|
||||||
NSRect rect = [window frame];
|
NSRect originalFrame = [window frame];
|
||||||
|
NSRect rect = [NSWindow contentRectForFrameRect: originalFrame styleMask: NSTitledWindowMask];
|
||||||
uint32_t width = uint32_t(rect.size.width);
|
uint32_t width = uint32_t(rect.size.width);
|
||||||
uint32_t height = uint32_t(rect.size.height);
|
uint32_t height = uint32_t(rect.size.height);
|
||||||
m_eventQueue.postSizeEvent(handle, width, height);
|
m_eventQueue.postSizeEvent(handle, width, height);
|
||||||
|
|
||||||
|
// Make sure mouse button state is 'up' after resize.
|
||||||
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Left, false);
|
||||||
|
m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t run(int _argc, char** _argv)
|
int32_t run(int _argc, char** _argv)
|
||||||
|
@ -429,7 +440,6 @@ namespace entry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_eventQueue.postExitEvent();
|
m_eventQueue.postExitEvent();
|
||||||
|
|
||||||
while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ) {};
|
while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ) {};
|
||||||
|
@ -443,8 +453,11 @@ namespace entry
|
||||||
bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc;
|
bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc;
|
||||||
NSWindow* m_window[ENTRY_CONFIG_MAX_WINDOWS];
|
NSWindow* m_window[ENTRY_CONFIG_MAX_WINDOWS];
|
||||||
|
|
||||||
|
float m_scrollf;
|
||||||
|
int32_t m_mx;
|
||||||
|
int32_t m_my;
|
||||||
int32_t m_scroll;
|
int32_t m_scroll;
|
||||||
bool m_exit;
|
bool m_exit;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Context s_ctx;
|
static Context s_ctx;
|
||||||
|
|
|
@ -1405,7 +1405,7 @@ struct Imgui
|
||||||
{
|
{
|
||||||
const size_t cursor = size_t(strlen(_str));
|
const size_t cursor = size_t(strlen(_str));
|
||||||
|
|
||||||
if (m_char == 0x08) //backspace
|
if (m_char == 0x08 || m_char == 0x7f) //backspace or delete
|
||||||
{
|
{
|
||||||
_str[cursor-1] = '\0';
|
_str[cursor-1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue