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_box.cpp | 73 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) (limited to 'src/c_fl_box.cpp') diff --git a/src/c_fl_box.cpp b/src/c_fl_box.cpp index ec1a5de..67b4e0b 100644 --- a/src/c_fl_box.cpp +++ b/src/c_fl_box.cpp @@ -6,68 +6,67 @@ #include #include "c_fl_box.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_Box : public Fl_Box { - public: - using Fl_Box::Fl_Box; - friend void box_set_draw_hook(BOX n, void * d); - friend void fl_box_draw(BOX n); - friend void box_set_handle_hook(BOX n, void * h); - friend int fl_box_handle(BOX n, 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_Box::Fl_Box; + + friend void fl_box_draw(BOX n); + friend int fl_box_handle(BOX n, int e); + + void draw(); + int handle(int e); }; void My_Box::draw() { - (*draw_hook)(this->user_data()); -} - -void My_Box::real_draw() { - Fl_Box::draw(); + widget_draw_hook(this->user_data()); } int My_Box::handle(int e) { - return (*handle_hook)(this->user_data(), e); + return widget_handle_hook(this->user_data(), e); } -int My_Box::real_handle(int e) { - return Fl_Box::handle(e); -} -void box_set_draw_hook(BOX n, void * d) { - reinterpret_cast(n)->draw_hook = reinterpret_cast(d); -} -void fl_box_draw(BOX n) { - reinterpret_cast(n)->real_draw(); + +// Flattened C API + +BOX new_fl_box(int x, int y, int w, int h, char* label) { + My_Box *b = new My_Box(x, y, w, h, label); + return b; } -void box_set_handle_hook(BOX n, void * h) { - reinterpret_cast(n)->handle_hook = reinterpret_cast(h); +BOX new_fl_box2(int k, int x, int y, int w, int h, char * label) { + My_Box *b = new My_Box(static_cast(k), x, y, w, h, label); + return b; } -int fl_box_handle(BOX n, int e) { - return reinterpret_cast(n)->real_handle(e); +void free_fl_box(BOX b) { + delete reinterpret_cast(b); } -BOX new_fl_box(int x, int y, int w, int h, char* label) { - My_Box *b = new My_Box(x, y, w, h, label); - return b; +void fl_box_draw(BOX n) { + reinterpret_cast(n)->Fl_Box::draw(); } -void free_fl_box(BOX b) { - delete reinterpret_cast(b); +int fl_box_handle(BOX n, int e) { + return reinterpret_cast(n)->Fl_Box::handle(e); } + -- cgit