From c41a1b1e34d0a8710e7d9a6188d4db50cf15a772 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sun, 4 Mar 2018 00:50:16 +1100 Subject: Added FLTK.Widgets.Valuators.Sliders.Fill --- progress.txt | 2 +- src/c_fl_fill_slider.cpp | 70 ++++++++++++++++++ src/c_fl_fill_slider.h | 27 +++++++ src/fltk-widgets-valuators-sliders-fill.adb | 109 ++++++++++++++++++++++++++++ src/fltk-widgets-valuators-sliders-fill.ads | 38 ++++++++++ 5 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 src/c_fl_fill_slider.cpp create mode 100644 src/c_fl_fill_slider.h create mode 100644 src/fltk-widgets-valuators-sliders-fill.adb create mode 100644 src/fltk-widgets-valuators-sliders-fill.ads diff --git a/progress.txt b/progress.txt index 984000e..303244f 100644 --- a/progress.txt +++ b/progress.txt @@ -53,6 +53,7 @@ FLTK.Widgets.Valuators.Dials FLTK.Widgets.Valuators.Dials.Fill FLTK.Widgets.Valuators.Dials.Line FLTK.Widgets.Valuators.Rollers +FLTK.Widgets.Valuators.Sliders.Fill @@ -103,7 +104,6 @@ FL_Tabs FL_Tile FL_Tree FL_Wizard -FL_Fill_Slider FL_Hor_Fill_Slider FL_Hor_Nice_Slider FL_Hor_Slider diff --git a/src/c_fl_fill_slider.cpp b/src/c_fl_fill_slider.cpp new file mode 100644 index 0000000..c066e07 --- /dev/null +++ b/src/c_fl_fill_slider.cpp @@ -0,0 +1,70 @@ + + +#include +#include "c_fl_fill_slider.h" +#include "c_fl_type.h" + + + + +class My_Fill_Slider : public Fl_Fill_Slider { + public: + using Fl_Fill_Slider::Fl_Fill_Slider; + friend void fill_slider_set_draw_hook(FILL_SLIDER s, void * d); + friend void fl_fill_slider_draw(FILL_SLIDER s); + friend void fill_slider_set_handle_hook(FILL_SLIDER s, void * h); + friend int fl_fill_slider_handle(FILL_SLIDER s, 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_Fill_Slider::draw() { + (*draw_hook)(this->user_data()); +} + +void My_Fill_Slider::real_draw() { + Fl_Fill_Slider::draw(); +} + +int My_Fill_Slider::handle(int e) { + return (*handle_hook)(this->user_data(), e); +} + +int My_Fill_Slider::real_handle(int e) { + return Fl_Fill_Slider::handle(e); +} + +void fill_slider_set_draw_hook(FILL_SLIDER s, void * d) { + reinterpret_cast(s)->draw_hook = reinterpret_cast(d); +} + +void fl_fill_slider_draw(FILL_SLIDER s) { + reinterpret_cast(s)->real_draw(); +} + +void fill_slider_set_handle_hook(FILL_SLIDER s, void * h) { + reinterpret_cast(s)->handle_hook = reinterpret_cast(h); +} + +int fl_fill_slider_handle(FILL_SLIDER s, int e) { + return reinterpret_cast(s)->real_handle(e); +} + + + + +FILL_SLIDER new_fl_fill_slider(int x, int y, int w, int h, char* label) { + My_Fill_Slider *s = new My_Fill_Slider(x, y, w, h, label); + return s; +} + +void free_fl_fill_slider(FILL_SLIDER s) { + delete reinterpret_cast(s); +} + + diff --git a/src/c_fl_fill_slider.h b/src/c_fl_fill_slider.h new file mode 100644 index 0000000..ac9a125 --- /dev/null +++ b/src/c_fl_fill_slider.h @@ -0,0 +1,27 @@ + + +#ifndef FL_FILL_SLIDER_GUARD +#define FL_FILL_SLIDER_GUARD + + + + +typedef void* FILL_SLIDER; + + + + +extern "C" void fill_slider_set_draw_hook(FILL_SLIDER s, void * d); +extern "C" void fl_fill_slider_draw(FILL_SLIDER s); +extern "C" void fill_slider_set_handle_hook(FILL_SLIDER s, void * h); +extern "C" int fl_fill_slider_handle(FILL_SLIDER s, int e); + + + + +extern "C" FILL_SLIDER new_fl_fill_slider(int x, int y, int w, int h, char* label); +extern "C" void free_fl_fill_slider(FILL_SLIDER s); + + +#endif + diff --git a/src/fltk-widgets-valuators-sliders-fill.adb b/src/fltk-widgets-valuators-sliders-fill.adb new file mode 100644 index 0000000..d2416e0 --- /dev/null +++ b/src/fltk-widgets-valuators-sliders-fill.adb @@ -0,0 +1,109 @@ + + +with + + Interfaces.C.Strings, + System; + +use type + + System.Address; + + +package body FLTK.Widgets.Valuators.Sliders.Fill is + + + procedure fill_slider_set_draw_hook + (W, D : in System.Address); + pragma Import (C, fill_slider_set_draw_hook, "fill_slider_set_draw_hook"); + + procedure fill_slider_set_handle_hook + (W, H : in System.Address); + pragma Import (C, fill_slider_set_handle_hook, "fill_slider_set_handle_hook"); + + + + + function new_fl_fill_slider + (X, Y, W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return System.Address; + pragma Import (C, new_fl_fill_slider, "new_fl_fill_slider"); + + procedure free_fl_fill_slider + (D : in System.Address); + pragma Import (C, free_fl_fill_slider, "free_fl_fill_slider"); + + + + + procedure fl_fill_slider_draw + (W : in System.Address); + pragma Import (C, fl_fill_slider_draw, "fl_fill_slider_draw"); + + function fl_fill_slider_handle + (W : in System.Address; + E : in Interfaces.C.int) + return Interfaces.C.int; + pragma Import (C, fl_fill_slider_handle, "fl_fill_slider_handle"); + + + + + procedure Finalize + (This : in out Fill_Slider) is + begin + if This.Void_Ptr /= System.Null_Address and then + This in Fill_Slider'Class + then + free_fl_fill_slider (This.Void_Ptr); + This.Void_Ptr := System.Null_Address; + end if; + Finalize (Valuator (This)); + end Finalize; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Fill_Slider is + begin + return This : Fill_Slider do + This.Void_Ptr := new_fl_fill_slider + (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)); + fill_slider_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); + fill_slider_set_handle_hook (This.Void_Ptr, Handle_Hook'Address); + end return; + end Create; + + + + + procedure Draw + (This : in out Fill_Slider) is + begin + fl_fill_slider_draw (This.Void_Ptr); + end Draw; + + + function Handle + (This : in out Fill_Slider; + Event : in Event_Kind) + return Event_Outcome is + begin + return Event_Outcome'Val + (fl_fill_slider_handle (This.Void_Ptr, Event_Kind'Pos (Event))); + end Handle; + + +end FLTK.Widgets.Valuators.Sliders.Fill; + diff --git a/src/fltk-widgets-valuators-sliders-fill.ads b/src/fltk-widgets-valuators-sliders-fill.ads new file mode 100644 index 0000000..7bddf1a --- /dev/null +++ b/src/fltk-widgets-valuators-sliders-fill.ads @@ -0,0 +1,38 @@ + + +package FLTK.Widgets.Valuators.Sliders.Fill is + + + type Fill_Slider is new Slider with private; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Fill_Slider; + + + + + procedure Draw + (This : in out Fill_Slider); + + function Handle + (This : in out Fill_Slider; + Event : in Event_Kind) + return Event_Outcome; + + +private + + + type Fill_Slider is new Slider with null record; + + overriding procedure Finalize + (This : in out Fill_Slider); + + +end FLTK.Widgets.Valuators.Sliders.Fill; + -- cgit