<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stompy.org &#187; SOBezier</title>
	<atom:link href="http://www.stompy.org/category/mac-os-x/sobezier/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stompy.org</link>
	<description>Excuse me, I believe you have my stapler</description>
	<lastBuildDate>Fri, 19 Mar 2010 00:11:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SOBezier &#8211; Getting started.</title>
		<link>http://www.stompy.org/2008/07/30/sobezier-getting-started/</link>
		<comments>http://www.stompy.org/2008/07/30/sobezier-getting-started/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 22:00:55 +0000</pubDate>
		<dc:creator>stompy</dc:creator>
				<category><![CDATA[SOBezier]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Mac Dev]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[screencast]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.stompy.org/?p=58</guid>
		<description><![CDATA[The first part of this demonstration will create an application that draws a predefined curve in a window that is not re-sizeable. The idea is to get a simple working version up and running in the first place which can then be built upon.
Create the Project
In Xcode, create a new project of type &#8220;Cocoa Document-based [...]]]></description>
			<content:encoded><![CDATA[<p>The first part of this demonstration will create an application that draws a predefined curve in a window that is not re-sizeable. The idea is to get a simple working version up and running in the first place which can then be built upon.</p>
<h3>Create the Project</h3>
<p>In Xcode, create a new project of type &#8220;Cocoa Document-based application&#8221;. Save it wherever you like and call it SOBezier. The only project setting that needs to be set is to make sure that Garbage collection is turned on.</p>
<p><img src="http://www.stompy.org/wp-content/uploads/2008/07/gc-on.png" alt="GC-on.png" border="0" width="439" height="151" /></p>
<h3>MVC Classes</h3>
<p>Cocoa makes extensive use of the Model-View-Controller (MVC) paradigm. <strong>Model</strong> objects are responsible for the data or state of the application. <strong>View</strong> objects are responsible for displaying the data and the <strong>Controller</strong> objects keep the two in sync. For this basic application, the model class is SOBezierCurve, a subclass of NSObject, which contains the points of the curve and also knows how to draw itself. The view class is SOBezierView, a subclass of NSView, in which the curve is drawn. These are co-ordinated by the MyDocument class, a subclass of NSDocument, which is the controller.</p>
<h3>SOBezierCurve &#8211; the model</h3>
<p>From the Xcode File menu, choose New File and then select a Cocoa Objective-C class. Call this SOBezier curve. This will create the header and the implementation files. Edit them to look like these code listings.</p>
<div style="text-align:left;color:#000000; background-color:#ffffff; border:solid black 1px; padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; "><span style="color:#236e25;">// &nbsp;SOBezierCurve.h<br />
</span><br />
<span style="color:#683821;">#import &lt;Cocoa/Cocoa.h&gt;<br />
</span></p>
<p><span style="color:#881350;">@interface</span> SOBezierCurve : <span style="color:#400080;">NSObject</span> {<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">NSPoint</span> pt1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">NSPoint</span> pt2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">NSPoint</span> ControlPt1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">NSPoint</span> ControlPt2;<br />
}</p>
<p><span style="color:#881350;">@property</span><span style="color:#003369;"> </span>(<span style="color:#881350;">readwrite</span>) <span style="color:#400080;">NSPoint</span> pt1;<br />
<span style="color:#881350;">@property</span><span style="color:#003369;"> </span>(<span style="color:#881350;">readwrite</span>) <span style="color:#400080;">NSPoint</span> pt2;<br />
<span style="color:#881350;">@property</span><span style="color:#003369;"> </span>(<span style="color:#881350;">readwrite</span>) <span style="color:#400080;">NSPoint</span> ControlPt1;<br />
<span style="color:#881350;">@property</span><span style="color:#003369;"> </span>(<span style="color:#881350;">readwrite</span>) <span style="color:#400080;">NSPoint</span> ControlPt2;</p>
<p>- (<span style="color:#881350;">id</span>)<span style="color:#6c0540;">initWithPt1:</span>(<span style="color:#400080;">NSPoint</span>)point1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">Pt2:</span>(<span style="color:#400080;">NSPoint</span>)point2<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">ControlPt1:</span>(<span style="color:#400080;">NSPoint</span>)cPoint1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">ControlPt2:</span>(<span style="color:#400080;">NSPoint</span>)cPoint2;<br />
- (<span style="color:#881350;">void</span>)<span style="color:#6c0540;">drawCurve</span>;</p>
<p><span style="color:#881350;">@end</span></div>
<p>Here, the four points that define the curve are declared and I am using the Objective-C 2.0 @property syntax to make these properties. Two methods are declared. First, an initialiser that creates the curve based on the four points being passed in, and a method that draws the curve.</p>
<p>The implementation is quite simple:</p>
<div style="text-align:left;color:#000000; background-color:#ffffff; border:solid black 1px; padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; "><span style="color:#236e25;">// &nbsp;SOBezierCurve.m<br />
</span><br />
<span style="color:#683821;">#import &quot;SOBezierCurve.h&quot;<br />
</span><br />
<span style="color:#881350;">@implementation</span> SOBezierCurve<br />
<span style="color:#881350;">@synthesize</span> pt1, pt2, ControlPt1, ControlPt2;</p>
<p>- (<span style="color:#881350;">id</span>)<span style="color:#6c0540;">initWithPt1:</span>(<span style="color:#400080;">NSPoint</span>)point1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">Pt2:</span>(<span style="color:#400080;">NSPoint</span>)point2<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">ControlPt1:</span>(<span style="color:#400080;">NSPoint</span>)cPoint1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">ControlPt2:</span>(<span style="color:#400080;">NSPoint</span>)cPoint2<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// Designated initialiser.<br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">if</span><span style="color:#003369;"> </span>(![<span style="color:#881350;">super</span> <span style="color:#6c0540;">init</span>]) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">return</span> <span style="color:#881350;">nil</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;pt1 = point1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;pt2 = point2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;ControlPt1 = cPoint1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;ControlPt2 = cPoint2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">return</span> <span style="color:#881350;">self</span>;<br />
}</p>
<p>- (<span style="color:#881350;">void</span>)drawCurve<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">NSBezierPath</span> *path = [<span style="color:#400080;">NSBezierPath</span> <span style="color:#6c0540;">bezierPath</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// Move to the first control point<br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;[path <span style="color:#6c0540;">moveToPoint:</span>ControlPt1];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// Add a line from the control point to the first point of the curve<br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;[path <span style="color:#6c0540;">lineToPoint:</span>pt1];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// Create the curve<br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;[path <span style="color:#6c0540;">curveToPoint:</span>pt2 <span style="color:#6c0540;">controlPoint1:</span>ControlPt1 <span style="color:#6c0540;">controlPoint2:</span>ControlPt2];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// Draw a line from the end of the curve to the second control point<br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;[path <span style="color:#6c0540;">lineToPoint:</span>ControlPt2];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// Now draw the curve<br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;[[<span style="color:#400080;">NSColor</span> <span style="color:#6c0540;">blackColor</span>] <span style="color:#6c0540;">set</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;[path <span style="color:#6c0540;">stroke</span>];<br />
}</p>
<p><span style="color:#881350;">@end</span></div>
<p>The initialiser just sets the points of the curve to the points that are passed in. the <code>@sythesize</code> directive lets Objective-C 2.0 create accessors for the properties that are Key Value Coding (KVC) compliant.</p>
<p>The <code>DrawCurve:</code> method is responsible for drawing the curve represented by these points. This is where the terminology becomes confusing with the term &#8216;bezier&#8217; appearing everywhere. The NSBezierPath class is used extensively in Cocoa graphics, (which is why it is so easy to draw bezier curves), so to draw the curve a series of bezier paths are linked together as a single path and then drawn on the view by stroking this single path.</p>
<h3>SOBezierView &#8211; the view</h3>
<p>This class needs to be creates as we did with the SOBezierCurve class. From the Xcode File menu, choose New File and then select a Cocoa Objective-C NSView subclass. Call this file SOBezierView. This will create the header and the implementation files. Edit them to look like these code listings.</p>
<div style="text-align:left;color:#000000; background-color:#ffffff; border:solid black 1px; padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; "><span style="color:#236e25;">// &nbsp;SOBezierView.h<br />
</span><br />
<span style="color:#683821;">#import &lt;Cocoa/Cocoa.h&gt;<br />
</span><span style="color:#881350;">@class</span> MyDocument;</p>
<p><span style="color:#881350;">@interface</span> SOBezierView : <span style="color:#400080;">NSView</span> {<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">IBOutlet</span> MyDocument *doc;<br />
}</p>
<p><span style="color:#881350;">@end</span></div>
<p>This class doesn&#8217;t do much at the moment so it is quite small. The interface file just declares an outlet called <code>doc</code> to the controller, which is the MyDocument object in this case.</p>
<p>The implementation file only has two methods, both of which come from the superclass so they don&#8217;t need to be declared in the header file.</p>
<div style="text-align:left;color:#000000; background-color:#ffffff; border:solid black 1px; padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; "><span style="color:#236e25;">// &nbsp;SOBezierView.m<br />
</span><br />
<span style="color:#683821;">#import &quot;SOBezierView.h&quot;<br />
#import &quot;MyDocument.h&quot;<br />
#import &quot;SOBezierCurve.h&quot;<br />
</span><br />
<span style="color:#881350;">@implementation</span> SOBezierView</p>
<p>- (<span style="color:#881350;">id</span>)<span style="color:#6c0540;">initWithFrame:</span>(<span style="color:#400080;">NSRect</span>)frame {<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">self</span> = [<span style="color:#881350;">super</span> <span style="color:#6c0540;">initWithFrame:</span>frame];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">if</span><span style="color:#003369;"> </span>(<span style="color:#881350;">self</span>) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// Initialization code here.<br />
</span>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">return</span> <span style="color:#881350;">self</span>;<br />
}</p>
<p>- (<span style="color:#881350;">void</span>)<span style="color:#6c0540;">drawRect:</span>(<span style="color:#400080;">NSRect</span>)rect {<br />
&nbsp;&nbsp;&nbsp;&nbsp;[[<span style="color:#400080;">NSColor</span> <span style="color:#6c0540;">yellowColor</span>] <span style="color:#6c0540;">set</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color:#400080;">NSBezierPath</span> <span style="color:#6c0540;">fillRect:</span>[<span style="color:#881350;">self</span> <span style="color:#6c0540;">bounds</span>]];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;[[doc <span style="color:#6c0540;">curve</span>] <span style="color:#6c0540;">drawCurve</span>];<br />
}</p>
<p><span style="color:#881350;">@end</span></div>
<p>The <code>initWithFrame:</code> method is where the initialisation code will go. But the important method is the <code>drawRect:</code> method which is invoked whenever the view needs to draw itself.</p>
<p>The first thing that the <code>drawRect:</code> method does is set the colour to be used and then calls the NSBezierPath <code>fillRect:</code> method to fill the entire view window with this colour. The <code>rect</code> paramater that is passed into the <code>drawRect:</code> method is the rectangle that is &#8216;dirty&#8217; and needs to be redrawn, but to keep things simple, this implementation just fills in the whole view. If the view was drawing a number of curves, this dirty rectangle could be used to determine which curves are within this rectangle and the drawing code could be optimised to only draw those curves. The method then uses the outlet to the MyDocument object outlet <code>doc</code> to access curve object which is then asked to draw itself.</p>
<h3>MyDocument &#8211; the controller</h3>
<p>The MyDocument class was created by Xcode as part of the project.</p>
<p>Edit the header file so that it looks like this listing.</p>
<div style="text-align:left;color:#000000; background-color:#ffffff; border:solid black 1px; padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; "><span style="color:#236e25;">// &nbsp;MyDocument.h<br />
// &nbsp;SOBezier<br />
</span><br />
<span style="color:#683821;">#import &lt;Cocoa/Cocoa.h&gt;<br />
</span><span style="color:#881350;">@class</span> SOBezierCurve; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// 1<br />
</span><br />
<span style="color:#881350;">@interface</span> MyDocument : <span style="color:#400080;">NSDocument</span><br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;SOBezierCurve *curve; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// 2<br />
</span>}<br />
<span style="color:#881350;">@property</span><span style="color:#003369;"> </span>(<span style="color:#881350;">readwrite</span>) SOBezierCurve *curve; &nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// 3<br />
</span><span style="color:#881350;">@end</span></div>
<ol>
<li>Here SOBezierCurve is declared to be a class.</li>
<li>The <code>curve</code> attribute is declared as a pointer to an SOBezierCurve object.</li>
<li>This attribute is declared as a property.</li>
</ol>
<p>The MyDocument.m file contains a lot of generated code. For now the only changes need to be made to the beginning of the file. Edit the code so it looks like this listing.</p>
<div style="text-align:left;color:#000000; background-color:#ffffff; border:solid black 1px; padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; "><span style="color:#236e25;">// &nbsp;MyDocument.m<br />
// &nbsp;SOBezier<br />
</span><br />
<span style="color:#683821;">#import &quot;MyDocument.h&quot;<br />
#import &quot;SOBezierCurve.h&quot; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color:#236e25;">// 1</span><span style="color:#683821;"><br />
</span><br />
<span style="color:#881350;">@implementation</span> MyDocument<br />
<span style="color:#881350;">@synthesize</span> curve; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// 2<br />
</span><br />
- (<span style="color:#881350;">id</span>)init &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#236e25;">// 3<br />
</span>{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">self</span> = [<span style="color:#881350;">super</span> <span style="color:#6c0540;">init</span>];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">if</span><span style="color:#003369;"> </span>(<span style="color:#881350;">self</span>) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">NSPoint</span> p1 = <span style="color:#400080;">NSMakePoint</span>(<span style="color:#0000ff;">100</span>, <span style="color:#0000ff;">150</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">NSPoint</span> p2 = <span style="color:#400080;">NSMakePoint</span>(<span style="color:#0000ff;">300</span>, <span style="color:#0000ff;">150</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">NSPoint</span> cP1 = <span style="color:#400080;">NSMakePoint</span>(<span style="color:#0000ff;">100</span>, <span style="color:#0000ff;">225</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#400080;">NSPoint</span> cP2 = <span style="color:#400080;">NSMakePoint</span>(<span style="color:#0000ff;">300</span>, <span style="color:#0000ff;">75</span>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curve = [[SOBezierCurve <span style="color:#ff0000;">alloc</span>] <span style="color:#6c0540;">initWithPt1:</span>p1 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">Pt2:</span>p2 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">ControlPt1:</span>cP1 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">ControlPt2:</span>cP2];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">return</span> <span style="color:#881350;">self</span>;<br />
}</p>
<p>.<br />
.<br />
.</p>
<p><span style="color:#881350;">@end</span></div>
<ol>
<li>Import the header file for the SOBezierCurve class.</li>
<li>This creates <span class="caps">KVC</span> compliant accessors for the <code>curve</code> attribute.</li>
<li>The <code>init</code> method, called when the object is created, sets up the points to be used for the default curve and then creates an SOBezierCurve object with these points.</li>
</ol>
<h3>Create the User Interface</h3>
<p>Here&#8217;s a short screencast of how the UI is created. (If a picture is worth a thousand words, how many more is a video worth?).</p>
<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="545" height="451" id="viddler_abb2009b"><param name="movie" value="http://www.viddler.com/player/abb2009b/" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><embed src="http://www.viddler.com/player/abb2009b/" width="545" height="451" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" name="viddler_abb2009b" ></embed></object></p>
<p>Once that is done, you can click build and go to see a simple bezier curve drawn on a yellow background. Not very interesting so far, but it&#8217;s a good starting point.</p>
<h3>Next Steps</h3>
<p>The next step will be to add handles to the points so they can be moved around the view causing the curve to change. </p>
<p>Finally, thanks for your attention and I&#8217;d appreciate any comments you have, particularly about things you don&#8217;t like, so that I can improve this demonstration.</p>
<h3>Resources</h3>
<p>You can get the source code up to this point from the project&#8217;s git repository <a href="http://github.com/Abizern/sobezier/tree/master">here</a>. A checkout of the Stage1_1 tag will get the code up to this point.</p>
<p>Alternatively, you can download a zip file of the completed version up to this point here: <a href="http://www.stompy.org/wp-content/uploads/2008/07/sobezier-01.zip" title="SOBezier_01.zip">SOBezier_01.zip (60 kb)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.stompy.org/2008/07/30/sobezier-getting-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SOBezier &#8211; A Cocoa Tutorial</title>
		<link>http://www.stompy.org/2008/07/29/sobezier-a-cocoa-tutorial/</link>
		<comments>http://www.stompy.org/2008/07/29/sobezier-a-cocoa-tutorial/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 15:00:26 +0000</pubDate>
		<dc:creator>stompy</dc:creator>
				<category><![CDATA[SOBezier]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Mac Dev]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.stompy.org/?p=50</guid>
		<description><![CDATA[
I am going to start a series of tutorials that will build a basic Mac application that draws and manipulates bezier curves. Following the example of the Hillegass book I am going to be building the application up bit by bit; adding functionality in stages. Although the sample code available on the Apple site and [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.stompy.org/wp-content/uploads/2008/07/basicapp.tiff" alt="BasicApp.tiff" border="0" width="440" height="362"/></p>
<p>I am going to start a series of tutorials that will build a basic Mac application that draws and manipulates <a href="http://en.wikipedia.org/wiki/Bezier_curve#Cubic_B.C3.A9zier_curves">bezier curves</a>. Following the example of the <a href="http://www.amazon.co.uk/Cocoa-Programming-Mac-OS-X/dp/0321503619/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1217347551&#038;sr=8-1">Hillegass book</a> I am going to be building the application up bit by bit; adding functionality in stages. Although the sample code available on the Apple site and elsewhere on the net is quite detailed, it is sometimes hard to see how an application can be built up in small steps.</p>
<p>Because I am a fan of version control, and also because it can show the stages that the application is built up in, the <a href="http://github.com/Abizern/sobezier/tree/master">git repository</a> is available online, but if you don&#8217;t have (or want to use) <a href="http://git.or.cz/">git</a>, I&#8217;ll also have zip files of the project as it goes along.</p>
<p>The screen shot looks a little dull right now, but I am planning to have support for preference panes, changing the curve, undo/redo, printing, archiving, and copying amongst other things.</p>
<p>Also, if there is enough support for it, I might screencast some of the stages.</p>
<p>I hope you&#8217;ll join me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stompy.org/2008/07/29/sobezier-a-cocoa-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.445 seconds -->
