issue #1429: First commit CCEditBox support, only valid on IOS. PLZ refer to ExtensionsTest/EditBoxTest.

This commit is contained in:
James Chen 2012-08-15 14:33:56 +08:00
parent 7da6171715
commit 0fce637ec7
28 changed files with 1670 additions and 72 deletions

View File

@ -44,9 +44,8 @@ static void removeUsedIndexBit(int index)
CCEGLViewProtocol::CCEGLViewProtocol() CCEGLViewProtocol::CCEGLViewProtocol()
: m_pDelegate(NULL) : m_pDelegate(NULL)
, m_fScreenScaleFactor(1.0f) , m_fScaleY(1.0f)
, m_fYScale(1.0f) , m_fScaleX(1.0f)
, m_fXScale(1.0f)
, m_bIsRetinaEnabled(false) , m_bIsRetinaEnabled(false)
, m_eResolutionPolicy(kResolutionUnKnown) , m_eResolutionPolicy(kResolutionUnKnown)
{ {
@ -69,22 +68,22 @@ void CCEGLViewProtocol::setDesignResolutionSize(float width, float height, Resol
m_obDesignResolutionSize.setSize(width, height); m_obDesignResolutionSize.setSize(width, height);
m_fXScale = (float)m_obScreenSize.width / m_obDesignResolutionSize.width; m_fScaleX = (float)m_obScreenSize.width / m_obDesignResolutionSize.width;
m_fYScale = (float)m_obScreenSize.height / m_obDesignResolutionSize.height; m_fScaleY = (float)m_obScreenSize.height / m_obDesignResolutionSize.height;
if (resolutionPolicy == kCCResolutionNoBorder) if (resolutionPolicy == kCCResolutionNoBorder)
{ {
m_fXScale = m_fYScale = MAX(m_fXScale, m_fYScale); m_fScaleX = m_fScaleY = MAX(m_fScaleX, m_fScaleY);
} }
if (resolutionPolicy == kCCResolutionShowAll) if (resolutionPolicy == kCCResolutionShowAll)
{ {
m_fXScale = m_fYScale = MIN(m_fXScale, m_fYScale); m_fScaleX = m_fScaleY = MIN(m_fScaleX, m_fScaleY);
} }
// calculate the rect of viewport // calculate the rect of viewport
float viewPortW = m_obDesignResolutionSize.width * m_fXScale; float viewPortW = m_obDesignResolutionSize.width * m_fScaleX;
float viewPortH = m_obDesignResolutionSize.height * m_fYScale; float viewPortH = m_obDesignResolutionSize.height * m_fScaleY;
m_obViewPortRect.setRect((m_obScreenSize.width - viewPortW) / 2, (m_obScreenSize.height - viewPortH) / 2, viewPortW, viewPortH); m_obViewPortRect.setRect((m_obScreenSize.width - viewPortW) / 2, (m_obScreenSize.height - viewPortH) / 2, viewPortW, viewPortH);
@ -103,21 +102,26 @@ bool CCEGLViewProtocol::enableRetina()
return false; return false;
} }
CCSize CCEGLViewProtocol::getSize() const CCSize& CCEGLViewProtocol::getSize() const
{ {
return m_obDesignResolutionSize; return m_obDesignResolutionSize;
} }
void CCEGLViewProtocol::setSize(float width, float height) const CCSize& CCEGLViewProtocol::getFrameSize() const
{
return m_obScreenSize;
}
void CCEGLViewProtocol::setFrameSize(float width, float height)
{ {
m_obDesignResolutionSize = m_obScreenSize = CCSizeMake(width, height); m_obDesignResolutionSize = m_obScreenSize = CCSizeMake(width, height);
} }
CCSize CCEGLViewProtocol::getVisibleSize() CCSize CCEGLViewProtocol::getVisibleSize() const
{ {
if (m_eResolutionPolicy == kCCResolutionNoBorder) if (m_eResolutionPolicy == kCCResolutionNoBorder)
{ {
return CCSizeMake(m_obScreenSize.width/m_fXScale, m_obScreenSize.height/m_fYScale); return CCSizeMake(m_obScreenSize.width/m_fScaleX, m_obScreenSize.height/m_fScaleY);
} }
else else
{ {
@ -125,12 +129,12 @@ CCSize CCEGLViewProtocol::getVisibleSize()
} }
} }
CCPoint CCEGLViewProtocol::getVisibleOrigin() CCPoint CCEGLViewProtocol::getVisibleOrigin() const
{ {
if (m_eResolutionPolicy == kCCResolutionNoBorder) if (m_eResolutionPolicy == kCCResolutionNoBorder)
{ {
return CCPointMake((m_obDesignResolutionSize.width - m_obScreenSize.width/m_fXScale)/2, return CCPointMake((m_obDesignResolutionSize.width - m_obScreenSize.width/m_fScaleX)/2,
(m_obDesignResolutionSize.height - m_obScreenSize.height/m_fYScale)/2); (m_obDesignResolutionSize.height - m_obScreenSize.height/m_fScaleY)/2);
} }
else else
{ {
@ -143,11 +147,6 @@ void CCEGLViewProtocol::setTouchDelegate(EGLTouchDelegate * pDelegate)
m_pDelegate = pDelegate; m_pDelegate = pDelegate;
} }
float CCEGLViewProtocol::getScreenScaleFactor()
{
return m_fScreenScaleFactor;
}
bool CCEGLViewProtocol::setContentScaleFactor(float contentScaleFactor) bool CCEGLViewProtocol::setContentScaleFactor(float contentScaleFactor)
{ {
return false; return false;
@ -155,18 +154,18 @@ bool CCEGLViewProtocol::setContentScaleFactor(float contentScaleFactor)
void CCEGLViewProtocol::setViewPortInPoints(float x , float y , float w , float h) void CCEGLViewProtocol::setViewPortInPoints(float x , float y , float w , float h)
{ {
glViewport((GLint)(x * m_fXScale + m_obViewPortRect.origin.x), glViewport((GLint)(x * m_fScaleX + m_obViewPortRect.origin.x),
(GLint)(y * m_fYScale + m_obViewPortRect.origin.y), (GLint)(y * m_fScaleY + m_obViewPortRect.origin.y),
(GLsizei)(w * m_fXScale), (GLsizei)(w * m_fScaleX),
(GLsizei)(h * m_fYScale)); (GLsizei)(h * m_fScaleY));
} }
void CCEGLViewProtocol::setScissorInPoints(float x , float y , float w , float h) void CCEGLViewProtocol::setScissorInPoints(float x , float y , float w , float h)
{ {
glScissor((GLint)(x * m_fXScale + m_obViewPortRect.origin.x), glScissor((GLint)(x * m_fScaleX + m_obViewPortRect.origin.x),
(GLint)(y * m_fYScale + m_obViewPortRect.origin.y), (GLint)(y * m_fScaleY + m_obViewPortRect.origin.y),
(GLsizei)(w * m_fXScale), (GLsizei)(w * m_fScaleX),
(GLsizei)(h * m_fYScale)); (GLsizei)(h * m_fScaleY));
} }
void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[]) void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[])
@ -202,8 +201,8 @@ void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float
} }
else else
{ {
pTouch->setTouchInfo(nUnusedIndex, (x - m_obViewPortRect.origin.x) / m_fXScale, pTouch->setTouchInfo(nUnusedIndex, (x - m_obViewPortRect.origin.x) / m_fScaleX,
(y - m_obViewPortRect.origin.y) / m_fYScale); (y - m_obViewPortRect.origin.y) / m_fScaleY);
} }
CCLOG("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y); CCLOG("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y);
@ -250,8 +249,8 @@ void CCEGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float
} }
else else
{ {
pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x) / m_fXScale, pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x) / m_fScaleX,
(y - m_obViewPortRect.origin.y) / m_fYScale); (y - m_obViewPortRect.origin.y) / m_fScaleY);
} }
set.addObject(pTouch); set.addObject(pTouch);
@ -300,8 +299,8 @@ void CCEGLViewProtocol::getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[
} }
else else
{ {
pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x) / m_fXScale, pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x) / m_fScaleX,
(y - m_obViewPortRect.origin.y) / m_fYScale); (y - m_obViewPortRect.origin.y) / m_fScaleY);
} }
set.addObject(pTouch); set.addObject(pTouch);
@ -343,4 +342,24 @@ void CCEGLViewProtocol::handleTouchesCancel(int num, int ids[], float xs[], floa
m_pDelegate->touchesCancelled(&set, NULL); m_pDelegate->touchesCancelled(&set, NULL);
} }
const CCRect& CCEGLViewProtocol::getViewPortRect() const
{
return m_obViewPortRect;
}
float CCEGLViewProtocol::getScaleX() const
{
return m_fScaleX;
}
float CCEGLViewProtocol::getScaleY() const
{
return m_fScaleY;
}
bool CCEGLViewProtocol::isRetinaEnabled() const
{
return m_bIsRetinaEnabled;
}
NS_CC_END NS_CC_END

