mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
Added ocornut-imgui key mapping.
This commit is contained in:
parent
51d41041b7
commit
aa99fe1313
3 changed files with 48 additions and 4 deletions
|
@ -89,10 +89,10 @@ struct Keyboard
|
|||
return state;
|
||||
}
|
||||
|
||||
static void decodeKeyState(uint32_t _state, uint8_t& _modifiers, bool& _down)
|
||||
static bool decodeKeyState(uint32_t _state, uint8_t& _modifiers)
|
||||
{
|
||||
_modifiers = (_state>>16)&0xff;
|
||||
_down = 0 != ( (_state>>8)&0xff);
|
||||
return 0 != ( (_state>> 8)&0xff);
|
||||
}
|
||||
|
||||
void setKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down)
|
||||
|
@ -101,6 +101,14 @@ struct Keyboard
|
|||
m_once[_key] = false;
|
||||
}
|
||||
|
||||
bool getKeyState(entry::Key::Enum _key, uint8_t* _modifiers)
|
||||
{
|
||||
uint8_t modifiers;
|
||||
_modifiers = NULL == _modifiers ? &modifiers : _modifiers;
|
||||
|
||||
return decodeKeyState(m_key[_key], *_modifiers);
|
||||
}
|
||||
|
||||
void pushChar(uint8_t _len, const uint8_t _char[4])
|
||||
{
|
||||
for (uint32_t len = m_ring.reserve(4)
|
||||
|
@ -196,8 +204,7 @@ struct Input
|
|||
for (const InputBinding* binding = _bindings; binding->m_key != entry::Key::None; ++binding)
|
||||
{
|
||||
uint8_t modifiers;
|
||||
bool down;
|
||||
Keyboard::decodeKeyState(m_keyboard.m_key[binding->m_key], modifiers, down);
|
||||
bool down = Keyboard::decodeKeyState(m_keyboard.m_key[binding->m_key], modifiers);
|
||||
|
||||
if (binding->m_flags == 1)
|
||||
{
|
||||
|
@ -302,6 +309,11 @@ void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down)
|
|||
s_input->m_keyboard.setKeyState(_key, _modifiers, _down);
|
||||
}
|
||||
|
||||
bool inputGetKeyState(entry::Key::Enum _key, uint8_t* _modifiers)
|
||||
{
|
||||
return s_input->m_keyboard.getKeyState(_key, _modifiers);
|
||||
}
|
||||
|
||||
void inputChar(uint8_t _len, const uint8_t _char[4])
|
||||
{
|
||||
s_input->m_keyboard.pushChar(_len, _char);
|
||||
|
|
|
@ -39,6 +39,9 @@ void inputProcess();
|
|||
///
|
||||
void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down);
|
||||
|
||||
///
|
||||
bool inputGetKeyState(entry::Key::Enum _key, uint8_t* _modifiers = NULL);
|
||||
|
||||
/// Adds single UTF-8 encoded character into input buffer.
|
||||
void inputChar(uint8_t _len, const uint8_t _char[4]);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <bx/allocator.h>
|
||||
#include <bx/fpumath.h>
|
||||
#include <ocornut-imgui/imgui.h>
|
||||
#include "../entry/input.h"
|
||||
#include "imgui.h"
|
||||
#include "ocornut_imgui.h"
|
||||
#include <stb/stb_image.c>
|
||||
|
@ -61,6 +62,11 @@ struct OcornutImguiContext
|
|||
uint32_t vtx_offset = 0;
|
||||
for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++)
|
||||
{
|
||||
if (0 == pcmd->vtx_count)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bgfx::setState(0
|
||||
| BGFX_STATE_RGB_WRITE
|
||||
| BGFX_STATE_ALPHA_WRITE
|
||||
|
@ -105,6 +111,11 @@ struct OcornutImguiContext
|
|||
io.IniFilename = NULL;
|
||||
// io.PixelCenterOffset = bgfx::RendererType::Direct3D9 == bgfx::getRendererType() ? -0.5f : 0.0f;
|
||||
|
||||
for (uint32_t ii = 0; ii < ImGuiKey_COUNT; ++ii)
|
||||
{
|
||||
io.KeyMap[ii] = ImGuiKey_(ii);
|
||||
}
|
||||
|
||||
const bgfx::Memory* vsmem;
|
||||
const bgfx::Memory* fsmem;
|
||||
|
||||
|
@ -182,6 +193,24 @@ struct OcornutImguiContext
|
|||
io.MousePos = ImVec2((float)_mx, (float)_my);
|
||||
io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT);
|
||||
|
||||
io.KeysDown[ImGuiKey_Tab] = inputGetKeyState(entry::Key::Tab);
|
||||
io.KeysDown[ImGuiKey_LeftArrow] = inputGetKeyState(entry::Key::Left);
|
||||
io.KeysDown[ImGuiKey_RightArrow] = inputGetKeyState(entry::Key::Right);
|
||||
io.KeysDown[ImGuiKey_UpArrow] = inputGetKeyState(entry::Key::Up);
|
||||
io.KeysDown[ImGuiKey_DownArrow] = inputGetKeyState(entry::Key::Down);
|
||||
io.KeysDown[ImGuiKey_Home] = inputGetKeyState(entry::Key::Home);
|
||||
io.KeysDown[ImGuiKey_End] = inputGetKeyState(entry::Key::End);
|
||||
io.KeysDown[ImGuiKey_Delete] = inputGetKeyState(entry::Key::Delete);
|
||||
io.KeysDown[ImGuiKey_Backspace] = inputGetKeyState(entry::Key::Backspace);
|
||||
io.KeysDown[ImGuiKey_Enter] = inputGetKeyState(entry::Key::Return);
|
||||
io.KeysDown[ImGuiKey_Escape] = inputGetKeyState(entry::Key::Esc);
|
||||
io.KeysDown[ImGuiKey_A] = inputGetKeyState(entry::Key::KeyA);
|
||||
io.KeysDown[ImGuiKey_C] = inputGetKeyState(entry::Key::KeyC);
|
||||
io.KeysDown[ImGuiKey_V] = inputGetKeyState(entry::Key::KeyV);
|
||||
io.KeysDown[ImGuiKey_X] = inputGetKeyState(entry::Key::KeyX);
|
||||
io.KeysDown[ImGuiKey_Y] = inputGetKeyState(entry::Key::KeyY);
|
||||
io.KeysDown[ImGuiKey_Z] = inputGetKeyState(entry::Key::KeyZ);
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
//ImGui::ShowTestWindow(); //Debug only.
|
||||
|
|
Loading…
Reference in a new issue