spacer
home / programming / javascript / gr / column21 / 1 To page 1To page 2current page
[previous]

Doodle, A Demo Drawing Program - Part 2

The Canvas is now a View

The Canvas class has changed slightly since the last article.

Now, nested within the Doodle namespace, the Canvas class now operates on a document object (given as an argument in its constructor).

The mouse events now gain a little sophistication as they coordinate together to generate line objects.

The onMouseDown records the mouse down position and creates a line object using the graphics code.

The onMouseMove records the new mouse position, removes the previous line and creates a new one using the new positions.

The onMouseUp handler uses the two recorded end points to create a new document line object, then removes the stored properties.

Conclusion

Here we've extended the application by laying the foundations of a document-view architecture. The entire Doodle code-base is nested within the Doodle namespace which apart from isolating the code from any other application that may be running, will also make class naming simpler since it's no longer necessary to conjure up names that won't be used elsewhere.

We've not seen the complete benefits of document-view; all that's been done is to record the mouse events on the canvas as line objects within the document. In the next part in this series the Canvas will enable selection and the opportunity for the user to modify and delete objects after they have been drawn.

Download The Code

Right click the links below and select "Save Target As" to download copies of the demo code.
core.js Core utilities and functions.
graphics.js Object Oriented JavaScript graphics package
doodle_canvas.js Canvas class
doodle_doc.js Canvas class
doodle.js Doodle application class
doodle.html Simple demonstration HTML page

Disclaimer

While I have endeavoured to make this code as browser compatible as possible, I've only tested it with Internet Explorer (6.0), Firefox (1.5.0.4) and Netscape (7.1) as this represents of a large proportion of users.

About the Author

Guyon Roche is a freelance web developer in London, Great Britain. He specializes in Windows platforms with an interest in bridging the gaps between different technologies, visit www.silver-daggers.co.uk for more details. He can be reached via e-mail at guyonroche@silver-daggers.co.uk.

home / programming / javascript / gr / column21 / 1 To page 1To page 2current page
[previous]



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Advanced Web Performance Optimization · Simple Comments Meets OpenID · Primitive Data Types, Arrays, Loops, and Conditions: Part 3
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Five Key Factors Drive Mobile Device Growth · Lian-Li Launches New Power Supply Line, Rack Mount Kit and Fan Blower · OpenOffice.org Tips and Tricks Part III

Created: March 27, 2003
Revised: Sept 27, 2006

URL: http://webreference.com/programming/javascript/gr/column21/1