View File

@ -36,43 +36,126 @@ public:
CCEGLViewProtocol(); CCEGLViewProtocol();
virtual ~CCEGLViewProtocol(); virtual ~CCEGLViewProtocol();
/** Force destorying EGL view, subclass must implement this method. */
virtual void end() = 0; virtual void end() = 0;
/** Get whether opengl render system is ready, subclass must implement this method. */
virtual bool isOpenGLReady() = 0; virtual bool isOpenGLReady() = 0;
/** Exchanges the front and back buffers, subclass must implement this method. */
virtual void swapBuffers() = 0; virtual void swapBuffers() = 0;
/** Open or close IME keyboard , subclass must implement this method. */
virtual void setIMEKeyboardState(bool bOpen) = 0; virtual void setIMEKeyboardState(bool bOpen) = 0;
virtual CCSize getSize(); /**
virtual void setSize(float width, float height); * Get design resolution size.
virtual CCSize getVisibleSize(); * If setDesignResolutionSize wasn't invoked, the result of this function return is the same as 'getFrameSize'
virtual CCPoint getVisibleOrigin(); */
virtual void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy);
virtual void setTouchDelegate(EGLTouchDelegate * pDelegate); virtual const CCSize& getSize() const;
virtual float getScreenScaleFactor();
virtual bool setContentScaleFactor(float contentScaleFactor); /**
virtual void setViewPortInPoints(float x , float y , float w , float h); * Get the frame size of EGL view.
virtual void setScissorInPoints(float x , float y , float w , float h); * In general, it returns the screen size since the EGL view is a fullscreen view.
virtual bool enableRetina(); */
virtual const CCSize& getFrameSize() const;
/**
* Set the frame size of EGL view.
*/
virtual void setFrameSize(float width, float height);
/**
* Get the visible area size of opengl viewport.
*/
virtual CCSize getVisibleSize() const;
/**
* Get the visible origin point of opengl viewport.
*/
virtual CCPoint getVisibleOrigin() const;
/**
* Set the design resolutin size.
* You can't use it with enableRetina together.
* @param width Design resolution width.
* @param height Design resolution height.
* @param resolutionPolicy The resolution policy you need, there are:
* [1] kCCResolutionExactFit Fill screen, if the design resolution ratio of width and height is different from the screen resolution ratio, your game view will be stretched.
* [2] kCCResolutionNoBorder Full screen without black border, if the design resolution ratio of width and height is different from the screen resolution ratio, two areas of your game view will be cut.
* [3] kCCResolutionShowAll Full screen with black border, if the design resolution ratio of width and height is different from the screen resolution ratio, two black border will be shown on the screen;
*/
virtual void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy);
/** Set touch delegate */
virtual void setTouchDelegate(EGLTouchDelegate * pDelegate);
/**
* Set content scale factor.
* @return If return true, it means the plaform supports retina display.
*/
virtual bool setContentScaleFactor(float contentScaleFactor);
/**
* Set opengl view port rectangle with points.
*/
virtual void setViewPortInPoints(float x , float y , float w , float h);
/**
* Set Scissor rectangle with points.
*/
virtual void setScissorInPoints(float x , float y , float w , float h);
/**
* Enable retina mode.
* You can't use it with setDesignResolutionSize
*/
virtual bool enableRetina();
/** handle touch events by default, if you want to custom your handles, please override these functions */ /** handle touch events by default, if you want to custom your handles, please override these functions */
virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]); virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]);
virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]); virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]);
virtual void handleTouchesEnd(int num, int ids[], float xs[], float ys[]); virtual void handleTouchesEnd(int num, int ids[], float xs[], float ys[]);
virtual void handleTouchesCancel(int num, int ids[], float xs[], float ys[]); virtual void handleTouchesCancel(int num, int ids[], float xs[], float ys[]);
/**
* Get opengl view port rectangle.
*/
const CCRect& getViewPortRect() const;
/**
* Get the scale factor of horizontal direction.
*
*/
float getScaleX() const;
/**
* Get the scale factor of vertical direction.
*/
float getScaleY() const;
/**
* Get whether the retina mode is enabled.
*/
bool isRetinaEnabled() const;
private: private:
void getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[], float xs[], float ys[]); void getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[], float xs[], float ys[]);
protected: protected:
EGLTouchDelegate* m_pDelegate; EGLTouchDelegate* m_pDelegate;
float m_fScreenScaleFactor;
// real size of screen // real size of screen
CCSize m_obScreenSize; CCSize m_obScreenSize;
// resolution size, it is the size the app resources designed for // resolution size, it is the size the app resources designed for
CCSize m_obDesignResolutionSize; CCSize m_obDesignResolutionSize;
// the view port size // the view port size
CCRect m_obViewPortRect; CCRect m_obViewPortRect;
// the view name
char m_szViewName[50]; char m_szViewName[50];
float m_fXScale;
float m_fYScale; float m_fScaleX;
float m_fScaleY;
ResolutionPolicy m_eResolutionPolicy; ResolutionPolicy m_eResolutionPolicy;
bool m_bIsRetinaEnabled; bool m_bIsRetinaEnabled;
}; };

View File

@ -62,7 +62,7 @@ bool CCEGLView::setContentScaleFactor(float contentScaleFactor)
view.contentScaleFactor = contentScaleFactor; view.contentScaleFactor = contentScaleFactor;
[view setNeedsLayout]; [view setNeedsLayout];
m_fXScale = m_fYScale = contentScaleFactor; m_fScaleX = m_fScaleY = contentScaleFactor;
m_bIsRetinaEnabled = true; m_bIsRetinaEnabled = true;
return true; return true;

View File

@ -171,6 +171,10 @@ void CCFileUtils::purgeCachedEntries()
void CCFileUtils::setResourceDirectory(const char *pszDirectoryName) void CCFileUtils::setResourceDirectory(const char *pszDirectoryName)
{ {
m_obDirectory = pszDirectoryName; m_obDirectory = pszDirectoryName;
if (m_obDirectory.size() > 0 && m_obDirectory[m_obDirectory.size() - 1] != '/')
{
m_obDirectory.append("/");
}
} }
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)

View File

