Skip to content

Commit

Permalink
Fixes issue cocos2d#1313 2nd part.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoquesada committed Feb 14, 2012
1 parent 7c4895b commit 0ddb5a2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 37 deletions.
3 changes: 3 additions & 0 deletions cocos2d/CCDirector.h
Expand Up @@ -146,6 +146,9 @@ and when to execute the Scenes.

/* action manager associated with this director */
CCActionManager *actionManager_;

/* OpenGLView. On iOS it is a copy of self.view */
CCGLView *view_;
}

/** returns the cocos2d thread.
Expand Down
35 changes: 21 additions & 14 deletions cocos2d/CCDirector.m
Expand Up @@ -174,7 +174,7 @@ - (id) init

- (NSString*) description
{
return [NSString stringWithFormat:@"<%@ = %08X | Size: %0.f x %0.f, view = %@>", [self class], self, winSizeInPoints_.width, winSizeInPoints_.height, self.view];
return [NSString stringWithFormat:@"<%@ = %08X | Size: %0.f x %0.f, view = %@>", [self class], self, winSizeInPoints_.width, winSizeInPoints_.height, view_];
}

- (void) dealloc
Expand All @@ -198,8 +198,8 @@ - (void) dealloc

-(void) setGLDefaultValues
{
// This method SHOULD be called only after openGLView_ was initialized
NSAssert( [self view], @"openGLView_ must be initialized");
// This method SHOULD be called only after view_ was initialized
NSAssert( view_, @"view_ must be initialized");

[self setAlphaBlending: YES];
[self setDepthTest: YES];
Expand Down Expand Up @@ -300,28 +300,34 @@ - (void) setDepthTest: (BOOL) on

-(void) setView:(CCGLView*)view
{
NSAssert( view, @"OpenGLView must be non-nil");
// NSAssert( view, @"OpenGLView must be non-nil");

if( view != view_ ) {

#ifdef __CC_PLATFORM_IOS
[super setView:view];
[super setView:view];
#endif
[view_ release];
view_ = [view retain];

// set size
winSizeInPixels_ = winSizeInPoints_ = CCNSSizeToCGSize( [view bounds].size );
// set size
winSizeInPixels_ = winSizeInPoints_ = CCNSSizeToCGSize( [view_ bounds].size );

[self setGLDefaultValues];
[self createStatsLabel];
[self createStatsLabel];

// it could be nil
if( view )
[self setGLDefaultValues];

CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
}
}

#ifdef __CC_PLATFORM_MAC
-(CCGLView*) view
{
// ignore on Mac
return nil;
return view_;
}
#endif //


#pragma mark Director Scene Landscape

Expand Down Expand Up @@ -422,6 +428,7 @@ -(void) end
[delegate_ release];
delegate_ = nil;

[self setView:nil];

// Purge bitmap cache
[CCLabelBMFont purgeCachedData];
Expand Down
3 changes: 0 additions & 3 deletions cocos2d/Platforms/Mac/CCDirectorMac.h
Expand Up @@ -61,9 +61,6 @@ enum {

NSWindow *fullScreenWindow_;

// OpenGLView
CCGLView *view_;

// Event Dispatcher
CCEventDispatcher *eventDispatcher_;

Expand Down
8 changes: 0 additions & 8 deletions cocos2d/Platforms/Mac/CCDirectorMac.m
Expand Up @@ -195,9 +195,6 @@ -(void) setView:(CCGLView *)view
{
if( view != view_) {

[view_ release];
view_ = [view retain];

[super setView:view];

// cache the NSWindow and NSOpenGLView created from the NIB
Expand All @@ -208,11 +205,6 @@ -(void) setView:(CCGLView *)view
}
}

-(CCGLView*) view
{
return view_;
}

-(int) resizeMode
{
return resizeMode_;
Expand Down
26 changes: 14 additions & 12 deletions cocos2d/Platforms/iOS/CCDirectorIOS.m
Expand Up @@ -266,7 +266,7 @@ -(void) setContentScaleFactor:(CGFloat)scaleFactor
__ccContentScaleFactor = scaleFactor;
winSizeInPixels_ = CGSizeMake( winSizeInPoints_.width * scaleFactor, winSizeInPoints_.height * scaleFactor );

if( self.view )
if( view_ )
[self updateContentScaleFactor];

// update projection
Expand All @@ -276,9 +276,9 @@ -(void) setContentScaleFactor:(CGFloat)scaleFactor

-(void) updateContentScaleFactor
{
NSAssert( [self.view respondsToSelector:@selector(setContentScaleFactor:)], @"cocos2d v2.0+ runs on iOS 4 or later");
NSAssert( [view_ respondsToSelector:@selector(setContentScaleFactor:)], @"cocos2d v2.0+ runs on iOS 4 or later");

[self.view setContentScaleFactor: __ccContentScaleFactor];
[view_ setContentScaleFactor: __ccContentScaleFactor];
isContentScaleSupported_ = YES;
}

Expand All @@ -293,7 +293,7 @@ -(BOOL) enableRetinaDisplay:(BOOL)enabled
return YES;

// setContentScaleFactor is not supported
if (! [self.view respondsToSelector:@selector(setContentScaleFactor:)])
if (! [view_ respondsToSelector:@selector(setContentScaleFactor:)])
return NO;

// SD device
Expand All @@ -312,7 +312,7 @@ -(BOOL) enableRetinaDisplay:(BOOL)enabled
// overriden, don't call super
-(void) reshapeProjection:(CGSize)size
{
winSizeInPoints_ = [self.view bounds].size;
winSizeInPoints_ = [view_ bounds].size;
winSizeInPixels_ = CGSizeMake(winSizeInPoints_.width * __ccContentScaleFactor, winSizeInPoints_.height *__ccContentScaleFactor);

[self setProjection:projection_];
Expand Down Expand Up @@ -350,16 +350,18 @@ -(void) end

-(void) setView:(CCGLView *)view
{
[super setView:view];
if( view != view_) {
[super setView:view];

// set size
winSizeInPixels_ = CGSizeMake(winSizeInPoints_.width * __ccContentScaleFactor, winSizeInPoints_.height *__ccContentScaleFactor);
// set size
winSizeInPixels_ = CGSizeMake(winSizeInPoints_.width * __ccContentScaleFactor, winSizeInPoints_.height *__ccContentScaleFactor);

if( __ccContentScaleFactor != 1 )
[self updateContentScaleFactor];
if( __ccContentScaleFactor != 1 )
[self updateContentScaleFactor];

[view setTouchDelegate: touchDispatcher_];
[touchDispatcher_ setDispatchEvents: YES];
[view setTouchDelegate: touchDispatcher_];
[touchDispatcher_ setDispatchEvents: YES];
}
}

// Override to allow orientations other than the default portrait orientation.
Expand Down

0 comments on commit 0ddb5a2

Please sign in to comment.