Reputation: 145
I'm trying to create a custom rpm gauge widget. everything looks fine when i test it by itself. But when i try to draw it at a different position in the parent window it seems to always draw using the origin of the window and not that of the widget no matter what x or y value i am passing to the constructor.
a printf() after calling the constructor confirmed that the widget "knows" the intended x and y.
Is this the default behavior ? i thought that the draw function uses the widgets 0,0 and not the window. do i need to explicitly call the x() and y() in the draw function and apply transforms to correct this ?
Upvotes: 0
Views: 313
Reputation: 354
Yep, that's correct. All coordinates in FLTK 1.x are relative to the window. Subwindows create their own coordinate space, i.e. coordinates in subwindows are relative to the subwindow, not the main window.
Upvotes: 1
Reputation: 25388
It looks to me that you need to translate the origin yourself. In the documentation it says:
Making Your Own Boxtypes
...
The Drawing Function
The drawing function is passed the bounding box and background color for the widget.
A simple drawing function might fill a rectangle with the given color and then draw a black outline:
void xyz_draw(int x, int y, int w, int h, Fl_Color c) {
fl_color(c);
fl_rectf(x, y, w, h);
fl_color(FL_BLACK);
fl_rect(x, y, w, h);
}
and you can see there that they are drawing their box at x, y
, not 0, 0
.
(For context, a box is just one particular type of widget).
Upvotes: 1