mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-19 22:36:35 +00:00
Examples: iOS: Fixed missing call to CreateContext() + various shallow coding style tweaks. (#1835)
This commit is contained in:
parent
b88fbd69cc
commit
5fd23eeb74
@ -8,11 +8,9 @@
|
|||||||
#import "imgui_impl_ios.h"
|
#import "imgui_impl_ios.h"
|
||||||
#import "debug_hud.h"
|
#import "debug_hud.h"
|
||||||
|
|
||||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||||
|
#define SERVERNAME_KEY @"ServerName"
|
||||||
#define SERVERNAME_KEY @"ServerName"
|
#define SERVERNAME_ALERT_TAG 10
|
||||||
|
|
||||||
#define SERVERNAME_ALERT_TAG (10)
|
|
||||||
|
|
||||||
// Uniform index.
|
// Uniform index.
|
||||||
enum
|
enum
|
||||||
@ -20,85 +18,80 @@ enum
|
|||||||
UNIFORM_MODELVIEWPROJECTION_MATRIX,
|
UNIFORM_MODELVIEWPROJECTION_MATRIX,
|
||||||
UNIFORM_NORMAL_MATRIX,
|
UNIFORM_NORMAL_MATRIX,
|
||||||
UNIFORM_DIFFUSE_COLOR,
|
UNIFORM_DIFFUSE_COLOR,
|
||||||
|
UNIFORM_COUNT_
|
||||||
NUM_UNIFORMS
|
|
||||||
};
|
};
|
||||||
GLint uniforms[NUM_UNIFORMS];
|
static GLint uniforms[UNIFORM_COUNT_];
|
||||||
|
|
||||||
// Attribute index.
|
// Attribute index.
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ATTRIB_VERTEX,
|
ATTRIB_VERTEX,
|
||||||
ATTRIB_NORMAL,
|
ATTRIB_NORMAL,
|
||||||
NUM_ATTRIBUTES
|
ATTRIB_COUNT_
|
||||||
};
|
};
|
||||||
|
|
||||||
GLfloat gCubeVertexData[216] =
|
static const GLfloat gCubeVertexData[216] =
|
||||||
{
|
{
|
||||||
// Data layout for each line below is:
|
// Data layout for each line below is:
|
||||||
// positionX, positionY,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f, 1.0f,
|
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
|
|
||||||
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f
|
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
@interface GameViewController () <UIAlertViewDelegate>
|
@interface GameViewController () <UIAlertViewDelegate>
|
||||||
{
|
{
|
||||||
GLuint _program;
|
GLuint _program;
|
||||||
|
GLKMatrix4 _modelViewProjectionMatrix;
|
||||||
GLKMatrix4 _modelViewProjectionMatrix;
|
GLKMatrix3 _normalMatrix;
|
||||||
GLKMatrix3 _normalMatrix;
|
float _rotation;
|
||||||
float _rotation;
|
GLuint _vertexArray;
|
||||||
|
GLuint _vertexBuffer;
|
||||||
GLuint _vertexArray;
|
DebugHUD _hud;
|
||||||
GLuint _vertexBuffer;
|
|
||||||
|
|
||||||
DebugHUD _hud;
|
|
||||||
}
|
}
|
||||||
@property (strong, nonatomic) EAGLContext *context;
|
@property (strong, nonatomic) EAGLContext* context;
|
||||||
@property (strong, nonatomic) GLKBaseEffect *effect;
|
@property (strong, nonatomic) GLKBaseEffect* effect;
|
||||||
@property (strong, nonatomic) ImGuiHelper *imgui;
|
@property (strong, nonatomic) ImGuiHelper* imgui;
|
||||||
@property (weak, nonatomic) IBOutlet UIButton *btnServername;
|
@property (weak, nonatomic) IBOutlet UIButton* btnServername;
|
||||||
|
@property (strong, nonatomic) NSString* serverName;
|
||||||
@property (strong, nonatomic) NSString *serverName;
|
|
||||||
|
|
||||||
- (IBAction)onServernameTapped:(id)sender;
|
- (IBAction)onServernameTapped:(id)sender;
|
||||||
|
|
||||||
@ -106,7 +99,7 @@ GLfloat gCubeVertexData[216] =
|
|||||||
- (void)tearDownGL;
|
- (void)tearDownGL;
|
||||||
|
|
||||||
- (BOOL)loadShaders;
|
- (BOOL)loadShaders;
|
||||||
- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file;
|
- (BOOL)compileShader:(GLuint*)shader type:(GLenum)type file:(NSString*)file;
|
||||||
- (BOOL)linkProgram:(GLuint)prog;
|
- (BOOL)linkProgram:(GLuint)prog;
|
||||||
- (BOOL)validateProgram:(GLuint)prog;
|
- (BOOL)validateProgram:(GLuint)prog;
|
||||||
@end
|
@end
|
||||||
@ -119,9 +112,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
|
|
||||||
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||||
|
|
||||||
if (!self.context) {
|
if (!self.context)
|
||||||
NSLog(@"Failed to create ES context");
|
NSLog(@"Failed to create ES context");
|
||||||
}
|
|
||||||
|
|
||||||
GLKView *view = (GLKView *)self.view;
|
GLKView *view = (GLKView *)self.view;
|
||||||
view.context = self.context;
|
view.context = self.context;
|
||||||
@ -140,30 +132,29 @@ GLfloat gCubeVertexData[216] =
|
|||||||
[self.imgui connectServer: self.serverName ];
|
[self.imgui connectServer: self.serverName ];
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugHUD_InitDefaults( &_hud );
|
DebugHUD_InitDefaults(&_hud);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
[self tearDownGL];
|
[self tearDownGL];
|
||||||
|
|
||||||
if ([EAGLContext currentContext] == self.context) {
|
if ([EAGLContext currentContext] == self.context)
|
||||||
[EAGLContext setCurrentContext:nil];
|
[EAGLContext setCurrentContext:nil];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didReceiveMemoryWarning
|
- (void)didReceiveMemoryWarning
|
||||||
{
|
{
|
||||||
[super didReceiveMemoryWarning];
|
[super didReceiveMemoryWarning];
|
||||||
|
|
||||||
if ([self isViewLoaded] && ([[self view] window] == nil)) {
|
if ([self isViewLoaded] && ([[self view] window] == nil))
|
||||||
|
{
|
||||||
self.view = nil;
|
self.view = nil;
|
||||||
|
|
||||||
[self tearDownGL];
|
[self tearDownGL];
|
||||||
|
|
||||||
if ([EAGLContext currentContext] == self.context) {
|
if ([EAGLContext currentContext] == self.context)
|
||||||
[EAGLContext setCurrentContext:nil];
|
[EAGLContext setCurrentContext:nil];
|
||||||
}
|
|
||||||
self.context = nil;
|
self.context = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +162,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)prefersStatusBarHidden {
|
- (BOOL)prefersStatusBarHidden
|
||||||
|
{
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +177,7 @@ GLfloat gCubeVertexData[216] =
|
|||||||
|
|
||||||
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
|
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
|
||||||
{
|
{
|
||||||
if ((buttonIndex==0)&&(alertView.tag==SERVERNAME_ALERT_TAG))
|
if ((buttonIndex==0) && (alertView.tag == SERVERNAME_ALERT_TAG))
|
||||||
{
|
{
|
||||||
// This is really janky. I usually just hardcode the servername since I'm building it anyway.
|
// This is really janky. I usually just hardcode the servername since I'm building it anyway.
|
||||||
// If you want to properly handle updating the server, you'll want to tear down and recreate
|
// If you want to properly handle updating the server, you'll want to tear down and recreate
|
||||||
@ -193,7 +185,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
BOOL serverNameWasSet = self.serverName.length > 0;
|
BOOL serverNameWasSet = self.serverName.length > 0;
|
||||||
NSString *serverName = [[alertView textFieldAtIndex:0] text];
|
NSString *serverName = [[alertView textFieldAtIndex:0] text];
|
||||||
|
|
||||||
if ([serverName length] > 0) {
|
if ([serverName length] > 0)
|
||||||
|
{
|
||||||
self.serverName = serverName;
|
self.serverName = serverName;
|
||||||
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
||||||
[userDefaults setObject:serverName forKey:SERVERNAME_KEY ];
|
[userDefaults setObject:serverName forKey:SERVERNAME_KEY ];
|
||||||
@ -202,7 +195,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
[self.btnServername setTitle:self.serverName forState:UIControlStateNormal];
|
[self.btnServername setTitle:self.serverName forState:UIControlStateNormal];
|
||||||
|
|
||||||
// If we hadn't previously connected, try now
|
// If we hadn't previously connected, try now
|
||||||
if (!serverNameWasSet) {
|
if (!serverNameWasSet)
|
||||||
|
{
|
||||||
[self.imgui connectServer:self.serverName];
|
[self.imgui connectServer:self.serverName];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -241,8 +235,6 @@ GLfloat gCubeVertexData[216] =
|
|||||||
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));
|
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));
|
||||||
|
|
||||||
glBindVertexArrayOES(0);
|
glBindVertexArrayOES(0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tearDownGL
|
- (void)tearDownGL
|
||||||
@ -254,7 +246,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
|
|
||||||
self.effect = nil;
|
self.effect = nil;
|
||||||
|
|
||||||
if (_program) {
|
if (_program)
|
||||||
|
{
|
||||||
glDeleteProgram(_program);
|
glDeleteProgram(_program);
|
||||||
_program = 0;
|
_program = 0;
|
||||||
}
|
}
|
||||||
@ -285,9 +278,7 @@ GLfloat gCubeVertexData[216] =
|
|||||||
modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix);
|
modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix);
|
||||||
|
|
||||||
_normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL);
|
_normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL);
|
||||||
|
|
||||||
_modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix);
|
_modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix);
|
||||||
|
|
||||||
_rotation += self.timeSinceLastUpdate * (_hud.rotation_speed * (M_PI / 180.0));
|
_rotation += self.timeSinceLastUpdate * (_hud.rotation_speed * (M_PI / 180.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +350,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
glBindAttribLocation(_program, GLKVertexAttribNormal, "normal");
|
glBindAttribLocation(_program, GLKVertexAttribNormal, "normal");
|
||||||
|
|
||||||
// Link program.
|
// Link program.
|
||||||
if (![self linkProgram:_program]) {
|
if (![self linkProgram:_program])
|
||||||
|
{
|
||||||
NSLog(@"Failed to link program: %d", _program);
|
NSLog(@"Failed to link program: %d", _program);
|
||||||
|
|
||||||
if (vertShader) {
|
if (vertShader) {
|
||||||
@ -384,11 +376,13 @@ GLfloat gCubeVertexData[216] =
|
|||||||
uniforms[UNIFORM_DIFFUSE_COLOR] = glGetUniformLocation(_program, "diffuseColor");
|
uniforms[UNIFORM_DIFFUSE_COLOR] = glGetUniformLocation(_program, "diffuseColor");
|
||||||
|
|
||||||
// Release vertex and fragment shaders.
|
// Release vertex and fragment shaders.
|
||||||
if (vertShader) {
|
if (vertShader)
|
||||||
|
{
|
||||||
glDetachShader(_program, vertShader);
|
glDetachShader(_program, vertShader);
|
||||||
glDeleteShader(vertShader);
|
glDeleteShader(vertShader);
|
||||||
}
|
}
|
||||||
if (fragShader) {
|
if (fragShader)
|
||||||
|
{
|
||||||
glDetachShader(_program, fragShader);
|
glDetachShader(_program, fragShader);
|
||||||
glDeleteShader(fragShader);
|
glDeleteShader(fragShader);
|
||||||
}
|
}
|
||||||
@ -402,7 +396,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
const GLchar *source;
|
const GLchar *source;
|
||||||
|
|
||||||
source = (GLchar *)[[NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil] UTF8String];
|
source = (GLchar *)[[NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil] UTF8String];
|
||||||
if (!source) {
|
if (!source)
|
||||||
|
{
|
||||||
NSLog(@"Failed to load vertex shader");
|
NSLog(@"Failed to load vertex shader");
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@ -423,7 +418,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
glGetShaderiv(*shader, GL_COMPILE_STATUS, &status);
|
glGetShaderiv(*shader, GL_COMPILE_STATUS, &status);
|
||||||
if (status == 0) {
|
if (status == 0)
|
||||||
|
{
|
||||||
glDeleteShader(*shader);
|
glDeleteShader(*shader);
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@ -439,7 +435,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
GLint logLength;
|
GLint logLength;
|
||||||
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
|
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
|
||||||
if (logLength > 0) {
|
if (logLength > 0)
|
||||||
|
{
|
||||||
GLchar *log = (GLchar *)malloc(logLength);
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
glGetProgramInfoLog(prog, logLength, &logLength, log);
|
glGetProgramInfoLog(prog, logLength, &logLength, log);
|
||||||
NSLog(@"Program link log:\n%s", log);
|
NSLog(@"Program link log:\n%s", log);
|
||||||
@ -448,10 +445,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
glGetProgramiv(prog, GL_LINK_STATUS, &status);
|
glGetProgramiv(prog, GL_LINK_STATUS, &status);
|
||||||
if (status == 0) {
|
if (status == 0)
|
||||||
return NO;
|
return NO;
|
||||||
}
|
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,10 +464,8 @@ GLfloat gCubeVertexData[216] =
|
|||||||
}
|
}
|
||||||
|
|
||||||
glGetProgramiv(prog, GL_VALIDATE_STATUS, &status);
|
glGetProgramiv(prog, GL_VALIDATE_STATUS, &status);
|
||||||
if (status == 0) {
|
if (status == 0)
|
||||||
return NO;
|
return NO;
|
||||||
}
|
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
|
|
||||||
typedef struct DebugHUD
|
typedef struct DebugHUD
|
||||||
{
|
{
|
||||||
bool show_demo_window;
|
bool show_demo_window;
|
||||||
bool show_another_window;
|
bool show_another_window;
|
||||||
float rotation_speed;
|
float rotation_speed;
|
||||||
float cubeColor1[4];
|
float cubeColor1[4];
|
||||||
float cubeColor2[4];
|
float cubeColor2[4];
|
||||||
float clearColor[4];
|
float clearColor[4];
|
||||||
} DebugHUD;
|
} DebugHUD;
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
@ -278,7 +278,6 @@ void ImGui_KeyboardCallback(uSynergyCookie cookie, uint16_t key,
|
|||||||
int charForKeycode = (modifiers & USYNERGY_MODIFIER_SHIFT) ? g_keycodeCharShifted[scanCode] : g_keycodeCharUnshifted[scanCode];
|
int charForKeycode = (modifiers & USYNERGY_MODIFIER_SHIFT) ? g_keycodeCharShifted[scanCode] : g_keycodeCharUnshifted[scanCode];
|
||||||
io.AddInputCharacter((unsigned short)charForKeycode);
|
io.AddInputCharacter((unsigned short)charForKeycode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_JoystickCallback(uSynergyCookie cookie, uint8_t joyNum, uint16_t buttons, int8_t leftStickX, int8_t leftStickY, int8_t rightStickX, int8_t rightStickY)
|
void ImGui_JoystickCallback(uSynergyCookie cookie, uint8_t joyNum, uint16_t buttons, int8_t leftStickX, int8_t leftStickY, int8_t rightStickX, int8_t rightStickY)
|
||||||
@ -461,14 +460,15 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat
|
|||||||
|
|
||||||
- (void)setupImGuiHooks
|
- (void)setupImGuiHooks
|
||||||
{
|
{
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
[self setupKeymaps];
|
[self setupKeymaps];
|
||||||
|
|
||||||
// Account for retina display for glScissor
|
// Account for retina display for glScissor
|
||||||
g_displayScale = [[UIScreen mainScreen] scale];
|
g_displayScale = [[UIScreen mainScreen] scale];
|
||||||
|
|
||||||
ImGuiStyle &style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
style.TouchExtraPadding = ImVec2( 4.0, 4.0 );
|
style.TouchExtraPadding = ImVec2( 4.0, 4.0 );
|
||||||
|
|
||||||
io.RenderDrawListsFn = ImGui_ImplIOS_RenderDrawLists;
|
io.RenderDrawListsFn = ImGui_ImplIOS_RenderDrawLists;
|
||||||
@ -532,9 +532,8 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat
|
|||||||
// Create a background thread for synergy
|
// Create a background thread for synergy
|
||||||
_synergyQueue = dispatch_queue_create( "imgui-usynergy", NULL );
|
_synergyQueue = dispatch_queue_create( "imgui-usynergy", NULL );
|
||||||
dispatch_async( _synergyQueue, ^{
|
dispatch_async( _synergyQueue, ^{
|
||||||
while (1) {
|
while (1)
|
||||||
uSynergyUpdate( &_synergyCtx );
|
uSynergyUpdate(&_synergyCtx);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -569,24 +568,20 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat
|
|||||||
- (void)newFrame
|
- (void)newFrame
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
ImGuiStyle &style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
|
|
||||||
if (!g_FontTexture)
|
if (!g_FontTexture)
|
||||||
{
|
|
||||||
ImGui_ImplIOS_CreateDeviceObjects();
|
ImGui_ImplIOS_CreateDeviceObjects();
|
||||||
}
|
|
||||||
|
|
||||||
io.DisplaySize = ImVec2( _view.bounds.size.width, _view.bounds.size.height );
|
io.DisplaySize = ImVec2(_view.bounds.size.width, _view.bounds.size.height);
|
||||||
|
|
||||||
io.MouseDrawCursor = g_synergyPtrActive;
|
io.MouseDrawCursor = g_synergyPtrActive;
|
||||||
if (g_synergyPtrActive)
|
if (g_synergyPtrActive)
|
||||||
{
|
{
|
||||||
style.TouchExtraPadding = ImVec2( 0.0, 0.0 );
|
style.TouchExtraPadding = ImVec2(0.0, 0.0);
|
||||||
io.MousePos = ImVec2( g_mousePosX, g_mousePosY );
|
io.MousePos = ImVec2(g_mousePosX, g_mousePosY);
|
||||||
for (int i=0; i < 3; i++)
|
for (int i=0; i < 3; i++)
|
||||||
{
|
|
||||||
io.MouseDown[i] = g_MousePressed[i];
|
io.MouseDown[i] = g_MousePressed[i];
|
||||||
}
|
|
||||||
|
|
||||||
// This is an arbitrary scaling factor that works for me. Not sure what units these mousewheel values from synergy are supposed to be in.
|
// This is an arbitrary scaling factor that works for me. Not sure what units these mousewheel values from synergy are supposed to be in.
|
||||||
io.MouseWheel = g_mouseWheelY / 500.0;
|
io.MouseWheel = g_mouseWheelY / 500.0;
|
||||||
@ -595,8 +590,8 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Synergy not active, use touch events
|
// Synergy not active, use touch events
|
||||||
style.TouchExtraPadding = ImVec2( 4.0, 4.0 );
|
style.TouchExtraPadding = ImVec2(4.0, 4.0);
|
||||||
io.MousePos = ImVec2(_touchPos.x, _touchPos.y );
|
io.MousePos = ImVec2(_touchPos.x, _touchPos.y);
|
||||||
if ((_mouseDown) || (_mouseTapped))
|
if ((_mouseDown) || (_mouseTapped))
|
||||||
{
|
{
|
||||||
io.MouseDown[0] = true;
|
io.MouseDown[0] = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user