@ -92,9 +92,13 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
//fsaa addition //fsaa addition
BOOL multisampling_; BOOL multisampling_;
unsigned int requestedSamples_; unsigned int requestedSamples_;
BOOL isUseUITextField;
@private @private
NSString * markedText_; NSString * markedText_;
CGRect caretRect_; CGRect caretRect_;
CGRect originalRect_;
NSNotification* keyboardShowNotification_;
BOOL isKeyboardShown_;
} }
@property(nonatomic, readonly) UITextPosition *beginningOfDocument; @property(nonatomic, readonly) UITextPosition *beginningOfDocument;
@ -104,7 +108,8 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
@property (nonatomic, copy) NSDictionary *markedTextStyle; @property (nonatomic, copy) NSDictionary *markedTextStyle;
@property(readwrite, copy) UITextRange *selectedTextRange; @property(readwrite, copy) UITextRange *selectedTextRange;
@property(nonatomic, readonly) id<UITextInputTokenizer> tokenizer; @property(nonatomic, readonly) id<UITextInputTokenizer> tokenizer;
@property(nonatomic, readonly, getter = isKeyboardShown) BOOL isKeyboardShown;
@property(nonatomic, retain) NSNotification* keyboardShowNotification;
/** creates an initializes an EAGLView with a frame and 0-bit depth buffer, and a RGB565 color buffer */ /** creates an initializes an EAGLView with a frame and 0-bit depth buffer, and a RGB565 color buffer */
+ (id) viewWithFrame:(CGRect)frame; + (id) viewWithFrame:(CGRect)frame;
/** creates an initializes an EAGLView with a frame, a color buffer format, and 0-bit depth buffer */ /** creates an initializes an EAGLView with a frame, a color buffer format, and 0-bit depth buffer */
@ -147,4 +152,6 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
-(int) getWidth; -(int) getWidth;
-(int) getHeight; -(int) getHeight;
-(void) doAnimationWhenKeyboardMoveWithDuration:(float) duration distance:(float) dis;
-(void) doAnimationWhenAnotherEditBeClicked;
@end @end

View File

@ -70,7 +70,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
#import "CCTouch.h" #import "CCTouch.h"
#import "CCIMEDispatcher.h" #import "CCIMEDispatcher.h"
#import "OpenGL_Internal.h" #import "OpenGL_Internal.h"
#import "CCEGLView.h"
//CLASS IMPLEMENTATIONS: //CLASS IMPLEMENTATIONS:
@ -87,7 +87,8 @@ static EAGLView *view = 0;
@synthesize pixelFormat=pixelformat_, depthFormat=depthFormat_; @synthesize pixelFormat=pixelformat_, depthFormat=depthFormat_;
@synthesize context=context_; @synthesize context=context_;
@synthesize multiSampling=multiSampling_; @synthesize multiSampling=multiSampling_;
@synthesize isKeyboardShown=isKeyboardShown_;
@synthesize keyboardShowNotification = keyboardShowNotification_;
+ (Class) layerClass + (Class) layerClass
{ {
return [CAEAGLLayer class]; return [CAEAGLLayer class];
@ -132,6 +133,7 @@ static EAGLView *view = 0;
{ {
if((self = [super initWithFrame:frame])) if((self = [super initWithFrame:frame]))
{ {
isUseUITextField = YES;
pixelformat_ = format; pixelformat_ = format;
depthFormat_ = depth; depthFormat_ = depth;
multiSampling_ = sampling; multiSampling_ = sampling;
@ -145,6 +147,9 @@ static EAGLView *view = 0;
view = self; view = self;
originalRect_ = self.frame;
self.keyboardShowNotification = nil;
} }
return self; return self;
@ -237,6 +242,7 @@ static EAGLView *view = 0;
- (void) dealloc - (void) dealloc
{ {
[renderer_ release]; [renderer_ release];
[self.keyboardShowNotification release];
[super dealloc]; [super dealloc];
} }
@ -359,11 +365,34 @@ static EAGLView *view = 0;
return ret; return ret;
} }
-(void) handleTouchesAfterKeyboardShow
{
NSArray *subviews = self.subviews;
for(UIView* view in subviews)
{
if([view isKindOfClass:NSClassFromString(@"CustomUITextField")])
{
if ([view isFirstResponder])
{
[view resignFirstResponder];
return;
}
}
}
}
// Pass the touches to the superview // Pass the touches to the superview
#pragma mark EAGLView - Touch Delegate #pragma mark EAGLView - Touch Delegate
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ {
if (isKeyboardShown_)
{
[self handleTouchesAfterKeyboardShow];
return;
}
int ids[CC_MAX_TOUCHES] = {0}; int ids[CC_MAX_TOUCHES] = {0};
float xs[CC_MAX_TOUCHES] = {0.0f}; float xs[CC_MAX_TOUCHES] = {0.0f};
float ys[CC_MAX_TOUCHES] = {0.0f}; float ys[CC_MAX_TOUCHES] = {0.0f};
@ -435,12 +464,29 @@ static EAGLView *view = 0;
[markedText_ release]; [markedText_ release];
} }
markedText_ = nil; markedText_ = nil;
if (isUseUITextField)
{
return NO;
}
return YES; return YES;
} }
- (BOOL)becomeFirstResponder
{
isUseUITextField = NO;
return [super becomeFirstResponder];
}
- (BOOL)resignFirstResponder
{
isUseUITextField = YES;
return [super resignFirstResponder];
}
#pragma mark - #pragma mark -
#pragma mark UIKeyInput protocol #pragma mark UIKeyInput protocol
- (BOOL)hasText - (BOOL)hasText
{ {
return NO; return NO;
@ -724,6 +770,7 @@ static EAGLView *view = 0;
default: default:
break; break;
} }
cocos2d::CCIMEKeyboardNotificationInfo notiInfo; cocos2d::CCIMEKeyboardNotificationInfo notiInfo;
notiInfo.begin = cocos2d::CCRect(begin.origin.x, notiInfo.begin = cocos2d::CCRect(begin.origin.x,
begin.origin.y, begin.origin.y,
@ -734,9 +781,36 @@ static EAGLView *view = 0;
end.size.width, end.size.width,
end.size.height); end.size.height);
notiInfo.duration = (float)aniDuration; notiInfo.duration = (float)aniDuration;
float offestY = cocos2d::CCEGLView::sharedOpenGLView().getViewPortRect().origin.y;
if (offestY > 0.0f)
{
notiInfo.begin.origin.y += offestY;
notiInfo.begin.size.height -= offestY;
notiInfo.end.size.height -= offestY;
}
if (!cocos2d::CCEGLView::sharedOpenGLView().isRetinaEnabled())
{
float scaleX = cocos2d::CCEGLView::sharedOpenGLView().getScaleX();
float scaleY = cocos2d::CCEGLView::sharedOpenGLView().getScaleY();
notiInfo.begin.origin.x /= scaleX;
notiInfo.begin.origin.y /= scaleY;
notiInfo.begin.size.width /= scaleX;
notiInfo.begin.size.height /= scaleY;
notiInfo.end.origin.x /= scaleX;
notiInfo.end.origin.y /= scaleY;
notiInfo.end.size.width /= scaleX;
notiInfo.end.size.height /= scaleY;
}
cocos2d::CCIMEDispatcher* dispatcher = cocos2d::CCIMEDispatcher::sharedDispatcher(); cocos2d::CCIMEDispatcher* dispatcher = cocos2d::CCIMEDispatcher::sharedDispatcher();
if (UIKeyboardWillShowNotification == type) if (UIKeyboardWillShowNotification == type)
{ {
self.keyboardShowNotification = [notif copy];
dispatcher->dispatchKeyboardWillShow(notiInfo); dispatcher->dispatchKeyboardWillShow(notiInfo);
} }
else if (UIKeyboardDidShowNotification == type) else if (UIKeyboardDidShowNotification == type)
@ -746,6 +820,7 @@ static EAGLView *view = 0;
caretRect_ = end; caretRect_ = end;
caretRect_.origin.y = viewSize.height - (caretRect_.origin.y + caretRect_.size.height + [UIFont smallSystemFontSize]); caretRect_.origin.y = viewSize.height - (caretRect_.origin.y + caretRect_.size.height + [UIFont smallSystemFontSize]);
caretRect_.size.height = 0; caretRect_.size.height = 0;
isKeyboardShown_ = YES;
} }
else if (UIKeyboardWillHideNotification == type) else if (UIKeyboardWillHideNotification == type)
{ {
@ -755,6 +830,58 @@ static EAGLView *view = 0;
{ {
caretRect_ = CGRectZero; caretRect_ = CGRectZero;
dispatcher->dispatchKeyboardDidHide(notiInfo); dispatcher->dispatchKeyboardDidHide(notiInfo);
isKeyboardShown_ = NO;
} }
} }
-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)dis
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:duration];
[UIView setAnimationBeginsFromCurrentState:YES];
NSLog(@"[animation] dis = %f\n", dis);
if (dis < 0.0f) dis = 0.0f;
if (!cocos2d::CCEGLView::sharedOpenGLView().isRetinaEnabled())
{
dis *= cocos2d::CCEGLView::sharedOpenGLView().getScaleY();
}
switch ([[UIApplication sharedApplication] statusBarOrientation])
{
case UIInterfaceOrientationPortrait:
self.frame = CGRectMake(originalRect_.origin.x, originalRect_.origin.y - dis, originalRect_.size.width, originalRect_.size.height);
break;
case UIInterfaceOrientationPortraitUpsideDown:
self.frame = CGRectMake(originalRect_.origin.x, originalRect_.origin.y + dis, originalRect_.size.width, originalRect_.size.height);
break;
case UIInterfaceOrientationLandscapeLeft:
self.frame = CGRectMake(originalRect_.origin.x - dis, originalRect_.origin.y , originalRect_.size.width, originalRect_.size.height);
break;
case UIInterfaceOrientationLandscapeRight:
self.frame = CGRectMake(originalRect_.origin.x + dis, originalRect_.origin.y , originalRect_.size.width, originalRect_.size.height);
break;
default:
break;
}
[UIView commitAnimations];
}
-(void) doAnimationWhenAnotherEditBeClicked
{
if (self.keyboardShowNotification != nil)
{
[[NSNotificationCenter defaultCenter]postNotification:self.keyboardShowNotification];
}
}
@end @end

View File

@ -397,10 +397,10 @@ void CCEGLView::resize(int width, int height)
rcClient.bottom - rcClient.top, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); rcClient.bottom - rcClient.top, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
} }
void CCEGLView::setSize(float width, float height) void CCEGLView::setFrameSize(float width, float height)
{ {
Create((LPCTSTR)m_szViewName, (int)width, (int)height); Create((LPCTSTR)m_szViewName, (int)width, (int)height);
CCEGLViewProtocol::setSize(width, height); CCEGLViewProtocol::setFrameSize(width, height);
} }
void CCEGLView::centerWindow() void CCEGLView::centerWindow()

View File

@ -45,7 +45,7 @@ public:
virtual void end(); virtual void end();
virtual void swapBuffers(); virtual void swapBuffers();
virtual bool setContentScaleFactor(float contentScaleFactor); virtual bool setContentScaleFactor(float contentScaleFactor);
virtual void setSize(float width, float height); virtual void setFrameSize(float width, float height);
virtual void setIMEKeyboardState(bool bOpen); virtual void setIMEKeyboardState(bool bOpen);
private: private:

View File

@ -0,0 +1,310 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCEditBox.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "CCEditBoxImplIOS.h"
#endif
NS_CC_EXT_BEGIN
CCEditBox::CCEditBox(void)
: m_pEditBoxImpl(NULL)
, m_pDelegate(NULL)
, m_eEditBoxInputMode(kEditBoxInputModeAny)
, m_eEditBoxInputFlag(kEditBoxInputFlagInitialCapsAllCharacters)
, m_eKeyboardReturnType(kKeyboardReturnTypeDefault)
, m_colText(ccWHITE)
, m_colPlaceHolder(ccGRAY)
, m_nMaxLength(0)
, m_fAdjustHeight(0.0f)
{
}
CCEditBox::~CCEditBox(void)
{
CC_SAFE_DELETE(m_pEditBoxImpl);
}
void CCEditBox::touchDownAction(CCObject *sender, CCControlEvent controlEvent)
{
m_pEditBoxImpl->openKeyboard();
}
CCEditBox* CCEditBox::create(const CCSize& size)
{
CCEditBox* pRet = new CCEditBox();
if (pRet != NULL && pRet->initWithSize(size))
{
pRet->autorelease();
}
else
{
CC_SAFE_DELETE(pRet);
}
return pRet;
}
bool CCEditBox::initWithSize(const CCSize& size)
{
if (CCControlButton::init())
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
m_pEditBoxImpl = new CCEditBoxImplIOS(this);
#endif
m_pEditBoxImpl->initWithSize(size);
CCScale9Sprite* pNormal9Sprite = CCScale9Sprite::create("extensions/button.png");
CCScale9Sprite* pPressed9Sprite = CCScale9Sprite::create("extensions/buttonHighlighted.png");
CCScale9Sprite* pDisabled9Sprite = CCScale9Sprite::create("extensions/button.png");
setBackgroundSpriteForState(pNormal9Sprite, CCControlStateNormal);
setBackgroundSpriteForState(pPressed9Sprite, CCControlStateHighlighted);
setBackgroundSpriteForState(pDisabled9Sprite, CCControlStateDisabled);
this->setPreferredSize(size);
this->setPosition(ccp(0, 0));
this->addTargetWithActionForControlEvent(this, cccontrol_selector(CCEditBox::touchDownAction), CCControlEventTouchDown);
return true;
}
return false;
}
void CCEditBox::setDelegate(CCEditBoxDelegate* pDelegate)
{
m_pDelegate = pDelegate;
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setDelegate(pDelegate);
}
}
void CCEditBox::setText(const char* pText)
{
if (pText != NULL)
{
m_strText = pText;
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setText(pText);
}
}
}
const char* CCEditBox::getText(void)
{
if (m_pEditBoxImpl != NULL)
{
return m_pEditBoxImpl->getText();
}
return NULL;
}
void CCEditBox::setFontColor(const ccColor3B& color)
{
m_colText = color;
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setFontColor(color);
}
}
void CCEditBox::setPlaceholderFontColor(const ccColor3B& color)
{
m_colText = color;
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setPlaceholderFontColor(color);
}
}
void CCEditBox::setPlaceHolder(const char* pText)
{
if (pText != NULL)
{
m_strPlaceHolder = pText;
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setPlaceHolder(pText);
}
}
}
const char* CCEditBox::getPlaceHolder(void)
{
return m_strPlaceHolder.c_str();
}
void CCEditBox::setInputMode(EditBoxInputMode inputMode)
{
m_eEditBoxInputMode = inputMode;
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setInputMode(inputMode);
}
}
void CCEditBox::setMaxLength(int maxLength)
{
m_nMaxLength = maxLength;
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setMaxLength(maxLength);
}
}
int CCEditBox::getMaxLength()
{
return m_nMaxLength;
}
void CCEditBox::setInputFlag(EditBoxInputFlag inputFlag)
{
m_eEditBoxInputFlag = inputFlag;
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setInputFlag(inputFlag);
}
}
void CCEditBox::setReturnType(KeyboardReturnType returnType)
{
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setReturnType(returnType);
}
}
/* override function */
void CCEditBox::setPosition(const CCPoint& pos)
{
CCControlButton::setPosition(pos);
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setPosition(pos);
}
}
void CCEditBox::setContentSize(const CCSize& size)
{
CCControlButton::setContentSize(size);
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->setContentSize(size);
}
}
void CCEditBox::visit(void)
{
CCControlButton::visit();
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->visit();
}
}
void CCEditBox::onExit(void)
{
CCControlButton::onExit();
if (m_pEditBoxImpl != NULL)
{
// remove system edit control
m_pEditBoxImpl->closeKeyboard();
}
}
static CCRect getRect(CCNode * pNode)
{
CCRect rc;
rc.origin = pNode->getPosition();
rc.size = pNode->getContentSize();
rc.origin.x -= rc.size.width / 2;
rc.origin.y -= rc.size.height / 2;
return rc;
}
void CCEditBox::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
{
//CCLOG("TextInputTest:keyboardWillShowAt(origin:%f,%f, size:%f,%f)",
// info.end.origin.x, info.end.origin.y, info.end.size.width, info.end.size.height);
CCRect rectTracked = getRect(this);
//CCLOG("TextInputTest:trackingNodeAt(origin:%f,%f, size:%f,%f)",
// rectTracked.origin.x, rectTracked.origin.y, rectTracked.size.width, rectTracked.size.height);
// if the keyboard area doesn't intersect with the tracking node area, nothing need to do.
if (! rectTracked.intersectsRect(info.end))
{
CCLog("info end x = %f, y = %f; width = %f, height = %f", info.end.origin.x, info.end.origin.y, info.end.size.width, info.end.size.height);
CCLog("rectTracked end x = %f, y = %f; width = %f, height = %f", rectTracked.origin.x, rectTracked.origin.y, rectTracked.size.width, rectTracked.size.height);
CCLog("needn't to adjust view layout.");
return;
}
// assume keyboard at the bottom of screen, calculate the vertical adjustment.
m_fAdjustHeight = info.end.getMaxY() - rectTracked.getMinY();
CCLOG("CCEditBox:needAdjustVerticalPosition(%f)", m_fAdjustHeight);
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->doAnimationWhenKeyboardMove(info.duration, m_fAdjustHeight);
}
}
void CCEditBox::keyboardDidShow(CCIMEKeyboardNotificationInfo& info)
{
if (m_pDelegate != NULL)
{
m_pDelegate->editBoxEditingDidBegin(this);
}
}
void CCEditBox::keyboardWillHide(CCIMEKeyboardNotificationInfo& info)
{
if (m_pEditBoxImpl != NULL)
{
m_pEditBoxImpl->doAnimationWhenKeyboardMove(info.duration, -m_fAdjustHeight);
}
}
void CCEditBox::keyboardDidHide(CCIMEKeyboardNotificationInfo& info)
{
if (m_pDelegate != NULL)
{
m_pDelegate->editBoxEditingDidEnd(this);
m_pDelegate->editBoxReturn(this);
}
}
NS_CC_EXT_END

