From 9c653e23b34b3e6bcd3031f5d7db1e925d3ba748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Sun, 13 Feb 2011 19:15:09 +0100 Subject: [PATCH] =?UTF-8?q?Affichage=20de=20blocs.=20Il=20faudrait=20que?= =?UTF-8?q?=20je=20rajoute=20des=20primitives=20=C3=A0=20r=20:=20marginTex?= =?UTF-8?q?t=20et=20Block.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- grunt.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/grunt.js b/grunt.js index 2c5d39b..2ee5558 100644 --- 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);