diff --git a/examples/README.txt b/examples/README.txt index c675a1d7..0a5ad0e0 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -11,7 +11,7 @@ opengl_example/ Prefer following this example since it is the shortest one! opengl3_example/ - OpenGL exemple, using GLFW/GL3W + programmable pipeline. + OpenGL example, using GLFW/GL3W + programmable pipeline. This uses more modern calls and custom shaders. I don't think there is an advantage using this over the simpler example, but it is provided for reference. @@ -22,3 +22,6 @@ directx11_example/ DirectX11 example, Windows only. This is quite long and tedious, because: DirectX11. +ios_example/ + iOS example. + Using Synergy to access keyboard/mouse data from server computer. Synergy keyboard integration is rather hacky. diff --git a/examples/ios_example/README.md b/examples/ios_example/README.md index fc179f0d..5b51b905 100644 --- a/examples/ios_example/README.md +++ b/examples/ios_example/README.md @@ -3,9 +3,9 @@ ---- ## Introduction -This example is the default XCode "OpenGL" example code, modified to support IMGUI and [Synergy](http://synergy-project.org/). +This example is the default XCode "OpenGL" example code, modified to support ImGui and [Synergy](http://synergy-project.org/). -Synergy (remote keyboard/mouse) is not required, but it's pretty hard to use IMGUI without it. Synergy includes a "uSynergy" library that allows embedding a synergy client, this is what is used here. IMGUI supports "Touch Padding", and this is enabled when Synergy is not active. +Synergy (remote keyboard/mouse) is not required, but it's pretty hard to use ImGui without it. Synergy includes a "uSynergy" library that allows embedding a synergy client, this is what is used here. ImGui supports "TouchPadding", and this is enabled when Synergy is not active. ## How to Use ---- @@ -28,8 +28,8 @@ Things that would be nice but I didn't get around to doing: ---- ## C++ on iOS -IMGUI is a c++ library. If you want to include it directly, rename your Obj-C file to have the ".mm" extension. +ImGui is a c++ library. If you want to include it directly, rename your Obj-C file to have the ".mm" extension. Alternatively, you can wrap your debug code in a C interface, this is what I am demonstrating here with the "debug_hud.h" interface. Either approach works, use whatever you prefer. -In my case, most of my game code is already in C++ so it's not really an issue and I can use IMGUI directly. +In my case, most of my game code is already in C++ so it's not really an issue and I can use ImGui directly. diff --git a/examples/ios_example/imguiex/GameViewController.h b/examples/ios_example/imguiex/GameViewController.h index 7c7eeeae..3323cfd5 100644 --- a/examples/ios_example/imguiex/GameViewController.h +++ b/examples/ios_example/imguiex/GameViewController.h @@ -2,8 +2,7 @@ // GameViewController.h // imguiex -// This is the OpenGL Example template from XCode, modified to -// support IMGUI +// This is the OpenGL Example template from XCode, modified to support ImGui #import #import diff --git a/examples/ios_example/imguiex/debug_hud.cpp b/examples/ios_example/imguiex/debug_hud.cpp index 5d364d7b..c75938a3 100644 --- a/examples/ios_example/imguiex/debug_hud.cpp +++ b/examples/ios_example/imguiex/debug_hud.cpp @@ -9,20 +9,19 @@ void DebugHUD_InitDefaults( DebugHUD *hud ) { - hud->show_test_window = 1; - hud->show_example_window = 1; - hud->rotation_speed = 15.0; + hud->show_test_window = true; + hud->show_example_window = true; + hud->rotation_speed = 15.0f; - hud->cubeColor1[0] = 0.4; - hud->cubeColor1[1] = 0.4; - hud->cubeColor1[2] = 1.0; - hud->cubeColor1[3] = 1.0; - - hud->cubeColor2[0] = 1.0; - hud->cubeColor2[1] = 0.4; - hud->cubeColor2[2] = 0.4; - hud->cubeColor2[3] = 1.0; + hud->cubeColor1[0] = 0.4f; + hud->cubeColor1[1] = 0.4f; + hud->cubeColor1[2] = 1.0f; + hud->cubeColor1[3] = 1.0f; + hud->cubeColor2[0] = 1.0f; + hud->cubeColor2[1] = 0.4f; + hud->cubeColor2[2] = 0.4f; + hud->cubeColor2[3] = 1.0f; } void DebugHUD_DoInterface( DebugHUD *hud ) @@ -30,24 +29,17 @@ void DebugHUD_DoInterface( DebugHUD *hud ) if (hud->show_test_window) { ImGui::SetNextWindowPos( ImVec2( 400, 20 ), ImGuiSetCond_FirstUseEver ); - bool show_test_window = hud->show_test_window; - ImGui::ShowTestWindow( &show_test_window ); - hud->show_test_window = show_test_window; + ImGui::ShowTestWindow( &hud->show_test_window ); } if (hud->show_example_window) { - bool show_window = hud->show_example_window; ImGui::SetNextWindowPos( ImVec2( 20, 20 ), ImGuiSetCond_FirstUseEver ); ImGui::SetNextWindowSize( ImVec2( 350, 200 ), ImGuiSetCond_FirstUseEver ); - ImGui::Begin("Another Window", &show_window); - hud->show_example_window = show_window; - + ImGui::Begin("Another Window", &hud->show_example_window); ImGui::ColorEdit3("Cube 1 Color", hud->cubeColor1); ImGui::ColorEdit3("Cube 2 Color", hud->cubeColor2); - ImGui::SliderFloat("Rotation Speed", &(hud->rotation_speed), 0.0f, 200.0f); - + ImGui::SliderFloat("Rotation Speed", &hud->rotation_speed, 0.0f, 200.0f); ImGui::End(); } - -} \ No newline at end of file +} diff --git a/examples/ios_example/imguiex/debug_hud.h b/examples/ios_example/imguiex/debug_hud.h index 6df9ff0c..17122f5e 100644 --- a/examples/ios_example/imguiex/debug_hud.h +++ b/examples/ios_example/imguiex/debug_hud.h @@ -2,13 +2,12 @@ // debug_hud.h // imguiex -#ifndef __imguiex__debug_hud__ -#define __imguiex__debug_hud__ +#pragma once typedef struct DebugHUD { - int show_test_window; - int show_example_window; + bool show_test_window; + bool show_example_window; float rotation_speed; float cubeColor1[4]; float cubeColor2[4]; @@ -24,5 +23,3 @@ void DebugHUD_DoInterface( DebugHUD *hud ); #if __cplusplus } #endif - -#endif /* defined(__imguiex__debug_hud__) */ diff --git a/examples/ios_example/imguiex/imgui_impl_ios.h b/examples/ios_example/imguiex/imgui_impl_ios.h index b882c1c1..132e589d 100644 --- a/examples/ios_example/imguiex/imgui_impl_ios.h +++ b/examples/ios_example/imguiex/imgui_impl_ios.h @@ -5,8 +5,7 @@ // Joel Davis (joeld42@gmail.com) // -#ifndef __imguiex__imgui_impl_ios__ -#define __imguiex__imgui_impl_ios__ +#pragma once #include #include @@ -21,6 +20,3 @@ - (void)newFrame; @end - - -#endif /* defined(__imguiex__imgui_impl_ios__) */ diff --git a/examples/ios_example/imguiex/imgui_impl_ios.mm b/examples/ios_example/imguiex/imgui_impl_ios.mm index c7cf41df..9b6513ac 100644 --- a/examples/ios_example/imguiex/imgui_impl_ios.mm +++ b/examples/ios_example/imguiex/imgui_impl_ios.mm @@ -16,6 +16,7 @@ #include "uSynergy.h" // From Carbon HIToolbox/Events.h +// FIXME: Keyboard mapping is hacked in because Synergy doesn't give us character but only keycode which aren't really portable if you consider keyboard locale. See https://github.com/ocornut/imgui/pull/247 enum { kVK_ANSI_A = 0x00, kVK_ANSI_S = 0x01, @@ -267,15 +268,10 @@ void ImGui_KeyboardCallback(uSynergyCookie cookie, uint16_t key, // Add this as keyboard input - if ((down) && (key) && (scanCode<256) && !(modifiers & USYNERGY_MODIFIER_CTRL)) { - int charForKeycode = 0; - if (modifiers & USYNERGY_MODIFIER_SHIFT ) { - charForKeycode = g_keycodeCharShifted[ scanCode ]; - } else { - charForKeycode = g_keycodeCharUnshifted[ scanCode ]; - } - + if ((down) && (key) && (scanCode<256) && !(modifiers & USYNERGY_MODIFIER_CTRL)) + { // If this key maps to a character input, apply it + int charForKeycode = (modifiers & USYNERGY_MODIFIER_SHIFT) ? g_keycodeCharShifted[scanCode] : g_keycodeCharUnshifted[scanCode]; io.AddInputCharacter((unsigned short)charForKeycode); } @@ -499,8 +495,6 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat io.KeyMap[ImGuiKey_X] = kVK_ANSI_X+1; io.KeyMap[ImGuiKey_Y] = kVK_ANSI_Y+1; io.KeyMap[ImGuiKey_Z] = kVK_ANSI_Z+1; - - } - (void)connectServer: (NSString*)serverName @@ -620,9 +614,7 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat static void ImGui_ImplIOS_RenderDrawLists (ImDrawList** const cmd_lists, int cmd_lists_count) { if (cmd_lists_count == 0) - { return; - } // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled GLint last_program, last_texture; @@ -703,7 +695,6 @@ static void ImGui_ImplIOS_RenderDrawLists (ImDrawList** const cmd_lists, int cmd cmd_offset = vtx_offset; } - // Restore modified state glBindVertexArray(0); glEnable(GL_CULL_FACE); @@ -822,4 +813,3 @@ bool ImGui_ImplIOS_CreateDeviceObjects() return true; } -