Are you sure beginPath() returns something persistent?
No, I'm not, I'm just guessing where it would make sense to return a path (or subpath, see below).
For example, if you are using this beginPath(), it returns nothing:
void QQuickContext2D::beginPath()
see: https://codebrowser.dev/qt5/qtdeclarative/src/quick/items/context2d/qquickcontext2d.cpp.html#_ZN15QQuickContext2D9beginPathEv
As usual for Qt, the documentation sucks. https://doc.qt.io/qt-5/qml-qtquick-context2d.html#beginPath-method clearly documents beginPath() to return an object. Not what kind of object, or what to expect from it, just an object.
In the very same document, there are several links to http://www.w3.org/TR/2dcontext/, which unfortunately just redirects to a big mess of HTML "living standard". https://html.spec.whatwg.org/multipage/canvas.html#2dcontext seems to be the desired content.
But you do get some value in p1, p2. This may be the current path, previous paths not persisting.
Yes, that matches the behaviour.
Looking again at https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ispointinpath, the example shows a click handler that (partially) draws each clickable object, then invokes isPointInPath() to check if that clickable object contains the mouse coordinates, and finally issues a redraw command, probably to clean up the mess that those checks made.
That does not look very sane and efficient to me. I'll try that.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] [d/l] |
Looking again at https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ispointinpath, the example shows a click handler that (partially) draws each clickable object, then invokes isPointInPath() to check if that clickable object contains the mouse coordinates, and finally issues a redraw command, probably to clean up the mess that those checks made.
That does not look very sane and efficient to me. I'll try that.
It may be inefficient, but it works.
Following the example from whatwg.org, I've moved the painting to javascript functions (generated at compile time from the SVG file using Perl and XML::LibXML). This is how it looks in QML:
import QtQuick 2.0
...
import "mymap.js" as MyMap
Rectangle {
...
Canvas {
id: canvas
...
onPaint: {
var ctx = getContext("2d");
MyMap.drawBackground(ctx);
MyMap.drawAreas(ctx);
}
MouseArea {
anchors.fill: parent
onClicked: function(mouse) {
var ctx = canvas.getContext("2d");
for (var i = 0; i < MyMap.areaIDs.length; i++) {
MyMap.drawArea(ctx, ..., MyMap.areaIDs[i]);
if (ctx.isPointInPath(mouse.x, mouse.y)) {
console.log("Mouse click at ("+mouse.x+", "+mo
+use.y+") hit area "+MyMap.areaIDs[i]);
return;
}
}
console.log("Mouse click at ("+mouse.x+", "+mouse.y+")
+ hit no area");
mouse.accepted = false;
}
}
}
}
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] [d/l] |