View File

@ -0,0 +1,308 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCEDITTEXT_H__
#define __CCEDITTEXT_H__
#include "cocos2d.h"
#include "ExtensionMacros.h"
#include "../CCControlExtension/CCControlExtensions.h"
NS_CC_EXT_BEGIN
enum KeyboardReturnType {
kKeyboardReturnTypeDefault = 0,
kKeyboardReturnTypeDone,
kKeyboardReturnTypeSend,
kKeyboardReturnTypeSearch,
kKeyboardReturnTypeGo
};
/**
* \brief The EditBoxInputMode defines the type of text that the user is allowed
* to enter.
*/
enum EditBoxInputMode
{
/**
* The user is allowed to enter any text, including line breaks.
*/
kEditBoxInputModeAny = 0,
/**
* The user is allowed to enter an e-mail address.
*/
kEditBoxInputModeEmailAddr,
/**
* The user is allowed to enter an integer value.
*/
kEditBoxInputModeNumeric,
/**
* The user is allowed to enter a phone number.
*/
kEditBoxInputModePhoneNumber,
/**
* The user is allowed to enter a URL.
*/
kEditBoxInputModeUrl,
/**
* The user is allowed to enter a real number value.
* This extends kEditBoxInputModeNumeric by allowing a decimal point.
*/
kEditBoxInputModeDecimal,
/**
* The user is allowed to enter any text, except for line breaks.
*/
kEditBoxInputModeSingleLine
};
/**
* \brief The EditBoxInputFlag defines how the input text is displayed/formatted.
*/
enum EditBoxInputFlag
{
/**
* Indicates that the text entered is confidential data that should be
* obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE.
*/
kEditBoxInputFlagPassword = 0,
/**
* Indicates that the text entered is sensitive data that the
* implementation must never store into a dictionary or table for use
* in predictive, auto-completing, or other accelerated input schemes.
* A credit card number is an example of sensitive data.
*/
kEditBoxInputFlagSensitive,
/**
* This flag is a hint to the implementation that during text editing,
* the initial letter of each word should be capitalized.
*/
kEditBoxInputFlagInitialCapsWord,
/**
* This flag is a hint to the implementation that during text editing,
* the initial letter of each sentence should be capitalized.
*/
kEditBoxInputFlagInitialCapsSentence,
/**
* Capitalize all characters automatically.
*/
kEditBoxInputFlagInitialCapsAllCharacters
};
class CCEditBox;
class CCEditBoxImpl;
class CCEditBoxDelegate
{
public:
virtual ~CCEditBoxDelegate() {};
/**
* This method is called when an edit box gains focus after keyboard is shown.
* @param editBox The edit box object that generated the event.
*/
virtual void editBoxEditingDidBegin(CCEditBox* editBox) {};
/**
* This method is called when an edit box loses focus after keyboard is hidden.
* @param editBox The edit box object that generated the event.
*/
virtual void editBoxEditingDidEnd(CCEditBox* editBox) {};
/**
* This method is called when the edit box text was changed.
* @param editBox The edit box object that generated the event.
* @param text The new text.
*/
virtual void editBoxTextChanged(
CCEditBox* editBox,
const std::string& text) {};
/**
* This method is called when the return button was pressed or the outside area of keyboard was touched.
* @param editBox The edit box object that generated the event.
*/
virtual void editBoxReturn(CCEditBox* editBox) = 0;
};
/**
* \brief Class for edit box.
*
* You can use this widget to gather small amounts of text from the user.
*
*/
class CCEditBox
: public CCControlButton
, public CCIMEDelegate
{
public:
/**
* Constructor.
*/
CCEditBox(void);
/**
* Destructor.
*/
virtual ~CCEditBox(void);
/**
* create a edit box with size.
* @return An autorelease pointer of CCEditBox, you don't need to release it only if you retain it again.
*/
static CCEditBox* create(const CCSize& size);
/**
* Init edit box with specified size. This method should be invoked right after constructor.
* @param size The size of edit box.
*/
bool initWithSize(const CCSize& size);
/**
* Set the delegate for edit box.
*/
void setDelegate(CCEditBoxDelegate* pDelegate);
/**
* Set the text entered in the edit box.
* @param pText The given text.
*/
void setText(const char* pText);
/**
* Get the text entered in the edit box.
* @return The text entered in the edit box.
*/
const char* getText(void);
/**
* Set the font color of the widget's text.
*/
void setFontColor(const ccColor3B& color);
/**
* Set the font color of the placeholder text when the edit box is empty.
*/
void setPlaceholderFontColor(const ccColor3B& color);
/**
* Set a text in the edit box that acts as a placeholder when an
* edit box is empty.
* @param pText The given text.
*/
void setPlaceHolder(const char* pText);
/**
* Get a text in the edit box that acts as a placeholder when an
* edit box is empty.
*/
const char* getPlaceHolder(void);
/**
* Set the input mode of the edit box.
* @param inputMode One of the EditBoxInputMode constants.
*/
void setInputMode(EditBoxInputMode inputMode);
/**
* Sets the maximum input length of the edit box.
* Setting this value enables multiline input mode by default.
* Available on Android, iOS and Windows Phone.
*
* @param maxLength The maximum length.
*/
void setMaxLength(int maxLength);
/**
* Gets the maximum input length of the edit box.
*
* @return Maximum input length.
*/
int getMaxLength();
/**
* Set the input flags that are to be applied to the edit box.
* @param inputFlag One of the EditBoxInputFlag constants.
*/
void setInputFlag(EditBoxInputFlag inputFlag);
/**
* Set the return type that are to be applied to the edit box.
* @param returnType One of the CCKeyboardReturnType constants.
*/
void setReturnType(KeyboardReturnType returnType);
/* override functions */
virtual void setPosition(const CCPoint& pos);
virtual void setContentSize(const CCSize& size);
virtual void visit(void);
virtual void onExit(void);
virtual void keyboardWillShow(CCIMEKeyboardNotificationInfo& info);
virtual void keyboardDidShow(CCIMEKeyboardNotificationInfo& info);
virtual void keyboardWillHide(CCIMEKeyboardNotificationInfo& info);
virtual void keyboardDidHide(CCIMEKeyboardNotificationInfo& info);
/* callback funtions */
void touchDownAction(CCObject *sender, CCControlEvent controlEvent);
protected:
CCEditBoxImpl* m_pEditBoxImpl;
CCEditBoxDelegate* m_pDelegate;
EditBoxInputMode m_eEditBoxInputMode;
EditBoxInputFlag m_eEditBoxInputFlag;
KeyboardReturnType m_eKeyboardReturnType;
std::string m_strText;
std::string m_strPlaceHolder;
ccColor3B m_colText;
ccColor3B m_colPlaceHolder;
int m_nMaxLength;
float m_fAdjustHeight;
};
NS_CC_EXT_END
#endif /* __CCEDITTEXT_H__ */

View File

@ -0,0 +1,74 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCEditBoxIMPL_H__
#define __CCEditBoxIMPL_H__
#include "cocos2d.h"
#include "ExtensionMacros.h"
#include "CCEditBox.h"
NS_CC_EXT_BEGIN
class CCEditBoxImpl
{
public:
CCEditBoxImpl(CCEditBox* pEditBox) : m_pEditBox(pEditBox), m_pDelegate(NULL) {}
virtual ~CCEditBoxImpl() {}
virtual bool initWithSize(const CCSize& size) = 0;
virtual void setFontColor(const ccColor3B& color) = 0;
virtual void setPlaceholderFontColor(const ccColor3B& color) = 0;
virtual void setInputMode(EditBoxInputMode inputMode) = 0;
virtual void setInputFlag(EditBoxInputFlag inputFlag) = 0;
virtual void setMaxLength(int maxLength) = 0;
virtual int getMaxLength() = 0;
virtual void setReturnType(KeyboardReturnType returnType) = 0;
virtual void setText(const char* pText) = 0;
virtual const char* getText(void) = 0;
virtual void setPlaceHolder(const char* pText) = 0;
virtual void doAnimationWhenKeyboardMove(float duration, float distance) = 0;
virtual void openKeyboard() = 0;
virtual void closeKeyboard() = 0;
virtual void setPosition(const CCPoint& pos) = 0;
virtual void setContentSize(const CCSize& size) = 0;
virtual void visit(void) = 0;
void setDelegate(CCEditBoxDelegate* pDelegate) { m_pDelegate = pDelegate; };
CCEditBoxDelegate* getDelegate() { return m_pDelegate; };
CCEditBox* getCCEditBox() { return m_pEditBox; };
protected:
CCEditBoxDelegate* m_pDelegate;
CCEditBox* m_pEditBox;
};
NS_CC_EXT_END
#endif /* __CCEditBoxIMPL_H__ */

View File

@ -0,0 +1,73 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCEditBoxIMPLIOS_H__
#define __CCEditBoxIMPLIOS_H__
#include "cocos2d.h"
#include "ExtensionMacros.h"
#include "CCEditBoxImpl.h"
NS_CC_EXT_BEGIN
class CCEditBox;
class CCEditBoxImplIOS : public CCEditBoxImpl
{
public:
CCEditBoxImplIOS(CCEditBox* pEditText);
virtual ~CCEditBoxImplIOS();
virtual bool initWithSize(const CCSize& size);
virtual void setFontColor(const ccColor3B& color);
virtual void setPlaceholderFontColor(const ccColor3B& color);
virtual void setInputMode(EditBoxInputMode inputMode);
virtual void setInputFlag(EditBoxInputFlag inputFlag);
virtual void setMaxLength(int maxLength);
virtual int getMaxLength();
virtual void setReturnType(KeyboardReturnType returnType);
virtual void setText(const char* pText);
virtual const char* getText(void);
virtual void setPlaceHolder(const char* pText);
virtual void setPosition(const CCPoint& pos);
virtual void setContentSize(const CCSize& size);
virtual void visit(void);
virtual void doAnimationWhenKeyboardMove(float duration, float distance);
virtual void openKeyboard();
virtual void closeKeyboard();
private:
CCEditBox* m_pEditBox;
CCSize m_tContentSize;
void* m_pSysEdit;
int m_nMaxTextLength;
};
NS_CC_EXT_END
#endif /* __CCEditBoxIMPLIOS_H__ */

View File

@ -0,0 +1,235 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCEditBoxImplIOS.h"
#include "CCEditBox.h"
#import "EAGLView.h"
#import "EditBoxImplIOS.h"
NS_CC_EXT_BEGIN
#define GET_IMPL ((EditBoxImplIOS*)m_pSysEdit)
CCEditBoxImplIOS::CCEditBoxImplIOS(CCEditBox* pEditText)
: CCEditBoxImpl(pEditText)
, m_pSysEdit(NULL)
, m_nMaxTextLength(-1)
{
}
CCEditBoxImplIOS::~CCEditBoxImplIOS()
{
[GET_IMPL release];
}
void CCEditBoxImplIOS::doAnimationWhenKeyboardMove(float duration, float distance)
{
if ([GET_IMPL isEditState] || distance < 0.0f)
{
[GET_IMPL doAnimationWhenKeyboardMoveWithDuration:duration distance:distance];
}
}
bool CCEditBoxImplIOS::initWithSize(const CCSize& size)
{
do
{
CCEGLViewProtocol& eglView = CCEGLView::sharedOpenGLView();
CGRect rect;
if (eglView.isRetinaEnabled())
{
rect = CGRectMake(0, 0, size.width,size.height);
}
else
{
rect = CGRectMake(0, 0, size.width * eglView.getScaleX(),size.height * eglView.getScaleY());
}
m_pSysEdit = [[EditBoxImplIOS alloc] initWithFrame:rect editBox:this];
if (!m_pSysEdit) break;
return true;
}while (0);
return false;
}
void CCEditBoxImplIOS::setFontColor(const ccColor3B& color)
{
GET_IMPL.textField.textColor = [UIColor colorWithRed:color.r / 255.0f green:color.g / 255.0f blue:color.b / 255.0f alpha:1.0f];
}
void CCEditBoxImplIOS::setPlaceholderFontColor(const ccColor3B& color)
{
// TODO need to be implemented.
}
void CCEditBoxImplIOS::setInputMode(EditBoxInputMode inputMode)
{
switch (inputMode)
{
case kEditBoxInputModeEmailAddr:
GET_IMPL.textField.keyboardType = UIKeyboardTypeEmailAddress;
break;
case kEditBoxInputModeNumeric:
GET_IMPL.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
break;
case kEditBoxInputModePhoneNumber:
GET_IMPL.textField.keyboardType = UIKeyboardTypePhonePad;
break;
case kEditBoxInputModeUrl:
GET_IMPL.textField.keyboardType = UIKeyboardTypeURL;
break;
case kEditBoxInputModeDecimal:
GET_IMPL.textField.keyboardType = UIKeyboardTypeDecimalPad;
break;
case kEditBoxInputModeSingleLine:
GET_IMPL.textField.keyboardType = UIKeyboardTypeDefault;
break;
default:
GET_IMPL.textField.keyboardType = UIKeyboardTypeDefault;
break;
}
}
void CCEditBoxImplIOS::setMaxLength(int maxLength)
{
m_nMaxTextLength = maxLength;
}
int CCEditBoxImplIOS::getMaxLength()
{
return m_nMaxTextLength;
}
void CCEditBoxImplIOS::setInputFlag(EditBoxInputFlag inputFlag)
{
switch (inputFlag)
{
case kEditBoxInputFlagPassword:
GET_IMPL.textField.secureTextEntry = YES;
break;
case kEditBoxInputFlagInitialCapsWord:
GET_IMPL.textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
break;
case kEditBoxInputFlagInitialCapsSentence:
GET_IMPL.textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
break;
case kEditBoxInputFlagInitialCapsAllCharacters:
GET_IMPL.textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
break;
default:
break;
}
}
void CCEditBoxImplIOS::setReturnType(KeyboardReturnType returnType)
{
switch (returnType) {
case kKeyboardReturnTypeDefault:
GET_IMPL.textField.returnKeyType = UIReturnKeyDefault;
break;
case kKeyboardReturnTypeDone:
GET_IMPL.textField.returnKeyType = UIReturnKeyGo;
break;
case kKeyboardReturnTypeSend:
GET_IMPL.textField.returnKeyType = UIReturnKeyDone;
break;
case kKeyboardReturnTypeSearch:
GET_IMPL.textField.returnKeyType = UIReturnKeySearch;
break;
case kKeyboardReturnTypeGo:
GET_IMPL.textField.returnKeyType = UIReturnKeySend;
break;
default:
GET_IMPL.textField.returnKeyType = UIReturnKeyDefault;
break;
}
}
void CCEditBoxImplIOS::setText(const char* pText)
{
GET_IMPL.textField.text = [NSString stringWithUTF8String:pText];
}
const char* CCEditBoxImplIOS::getText(void)
{
return [GET_IMPL.textField.text UTF8String];
}
void CCEditBoxImplIOS::setPlaceHolder(const char* pText)
{
GET_IMPL.textField.placeholder = [NSString stringWithUTF8String:pText];
}
static CGPoint convertDesignCoordToScreenCoord(const CCPoint& designCoord)
{
float viewH = (float)[[EAGLView sharedEGLView] getHeight];
CCEGLViewProtocol& eglView = CCEGLView::sharedOpenGLView();
CCPoint visiblePos;
if (eglView.isRetinaEnabled())
{
visiblePos = ccp(designCoord.x, designCoord.y);
}
else
{
visiblePos = ccp(designCoord.x * eglView.getScaleX(), designCoord.y * eglView.getScaleY());
}
CCPoint screenGLPos = ccpAdd(visiblePos, eglView.getViewPortRect().origin);
CGPoint screenPos = CGPointMake(screenGLPos.x, viewH - screenGLPos.y);
return screenPos;
}
void CCEditBoxImplIOS::setPosition(const CCPoint& pos)
{
//TODO should consider anchor point, the default value is (0.5, 0,5)
[GET_IMPL setPosition:convertDesignCoordToScreenCoord(ccp(pos.x-m_tContentSize.width/2, pos.y+m_tContentSize.height/2))];
}
void CCEditBoxImplIOS::setContentSize(const CCSize& size)
{
m_tContentSize = size;
CCLog("[Edit text] content size = (%f, %f)", size.width, size.height);
}
void CCEditBoxImplIOS::visit(void)
{
}
void CCEditBoxImplIOS::openKeyboard()
{
[GET_IMPL openKeyboard];
}
void CCEditBoxImplIOS::closeKeyboard()
{
[GET_IMPL closeKeyboard];
}
NS_CC_EXT_END

