From b4438b2fbe895694be98e6e8426103deefc51448 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Tue, 21 Jan 2025 21:04:54 +1300 Subject: Split public API and private implementation files into different directories --- body/c_fl_clock_output.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 body/c_fl_clock_output.cpp (limited to 'body/c_fl_clock_output.cpp') diff --git a/body/c_fl_clock_output.cpp b/body/c_fl_clock_output.cpp new file mode 100644 index 0000000..a34b1c4 --- /dev/null +++ b/body/c_fl_clock_output.cpp @@ -0,0 +1,111 @@ + + +// Programmed by Jedidiah Barber +// Released into the public domain + + +#include +#include "c_fl_clock_output.h" + + + + +// 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_Clock_Output : Fl_Clock_Output { +public: + // Really only needed for the (int,int,int,int) version + using Fl_Clock_Output::draw; +}; + + + + +// Attaching all relevant hooks and friends + +class My_Clock_Output : public Fl_Clock_Output { +public: + using Fl_Clock_Output::Fl_Clock_Output; + + friend void fl_clock_output_draw(CLOCKOUTPUT c); + friend int fl_clock_output_handle(CLOCKOUTPUT c, int e); + + void draw(); + int handle(int e); +}; + +void My_Clock_Output::draw() { + widget_draw_hook(this->user_data()); +} + +int My_Clock_Output::handle(int e) { + return widget_handle_hook(this->user_data(), e); +} + + + + +// Flattened C API + +CLOCKOUTPUT new_fl_clock_output(int x, int y, int w, int h, char* label) { + My_Clock_Output *c = new My_Clock_Output(x, y, w, h, label); + return c; +} + +void free_fl_clock_output(CLOCKOUTPUT c) { + delete static_cast(c); +} + + + + +int fl_clock_output_get_hour(CLOCKOUTPUT c) { + return static_cast(c)->Fl_Clock_Output::hour(); +} + +int fl_clock_output_get_minute(CLOCKOUTPUT c) { + return static_cast(c)->Fl_Clock_Output::minute(); +} + +int fl_clock_output_get_second(CLOCKOUTPUT c) { + return static_cast(c)->Fl_Clock_Output::second(); +} + + +unsigned long fl_clock_output_get_value(CLOCKOUTPUT c) { + return static_cast(c)->Fl_Clock_Output::value(); +} + +void fl_clock_output_set_value(CLOCKOUTPUT c, unsigned long v) { + static_cast(c)->Fl_Clock_Output::value(v); +} + +void fl_clock_output_set_value2(CLOCKOUTPUT c, int h, int m, int s) { + static_cast(c)->Fl_Clock_Output::value(h,m,s); +} + + + + +void fl_clock_output_draw(CLOCKOUTPUT c) { + static_cast(c)->Fl_Clock_Output::draw(); +} + +void fl_clock_output_draw2(CLOCKOUTPUT c, int x, int y, int w, int h) { + void (Fl_Clock_Output::*mydraw)(int,int,int,int) = &Friend_Clock_Output::draw; + (static_cast(c)->*mydraw)(x, y, w, h); +} + +int fl_clock_output_handle(CLOCKOUTPUT c, int e) { + return static_cast(c)->Fl_Clock_Output::handle(e); +} + + -- cgit