Introduction to Graphical Interface Design
A BIT OF ADVICE: This part gets a bit involved. Skip through the details, looking mainly at the structure. I've tried to keep it general for the most part, but there must be (of necessity) some array items specific to my model railroad layout. I'll try to moderate that and add comments where appropriate.
First, look at the overall structure. Keep in mind what's happening programmatically: how the interface is build in GLADE, how the C program incorporates the GLADE file, how "messaging" works, how arrays of pointers are used to access various user-specified input information, and how the information is displayed.
You'll see two types of buffers: one for the information that controls the electronics, plus does some checking to see that power & direction relays are set up properly, using information from user inputs via the graphical display interface (which is fairly static). You'll also see one for the dynamic information from the position detector cards (which must be "de-bounced" and is time-sensitive).
You'll see how to build a "Status" screen which checks that power and direction controls are set properly, and shows block occupancy. This is independent (for the most part) from the earlier code which displays relay setting information showing whether it is safe or not to cross from one track block to the next.
REVISION WARNING: As of March 2021, the program is undergoing a major internal revision so as to make loading/saving possible and, soon, editing much of the layout information without recompiling. What the re-write amounts to is substituting more-or-less dynamic arrays for the myriad fixed-at-compile-time arrays. This will (someday "Real Soon Now") make it possible to edit the railroad configuration without "getting down into the weeds" of the C code. Anyone who's done good ol' C (as opposed to C++ or C#) code knows that dynamic arrays are NOT built in. There are a number of ways to add this, none of them "pretty." I have elected to start by using a configuration file which can be edited with a text editor, loading the configuration dynamically at program startup, and of course, saving the configuration before exit. (My secret: extensive use of pointers.) Once that code is reliable (which it is now, but not fully implemented for all items), I'll move on into editing while the code is running. For now, though, the program reads in required array sizes based on the number of blocks, block gaps, detectors, trackage drawing, and what-not, then reads in the values for the multitude of arrays. On exit, it writes out all this information into an output file which can be used for loading, next run, if you wish. This foreshadows the ability of editing on the fly and saving the results.
What's holding up the effort is the fact that I used GLADE to set up all the "widgets" that are used to input the control settings and display the layout status. Making this dynamic would take a fair amount of graphics coding and expertise, which I'm still in the process of learning. The ideal result would be incorporating my own version of the GLADE editor, which quite frankly isn't going to happen. Although we can approach this, we probably will have to do without it. (sigh). Otherwise, it would be too much for one individual to do, as it would require reinventing much of the Gnome folks' work, which I am not about to do. Model railroading is fun, but it's not popular enough to expend several lifetimes' work.
So, take it for what it's worth- - a guideline. Copy and adapt the code where applicable. Tear out a bit of hair while you're at it. (I sure did!) ...but above all, enjoy.
Click here to see the details about building your graphics with GLADE.
Click here to see the details about Adding C code to Utilize GLADE Output File
Click here to see the details about Hooking it All Together with the main() function
Click here to see the details about Message Handling functions.
To move on to the next major topic, Position Detector Boards, Click here