ios keyboard stuff

This commit is contained in:
Vladislav Khorev 2013-07-15 18:44:22 +00:00
parent e9de663388
commit 9a27aacbab
10 changed files with 128 additions and 10 deletions

View File

@ -83,6 +83,8 @@
4CD41A2A16C2D23C0071E598 /* ViewControllerTemplate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CD41A2716C2D23C0071E598 /* ViewControllerTemplate.h */; };
4CD41A3116C2D2490071E598 /* GLKViewTemplate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CD41A2E16C2D2490071E598 /* GLKViewTemplate.mm */; };
4CD41A3216C2D2490071E598 /* ViewControllerTemplate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CD41A2F16C2D2490071E598 /* ViewControllerTemplate.mm */; };
4CDAB6F8176A60620075FC65 /* KeyboardWidget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CDAB6F7176A60620075FC65 /* KeyboardWidget.cpp */; };
4CDAB6FA176A60750075FC65 /* KeyboardWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CDAB6F9176A60750075FC65 /* KeyboardWidget.h */; };
4CEE2DD215CDC55B00C4D5F5 /* SalmonRenderGLES20.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CEE2DD115CDC55B00C4D5F5 /* SalmonRenderGLES20.h */; };
4CEE2DD515CDC57200C4D5F5 /* SalmonRenderGLES20.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2DD415CDC57200C4D5F5 /* SalmonRenderGLES20.cpp */; };
4CF8747916B65210009B1214 /* ButtonWidget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8747616B65210009B1214 /* ButtonWidget.cpp */; };
@ -178,6 +180,8 @@
4CD41A2716C2D23C0071E598 /* ViewControllerTemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewControllerTemplate.h; sourceTree = "<group>"; };
4CD41A2E16C2D2490071E598 /* GLKViewTemplate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GLKViewTemplate.mm; sourceTree = "<group>"; };
4CD41A2F16C2D2490071E598 /* ViewControllerTemplate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ViewControllerTemplate.mm; sourceTree = "<group>"; };
4CDAB6F7176A60620075FC65 /* KeyboardWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KeyboardWidget.cpp; path = ../../../src/GUIManager/KeyboardWidget.cpp; sourceTree = "<group>"; };
4CDAB6F9176A60750075FC65 /* KeyboardWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KeyboardWidget.h; path = ../../../include/GUIManager/KeyboardWidget.h; sourceTree = "<group>"; };
4CEE2DD115CDC55B00C4D5F5 /* SalmonRenderGLES20.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SalmonRenderGLES20.h; path = ../../../include/Render/SalmonRender/SalmonRenderGLES20.h; sourceTree = "<group>"; };
4CEE2DD415CDC57200C4D5F5 /* SalmonRenderGLES20.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SalmonRenderGLES20.cpp; path = ../../../src/Render/SalmonRender/SalmonRenderGLES20.cpp; sourceTree = "<group>"; };
4CF8747616B65210009B1214 /* ButtonWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ButtonWidget.cpp; path = ../../../src/GUIManager/ButtonWidget.cpp; sourceTree = "<group>"; };
@ -744,6 +748,7 @@
4CF8747416B65183009B1214 /* GUIManager */ = {
isa = PBXGroup;
children = (
4CDAB6F7176A60620075FC65 /* KeyboardWidget.cpp */,
4CF8747616B65210009B1214 /* ButtonWidget.cpp */,
4CF8747716B65210009B1214 /* GUIManager.cpp */,
4CF8747816B65210009B1214 /* WidgetXmlParsers.cpp */,
@ -770,6 +775,7 @@
4CF8748216B65249009B1214 /* GUIManager */ = {
isa = PBXGroup;
children = (
4CDAB6F9176A60750075FC65 /* KeyboardWidget.h */,
4CF8748716B652A4009B1214 /* ButtonWidget.h */,
4CF8748816B652A4009B1214 /* GUIManager.h */,
4CF8748916B652A4009B1214 /* WidgetTemplatesImpl.h */,
@ -834,6 +840,7 @@
4CD41A2A16C2D23C0071E598 /* ViewControllerTemplate.h in Headers */,
4C8024B516D4BD9F001A4521 /* Network.h in Headers */,
4C8024B616D4BD9F001A4521 /* SignalSender.h in Headers */,
4CDAB6FA176A60750075FC65 /* KeyboardWidget.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -928,6 +935,7 @@
4C8024BA16D4BDBC001A4521 /* Network.cpp in Sources */,
4C470853175405220069C707 /* JpegHelper.cpp in Sources */,
4C470854175405220069C707 /* TgaLoader.cpp in Sources */,
4CDAB6F8176A60620075FC65 /* KeyboardWidget.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -208,6 +208,8 @@ public:
virtual void OnTapDown(vec2 pos);
void SetText(const std::string& newText);
void OnSetAllText(std::string newText); //For iOS only
std::string GetText();
static TEdit* CreateEdit(vec2 posFrom, vec2 posTo);
static TEdit* CreateEditWithFiller(vec2 posFrom, vec2 posTo, boost::function<void(TEdit*)> fillerFunc);

View File

@ -142,6 +142,7 @@ protected:
public:
boost::signal<void(int)> KeyPressedSignal;
boost::signal<void(std::string)> SetTextSignal;
//boost::signal<void()> PostUpdateSignal;
TGUIManager();
@ -170,7 +171,7 @@ public:
void OnMove(vec2 shift);
void ShowKeyboard();
void ShowKeyboard(const std::string text = "");
void HideKeyboard();

View File

@ -21,6 +21,9 @@ std::string IosGetFileReadPath(const std::string& filename);
std::string IosGetFilePathUserData(const std::string& filename);
void IosSwitchToScreen();
void ShowKeyboard(std::string text);
void HideKeyboard();
} //namespace SE

View File

@ -9,8 +9,11 @@
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
@interface ViewControllerTemplate : GLKViewController
@interface ViewControllerTemplate : GLKViewController<UITextFieldDelegate>
{
}
@property (nonatomic, readonly) UITextField* hiddenTextField; //for keyboard
- (void) appInitCaller;

View File

@ -643,7 +643,8 @@ void TEdit::OnTapDown(vec2 pos)
}
ResourceManager->GUIManager.ShowKeyboard();
ResourceManager->GUIManager.ShowKeyboard(GetText());
ResourceManager->GUIManager.SetTextSignal.connect(boost::bind(&TEdit::OnSetAllText, this, _1));
}
void TEdit::OnKeyPress(int key)
@ -676,6 +677,22 @@ void TEdit::SetText(const std::string& newText)
RefreshTextTriangleList();
}
}
void TEdit::OnSetAllText(std::string newText)
{
if (newText != TextParams.Text)
{
TextParams.Text = newText;
RefreshTextTriangleList();
}
}
std::string TEdit::GetText()
{
return TextParams.Text;
}
//============================ Check Box ============================

View File

@ -7,6 +7,13 @@ namespace SE
const std::string CONST_HOLD_SIGNAL_NAME = "OnHold";
const std::string CONST_CLICK_SIGNAL_NAME = "OnClick";
const std::string CONST_DRAG_SIGNAL_NAME = "OnDrag";
void GuiManagerSetKeyboardText(std::string newText)
{
ResourceManager->GUIManager.SetTextSignal(newText);
}
TGUIManager::TGUIManager()
@ -371,23 +378,27 @@ void TGUIManager::OnMove(vec2 shift)
}
void TGUIManager::ShowKeyboard()
void TGUIManager::ShowKeyboard(const std::string text)
{
SE::ShowKeyboard(text);
/*
if (!KeyboardIsOnScreen)
{
MoveWidget("Keyboard", vec2(0, 216));
KeyboardIsOnScreen = true;
}
}*/
}
void TGUIManager::HideKeyboard()
{
ResourceManager->GUIManager.SetTextSignal.disconnect_all_slots();
/*
if (KeyboardIsOnScreen)
{
MoveWidget("Keyboard", vec2(0, -216));
KeyboardIsOnScreen = false;
}
}*/
}
void TGUIManager::PrintWidgetList()

View File

@ -8,11 +8,15 @@
#import <Foundation/Foundation.h>
#import <GLKit/GLKit.h>
#import <UIKit/UIKit.h>
#include "include/Utils/Utils.h"
GLKView* defaultView = 0; //Need to be set up by App!
UITextField* extKeyboardTextView = 0;
namespace SE
{
@ -58,6 +62,25 @@ void IosSwitchToScreen()
{
[defaultView bindDrawable];
}
void ShowKeyboard(std::string text)
{
extKeyboardTextView.text = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding];
[extKeyboardTextView becomeFirstResponder];
}
void HideKeyboard()
{
[extKeyboardTextView resignFirstResponder];
}
void GuiManagerSetKeyboardText(std::string newText); //Find it in GUIManager.cpp
void SetKeyboardText(const char* newText)
{
GuiManagerSetKeyboardText(newText);
NSLog(@"text: %s", newText);
}
} //namespace SE

View File

@ -9,6 +9,13 @@
#import "include/Utils/IosApi/ObjC/GLKViewTemplate.h"
#include "include/Utils/IosApi/IosWrapper.h"
#include <string>
namespace SE
{
void ShowKeyboard(std::string text);
}
@implementation GLKViewTemplate
- (id)initWithFrame:(CGRect)frame
@ -16,7 +23,6 @@
self = [super initWithFrame:frame];
if (self)
{
touchMoved = false;
}
@ -66,6 +72,4 @@
}
@end

View File

@ -12,6 +12,15 @@
extern GLKView* defaultView; //Find this in IosApi.mm
extern UITextField* extKeyboardTextView; //Find this in IosApi.mm
namespace SE
{
void SetKeyboardText(const char* newText);
}
@interface ViewControllerTemplate () {
}
@ -28,6 +37,8 @@ extern GLKView* defaultView; //Find this in IosApi.mm
@synthesize context = _context;
@synthesize effect = _effect;
@synthesize hiddenTextField = _hiddenTextField;
- (void)viewDidLoad
{
@ -55,6 +66,19 @@ extern GLKView* defaultView; //Find this in IosApi.mm
initWithTarget:self action:@selector(respondToPinch:)];
[self.view addGestureRecognizer:recognizer];
//Keyboard
_hiddenTextField = [[UITextField alloc] initWithFrame:CGRectMake(-200,-200,0,0)];
[self.view addSubview:_hiddenTextField];
extKeyboardTextView = _hiddenTextField;
_hiddenTextField.delegate = self;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReceiveKeyboardNotification:) name:UITextFieldTextDidChangeNotification object:nil];
}
- (void)viewDidUnload
@ -67,6 +91,8 @@ extern GLKView* defaultView; //Find this in IosApi.mm
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
_hiddenTextField = nil;
}
- (void)didReceiveMemoryWarning
@ -99,6 +125,26 @@ extern GLKView* defaultView; //Find this in IosApi.mm
SE::AppOnScale(gestureRecognizer.scale);
}
- (void) onReceiveKeyboardNotification:(NSNotification*) notification
{
if (notification.name == UITextFieldTextDidChangeNotification)
{
UITextField* textField = notification.object;
const char* text = [[textField text] UTF8String];
SE::SetKeyboardText(text);
}
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"Begin");
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSLog(@"End");
}
#pragma mark - GLKView and GLKViewController delegate methods
@ -115,5 +161,5 @@ extern GLKView* defaultView; //Find this in IosApi.mm
}
@end