From 4e6213ef584b9c75f24d0a8e7edac31541fd233b Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 3 Mar 2018 16:42:19 +1100 Subject: Added FLTK.Widgets.Valuators.Counters.Simple --- src/c_fl_simple_counter.cpp | 70 ++++++++++++++++ src/c_fl_simple_counter.h | 27 ++++++ src/fltk-widgets-valuators-counters-simple.adb | 109 +++++++++++++++++++++++++ src/fltk-widgets-valuators-counters-simple.ads | 38 +++++++++ 4 files changed, 244 insertions(+) create mode 100644 src/c_fl_simple_counter.cpp create mode 100644 src/c_fl_simple_counter.h create mode 100644 src/fltk-widgets-valuators-counters-simple.adb create mode 100644 src/fltk-widgets-valuators-counters-simple.ads (limited to 'src') diff --git a/src/c_fl_simple_counter.cpp b/src/c_fl_simple_counter.cpp new file mode 100644 index 0000000..87ace91 --- /dev/null +++ b/src/c_fl_simple_counter.cpp @@ -0,0 +1,70 @@ + + +#include +#include "c_fl_simple_counter.h" +#include "c_fl_type.h" + + + + +class My_Simple_Counter : public Fl_Simple_Counter { + public: + using Fl_Simple_Counter::Fl_Simple_Counter; + friend void simple_counter_set_draw_hook(SIMPLE_COUNTER c, void * d); + friend void fl_simple_counter_draw(SIMPLE_COUNTER c); + friend void simple_counter_set_handle_hook(SIMPLE_COUNTER c, void * h); + friend int fl_simple_counter_handle(SIMPLE_COUNTER c, 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; +}; + +void My_Simple_Counter::draw() { + (*draw_hook)(this->user_data()); +} + +void My_Simple_Counter::real_draw() { + Fl_Simple_Counter::draw(); +} + +int My_Simple_Counter::handle(int e) { + return (*handle_hook)(this->user_data(), e); +} + +int My_Simple_Counter::real_handle(int e) { + return Fl_Simple_Counter::handle(e); +} + +void simple_counter_set_draw_hook(SIMPLE_COUNTER c, void * d) { + reinterpret_cast(c)->draw_hook = reinterpret_cast(d); +} + +void fl_simple_counter_draw(SIMPLE_COUNTER c) { + reinterpret_cast(c)->real_draw(); +} + +void simple_counter_set_handle_hook(SIMPLE_COUNTER c, void * h) { + reinterpret_cast(c)->handle_hook = reinterpret_cast(h); +} + +int fl_simple_counter_handle(SIMPLE_COUNTER c, int e) { + return reinterpret_cast(c)->real_handle(e); +} + + + + +SIMPLE_COUNTER new_fl_simple_counter(int x, int y, int w, int h, char* label) { + My_Simple_Counter *c = new My_Simple_Counter(x, y, w, h, label); + return c; +} + +void free_fl_simple_counter(SIMPLE_COUNTER c) { + delete reinterpret_cast(c); +} + + diff --git a/src/c_fl_simple_counter.h b/src/c_fl_simple_counter.h new file mode 100644 index 0000000..54c5f19 --- /dev/null +++ b/src/c_fl_simple_counter.h @@ -0,0 +1,27 @@ + + +#ifndef FL_SIMPLE_COUNTER_GUARD +#define FL_SIMPLE_COUNTER_GUARD + + + + +typedef void* SIMPLE_COUNTER; + + + + +extern "C" void simple_counter_set_draw_hook(SIMPLE_COUNTER c, void * d); +extern "C" void fl_simple_counter_draw(SIMPLE_COUNTER c); +extern "C" void simple_counter_set_handle_hook(SIMPLE_COUNTER c, void * h); +extern "C" int fl_simple_counter_handle(SIMPLE_COUNTER c, int e); + + + + +extern "C" SIMPLE_COUNTER new_fl_simple_counter(int x, int y, int w, int h, char* label); +extern "C" void free_fl_simple_counter(SIMPLE_COUNTER c); + + +#endif + diff --git a/src/fltk-widgets-valuators-counters-simple.adb b/src/fltk-widgets-valuators-counters-simple.adb new file mode 100644 index 0000000..3b05cb0 --- /dev/null +++ b/src/fltk-widgets-valuators-counters-simple.adb @@ -0,0 +1,109 @@ + + +with + + Interfaces.C.Strings, + System; + +use type + + System.Address; + + +package body FLTK.Widgets.Valuators.Counters.Simple is + + + procedure simple_counter_set_draw_hook + (W, D : in System.Address); + pragma Import (C, simple_counter_set_draw_hook, "simple_counter_set_draw_hook"); + + procedure simple_counter_set_handle_hook + (W, H : in System.Address); + pragma Import (C, simple_counter_set_handle_hook, "simple_counter_set_handle_hook"); + + + + + function new_fl_simple_counter + (X, Y, W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return System.Address; + pragma Import (C, new_fl_simple_counter, "new_fl_simple_counter"); + + procedure free_fl_simple_counter + (A : in System.Address); + pragma Import (C, free_fl_simple_counter, "free_fl_simple_counter"); + + + + + procedure fl_simple_counter_draw + (W : in System.Address); + pragma Import (C, fl_simple_counter_draw, "fl_simple_counter_draw"); + + function fl_simple_counter_handle + (W : in System.Address; + E : in Interfaces.C.int) + return Interfaces.C.int; + pragma Import (C, fl_simple_counter_handle, "fl_simple_counter_handle"); + + + + + procedure Finalize + (This : in out Simple_Counter) is + begin + if This.Void_Ptr /= System.Null_Address and then + This in Simple_Counter'Class + then + free_fl_simple_counter (This.Void_Ptr); + This.Void_Ptr := System.Null_Address; + end if; + Finalize (Counter (This)); + end Finalize; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Simple_Counter is + begin + return This : Simple_Counter do + This.Void_Ptr := new_fl_simple_counter + (Interfaces.C.int (X), + Interfaces.C.int (Y), + Interfaces.C.int (W), + Interfaces.C.int (H), + Interfaces.C.To_C (Text)); + fl_widget_set_user_data + (This.Void_Ptr, + Widget_Convert.To_Address (This'Unchecked_Access)); + simple_counter_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); + simple_counter_set_handle_hook (This.Void_Ptr, Handle_Hook'Address); + end return; + end Create; + + + + + procedure Draw + (This : in out Simple_Counter) is + begin + fl_simple_counter_draw (This.Void_Ptr); + end Draw; + + + function Handle + (This : in out Simple_Counter; + Event : in Event_Kind) + return Event_Outcome is + begin + return Event_Outcome'Val + (fl_simple_counter_handle (This.Void_Ptr, Event_Kind'Pos (Event))); + end Handle; + + +end FLTK.Widgets.Valuators.Counters.Simple; + diff --git a/src/fltk-widgets-valuators-counters-simple.ads b/src/fltk-widgets-valuators-counters-simple.ads new file mode 100644 index 0000000..195db5a --- /dev/null +++ b/src/fltk-widgets-valuators-counters-simple.ads @@ -0,0 +1,38 @@ + + +package FLTK.Widgets.Valuators.Counters.Simple is + + + type Simple_Counter is new Counter with private; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Simple_Counter; + + + + + procedure Draw + (This : in out Simple_Counter); + + function Handle + (This : in out Simple_Counter; + Event : in Event_Kind) + return Event_Outcome; + + +private + + + type Simple_Counter is new Counter with null record; + + overriding procedure Finalize + (This : in out Simple_Counter); + + +end FLTK.Widgets.Valuators.Counters.Simple; + -- cgit