iOS example: shallow tweaks and fixes (untested)

docking
ocornut 9 years ago
parent eee6dab226
commit fb27360ea8

@ -11,7 +11,7 @@ opengl_example/
Prefer following this example since it is the shortest one! Prefer following this example since it is the shortest one!
opengl3_example/ opengl3_example/
OpenGL exemple, using GLFW/GL3W + programmable pipeline. OpenGL example, using GLFW/GL3W + programmable pipeline.
This uses more modern calls and custom shaders. 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. 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. DirectX11 example, Windows only.
This is quite long and tedious, because: DirectX11. 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.

@ -3,9 +3,9 @@
---- ----
## Introduction ## 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 ## How to Use
---- ----
@ -28,8 +28,8 @@ Things that would be nice but I didn't get around to doing:
---- ----
## C++ on iOS ## 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. 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.

@ -2,8 +2,7 @@
// GameViewController.h // GameViewController.h
// imguiex // imguiex
// This is the OpenGL Example template from XCode, modified to // This is the OpenGL Example template from XCode, modified to support ImGui
// support IMGUI
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <GLKit/GLKit.h> #import <GLKit/GLKit.h>

@ -9,20 +9,19 @@
void DebugHUD_InitDefaults( DebugHUD *hud ) void DebugHUD_InitDefaults( DebugHUD *hud )
{ {
hud->show_test_window = 1; hud->show_test_window = true;
hud->show_example_window = 1; hud->show_example_window = true;
hud->rotation_speed = 15.0; hud->rotation_speed = 15.0f;
hud->cubeColor1[0] = 0.4; hud->cubeColor1[0] = 0.4f;
hud->cubeColor1[1] = 0.4; hud->cubeColor1[1] = 0.4f;
hud->cubeColor1[2] = 1.0; hud->cubeColor1[2] = 1.0f;
hud->cubeColor1[3] = 1.0; hud->cubeColor1[3] = 1.0f;
hud->cubeColor2[0] = 1.0;
hud->cubeColor2[1] = 0.4;
hud->cubeColor2[2] = 0.4;
hud->cubeColor2[3] = 1.0;
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 ) void DebugHUD_DoInterface( DebugHUD *hud )
@ -30,24 +29,17 @@ void DebugHUD_DoInterface( DebugHUD *hud )
if (hud->show_test_window) if (hud->show_test_window)
{ {
ImGui::SetNextWindowPos( ImVec2( 400, 20 ), ImGuiSetCond_FirstUseEver ); ImGui::SetNextWindowPos( ImVec2( 400, 20 ), ImGuiSetCond_FirstUseEver );
bool show_test_window = hud->show_test_window; ImGui::ShowTestWindow( &hud->show_test_window );
ImGui::ShowTestWindow( &show_test_window );
hud->show_test_window = show_test_window;
} }
if (hud->show_example_window) if (hud->show_example_window)
{ {
bool show_window = hud->show_example_window;
ImGui::SetNextWindowPos( ImVec2( 20, 20 ), ImGuiSetCond_FirstUseEver ); ImGui::SetNextWindowPos( ImVec2( 20, 20 ), ImGuiSetCond_FirstUseEver );
ImGui::SetNextWindowSize( ImVec2( 350, 200 ), ImGuiSetCond_FirstUseEver ); ImGui::SetNextWindowSize( ImVec2( 350, 200 ), ImGuiSetCond_FirstUseEver );
ImGui::Begin("Another Window", &show_window); ImGui::Begin("Another Window", &hud->show_example_window);
hud->show_example_window = show_window;
ImGui::ColorEdit3("Cube 1 Color", hud->cubeColor1); ImGui::ColorEdit3("Cube 1 Color", hud->cubeColor1);
ImGui::ColorEdit3("Cube 2 Color", hud->cubeColor2); 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(); ImGui::End();
} }
}
}

@ -2,13 +2,12 @@
// debug_hud.h // debug_hud.h
// imguiex // imguiex
#ifndef __imguiex__debug_hud__ #pragma once
#define __imguiex__debug_hud__
typedef struct DebugHUD typedef struct DebugHUD
{ {
int show_test_window; bool show_test_window;
int show_example_window; bool show_example_window;
float rotation_speed; float rotation_speed;
float cubeColor1[4]; float cubeColor1[4];
float cubeColor2[4]; float cubeColor2[4];
@ -24,5 +23,3 @@ void DebugHUD_DoInterface( DebugHUD *hud );
#if __cplusplus #if __cplusplus
} }
#endif #endif
#endif /* defined(__imguiex__debug_hud__) */

@ -5,8 +5,7 @@
// Joel Davis (joeld42@gmail.com) // Joel Davis (joeld42@gmail.com)
// //
#ifndef __imguiex__imgui_impl_ios__ #pragma once
#define __imguiex__imgui_impl_ios__
#include <Foundation/Foundation.h> #include <Foundation/Foundation.h>
#include <UIKit/UIKit.h> #include <UIKit/UIKit.h>
@ -21,6 +20,3 @@
- (void)newFrame; - (void)newFrame;
@end @end
#endif /* defined(__imguiex__imgui_impl_ios__) */

@ -16,6 +16,7 @@
#include "uSynergy.h" #include "uSynergy.h"
// From Carbon HIToolbox/Events.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 { enum {
kVK_ANSI_A = 0x00, kVK_ANSI_A = 0x00,
kVK_ANSI_S = 0x01, kVK_ANSI_S = 0x01,
@ -267,15 +268,10 @@ void ImGui_KeyboardCallback(uSynergyCookie cookie, uint16_t key,
// Add this as keyboard input // Add this as keyboard input
if ((down) && (key) && (scanCode<256) && !(modifiers & USYNERGY_MODIFIER_CTRL)) { 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 this key maps to a character input, apply it // 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); 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_X] = kVK_ANSI_X+1;
io.KeyMap[ImGuiKey_Y] = kVK_ANSI_Y+1; io.KeyMap[ImGuiKey_Y] = kVK_ANSI_Y+1;
io.KeyMap[ImGuiKey_Z] = kVK_ANSI_Z+1; io.KeyMap[ImGuiKey_Z] = kVK_ANSI_Z+1;
} }
- (void)connectServer: (NSString*)serverName - (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) static void ImGui_ImplIOS_RenderDrawLists (ImDrawList** const cmd_lists, int cmd_lists_count)
{ {
if (cmd_lists_count == 0) if (cmd_lists_count == 0)
{
return; return;
}
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
GLint last_program, last_texture; GLint last_program, last_texture;
@ -703,7 +695,6 @@ static void ImGui_ImplIOS_RenderDrawLists (ImDrawList** const cmd_lists, int cmd
cmd_offset = vtx_offset; cmd_offset = vtx_offset;
} }
// Restore modified state // Restore modified state
glBindVertexArray(0); glBindVertexArray(0);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
@ -822,4 +813,3 @@ bool ImGui_ImplIOS_CreateDeviceObjects()
return true; return true;
} }

Loading…
Cancel
Save