Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for a new display object "freeform" #145

Open
lionstorke opened this issue Jul 12, 2017 · 0 comments
Open

Request for a new display object "freeform" #145

lionstorke opened this issue Jul 12, 2017 · 0 comments

Comments

@lionstorke
Copy link

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:

grafik

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.

grafik

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant