Inheriting Fl_Dial gotchas

已查看 10 次
跳至第一个未读帖子

pvr...@btinternet.com

未读,
2022年3月21日 17:19:172022/3/21
收件人 fltk.general
I found the hard way that when overriding the draw and handle methods of Fl_Dial (actually Fl_Line_Dial) i could only effectively inherit the draw() and handle(int event) metods and not those which supplied the position and size values. The documentation inferred that the draw(X,Y,W,H) and equivalent handle methods were available for sub-classes. I took this to mean they could be overridden.

Thanks Phil.

Matthias Melcher

未读,
2022年3月22日 08:49:072022/3/22
收件人 fltk.general
The documentation shows, which functions are `virtual`. C++ is relatively limited in comparison to other languages. In Java, everything is virtual, and Lua goes even further, for example.


You can of course still call all non-private methods. So, to achieve overriding draw(x, y, w, h), you override draw() instead and get the coordinates using Fl_Widget::x(), y(), w(), and h().

The original Dial code does just that:

void Fl_Dial::draw() {

  draw(x(), y(), w(), h());

  draw_label();

}

回复全部
回复作者
转发
0 个新帖子