History: iOS Input via UIView
Preview of version: 1
- «
- »
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 _startup ( int inputAreaX, int inputAreaY, int inputAreaWidth, int inputAreaHeight ); void _shutdown( void ); private: void * self; }; //////////////////////////////////////////////////////////////////////// #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) startup :(UIInputPimpl *)pimpl; - (void) shutdown; - (void) setEnabled:(BOOL)value; @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 ) { _shutdown(); } //////////////////////////////////////////////////////////////////////// void UIInputPimpl::_startup ( int inputAreaX, int inputAreaY, int inputAreaWidth, int inputAreaHeight ) { CGRect viewRect = CGRectMake( inputAreaX, inputAreaY, inputAreaWidth, inputAreaHeight ); self = [[iOS_UIInputImpl alloc] initWithFrame:viewRect]; [(id)self startup:this]; } //////////////////////////////////////////////////////////////////////// void UIInputPimpl::_shutdown( void ) { if ( self ) { [(id)self shutdown]; [(id)self dealloc]; self = NULL; } } //////////////////////////////////////////////////////////////////////// void UIInputPimpl::_setInputEnabled( bool value ) { [(id)self setEnabled:value]; } //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -(void) startup:(UIInputPimpl *)pimpl { _pimpl = pimpl; } //////////////////////////////////////////////////////////////////////// -(void) shutdown { _pimpl = NULL; } //////////////////////////////////////////////////////////////////////// - (void) setEnabled:(BOOL)value { if ( value ) { self.hidden = NO; } else { self.hidden = YES; } } //////////////////////////////////////////////////////////////////////// -(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 startup( void ); void shutdown( 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.h
Copy to clipboard
#include <Ogre.h> //////////////////////////////////////////////////////////////////////// UIInput::UIInput( void ) { } //////////////////////////////////////////////////////////////////////// UIInput::~UIInput( void ) { shutdown(); } //////////////////////////////////////////////////////////////////////// void UIInput::startup( void ) { _startup( 0, 0, 1024, 768 ); } //////////////////////////////////////////////////////////////////////// void UIInput::shutdown( void ) { _shutdown(); } //////////////////////////////////////////////////////////////////////// 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. }