summaryrefslogtreecommitdiff
path: root/src/fltk-widgets-groups-color_choosers.adb
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2025-01-12 01:14:58 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2025-01-12 01:14:58 +1300
commite93b9bbc02e2791f3a35b6f077fcbb8514c28aed (patch)
tree3661530027db6809a9cbad7b2477416009e00787 /src/fltk-widgets-groups-color_choosers.adb
parent53aa8144851913994b963ed611cca8885b8f9a9e (diff)
Refactored draw/handle methods in Widgets hierarchy, improved docs, added a few minor method bindings here and there
Diffstat (limited to 'src/fltk-widgets-groups-color_choosers.adb')
-rw-r--r--src/fltk-widgets-groups-color_choosers.adb128
1 files changed, 74 insertions, 54 deletions
diff --git a/src/fltk-widgets-groups-color_choosers.adb b/src/fltk-widgets-groups-color_choosers.adb
index 9c02667..5c52ce3 100644
--- a/src/fltk-widgets-groups-color_choosers.adb
+++ b/src/fltk-widgets-groups-color_choosers.adb
@@ -6,6 +6,7 @@
with
+ Ada.Assertions,
Interfaces.C;
use type
@@ -16,18 +17,14 @@ use type
package body FLTK.Widgets.Groups.Color_Choosers is
- procedure color_chooser_set_draw_hook
- (W, D : in Storage.Integer_Address);
- pragma Import (C, color_chooser_set_draw_hook, "color_chooser_set_draw_hook");
- pragma Inline (color_chooser_set_draw_hook);
+ package Chk renames Ada.Assertions;
- procedure color_chooser_set_handle_hook
- (W, H : in Storage.Integer_Address);
- pragma Import (C, color_chooser_set_handle_hook, "color_chooser_set_handle_hook");
- pragma Inline (color_chooser_set_handle_hook);
+ ------------------------
+ -- Functions From C --
+ ------------------------
function new_fl_color_chooser
(X, Y, W, H : in Interfaces.C.int;
@@ -145,6 +142,10 @@ package body FLTK.Widgets.Groups.Color_Choosers is
+ -------------------
+ -- Destructors --
+ -------------------
+
procedure Extra_Final
(This : in out Color_Chooser) is
begin
@@ -165,6 +166,10 @@ package body FLTK.Widgets.Groups.Color_Choosers is
+ --------------------
+ -- Constructors --
+ --------------------
+
procedure Extra_Init
(This : in out Color_Chooser;
X, Y, W, H : in Integer;
@@ -174,6 +179,14 @@ package body FLTK.Widgets.Groups.Color_Choosers is
end Extra_Init;
+ procedure Initialize
+ (This : in out Color_Chooser) is
+ begin
+ This.Draw_Ptr := fl_color_chooser_draw'Address;
+ This.Handle_Ptr := fl_color_chooser_handle'Address;
+ end Initialize;
+
+
package body Forge is
function Create
@@ -189,10 +202,6 @@ package body FLTK.Widgets.Groups.Color_Choosers is
Interfaces.C.int (H),
Interfaces.C.To_C (Text));
Extra_Init (This, X, Y, W, H, Text);
- color_chooser_set_draw_hook
- (This.Void_Ptr, Storage.To_Integer (Draw_Hook'Address));
- color_chooser_set_handle_hook
- (This.Void_Ptr, Storage.To_Integer (Handle_Hook'Address));
end return;
end Create;
@@ -201,6 +210,10 @@ package body FLTK.Widgets.Groups.Color_Choosers is
+ -----------------------
+ -- API Subprograms --
+ -----------------------
+
function Get_Red
(This : in Color_Chooser)
return Long_Float is
@@ -227,13 +240,34 @@ package body FLTK.Widgets.Groups.Color_Choosers is
procedure Set_RGB
(This : in out Color_Chooser;
- R, G, B : in Long_Float) is
+ R, G, B : in Long_Float)
+ is
+ Result : Interfaces.C.int := fl_color_chooser_rgb
+ (This.Void_Ptr,
+ Interfaces.C.double (R),
+ Interfaces.C.double (G),
+ Interfaces.C.double (B));
begin
- This.Was_Changed := fl_color_chooser_rgb
+ pragma Assert (Result in 0 .. 1);
+ exception
+ when Chk.Assertion_Error => raise Internal_FLTK_Error;
+ end Set_RGB;
+
+
+ function Set_RGB
+ (This : in out Color_Chooser;
+ R, G, B : in Long_Float)
+ return Boolean
+ is
+ Result : Interfaces.C.int := fl_color_chooser_rgb
(This.Void_Ptr,
Interfaces.C.double (R),
Interfaces.C.double (G),
- Interfaces.C.double (B)) /= 0;
+ Interfaces.C.double (B));
+ begin
+ return Boolean'Val (Result);
+ exception
+ when Constraint_Error => raise Internal_FLTK_Error;
end Set_RGB;
@@ -265,13 +299,34 @@ package body FLTK.Widgets.Groups.Color_Choosers is
procedure Set_HSV
(This : in out Color_Chooser;
- H, S, V : in Long_Float) is
+ H, S, V : in Long_Float)
+ is
+ Result : Interfaces.C.int := fl_color_chooser_hsv
+ (This.Void_Ptr,
+ Interfaces.C.double (H),
+ Interfaces.C.double (S),
+ Interfaces.C.double (V));
begin
- This.Was_Changed := fl_color_chooser_hsv
+ pragma Assert (Result in 0 .. 1);
+ exception
+ when Chk.Assertion_Error => raise Internal_FLTK_Error;
+ end Set_HSV;
+
+
+ function Set_HSV
+ (This : in out Color_Chooser;
+ H, S, V : in Long_Float)
+ return Boolean
+ is
+ Result : Interfaces.C.int := fl_color_chooser_hsv
(This.Void_Ptr,
Interfaces.C.double (H),
Interfaces.C.double (S),
- Interfaces.C.double (V)) /= 0;
+ Interfaces.C.double (V));
+ begin
+ return Boolean'Val (Result);
+ exception
+ when Constraint_Error => raise Internal_FLTK_Error;
end Set_HSV;
@@ -307,23 +362,6 @@ package body FLTK.Widgets.Groups.Color_Choosers is
- function Color_Was_Changed
- (This : in Color_Chooser)
- return Boolean is
- begin
- return This.Was_Changed;
- end Color_Was_Changed;
-
-
- procedure Clear_Changed
- (This : in out Color_Chooser) is
- begin
- This.Was_Changed := False;
- end Clear_Changed;
-
-
-
-
function Get_Mode
(This : in Color_Chooser)
return Color_Mode is
@@ -340,24 +378,6 @@ package body FLTK.Widgets.Groups.Color_Choosers is
end Set_Mode;
-
-
- procedure Draw
- (This : in out Color_Chooser) is
- begin
- fl_color_chooser_draw (This.Void_Ptr);
- end Draw;
-
-
- function Handle
- (This : in out Color_Chooser;
- Event : in Event_Kind)
- return Event_Outcome is
- begin
- return Event_Outcome'Val
- (fl_color_chooser_handle (This.Void_Ptr, Event_Kind'Pos (Event)));
- end Handle;
-
-
end FLTK.Widgets.Groups.Color_Choosers;
+