summaryrefslogtreecommitdiff
path: root/src/fltk-widgets-positioners.adb
blob: 0e3dfb2862aa25314a1627af21457b0f5471c3a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525


--  Programmed by Jedidiah Barber
--  Released into the public domain


with

    Ada.Assertions,
    Interfaces.C;


package body FLTK.Widgets.Positioners is


    package Chk renames Ada.Assertions;




    ------------------------
    --  Functions From C  --
    ------------------------

    function new_fl_positioner
           (X, Y, W, H : in Interfaces.C.int;
            Text       : in Interfaces.C.char_array)
        return Storage.Integer_Address;
    pragma Import (C, new_fl_positioner, "new_fl_positioner");
    pragma Inline (new_fl_positioner);

    procedure free_fl_positioner
           (P : in Storage.Integer_Address);
    pragma Import (C, free_fl_positioner, "free_fl_positioner");
    pragma Inline (free_fl_positioner);




    function fl_positioner_set_value
           (P    : in Storage.Integer_Address;
            X, Y : in Interfaces.C.double)
        return Interfaces.C.int;
    pragma Import (C, fl_positioner_set_value, "fl_positioner_set_value");
    pragma Inline (fl_positioner_set_value);




    procedure fl_positioner_xbounds
           (P    : in Storage.Integer_Address;
            L, H : in Interfaces.C.double);
    pragma Import (C, fl_positioner_xbounds, "fl_positioner_xbounds");
    pragma Inline (fl_positioner_xbounds);

    procedure fl_positioner_xstep
           (P : in Storage.Integer_Address;
            A : in Interfaces.C.double);
    pragma Import (C, fl_positioner_xstep, "fl_positioner_xstep");
    pragma Inline (fl_positioner_xstep);

    function fl_positioner_get_xminimum
           (P : in Storage.Integer_Address)
        return Interfaces.C.double;
    pragma Import (C, fl_positioner_get_xminimum, "fl_positioner_get_xminimum");
    pragma Inline (fl_positioner_get_xminimum);

    procedure fl_positioner_set_xminimum
           (P : in Storage.Integer_Address;
            A : in Interfaces.C.double);
    pragma Import (C, fl_positioner_set_xminimum, "fl_positioner_set_xminimum");
    pragma Inline (fl_positioner_set_xminimum);

    function fl_positioner_get_xmaximum
           (P : in Storage.Integer_Address)
        return Interfaces.C.double;
    pragma Import (C, fl_positioner_get_xmaximum, "fl_positioner_get_xmaximum");
    pragma Inline (fl_positioner_get_xmaximum);

    procedure fl_positioner_set_xmaximum
           (P : in Storage.Integer_Address;
            A : in Interfaces.C.double);
    pragma Import (C, fl_positioner_set_xmaximum, "fl_positioner_set_xmaximum");
    pragma Inline (fl_positioner_set_xmaximum);

    function fl_positioner_get_xvalue
           (P : in Storage.Integer_Address)
        return Interfaces.C.double;
    pragma Import (C, fl_positioner_get_xvalue, "fl_positioner_get_xvalue");
    pragma Inline (fl_positioner_get_xvalue);

    function fl_positioner_set_xvalue
           (P : in Storage.Integer_Address;
            V : in Interfaces.C.double)
        return Interfaces.C.int;
    pragma Import (C, fl_positioner_set_xvalue, "fl_positioner_set_xvalue");
    pragma Inline (fl_positioner_set_xvalue);




    procedure fl_positioner_ybounds
           (P    : in Storage.Integer_Address;
            L, H : in Interfaces.C.double);
    pragma Import (C, fl_positioner_ybounds, "fl_positioner_ybounds");
    pragma Inline (fl_positioner_ybounds);

    procedure fl_positioner_ystep
           (P : in Storage.Integer_Address;
            A : in Interfaces.C.double);
    pragma Import (C, fl_positioner_ystep, "fl_positioner_ystep");
    pragma Inline (fl_positioner_ystep);

    function fl_positioner_get_yminimum
           (P : in Storage.Integer_Address)
        return Interfaces.C.double;
    pragma Import (C, fl_positioner_get_yminimum, "fl_positioner_get_yminimum");
    pragma Inline (fl_positioner_get_yminimum);

    procedure fl_positioner_set_yminimum
           (P : in Storage.Integer_Address;
            A : in Interfaces.C.double);
    pragma Import (C, fl_positioner_set_yminimum, "fl_positioner_set_yminimum");
    pragma Inline (fl_positioner_set_yminimum);

    function fl_positioner_get_ymaximum
           (P : in Storage.Integer_Address)
        return Interfaces.C.double;
    pragma Import (C, fl_positioner_get_ymaximum, "fl_positioner_get_ymaximum");
    pragma Inline (fl_positioner_get_ymaximum);

    procedure fl_positioner_set_ymaximum
           (P : in Storage.Integer_Address;
            A : in Interfaces.C.double);
    pragma Import (C, fl_positioner_set_ymaximum, "fl_positioner_set_ymaximum");
    pragma Inline (fl_positioner_set_ymaximum);

    function fl_positioner_get_yvalue
           (P : in Storage.Integer_Address)
        return Interfaces.C.double;
    pragma Import (C, fl_positioner_get_yvalue, "fl_positioner_get_yvalue");
    pragma Inline (fl_positioner_get_yvalue);

    function fl_positioner_set_yvalue
           (P : in Storage.Integer_Address;
            V : in Interfaces.C.double)
        return Interfaces.C.int;
    pragma Import (C, fl_positioner_set_yvalue, "fl_positioner_set_yvalue");
    pragma Inline (fl_positioner_set_yvalue);




    procedure fl_positioner_draw
           (P : in Storage.Integer_Address);
    pragma Import (C, fl_positioner_draw, "fl_positioner_draw");
    pragma Inline (fl_positioner_draw);

    procedure fl_positioner_draw2
           (P          : in Storage.Integer_Address;
            X, Y, W, H : in Interfaces.C.int);
    pragma Import (C, fl_positioner_draw2, "fl_positioner_draw2");
    pragma Inline (fl_positioner_draw2);

    function fl_positioner_handle
           (P : in Storage.Integer_Address;
            E : in Interfaces.C.int)
        return Interfaces.C.int;
    pragma Import (C, fl_positioner_handle, "fl_positioner_handle");
    pragma Inline (fl_positioner_handle);

    function fl_positioner_handle2
           (P             : in Storage.Integer_Address;
            E, X, Y, W, H : in Interfaces.C.int)
        return Interfaces.C.int;
    pragma Import (C, fl_positioner_handle2, "fl_positioner_handle2");
    pragma Inline (fl_positioner_handle2);




    -------------------
    --  Destructors  --
    -------------------

    procedure Extra_Final
           (This : in out Positioner) is
    begin
        Extra_Final (Widget (This));
    end Extra_Final;


    procedure Finalize
           (This : in out Positioner) is
    begin
        Extra_Final (This);
        if This.Void_Ptr /= Null_Pointer and This.Needs_Dealloc then
            free_fl_positioner (This.Void_Ptr);
            This.Void_Ptr := Null_Pointer;
        end if;
    end Finalize;




    --------------------
    --  Constructors  --
    --------------------

    procedure Extra_Init
           (This       : in out Positioner;
            X, Y, W, H : in     Integer;
            Text       : in     String) is
    begin
        Extra_Init (Widget (This), X, Y, W, H, Text);
    end Extra_Init;


    procedure Initialize
           (This : in out Positioner) is
    begin
        This.Draw_Ptr   := fl_positioner_draw'Address;
        This.Handle_Ptr := fl_positioner_handle'Address;
    end Initialize;


    package body Forge is

        function Create
               (X, Y, W, H : in Integer;
                Text       : in String := "")
            return Positioner is
        begin
            return This : Positioner do
                This.Void_Ptr := new_fl_positioner
                   (Interfaces.C.int (X),
                    Interfaces.C.int (Y),
                    Interfaces.C.int (W),
                    Interfaces.C.int (H),
                    Interfaces.C.To_C (Text));
                Extra_Init (This, X, Y, W, H, Text);
            end return;
        end Create;

    end Forge;




    -----------------------
    --  API Subprograms  --
    -----------------------

    procedure Get_Coords
           (This : in     Positioner;
            X, Y :    out Long_Float) is
    begin
        X := This.Get_Ecks;
        Y := This.Get_Why;
    end Get_Coords;


    procedure Set_Coords
           (This : in out Positioner;
            X, Y : in     Long_Float)
    is
        Result : Interfaces.C.int := fl_positioner_set_value
           (This.Void_Ptr,
            Interfaces.C.double (X),
            Interfaces.C.double (Y));
    begin
        pragma Assert (Result in 0 .. 1);
    exception
    when Chk.Assertion_Error => raise Internal_FLTK_Error;
    end Set_Coords;


    function Set_Coords
           (This : in out Positioner;
            X, Y : in     Long_Float)
        return Boolean
    is
        Result : Interfaces.C.int := fl_positioner_set_value
           (This.Void_Ptr,
            Interfaces.C.double (X),
            Interfaces.C.double (Y));
    begin
        return Boolean'Val (Result);
    exception
    when Constraint_Error => raise Internal_FLTK_Error;
    end Set_Coords;




    procedure Set_Ecks_Bounds
           (This      : in out Positioner;
            Low, High : in     Long_Float) is
    begin
        fl_positioner_xbounds
           (This.Void_Ptr,
            Interfaces.C.double (Low),
            Interfaces.C.double (High));
    end Set_Ecks_Bounds;


    procedure Set_Ecks_Step
           (This  : in out Positioner;
            Value : in     Long_Float) is
    begin
        fl_positioner_xstep (This.Void_Ptr, Interfaces.C.double (Value));
    end Set_Ecks_Step;


    function Get_Ecks_Minimum
           (This : in Positioner)
        return Long_Float is
    begin
        return Long_Float (fl_positioner_get_xminimum (This.Void_Ptr));
    end Get_Ecks_Minimum;


    procedure Set_Ecks_Minimum
           (This  : in out Positioner;
            Value : in     Long_Float) is
    begin
        fl_positioner_set_xminimum (This.Void_Ptr, Interfaces.C.double (Value));
    end Set_Ecks_Minimum;


    function Get_Ecks_Maximum
           (This : in Positioner)
        return Long_Float is
    begin
        return Long_Float (fl_positioner_get_xmaximum (This.Void_Ptr));
    end Get_Ecks_Maximum;


    procedure Set_Ecks_Maximum
           (This  : in out Positioner;
            Value : in     Long_Float) is
    begin
        fl_positioner_set_xmaximum (This.Void_Ptr, Interfaces.C.double (Value));
    end Set_Ecks_Maximum;


    function Get_Ecks
           (This : in Positioner)
        return Long_Float is
    begin
        return Long_Float (fl_positioner_get_xvalue (This.Void_Ptr));
    end Get_Ecks;


    procedure Set_Ecks
           (This  : in out Positioner;
            Value : in     Long_Float)
    is
        Result : Interfaces.C.int := fl_positioner_set_xvalue
           (This.Void_Ptr,
            Interfaces.C.double (Value));
    begin
        pragma Assert (Result in 0 .. 1);
    exception
    when Chk.Assertion_Error => raise Internal_FLTK_Error;
    end Set_Ecks;


    function Set_Ecks
           (This  : in out Positioner;
            Value : in     Long_Float)
        return Boolean
    is
        Result : Interfaces.C.int := fl_positioner_set_xvalue
           (This.Void_Ptr,
            Interfaces.C.double (Value));
    begin
        return Boolean'Val (Result);
    exception
    when Constraint_Error => raise Internal_FLTK_Error;
    end Set_Ecks;




    procedure Set_Why_Bounds
           (This      : in out Positioner;
            Low, High : in     Long_Float) is
    begin
        fl_positioner_ybounds
           (This.Void_Ptr,
            Interfaces.C.double (Low),
            Interfaces.C.double (High));
    end Set_Why_Bounds;


    procedure Set_Why_Step
           (This  : in out Positioner;
            Value : in     Long_Float) is
    begin
        fl_positioner_ystep (This.Void_Ptr, Interfaces.C.double (Value));
    end Set_Why_Step;


    function Get_Why_Minimum
           (This : in Positioner)
        return Long_Float is
    begin
        return Long_Float (fl_positioner_get_yminimum (This.Void_Ptr));
    end Get_Why_Minimum;


    procedure Set_Why_Minimum
           (This  : in out Positioner;
            Value : in     Long_Float) is
    begin
        fl_positioner_set_yminimum (This.Void_Ptr, Interfaces.C.double (Value));
    end Set_Why_Minimum;


    function Get_Why_Maximum
           (This : in Positioner)
        return Long_Float is
    begin
        return Long_Float (fl_positioner_get_ymaximum (This.Void_Ptr));
    end Get_Why_Maximum;


    procedure Set_Why_Maximum
           (This  : in out Positioner;
            Value : in     Long_Float) is
    begin
        fl_positioner_set_ymaximum (This.Void_Ptr, Interfaces.C.double (Value));
    end Set_Why_Maximum;


    function Get_Why
           (This : in Positioner)
        return Long_Float is
    begin
        return Long_Float (fl_positioner_get_yvalue (This.Void_Ptr));
    end Get_Why;


    procedure Set_Why
           (This  : in out Positioner;
            Value : in     Long_Float)
    is
        Result : Interfaces.C.int := fl_positioner_set_yvalue
           (This.Void_Ptr,
            Interfaces.C.double (Value));
    begin
        pragma Assert (Result in 0 .. 1);
    exception
    when Chk.Assertion_Error => raise Internal_FLTK_Error;
    end Set_Why;


    function Set_Why
           (This  : in out Positioner;
            Value : in     Long_Float)
        return Boolean
    is
        Result : Interfaces.C.int := fl_positioner_set_yvalue
           (This.Void_Ptr,
            Interfaces.C.double (Value));
    begin
        return Boolean'Val (Result);
    exception
    when Constraint_Error => raise Internal_FLTK_Error;
    end Set_Why;




    procedure Draw
           (This : in out Positioner) is
    begin
        Widget (This).Draw;
    end Draw;


    procedure Draw
           (This       : in out Positioner;
            X, Y, W, H : in     Integer) is
    begin
        fl_positioner_draw2
           (This.Void_Ptr,
            Interfaces.C.int (X),
            Interfaces.C.int (Y),
            Interfaces.C.int (W),
            Interfaces.C.int (H));
    end Draw;


    function Handle
           (This  : in out Positioner;
            Event : in     Event_Kind)
        return Event_Outcome is
    begin
        return Widget (This).Handle (Event);
    end Handle;


    function Handle
           (This       : in out Positioner;
            Event      : in     Event_Kind;
            X, Y, W, H : in     Integer)
        return Event_Outcome is
    begin
        return Event_Outcome'Val (fl_positioner_handle2
           (This.Void_Ptr,
            Event_Kind'Pos (Event),
            Interfaces.C.int (X),
            Interfaces.C.int (Y),
            Interfaces.C.int (W),
            Interfaces.C.int (H)));
    exception
    when Constraint_Error => raise Internal_FLTK_Error;
    end Handle;


end FLTK.Widgets.Positioners;