From e93b9bbc02e2791f3a35b6f077fcbb8514c28aed Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Sun, 12 Jan 2025 01:14:58 +1300 Subject: Refactored draw/handle methods in Widgets hierarchy, improved docs, added a few minor method bindings here and there --- src/fltk-widgets-valuators-counters.adb | 72 ++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 23 deletions(-) (limited to 'src/fltk-widgets-valuators-counters.adb') diff --git a/src/fltk-widgets-valuators-counters.adb b/src/fltk-widgets-valuators-counters.adb index fd0619e..30001a8 100644 --- a/src/fltk-widgets-valuators-counters.adb +++ b/src/fltk-widgets-valuators-counters.adb @@ -12,18 +12,9 @@ with package body FLTK.Widgets.Valuators.Counters is - procedure counter_set_draw_hook - (W, D : in Storage.Integer_Address); - pragma Import (C, counter_set_draw_hook, "counter_set_draw_hook"); - pragma Inline (counter_set_draw_hook); - - procedure counter_set_handle_hook - (W, H : in Storage.Integer_Address); - pragma Import (C, counter_set_handle_hook, "counter_set_handle_hook"); - pragma Inline (counter_set_handle_hook); - - - + ------------------------ + -- Functions From C -- + ------------------------ function new_fl_counter (X, Y, W, H : in Interfaces.C.int; @@ -46,11 +37,11 @@ package body FLTK.Widgets.Valuators.Counters is pragma Import (C, fl_counter_get_step, "fl_counter_get_step"); pragma Inline (fl_counter_get_step); - procedure fl_counter_set_step + procedure fl_counter_set_step_top (C : in Storage.Integer_Address; T : in Interfaces.C.double); - pragma Import (C, fl_counter_set_step, "fl_counter_set_step"); - pragma Inline (fl_counter_set_step); + pragma Import (C, fl_counter_set_step_top, "fl_counter_set_step_top"); + pragma Inline (fl_counter_set_step_top); procedure fl_counter_set_lstep (C : in Storage.Integer_Address; @@ -58,6 +49,12 @@ package body FLTK.Widgets.Valuators.Counters is pragma Import (C, fl_counter_set_lstep, "fl_counter_set_lstep"); pragma Inline (fl_counter_set_lstep); + procedure fl_counter_set_step_both + (C : in Storage.Integer_Address; + S, L : in Interfaces.C.double); + pragma Import (C, fl_counter_set_step_both, "fl_counter_set_step_both"); + pragma Inline (fl_counter_set_step_both); + @@ -115,6 +112,10 @@ package body FLTK.Widgets.Valuators.Counters is + ------------------- + -- Destructors -- + ------------------- + procedure Extra_Final (This : in out Counter) is begin @@ -135,6 +136,10 @@ package body FLTK.Widgets.Valuators.Counters is + -------------------- + -- Constructors -- + -------------------- + procedure Extra_Init (This : in out Counter; X, Y, W, H : in Integer; @@ -144,6 +149,14 @@ package body FLTK.Widgets.Valuators.Counters is end Extra_Init; + procedure Initialize + (This : in out Counter) is + begin + This.Draw_Ptr := fl_counter_draw'Address; + This.Handle_Ptr := fl_counter_handle'Address; + end Initialize; + + package body Forge is function Create @@ -159,8 +172,6 @@ package body FLTK.Widgets.Valuators.Counters is Interfaces.C.int (H), Interfaces.C.To_C (Text)); Extra_Init (This, X, Y, W, H, Text); - counter_set_draw_hook (This.Void_Ptr, Storage.To_Integer (Draw_Hook'Address)); - counter_set_handle_hook (This.Void_Ptr, Storage.To_Integer (Handle_Hook'Address)); end return; end Create; @@ -169,6 +180,10 @@ package body FLTK.Widgets.Valuators.Counters is + ----------------------- + -- API Subprograms -- + ----------------------- + function Get_Step (This : in Counter) return Long_Float is @@ -177,12 +192,12 @@ package body FLTK.Widgets.Valuators.Counters is end Get_Step; - procedure Set_Step + procedure Set_Step_Top (This : in out Counter; To : in Long_Float) is begin - fl_counter_set_step (This.Void_Ptr, Interfaces.C.double (To)); - end Set_Step; + fl_counter_set_step_top (This.Void_Ptr, Interfaces.C.double (To)); + end Set_Step_Top; function Get_Long_Step @@ -202,6 +217,17 @@ package body FLTK.Widgets.Valuators.Counters is end Set_Long_Step; + procedure Set_Step_Both + (This : in out Counter; + Short, Long : in Long_Float) is + begin + fl_counter_set_step_both + (This.Void_Ptr, + Interfaces.C.double (Short), + Interfaces.C.double (Long)); + end Set_Step_Both; + + function Get_Text_Color @@ -257,7 +283,7 @@ package body FLTK.Widgets.Valuators.Counters is procedure Draw (This : in out Counter) is begin - fl_counter_draw (This.Void_Ptr); + Valuator (This).Draw; end Draw; @@ -266,10 +292,10 @@ package body FLTK.Widgets.Valuators.Counters is Event : in Event_Kind) return Event_Outcome is begin - return Event_Outcome'Val - (fl_counter_handle (This.Void_Ptr, Event_Kind'Pos (Event))); + return Valuator (This).Handle (Event); end Handle; end FLTK.Widgets.Valuators.Counters; + -- cgit