|DGLib - Documentation|
|Saturday, 28 November 2009 16:48|
note: As you might have already noticed, this library has a dependency on mootools. So it has to be included before DGLib.js. Mootools 1.2.4 is included on the DGLib package in it's compressed version but be sure to check out http://mootools.net/ for new versions and documentation.
And that's about it!
The functionalities are all encapsulated on an object named DGlib. That means you can call all the methods from this object for example: DGlib.selectCanvas("myCanvas");
The first method to be called should be DGlib.selectCanvas() in order to select witch canvas you want to affect with the next drawing method calls. To switch between canvas elements in the page you only need to call DGlib.selectCanvas() again with the new canvas id as an argument.
All the methods in DGlib require a canvas to be selected and to select a canvas you have to make sure that the canvas element is allready loaded in the DOM. For that I recommend running your script on the domReady event of mootools or the standard .
Switches between canvas to draw
Sets the current canvas size. Should be set before drawing. The arguments can be numbers (pixels) or strings like ('100%').
Example: DGlib.setCanvasSize('100%', 300);
DGlib.drawRect(pointAndSize, color, mode)
Draws a rectangle on the current canvas
Example: DGlib.drawRect([0, 0, '100%', '100%'], 'rgb(0,0,0)', 'stroke');
DGlib.drawPoly(points, color, thickness, closeShape, mode)
Draws a polygon or a line on the current selected canvas
Example: DGlib.drawPoly([[300,10],[10,10],[200,400],[300,400]], ['rgba(0,0,150,0.5)', 'rgba(0,0,0,0.5)'], 4, true, 'both');
DGlib.drawLine(from, to, color, thickness)
Draws a line
Example: DGlib.drawLine([20,20], ['20%','20%'], 'rgb(200,0,34)', 2);
DGlib.drawCircle(center, radius, color, thickness, mode)
Draws a circle on the selected canvas
Example: DGlib.drawCircle(['20%', '20%'], 50, ['rgb(0,0,0)','rgb(200,0,34)'], 10, 'both');
DGlib.drawRoundedRectangle(pointAndSize, radius, color, thickness, mode)
Draws a rectangle with rouded corners
Example: DGlib.drawRoundedRectangle(['50%', '50%', 200, 200], 20, ['rgba(150,140,250,0.9)', 'rgb(150,0,0)'], 1, 'both');
Returns a gradient for use as color
Places a bitmap image on the screen (works with jpg, bmp, and png with or without transparency)