-
Notifications
You must be signed in to change notification settings - Fork 0
/
p_fenetre.adb
530 lines (441 loc) · 17.3 KB
/
p_fenetre.adb
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
526
527
528
529
530
-----------------------------------------------------------------------
--
-- File: adagraph.adb
-- Description: basic Win32 graphics
-- Rev: 0.7
-- Date: march-2013
-- Author: Jerry van Dijk
-- Mail: jdijk@acm.org
--
-- Copyright (c) Jerry van Dijk, 1997 - 2003
-- Billie Hollidaystraat 28
-- 2324 LK Leiden
-- THE NETHERLANDS
-- tel int + 31 71 531 4365
--
-- Permission granted to use for any purpose, provided this copyright
-- remains attached and unmodified.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
-- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
--
-- Correctif
-- Author: B. Weinberg
-- Mail: benjamin.roman.weinberg@gmail.com
--
-----------------------------------------------------------------------
with Interfaces.C, Ada.Numerics;
package body P_fenetre is
pragma Linker_Options ("-lfenetre");
--------------------------------
-- Make the C types available --
--------------------------------
package C renames Interfaces.C;
----------------------------
-- DLL Internal constants --
----------------------------
No_Errors : constant Integer := 0;
MouseNone : constant Integer := 0;
MouseMove : constant Integer := 1;
MouseLeftUp : constant Integer := 2;
MouseRightUp : constant Integer := 3;
MouseLeftDown : constant Integer := 4;
MouseRightDown : constant Integer := 5;
------------------------
-- DLL Internal types --
------------------------
type MouseEventStruct is
record
Event : Integer;
Xpos : Integer;
Ypos : Integer;
end record;
pragma Convention (C, MouseEventStruct);
type MouseEventStructAccess is access all MouseEventStruct;
pragma Convention (C, MouseEventStructAccess);
type Integer_Access is access all Integer;
pragma Convention (C, Integer_Access);
type character_Access is access all CHARACTER;
pragma Convention (C, character_Access);
----------------------
-- Global variables --
----------------------
------------------------------
-- Import the DLL functions --
------------------------------
function GetKey (c : character_Access) return Integer;
pragma Import (C, GetKey, "GetKey");
function GetMouseLeftButtonDown (x, y : integer_Access) return Integer;
pragma Import (C, GetMouseLeftButtonDown, "GetMouseLeftButtonDown");
function GetMouseLeftButtonUp (x, y : integer_Access) return Integer;
pragma Import (C, GetMouseLeftButtonUp, "GetMouseLeftButtonUp");
function GetMouseRightButtonDown (x, y : integer_Access) return Integer;
pragma Import (C, GetMouseRightButtonDown, "GetMouseRightButtonDown");
function GetMouseRightButtonUp (x, y : integer_Access) return Integer;
pragma Import (C, GetMouseRightButtonUp, "GetMouseRightButtonUp");
function IsOpen return Integer;
pragma Import (C, IsOpen, "IsOpen");
function GetFontWidth return Integer;
pragma Import (C, GetFontWidth, "GetFontWidth");
function GetFontHeight return Integer;
pragma Import (C, GetFontHeight, "GetFontHeight");
function GetDllVersion return Integer;
pragma Import (C, GetDllVersion, "GetDLLVersion");
function GetWindowWidth return Integer;
pragma Import (C, GetWindowWidth, "GetWindowWidth");
function GetWindowHeight return Integer;
pragma Import (C, GetWindowHeight, "GetWindowHeight");
function CreateGraphWindow return Integer;
pragma Import (C, CreateGraphWindow, "CreateGraphWindow");
function DestroyGraphWindow return Integer;
pragma Import (C, DestroyGraphWindow, "DestroyGraphWindow");
function ClearWindow (Hue : Integer) return Integer;
pragma Import (C, ClearWindow, "ClearWindow");
function GetColorPixel (X, Y: Integer) return Integer;
pragma Import (C, GetColorPixel, "GetColorPixel");
function Putpixel (X, Y, Hue : Integer) return Integer;
pragma Import (C, Putpixel, "PutPixel");
function FillFlood (X, Y, Hue : Integer) return Integer;
pragma Import (C, FillFlood, "FillFlood");
function SetWindowTitle (Title : C.Char_Array) return Integer;
pragma Import (C, SetWindowTitle, "SetWindowTitle");
function DrawLine (X1, Y1, X2, Y2, Hue : Integer) return Integer;
pragma Import (C, DrawLine, "DrawLine");
function DrawBox (X1, Y1, X2, Y2, Hue, Filled : Integer) return Integer;
pragma Import (C, DrawBox, "DrawBox");
function DrawCircle (X, Y, Radius, Hue, Filled : Integer) return Integer;
pragma Import (C, DrawCircle, "DrawCircle");
function DrawArc (X, Y, a, b : INTEGER; debut, fin : FLOAT; Hue : Integer) return Integer;
pragma Import (C, DrawArc, "DrawArc");
function DrawEllipse (X1, Y1, X2, Y2, Hue, Filled : Integer) return Integer;
pragma Import (C, DrawEllipse, "DrawEllipse");
function DisplayText (X, Y : Integer; Text : C.Char_Array; Hue : Integer) return Integer;
pragma Import (C, DisplayText, "DisplayText");
function WhereX return Integer;
pragma Import (C, WhereX, "WhereX");
function WhereY return Integer;
pragma Import (C, WhereY, "WhereY");
function GotoXY (X, Y : Integer) return Integer;
pragma Import (C, GotoXY, "GotoXY");
function DrawTo (X, Y, Hue : Integer) return Integer;
pragma Import (C, DrawTo, "DrawTo");
---------------------------------------------------
-- Translate DLL error codes into Ada exceptions --
---------------------------------------------------
procedure Make_Exception (Error : Integer) is
begin
if Error < No_Errors then
case Error is
when -1 => raise Window_Already_Open;
when -2 => raise Window_Already_Closed;
when -3 => raise Message_Reg_Failed;
when -4 => raise Create_Event_Failed;
when -5 => raise Create_Thread_Failed;
when -6 => raise Window_Not_Open;
when -7 => raise Invalid_Color_Value;
when -8 => raise Invalid_Coordinate;
when -9 => raise Invalid_Fill_Option;
when -10 => raise Create_Class_Failed;
when -11 => raise Create_Window_Failed;
when -12 => raise Error_Copying_Title;
when -13 => raise Error_Copying_Cmdline;
when -14 => raise Wait_Failed_Error;
when -15 => raise Set_Title_Error;
when -16 => raise Fill_Rect_Error;
when -17 => raise Invalidate_Rect_Error;
when -18 => raise Update_Window_Error;
when -19 => raise Set_Pixel_Error;
when -20 => raise Select_Pen_Error;
when -21 => raise Move_To_Error;
when -22 => raise Line_To_Error;
when -23 => raise Select_Brush_Error;
when -24 => raise Rectangle_Error;
when -25 => raise Ellipse_Error;
when -26 => raise Get_Pixel_Error;
when -27 => raise Flood_Fill_Error;
when -28 => raise Set_Textcolor_Error;
when -29 => raise Text_Out_Error;
when -30 => raise Invalid_Window_Size;
when -31 => raise Get_Position_Error;
when -32 => raise Close_Handle_Failed;
when -33 => raise Thread_Status_Error;
when others => raise Unknown_Adagraph_Error;
end case;
end if;
end Make_Exception;
----------------------------
-- Call the DLL functions --
----------------------------
--------------------------------------------------------------------
function Is_Open return Boolean is
Result : Boolean;
begin
case IsOpen is
when 0 => Result := False;
when 1 => Result := True;
when others => raise Unknown_Adagraph_Error;
end case;
return Result;
end Is_Open;
--------------------------------------------------------------------
function Get_Dll_Version return Integer is
Return_Value : Integer;
begin
Return_Value := GetDllVersion;
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
return Return_Value;
end Get_Dll_Version;
--------------------------------------------------------------------
function Get_window_Width return INTEGER is
begin
return GetWindowWidth;
end Get_window_Width;
function Get_window_Height return INTEGER is
begin
return GetWindowHeight;
end Get_window_height;
function Get_Font_Width return INTEGER is
begin
return GetFontWidth;
end Get_Font_Width;
function Get_Font_Height return INTEGER is
begin
return GetFontHeight;
end Get_Font_height;
--------------------------------------------------------------------
procedure Create_Graph_Window is
Return_Value : Integer;
begin
Return_Value := CreateGraphWindow; -- (Default_Window);
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Create_Graph_Window;
--------------------------------------------------------------------
procedure Destroy_Graph_Window is
Return_Value : Integer;
begin
Return_Value := DestroyGraphWindow;
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Destroy_Graph_Window;
--------------------------------------------------------------------
procedure Clear_Window (Hue : in Color_Type := Black) is
Return_Value : Integer;
begin
Return_Value := ClearWindow (Color_Type'Pos (Hue));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Clear_Window;
--------------------------------------------------------------------
procedure Set_Window_Title(Title : in String) is
Return_Value : Integer;
begin
Return_Value := SetWindowTitle (C.To_C (Title));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Set_Window_Title;
--------------------------------------------------------------------
function Get_Pixel (X, Y : Integer) return Color_Type is
Return_Value : Integer;
begin
Return_Value := GetColorPixel (X, Y);
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
return Color_Type'Val (Return_Value);
end Get_Pixel;
--------------------------------------------------------------------
procedure Put_Pixel (X, Y : in Integer; Hue : in Color_Type := White) is
Return_Value : Integer;
begin
Return_Value := PutPixel (X, Y, Color_Type'Pos (Hue));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Put_Pixel;
--------------------------------------------------------------------
function Get_Key return Character is
key : aliased CHARACTER;
return_value : integer;
begin
return_value := GetKey(key'unchecked_access);
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
return key;
end Get_Key;
procedure Get_mouse_Left_button_down(X, Y : out INTEGER) is
x_aux, y_aux : aliased INTEGER;
return_value : integer;
begin
return_value := GetMouseLeftButtonDown(x_aux'unchecked_access, y_aux'unchecked_access);
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
X := X_Aux;
y := Y_aux;
end Get_mouse_Left_button_down;
procedure Get_mouse_Left_button_up(X, Y : out INTEGER) is
x_aux, y_aux : aliased INTEGER;
return_value : integer;
begin
return_value := GetMouseLeftButtonUp(x_aux'unchecked_access, y_aux'unchecked_access);
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
X := X_Aux;
y := Y_aux;
end Get_Mouse_Left_Button_up;
procedure Get_mouse_Right_button_down(X, Y : out INTEGER) is
x_aux, y_aux : aliased INTEGER;
return_value : integer;
begin
return_value := GetMouseRightButtonDown(x_aux'unchecked_access, y_aux'unchecked_access);
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
X := X_Aux;
y := Y_aux;
end Get_mouse_Right_button_down;
procedure Get_mouse_Right_button_up(X, Y : out INTEGER) is
x_aux, y_aux : aliased INTEGER;
return_value : integer;
begin
return_value := GetMouseRightButtonUp(x_aux'unchecked_access, y_aux'unchecked_access);
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
X := X_Aux;
y := Y_aux;
end Get_Mouse_Right_Button_up;
--------------------------------------------------------------------
procedure Draw_Line (X1, Y1, X2, Y2 : in Integer;
Hue : in Color_Type := White) is
Return_Value : Integer;
begin
Return_Value := DrawLine (X1, Y1, X2, Y2, Color_Type'Pos (Hue));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Draw_Line;
--------------------------------------------------------------------
procedure Draw_Box (X1, Y1, X2, Y2 : in Integer;
Hue : in Color_Type := White;
Filled : in Fill_Type := No_Fill) is
Return_Value : Integer;
begin
Return_Value := DrawBox (X1, Y1, X2, Y2, Color_Type'Pos (Hue), Fill_Type'Pos (Filled));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Draw_Box;
--------------------------------------------------------------------
procedure Draw_Circle (X, Y, Radius : in Integer;
Hue : in Color_Type := White;
Filled : in Fill_Type := No_Fill) is
Return_Value : Integer;
begin
Return_Value := DrawCircle (X, Y, Radius, Color_Type'Pos (Hue), Fill_Type'Pos (Filled));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Draw_Circle;
--------------------------------------------------------------------
procedure Draw_Arc (X, Y, A, B : in Integer;
debut, fin : FLOAT;
Hue : in Color_Type := White) is
Return_Value : Integer;
begin
Return_Value := DrawArc (X, Y, a, b, debut, fin, Color_Type'Pos (Hue));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Draw_Arc;
--------------------------------------------------------------------
procedure Draw_Ellipse (X1, Y1, X2, Y2 : in Integer;
Hue : in Color_Type := White;
Filled : in Fill_Type := No_Fill) is
Return_Value : Integer;
begin
Return_Value := DrawEllipse (X1, Y1, X2, Y2, Color_Type'Pos (Hue), Fill_Type'Pos (Filled));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Draw_Ellipse;
--------------------------------------------------------------------
procedure Flood_Fill (X, Y : in Integer; Hue : in Color_Type := White) is
Return_Value : Integer;
begin
Return_Value := FillFlood (X, Y, Color_Type'Pos (Hue));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Flood_Fill;
--------------------------------------------------------------------
procedure Display_Text (X, Y : in Integer;
Text : in String;
Hue : in Color_Type := White) is
Return_Value : Integer;
begin
Return_Value := DisplayText (X, Y, C.To_C (Text), Color_Type'Pos (Hue));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Display_Text;
--------------------------------------------------------------------
function Where_X return Integer is
Return_Value : Integer;
begin
Return_Value := WhereX;
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
return Return_Value;
end Where_X;
--------------------------------------------------------------------
function Where_Y return Integer is
Return_Value : Integer;
begin
Return_Value := WhereY;
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
return Return_Value;
end Where_Y;
--------------------------------------------------------------------
procedure Goto_XY (X, Y : in Integer) is
Return_Value : Integer;
begin
Return_Value := GotoXY (X, Y);
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Goto_XY;
--------------------------------------------------------------------
procedure Draw_To (X, Y : in Integer; Hue : in Color_Type := White) is
Return_Value : Integer;
begin
Return_Value := DrawTo (X, Y, Color_Type'Pos (Hue));
if Return_Value < No_Errors then
Make_Exception (Return_Value);
end if;
end Draw_To;
function Pi return FLOAT is
begin
return Ada.Numerics.Pi;
end Pi;
begin
-----------------------------------------------------
-- Check if the right version of the DLL is loaded --
-----------------------------------------------------
if Get_Dll_Version < Adagraph_Dll_Version then
raise Dll_Version_Error;
end if;
end P_fenetre;