How can I implement a lasso or selection tool? Will this tool be able to scale, and rotate the selected strokes?
I see that there is a selection tool in your MyScriptATK_1.3 but nothing regarding it in iink.
Indeed, we do not have a lasso tool available out of the box in the API.
Basicall to develop a lasso, you should get the position of your lasso. You can then get the strokes inside of it. Once done, you can transform the strokes as you prefer (do a rotation, re-scale...), and also do the recognition if necessary!
basically, you normally have the cordinates of your lasso.
Once you have it, you need to export the content of your editor as JIIX. This way, you can process all the X and Y coordinates of your lasso, and determine if it is inside your lasso.
For each point of the JIIX, first transform it as follows (x_model and y_model are the coordinates from the JIIX):
auto transform = mEditorWidget->getEditor()->getRenderer()->getViewTransform();
auto point = transform.apply(x_model, y_model);
float x = point.x;
float y = point.y;
Then we use a isPointInsidePolygon function to determine if a point is inside the lasso (polygon is basically the lasso):
bool isPointInsidePolygon(float x, float y, const QList<QPoint>& polygon)
bool inside = false;
for (int i = 0, j = polygon.size() - 1; i < polygon.size(); j = i++)
float xi = (float)polygon[i].x(), yi = (float)polygon[i].y();
float xj = (float)polygon[j].x(), yj = (float)polygon[j].y();
bool intersect = ((yi > y) != (yj > y))
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
inside = !inside;
You can then determine the strokes inside of a lasso, and use these according to your needs.
How can I save those strokes back into the environment/ jiix after transforming them on the interface level.
I am not sure to understand your request?
Did you get the strokes inside of the lasso? In that case, you can add these to the editor using the editor.pointerEvents API?
Please provide with more insight on what you want to achieve using lasso.
I don't think I quite understand the process. Correct me if I'm wrong here:
1) I've determined the area I want to select
2) I have looped through all the strokes inside the jiix export to determine which ones I want to transform
3) I then transform them with editor.renderer.viewTransform.scaled/rotated/translated
4) I need to remove the original strokes and save the transformed ones into the model through editor.pointerEvents ?
Dear Jay S,
Basically, you are getting it.
Indeed, once you have transformed the strokes you want to keep, you should feed the editor with these latter ones, and process these.
On your side, what do you want to achieve with your lasso? You want to process the selected strokes with the contentPart (Text, Math) you prefer?