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_scroll.cpp | 70 ++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 38 deletions(-) (limited to 'src/c_fl_scroll.cpp') diff --git a/src/c_fl_scroll.cpp b/src/c_fl_scroll.cpp index 9c1eabf..ab63827 100644 --- a/src/c_fl_scroll.cpp +++ b/src/c_fl_scroll.cpp @@ -6,62 +6,44 @@ #include #include "c_fl_scroll.h" -#include "c_fl_type.h" -class My_Scroll : public Fl_Scroll { - public: - using Fl_Scroll::Fl_Scroll; - friend void scroll_set_draw_hook(SCROLL s, void * d); - friend void fl_scroll_draw(SCROLL s); - friend void scroll_set_handle_hook(SCROLL s, void * h); - friend int fl_scroll_handle(SCROLL s, 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_Scroll::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_Scroll::real_draw() { - Fl_Scroll::draw(); -} -int My_Scroll::handle(int e) { - return (*handle_hook)(this->user_data(), e); -} -int My_Scroll::real_handle(int e) { - return Fl_Scroll::handle(e); -} -void scroll_set_draw_hook(SCROLL s, void * d) { - reinterpret_cast(s)->draw_hook = reinterpret_cast(d); -} +// Attaching all relevant hooks and friends -void fl_scroll_draw(SCROLL s) { - reinterpret_cast(s)->real_draw(); -} +class My_Scroll : public Fl_Scroll { +public: + using Fl_Scroll::Fl_Scroll; + + friend void fl_scroll_draw(SCROLL s); + friend int fl_scroll_handle(SCROLL s, int e); + + void draw(); + int handle(int e); +}; -void scroll_set_handle_hook(SCROLL s, void * h) { - reinterpret_cast(s)->handle_hook = reinterpret_cast(h); +void My_Scroll::draw() { + widget_draw_hook(this->user_data()); } -int fl_scroll_handle(SCROLL s, int e) { - return reinterpret_cast(s)->real_handle(e); +int My_Scroll::handle(int e) { + return widget_handle_hook(this->user_data(), e); } +// Flattened C API + SCROLL new_fl_scroll(int x, int y, int w, int h, char* label) { My_Scroll *s = new My_Scroll(x, y, w, h, label); return s; @@ -108,3 +90,15 @@ int fl_scroll_yposition(SCROLL s) { return reinterpret_cast(s)->yposition(); } + + + +void fl_scroll_draw(SCROLL s) { + reinterpret_cast(s)->Fl_Scroll::draw(); +} + +int fl_scroll_handle(SCROLL s, int e) { + return reinterpret_cast(s)->Fl_Scroll::handle(e); +} + + -- cgit