[ios] tests add RootViewController for rotate with ui object.

This commit is contained in:
yangws 2011-04-28 14:19:12 +08:00
parent 323c065934
commit d73699aabb
9 changed files with 161 additions and 38 deletions

View File

@ -96,6 +96,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
CFMutableDictionaryRef touchesIntergerDict; CFMutableDictionaryRef touchesIntergerDict;
unsigned int indexBitsUsed; unsigned int indexBitsUsed;
NSString * markedText_; NSString * markedText_;
CGRect caretRect_;
} }
@property(nonatomic, readonly) UITextPosition *beginningOfDocument; @property(nonatomic, readonly) UITextPosition *beginningOfDocument;

View File

@ -696,7 +696,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
- (CGRect)caretRectForPosition:(UITextPosition *)position; - (CGRect)caretRectForPosition:(UITextPosition *)position;
{ {
CCLOG("caretRectForPosition"); CCLOG("caretRectForPosition");
return CGRectMake(0, 0, 0, 0); return caretRect_;
} }
#pragma mark Hit testing #pragma mark Hit testing
@ -756,13 +756,16 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
tmp = end.size.width; tmp = end.size.width;
end.size.width = end.size.height; end.size.width = end.size.height;
end.size.height = tmp; end.size.height = tmp;
tmp = viewSize.width;
viewSize.width = viewSize.height;
viewSize.height = tmp;
tmp = begin.origin.x; tmp = begin.origin.x;
begin.origin.x = begin.origin.y; begin.origin.x = begin.origin.y;
begin.origin.y = viewSize.width - tmp - begin.size.height; begin.origin.y = viewSize.height - tmp - begin.size.height;
tmp = end.origin.x; tmp = end.origin.x;
end.origin.x = end.origin.y; end.origin.x = end.origin.y;
end.origin.y = viewSize.width - tmp - end.size.height; end.origin.y = viewSize.height - tmp - end.size.height;
break; break;
case UIInterfaceOrientationLandscapeRight: case UIInterfaceOrientationLandscapeRight:
@ -772,6 +775,9 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
tmp = end.size.width; tmp = end.size.width;
end.size.width = end.size.height; end.size.width = end.size.height;
end.size.height = tmp; end.size.height = tmp;
tmp = viewSize.width;
viewSize.width = viewSize.height;
viewSize.height = tmp;
tmp = begin.origin.x; tmp = begin.origin.x;
begin.origin.x = begin.origin.y; begin.origin.x = begin.origin.y;
@ -802,6 +808,9 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
else if (UIKeyboardDidShowNotification == type) else if (UIKeyboardDidShowNotification == type)
{ {
dispatcher->dispatchKeyboardDidShow(notiInfo); dispatcher->dispatchKeyboardDidShow(notiInfo);
caretRect_ = end;
caretRect_.origin.y = caretRect_.origin.y + caretRect_.size.height;
caretRect_.size.height = 0;
} }
else if (UIKeyboardWillHideNotification == type) else if (UIKeyboardWillHideNotification == type)
{ {
@ -809,6 +818,7 @@ static cocos2d::CCTouch *s_pTouches[MAX_TOUCHES];
} }
else if (UIKeyboardDidHideNotification == type) else if (UIKeyboardDidHideNotification == type)
{ {
caretRect_ = CGRectZero;
dispatcher->dispatchKeyboardDidHide(notiInfo); dispatcher->dispatchKeyboardDidHide(notiInfo);
} }
} }

View File

@ -0,0 +1,16 @@
//
// RootViewController.h
// test
//
// Created by Walzer on 11-4-28.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController {
}
@end

View File

@ -0,0 +1,61 @@
//
// RootViewController.mm
// test
//
// Created by Walzer on 11-4-28.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "RootViewController.h"
@implementation RootViewController
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end

View File

@ -8,8 +8,11 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@class RootViewController;
@interface AppController : NSObject <UIApplicationDelegate> { @interface AppController : NSObject <UIApplicationDelegate> {
UIWindow *window; UIWindow *window;
RootViewController *viewController;
} }
@end @end

View File

@ -11,6 +11,7 @@
#import "EAGLView.h" #import "EAGLView.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h"
@implementation AppController @implementation AppController
@ -26,6 +27,11 @@ static AppDelegate s_sharedApplication;
// Add the view controller's view to the window and display. // Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
// Init the View Controller
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8 pixelFormat: kEAGLColorFormatRGBA8
depthFormat: GL_DEPTH_COMPONENT16_OES depthFormat: GL_DEPTH_COMPONENT16_OES
@ -34,7 +40,12 @@ static AppDelegate s_sharedApplication;
multiSampling:NO multiSampling:NO
numberOfSamples:0]; numberOfSamples:0];
[__glView setMultipleTouchEnabled:YES]; [__glView setMultipleTouchEnabled:YES];
[window addSubview: __glView];
// make the OpenGLView a child of the view controller
[viewController setView:__glView];
// make the View Controller a child of the main window
[window addSubview: viewController.view];
[window makeKeyAndVisible]; [window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden:true]; [[UIApplication sharedApplication] setStatusBarHidden:true];

View File

@ -1 +1 @@
85a9422443707c5ba69d66e2047740c1a865b91c a20fbecde64a220d0dbf2af6fc8bdff6f6c775d1

View File