View File

@ -0,0 +1,54 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#import <Foundation/Foundation.h>
@interface CustomUITextField : UITextField
{
}
@end
@interface EditBoxImplIOS : NSObject <UITextFieldDelegate>
{
CustomUITextField* textField_;
void* editBox_;
BOOL editState_;
}
@property(nonatomic, retain) UITextField* textField;
@property(nonatomic, readonly, getter = isEditState) BOOL editState;
@property(nonatomic, assign) void* editBox;
-(id) initWithFrame: (CGRect) frameRect editBox: (void*) editBox;
-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance;
-(void) setPosition:(CGPoint) pos;
-(void) setContentSize:(CGSize) size;
-(void) visit;
-(void) openKeyboard;
-(void) closeKeyboard;
@end

View File

@ -0,0 +1,189 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#import "EditBoxImplIOS.h"
#import "EAGLView.h"
#import "CCEditBoxImplIOS.h"
#define getEditBoxImplIOS() ((cocos2d::extension::CCEditBoxImplIOS*)editBox_)
@implementation CustomUITextField
- (CGRect)textRectForBounds:(CGRect)bounds {
float padding = 5.0f;
return CGRectMake(bounds.origin.x + padding, bounds.origin.y + padding,
bounds.size.width - padding*2, bounds.size.height - padding*2);
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
return [self textRectForBounds:bounds];
}
@end
@implementation EditBoxImplIOS
@synthesize textField = textField_;
@synthesize editState = editState_;
@synthesize editBox = editBox_;
- (void)dealloc
{
[textField_ resignFirstResponder];
[textField_ removeFromSuperview];
[textField_ release];
[super dealloc];
}
-(id) initWithFrame: (CGRect) frameRect editBox: (void*) editBox
{
self = [super init];
do
{
if (self == nil) break;
editState_ = NO;
textField_ = [[CustomUITextField alloc] initWithFrame: frameRect];
if (!textField_) break;
[textField_ setTextColor:[UIColor whiteColor]];
textField_.font = [UIFont systemFontOfSize:frameRect.size.height*2/3]; //TODO need to delete hard code here.
textField_.backgroundColor = [UIColor clearColor];
textField_.borderStyle = UITextBorderStyleNone;
textField_.delegate = self;
textField_.returnKeyType = UIReturnKeyDefault;
[textField_ addTarget:self action:@selector(textChanged) forControlEvents:UIControlEventEditingChanged];
self.editBox = editBox;
[[EAGLView sharedEGLView] addSubview:textField_];
return self;
}while(0);
[textField_ release];
return nil;
}
-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance
{
id eglView = [EAGLView sharedEGLView];
[eglView doAnimationWhenKeyboardMoveWithDuration:duration distance:distance];
}
-(void) setPosition:(CGPoint) pos
{
CGRect frame = [textField_ frame];
frame.origin = pos;
[textField_ setFrame:frame];
}
-(void) setContentSize:(CGSize) size
{
}
-(void) visit
{
}
-(void) openKeyboard
{
[textField_ becomeFirstResponder];
}
-(void) closeKeyboard
{
[textField_ resignFirstResponder];
[textField_ removeFromSuperview];
}
- (BOOL)textFieldShouldReturn:(UITextField *)sender
{
if (sender == textField_) {
[sender resignFirstResponder];
}
return NO;
}
-(void)animationSelector
{
id eglView = [EAGLView sharedEGLView];
[eglView doAnimationWhenAnotherEditBeClicked];
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)sender // return NO to disallow editing.
{
editState_ = YES;
id eglView = [EAGLView sharedEGLView];
if ([eglView isKeyboardShown])
{
[self performSelector:@selector(animationSelector) withObject:nil afterDelay:0.0f];
}
return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)sender
{
editState_ = NO;
return YES;
}
/**
* Delegate method called before the text has been changed.
* @param textField The text field containing the text.
* @param range The range of characters to be replaced.
* @param string The replacement string.
* @return YES if the specified text range should be replaced; otherwise, NO to keep the old text.
*/
- (BOOL)textField:(UITextField *) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (getEditBoxImplIOS()->getMaxLength() < 0)
{
return YES;
}
NSUInteger oldLength = [textField.text length];
NSUInteger replacementLength = [string length];
NSUInteger rangeLength = range.length;
NSUInteger newLength = oldLength - rangeLength + replacementLength;
return newLength <= getEditBoxImplIOS()->getMaxLength();
}
/**
* Called each time when the text field's text has changed.
*/
- (void) textChanged
{
NSLog(@"text is %@", self.textField.text);
cocos2d::extension::CCEditBoxDelegate* pDelegate = getEditBoxImplIOS()->getDelegate();
if (pDelegate != NULL)
{
pDelegate->editBoxTextChanged(getEditBoxImplIOS()->getCCEditBox(), getEditBoxImplIOS()->getText());
}
}
@end

View File

@ -27,6 +27,7 @@
#include "GUI/CCControlExtension/CCControlExtensions.h" #include "GUI/CCControlExtension/CCControlExtensions.h"
#include "GUI/CCScrollView/CCScrollView.h" #include "GUI/CCScrollView/CCScrollView.h"
#include "GUI/CCEditBox/CCEditBox.h"
#include "network/HttpRequest.h" #include "network/HttpRequest.h"
#include "network/HttpResponse.h" #include "network/HttpResponse.h"

