www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules

commit 9c653e23b34b3e6bcd3031f5d7db1e925d3ba748
parent 8bdb6b66af771640701041c219ca17e5f59f216f
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Sun, 13 Feb 2011 19:15:09 +0100

Affichage de blocs. Il faudrait que je rajoute des primitives à r : marginText et Block.

Diffstat:
Mgrunt.js | 33+++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/grunt.js b/grunt.js @@ -1,3 +1,32 @@ -new Event.observe(window, 'load', function() { +function drawText(x,y,text,margin) { + margin = (margin == null) ? 10 : margin; + var t = r.text(0,0,text); + var size = t.getBBox(); + var marginRect = r.rect(size.x - margin, size.y - margin, size.width + 2*margin, size.height + 2*margin).hide().attr("stroke-width", 0); + return r.set().push(t,marginRect).translate(margin+x-size.x, margin+y-size.y); +} + +function Block(name) { + this.name = name; + this.draw = function(x,y) { + var name = drawText(x,y,this.name); + var size = name.getBBox(); + var block = r.rect(x, y, size.width, 50 + size.height).insertBefore(name).attr({ + stroke: this.borderColor, + fill: this.fillColor + }); + return r.set().push(block, name); + }; +} + +// Colors +Block.prototype.borderColor = "#000"; +Block.prototype.fillColor = "#ff8"; + +function init() { r = Raphael("ide", 640, 480); -}); + new Block("Block 1").draw(150, 100); + new Block("My pretty block").draw(30, 200); +} + +new Event.observe(window, 'load', init);