From 1d1f1f79c4091aaf673371ee8cca8688eab8ab70 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Fri, 16 Mar 2018 16:51:01 +1100 Subject: Added FLTK.Widgets.Valuators.Sliders.Value --- src/c_fl_value_slider.cpp | 96 +++++++++++++ src/c_fl_value_slider.h | 37 +++++ src/fltk-widgets-valuators-sliders-value.adb | 196 +++++++++++++++++++++++++++ src/fltk-widgets-valuators-sliders-value.ads | 69 ++++++++++ 4 files changed, 398 insertions(+) create mode 100644 src/c_fl_value_slider.cpp create mode 100644 src/c_fl_value_slider.h create mode 100644 src/fltk-widgets-valuators-sliders-value.adb create mode 100644 src/fltk-widgets-valuators-sliders-value.ads (limited to 'src') diff --git a/src/c_fl_value_slider.cpp b/src/c_fl_value_slider.cpp new file mode 100644 index 0000000..757424c --- /dev/null +++ b/src/c_fl_value_slider.cpp @@ -0,0 +1,96 @@ + + +#include +#include "c_fl_value_slider.h" +#include "c_fl_type.h" + + + + +class My_Value_Slider : public Fl_Value_Slider { + public: + using Fl_Value_Slider::Fl_Value_Slider; + friend void value_slider_set_draw_hook(VALUE_SLIDER s, void * d); + friend void fl_value_slider_draw(VALUE_SLIDER s); + friend void value_slider_set_handle_hook(VALUE_SLIDER s, void * h); + friend int fl_value_slider_handle(VALUE_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_Value_Slider::draw() { + (*draw_hook)(this->user_data()); +} + +void My_Value_Slider::real_draw() { + Fl_Value_Slider::draw(); +} + +int My_Value_Slider::handle(int e) { + return (*handle_hook)(this->user_data(), e); +} + +int My_Value_Slider::real_handle(int e) { + return Fl_Value_Slider::handle(e); +} + +void value_slider_set_draw_hook(VALUE_SLIDER s, void * d) { + reinterpret_cast(s)->draw_hook = reinterpret_cast(d); +} + +void fl_value_slider_draw(VALUE_SLIDER s) { + reinterpret_cast(s)->real_draw(); +} + +void value_slider_set_handle_hook(VALUE_SLIDER s, void * h) { + reinterpret_cast(s)->handle_hook = reinterpret_cast(h); +} + +int fl_value_slider_handle(VALUE_SLIDER s, int e) { + return reinterpret_cast(s)->real_handle(e); +} + + + + +VALUE_SLIDER new_fl_value_slider(int x, int y, int w, int h, char* label) { + My_Value_Slider *s = new My_Value_Slider(x, y, w, h, label); + return s; +} + +void free_fl_value_slider(VALUE_SLIDER s) { + delete reinterpret_cast(s); +} + + + + +unsigned int fl_value_slider_get_textcolor(VALUE_SLIDER s) { + return reinterpret_cast(s)->textcolor(); +} + +void fl_value_slider_set_textcolor(VALUE_SLIDER s, unsigned int t) { + reinterpret_cast(s)->textcolor(t); +} + +int fl_value_slider_get_textfont(VALUE_SLIDER s) { + return reinterpret_cast(s)->textfont(); +} + +void fl_value_slider_set_textfont(VALUE_SLIDER s, int t) { + reinterpret_cast(s)->textfont(t); +} + +int fl_value_slider_get_textsize(VALUE_SLIDER s) { + return reinterpret_cast(s)->textsize(); +} + +void fl_value_slider_set_textsize(VALUE_SLIDER s, int t) { + reinterpret_cast(s)->textsize(t); +} + diff --git a/src/c_fl_value_slider.h b/src/c_fl_value_slider.h new file mode 100644 index 0000000..9229fe6 --- /dev/null +++ b/src/c_fl_value_slider.h @@ -0,0 +1,37 @@ + + +#ifndef FL_VALUE_SLIDER_GUARD +#define FL_VALUE_SLIDER_GUARD + + + + +typedef void* VALUE_SLIDER; + + + + +extern "C" void value_slider_set_draw_hook(VALUE_SLIDER s, void * d); +extern "C" void fl_value_slider_draw(VALUE_SLIDER s); +extern "C" void value_slider_set_handle_hook(VALUE_SLIDER s, void * h); +extern "C" int fl_value_slider_handle(VALUE_SLIDER s, int e); + + + + +extern "C" VALUE_SLIDER new_fl_value_slider(int x, int y, int w, int h, char* label); +extern "C" void free_fl_value_slider(VALUE_SLIDER s); + + + + +extern "C" unsigned int fl_value_slider_get_textcolor(VALUE_SLIDER s); +extern "C" void fl_value_slider_set_textcolor(VALUE_SLIDER s, unsigned int t); +extern "C" int fl_value_slider_get_textfont(VALUE_SLIDER s); +extern "C" void fl_value_slider_set_textfont(VALUE_SLIDER s, int t); +extern "C" int fl_value_slider_get_textsize(VALUE_SLIDER s); +extern "C" void fl_value_slider_set_textsize(VALUE_SLIDER s, int t); + + +#endif + diff --git a/src/fltk-widgets-valuators-sliders-value.adb b/src/fltk-widgets-valuators-sliders-value.adb new file mode 100644 index 0000000..584aca6 --- /dev/null +++ b/src/fltk-widgets-valuators-sliders-value.adb @@ -0,0 +1,196 @@ + + +with + + Interfaces.C.Strings, + System; + +use type + + System.Address; + + +package body FLTK.Widgets.Valuators.Sliders.Value is + + + procedure value_slider_set_draw_hook + (W, D : in System.Address); + pragma Import (C, value_slider_set_draw_hook, "value_slider_set_draw_hook"); + + procedure value_slider_set_handle_hook + (W, H : in System.Address); + pragma Import (C, value_slider_set_handle_hook, "value_slider_set_handle_hook"); + + + + + function new_fl_value_slider + (X, Y, W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return System.Address; + pragma Import (C, new_fl_value_slider, "new_fl_value_slider"); + + procedure free_fl_value_slider + (D : in System.Address); + pragma Import (C, free_fl_value_slider, "free_fl_value_slider"); + + + + + function fl_value_slider_get_textcolor + (S : in System.Address) + return Interfaces.C.unsigned; + pragma Import (C, fl_value_slider_get_textcolor, "fl_value_slider_get_textcolor"); + + procedure fl_value_slider_set_textcolor + (S : in System.Address; + C : in Interfaces.C.unsigned); + pragma Import (C, fl_value_slider_set_textcolor, "fl_value_slider_set_textcolor"); + + function fl_value_slider_get_textfont + (S : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_value_slider_get_textfont, "fl_value_slider_get_textfont"); + + procedure fl_value_slider_set_textfont + (S : in System.Address; + F : in Interfaces.C.int); + pragma Import (C, fl_value_slider_set_textfont, "fl_value_slider_set_textfont"); + + function fl_value_slider_get_textsize + (S : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_value_slider_get_textsize, "fl_value_slider_get_textsize"); + + procedure fl_value_slider_set_textsize + (S : in System.Address; + F : in Interfaces.C.int); + pragma Import (C, fl_value_slider_set_textsize, "fl_value_slider_set_textsize"); + + + + + procedure fl_value_slider_draw + (W : in System.Address); + pragma Import (C, fl_value_slider_draw, "fl_value_slider_draw"); + + function fl_value_slider_handle + (W : in System.Address; + E : in Interfaces.C.int) + return Interfaces.C.int; + pragma Import (C, fl_value_slider_handle, "fl_value_slider_handle"); + + + + + procedure Finalize + (This : in out Value_Slider) is + begin + if This.Void_Ptr /= System.Null_Address and then + This in Value_Slider'Class + then + free_fl_value_slider (This.Void_Ptr); + This.Void_Ptr := System.Null_Address; + end if; + Finalize (Slider (This)); + end Finalize; + + + + + package body Forge is + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Value_Slider is + begin + return This : Value_Slider do + This.Void_Ptr := new_fl_value_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)); + value_slider_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); + value_slider_set_handle_hook (This.Void_Ptr, Handle_Hook'Address); + end return; + end Create; + + end Forge; + + + + + function Get_Text_Color + (This : in Value_Slider) + return Color is + begin + return Color (fl_value_slider_get_textcolor (This.Void_Ptr)); + end Get_Text_Color; + + + procedure Set_Text_Color + (This : in out Value_Slider; + To : in Color) is + begin + fl_value_slider_set_textcolor (This.Void_Ptr, Interfaces.C.unsigned (To)); + end Set_Text_Color; + + + function Get_Text_Font + (This : in Value_Slider) + return Font_Kind is + begin + return Font_Kind'Val (fl_value_slider_get_textfont (This.Void_Ptr)); + end Get_Text_Font; + + + procedure Set_Text_Font + (This : in out Value_Slider; + To : in Font_Kind) is + begin + fl_value_slider_set_textfont (This.Void_Ptr, Font_Kind'Pos (To)); + end Set_Text_Font; + + + function Get_Text_Size + (This : in Value_Slider) + return Font_Size is + begin + return Font_Size (fl_value_slider_get_textsize (This.Void_Ptr)); + end Get_Text_Size; + + + procedure Set_Text_Size + (This : in out Value_Slider; + To : in Font_Size) is + begin + fl_value_slider_set_textsize (This.Void_Ptr, Interfaces.C.int (To)); + end Set_Text_Size; + + + + + procedure Draw + (This : in out Value_Slider) is + begin + fl_value_slider_draw (This.Void_Ptr); + end Draw; + + + function Handle + (This : in out Value_Slider; + Event : in Event_Kind) + return Event_Outcome is + begin + return Event_Outcome'Val + (fl_value_slider_handle (This.Void_Ptr, Event_Kind'Pos (Event))); + end Handle; + + +end FLTK.Widgets.Valuators.Sliders.Value; + diff --git a/src/fltk-widgets-valuators-sliders-value.ads b/src/fltk-widgets-valuators-sliders-value.ads new file mode 100644 index 0000000..f3ac1c3 --- /dev/null +++ b/src/fltk-widgets-valuators-sliders-value.ads @@ -0,0 +1,69 @@ + + +package FLTK.Widgets.Valuators.Sliders.Value is + + + type Value_Slider is new Slider with private; + + + + + package Forge is + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Value_Slider; + + end Forge; + + + + + function Get_Text_Color + (This : in Value_Slider) + return Color; + + procedure Set_Text_Color + (This : in out Value_Slider; + To : in Color); + + function Get_Text_Font + (This : in Value_Slider) + return Font_Kind; + + procedure Set_Text_Font + (This : in out Value_Slider; + To : in Font_Kind); + + function Get_Text_Size + (This : in Value_Slider) + return Font_Size; + + procedure Set_Text_Size + (This : in out Value_Slider; + To : in Font_Size); + + + + + procedure Draw + (This : in out Value_Slider); + + function Handle + (This : in out Value_Slider; + Event : in Event_Kind) + return Event_Outcome; + + +private + + + type Value_Slider is new Slider with null record; + + overriding procedure Finalize + (This : in out Value_Slider); + + +end FLTK.Widgets.Valuators.Sliders.Value; + -- cgit