From e93b9bbc02e2791f3a35b6f077fcbb8514c28aed Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Sun, 12 Jan 2025 01:14:58 +1300 Subject: Refactored draw/handle methods in Widgets hierarchy, improved docs, added a few minor method bindings here and there --- src/c_fl_repeat_button.cpp | 75 +++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 37 deletions(-) (limited to 'src/c_fl_repeat_button.cpp') diff --git a/src/c_fl_repeat_button.cpp b/src/c_fl_repeat_button.cpp index fbbbf35..7f05235 100644 --- a/src/c_fl_repeat_button.cpp +++ b/src/c_fl_repeat_button.cpp @@ -6,68 +6,69 @@ #include #include "c_fl_repeat_button.h" -#include "c_fl_type.h" +// Exports from Ada + +extern "C" void widget_draw_hook(void * ud); +extern "C" int widget_handle_hook(void * ud, int e); + + + + +// Attaching all relevant hooks and friends + class My_Repeat_Button : public Fl_Repeat_Button { - public: - using Fl_Repeat_Button::Fl_Repeat_Button; - friend void repeat_button_set_draw_hook(REPEATBUTTON b, void * d); - friend void fl_repeat_button_draw(REPEATBUTTON b); - friend void repeat_button_set_handle_hook(REPEATBUTTON b, void * h); - friend int fl_repeat_button_handle(REPEATBUTTON b, int e); - protected: - void draw(); - void real_draw(); - int handle(int e); - int real_handle(int e); - d_hook_p draw_hook; - h_hook_p handle_hook; +public: + using Fl_Repeat_Button::Fl_Repeat_Button; + + friend void fl_repeat_button_draw(REPEATBUTTON b); + friend int fl_repeat_button_handle(REPEATBUTTON b, int e); + + void draw(); + int handle(int e); }; void My_Repeat_Button::draw() { - (*draw_hook)(this->user_data()); -} - -void My_Repeat_Button::real_draw() { - Fl_Repeat_Button::draw(); + widget_draw_hook(this->user_data()); } int My_Repeat_Button::handle(int e) { - return (*handle_hook)(this->user_data(), e); + return widget_handle_hook(this->user_data(), e); } -int My_Repeat_Button::real_handle(int e) { - return Fl_Repeat_Button::handle(e); -} -void repeat_button_set_draw_hook(REPEATBUTTON b, void * d) { - reinterpret_cast(b)->draw_hook = reinterpret_cast(d); -} -void fl_repeat_button_draw(REPEATBUTTON b) { - reinterpret_cast(b)->real_draw(); + +// Flattened C API + +REPEATBUTTON new_fl_repeat_button(int x, int y, int w, int h, char* label) { + My_Repeat_Button *b = new My_Repeat_Button(x, y, w, h, label); + return b; } -void repeat_button_set_handle_hook(REPEATBUTTON b, void * h) { - reinterpret_cast(b)->handle_hook = reinterpret_cast(h); +void free_fl_repeat_button(REPEATBUTTON b) { + delete reinterpret_cast(b); } -int fl_repeat_button_handle(REPEATBUTTON b, int e) { - return reinterpret_cast(b)->real_handle(e); + + + +void fl_repeat_button_deactivate(REPEATBUTTON b) { + reinterpret_cast(b)->deactivate(); } -REPEATBUTTON new_fl_repeat_button(int x, int y, int w, int h, char* label) { - My_Repeat_Button *b = new My_Repeat_Button(x, y, w, h, label); - return b; +void fl_repeat_button_draw(REPEATBUTTON b) { + reinterpret_cast(b)->Fl_Repeat_Button::draw(); } -void free_fl_repeat_button(REPEATBUTTON b) { - delete reinterpret_cast(b); +int fl_repeat_button_handle(REPEATBUTTON b, int e) { + return reinterpret_cast(b)->Fl_Repeat_Button::handle(e); } + -- cgit