Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

nbrk/quiza

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brief

Quiza stands for "Quick visualization in Ada". It is a small package on top of ASFML (the SFML bindings for Ada) that greatly abstracts and simplifies some common routines like drawing to screen, checking for inputs, loading images, setting transforms, etc.

With this package you can get something on the screen in just no time!

The intended use case is quick and dirty visualizations, with "quick" being primarily quick to code in Ada, but the performance should be acceptable for these small tasks as well.

Design notes

  • the API is centered around type Quiza.Screen.Screen_Type and its primitive subprograms
  • when loading external resources with Load_Images_Directory, etc. the program tries to load all files (e.g. *.*) in the directory, so populate the dir with the relevant content only
  • there are no events, only real-time queries
  • execution time from Begin_Draw to End_Draw is measured and reported via Get_Draw_Time
  • all SFML "objects" are cached and reused under the hood

Example

with Quiza;
with Quiza.Screen; use Quiza.Screen;

procedure Test is
   S : Screen_Type := Make_Screen (1_024, 768, False);
begin
   Quiza.Init;
   S.Load_Fonts_Directory ("/home/nbrk/tmp/fonts");
   S.Load_Images_Directory ("/home/nbrk/tmp/images");

   while S.Is_Open loop
      exit when S.Is_Key_Or_Button_Pressed (Key_Escape);

      if S.Is_Key_Or_Button_Pressed (Key_Left) then
         S.Set_Draw_Translation
           (S.Get_Draw_Translation_DX + 10.0, S.Get_Draw_Translation_DY);
      end if;
      if S.Is_Key_Or_Button_Pressed (Key_Right) then
         S.Set_Draw_Translation
           (S.Get_Draw_Translation_DX - 10.0, S.Get_Draw_Translation_DY);
      end if;
      if S.Is_Key_Or_Button_Pressed (Key_Up) then
         S.Set_Draw_Translation
           (S.Get_Draw_Translation_DX, S.Get_Draw_Translation_DY + 10.0);
      end if;
      if S.Is_Key_Or_Button_Pressed (Key_Down) then
         S.Set_Draw_Translation
           (S.Get_Draw_Translation_DX, S.Get_Draw_Translation_DY - 10.0);
      end if;
      if S.Is_Key_Or_Button_Pressed (Key_Z) then
         S.Set_Draw_Scale
           (S.Get_Draw_Scale_SX + 0.1, S.Get_Draw_Scale_SY + 0.1,
            Float (S.Mouse_X), Float (S.Mouse_Y));
      end if;
      if S.Is_Key_Or_Button_Pressed (Key_X) then
         S.Set_Draw_Scale
           (S.Get_Draw_Scale_SX - 0.1, S.Get_Draw_Scale_SY - 0.1,
            Float (S.Mouse_X), Float (S.Mouse_Y));
      end if;

      S.Begin_Draw;
      S.Clear;
      S.Draw_Line (0.0, 0.0, 100.0, 100.0, 0, 255, 0, 255);
      S.Draw_Circle (100.0, 100.0, 60.0, 0, 0, 255, 255);
      S.Draw_Rectangle
        (100.0, 200.0, 200.0, 200.0, 0, 0, 0, 255, 255, 255, 255, 255);
      S.Draw_Text
        (200.0, 200.0, "Hello", 0, 255, 255, 255, "DroidSans.ttf", 24);

      if S.Is_Mouse_Inside then
         S.Draw_Text
           (Float (S.Mouse_X) + 10.0, Float (S.Mouse_Y) + 10.0,
            S.Mouse_X'Image & ", " & S.Mouse_Y'Image, 255, 255, 255, 255,
            "Roboto-Bold.ttf", 20);

         S.Draw_Image (300.0, 100.0, "nick.jpg");

         if S.Is_Key_Or_Button_Pressed (Mouse_Button_Right) then
            S.Draw_Line
              (1_024.0 / 2.0, 768.0 / 2.0, Float (S.Mouse_X),
               Float (S.Mouse_Y), 255, 255, 0, 255);
         end if;
      end if;

      S.End_Draw;

      delay (0.016_6) - Duration (S.Get_Draw_Time);
   end loop;
   
   Quiza.Shutdown;

end Test;

About

Quick visualization in Ada

Resources

Stars

Watchers

Forks

Languages