@ -14,7 +14,7 @@ enum
static int testIdx = -1; static int testIdx = -1;
CCLayer* createTextInputTest(int nIndex) KeyboardNotificationLayer* createTextInputTest(int nIndex)
{ {
switch(nIndex) switch(nIndex)
{ {
@ -26,13 +26,12 @@ CCLayer* createTextInputTest(int nIndex)
CCLayer* restartTextInputTest() CCLayer* restartTextInputTest()
{ {
CCLayer* pContainerLayer = new TextInputTest; TextInputTest* pContainerLayer = new TextInputTest;
pContainerLayer->autorelease(); pContainerLayer->autorelease();
CCLayer* pTestLayer = createTextInputTest(testIdx); KeyboardNotificationLayer* pTestLayer = createTextInputTest(testIdx);
pTestLayer->autorelease(); pTestLayer->autorelease();
pContainerLayer->addKeyboardNotificationLayer(pTestLayer);
pContainerLayer->addChild(pTestLayer);
return pContainerLayer; return pContainerLayer;
} }
@ -69,6 +68,12 @@ CCRect getRect(CCNode * pNode)
// implement TextInputTest // implement TextInputTest
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
TextInputTest::TextInputTest()
: m_pNotificationLayer(0)
{
}
void TextInputTest::restartCallback(CCObject* pSender) void TextInputTest::restartCallback(CCObject* pSender)
{ {
CCScene* s = new TextInputTestScene(); CCScene* s = new TextInputTestScene();
@ -94,6 +99,18 @@ void TextInputTest::backCallback(CCObject* pSender)
s->release(); s->release();
} }
void TextInputTest::addKeyboardNotificationLayer(KeyboardNotificationLayer * pLayer)
{
m_pNotificationLayer = pLayer;
m_pNotificationLayer->retain();
addChild(pLayer);
}
std::string TextInputTest::title()
{
return "text input test";
}
void TextInputTest::onEnter() void TextInputTest::onEnter()
{ {
CCLayer::onEnter(); CCLayer::onEnter();
@ -104,7 +121,7 @@ void TextInputTest::onEnter()
addChild(label); addChild(label);
label->setPosition(ccp(s.width/2, s.height-50)); label->setPosition(ccp(s.width/2, s.height-50));
std::string subTitle = subtitle(); std::string subTitle = m_pNotificationLayer->subtitle();
if(! subTitle.empty()) if(! subTitle.empty())
{ {
CCLabelTTF* l = CCLabelTTF::labelWithString(subTitle.c_str(), "Thonburi", 16); CCLabelTTF* l = CCLabelTTF::labelWithString(subTitle.c_str(), "Thonburi", 16);
@ -125,14 +142,12 @@ void TextInputTest::onEnter()
addChild(menu, 1); addChild(menu, 1);
} }
std::string TextInputTest::title() void TextInputTest::onExit()
{ {
return "text input test"; if (m_pNotificationLayer)
} {
m_pNotificationLayer->release();
std::string TextInputTest::subtitle() }
{
return "";
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -145,6 +160,11 @@ KeyboardNotificationLayer::KeyboardNotificationLayer()
setIsTouchEnabled(true); setIsTouchEnabled(true);
} }
std::string KeyboardNotificationLayer::subtitle()
{
return "";
}
void KeyboardNotificationLayer::registerWithTouchDispatcher() void KeyboardNotificationLayer::registerWithTouchDispatcher()
{ {
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, false); CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, false);
@ -256,12 +276,6 @@ void TextFieldTTFTest::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
} }
} }
if (index == m_nSelected)
{
CCLOG("TextFieldTTFTest:noCCTextFieldTTFClicked.");
return;
}
if (m_nSelected >= 0) if (m_nSelected >= 0)
{ {
// hide the keyboard // hide the keyboard

View File

@ -3,17 +3,23 @@
#include "../testBasic.h" #include "../testBasic.h"
class KeyboardNotificationLayer;
class TextInputTest : public CCLayer, public CCIMEDelegate class TextInputTest : public CCLayer, public CCIMEDelegate
{ {
KeyboardNotificationLayer * m_pNotificationLayer;
public: public:
void restartCallback(CCObject* pSender); TextInputTest();
void nextCallback(CCObject* pSender);
void restartCallback(CCObject* pSender);
void nextCallback(CCObject* pSender);
void backCallback(CCObject* pSender); void backCallback(CCObject* pSender);
virtual std::string title(); std::string title();
virtual std::string subtitle(); void addKeyboardNotificationLayer(KeyboardNotificationLayer * pLayer);
virtual void onEnter(); virtual void onEnter();
virtual void onExit();
}; };
class KeyboardNotificationLayer : public CCLayer, public CCIMEDelegate class KeyboardNotificationLayer : public CCLayer, public CCIMEDelegate
@ -21,11 +27,12 @@ class KeyboardNotificationLayer : public CCLayer, public CCIMEDelegate
public: public:
KeyboardNotificationLayer(); KeyboardNotificationLayer();
virtual std::string subtitle();
virtual void registerWithTouchDispatcher(); virtual void registerWithTouchDispatcher();
virtual void keyboardWillShow(CCIMEKeyboardNotificationInfo& info); virtual void keyboardWillShow(CCIMEKeyboardNotificationInfo& info);
protected: protected:
CCNode * m_pTrackNode; CCNode * m_pTrackNode;
}; };
class TextFieldTTFTest : public KeyboardNotificationLayer class TextFieldTTFTest : public KeyboardNotificationLayer
@ -36,16 +43,16 @@ class TextFieldTTFTest : public KeyboardNotificationLayer
public: public:
TextFieldTTFTest(); TextFieldTTFTest();
virtual std::string subtitle(); virtual std::string subtitle();
virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent); virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent); virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
}; };
class TextInputTestScene : public TestScene class TextInputTestScene : public TestScene
{ {
public: public:
virtual void runThisTest(); virtual void runThisTest();
}; };
#endif // __TEXT_INPUT_TEST_H__ #endif // __TEXT_INPUT_TEST_H__