Advanced Code Edition with GNAT Studio
The purpose of this exercise is to use GNAT Studio’s integrated code edition features.
This lab uses the Getting Started lab (default).
Question 1
We want to wrap the call to Draw_Sphere
into its own subprogram, and its own package.
Create a package Red_Ball
without its body from the GNAT Studio project view.
Question 2
In red_ball.ads
, declare a new procedure Draw_Red_Ball (Canvas : Canvas_ID; X, Y, Radius : Float)
Try checking the semantics of the file, using the “Check Semantic” button (or option from the Build menu).
This should fail: GNAT Studio will propose an automatic fix to “qualify” with a package; run it.
Question 3
Using the GNAT Studio Generate right-click menu, generate a body for the package Red_Ball
.
Jump to the body, and copy-paste there the call to Draw_Sphere
from
getting_started_main.adb
.
Rename Ball_Radius
to Radius
.
Try compiling red_ball.adb
by using Shift+F4. This will fail: use the automatic tip from GNAT
Studio about qualifying Draw_Sphere
.
Try recompiling the file; it should work.
Go back to getting_started_main.adb
, and replace the call to Draw_Sphere
by the
equivalent call to Draw_Red_Ball
. Fix any qualification issue using GNAT Studio’s autofix.
Question 4
Red_Ball.Draw_Red_Ball
is a bit repetitive. Rename it to Red_Ball.Draw
using GNAT
Studio’s Refactor menu.
Question 5
We want to add a pink circle inside the red ball.
Go to the body of Red_Ball.Draw
.
There is no Pink
color already defined, declare Pink : Mage.RGBA_T
.
Try to compile, use the tip from GNAT Studio so that it inserts with Mage
by itself.
Add a value for Pink
, type := (
and in the menu that opens, choose “Aggregate for
RGBA_T”. Then complete the template with the values R = 255, G = 100, B = 100, A = 100.
Once this is done, add a call to Draw_Circle
after the call to Draw_Sphere
.
Use the autocompletion “Params of Mage.Draw.Draw_Circle”. The circle radius should be half
that of the sphere.
Finally, compile and use autofix to fix the warning emited by GNAT Studio, and run the
“Code > Format File” command, to reformat the file automatically using gnatpp
.