| DGLib - Documentation |
| Saturday, 28 November 2009 16:48 |
|
This is the documentation for DGLib javascript graphics library.
InstallationThis is a graphics library meant to provide tools for javascript programmers to manage the content of canvas elements on HTML pages. As so, it doesn't do anything for it self and requires no instalation. All you have to do is include mootools and the js file for DGLib on your HTML head before your scripts in this order: 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!
UsageThe 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 . Color attributes are all strings constructed according to the javascript color formats like 'rgb(255,0,0)' or 'rgba(255,255,255,0.5)' or 'hsl(0,100%,100%)'.
Method description:DGlib.selectCanvas(canvasID)Switches between canvas to draw Example: DGlib.selectCanvas("canvasTest");
DGlib.setCanvasSize(width, height)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'); DGlib.linearGradient(point1, point2)Returns a gradient for use as color Example: DGlib.drawImage(url, position)Places a bitmap image on the screen (works with jpg, bmp, and png with or without transparency) Example: DGlib.drawImage('ballTest_blue.png',[0,0]); |