View File

@ -25,7 +25,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
if (!CCDirector::sharedDirector()->getOpenGLView()) if (!CCDirector::sharedDirector()->getOpenGLView())
{ {
CCEGLView *view = &CCEGLView::sharedOpenGLView(); CCEGLView *view = &CCEGLView::sharedOpenGLView();
view->setSize(w, h); view->setFrameSize(w, h);
AppDelegate *pAppDelegate = new AppDelegate(); AppDelegate *pAppDelegate = new AppDelegate();
CCApplication::sharedApplication().run(); CCApplication::sharedApplication().run();

View File

@ -15,6 +15,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
// create the application instance // create the application instance
AppDelegate app; AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView(); CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setSize(960, 640 ); eglView.setFrameSize(960, 640 );
return CCApplication::sharedApplication().run(); return CCApplication::sharedApplication().run();
} }

View File

@ -24,7 +24,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
if (!CCDirector::sharedDirector()->getOpenGLView()) if (!CCDirector::sharedDirector()->getOpenGLView())
{ {
CCEGLView *view = &CCEGLView::sharedOpenGLView(); CCEGLView *view = &CCEGLView::sharedOpenGLView();
view->setSize(w, h); view->setFrameSize(w, h);
AppDelegate *pAppDelegate = new AppDelegate(); AppDelegate *pAppDelegate = new AppDelegate();
CCApplication::sharedApplication().run(); CCApplication::sharedApplication().run();

View File

@ -25,7 +25,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
// create the application instance // create the application instance
AppDelegate app; AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView(); CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setSize(480, 320); eglView.setFrameSize(480, 320);
int ret = CCApplication::sharedApplication().run(); int ret = CCApplication::sharedApplication().run();
#ifdef USE_WIN32_CONSOLE #ifdef USE_WIN32_CONSOLE

View File

@ -0,0 +1,69 @@
//
// CCEditBoxTest.cpp
// TestCpp
//
// Created by James on 8/14/12.
//
//
#include "EditBoxTest.h"
#include "../ExtensionsTest.h"
USING_NS_CC;
USING_NS_CC_EXT;
EditBoxTest::EditBoxTest()
{
CCPoint visibleOrigin = CCEGLView::sharedOpenGLView().getVisibleOrigin();
CCSize visibleSize = CCEGLView::sharedOpenGLView().getVisibleSize();
CCSprite* pBg = CCSprite::create("Images/HelloWorld.png");
pBg->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2));
addChild(pBg);
// Back Menu
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(EditBoxTest::toExtensionsMainLayer));
itemBack->setPosition(ccp(visibleOrigin.x+visibleSize.width - 50, visibleOrigin.y+25));
CCMenu *menuBack = CCMenu::create(itemBack, NULL);
menuBack->setPosition(CCPointZero);
addChild(menuBack);
CCSize editBoxSize = CCSizeMake(visibleSize.width/3, visibleSize.height/8);
CCEditBox* pEdit = NULL;
// top
pEdit = CCEditBox::create(editBoxSize);
pEdit->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/4));
addChild(pEdit);
// middle
pEdit = CCEditBox::create(editBoxSize);
pEdit->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2));
addChild(pEdit);
// bottom
pEdit = CCEditBox::create(editBoxSize);
pEdit->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height*3/4));
addChild(pEdit);
}
EditBoxTest::~EditBoxTest()
{
}
void EditBoxTest::toExtensionsMainLayer(cocos2d::CCObject *sender)
{
ExtensionsTestScene *pScene = new ExtensionsTestScene();
pScene->runThisTest();
pScene->release();
}
void runEditBoxTest()
{
CCScene *pScene = CCScene::create();
EditBoxTest *pLayer = new EditBoxTest();
pScene->addChild(pLayer);
CCDirector::sharedDirector()->replaceScene(pScene);
pLayer->release();
}

View File

@ -0,0 +1,28 @@
//
// CCEditBoxTest.h
// TestCpp
//
// Created by James on 8/14/12.
//
//
#ifndef __TestCpp__CCEditBoxTest__
#define __TestCpp__CCEditBoxTest__
#include "cocos2d.h"
#include "cocos-ext.h"
class EditBoxTest : public cocos2d::CCLayer
{
public:
EditBoxTest();
virtual ~EditBoxTest();
void toExtensionsMainLayer(cocos2d::CCObject *sender);
private:
};
void runEditBoxTest();
#endif /* defined(__TestCpp__CCEditBoxTest__) */

View File

@ -4,6 +4,9 @@
#include "ControlExtensionTest/CCControlSceneManager.h" #include "ControlExtensionTest/CCControlSceneManager.h"
#include "CocosBuilderTest/CocosBuilderTest.h" #include "CocosBuilderTest/CocosBuilderTest.h"
#include "NetworkTest/HttpClientTest.h" #include "NetworkTest/HttpClientTest.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "EditBoxTest/EditBoxTest.h"
#endif
enum enum
{ {
@ -17,6 +20,9 @@ enum
TEST_CCCONTROLBUTTON, TEST_CCCONTROLBUTTON,
TEST_COCOSBUILDER, TEST_COCOSBUILDER,
TEST_HTTPCLIENT, TEST_HTTPCLIENT,
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
TEST_EDITBOX,
#endif
TEST_MAX_COUNT, TEST_MAX_COUNT,
}; };
@ -26,6 +32,9 @@ static const std::string testsName[TEST_MAX_COUNT] =
"CCControlButtonTest", "CCControlButtonTest",
"CocosBuilderTest", "CocosBuilderTest",
"HttpClientTest", "HttpClientTest",
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
"EditBoxTest"
#endif
}; };
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
@ -87,6 +96,14 @@ void ExtensionsMainLayer::menuCallback(CCObject* pSender)
{ {
runHttpClientTest(); runHttpClientTest();
} }
break;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
case TEST_EDITBOX:
{
runEditBoxTest();
}
break;
#endif
default: default:
break; break;
} }

View File

@ -25,7 +25,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
if (!CCDirector::sharedDirector()->getOpenGLView()) if (!CCDirector::sharedDirector()->getOpenGLView())
{ {
CCEGLView *view = &CCEGLView::sharedOpenGLView(); CCEGLView *view = &CCEGLView::sharedOpenGLView();
view->setSize(w, h); view->setFrameSize(w, h);
AppDelegate *pAppDelegate = new AppDelegate(); AppDelegate *pAppDelegate = new AppDelegate();
CCApplication::sharedApplication().run(); CCApplication::sharedApplication().run();

View File

@ -1 +1 @@
86f6b6c3837508de917c08ed3e087b901da16e27 9dc4229a0e1a4577d300081dc8e3abc2a1e2f1f2

View File

@ -15,6 +15,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
// create the application instance // create the application instance
AppDelegate app; AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView(); CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setSize(480, 320); eglView.setFrameSize(480, 320);
return CCApplication::sharedApplication().run(); return CCApplication::sharedApplication().run();
} }

View File

@ -25,7 +25,7 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
if (!CCDirector::sharedDirector()->getOpenGLView()) if (!CCDirector::sharedDirector()->getOpenGLView())
{ {
CCEGLView *view = &CCEGLView::sharedOpenGLView(); CCEGLView *view = &CCEGLView::sharedOpenGLView();
view->setSize(w, h); view->setFrameSize(w, h);
AppDelegate *pAppDelegate = new AppDelegate(); AppDelegate *pAppDelegate = new AppDelegate();
CCApplication::sharedApplication().run(); CCApplication::sharedApplication().run();

View File

@ -25,7 +25,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
// create the application instance // create the application instance
AppDelegate app; AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView(); CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setSize(480, 320); eglView.setFrameSize(480, 320);
int ret = CCApplication::sharedApplication().run(); int ret = CCApplication::sharedApplication().run();