Universidad de Cantabria, SPAIN
Author: Michael Gonzalez mgh@unican.es
Win_IO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. It is based on GtkAda, and thus is portable within Unix, Linux and Windows platforms.
The current version 5.0 is designed for GtkAda 3.4.0. The introduction of GtkAda 3 (and gtk 3) has introduced various incompatibilities with version 2 software. Thus, if you are still using Gtkada 2.X please use Win_IO 4.0.
Win_IO is composed of the following modules:
Input_Windows | Provides a simple window with I/O capabilities for data of
the types
Integer, Float, and String
Several data can be displayed and/or retrieved on the same window. |
|
Output_Windows | Provides a simple window with Output capabilities for data of
the types
Integer, Float, and String.
Several data can be displayed on the same window. |
|
Message_Windows | Provides a simple window for displaying a short message. It provides an OK button for closing the window. |
|
Menu_Windows | Provides a simple window with several buttons that enable the
user
to select from a number of options.
It is a generic package that must be instantiated with an enumeration type. One button will be created for each value in this type. |
|
Graphics_Windows | Provides a simple window with drawing capabilities. |
|
Plot_Windows | Provides a simple window for drawing two-dimensional graphs from sets of points. |
|
An example using this package can be found in: Example with Input_Windows
Input_Window operations:
function
Input_Window (Title : String) return Input_Window_Type; |
Create the window, with the specified title. |
procedure Put_Line (IW : in out Input_Window_Type; Str : String); |
Put the Str String on the results area of the IW window. |
procedure Create_Entry (IW : in out Input_Window_Type; Label : String; Initial_Value : String); |
Create an entry box on the IW window with the specified label and initial value (String). May raise Repeated_Label. |
procedure Create_Entry (IW : in out Input_Window_Type; Label : String; Initial_Value : Integer); |
Create an entry box on the IW window with the specified label and initial value (Integer). May raise Repeated_Label. |
procedure
Create_Entry (IW : in out Input_Window_Type; Label : String; Initial_Value : Float); |
Create an entry box on the IW window with the specified label and initial value (Float). May raise Repeated_Label. |
procedure Wait (IW : in out Input_Window_Type; Message : String); |
Display Message on the results area of the IW window, and wait for the OK button to be pressed. This will be an indication that the data on the entry boxes has been edited. May raise Canceled if the Cancel button is pressed. Before returning, it hides the window. |
procedure Get (IW : in out Input_Window_Type; Label : String; Item : out Integer); |
Read an Integer from the entry box matching Label in the IW window. Value is returned in Item. May raise Label_Not_Found. May raise Data_Error if text on the entry box is not an integer. |
procedure Get (IW : in out Input_Window_Type; Label : String; Item : out Float); |
Read a Float from the entry box matching Label in the IW window. Value is returned in Item. May raise Label_Not_Found. May raise Data_Error if text on the entry box is not a float. |
procedure Get (IW : in out Input_Window_Type; Label : String; Item : out String); |
Read a String from the entry box matching Label in the IW window. Value is returned in Item. If the Item parameter is longer than the text in the box it is padded with spaces if the Item parameter is shorter, then the input text is truncated. May raise Label_Not_Found. |
procedure Get_Line (IW : in out Input_Window_Type; Label : String; Item : out String; Num : out Natural); |
Read a String from the entry box matching Label in the IW window Works similar to Ada.Text_IO.Get_Line, returning the input text in the first characters of Item, and the number of read characters in Num. May raise Label_Not_Found |
An example using this package can be found in: Example with Output_Windows
An example using this package to continuously update the data on the window is shown in: Example with Continuous Update Output_Windows
The operations of Output_Windows are:
function
Output_Window (Title : String) return Output_Window_Type; |
Create the window, with the specified title |
procedure Create_Box
(OW : in out Output_Window_Type; Label : String; Initial_Value : String); |
Create a display box on the OW window, with the specified label and value (String). May raise Repeated_Label. |
procedure Create_Box
(OW : in out Output_Window_Type; Label : String; Initial_Value : Integer); |
Create a display box on the OW window, with the specified label and value (Integer). May raise Repeated_Label. |
procedure Create_Box (OW : in out Output_Window_Type; Label : String; Initial_Value : Float); |
Create a display box on the OW window, with the specified label and value (Float). May raise Repeated_Label. |
procedure Update_Box (OW : in out Output_Window_Type; Label : String; New_Value : String); |
Update the display box on the OW window corresponding to the specified label using the new_value (String). May raise Label_Not_Found. |
procedure Update_Box
(OW : in out Output_Window_Type; Label : String; New_Value : Integer); |
Update the display box on the OW window corresponding to the specified label using the new_value (Integer). May raise Label_Not_Found. |
procedure Update_Box
(OW : in out Output_Window_Type; Label : String; New_Value : Float); |
Update the display box on the OW window corresponding to the specified label using the new_value (Float). May raise Label_Not_Found. |
procedure Draw (OW : in out Output_Window_Type); |
Draws the window, and returns immediately |
procedure Wait (OW : in out Output_Window_Type); |
Draws the window and then waits for the OK button to be pressed. This will an indication that the data on the entry boxes has been viewed. Before returning, it hides the window |
procedure Close (OW : in out Output_Window_Type); |
Destroys the window, which now becomes unavailable |
The spec can be found in: message_windows.ads
An example using this package can be found in: Example with Message_Windows
The operations of Message_Windows are:
function
Message_Window (Message : String) return Message_Window_Type; |
Create the window, with the specified message. |
procedure Wait (MW : in out Message_Window_Type); |
Wait for the OK button to be pressed. This will an indication that message has been viewed. Before returning, it hides the window |
It provides a button for each value of the generic enumeration type parameter.
It provides a Wait operation that waits until the user presses one of those buttons. The operation returns the chosen option.
An example using this package can be found in: Example with Menu_Windows
The spec can be found in: menu_windows.ads
The operations of Menu_Windows are:
function Menu_Window
(Title : String) return Menu_Window_Type; |
Create the window, with the specified title. |
procedure Wait (MW : in out Menu_Window_Type; Selection : out Enum); |
Wait for a button to be pressed. This will an indication that the option has been chosen. The chosen option is returned in Selection. Before returning, it hides the window |
It also provides an OK button for which a Wait operation is provided.
A canvas has an associated font size, a pen colour, a pen size for drawing lines (initially black, one pixel wide) and a fill colour used to colour closed shapes (initially white).
The spec can be found in: graphics_windows.ads
An example using this package can be found in: Example with Graphics_Windows
Another example using this package to show an animated graphic can be found in: Example of Animation with Graphics_Windows
The description of the Graphics_Windows package appears in the following subsections:
subtype
Colour_Range is Cairo.Color_Range; subtype Color_Range is Colour_Range; type Colour_Type is record
function Light Black : constant
Colour_Type := ( 0, 0, 0); |
A colour specified as an RGB value. Several common colors are
specified
as constants. Operations Light and Dark provided for convenience.
Color_Type is a renaming of the above, with American spelling |
type Point_Type is
record X,Y : Integer; end record; function "+" |
(X,Y) coordinates of a point on the window
Origin is at the top left corner. "+" and "-" operators
defined |
type
Point_List is
array (Positive range <>) of Point_Type; |
An array of points, used by some operations |
type Image_Type is
private;
function Image |
Refers to an image, obtained through the Image operation. A variety of file formats are supported, including JPG, GIF and XPM |
function Canvas (Width : Integer; Height : Integer; Title : String:="Graphics Window") return Canvas_Type; |
Creates a new Canvas with the specified width, height and title. |
procedure Set_Colour (Canvas : in out Canvas_Type; Colour : in Colour_Type := Black); procedure Set_Color |
Set the pen colour for a canvas |
procedure Erase (Canvas : in Canvas_Type); | Erase the drawing in a canvas |
procedure
Set_Font_Size (Canvas : in out Canvas_Type; size : in Integer); |
Set a new font size for all subsequent text drawn on the canvas. |
procedure
Set_Pen (Canvas : in out Canvas_Type; Colour : in Colour_Type := Black; Width : in Natural := 1); |
Set the pen used to draw lines on the canvas to this colour and thickness. |
procedure
Set_Fill (Canvas : in out Canvas_Type; Colour : in Colour_Type); |
Set the colour used to fill subsequent closed shapes drawn on the canvas. |
procedure
Set_Fill (Canvas : in out Canvas_Type); |
Clear the fill property for subsequent closed shapes drawn on the canvas. |
procedure
Set_Fill (Canvas : in out Canvas_Type; Filled : in Boolean); |
Set (or clear) the fill property for subsequent closed shapes drawn on the canvas. |
procedure
Draw_Point (Canvas : in Canvas_Type; Point : in Point_Type); |
Draw a point on the canvas |
procedure
Draw_Text (Canvas : in Canvas_Type; From : in Point_Type; Text : in String); |
Draw a text string on the canvas from the top-left point specified by From. |
procedure
Draw_Line (Canvas : in Canvas_Type; From : in Point_Type; To : in Point_Type); |
Draw a line on the canvas starting at point From and finishing at point To. |
procedure
Draw_Line_List (Canvas : in Canvas_Type; Points : in Point_List); |
Draw lines on the canvas connecting the points in the list. |
procedure
Draw_Rectangle (Canvas : in Canvas_Type; From : in Point_Type; To : in Point_Type); |
Draw a rectangle on the canvas from the From corner point to the To diagonally-opposite point. |
procedure Draw_Rectangle (Canvas : in Canvas_Type; From : in Point_Type; Width : in Positive; Height : in Positive); |
Draw a rectangle on the canvas from the From corner point with the specified Width and Height. |
procedure
Draw_Ellipse (Canvas : in Canvas_Type; From : in Point_Type; To : in Point_Type); |
Draw an ellipse on the canvas bounded by a rectangle from the From corner point to the To diagonally-opposite point. |
procedure
Draw_Ellipse (Canvas : in Canvas_Type; From : in Point_Type; Width : in Positive; Height : in Positive); |
Draw an ellipse on the canvas bounded by a rectangle from the From corner point with the specified Width and Height. |
procedure
Draw_Circle (Canvas : in Canvas_Type; Centre : in Point_Type; Radius : in Positive); |
Draw a circle on the canvas with the specified centre point and radius. |
procedure Draw_Arc (Canvas : in Canvas_Type; From : in Point_Type; Width : in Positive; Height : in Positive; Angle1 : in Natural; Angle2 : in Natural); |
Draw an arc on the canvas; it is part of an ellipse bounded by a rectangle from the From point, with the specified width and height; Angle 1 is the the initial angle of the arc (in degrees) and Angle2 is the final angle of the arc (in degrees). |
procedure
Draw_Polygon (Canvas : in Canvas_Type; Points : in Point_List); |
Draw a polygon on the canvas with vertices at these points. |
procedure
Draw_Image (Canvas : in Canvas_Type; From : in Point_Type; Image : in Image_Type); |
Draw an image on the canvas from the From point using the Image object. |
procedure Draw (Canvas : in out Canvas_Type); |
Draws the canvas and returns immediately |
procedure Wait (Canvas : in out Canvas_Type); |
Draw the canvas and wait until the OK button is pressed: then, the Canvas is hid. |
procedure Close (Canvas : in out Canvas_Type); |
Destroys the canvas, which now becomes unavailable |
A Plot Window has an associated title, X Axis title and Y Axis title
Each Graph has a set of points and the following attributes:
Another operation, New_Graph, is used to switch to a new graph once the previous one has been built.
An example using this package can be found in: Example with Plot_Windows
The spec can be found in: plot_windows.ads
The operations of Plot_Windows are:
function Plot_Window
(Plot_Title, X_Axis_Title, Y_Axis_Title : String) return Plot_Window_Type; |
Creates a new Plot window with the specified title and axes titles. The first graph in this plot will be ready to accept points and attribute changes |
procedure
Add_Point (Plot : in out Plot_Window_Type; X,Y : in Float); |
Adds a point to the current graph; (X,Y) are the coordinates |
type Colour_Type is
(Black, White, Red, Green, Blue, Gray, Yellow, Cyan, Magenta); subtype Color_Type is Colour_Type; procedure Set_Colour procedure Set_Color |
Sets the color of the current graph to this value. The type and operation are provided with both American and British spellings. |
type Symbol_Type is
(No_Symbol, Square, Circle, Up_Triangle, Down_Triangle); procedure Set_Symbol |
Sets the symbol of the current graph to this value |
procedure
Set_Lines (Plot : in out Plot_Window_Type; With_Lines : Boolean); |
Sets the lines attribute of the current graph. If true, lines will be drawn between points. |
procedure
Set_Graph_Title (Plot : in out Plot_Window_Type; Graph_Title : String); |
Sets the title of the current graph to this value. |
procedure New_Graph (Plot : in out Plot_Window_Type); |
Switches to a new graph. All subsequent operations to add points or set graph attributes will refer to the new graph. May raise Too_Many_Graphs if Max_Graphs is exceeded. |
procedure Wait (Plot : in out Plot_Window_Type); |
Draws the graphs in the Plot_Window and then waits for the OK button to be pressed. Then, it hides the window |
|
|
All | Wait |
All | Close |
Output_Windows | Draw |
Graphics_Windows | Draw |
Consequently, a tasking application architecture using Win_IO must put any call in the table above in a single task (or the main program). Other calls may be made from different tasks.
An example can be found in test_tasking_graphics_window. In this example, two concurrent tasks draw rectangles in a Graphics_Window object. The main program periodically refreshes the window by invoking the Draw operation.Fixed a bug in Plot_Windows, which failed if no title was given to a graph.
Fixed the Graphics_Windows.Erase procedure.
Added some limited support for tasking. See "8. Tasking" for more details
The Graphics_Windows implementation is changed because of a non-portability issue between the Windows and Linux implementations affecting the animated graphics display.
The Graphics_Windows package has been changed to add a new Draw operation, that does not wait for the OK button to be pressed. This allows animated graphics to be displayed.
To download Win_IO click on one of the following links:
with "c:\GtkAda\lib\gnat\gtkada.gpr";
project Test_Win_Io is
for Source_Dirs use (".", "c:\Win_IO_Dir");
for Main use ("test_win_io.adb");
end Test_Win_Io;
The compilation command would be:
gnatmake -P test_win_io.gpr
For GPS you should create a dependency between your project and the gtkada project by right-clicking on the project icon (in the project window at the left hand side, which can be shown with "Tools" => "Views" => "Project") and selecting "Project" and then "Dependencies", and finally adding file lib\gnat\gtkada.gpr from the gtkada installation directory.
Then, you should configure the project to include the sources for Win_IO. You can do this by adding the Win_IO directory to the "Source dirs" part of the "Properties" part of the "Project" menu. Remember also to add the ".exe" suffix as the default suffix for the main file.Build the application from "Build" => "Project" => "Build All".
When running your application do it from "Build"
=> "Run" =>
"Your application" and then
remember to tick the "Run in
external terminal" option.
with "/usr/local/include/gtkada/lib/gnat/gtkada.gpr";
project Test_Win_Io is
for Source_Dirs use (".", "/usr/local/win_io");
for Main use ("test_win_io.adb");
end Test_Win_Io;
The compilation command would be:
gnatmake -P test_win_io.gpr
For GPS you should create a dependency between your project and the gtkada project by right-clicking on the project icon (in the project window at the left hand side, which can be shown with "Tools" => "Views" => "Project") and selecting "Project" and then "Dependencies", and finally adding file lib\gnat\gtkada.gpr from the gtkada installation directory.
Then, you should configure the project to include the sources for Win_IO. You can do this by adding the Win_IO directory to the "Source dirs" part of the "Properties" part of the "Project" menu.
Build the application from "Build" => "Project" => "Build All".
When running your application do it from "Build" => "Run" => "Your application" and then remember to tick the "Run in external terminal" option, or run it directly from an external terminal if you get gtk-related errors.