[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;
unsigned int indexBitsUsed;
NSString * markedText_;
CGRect caretRect_;
}
@property(nonatomic, readonly) UITextPosition *beginningOfDocument;

View File

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

View File

@ -11,6 +11,7 @@
#import "EAGLView.h"
#import "cocos2d.h"
#import "AppDelegate.h"
#import "RootViewController.h"
@implementation AppController
@ -26,6 +27,11 @@ static AppDelegate s_sharedApplication;
// Add the view controller's view to the window and display.
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]
pixelFormat: kEAGLColorFormatRGBA8
depthFormat: GL_DEPTH_COMPONENT16_OES
@ -34,7 +40,12 @@ static AppDelegate s_sharedApplication;
multiSampling:NO
numberOfSamples:0];
[__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];
[[UIApplication sharedApplication] setStatusBarHidden:true];

View File

@ -1 +1 @@
85a9422443707c5ba69d66e2047740c1a865b91c
a20fbecde64a220d0dbf2af6fc8bdff6f6c775d1

View File

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

View File

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