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_wizard.cpp | 70 +++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 37 deletions(-) (limited to 'src/c_fl_wizard.cpp') diff --git a/src/c_fl_wizard.cpp b/src/c_fl_wizard.cpp index 1aeb0e5..d826ca6 100644 --- a/src/c_fl_wizard.cpp +++ b/src/c_fl_wizard.cpp @@ -6,34 +6,37 @@ #include #include "c_fl_wizard.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_Wizard : public Fl_Wizard { - public: - using Fl_Wizard::Fl_Wizard; - friend void wizard_set_draw_hook(WIZARD w, void * d); - friend void fl_wizard_draw(WIZARD w); - friend void wizard_set_handle_hook(WIZARD w, void * h); - friend int fl_wizard_handle(WIZARD w, 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_Wizard::Fl_Wizard; + + friend void fl_wizard_draw(WIZARD w); + friend int fl_wizard_handle(WIZARD w, int e); + + void draw(); + void real_draw(); + int handle(int e); }; void My_Wizard::draw() { - (*draw_hook)(this->user_data()); + widget_draw_hook(this->user_data()); } void My_Wizard::real_draw() { - //Fl_Wizard::draw(); - // required because of Fl_Wizard::draw() being private // probably a bug in FLTK? Fl_Widget *kid = value(); @@ -50,31 +53,13 @@ void My_Wizard::real_draw() { } int My_Wizard::handle(int e) { - return (*handle_hook)(this->user_data(), e); + return widget_handle_hook(this->user_data(), e); } -int My_Wizard::real_handle(int e) { - return Fl_Wizard::handle(e); -} - -void wizard_set_draw_hook(WIZARD w, void * d) { - reinterpret_cast(w)->draw_hook = reinterpret_cast(d); -} - -void fl_wizard_draw(WIZARD w) { - reinterpret_cast(w)->real_draw(); -} - -void wizard_set_handle_hook(WIZARD w, void * h) { - reinterpret_cast(w)->handle_hook = reinterpret_cast(h); -} - -int fl_wizard_handle(WIZARD w, int e) { - return reinterpret_cast(w)->real_handle(e); -} +// Flattened C API WIZARD new_fl_wizard(int x, int y, int w, int h, char* label) { My_Wizard *g = new My_Wizard(x, y, w, h, label); @@ -108,3 +93,14 @@ void fl_wizard_set_visible(WIZARD w, void * i) { } + + +void fl_wizard_draw(WIZARD w) { + reinterpret_cast(w)->real_draw(); +} + +int fl_wizard_handle(WIZARD w, int e) { + return reinterpret_cast(w)->Fl_Wizard::handle(e); +} + + -- cgit