From 098adf24b20bb7ae71cfd7e6af5517205552e9e5 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 17 May 2018 19:18:34 +1000 Subject: Added FLTK.Widgets.Valuators.Value_Inputs --- src/c_fl_value_input.cpp | 137 +++++++++++ src/c_fl_value_input.h | 52 +++++ src/fltk-widgets-valuators-value_inputs.adb | 340 ++++++++++++++++++++++++++++ src/fltk-widgets-valuators-value_inputs.ads | 154 +++++++++++++ 4 files changed, 683 insertions(+) create mode 100644 src/c_fl_value_input.cpp create mode 100644 src/c_fl_value_input.h create mode 100644 src/fltk-widgets-valuators-value_inputs.adb create mode 100644 src/fltk-widgets-valuators-value_inputs.ads (limited to 'src') diff --git a/src/c_fl_value_input.cpp b/src/c_fl_value_input.cpp new file mode 100644 index 0000000..91404a6 --- /dev/null +++ b/src/c_fl_value_input.cpp @@ -0,0 +1,137 @@ + + +#include +#include "c_fl_value_input.h" +#include "c_fl_type.h" + + + + +class My_Value_Input : public Fl_Value_Input { + public: + using Fl_Value_Input::Fl_Value_Input; + friend void value_input_set_draw_hook(VALUE_INPUT a, void * d); + friend void fl_value_input_draw(VALUE_INPUT a); + friend void value_input_set_handle_hook(VALUE_INPUT a, void * h); + friend int fl_value_input_handle(VALUE_INPUT a, 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_Input::draw() { + (*draw_hook)(this->user_data()); +} + +void My_Value_Input::real_draw() { + Fl_Value_Input::draw(); +} + +int My_Value_Input::handle(int e) { + return (*handle_hook)(this->user_data(), e); +} + +int My_Value_Input::real_handle(int e) { + return Fl_Value_Input::handle(e); +} + +void value_input_set_draw_hook(VALUE_INPUT a, void * d) { + reinterpret_cast(a)->draw_hook = reinterpret_cast(d); +} + +void fl_value_input_draw(VALUE_INPUT a) { + reinterpret_cast(a)->real_draw(); +} + +void value_input_set_handle_hook(VALUE_INPUT a, void * h) { + reinterpret_cast(a)->handle_hook = reinterpret_cast(h); +} + +int fl_value_input_handle(VALUE_INPUT a, int e) { + return reinterpret_cast(a)->real_handle(e); +} + + + + +VALUE_INPUT new_fl_value_input(int x, int y, int w, int h, char* label) { + My_Value_Input *a = new My_Value_Input(x, y, w, h, label); + return a; +} + +void free_fl_value_input(VALUE_INPUT a) { + delete reinterpret_cast(a); +} + + + + +void * fl_value_input_get_input(VALUE_INPUT v) { + return &(reinterpret_cast(v)->input); +} + + + + +unsigned int fl_value_input_get_cursor_color(VALUE_INPUT v) { + return reinterpret_cast(v)->cursor_color(); +} + +void fl_value_input_set_cursor_color(VALUE_INPUT v, unsigned int c) { + reinterpret_cast(v)->cursor_color(c); +} + + + + +int fl_value_input_get_shortcut(VALUE_INPUT v) { + return reinterpret_cast(v)->Fl_Value_Input::shortcut(); +} + +void fl_value_input_set_shortcut(VALUE_INPUT v, int k) { + reinterpret_cast(v)->Fl_Value_Input::shortcut(k); +} + + + + +int fl_value_input_is_soft(VALUE_INPUT a) { + return reinterpret_cast(a)->soft(); +} + +void fl_value_input_set_soft(VALUE_INPUT a, int t) { + reinterpret_cast(a)->soft(t); +} + + + + +unsigned int fl_value_input_get_text_color(VALUE_INPUT v) { + return reinterpret_cast(v)->textcolor(); +} + +void fl_value_input_set_text_color(VALUE_INPUT v, unsigned int c) { + reinterpret_cast(v)->textcolor(static_cast(c)); +} + +int fl_value_input_get_text_font(VALUE_INPUT v) { + return reinterpret_cast(v)->textfont(); +} + +void fl_value_input_set_text_font(VALUE_INPUT v, int f) { + reinterpret_cast(v)->textfont(static_cast(f)); +} + +int fl_value_input_get_text_size(VALUE_INPUT v) { + return reinterpret_cast(v)->textsize(); +} + +void fl_value_input_set_text_size(VALUE_INPUT v, int s) { + reinterpret_cast(v)->textsize(static_cast(s)); +} + + diff --git a/src/c_fl_value_input.h b/src/c_fl_value_input.h new file mode 100644 index 0000000..ff360bd --- /dev/null +++ b/src/c_fl_value_input.h @@ -0,0 +1,52 @@ + + +#ifndef FL_VALUE_INPUT_GUARD +#define FL_VALUE_INPUT_GUARD + + + + +typedef void* VALUE_INPUT; + + + + +extern "C" void value_input_set_draw_hook(VALUE_INPUT a, void * d); +extern "C" void fl_value_input_draw(VALUE_INPUT a); +extern "C" void value_input_set_handle_hook(VALUE_INPUT a, void * h); +extern "C" int fl_value_input_handle(VALUE_INPUT a, int e); + + + + +extern "C" VALUE_INPUT new_fl_value_input(int x, int y, int w, int h, char* label); +extern "C" void free_fl_value_input(VALUE_INPUT a); + + + + +extern "C" void * fl_value_input_get_input(VALUE_INPUT v); + + +extern "C" unsigned int fl_value_input_get_cursor_color(VALUE_INPUT v); +extern "C" void fl_value_input_set_cursor_color(VALUE_INPUT v, unsigned int c); + + +extern "C" int fl_value_input_get_shortcut(VALUE_INPUT v); +extern "C" void fl_value_input_set_shortcut(VALUE_INPUT v, int k); + + +extern "C" int fl_value_input_is_soft(VALUE_INPUT a); +extern "C" void fl_value_input_set_soft(VALUE_INPUT a, int t); + + +extern "C" unsigned int fl_value_input_get_text_color(VALUE_INPUT v); +extern "C" void fl_value_input_set_text_color(VALUE_INPUT v, unsigned int c); +extern "C" int fl_value_input_get_text_font(VALUE_INPUT v); +extern "C" void fl_value_input_set_text_font(VALUE_INPUT v, int f); +extern "C" int fl_value_input_get_text_size(VALUE_INPUT v); +extern "C" void fl_value_input_set_text_size(VALUE_INPUT v, int s); + + +#endif + diff --git a/src/fltk-widgets-valuators-value_inputs.adb b/src/fltk-widgets-valuators-value_inputs.adb new file mode 100644 index 0000000..010906d --- /dev/null +++ b/src/fltk-widgets-valuators-value_inputs.adb @@ -0,0 +1,340 @@ + + +with + + Ada.Unchecked_Deallocation, + Interfaces.C.Strings, + System; + +use type + + Interfaces.C.int, + System.Address; + + +package body FLTK.Widgets.Valuators.Value_Inputs is + + + procedure value_input_set_draw_hook + (W, D : in System.Address); + pragma Import (C, value_input_set_draw_hook, "value_input_set_draw_hook"); + pragma Inline (value_input_set_draw_hook); + + procedure value_input_set_handle_hook + (W, H : in System.Address); + pragma Import (C, value_input_set_handle_hook, "value_input_set_handle_hook"); + pragma Inline (value_input_set_handle_hook); + + + + + function new_fl_value_input + (X, Y, W, H : in Interfaces.C.int; + Text : in Interfaces.C.char_array) + return System.Address; + pragma Import (C, new_fl_value_input, "new_fl_value_input"); + pragma Inline (new_fl_value_input); + + procedure free_fl_value_input + (A : in System.Address); + pragma Import (C, free_fl_value_input, "free_fl_value_input"); + pragma Inline (free_fl_value_input); + + + + + function fl_value_input_get_input + (V : in System.Address) + return System.Address; + pragma Import (C, fl_value_input_get_input, "fl_value_input_get_input"); + pragma Inline (fl_value_input_get_input); + + + + + function fl_value_input_get_cursor_color + (TD : in System.Address) + return Interfaces.C.unsigned; + pragma Import (C, fl_value_input_get_cursor_color, "fl_value_input_get_cursor_color"); + pragma Inline (fl_value_input_get_cursor_color); + + procedure fl_value_input_set_cursor_color + (TD : in System.Address; + C : in Interfaces.C.unsigned); + pragma Import (C, fl_value_input_set_cursor_color, "fl_value_input_set_cursor_color"); + pragma Inline (fl_value_input_set_cursor_color); + + + + + function fl_value_input_get_shortcut + (B : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_value_input_get_shortcut, "fl_value_input_get_shortcut"); + pragma Inline (fl_value_input_get_shortcut); + + procedure fl_value_input_set_shortcut + (B : in System.Address; + T : in Interfaces.C.int); + pragma Import (C, fl_value_input_set_shortcut, "fl_value_input_set_shortcut"); + pragma Inline (fl_value_input_set_shortcut); + + + + + function fl_value_input_is_soft + (A : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_value_input_is_soft, "fl_value_input_is_soft"); + pragma Inline (fl_value_input_is_soft); + + procedure fl_value_input_set_soft + (A : in System.Address; + T : in Interfaces.C.int); + pragma Import (C, fl_value_input_set_soft, "fl_value_input_set_soft"); + pragma Inline (fl_value_input_set_soft); + + + + + function fl_value_input_get_text_color + (TD : in System.Address) + return Interfaces.C.unsigned; + pragma Import (C, fl_value_input_get_text_color, "fl_value_input_get_text_color"); + pragma Inline (fl_value_input_get_text_color); + + procedure fl_value_input_set_text_color + (TD : in System.Address; + C : in Interfaces.C.unsigned); + pragma Import (C, fl_value_input_set_text_color, "fl_value_input_set_text_color"); + pragma Inline (fl_value_input_set_text_color); + + function fl_value_input_get_text_font + (TD : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_value_input_get_text_font, "fl_value_input_get_text_font"); + pragma Inline (fl_value_input_get_text_font); + + procedure fl_value_input_set_text_font + (TD : in System.Address; + F : in Interfaces.C.int); + pragma Import (C, fl_value_input_set_text_font, "fl_value_input_set_text_font"); + pragma Inline (fl_value_input_set_text_font); + + function fl_value_input_get_text_size + (TD : in System.Address) + return Interfaces.C.int; + pragma Import (C, fl_value_input_get_text_size, "fl_value_input_get_text_size"); + pragma Inline (fl_value_input_get_text_size); + + procedure fl_value_input_set_text_size + (TD : in System.Address; + S : in Interfaces.C.int); + pragma Import (C, fl_value_input_set_text_size, "fl_value_input_set_text_size"); + pragma Inline (fl_value_input_set_text_size); + + + + + procedure fl_value_input_draw + (W : in System.Address); + pragma Import (C, fl_value_input_draw, "fl_value_input_draw"); + pragma Inline (fl_value_input_draw); + + function fl_value_input_handle + (W : in System.Address; + E : in Interfaces.C.int) + return Interfaces.C.int; + pragma Import (C, fl_value_input_handle, "fl_value_input_handle"); + pragma Inline (fl_value_input_handle); + + + + + procedure Free is new Ada.Unchecked_Deallocation + (INP.Input, Input_Access); + + + + + procedure Finalize + (This : in out Value_Input) is + begin + if This.Void_Ptr /= System.Null_Address and then + This in Value_Input'Class + then + free_fl_value_input (This.Void_Ptr); + Free (This.My_Input); + This.Void_Ptr := System.Null_Address; + end if; + Finalize (Valuator (This)); + end Finalize; + + + + + package body Forge is + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Value_Input is + begin + return This : Value_Input do + This.Void_Ptr := new_fl_value_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)); + value_input_set_draw_hook (This.Void_Ptr, Draw_Hook'Address); + value_input_set_handle_hook (This.Void_Ptr, Handle_Hook'Address); + + This.My_Input := new INP.Input; + Wrapper (This.My_Input.all).Void_Ptr := + fl_value_input_get_input (This.Void_Ptr); + Wrapper (This.My_Input.all).Needs_Dealloc := False; + end return; + end Create; + + end Forge; + + + + + function Input + (This : in Value_Input) + return FLTK.Widgets.Inputs.Input_Reference is + begin + return (Data => This.My_Input); + end Input; + + + + + function Get_Cursor_Color + (This : in Value_Input) + return Color is + begin + return Color (fl_value_input_get_cursor_color (This.Void_Ptr)); + end Get_Cursor_Color; + + + procedure Set_Cursor_Color + (This : in out Value_Input; + Col : in Color) is + begin + fl_value_input_set_cursor_color (This.Void_Ptr, Interfaces.C.unsigned (Col)); + end Set_Cursor_Color; + + + + + function Get_Shortcut + (This : in Value_Input) + return Key_Combo is + begin + return To_Ada (Interfaces.C.unsigned_long (fl_value_input_get_shortcut (This.Void_Ptr))); + end Get_Shortcut; + + + procedure Set_Shortcut + (This : in out Value_Input; + Key : in Key_Combo) is + begin + fl_value_input_set_shortcut (This.Void_Ptr, Interfaces.C.int (To_C (Key))); + end Set_Shortcut; + + + + + function Is_Soft + (This : in Value_Input) + return Boolean is + begin + return fl_value_input_is_soft (This.Void_Ptr) /= 0; + end Is_Soft; + + + procedure Set_Soft + (This : in out Value_Input; + To : in Boolean) is + begin + fl_value_input_set_soft (This.Void_Ptr, Boolean'Pos (To)); + end Set_Soft; + + + + + function Get_Text_Color + (This : in Value_Input) + return Color is + begin + return Color (fl_value_input_get_text_color (This.Void_Ptr)); + end Get_Text_Color; + + + procedure Set_Text_Color + (This : in out Value_Input; + Col : in Color) is + begin + fl_value_input_set_text_color (This.Void_Ptr, Interfaces.C.unsigned (Col)); + end Set_Text_Color; + + + function Get_Text_Font + (This : in Value_Input) + return Font_Kind is + begin + return Font_Kind'Val (fl_value_input_get_text_font (This.Void_Ptr)); + end Get_Text_Font; + + + procedure Set_Text_Font + (This : in out Value_Input; + Font : in Font_Kind) is + begin + fl_value_input_set_text_font (This.Void_Ptr, Font_Kind'Pos (Font)); + end Set_Text_Font; + + + function Get_Text_Size + (This : in Value_Input) + return Font_Size is + begin + return Font_Size (fl_value_input_get_text_size (This.Void_Ptr)); + end Get_Text_Size; + + + procedure Set_Text_Size + (This : in out Value_Input; + Size : in Font_Size) is + begin + fl_value_input_set_text_size (This.Void_Ptr, Interfaces.C.int (Size)); + end Set_Text_Size; + + + + + procedure Draw + (This : in out Value_Input) is + begin + fl_value_input_draw (This.Void_Ptr); + end Draw; + + + function Handle + (This : in out Value_Input; + Event : in Event_Kind) + return Event_Outcome is + begin + return Event_Outcome'Val + (fl_value_input_handle (This.Void_Ptr, Event_Kind'Pos (Event))); + end Handle; + + +end FLTK.Widgets.Valuators.Value_Inputs; + diff --git a/src/fltk-widgets-valuators-value_inputs.ads b/src/fltk-widgets-valuators-value_inputs.ads new file mode 100644 index 0000000..b56874c --- /dev/null +++ b/src/fltk-widgets-valuators-value_inputs.ads @@ -0,0 +1,154 @@ + + +with + + FLTK.Widgets.Inputs; + + +package FLTK.Widgets.Valuators.Value_Inputs is + + + type Value_Input is new Valuator with private; + + type Value_Input_Reference (Data : not null access Value_Input'Class) is + limited null record with Implicit_Dereference => Data; + + + + + package Forge is + + function Create + (X, Y, W, H : in Integer; + Text : in String) + return Value_Input; + + end Forge; + + + + + function Input + (This : in Value_Input) + return FLTK.Widgets.Inputs.Input_Reference; + + + + + function Get_Cursor_Color + (This : in Value_Input) + return Color; + + procedure Set_Cursor_Color + (This : in out Value_Input; + Col : in Color); + + + + + function Get_Shortcut + (This : in Value_Input) + return Key_Combo; + + procedure Set_Shortcut + (This : in out Value_Input; + Key : in Key_Combo); + + + + + function Is_Soft + (This : in Value_Input) + return Boolean; + + procedure Set_Soft + (This : in out Value_Input; + To : in Boolean); + + + + + function Get_Text_Color + (This : in Value_Input) + return Color; + + procedure Set_Text_Color + (This : in out Value_Input; + Col : in Color); + + function Get_Text_Font + (This : in Value_Input) + return Font_Kind; + + procedure Set_Text_Font + (This : in out Value_Input; + Font : in Font_Kind); + + function Get_Text_Size + (This : in Value_Input) + return Font_Size; + + procedure Set_Text_Size + (This : in out Value_Input; + Size : in Font_Size); + + + + + procedure Draw + (This : in out Value_Input); + + function Handle + (This : in out Value_Input; + Event : in Event_Kind) + return Event_Outcome; + + +private + + + package INP renames FLTK.Widgets.Inputs; + + + type Input_Access is access INP.Input; + + + type Value_Input is new Valuator with record + My_Input : Input_Access; + end record; + + overriding procedure Finalize + (This : in out Value_Input); + + + + + pragma Inline (Input); + + + pragma Inline (Get_Cursor_Color); + pragma Inline (Set_Cursor_Color); + + + pragma Inline (Get_Shortcut); + pragma Inline (Set_Shortcut); + + + pragma Inline (Is_Soft); + pragma Inline (Set_Soft); + + + pragma Inline (Get_Text_Color); + pragma Inline (Set_Text_Color); + pragma Inline (Get_Text_Font); + pragma Inline (Set_Text_Font); + pragma Inline (Get_Text_Size); + pragma Inline (Set_Text_Size); + + + pragma Inline (Draw); + pragma Inline (Handle); + + +end FLTK.Widgets.Valuators.Value_Inputs; + -- cgit