History: iOS Input via UIView
Preview of version: 2
UIInputPimpl.h
Copy to clipboard
#ifndef UIInputPimpl_h #define UIInputPimpl_h class UIInputPimpl { public: UIInputPimpl ( void ); virtual ~UIInputPimpl( void ); void _setInputEnabled( bool value ); virtual void _notifyTouchBegan( float absX, float absY ) = 0; virtual void _notifyTouchMoved( float absX, float absY, float relX, float relY ) = 0; virtual void _notifyTouchEnded( float absX, float absY ) = 0; virtual void _notifyTouchCancelled( float absX, float absY ) = 0; protected: void _init( int inputAreaX, int inputAreaY, int inputAreaWidth, int inputAreaHeight ); private: void * self; void * window; }; //////////////////////////////////////////////////////////////////////// #endif
iOS_UIInputImpl.h
Copy to clipboard
#ifndef iOS_UIInputImpl_h #define iOS_UIInputImpl_h #import "UIInputPimpl.h" #import <UIKit/UIKit.h> //////////////////////////////////////////////////////////////////////// @interface iOS_UIInputImpl : UIView { UIInputPimpl * _pimpl; } - (void) setPimpl :(UIInputPimpl *)pimpl; @end //////////////////////////////////////////////////////////////////////// #endif
iOS_UIInputImpl.mm
Copy to clipboard
#import "UIInputPimpl.h" #import "iOS_UIInputImpl.h" //////////////////////////////////////////////////////////////////////// // PRIVATE METHODS @interface iOS_UIInputImpl() @end //////////////////////////////////////////////////////////////////////// @implementation iOS_UIInputImpl //////////////////////////////////////////////////////////////////////// UIInputPimpl::UIInputPimpl( void ) : self( NULL ) { } //////////////////////////////////////////////////////////////////////// UIInputPimpl::~UIInputPimpl( void ) { if ( self ) { [(id)self removeFromSuperview]; } if ( window ) { [(id)window dealloc]; } if ( self ) { [(id)self dealloc]; self = NULL; } } //////////////////////////////////////////////////////////////////////// void UIInputPimpl::_init ( int inputAreaX, int inputAreaY, int inputAreaWidth, int inputAreaHeight ) { CGRect viewRect = CGRectMake( inputAreaX, inputAreaY, inputAreaWidth, inputAreaHeight ); self = [[iOS_UIInputImpl alloc] initWithFrame:viewRect]; window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; ((UIWindow*)window).windowLevel = UIWindowLevelStatusBar; ((UIWindow*)window).hidden = NO; ((UIWindow*)window).backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.0]; [(id)window makeKeyAndVisible]; [(id)window addSubview:(UIView*)self]; [(id)self setPimpl:this]; } //////////////////////////////////////////////////////////////////////// void UIInputPimpl::_setInputEnabled( bool value ) { ((UIView*)self).userInteractionEnabled = value; } //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -(void) setPimpl:(UIInputPimpl *)pimpl { _pimpl = pimpl; } //////////////////////////////////////////////////////////////////////// -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for ( UITouch * touch in touches ) { CGPoint p = [touch locationInView:self]; _pimpl->_notifyTouchBegan( p.x, p.y ); } } //////////////////////////////////////////////////////////////////////// -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { for ( UITouch * touch in touches ) { CGPoint p0 = [touch previousLocationInView:self]; CGPoint p1 = [touch locationInView:self]; _pimpl->_notifyTouchMoved( p1.x, p1.y, p1.x - p0.x, p1.y - p0.y ); } } //////////////////////////////////////////////////////////////////////// -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { for ( UITouch * touch in touches ) { CGPoint p = [touch locationInView:self]; _pimpl->_notifyTouchEnded( p.x, p.y ); } } //////////////////////////////////////////////////////////////////////// -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { for ( UITouch * touch in touches ) { CGPoint p = [touch locationInView:self]; _pimpl->_notifyTouchCancelled( p.x, p.y ); } } //////////////////////////////////////////////////////////////////////// - (void) dealloc { [super dealloc]; } @end
UIInput.h
Copy to clipboard
#ifndef UIInput_h #define UIInput_h #include "UIInputPimpl.h" class UIInput : private UIInputPimpl { public: UIInput( void ); virtual ~UIInput( void ); void setInputEnabled( bool value ); virtual void _notifyTouchBegan( float absX, float absY ); virtual void _notifyTouchMoved( float absX, float absY, float relX, float relY ); virtual void _notifyTouchEnded( float absX, float absY ); virtual void _notifyTouchCancelled( float absX, float absY ); }; //////////////////////////////////////////////////////////////////////// #endif
UIInput.cpp
Copy to clipboard
#include <Ogre.h> //////////////////////////////////////////////////////////////////////// UIInput::UIInput( void ) { _init( 0, 0, 1024, 768 ); } //////////////////////////////////////////////////////////////////////// UIInput::~UIInput( void ) { } //////////////////////////////////////////////////////////////////////// void UIInput::setInputEnabled( bool value ) { _setInputEnabled( value ); } //////////////////////////////////////////////////////////////////////// void UIInput::_notifyTouchBegan( float absX, float absY ) { // Dispatch event or handle internally. } //////////////////////////////////////////////////////////////////////// void UIInput::_notifyTouchMoved( float absX, float absY, float relX, float relY ) { // Dispatch event or handle internally. } //////////////////////////////////////////////////////////////////////// void UIInput::_notifyTouchEnded( float absX, float absY ) { // Dispatch event or handle internally. } //////////////////////////////////////////////////////////////////////// void UIInput::_notifyTouchCancelled( float absX, float absY ) { // Dispatch event or handle internally. }