11-30-2018 12:42 PM
I created a new control using
int control = NewCtrl (panelHandle, CTRL_ROUND_LED, 0, y, x);
and then I drew a line using the same coordinate (x,y) using the code below.
I expected the cross hair lines to be at least near the newly created LED,
but they are not. They are far away. The CanvasDrawLine(), I think
is using the top-left as the origin. The NewCtrl() seems NOT.
How do I reconcile the coordinates used in CanvasDrawLine() and
NewCtrl() functions.
Point start, end;
start.x = x - 50; end.x = x + 50;
start.y = y; end.y = y;
CanvasDrawLine(panelHandle, canvas, start, end);
start.x = x; end.x = x;
start.y = y - 50; end.y = y + 50;
CanvasDrawLine(panelHandle, canvas, start, end);
12-01-2018 07:14 AM - edited 12-01-2018 07:18 AM
NewCtrl indeed uses the top left corner of the panel as the origin, the same applies to ATTR_TOP and ATTR_LEFT control attributes (including of course your canvas control). The origin of all CanvasDraw functions, instead, is the top left corner of the canvas itself. That is to say, coordinates of controls placed on top of a canvas can be mapped to point on the canvas by offsetting them by the top and left position of the canvas control.
As a side note, if you are using a menubar in your panel, this is not considered in getting control coordinates: the top position of controls always refers to the point immediately below the title bar, regardless the presence of a menu bar.