You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Johannes,
I have a request for a new display object "freeform". Freeform is a display object, which wiil be drawn by a an array of points. The point array is drawn with lines, which connects the points. See the image:
This element isn't neither a rectangle nor a radial element.
I add some code to give you an idea:
var viewportPoints = [{x: 10, y: 20}, {x: 11, y: 22}, ....]; // array of points
this.pathLines = this.createPathLines(viewportPoints);
createPathLines: function(viewportPoints) {
var my = this;
var pathLines = [];
var prev = null;
viewportPoints.forEach(function(p){
if (prev) {
var pathLine = my.ocanvas.display.line({
start: {x: p.x, y: p.y},
end: {x: prev.x, y: prev.y}
});
pathLines.push(pathLine);
}
prev = p;
});
return pathLines;
},
The freeform object should be draggable, scalable and should have the behaviour of all the other display objects.
E. g. I add my own isPointerInside(x, y) Method, which checks, if a pointer position is inside this shape.
isPointerInside: function(x, y) {
// Example, retrieve canvas context with jQuery
var $canvas = $(this.ocanvas.settings.canvas);
var canvas = $canvas.get(0);
var ctx = canvas.getContext("2d");
var first = true;
ctx.beginPath();
this.pathPoints.forEach(function(pathPoint){
if (true === first) {
ctx.moveTo(pathPoint.x, pathPoint.y);
first = false;
} else {
ctx.lineTo(pathPoint.x, pathPoint.y);
}
});
ctx.closePath();
var inside = ctx.isPointInPath(x, y);
return inside;
},
But this method only works, if I add an outerBox to my freeform. The outerBox ist light blue, the selected freeform widget has a wider selection stroke in the next image.
The outerBox is drawn around my freeform. Here is how I create it:
this.outerBox = this.createOuterBox(x, y, w, h); // x, y, w, h outerBox geometrie
createOuterBox: function(x, y, w, h) {
var my = this;
var box = this.ocanvas.display.rectangle({
x: x,
y: y,
width: w,
height: h,
fill: "transparent"
});
box.setOrigin("left", "top");
box.bind("mousemove", function(){
if (my.isPointerInside(my.ocanvas.pointer.x, mu.ocanvas.pointer.y)) {
my.ocanvas.mouse.cursor("move");
} else {
my.ocanvas.mouse.cursor("default");
}
});
return box;
},
I'd like to use this new element to select an arbitray region in an image, where someone can leave a comment to this region.
It would be very fine, if you can add this new display object to your wonderful library.
Thank you very much.
The text was updated successfully, but these errors were encountered:
Hi Johannes,
I have a request for a new display object "freeform". Freeform is a display object, which wiil be drawn by a an array of points. The point array is drawn with lines, which connects the points. See the image:
This element isn't neither a rectangle nor a radial element.
I add some code to give you an idea:
var viewportPoints = [{x: 10, y: 20}, {x: 11, y: 22}, ....]; // array of points
this.pathLines = this.createPathLines(viewportPoints);
createPathLines: function(viewportPoints) {
var my = this;
var pathLines = [];
var prev = null;
viewportPoints.forEach(function(p){
if (prev) {
var pathLine = my.ocanvas.display.line({
start: {x: p.x, y: p.y},
end: {x: prev.x, y: prev.y}
});
pathLines.push(pathLine);
}
prev = p;
});
return pathLines;
},
The freeform object should be draggable, scalable and should have the behaviour of all the other display objects.
E. g. I add my own isPointerInside(x, y) Method, which checks, if a pointer position is inside this shape.
isPointerInside: function(x, y) {$canvas = $ (this.ocanvas.settings.canvas);
// Example, retrieve canvas context with jQuery
var
var canvas = $canvas.get(0);
var ctx = canvas.getContext("2d");
},
But this method only works, if I add an outerBox to my freeform. The outerBox ist light blue, the selected freeform widget has a wider selection stroke in the next image.
The outerBox is drawn around my freeform. Here is how I create it:
this.outerBox = this.createOuterBox(x, y, w, h); // x, y, w, h outerBox geometrie
createOuterBox: function(x, y, w, h) {
var my = this;
var box = this.ocanvas.display.rectangle({
x: x,
y: y,
width: w,
height: h,
fill: "transparent"
});
box.setOrigin("left", "top");
box.bind("mousemove", function(){
if (my.isPointerInside(my.ocanvas.pointer.x, mu.ocanvas.pointer.y)) {
my.ocanvas.mouse.cursor("move");
} else {
my.ocanvas.mouse.cursor("default");
}
});
return box;
},
I'd like to use this new element to select an arbitray region in an image, where someone can leave a comment to this region.
It would be very fine, if you can add this new display object to your wonderful library.
Thank you very much.
The text was updated successfully, but these errors were encountered: