[Chlor-commits] SF.net SVN: chlor: [319] trunk/src
Status: Pre-Alpha
Brought to you by:
lenny222
From: <chl...@li...> - 2006-03-20 21:51:17
|
Revision: 319 Author: wzdrg Date: 2006-03-20 13:50:55 -0800 (Mon, 20 Mar 2006) ViewCVS: http://svn.sourceforge.net/chlor/?rev=319&view=rev Log Message: ----------- Moved shape construction to CShape file Modified Paths: -------------- trunk/src/CColorSelectView.m trunk/src/CEllipseTool.m trunk/src/CPolygonTool.m trunk/src/CRectangleTool.m trunk/src/CRoundRectTool.m trunk/src/CStarTool.m trunk/src/Chlor.xcodeproj/project.pbxproj trunk/src/core/CNode.h trunk/src/core/CNode.m trunk/src/core/CPath.h trunk/src/core/CPath.m trunk/src/core/CRect.h trunk/src/core/CRect.m trunk/src/io/pdf/CPdfImport.m trunk/src/io/svg/CSvgImport.m Modified: trunk/src/CColorSelectView.m =================================================================== --- trunk/src/CColorSelectView.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/CColorSelectView.m 2006-03-20 21:50:55 UTC (rev 319) @@ -26,14 +26,16 @@ #import "CSolidFill.h" #import "CStroke.h" +#import "CShape.h" + @implementation CColorSelectView - (id) initWithFrame: (NSRect) frameRect { if( ( self = [super initWithFrame: frameRect] ) != nil ) { - m_fillRepresentation = [[CPath rectangleLeft: 20.0 Bottom: 1.0 Width:30.0 Height: 30.0] retain]; - m_strokeRepresentation = [[CPath rectangleLeft: 1.0 Bottom: 20.0 Width: 30.0 Height: 30.0] retain]; + m_fillRepresentation = [[CShape rectangleLeft: 20.0 Bottom: 1.0 Width:30.0 Height: 30.0] retain]; + m_strokeRepresentation = [[CShape rectangleLeft: 1.0 Bottom: 20.0 Width: 30.0 Height: 30.0] retain]; // TODO: Remove test code. CSolidFill* fill = [[CSolidFill alloc] init]; Modified: trunk/src/CEllipseTool.m =================================================================== --- trunk/src/CEllipseTool.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/CEllipseTool.m 2006-03-20 21:50:55 UTC (rev 319) @@ -20,6 +20,7 @@ #import "CEllipseTool.h" #import "CPath.h" #import "CRect.h" +#import "CShape.h" @implementation CEllipseTool @@ -38,11 +39,7 @@ if( !m_shape ) { m_shape = - [CPath - ellipseLeft: [m_rect left] - Bottom: [m_rect bottom] - Width: [m_rect width] - Height: [m_rect height]]; + [CShape ellipseWithinRectangle:m_rect]; [m_shape retain]; } Modified: trunk/src/CPolygonTool.m =================================================================== --- trunk/src/CPolygonTool.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/CPolygonTool.m 2006-03-20 21:50:55 UTC (rev 319) @@ -19,6 +19,7 @@ #import "CPath.h" #import "CPolygonTool.h" +#import "CShape.h" @implementation CPolygonTool @@ -37,7 +38,7 @@ if( !m_shape ) { m_shape = - [CPath + [CShape polygonX: m_x Y: m_y Radius: m_radius Modified: trunk/src/CRectangleTool.m =================================================================== --- trunk/src/CRectangleTool.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/CRectangleTool.m 2006-03-20 21:50:55 UTC (rev 319) @@ -20,6 +20,7 @@ #import "CPath.h" #import "CRect.h" #import "CRectangleTool.h" +#import "CShape.h" @implementation CRectangleTool @@ -38,7 +39,7 @@ if( !m_shape ) { m_shape = - [CPath + [CShape rectangleLeft: [m_rect left] Bottom: [m_rect bottom] Width: [m_rect width] Modified: trunk/src/CRoundRectTool.m =================================================================== --- trunk/src/CRoundRectTool.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/CRoundRectTool.m 2006-03-20 21:50:55 UTC (rev 319) @@ -20,6 +20,7 @@ #import "CPath.h" #import "CRect.h" #import "CRoundRectTool.h" +#import "CShape.h" @implementation CRoundRectTool @@ -38,7 +39,7 @@ if( !m_shape ) { m_shape = - [CPath + [CShape roundRectLeft: [m_rect left] Bottom: [m_rect bottom] Width: [m_rect width] Modified: trunk/src/CStarTool.m =================================================================== --- trunk/src/CStarTool.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/CStarTool.m 2006-03-20 21:50:55 UTC (rev 319) @@ -20,6 +20,7 @@ #import "CPath.h" #import "CRect.h" #import "CStarTool.h" +#import "CShape.h" @implementation CStarTool @@ -38,7 +39,7 @@ if( !m_shape ) { m_shape = - [CPath + [CShape starX: m_x Y: m_y OuterRadius: m_radius Modified: trunk/src/Chlor.xcodeproj/project.pbxproj =================================================================== (Binary files differ) Modified: trunk/src/core/CNode.h =================================================================== --- trunk/src/core/CNode.h 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/core/CNode.h 2006-03-20 21:50:55 UTC (rev 319) @@ -31,19 +31,56 @@ BOOL m_selected; } -// Initialize the node with a point +/** + * Factory method construct a node with a point + + * @param point Point + */ ++ (CNode *) nodeWithPoint:(CPoint *)point; + + +/** + * Factory method + * Construct a node with x and y coordinates + * + * @param x X coordinate + * @param y Y coordinate + */ ++ (CNode *) nodeWithX:(double)x andY:(double)y; + + +/** + * Initialize the node with a point + * + * @param point Point + */ - (id) initWithPoint:(CPoint *)point; + + +/** + * Initialize the node with x and y coordinate + * + * @param x X coordinate + * @param y Y coordinate + */ - (id) initWithX: (double)x Y: (double)y; -// X coordinate of the node + +/** + * @return X coordinate of the node + */ - (double) x; -// Y coordinate of the node + +/** + * @return Y coordinate of the node + */ - (double) y; // Point - (CPoint *) point; + // Move node to new coordinate - (void) moveToX:(double)x andY:(double)y; - (void) moveToPoint:(CPoint *)point; Modified: trunk/src/core/CNode.m =================================================================== --- trunk/src/core/CNode.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/core/CNode.m 2006-03-20 21:50:55 UTC (rev 319) @@ -21,6 +21,22 @@ @implementation CNode ++ (CNode *) nodeWithX:(double)x andY:(double)y +{ + CNode * result = [[CNode alloc] initWithX:x Y:y]; + [result autorelease]; + return result; +} + + ++ (CNode *) nodeWithPoint:(CPoint *)point +{ + CNode* result = [[CNode alloc] initWithPoint:point]; + [result autorelease]; + return result; +} + + - (id) initWithX: (double)x Y: (double)y { if (self = [super init]) Modified: trunk/src/core/CPath.h =================================================================== --- trunk/src/core/CPath.h 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/core/CPath.h 2006-03-20 21:50:55 UTC (rev 319) @@ -96,40 +96,8 @@ { } -+ (CPath*) - ellipseLeft: (double) left - Bottom: (double) bottom - Width: (double) width - Height: (double) height; -+ (CPath*) - polygonX: (double) x - Y: (double) y - Radius: (double) radius - Edges: (int) edges - Angle: (double) startAngle; -+ (CPath*) - rectangleLeft: (double) left - Bottom: (double) bottom - Width: (double) width - Height: (double) height; - -+ (CPath*) - roundRectLeft: (double) left - Bottom: (double) bottom - Width: (double) width - Height: (double) height - Radius: (double) theRadius; - -+ (CPath*) - starX: (double) x - Y: (double) y - OuterRadius: (double) outerRadius - InnerRadius: (double) innerRadius - Edges: (int) edges - Angle: (double) startAngle; - - (CPath*) arcToX: (double) x Y: (double) y Modified: trunk/src/core/CPath.m =================================================================== --- trunk/src/core/CPath.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/core/CPath.m 2006-03-20 21:50:55 UTC (rev 319) @@ -403,145 +403,6 @@ [aVisitor visitPath: self]; } -+ (CPath*) - ellipseLeft: (double) left - Bottom: (double) bottom - Width: (double) width - Height: (double) height -{ - // Create circle with radius 0.5 and bottom left (0, 0). - CPath* path = [[CPath alloc] init]; - - [path moveToX: 0.0 Y: 0.5]; - [path arcToX: 0.5 Y: 0.0 TanX: 0.0 TanY: 0.0 Radius: 0.5]; - [path arcToX: 1.0 Y: 0.5 TanX: 1.0 TanY: 0.0 Radius: 0.5]; - [path arcToX: 0.5 Y: 1.0 TanX: 1.0 TanY: 1.0 Radius: 0.5]; - [path arcToX: 0.0 Y: 0.5 TanX: 0.0 TanY: 1.0 Radius: 0.5]; - [path close]; - - // Scale and translate to final position. - CAffineTrafo* trafo = [[CAffineTrafo alloc] init]; - [[trafo affineMap] scaleX: width Y: height]; - [[trafo affineMap] translateX: left Y: bottom]; - [trafo visit: path]; - [trafo release]; - - return [path autorelease]; -} - -+ (CPath*) - polygonX: (double) x - Y: (double) y - Radius: (double) radius - Edges: (int) edges - Angle: (double) startAngle -{ - CPath* path = [[CPath alloc] init]; - double a; - const double offset = startAngle + M_PI_2; - const double incr = 2 * M_PI / edges; - - a = offset; - [path - moveToX: radius * cos( a ) + x - Y: radius * sin( a ) + y]; - - int i; - for( i = 0; i < edges; ++i ) - { - a = offset + incr * ( i + 1.0 ); - [path - lineToX: radius * cos( a ) + x - Y: radius * sin( a ) + y]; - } - - [path close]; - - return [path autorelease]; -} - -+ (CPath*) - rectangleLeft: (double) left - Bottom: (double) bottom - Width: (double) width - Height: (double) height -{ - CPath* path = [[CPath alloc] init]; - - [path moveToX: left Y: bottom]; - [path lineToX: left + width Y: bottom]; - [path lineToX: left + width Y: bottom + height]; - [path lineToX: left Y: bottom + height]; - [path close]; - - return [path autorelease]; -} - -+ (CPath*) - roundRectLeft: (double) left - Bottom: (double) bottom - Width: (double) width - Height: (double) height - Radius: (double) radius -{ - // Adapt radius if it is larger then width or height. - if( radius > width * 0.5 ) - radius = width * 0.5; - - if( radius > height * 0.5 ) - radius = height * 0.5; - - CPath* path = [[CPath alloc] init]; - - [path moveToX: left Y: bottom + height - radius]; - [path - arcToX: left + radius Y: bottom - TanX: left TanY: bottom Radius: radius]; - [path - arcToX: left + width Y: bottom + radius - TanX: left + width TanY: bottom Radius: radius]; - [path - arcToX: left + width - radius Y: bottom + height - TanX: left + width TanY: bottom + height Radius: radius]; - [path - arcToX: left Y: bottom + height - radius - TanX: left TanY: bottom + height Radius: radius]; - [path close]; - - return [path autorelease]; -} - -+ (CPath*) - starX: (double) x - Y: (double) y - OuterRadius: (double) outerRadius - InnerRadius: (double) innerRadius - Edges: (int) edges - Angle: (double) startAngle -{ - CPath* path = [[CPath alloc] init]; - double a; - const double offset = startAngle + M_PI_2; - const double incr = 2 * M_PI / edges; - - a = offset; - [path moveToX: outerRadius * cos( a ) + x Y: outerRadius * sin( a ) + y]; - - int i; - for( i = 0; i < edges; ++i ) - { - a = offset + incr * ( i + 0.5 ); - [path lineToX: innerRadius * cos( a ) + x Y: innerRadius * sin( a ) + y]; - - a = offset + incr * ( i + 1.0 ); - [path lineToX: outerRadius * cos( a ) + x Y: outerRadius * sin( a ) + y]; - } - - [path close]; - - return [path autorelease]; -} - - (CPath*) arcToX: (double) x Y: (double) y Modified: trunk/src/core/CRect.h =================================================================== --- trunk/src/core/CRect.h 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/core/CRect.h 2006-03-20 21:50:55 UTC (rev 319) @@ -33,6 +33,17 @@ } /** + * Initialize the rectangle + * + * @param bottom Bottom position of the rectangle + * @param left Left position of the rectangle + * @param width Width of the rectangle + * @param height Height of the rectangle + */ +- (id) initWithBottom:(double)bottom left:(double)left width:(double)width andHeight:(double)height; + + +/** * Enlarges this rect so that it also contains point (x, y). */ - (void) addPointX: (double) x Y: (double) y; Modified: trunk/src/core/CRect.m =================================================================== --- trunk/src/core/CRect.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/core/CRect.m 2006-03-20 21:50:55 UTC (rev 319) @@ -36,6 +36,30 @@ return self; } + +/** +* Initialize the rectangle + * + * @param bottom Bottom position of the rectangle + * @param left Left position of the rectangle + * @param width Width of the rectangle + * @param height Height of the rectangle + */ +- (id) initWithBottom:(double)bottom left:(double)left width:(double)width andHeight:(double)height +{ + if (self = [super init]) + { + m_bottom = bottom; + m_left = left; + m_right = left + width; + m_top = bottom + height; + m_centerX = left + width / 2.0; + m_centerY = bottom + height / 2.0; + } + return self; +} + + - (id) copyWithZone: (NSZone*) zone { CRect* copy = [[self class] allocWithZone: zone]; Modified: trunk/src/io/pdf/CPdfImport.m =================================================================== --- trunk/src/io/pdf/CPdfImport.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/io/pdf/CPdfImport.m 2006-03-20 21:50:55 UTC (rev 319) @@ -29,6 +29,7 @@ #import "CPoint.h" #import "CSolidFill.h" #import "CStroke.h" +#import "CShape.h" // Included for debugging: @@ -599,7 +600,7 @@ CLayer* layer = getLastChlorLayer(); // Add rectangle Chlor path. - s_lastPath = [CPath rectangleLeft: x Bottom: y Width: width Height: height]; + s_lastPath = [CShape rectangleLeft: x Bottom: y Width: width Height: height]; [layer add: s_lastPath]; // Finish the last Chlor path. Modified: trunk/src/io/svg/CSvgImport.m =================================================================== --- trunk/src/io/svg/CSvgImport.m 2006-03-19 16:30:40 UTC (rev 318) +++ trunk/src/io/svg/CSvgImport.m 2006-03-20 21:50:55 UTC (rev 319) @@ -31,6 +31,7 @@ #import "CStroke.h" #import "CSvgImport.h" #import "CText.h" +#import "CShape.h" // Included for debugging: #import "CConsoleExport.h" @@ -1089,11 +1090,9 @@ { // Create circle path. CPath* path = - [CPath - ellipseLeft: centerX - radius * 0.5 - Bottom: centerY - radius * 0.5 - Width: 2 * radius - Height: 2 * radius]; + [CShape + circleWithCenterAtX: centerX andY:centerY andRadius + :radius]; // Add path to parent group. [theCGroup add: path]; @@ -1128,11 +1127,7 @@ { // Create ellipse path. CPath* path = - [CPath - ellipseLeft: centerX - radiusX * 0.5 - Bottom: centerY - radiusY * 0.5 - Width: 2 * radiusX - Height: 2 * radiusY]; + [CShape ellipseWithCenterAtX:centerX andY:centerY andRadiusX:radiusX andRadiusY:radiusY]; // Add path to parent group. [theCGroup add: path]; @@ -1271,7 +1266,7 @@ } // Create Chlor rectangle path. - CPath* path = [CPath rectangleLeft: x Bottom: y Width: width Height: height]; + CPath* path = [CShape rectangleLeft: x Bottom: y Width: width Height: height]; // Add Chlor path to parent Chlor group. [theCGroup add: path]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |