Adds descriptions to Sparrow objects so missing. Some attempts at dealing with the...
authordsc <david.schoonover@gmail.com>
Mon, 6 Jun 2011 18:44:58 +0000 (11:44 -0700)
committerdsc <david.schoonover@gmail.com>
Mon, 6 Jun 2011 18:44:58 +0000 (11:44 -0700)
libs/sparrow/src/Classes/SPDisplayObject.m
libs/sparrow/src/Classes/SPMacros.h
libs/sparrow/src/Classes/SPMatrix.h
libs/sparrow/src/Classes/SPMatrix.m
libs/sparrow/src/Classes/SPQuad.m
libs/sparrow/src/Classes/SPRectangle.m
libs/sparrow/src/Classes/SPStage.m
libs/sparrow/src/Classes/SPTouch.m
libs/sparrow/src/Classes/SPTouchEvent.m

index fb72245..d90ee07 100644 (file)
         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];
     
 }
 
 - (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
+        ];
 }
 
 
index aea1b3e..6eb4108 100644 (file)
@@ -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"))
index 7ca72df..8de74e5 100644 (file)
@@ -50,6 +50,8 @@
 /// Factory method.
 + (SPMatrix*)matrixWithIdentity;
 
++ (SPMatrix*) matrixWithRotation:(float)angle;
+
 /// -------------
 /// @name Methods
 /// -------------
index 2e83df0..130224c 100644 (file)
@@ -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;
index 5285a21..ed099f3 100644 (file)
     return [self initWithWidth:width height:height color:SP_WHITE];
 }
 
-- (id)init
-{    
-    return [self initWithWidth:32 height:32];
-}
 
 - (SPRectangle*)boundsInSpace:(SPDisplayObject*)targetCoordinateSpace
 {
index 0a00da7..1f9ac77 100644 (file)
 
 - (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
index f767c3e..ae4365d 100644 (file)
@@ -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
 
 // -------------------------------------------------------------------------------------------------
index 7e04083..5cfb82d 100644 (file)
     }
 }
 
+- (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];
index 5d895a5..187b55a 100644 (file)
     return [[[SPTouchEvent alloc] initWithType:type touches:touches] autorelease];
 }
 
+- (NSString*) description {
+    return [NSString stringWithFormat:@"<%@: %p> {touches=%@}",
+            [self class], self, self.touches];
+}
+
+
 @end