Getting Started with AppGraphics
AppGraphics is designed with simplicity in mind. Using this library, developers can create simple, yet powerful, graphical user interfaces with ease. The following guide will walk new users through the process of creating a window, adding menus, and drawing in both C and Fortran.
Creating a Window
Before most functions in AppGraphics cna be called, we need to first create a window. The initwindow function is used to open a new window, and it returns an integer identifying this new window:
#include <appgraphics.h> ... int window; ... window = initwindow(800, 600, "Example Application", DEFAULT_POSITION, DEFAULT_POSITION, FALSE, TRUE);
In the C example, we create a window 800 pixels wide by 600 pixels tall with the title Example Application in the titlebar. The DEFAULT_POSITION constants tell Windows to position the window on the screen as it sees fit. The FALSE entry disables double buffering; double buffering is useful for fast draw operations, but it is unnecessary here. Finally, the TRUE parameter instructs AppGraphics to close the program when the window closes.
use appgraphics ... integer::window ... window = initwindow(800, 600, title="Example Application")
In the Fortran example, we’ve relied on some default values, although all the same parameters as the C version are also available. This call will create a window 800 pixels wide by 600 pixels tall with the title Example Application in the titlebar. By default, it will be positioned by the operating system, disable double buffering, and end the program when the window closes.
In AppGraphics applications, there is a distinction between menus and menu items. Menus contain additional menus and menu items, and menu items are usually a single-click action when selected. To add menus to our window, we first need to create a root menu for the window, which represents the menu bar, using the function addmenu and passing MENU_FOR_WINDOW as the parent parameter.
After adding the root menu, we can add a useful file menu by again calling addmenu and using our new root menu as the parent parameter. These drop-down menus can also have submenus if you wish by again calling addmenu and referencing our drop-down menu as the parent parameter.
Finally, we can menu items to our file menu using the addmenuitem function. When adding a menu item, though, we can also add a subroutine to be called when the menu item is clicked.
<pre><pre><pre>#include <appgraphics.h> /* Some functions prototypes to be called from menu clicks *./ void save(); void quit(); </pre> ... int root_menu; int file_menu; ... </pre> root_menu = addmenu(NULL, MENU_FOR_WINDOW); file_menu = addmenu("File", root_menu); </pre> addmenuitem("Save", file_menu, save); addmenuitem("Quit", file_menu, quit);
The above creates a “File” menu on a window’s menu bar with two options, “Save” and “Quit.” When the user clicks “Save,” for example, the function save() will be called. One should note, however, that the call to save() will be within another thread. See the section on threads for more information.
<pre><pre>use appgraphics ... integer::root_menu, file_menu, item interface subroutine quit() end subroutine quit end interface </pre> interface subroutine save() end subroutine save end interface ... root_menu = addmenu("", MENU_FOR_WINDOW) file_menu = addmenu("File", root_menu) </pre> item = addmenuitem("Save", file_menu, save) item = addmenuitem("Quit", file_menu, quit)
In the Fortran example, we’re adding “Save” and “Quit” items to a “File” menu as well. Note that the save and quit procedures are subroutines without arguments. These subroutines can be module procedures also, as long as they are within the scope of the subprogram that is calling addmenuitem. Like their C counterparts, the save() and quit() subroutines will be executed from a separate thread.
Drawing in the Window
AppGraphics provides a significant number of different line, text, and shape drawing procedures. These can all be called from the main program or any callback function without any problems. The examples below both create a few simple shapes within the main window.
<pre><pre>#include <appgraphics.h> ... </pre> setfillstyle(SOLID_FILL, RED); bar(10, 10, 160, 110); </pre> setfillstyle(SOLID_FILL, BLUE); fillellipse(85, 60, 75, 50);
The above example first draws a red rectangle measuring 150 pixels wide and 100 pixels tall. The next call draws a blue, filled ellipse over this rectangle with the same dimensions. The call to setfillstyle() is using some predefined colors provided by AppGraphics; the developer may also specify a color in red-green-blue values using the creatergb() function.
<pre><pre>use appgraphics ... </pre> call setfillstyle(SOLID_FILL, RED) call bar(10, 10, 160, 110) </pre> call setfillstyle(SOLID_FILL, BLUE) call fillellipse(85, 60, 75, 50)
The Fortran example works identically to the C example.
Adding More Features
This simple tutorial shows the basics of working with AppGraphics. Users can also add more complicated features such as multiple windows, buttons and textboxes, mouse-handling callbacks, and interactive graphics. The reference sections included with this document provide explanations for all the features available from AppGraphics. Additionally, if users would like to request additional features, they are encouraged to visit the Approximatrix Forums to discuss and suggest ideas.