[Drawkit] Drawkit Digest, Vol 9, Issue 1
Bill Monk
billmonk at mac.com
Wed Nov 5 22:20:27 PST 2008
Hi. I've been following this list with interest since its inception,
but have only now had a chance to use DrawKit in a project.
I'd like to use it as a rather basic "polygon editor" for four
NSPoints supplied by the user. Using DrawkitSimplerDemo, I've got a
window up which works fine. (Fine? It works great! The number of
features is amazing - most of my work was in removing things not
required but this simple editor.)
What I need to do now is
1) programmatically create an initial polygon from the supplied points
users.
2) When the window closes, I need to get the (possibly edited) points
back out.
Basically I have something like this...
================================
@interface EXShape : NSManagedObject
{
}
@property (retain) NSString * displayName;
// (x,y,z) points, but all we care about is (x,y)
@property (retain) CIVector * topLeft;
@property (retain) CIVector * bottomLeft;
@property (retain) CIVector * topRight;
@property (retain) CIVector * bottomRight;
================================
and want to do something like this...
#import <GCDrawKit/DKDrawKit.h>
#import "DrawKitWindowController.h"
@interface ShapeWindowController : DKSDController {
EXShape *shapeNode;
}
@property (retain) EXShapeNode * shapeNode;
- (id)initWithShapeNode:(EXShape *)shape;
@end
================================
@implementation ShapeWindowController
@synthesize shapeNode;
//
// designated intializer
//
- (id)initWithShapeNode:(EXShape *)shape;
{
if (self = [super initWithWindowNibName:@"ShapeWindow"]) {
self.shapeNode = shape;
}
return self;
}
- (void)windowDidLoad
{
self.window.title = self.shapeNode.displayName;
}
- (void)awakeFromNib
{
// In here, want to select the polygon tool...
// From the docs, seems like this should work,
// but nothing happens and there are no log messages.
DKDrawingTool* tool = [DKDrawingTool drawingToolWithName:@"Polygon"];
[tool set];
// From docs, seems this might work as well
// [[mDrawingView controller] selectDrawingToolWithName:@"Polygon"];
// however I get a warning 'DKViewController' may not respond to '-
selectDrawingToolWithName:'
// which is odd : we are a subclass of DKViewController
// Then, create an initial polygon from in DKDrawing (x, y) values of
four CIVectors
// in self.shapeNode.topLeft, etc.
}
- (void)windowWillClose
{
// get vertices of polygon in the DKDrawing
// store them into (x, y) values of self.shapeNode.topLeft, etc.
}
- (void)dealloc
{
[shapeNode release];
[super dealloc];
}
@end
... but after reading the docs and perusing the code, I'm still
stumped. Can anyone point me in the right direction?
More information about the Drawkit
mailing list