Problem with custom function

12 views
Skip to first unread message

voltron

unread,
Mar 2, 2010, 11:19:38 AM3/2/10
to jsvectoreditor
I have coded a test button, its is actually aclone of the "create
rectangle" button:

<button id="test" onclick="setMode('test')"><img src="http://
ajaxanimator.googlecode.com/svn/trunk/ajaxanimator/img/icon/line.gif"
title="Test"</button>

in the mousedown event function of editor.js

}else if(this.mode == "test"){
shape = this.draw.rect(x, y, 0, 0);

// in the mouseMove() function:
// ===============================
if(this.selected[0].type == "test"){
this.resize(this.selected[0], x - this.onGrabXY[0], y -
this.onGrabXY[1], this.onGrabXY[0], this.onGrabXY[1])

// in the mouseUp() function
//===================================
}else if(this.mode == "test"){
this.unselect()

Sadly, nothing happens when I try out the custom button, can someone
tell me what I am doing wrong?

Thanks

antimatter15

unread,
Mar 2, 2010, 11:28:36 PM3/2/10
to jsvectoreditor
Can you upload a copy with your changes to a web server so I can see?

Noah Vawter

unread,
Mar 10, 2010, 11:28:20 AM3/10/10
to jsvecto...@googlegroups.com

Heya! did anyone ever get someplace with this? I tried the changes,
too, and got the same results, but I'm just getting to know the code,
so my debugging only consisted of the most obvious things... It
would be sweet to be able to add some more functions. I'd like to add
"regular polygon" for example :)

-Noah

antimatter15

unread,
Mar 10, 2010, 5:43:16 PM3/10/10
to jsvectoreditor
Here is a custom tool which draws a star.


Index: editor.js
===================================================================
--- editor.js (revision 201)
+++ editor.js (working copy)
@@ -270,6 +270,18 @@
shape = this.draw.ellipse(x, y, 0, 0);
}else if(this.mode == "path"){
shape = this.draw.path("M{0},{1}",x,y)
+ }else if(this.mode == "demo"){
+ //this is a tad bit awkward because resizing path type objects
is significantly different from normal rectangle/ellipse type objects
+
+ shape = this.draw.path("M{0},{1}
1l-5.55944,11.26437l-10.8042,0.22989l9.33566,7.47126l-5.45454,11.03448l10.90909,-9.42529l7.76225,9.1954l-2.72728,-11.26437l10.17483,-6.66666l-10.8042,-0.68966l-2.83216,-11.14942",x,y)
+ shape.polypoints = [[x,y]]
+ shape.subtype = "demo"
+ this.onGrabXY = [
+ shape.getBBox().x,
+ shape.getBBox().y,
+ shape.getBBox().width,
+ shape.getBBox().height
+ ]
}else if(this.mode == "line"){
shape = this.draw.path("M{0},{1}",x,y)
shape.subtype = "line"
@@ -385,6 +397,10 @@
this.resize(this.selected[0], x - this.onHitXY[0], y -
this.onHitXY[1], this.onHitXY[0], this.onHitXY[1])
}else if(this.mode == "ellipse"){
this.resize(this.selected[0], x - this.onHitXY[0], y -
this.onHitXY[1], this.onHitXY[0], this.onHitXY[1])
+ }else if(this.mode == "demo"){
+ if(x - this.onGrabXY[0] > this.onGrabXY[2] && y -
this.onGrabXY[1] > this.onGrabXY[3]){
+ this.selected[0].scale((x - this.onGrabXY[0])/
this.onGrabXY[2], (y - this.onGrabXY[1])/this.onGrabXY[3],


this.onGrabXY[0], this.onGrabXY[1])

+ }
}else if(this.mode == "text"){
this.resize(this.selected[0], x - this.onHitXY[0], y -
this.onHitXY[1], this.onHitXY[0], this.onHitXY[1])
}else if(this.mode == "path"){
@@ -507,6 +523,8 @@
this.unselect()
}else if(this.mode == "line"){
this.unselect()
+ }else if(this.mode == "demo"){
+ this.unselect()
}else if(this.mode == "image"){
this.unselect()
}else if(this.mode == "text"){
Index: index.html
===================================================================
--- index.html (revision 201)
+++ index.html (working copy)
@@ -49,6 +49,7 @@
<button id="open" onclick="opendialog()"><img src="
http://ajaxanimator.googlecode.com/svn/trunk/ajaxanimator/img/silk/folder_go.png"
title="Open"></button>

+ <button onclick="setMode('demo')" style="width:60px">Star</
button>

<br>

Reply all
Reply to author
Forward
0 new messages