From 7923568dc6447332ab1b9db727b9d64bea76dfcb Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Mon, 14 Nov 2016 20:36:33 +1100 Subject: Added FLTK integer inputs --- c_fl_int_input.cpp | 21 +++++++++++++ c_fl_int_input.h | 18 +++++++++++ fltk-widgets-inputs-int.adb | 75 +++++++++++++++++++++++++++++++++++++++++++++ fltk-widgets-inputs-int.ads | 31 +++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 c_fl_int_input.cpp create mode 100644 c_fl_int_input.h create mode 100644 fltk-widgets-inputs-int.adb create mode 100644 fltk-widgets-inputs-int.ads diff --git a/c_fl_int_input.cpp b/c_fl_int_input.cpp new file mode 100644 index 0000000..2224857 --- /dev/null +++ b/c_fl_int_input.cpp @@ -0,0 +1,21 @@ + + +#include +#include "c_fl_int_input.h" + + +INT_INPUT new_fl_int_input(int x, int y, int w, int h, char* label) { + Fl_Int_Input *i = new Fl_Int_Input(x, y, w, h, label); + return i; +} + + +void free_fl_int_input(INT_INPUT i) { + delete reinterpret_cast(i); +} + + +const char * fl_int_input_get_value(INT_INPUT i) { + return reinterpret_cast(i)->value(); +} + diff --git a/c_fl_int_input.h b/c_fl_int_input.h new file mode 100644 index 0000000..5d99c3f --- /dev/null +++ b/c_fl_int_input.h @@ -0,0 +1,18 @@ + + +#ifndef FL_INT_INPUT_GUARD +#define FL_INT_INPUT_GUARD + + +typedef void* INT_INPUT; + + +extern "C" INT_INPUT new_fl_int_input(int x, int y, int w, int h, char* label); +extern "C" void free_fl_int_input(INT_INPUT i); + + +extern "C" const char * fl_int_input_get_value(INT_INPUT i); + + +#endif + diff --git a/fltk-widgets-inputs-int.adb b/fltk-widgets-inputs-int.adb new file mode 100644 index 0000000..30f3d01 --- /dev/null +++ b/fltk-widgets-inputs-int.adb @@ -0,0 +1,75 @@ + + +with Interfaces.C.Strings; +with System; +use type System.Address; + + +package body FLTK.Widgets.Inputs.Int is + + + function new_fl_int_input + (X, Y, W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return System.Address; + pragma Import (C, new_fl_int_input, "new_fl_int_input"); + + procedure free_fl_int_input + (F : in System.Address); + pragma Import (C, free_fl_int_input, "free_fl_int_input"); + + function fl_int_input_get_value + (F : in System.Address) + return Interfaces.C.Strings.chars_ptr; + pragma Import (C, fl_int_input_get_value, "fl_int_input_get_value"); + + + + + procedure Finalize + (This : in out Integer_Input) is + begin + Finalize (Input (This)); + if This.Void_Ptr /= System.Null_Address then + if This in Integer_Input then + free_fl_int_input (This.Void_Ptr); + end if; + end if; + end Finalize; + + + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Integer_Input is + begin + return This : Integer_Input do + This.Void_Ptr := new_fl_int_input + (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)); + end return; + end Create; + + + + + function Get_Value + (This : in Integer_Input) + return Integer is + begin + return Integer'Value + (Interfaces.C.Strings.Value + (fl_int_input_get_value (This.Void_Ptr))); + end Get_Value; + + +end FLTK.Widgets.Inputs.Int; + diff --git a/fltk-widgets-inputs-int.ads b/fltk-widgets-inputs-int.ads new file mode 100644 index 0000000..2777f54 --- /dev/null +++ b/fltk-widgets-inputs-int.ads @@ -0,0 +1,31 @@ + + +package FLTK.Widgets.Inputs.Int is + + + type Integer_Input is new Input with private; + + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Integer_Input; + + + function Get_Value + (This : in Integer_Input) + return Integer; + + +private + + + type Integer_Input is new Input with null record; + + + overriding procedure Finalize + (This : in out Integer_Input); + + +end FLTK.Widgets.Inputs.Int; + -- cgit