From: dsc Date: Mon, 6 Jun 2011 18:44:58 +0000 (-0700) Subject: Adds descriptions to Sparrow objects so missing. Some attempts at dealing with the... X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=8ad9263171dad5df78dae75d882fbe85b3b95b95;p=tanks-ios.git Adds descriptions to Sparrow objects so missing. Some attempts at dealing with the registration debacle. --- diff --git a/libs/sparrow/src/Classes/SPDisplayObject.m b/libs/sparrow/src/Classes/SPDisplayObject.m index fb72245..d90ee07 100644 --- a/libs/sparrow/src/Classes/SPDisplayObject.m +++ b/libs/sparrow/src/Classes/SPDisplayObject.m @@ -303,6 +303,15 @@ if (regMatters) [matrix translateXBy:mRegX yBy:mRegY]; [matrix rotateBy:mRotationZ]; if (regMatters) [matrix translateXBy:-mRegX yBy:-mRegY]; + + // if (mRegX != 0.0f || mRegY != 0.0f) { + // [matrix translateXBy:mRegX yBy:mRegY]; + // SPMatrix* origin = [SPMatrix matrixWithRotation:mRotationZ]; + // SPPoint* reg = [origin transformPoint:[SPPoint pointWithX:-mRegX y:-mRegY]]; + // [matrix rotateBy:mRotationZ]; + // [matrix translateXBy:reg.x yBy:reg.y]; + // } else + // [matrix rotateBy:mRotationZ]; } if (mScaleX != 1.0f || mScaleY != 1.0f) [matrix scaleXBy:mScaleX yBy:mScaleY]; @@ -310,8 +319,14 @@ } - (NSString*) description { - return [NSString stringWithFormat:@"[%@ pos=(%f,%f), rotation=%f @ (%f,%f), scale=(%f,%f)]", - [super description], self.x,self.y, self.rotation, self.registrationX,self.registrationY, self.scaleX,self.scaleY]; + SPDisplayObjectContainer* parent = self.parent; + return [NSString stringWithFormat:@"<%@: %p> {name=%@, global=%@, local=(%.3f,%.3f), scale=(%.3f,%.3f), rotation=%.3f @ (%.3f,%.3f), visible=%s @ %.3f, touchable=%s, parent=<%@: %p>}", + [self class], self, self.name, + self.bounds, self.x,self.y, self.scaleX,self.scaleY, + self.rotation, self.registrationX,self.registrationY, + SP_B2S(self.visible), self.alpha, SP_B2S(self.touchable), + (parent ? [parent class] : NULL), parent + ]; } diff --git a/libs/sparrow/src/Classes/SPMacros.h b/libs/sparrow/src/Classes/SPMacros.h index aea1b3e..6eb4108 100644 --- a/libs/sparrow/src/Classes/SPMacros.h +++ b/libs/sparrow/src/Classes/SPMacros.h @@ -49,8 +49,8 @@ #define SP_COLOR_PART_GREEN(color) (((color) >> 8) & 0xff) #define SP_COLOR_PART_BLUE(color) ( (color) & 0xff) -#define SP_COLOR(r, g, b) (((r) << 16) | ((g) << 8) | (b)) +#define SP_COLOR(r, g, b) (((r) << 16) | ((g) << 8) | (b)) #define SP_IS_FLOAT_EQUAL(f1, f2) (fabsf((f1)-(f2)) < SP_FLOAT_EPSILON) - +#define SP_B2S(__val) ((__val)?("YES"):("NO")) diff --git a/libs/sparrow/src/Classes/SPMatrix.h b/libs/sparrow/src/Classes/SPMatrix.h index 7ca72df..8de74e5 100644 --- a/libs/sparrow/src/Classes/SPMatrix.h +++ b/libs/sparrow/src/Classes/SPMatrix.h @@ -50,6 +50,8 @@ /// Factory method. + (SPMatrix*)matrixWithIdentity; ++ (SPMatrix*) matrixWithRotation:(float)angle; + /// ------------- /// @name Methods /// ------------- diff --git a/libs/sparrow/src/Classes/SPMatrix.m b/libs/sparrow/src/Classes/SPMatrix.m index 2e83df0..130224c 100644 --- a/libs/sparrow/src/Classes/SPMatrix.m +++ b/libs/sparrow/src/Classes/SPMatrix.m @@ -74,7 +74,7 @@ static void setValues(SPMatrix *matrix, float a, float b, float c, float d, floa - (void)translateXBy:(float)dx yBy:(float)dy { mTx += dx; - mTy += dy; + mTy += dy; } - (void)scaleXBy:(float)sx yBy:(float)sy @@ -97,7 +97,7 @@ static void setValues(SPMatrix *matrix, float a, float b, float c, float d, floa SPMatrix *rotMatrix = [[SPMatrix alloc] initWithA:cosf(angle) b:sinf(angle) c:-sinf(angle) d:cosf(angle) tx:0 ty:0]; [self concatMatrix:rotMatrix]; - [rotMatrix release]; + [rotMatrix release]; } - (void)identity @@ -114,6 +114,9 @@ static void setValues(SPMatrix *matrix, float a, float b, float c, float d, floa - (void)invert { float det = self.determinant; + // XXX: isn't this wrong? shouldn't it be... + // setValues(self, mD/det, -mC/det, -mB/det, mA/det, (mC*mTy-mD*mTx)/det, (mB*mTx-mA*mTy)/det); + // not... setValues(self, mD/det, -mB/det, -mC/det, mA/det, (mC*mTy-mD*mTx)/det, (mB*mTx-mA*mTy)/det); } @@ -146,6 +149,10 @@ static void setValues(SPMatrix *matrix, float a, float b, float c, float d, floa return [[[SPMatrix alloc] init] autorelease]; } ++ (SPMatrix*) matrixWithRotation:(float)angle { + return [[[SPMatrix alloc] initWithA:cosf(angle) b:sinf(angle) c:-sinf(angle) d:cosf(angle) tx:0 ty:0] autorelease]; +} + #pragma mark NSCopying - (id)copyWithZone:(NSZone*)zone; diff --git a/libs/sparrow/src/Classes/SPQuad.m b/libs/sparrow/src/Classes/SPQuad.m index 5285a21..ed099f3 100644 --- a/libs/sparrow/src/Classes/SPQuad.m +++ b/libs/sparrow/src/Classes/SPQuad.m @@ -39,10 +39,6 @@ return [self initWithWidth:width height:height color:SP_WHITE]; } -- (id)init -{ - return [self initWithWidth:32 height:32]; -} - (SPRectangle*)boundsInSpace:(SPDisplayObject*)targetCoordinateSpace { diff --git a/libs/sparrow/src/Classes/SPRectangle.m b/libs/sparrow/src/Classes/SPRectangle.m index 0a00da7..1f9ac77 100644 --- a/libs/sparrow/src/Classes/SPRectangle.m +++ b/libs/sparrow/src/Classes/SPRectangle.m @@ -117,7 +117,7 @@ - (NSString*)description { - return [NSString stringWithFormat:@"(x: %f, y: %f, width: %f, height: %f)", mX, mY, mWidth, mHeight]; + return [NSString stringWithFormat:@"[SPRect (%.3f,%.3f) w=%f, h=%f]", mX, mY, mWidth, mHeight]; } + (SPRectangle*)rectangleWithX:(float)x y:(float)y width:(float)width height:(float)height diff --git a/libs/sparrow/src/Classes/SPStage.m b/libs/sparrow/src/Classes/SPStage.m index f767c3e..ae4365d 100644 --- a/libs/sparrow/src/Classes/SPStage.m +++ b/libs/sparrow/src/Classes/SPStage.m @@ -162,6 +162,12 @@ static NSMutableArray *stages = NULL; [super dealloc]; } +- (NSString*) description { + return [NSString stringWithFormat:@"<%@: %p> {pos=(%.3f,%.3f), width=%.3f, height=%.3f}", + [self class], self, self.x,self.y, self.width, self.height]; +} + + @end // ------------------------------------------------------------------------------------------------- diff --git a/libs/sparrow/src/Classes/SPTouch.m b/libs/sparrow/src/Classes/SPTouch.m index 7e04083..5cfb82d 100644 --- a/libs/sparrow/src/Classes/SPTouch.m +++ b/libs/sparrow/src/Classes/SPTouch.m @@ -100,6 +100,12 @@ } } +- (NSString*) description { + return [NSString stringWithFormat:@"<%@: %p> {global=(%.3f,%.3f), tapCount=%i, timestamp=%f, target=%@}", + [self class], self, self.globalX,self.globalY, self.tapCount, self.timestamp, self.target]; +} + + + (SPTouch*)touch { return [[[SPTouch alloc] init] autorelease]; diff --git a/libs/sparrow/src/Classes/SPTouchEvent.m b/libs/sparrow/src/Classes/SPTouchEvent.m index 5d895a5..187b55a 100644 --- a/libs/sparrow/src/Classes/SPTouchEvent.m +++ b/libs/sparrow/src/Classes/SPTouchEvent.m @@ -89,4 +89,10 @@ return [[[SPTouchEvent alloc] initWithType:type touches:touches] autorelease]; } +- (NSString*) description { + return [NSString stringWithFormat:@"<%@: %p> {touches=%@}", + [self class], self, self.touches]; +} + + @end