The previous article on building a cross-platform C++ application with Allegro showed a short snippet of code to erect a graphical window with 3 colored regeions. A file named main.cxx was used self-contained and encompassed all the code that produced the graphics window and 3 separate regions each with a different color using Allegro 5. The regions are arranged proportionally so they could work on nearly all display resolutions past and future. The choice to use Allegro means I’ve given up pre-packaged graphical widgets such as you have in Qt, wxWidgets, FLTK, Gnome and others. Rather, I have to define each and every graphical element myself using lines, geometry, and calculation of mouse position, etc. Just like in a video game, but geared towards a standard application. I made this choice because pre-built frameworks that have widgets have a tendency to stall for a good while in their support of minor things like language versions, compiler versions, display resolutions, and so the best way to get full support for the latest technology is to get granular. Allegro provides enough encapsulation and some good high-level drawing routines that it is productive enough to make progress.
The time I’ve put in so far on this is about 3 days (roughly 2 hours at night and an hour here or there on weekends). I started on this Nov. 2nd and so far I have a revision that not only present color regions but outputs scrollbars, or at least the lines and triangles where scrollbars would go. I also took most of the code in the single file, main.cxx and broke it out into C++ classes. I did this to get the RAII idiom on the display and event pointers returned by the Allegro 5 library and to start early decoupling the display handle from the drawing from the application level code.
Let’s start with the file named, PrimaryDisplaySurfaceWindow.hxx. It defines the interface to the Allegro 5 library to the rest of teh application. Unlike my earlier solutions, the goal is not to create a wrapper for the graphics library this time around. Instead, the goal is to have a clean division between the graphics library and the application to minimize or eliminate the co-mingling to specific elements from either graphics processing and application logic. Doing this also consolidates the logic for determining high-level events based on changes to window size, mouse position, and other attributes of the display and peripherals.
Cross-Platform GUI Window Iteration 0.3, Allegro 5 Graphics Library, C++14 – Primary Display Surface Window Header
Further implementation of the definitions for PrimaryDisplaySurfaceWindow are in the file PrimaryDisplaySurfaceWindow.cxx. The goal of the implementation is to meet the requirements of Allegro for start-up and clean shutdown.
Cross-Platform GUI Window Iteration 0.3, Allegro 5 Graphics Library, C++14 – Primary Display Surface Window Implementation
The RssDisplay.hxx contains the definition for the class that provides an entry point into the GUI application. The GUI application is the logic that requests what is to be drawn on the screen (where and in what form) as well as the triggers define certain layout shapes and change in visual state.
Cross-Platform GUI Window Iteration 0.3, Allegro 5 Graphics Library, C++14 – Rss Display Header
The RssDisplay.cxx is the implementation that provides that actual logic of the application. At this stage, it is the early scaffold of the general structure of the application.
Cross-Platform GUI Window Iteration 0.3, Allegro 5 Graphics Library, C++14 – Rss Display Implementation
When the program is called, a main method is executed. The main method is defined in main.cxx in which the PrimaryDisplaySurfaceWindow type presented at the beginning is tied to RssDisplay. The glue is the callback function shown on line 13 below.
Cross-Platform GUI Window Iteration 0.3, Allegro 5 Graphics Library, C++14 – Program Entry