From 6e6e16e2ba97cd4f3d8df6ad7a6808452d1fcfa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 9 Jun 2015 22:24:49 -0700 Subject: [PATCH 1/7] Pass thread exit code from app thread as process exit code. Issue #430. --- examples/common/entry/entry_sdl.cpp | 7 ++++--- examples/common/entry/entry_windows.cpp | 2 +- examples/common/entry/entry_x11.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/common/entry/entry_sdl.cpp b/examples/common/entry/entry_sdl.cpp index 91bfef74..d8ba1b47 100644 --- a/examples/common/entry/entry_sdl.cpp +++ b/examples/common/entry/entry_sdl.cpp @@ -320,7 +320,7 @@ namespace entry initTranslateGamepadAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT, GamepadAxis::RightZ); } - void run(int _argc, char** _argv) + int run(int _argc, char** _argv) { m_mte.m_argc = _argc; m_mte.m_argv = _argv; @@ -710,6 +710,8 @@ namespace entry SDL_DestroyWindow(m_window[0]); SDL_Quit(); + + return m_thread.getExitCode(); } WindowHandle findHandle(uint32_t _windowId) @@ -896,8 +898,7 @@ namespace entry int main(int _argc, char** _argv) { using namespace entry; - s_ctx.run(_argc, _argv); - return 0; + return s_ctx.run(_argc, _argv); } #endif // ENTRY_CONFIG_USE_SDL diff --git a/examples/common/entry/entry_windows.cpp b/examples/common/entry/entry_windows.cpp index 26f496d6..376ce8ac 100644 --- a/examples/common/entry/entry_windows.cpp +++ b/examples/common/entry/entry_windows.cpp @@ -499,7 +499,7 @@ namespace entry s_xinput.shutdown(); - return 0; + return thread.getExitCode(); } LRESULT process(HWND _hwnd, UINT _id, WPARAM _wparam, LPARAM _lparam) diff --git a/examples/common/entry/entry_x11.cpp b/examples/common/entry/entry_x11.cpp index 44a501e7..ff1768c7 100644 --- a/examples/common/entry/entry_x11.cpp +++ b/examples/common/entry/entry_x11.cpp @@ -477,7 +477,7 @@ namespace entry XUnmapWindow(m_display, m_window[0]); XDestroyWindow(m_display, m_window[0]); - return EXIT_SUCCESS; + return thread.getExitCode(); } void setModifier(Modifier::Enum _modifier, bool _set) From f0b76697c5b5fa3530c41c6cb9b23692cf052beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 9 Jun 2015 23:56:30 -0700 Subject: [PATCH 2/7] Fixing GCC warnings. --- examples/common/imgui/scintilla.cpp | 33 +++++++++++++++-------------- scripts/example-common.lua | 4 ++++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/examples/common/imgui/scintilla.cpp b/examples/common/imgui/scintilla.cpp index 7eb138a1..59258d39 100644 --- a/examples/common/imgui/scintilla.cpp +++ b/examples/common/imgui/scintilla.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "scintilla/include/Platform.h" #include "scintilla/include/Scintilla.h" @@ -351,16 +352,16 @@ inline WindowInt* GetWindow(Scintilla::WindowID id) class ListBoxInt : public Scintilla::ListBox { public: - ListBoxInt::ListBoxInt() - : m_lineHeight(10) - , m_unicodeMode(false) + ListBoxInt() + : m_maxStrWidth(0) + , m_lineHeight(10) , m_desiredVisibleRows(5) , m_aveCharWidth(8) - , m_maxStrWidth(0) + , m_unicodeMode(false) { } - ListBoxInt::~ListBoxInt() + ~ListBoxInt() { } @@ -468,16 +469,14 @@ private: bool m_unicodeMode; }; -struct ScEditor : public Scintilla::ScintillaBase +struct Editor : public Scintilla::ScintillaBase { public: - ScEditor() + Editor() : m_width(0) , m_height(0) , m_wheelVRotation(0) , m_wheelHRotation(0) - , m_foreground(0xffffffff) - , m_lineNumber(0xff00ffff) , m_searchResultIndication(0xff5A5A5A) , m_filteredSearchResultIndication(0xff5a5a5a) , m_occurrenceIndication(0xff5a5a5a) @@ -508,10 +507,12 @@ public: , m_staticField(0xff4b9ce9) , m_staticFinalField(0xff4b9ce9) , m_deprecatedMember(0xfff9f9f9) + , m_foreground(0xffffffff) + , m_lineNumber(0xff00ffff) { } - virtual ~ScEditor() + virtual ~Editor() { } @@ -833,7 +834,7 @@ private: ScintillaEditor* ScintillaEditor::create(int _width, int _height) { - ScEditor* editor = IMGUI_NEW(ScEditor); + Editor* editor = IMGUI_NEW(Editor); editor->Initialise(); editor->Resize(0, 0, _width, _height); @@ -843,18 +844,18 @@ ScintillaEditor* ScintillaEditor::create(int _width, int _height) void ScintillaEditor::destroy(ScintillaEditor* _scintilla) { - IMGUI_DELETE(ScEditor, _scintilla); + IMGUI_DELETE(Editor, _scintilla); } intptr_t ScintillaEditor::command(unsigned int _msg, uintptr_t _p0, intptr_t _p1) { - ScEditor* editor = reinterpret_cast(this); + Editor* editor = reinterpret_cast(this); return editor->command(_msg, _p0, _p1); } void ScintillaEditor::draw() { - ScEditor* editor = reinterpret_cast(this); + Editor* editor = reinterpret_cast(this); return editor->draw(); } @@ -1019,9 +1020,9 @@ namespace Scintilla GetWindow(wid)->position = rc; } - void Window::SetPositionRelative(PRectangle rc, Window w) + void Window::SetPositionRelative(PRectangle _rc, Window /*_w*/) { - SetPosition(rc); + SetPosition(_rc); } PRectangle Window::GetClientPosition() diff --git a/scripts/example-common.lua b/scripts/example-common.lua index f95e29ec..94aa9d5c 100644 --- a/scripts/example-common.lua +++ b/scripts/example-common.lua @@ -28,6 +28,10 @@ project ("example-common") "SCI_LEXER", } + buildoptions { +-- "-Wno-missing-field-initializers", + } + includedirs { path.join(BGFX_DIR, "3rdparty/scintilla/include"), path.join(BGFX_DIR, "3rdparty/scintilla/lexlib"), From e97be61a752f13304e239ebad4cbe622cf092817 Mon Sep 17 00:00:00 2001 From: Kocsis Attila Date: Wed, 10 Jun 2015 15:52:12 +0200 Subject: [PATCH 3/7] added iOS GL extension function import --- src/glcontext_eagl.mm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/glcontext_eagl.mm b/src/glcontext_eagl.mm index 1f1c0880..2a756ea1 100644 --- a/src/glcontext_eagl.mm +++ b/src/glcontext_eagl.mm @@ -15,8 +15,13 @@ namespace bgfx { namespace gl # define GL_IMPORT(_optional, _proto, _func, _import) _proto _func = NULL # include "glimports.h" + static void* s_opengles = NULL; + void GlContext::create(uint32_t _width, uint32_t _height) { + s_opengles = bx::dlopen("/System/Library/Frameworks/OpenGLES.framework/OpenGLES"); + BX_CHECK(NULL != s_opengles, "OpenGLES dynamic library is not found!"); + BX_UNUSED(_width, _height); CAEAGLLayer* layer = (CAEAGLLayer*)g_platformData.nwh; layer.opaque = true; @@ -59,6 +64,8 @@ namespace bgfx { namespace gl , "glCheckFramebufferStatus failed 0x%08x" , glCheckFramebufferStatus(GL_FRAMEBUFFER) ); + + import(); } void GlContext::destroy() @@ -83,6 +90,8 @@ namespace bgfx { namespace gl EAGLContext* context = (EAGLContext*)m_context; [context release]; + + bx::dlclose(s_opengles); } void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags) @@ -121,6 +130,17 @@ namespace bgfx { namespace gl void GlContext::import() { + BX_TRACE("Import:"); +# define GL_EXTENSION(_optional, _proto, _func, _import) \ + { \ + if (_func == NULL) \ + { \ + _func = (_proto)bx::dlsym(s_opengles, #_import); \ + BX_TRACE("%p " #_func " (" #_import ")", _func); \ + } \ + BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. EAGLGetProcAddress(\"%s\")", #_import); \ + } +# include "glimports.h" } } /* namespace gl */ } // namespace bgfx From eccbae09b1f363d986d1b09693c5b160cb35f93a Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 10 Jun 2015 08:53:50 -0600 Subject: [PATCH 4/7] Fixes for ocornut-imgui integrations: mouse wheel, render callbacks --- examples/09-hdr/hdr.cpp | 2 +- examples/11-fontsdf/fontsdf.cpp | 2 +- examples/12-lod/lod.cpp | 2 +- examples/13-stencil/stencil.cpp | 2 +- examples/14-shadowvolumes/shadowvolumes.cpp | 2 +- examples/16-shadowmaps/shadowmaps.cpp | 2 +- examples/17-drawstress/drawstress.cpp | 2 +- examples/18-ibl/ibl.cpp | 2 +- examples/19-oit/oit.cpp | 2 +- examples/21-deferred/deferred.cpp | 2 +- examples/24-nbody/nbody.cpp | 2 +- examples/common/imgui/imgui.cpp | 2 +- examples/common/imgui/ocornut_imgui.cpp | 21 ++++++++++++++++----- examples/common/imgui/ocornut_imgui.h | 2 +- 14 files changed, 29 insertions(+), 18 deletions(-) diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index 9c18ba38..cc8a96d4 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -265,7 +265,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , width , height ); diff --git a/examples/11-fontsdf/fontsdf.cpp b/examples/11-fontsdf/fontsdf.cpp index bf60dd8d..02d17314 100644 --- a/examples/11-fontsdf/fontsdf.cpp +++ b/examples/11-fontsdf/fontsdf.cpp @@ -132,7 +132,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , width , height ); diff --git a/examples/12-lod/lod.cpp b/examples/12-lod/lod.cpp index 2a6775ea..acc8c17d 100644 --- a/examples/12-lod/lod.cpp +++ b/examples/12-lod/lod.cpp @@ -119,7 +119,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , width , height ); diff --git a/examples/13-stencil/stencil.cpp b/examples/13-stencil/stencil.cpp index c9252294..1493c823 100644 --- a/examples/13-stencil/stencil.cpp +++ b/examples/13-stencil/stencil.cpp @@ -945,7 +945,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , viewState.m_width , viewState.m_height ); diff --git a/examples/14-shadowvolumes/shadowvolumes.cpp b/examples/14-shadowvolumes/shadowvolumes.cpp index 1613f8ef..d75797d7 100644 --- a/examples/14-shadowvolumes/shadowvolumes.cpp +++ b/examples/14-shadowvolumes/shadowvolumes.cpp @@ -2128,7 +2128,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , viewState.m_width , viewState.m_height ); diff --git a/examples/16-shadowmaps/shadowmaps.cpp b/examples/16-shadowmaps/shadowmaps.cpp index 5f050f92..cc106298 100644 --- a/examples/16-shadowmaps/shadowmaps.cpp +++ b/examples/16-shadowmaps/shadowmaps.cpp @@ -1974,7 +1974,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , viewState.m_width , viewState.m_height ); diff --git a/examples/17-drawstress/drawstress.cpp b/examples/17-drawstress/drawstress.cpp index ba79c792..9e649dae 100644 --- a/examples/17-drawstress/drawstress.cpp +++ b/examples/17-drawstress/drawstress.cpp @@ -141,7 +141,7 @@ BX_NO_INLINE bool mainloop() , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , width , height ); diff --git a/examples/18-ibl/ibl.cpp b/examples/18-ibl/ibl.cpp index 2291fef3..08f3be89 100644 --- a/examples/18-ibl/ibl.cpp +++ b/examples/18-ibl/ibl.cpp @@ -311,7 +311,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , width , height ); diff --git a/examples/19-oit/oit.cpp b/examples/19-oit/oit.cpp index 9aa3ff2d..f5f73a96 100644 --- a/examples/19-oit/oit.cpp +++ b/examples/19-oit/oit.cpp @@ -244,7 +244,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , width , height ); diff --git a/examples/21-deferred/deferred.cpp b/examples/21-deferred/deferred.cpp index 87c93bee..a477730e 100644 --- a/examples/21-deferred/deferred.cpp +++ b/examples/21-deferred/deferred.cpp @@ -407,7 +407,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , width , height ); diff --git a/examples/24-nbody/nbody.cpp b/examples/24-nbody/nbody.cpp index 52dfce19..90d95e56 100644 --- a/examples/24-nbody/nbody.cpp +++ b/examples/24-nbody/nbody.cpp @@ -221,7 +221,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) , mouseState.m_my , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - , 0 + , mouseState.m_mz , width , height ); diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index dd2a9ad7..7661c3bb 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -824,7 +824,7 @@ struct Imgui const int32_t mx = int32_t(float(_mx)*xscale); const int32_t my = int32_t(float(_my)*yscale); - IMGUI_beginFrame(mx, my, _button, _width, _height, _inputChar, _view); + IMGUI_beginFrame(mx, my, _button, _scroll, _width, _height, _inputChar, _view); nvgBeginFrameScaled(m_nvg, m_viewWidth, m_viewHeight, m_surfaceWidth, m_surfaceHeight, 1.0f); nvgViewId(m_nvg, _view); diff --git a/examples/common/imgui/ocornut_imgui.cpp b/examples/common/imgui/ocornut_imgui.cpp index c38c0dd9..c9feca10 100644 --- a/examples/common/imgui/ocornut_imgui.cpp +++ b/examples/common/imgui/ocornut_imgui.cpp @@ -35,7 +35,6 @@ struct OcornutImguiContext { bgfx::TransientVertexBuffer tvb; - const ImDrawList* cmd_list = _lists[ii]; const ImDrawVert* vtx_buffer = cmd_list->vtx_buffer.begin(); uint32_t vtx_size = (uint32_t)cmd_list->vtx_buffer.size(); @@ -56,6 +55,12 @@ struct OcornutImguiContext const ImDrawCmd* pcmd_end = cmd_list->commands.end(); for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++) { + if (pcmd->user_callback) + { + pcmd->user_callback(cmd_list, pcmd); + vtx_offset += pcmd->vtx_count; + continue; + } if (0 == pcmd->vtx_count) { continue; @@ -92,6 +97,7 @@ struct OcornutImguiContext { m_viewId = 255; m_allocator = _allocator; + m_lastScroll = 0; ImGuiIO& io = ImGui::GetIO(); io.RenderDrawListsFn = renderDrawLists; @@ -177,15 +183,19 @@ struct OcornutImguiContext m_allocator = NULL; } - void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int _width, int _height, char _inputChar, uint8_t _viewId) + void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId) { m_viewId = _viewId; ImGuiIO& io = ImGui::GetIO(); - io.AddInputCharacter(_inputChar & 0x7f); // ASCII or GTFO! :) + if (_inputChar < 0x7f) + io.AddInputCharacter(_inputChar); // ASCII or GTFO! :( io.DisplaySize = ImVec2((float)_width, (float)_height); io.DeltaTime = 1.0f / 60.0f; io.MousePos = ImVec2((float)_mx, (float)_my); io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT); + io.MouseDown[1] = 0 != (_button & IMGUI_MBUT_RIGHT); + io.MouseWheel = (float)(_scroll - m_lastScroll); + m_lastScroll = _scroll; #if 0 io.KeysDown[ImGuiKey_Tab] = inputGetKeyState(entry::Key::Tab); @@ -223,6 +233,7 @@ struct OcornutImguiContext bgfx::TextureHandle m_texture; bgfx::UniformHandle s_tex; uint8_t m_viewId; + int32_t m_lastScroll; }; static OcornutImguiContext s_ctx; @@ -252,9 +263,9 @@ void IMGUI_destroy() s_ctx.destroy(); } -void IMGUI_beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int _width, int _height, char _inputChar, uint8_t _viewId) +void IMGUI_beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId) { - s_ctx.beginFrame(_mx, _my, _button, _width, _height, _inputChar, _viewId); + s_ctx.beginFrame(_mx, _my, _button, _scroll, _width, _height, _inputChar, _viewId); } void IMGUI_endFrame() diff --git a/examples/common/imgui/ocornut_imgui.h b/examples/common/imgui/ocornut_imgui.h index fd5d2503..450b2817 100644 --- a/examples/common/imgui/ocornut_imgui.h +++ b/examples/common/imgui/ocornut_imgui.h @@ -12,7 +12,7 @@ namespace bx { struct AllocatorI; } void IMGUI_create(const void* _data, uint32_t _size, float _fontSize, bx::AllocatorI* _allocator); void IMGUI_destroy(); -void IMGUI_beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int _width, int _height, char _inputChar, uint8_t _viewId); +void IMGUI_beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId); void IMGUI_endFrame(); #endif // OCORNUT_IMGUI_H_HEADER_GUARD From a3fd7b7132ec27e94be96dd4da08b195662d50a4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 10 Jun 2015 09:03:17 -0600 Subject: [PATCH 5/7] Fixes for ocornut-imgui integration: keyboard keys, modifiers --- examples/common/imgui/ocornut_imgui.cpp | 47 +++++++++++++------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/examples/common/imgui/ocornut_imgui.cpp b/examples/common/imgui/ocornut_imgui.cpp index c9feca10..06c954da 100644 --- a/examples/common/imgui/ocornut_imgui.cpp +++ b/examples/common/imgui/ocornut_imgui.cpp @@ -10,6 +10,7 @@ #include "imgui.h" #include "ocornut_imgui.h" #include +#include "../entry/input.h" #include "vs_ocornut_imgui.bin.h" #include "fs_ocornut_imgui.bin.h" @@ -111,10 +112,23 @@ struct OcornutImguiContext io.IniFilename = NULL; io.PixelCenterOffset = bgfx::RendererType::Direct3D9 == bgfx::getRendererType() ? 0.0f : 0.5f; - for (uint32_t ii = 0; ii < ImGuiKey_COUNT; ++ii) - { - io.KeyMap[ii] = ImGuiKey_(ii); - } + io.KeyMap[ImGuiKey_Tab] = (int)entry::Key::Tab; + io.KeyMap[ImGuiKey_LeftArrow] = (int)entry::Key::Left; + io.KeyMap[ImGuiKey_RightArrow] = (int)entry::Key::Right; + io.KeyMap[ImGuiKey_UpArrow] = (int)entry::Key::Up; + io.KeyMap[ImGuiKey_DownArrow] = (int)entry::Key::Down; + io.KeyMap[ImGuiKey_Home] = (int)entry::Key::Home; + io.KeyMap[ImGuiKey_End] = (int)entry::Key::End; + io.KeyMap[ImGuiKey_Delete] = (int)entry::Key::Delete; + io.KeyMap[ImGuiKey_Backspace] = (int)entry::Key::Backspace; + io.KeyMap[ImGuiKey_Enter] = (int)entry::Key::Return; + io.KeyMap[ImGuiKey_Escape] = (int)entry::Key::Esc; + io.KeyMap[ImGuiKey_A] = (int)entry::Key::KeyA; + io.KeyMap[ImGuiKey_C] = (int)entry::Key::KeyC; + io.KeyMap[ImGuiKey_V] = (int)entry::Key::KeyV; + io.KeyMap[ImGuiKey_X] = (int)entry::Key::KeyX; + io.KeyMap[ImGuiKey_Y] = (int)entry::Key::KeyY; + io.KeyMap[ImGuiKey_Z] = (int)entry::Key::KeyZ; const bgfx::Memory* vsmem; const bgfx::Memory* fsmem; @@ -197,25 +211,12 @@ struct OcornutImguiContext io.MouseWheel = (float)(_scroll - m_lastScroll); m_lastScroll = _scroll; -#if 0 - 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); -#endif // 0 + uint8_t modifiers = inputGetModifiersState(); + io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) ); + io.KeyCtrl = 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) ); + io.KeyAlt = 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt ) ); + for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii) + io.KeysDown[ii] = inputGetKeyState((entry::Key::Enum)ii); ImGui::NewFrame(); From a2716a3fe6937dff6a5f18fab70596f9ef5192e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 10 Jun 2015 09:53:09 -0700 Subject: [PATCH 6/7] Cleanup. --- examples/common/imgui/imgui.cpp | 1 - examples/common/imgui/ocornut_imgui.cpp | 66 +++++++++++++++---------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 7661c3bb..d2cbc0e7 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -29,7 +29,6 @@ #include #include -#include "../entry/dbg.h" #include "imgui.h" #include "ocornut_imgui.h" #include "../nanovg/nanovg.h" diff --git a/examples/common/imgui/ocornut_imgui.cpp b/examples/common/imgui/ocornut_imgui.cpp index 06c954da..99bd0da7 100644 --- a/examples/common/imgui/ocornut_imgui.cpp +++ b/examples/common/imgui/ocornut_imgui.cpp @@ -10,7 +10,10 @@ #include "imgui.h" #include "ocornut_imgui.h" #include -#include "../entry/input.h" + +#if defined(SCI_NAMESPACE) +# include "../entry/input.h" +#endif // defined(SCI_NAMESPACE) #include "vs_ocornut_imgui.bin.h" #include "fs_ocornut_imgui.bin.h" @@ -112,23 +115,25 @@ struct OcornutImguiContext io.IniFilename = NULL; io.PixelCenterOffset = bgfx::RendererType::Direct3D9 == bgfx::getRendererType() ? 0.0f : 0.5f; - io.KeyMap[ImGuiKey_Tab] = (int)entry::Key::Tab; - io.KeyMap[ImGuiKey_LeftArrow] = (int)entry::Key::Left; - io.KeyMap[ImGuiKey_RightArrow] = (int)entry::Key::Right; - io.KeyMap[ImGuiKey_UpArrow] = (int)entry::Key::Up; - io.KeyMap[ImGuiKey_DownArrow] = (int)entry::Key::Down; - io.KeyMap[ImGuiKey_Home] = (int)entry::Key::Home; - io.KeyMap[ImGuiKey_End] = (int)entry::Key::End; - io.KeyMap[ImGuiKey_Delete] = (int)entry::Key::Delete; - io.KeyMap[ImGuiKey_Backspace] = (int)entry::Key::Backspace; - io.KeyMap[ImGuiKey_Enter] = (int)entry::Key::Return; - io.KeyMap[ImGuiKey_Escape] = (int)entry::Key::Esc; - io.KeyMap[ImGuiKey_A] = (int)entry::Key::KeyA; - io.KeyMap[ImGuiKey_C] = (int)entry::Key::KeyC; - io.KeyMap[ImGuiKey_V] = (int)entry::Key::KeyV; - io.KeyMap[ImGuiKey_X] = (int)entry::Key::KeyX; - io.KeyMap[ImGuiKey_Y] = (int)entry::Key::KeyY; - io.KeyMap[ImGuiKey_Z] = (int)entry::Key::KeyZ; +#if defined(SCI_NAMESPACE) + io.KeyMap[ImGuiKey_Tab] = (int)entry::Key::Tab; + io.KeyMap[ImGuiKey_LeftArrow] = (int)entry::Key::Left; + io.KeyMap[ImGuiKey_RightArrow] = (int)entry::Key::Right; + io.KeyMap[ImGuiKey_UpArrow] = (int)entry::Key::Up; + io.KeyMap[ImGuiKey_DownArrow] = (int)entry::Key::Down; + io.KeyMap[ImGuiKey_Home] = (int)entry::Key::Home; + io.KeyMap[ImGuiKey_End] = (int)entry::Key::End; + io.KeyMap[ImGuiKey_Delete] = (int)entry::Key::Delete; + io.KeyMap[ImGuiKey_Backspace] = (int)entry::Key::Backspace; + io.KeyMap[ImGuiKey_Enter] = (int)entry::Key::Return; + io.KeyMap[ImGuiKey_Escape] = (int)entry::Key::Esc; + io.KeyMap[ImGuiKey_A] = (int)entry::Key::KeyA; + io.KeyMap[ImGuiKey_C] = (int)entry::Key::KeyC; + io.KeyMap[ImGuiKey_V] = (int)entry::Key::KeyV; + io.KeyMap[ImGuiKey_X] = (int)entry::Key::KeyX; + io.KeyMap[ImGuiKey_Y] = (int)entry::Key::KeyY; + io.KeyMap[ImGuiKey_Z] = (int)entry::Key::KeyZ; +#endif // defined(SCI_NAMESPACE) const bgfx::Memory* vsmem; const bgfx::Memory* fsmem; @@ -202,21 +207,28 @@ struct OcornutImguiContext m_viewId = _viewId; ImGuiIO& io = ImGui::GetIO(); if (_inputChar < 0x7f) + { io.AddInputCharacter(_inputChar); // ASCII or GTFO! :( + } + io.DisplaySize = ImVec2((float)_width, (float)_height); io.DeltaTime = 1.0f / 60.0f; io.MousePos = ImVec2((float)_mx, (float)_my); io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT); - io.MouseDown[1] = 0 != (_button & IMGUI_MBUT_RIGHT); - io.MouseWheel = (float)(_scroll - m_lastScroll); - m_lastScroll = _scroll; + io.MouseDown[1] = 0 != (_button & IMGUI_MBUT_RIGHT); + io.MouseWheel = (float)(_scroll - m_lastScroll); + m_lastScroll = _scroll; - uint8_t modifiers = inputGetModifiersState(); - io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) ); - io.KeyCtrl = 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) ); - io.KeyAlt = 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt ) ); - for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii) - io.KeysDown[ii] = inputGetKeyState((entry::Key::Enum)ii); +#if defined(SCI_NAMESPACE) + uint8_t modifiers = inputGetModifiersState(); + io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) ); + io.KeyCtrl = 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) ); + io.KeyAlt = 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt ) ); + for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii) + { + io.KeysDown[ii] = inputGetKeyState(entry::Key::Enum(ii) ); + } +#endif // defined(SCI_NAMESPACE) ImGui::NewFrame(); From 5cbc5d55f4618dce4ba830e04a99f8bbaf215bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 10 Jun 2015 13:21:59 -0700 Subject: [PATCH 7/7] Cleanup. --- examples/common/imgui/scintilla.cpp | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/common/imgui/scintilla.cpp b/examples/common/imgui/scintilla.cpp index 59258d39..e9225cd8 100644 --- a/examples/common/imgui/scintilla.cpp +++ b/examples/common/imgui/scintilla.cpp @@ -669,71 +669,71 @@ public: const bool ctrl = 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) ); const bool alt = 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt ) ); - if (ImGui::IsKeyPressed(ImGuiKey_Tab) ) + if (ImGui::IsKeyPressed(entry::Key::Tab) ) { Editor::KeyDown(SCK_TAB, shift, ctrl, alt); } - else if (ImGui::IsKeyPressed(ImGuiKey_LeftArrow) ) + else if (ImGui::IsKeyPressed(entry::Key::Left) ) { Editor::KeyDown(SCK_LEFT, shift, ctrl, alt); } - else if (ImGui::IsKeyPressed(ImGuiKey_RightArrow) ) + else if (ImGui::IsKeyPressed(entry::Key::Right) ) { Editor::KeyDown(SCK_RIGHT, shift, ctrl, alt); } - else if (ImGui::IsKeyPressed(ImGuiKey_UpArrow) ) + else if (ImGui::IsKeyPressed(entry::Key::Up) ) { Editor::KeyDown(SCK_UP, shift, ctrl, alt); } - else if (ImGui::IsKeyPressed(ImGuiKey_DownArrow) ) + else if (ImGui::IsKeyPressed(entry::Key::Down) ) { Editor::KeyDown(SCK_DOWN, shift, ctrl, alt); } - else if (ImGui::IsKeyPressed(ImGuiKey_Home) ) + else if (ImGui::IsKeyPressed(entry::Key::Home) ) { Editor::KeyDown(SCK_HOME, shift, ctrl, alt); } - else if (ImGui::IsKeyPressed(ImGuiKey_End) ) + else if (ImGui::IsKeyPressed(entry::Key::End) ) { Editor::KeyDown(SCK_END, shift, ctrl, alt); } - else if (ImGui::IsKeyPressed(ImGuiKey_Delete) ) + else if (ImGui::IsKeyPressed(entry::Key::Delete) ) { Editor::KeyDown(SCK_DELETE, shift, ctrl, alt); } - else if (ImGui::IsKeyPressed(ImGuiKey_Backspace) ) + else if (ImGui::IsKeyPressed(entry::Key::Backspace) ) { Editor::KeyDown(SCK_BACK, shift, ctrl, alt); inputGetChar(); } - else if (ImGui::IsKeyPressed(ImGuiKey_Enter) ) + else if (ImGui::IsKeyPressed(entry::Key::Return) ) { Editor::KeyDown(SCK_RETURN, shift, ctrl, alt); inputGetChar(); } - else if (ImGui::IsKeyPressed(ImGuiKey_Escape) ) + else if (ImGui::IsKeyPressed(entry::Key::Esc) ) { Editor::KeyDown(SCK_ESCAPE, shift, ctrl, alt); } - else if (ctrl && ImGui::IsKeyPressed(ImGuiKey_A) ) + else if (ctrl && ImGui::IsKeyPressed(entry::Key::KeyA) ) { Editor::KeyDown('A', shift, ctrl, alt); inputGetChar(); } - else if (ctrl && ImGui::IsKeyPressed(ImGuiKey_C) ) + else if (ctrl && ImGui::IsKeyPressed(entry::Key::KeyC) ) { Editor::KeyDown('C', shift, ctrl, alt); inputGetChar(); } - else if (ctrl && ImGui::IsKeyPressed(ImGuiKey_V) ) + else if (ctrl && ImGui::IsKeyPressed(entry::Key::KeyV) ) { Editor::KeyDown('V', shift, ctrl, alt); inputGetChar(); } - else if (ctrl && ImGui::IsKeyPressed(ImGuiKey_X) ) + else if (ctrl && ImGui::IsKeyPressed(entry::Key::KeyX) ) { Editor::KeyDown('X', shift, ctrl, alt); inputGetChar(); } - else if (ctrl && ImGui::IsKeyPressed(ImGuiKey_Y) ) + else if (ctrl && ImGui::IsKeyPressed(entry::Key::KeyY) ) { Editor::KeyDown('Y', shift, ctrl, alt); inputGetChar(); } - else if (ctrl && ImGui::IsKeyPressed(ImGuiKey_Z) ) + else if (ctrl && ImGui::IsKeyPressed(entry::Key::KeyZ) ) { Editor::KeyDown('Z', shift, ctrl, alt); inputGetChar(); }