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_progress.cpp | 70 +++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 38 deletions(-) (limited to 'src/c_fl_progress.cpp') diff --git a/src/c_fl_progress.cpp b/src/c_fl_progress.cpp index 2e49643..9c18300 100644 --- a/src/c_fl_progress.cpp +++ b/src/c_fl_progress.cpp @@ -6,62 +6,44 @@ #include #include "c_fl_progress.h" -#include "c_fl_type.h" -class My_Progress : public Fl_Progress { - public: - using Fl_Progress::Fl_Progress; - friend void progress_set_draw_hook(PROGRESS p, void * d); - friend void fl_progress_draw(PROGRESS p); - friend void progress_set_handle_hook(PROGRESS p, void * h); - friend int fl_progress_handle(PROGRESS p, 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; -}; +// Exports from Ada -void My_Progress::draw() { - (*draw_hook)(this->user_data()); -} +extern "C" void widget_draw_hook(void * ud); +extern "C" int widget_handle_hook(void * ud, int e); -void My_Progress::real_draw() { - Fl_Progress::draw(); -} -int My_Progress::handle(int e) { - return (*handle_hook)(this->user_data(), e); -} -int My_Progress::real_handle(int e) { - return Fl_Progress::handle(e); -} -void progress_set_draw_hook(PROGRESS p, void * d) { - reinterpret_cast(p)->draw_hook = reinterpret_cast(d); -} +// Attaching all relevant hooks and friends -void fl_progress_draw(PROGRESS p) { - reinterpret_cast(p)->real_draw(); -} +class My_Progress : public Fl_Progress { +public: + using Fl_Progress::Fl_Progress; + + friend void fl_progress_draw(PROGRESS p); + friend int fl_progress_handle(PROGRESS p, int e); + + void draw(); + int handle(int e); +}; -void progress_set_handle_hook(PROGRESS p, void * h) { - reinterpret_cast(p)->handle_hook = reinterpret_cast(h); +void My_Progress::draw() { + widget_draw_hook(this->user_data()); } -int fl_progress_handle(PROGRESS p, int e) { - return reinterpret_cast(p)->real_handle(e); +int My_Progress::handle(int e) { + return widget_handle_hook(this->user_data(), e); } +// Flattened C API + PROGRESS new_fl_progress(int x, int y, int w, int h, char* label) { My_Progress *p = new My_Progress(x, y, w, h, label); return p; @@ -98,3 +80,15 @@ void fl_progress_set_value(PROGRESS p, float t) { reinterpret_cast(p)->value(t); } + + + +void fl_progress_draw(PROGRESS p) { + reinterpret_cast(p)->Fl_Progress::draw(); +} + +int fl_progress_handle(PROGRESS p, int e) { + return reinterpret_cast(p)->Fl_Progress::handle(e); +} + + -- cgit