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_overlay_window.cpp | 87 ++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 48 deletions(-) (limited to 'src/c_fl_overlay_window.cpp') 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 #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(w)->draw_hook = reinterpret_cast(d); -} +// Attaching all relevant hooks and friends -void fl_overlay_window_draw(OVERLAYWINDOW w) { - reinterpret_cast(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(w)->draw_overlay_hook = reinterpret_cast(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(w)->handle_hook = reinterpret_cast(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(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(w)->can_do_overlay(); } +void fl_overlay_window_resize(OVERLAYWINDOW ow, int x, int y, int w, int h) { + reinterpret_cast(ow)->resize(x, y, w, h); +} + @@ -118,4 +101,12 @@ void fl_overlay_window_redraw_overlay(OVERLAYWINDOW w) { reinterpret_cast(w)->redraw_overlay(); } +void fl_overlay_window_draw(OVERLAYWINDOW w) { + reinterpret_cast(w)->Fl_Overlay_Window::draw(); +} + +int fl_overlay_window_handle(OVERLAYWINDOW w, int e) { + return reinterpret_cast(w)->Fl_Overlay_Window::handle(e); +} + -- cgit