aboutsummaryrefslogtreecommitdiff
path: root/example/window.adb
blob: 2c0abdf2437cafe73ba2b53d9a323b2c59c87691 (plain) (blame)
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
with Raylib; -- File path specified in 'install.sh' script.
use  Raylib; -- I agree with raysan5 on namespaces being boring.

procedure Window is

   -- This is not Ada tutorial, but brief explanation of my bindings.
   -- This is not my usual style of programming, following conventions.
   --
   -- C uses null terminated strings, while Ada does not, hence:
   -- - "Foo" & Character'Val (0)
   -- - "Bar" & ASCII.NUL
   -- - To_C_String ("Baz")
   --
   -- This decision was made intentionally to avoid package body.
   -- If your project uses 10-40 functions and 5-10 structures:
   -- - Write your own bindings, it's simple and bloat-free.
   -- - Use someone elses Ada bindings, or run command:
   -- - $ gcc -c -fdump-ada-spec -C /usr/include/raylib.h
   --
   -- I don't like to use Interfaces.C package unless I have to...

   function To_C_String ( -- I find this better than Interfaces.C.To_C.
      Data : String := "" -- Concatenate this however you like...
   ) return String is     -- Or simply use GCC generated bindings.
   begin
      return (Data & Character'Val (0)); -- This null terminates string.
   end To_C_String;

begin
   Open_Window (720, 360, "Heyo Raylib!" & Character'Val (0));
   --
   -- You can have main loop in several ways, choose what you like:
   -- - Foo: loop ... exit when ... end loop Foo;
   -- - loop ... exit when ... end loop;
   -- - while (not) ... loop (exit when ...) ... end loop;
   --
   Main_Loop: loop
      exit when Window_Should_Close;
      --
      Begin_Drawing;
      Clear_Background (Ray_White);
      -- You can specify all arguments, or use defaults after one point.
      Draw_Text ("Heyo from Ada." & ASCII.NUL, 4,  4, 32, Black);
      -- You can explicitly state all arguments and their values.
      Draw_Text (
         Text => To_C_String ("Press Escape key to exit program."),
         X    => 4,
         Y    => 36,
         Size => 32,
         Tint => Black
      );
      -- Or at last, you can specify which arguments won't be defaults.
      Draw_Text (
         Text => To_C_String ("You can ignore some arguments."),
         X    => 4,
         Y    => 68
      );
      -- And naturally, you can align them however you like...
      End_Drawing;
   end loop Main_Loop;
   --
   Close_Window;
end Window;