From 143488ea1731fe09d7bb396190607677ebfbd6f7 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 3 Mar 2018 23:11:47 +1100 Subject: Added almost complete FLTK.Widgets.Valuators.Sliders --- progress.txt | 2 +- src/c_fl_slider.cpp | 92 +++++++++++++++++ src/c_fl_slider.h | 36 +++++++ src/fltk-widgets-valuators-sliders.adb | 182 +++++++++++++++++++++++++++++++++ src/fltk-widgets-valuators-sliders.ads | 61 +++++++++++ 5 files changed, 372 insertions(+), 1 deletion(-) create mode 100644 src/c_fl_slider.cpp create mode 100644 src/c_fl_slider.h create mode 100644 src/fltk-widgets-valuators-sliders.adb create mode 100644 src/fltk-widgets-valuators-sliders.ads diff --git a/progress.txt b/progress.txt index e5c91d2..984000e 100644 --- a/progress.txt +++ b/progress.txt @@ -73,6 +73,7 @@ FLTK.Widgets.Inputs.File FLTK.Widgets.Menus FLTK.Widgets.Menus.Menu_Buttons FLTK.Widgets.Valuators +FLTK.Widgets.Valuators.Sliders @@ -102,7 +103,6 @@ FL_Tabs FL_Tile FL_Tree FL_Wizard -FL_Slider FL_Fill_Slider FL_Hor_Fill_Slider FL_Hor_Nice_Slider diff --git a/src/c_fl_slider.cpp b/src/c_fl_slider.cpp new file mode 100644 index 0000000..8fdf2da --- /dev/null +++ b/src/c_fl_slider.cpp @@ -0,0 +1,92 @@ + + +#include +#include "c_fl_slider.h" +#include "c_fl_type.h" + + + + +class My_Slider : public Fl_Slider { + public: + using Fl_Slider::Fl_Slider; + friend void slider_set_draw_hook(SLIDER s, void * d); + friend void fl_slider_draw(SLIDER s); + friend void slider_set_handle_hook(SLIDER s, void * h); + friend int fl_slider_handle(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_Slider::draw() { + (*draw_hook)(this->user_data()); +} + +void My_Slider::real_draw() { + Fl_Slider::draw(); +} + +int My_Slider::handle(int e) { + return (*handle_hook)(this->user_data(), e); +} + +int My_Slider::real_handle(int e) { + return Fl_Slider::handle(e); +} + +void slider_set_draw_hook(SLIDER s, void * d) { + reinterpret_cast(s)->draw_hook = reinterpret_cast(d); +} + +void fl_slider_draw(SLIDER s) { + reinterpret_cast(s)->real_draw(); +} + +void slider_set_handle_hook(SLIDER s, void * h) { + reinterpret_cast(s)->handle_hook = reinterpret_cast(h); +} + +int fl_slider_handle(SLIDER s, int e) { + return reinterpret_cast(s)->real_handle(e); +} + + + + +SLIDER new_fl_slider(int x, int y, int w, int h, char* label) { + My_Slider *s = new My_Slider(x, y, w, h, label); + return s; +} + +void free_fl_slider(SLIDER s) { + delete reinterpret_cast(s); +} + + + + +void fl_slider_set_bounds(SLIDER s, double a, double b) { + reinterpret_cast(s)->bounds(a,b); +} + +int fl_slider_get_slider(SLIDER s) { + return reinterpret_cast(s)->slider(); +} + +void fl_slider_set_slider(SLIDER s, int t) { + reinterpret_cast(s)->slider(static_cast(t)); +} + +float fl_slider_get_slider_size(SLIDER s) { + return reinterpret_cast(s)->slider_size(); +} + +void fl_slider_set_slider_size(SLIDER s, float t) { + reinterpret_cast(s)->slider_size(t); +} + diff --git a/src/c_fl_slider.h b/src/c_fl_slider.h new file mode 100644 index 0000000..b3955f5 --- /dev/null +++ b/src/c_fl_slider.h @@ -0,0 +1,36 @@ + + +#ifndef FL_SLIDER_GUARD +#define FL_SLIDER_GUARD + + + + +typedef void* SLIDER; + + + + +extern "C" void slider_set_draw_hook(SLIDER s, void * d); +extern "C" void fl_slider_draw(SLIDER s); +extern "C" void slider_set_handle_hook(SLIDER s, void * h); +extern "C" int fl_slider_handle(SLIDER s, int e); + + + + +extern "C" SLIDER new_fl_slider(int x, int y, int w, int h, char* label); +extern "C" void free_fl_slider(SLIDER s); + + + + +extern "C" void fl_slider_set_bounds(SLIDER s, double a, double b); +extern "C" int fl_slider_get_slider(SLIDER s); +extern "C" void fl_slider_set_slider(SLIDER s, int t); +extern "C" float fl_slider_get_slider_size(SLIDER s); +extern "C" void fl_slider_set_slider_size(SLIDER s, float t); + + +#endif + diff --git a/src/fltk-widgets-valuators-sliders.adb b/src/fltk-widgets-valuators-sliders.adb new file mode 100644 index 0000000..a7392cf --- /dev/null +++ b/src/fltk-widgets-valuators-sliders.adb @@ -0,0 +1,182 @@ + + +with + + Interfaces.C.Strings, + System; + +use type + + System.Address; + + +package body FLTK.Widgets.Valuators.Sliders is + + + procedure slider_set_draw_hook + (W, D : in System.Address); + pragma Import (C, slider_set_draw_hook, "slider_set_draw_hook"); + + procedure slider_set_handle_hook + (W, H : in System.Address); + pragma Import (C, slider_set_handle_hook, "slider_set_handle_hook"); + + + + + function new_fl_slider + (X, Y, W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return System.Address; + pragma Import (C, new_fl_slider, "new_fl_slider"); + + procedure free_fl_slider + (D : in System.Address); + pragma Import (C, free_fl_slider, "free_fl_slider"); + + + + + procedure fl_slider_set_bounds + (S : in System.Address; + A, B : in Interfaces.C.double); + pragma Import (C, fl_slider_set_bounds, "fl_slider_set_bounds"); + + function fl_slider_get_slider + (S : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_slider_get_slider, "fl_slider_get_slider"); + + procedure fl_slider_set_slider + (S : in System.Address; + T : in Interfaces.C.int); + pragma Import (C, fl_slider_set_slider, "fl_slider_set_slider"); + + function fl_slider_get_slider_size + (S : in System.Address) + return Interfaces.C.C_float; + pragma Import (C, fl_slider_get_slider_size, "fl_slider_get_slider_size"); + + procedure fl_slider_set_slider_size + (S : in System.Address; + T : in Interfaces.C.C_float); + pragma Import (C, fl_slider_set_slider_size, "fl_slider_set_slider_size"); + + + + + procedure fl_slider_draw + (W : in System.Address); + pragma Import (C, fl_slider_draw, "fl_slider_draw"); + + function fl_slider_handle + (W : in System.Address; + E : in Interfaces.C.int) + return Interfaces.C.int; + pragma Import (C, fl_slider_handle, "fl_slider_handle"); + + + + + procedure Finalize + (This : in out Slider) is + begin + if This.Void_Ptr /= System.Null_Address and then + This in Slider'Class + then + free_fl_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 Slider is + begin + return This : Slider do + This.Void_Ptr := new_fl_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)); + slider_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); + slider_set_handle_hook (This.Void_Ptr, Handle_Hook'Address); + end return; + end Create; + + + + + procedure Set_Bounds + (This : in out Slider; + A, B : in Long_Float) is + begin + fl_slider_set_bounds + (This.Void_Ptr, + Interfaces.C.double (A), + Interfaces.C.double (B)); + end Set_Bounds; + + + function Get_Box + (This : in Slider) + return Box_Kind is + begin + return Box_Kind'Val (fl_slider_get_slider (This.Void_Ptr)); + end Get_Box; + + + procedure Set_Box + (This : in out Slider; + To : in Box_Kind) is + begin + fl_slider_set_slider (This.Void_Ptr, Box_Kind'Pos (To)); + end Set_Box; + + + function Get_Slide_Size + (This : in Slider) + return Float is + begin + return Float (fl_slider_get_slider_size (This.Void_Ptr)); + end Get_Slide_Size; + + + procedure Set_Slide_Size + (This : in out Slider; + To : in Float) is + begin + fl_slider_set_slider_size (This.Void_Ptr, Interfaces.C.C_float (To)); + end Set_Slide_Size; + + + + + procedure Draw + (This : in out Slider) is + begin + fl_slider_draw (This.Void_Ptr); + end Draw; + + + function Handle + (This : in out Slider; + Event : in Event_Kind) + return Event_Outcome is + begin + return Event_Outcome'Val + (fl_slider_handle (This.Void_Ptr, Event_Kind'Pos (Event))); + end Handle; + + +end FLTK.Widgets.Valuators.Sliders; + diff --git a/src/fltk-widgets-valuators-sliders.ads b/src/fltk-widgets-valuators-sliders.ads new file mode 100644 index 0000000..3760e53 --- /dev/null +++ b/src/fltk-widgets-valuators-sliders.ads @@ -0,0 +1,61 @@ + + +package FLTK.Widgets.Valuators.Sliders is + + + type Slider is new Valuator with private; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Slider; + + + + + procedure Set_Bounds + (This : in out Slider; + A, B : in Long_Float); + + function Get_Box + (This : in Slider) + return Box_Kind; + + procedure Set_Box + (This : in out Slider; + To : in Box_Kind); + + function Get_Slide_Size + (This : in Slider) + return Float; + + procedure Set_Slide_Size + (This : in out Slider; + To : in Float); + + + + + procedure Draw + (This : in out Slider); + + function Handle + (This : in out Slider; + Event : in Event_Kind) + return Event_Outcome; + + +private + + + type Slider is new Valuator with null record; + + overriding procedure Finalize + (This : in out Slider); + + +end FLTK.Widgets.Valuators.Sliders; + -- cgit