diff options
author | Jedidiah Barber <contact@jedbarber.id.au> | 2025-01-12 01:14:58 +1300 |
---|---|---|
committer | Jedidiah Barber <contact@jedbarber.id.au> | 2025-01-12 01:14:58 +1300 |
commit | e93b9bbc02e2791f3a35b6f077fcbb8514c28aed (patch) | |
tree | 3661530027db6809a9cbad7b2477416009e00787 /src/c_fl_button.cpp | |
parent | 53aa8144851913994b963ed611cca8885b8f9a9e (diff) |
Refactored draw/handle methods in Widgets hierarchy, improved docs, added a few minor method bindings here and there
Diffstat (limited to 'src/c_fl_button.cpp')
-rw-r--r-- | src/c_fl_button.cpp | 84 |
1 files changed, 47 insertions, 37 deletions
diff --git a/src/c_fl_button.cpp b/src/c_fl_button.cpp index 07d5c64..1cff342 100644 --- a/src/c_fl_button.cpp +++ b/src/c_fl_button.cpp @@ -6,7 +6,6 @@ #include <FL/Fl_Button.H> #include "c_fl_button.h" -#include "c_fl_type.h" @@ -26,57 +25,50 @@ void fl_button_extra_final(void * adaobj) { -class My_Button : public Fl_Button { - public: - using Fl_Button::Fl_Button; - friend void button_set_draw_hook(BUTTON b, void * d); - friend void fl_button_draw(BUTTON b); - friend void button_set_handle_hook(BUTTON b, void * h); - friend int fl_button_handle(BUTTON 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; +// Exports from Ada + +extern "C" void widget_draw_hook(void * ud); +extern "C" int widget_handle_hook(void * ud, int e); + + + + +// Non-friend protected access + +class Friend_Button : Fl_Button { +public: + using Fl_Button::simulate_key_action; }; -void My_Button::draw() { - (*draw_hook)(this->user_data()); -} -void My_Button::real_draw() { - Fl_Button::draw(); -} -int My_Button::handle(int e) { - return (*handle_hook)(this->user_data(), e); -} -int My_Button::real_handle(int e) { - return Fl_Button::handle(e); -} +// Attaching all relevant hooks and friends -void button_set_draw_hook(BUTTON b, void * d) { - reinterpret_cast<My_Button*>(b)->draw_hook = reinterpret_cast<d_hook_p>(d); -} +class My_Button : public Fl_Button { +public: + using Fl_Button::Fl_Button; -void fl_button_draw(BUTTON b) { - reinterpret_cast<My_Button*>(b)->real_draw(); -} + friend void fl_button_draw(BUTTON b); + friend int fl_button_handle(BUTTON b, int e); + + void draw(); + int handle(int e); +}; -void button_set_handle_hook(BUTTON b, void * h) { - reinterpret_cast<My_Button*>(b)->handle_hook = reinterpret_cast<h_hook_p>(h); +void My_Button::draw() { + widget_draw_hook(this->user_data()); } -int fl_button_handle(BUTTON b, int e) { - return reinterpret_cast<My_Button*>(b)->real_handle(e); +int My_Button::handle(int e) { + return widget_handle_hook(this->user_data(), e); } +// Flattened C API + BUTTON new_fl_button(int x, int y, int w, int h, char* label) { My_Button *b = new My_Button(x, y, w, h, label); return b; @@ -121,3 +113,21 @@ void fl_button_set_shortcut(BUTTON b, int k) { } + + +void fl_button_draw(BUTTON b) { + reinterpret_cast<My_Button*>(b)->Fl_Button::draw(); +} + +int fl_button_handle(BUTTON b, int e) { + return reinterpret_cast<My_Button*>(b)->Fl_Button::handle(e); +} + + + + +void fl_button_simulate_key_action(BUTTON b) { + (reinterpret_cast<Fl_Button*>(b)->*(&Friend_Button::simulate_key_action))(); +} + + |