aboutsummaryrefslogtreecommitdiffstats
path: root/src/video.adb
blob: 0a93592e45c890d672dd1239ed6886e9ce770624 (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
with Sf.Window;
with Sf.Window.Event;
with Sf.Graphics.Color;

package body Video is
   procedure Clear_Screen is
   begin
      for X in 0 .. sfUint32 (Width) - 1 loop
         for Y in 0 .. sfUint32 (Height) - 1 loop
            Image.setPixel (Pixels, X, Y, Color.sfBlack);
         end loop;
      end loop;
   end Clear_Screen;

   procedure Initialize is
   begin
      Sprite.setTexture (Pixels_Sprite, Pixels_Texture);
      Sprite.setPosition (Pixels_Sprite, (Float (0), Float (0)));
      Sprite.setScale (Pixels_Sprite, (Float (Scale), Float (Scale)));
      RenderWindow.setFramerateLimit (app, 60);
   end Initialize;

   function Is_Running return Boolean is
   begin
      return RenderWindow.isOpen (app) = sfTrue;
   end Is_Running;

   procedure Display is
      use Sf.Window.Event;

      e : sfEvent;
   begin
      while RenderWindow.pollEvent (app, event => e) = sfTrue loop
         if e.eventType = sfEvtClosed then
            RenderWindow.close (app);
         end if;
      end loop;

      RenderWindow.clear (app, Color.sfWhite);
      Texture.updateFromImage (Pixels_Texture, Pixels, 0, 0);
      RenderWindow.drawSprite (app, Pixels_Sprite);
      RenderWindow.display (app);
   end Display;

   function Toggle_Pixel (X, Y : sfUint32) return Boolean is
      use Color;

      P : constant sfColor := Image.getPixel (Pixels, X, Y);
      R : constant Boolean := P = sfWhite;
   begin
      Image.setPixel (Pixels, X, Y, (if R then sfBlack else sfWhite));
      return R;
   end Toggle_Pixel;

   procedure Finish is
   begin
      RenderWindow.close (app);
   end Finish;
end Video;