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_overlay_window.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_overlay_window.cpp')
-rw-r--r-- | src/c_fl_overlay_window.cpp | 87 |
1 files changed, 39 insertions, 48 deletions
diff --git a/src/c_fl_overlay_window.cpp b/src/c_fl_overlay_window.cpp index be924dc..3ce76a4 100644 --- a/src/c_fl_overlay_window.cpp +++ b/src/c_fl_overlay_window.cpp @@ -6,75 +6,54 @@ #include <FL/Fl_Overlay_Window.H> #include "c_fl_overlay_window.h" -#include "c_fl_type.h" -class My_Overlay_Window : public Fl_Overlay_Window { - public: - using Fl_Overlay_Window::Fl_Overlay_Window; - friend void overlay_window_set_draw_hook(OVERLAYWINDOW w, void * d); - friend void fl_overlay_window_draw(OVERLAYWINDOW w); - friend void overlay_window_set_draw_overlay_hook(OVERLAYWINDOW w, void * d); - friend void overlay_window_set_handle_hook(OVERLAYWINDOW w, void * h); - friend int fl_overlay_window_handle(OVERLAYWINDOW w, int e); - friend OVERLAYWINDOW new_fl_overlay_window(int x, int y, int w, int h, char *label); - friend OVERLAYWINDOW new_fl_overlay_window2(int w, int h, char *label); - protected: - void draw(); - void real_draw(); - void draw_overlay(); - int handle(int e); - int real_handle(int e); - d_hook_p draw_hook; - d_hook_p draw_overlay_hook; - h_hook_p handle_hook; -}; +// Exports from Ada -void My_Overlay_Window::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_Overlay_Window::real_draw() { - Fl_Overlay_Window::draw(); -} +extern "C" void overlay_window_draw_overlay_hook(void * ud); -void My_Overlay_Window::draw_overlay() { - (*draw_overlay_hook)(this->user_data()); -} -int My_Overlay_Window::handle(int e) { - return (*handle_hook)(this->user_data(), e); -} -int My_Overlay_Window::real_handle(int e) { - return Fl_Overlay_Window::handle(e); -} -void overlay_window_set_draw_hook(OVERLAYWINDOW w, void * d) { - reinterpret_cast<My_Overlay_Window*>(w)->draw_hook = reinterpret_cast<d_hook_p>(d); -} +// Attaching all relevant hooks and friends -void fl_overlay_window_draw(OVERLAYWINDOW w) { - reinterpret_cast<My_Overlay_Window*>(w)->real_draw(); -} +class My_Overlay_Window : public Fl_Overlay_Window { +public: + using Fl_Overlay_Window::Fl_Overlay_Window; + + friend OVERLAYWINDOW new_fl_overlay_window(int x, int y, int w, int h, char *label); + friend OVERLAYWINDOW new_fl_overlay_window2(int w, int h, char *label); + + friend void fl_overlay_window_draw(OVERLAYWINDOW w); + friend int fl_overlay_window_handle(OVERLAYWINDOW w, int e); -void overlay_window_set_draw_overlay_hook(OVERLAYWINDOW w, void * d) { - reinterpret_cast<My_Overlay_Window*>(w)->draw_overlay_hook = reinterpret_cast<d_hook_p>(d); + void draw(); + void draw_overlay(); + int handle(int e); +}; + +void My_Overlay_Window::draw() { + widget_draw_hook(this->user_data()); } -void overlay_window_set_handle_hook(OVERLAYWINDOW w, void * h) { - reinterpret_cast<My_Overlay_Window*>(w)->handle_hook = reinterpret_cast<h_hook_p>(h); +void My_Overlay_Window::draw_overlay() { + overlay_window_draw_overlay_hook(this->user_data()); } -int fl_overlay_window_handle(OVERLAYWINDOW w, int e) { - return reinterpret_cast<My_Overlay_Window*>(w)->real_handle(e); +int My_Overlay_Window::handle(int e) { + return widget_handle_hook(this->user_data(), e); } +// Flattened C API + OVERLAYWINDOW new_fl_overlay_window(int x, int y, int w, int h, char *label) { My_Overlay_Window *ow = new My_Overlay_Window(x, y, w, h, label); return ow; @@ -96,6 +75,10 @@ int fl_overlay_window_can_do_overlay(OVERLAYWINDOW w) { return reinterpret_cast<Fl_Overlay_Window*>(w)->can_do_overlay(); } +void fl_overlay_window_resize(OVERLAYWINDOW ow, int x, int y, int w, int h) { + reinterpret_cast<Fl_Overlay_Window*>(ow)->resize(x, y, w, h); +} + @@ -118,4 +101,12 @@ void fl_overlay_window_redraw_overlay(OVERLAYWINDOW w) { reinterpret_cast<Fl_Overlay_Window*>(w)->redraw_overlay(); } +void fl_overlay_window_draw(OVERLAYWINDOW w) { + reinterpret_cast<My_Overlay_Window*>(w)->Fl_Overlay_Window::draw(); +} + +int fl_overlay_window_handle(OVERLAYWINDOW w, int e) { + return reinterpret_cast<My_Overlay_Window*>(w)->Fl_Overlay_Window::handle(e); +} + |