The Downfalls of Allegro GUI
Okay, so after hours of torturous tutorials and lots of headaches over code that is making my brain hurt, I’ve finally found a way to get my GUI login working for PLEX. Because Allegro GUI’s steal the focus until they are closed, this presented me with a few problems.
1) I couldn’t figure out how to get the focus back to my own coding
2) Once I got the focus back, I had to find a way to draw what was on the screen before (and wasn’t showing up because the focus was lost)
3) Changing fonts for password protection
Now, the best solution I came up with — with a little help from Chris Martin — was to incorporate a lot of what I had planned outside of the GUI into the GUI itself. This means that instead of having clickable text in the background I made that text into buttons on the GUI.
Sooo… how to get the focus back after you’ve started the GUI dialog? The answer isn’t as simple as it should be. I’m going to end up using a flag. When the flag is set then I’ll show the dialogs (and loose the focus of my background scripts) and once the mouse has been clicked outside of any of the GUI boxes then I’m going to swap the flag and give the focus back to my scripts.
One of the issues with this is that when you bring the focus off of the dialog then it disappears from the screen. In order to fix that, I’ll have to capture the screen before the dialog is closed and then blit that to the screen in its place. That way it will look like the dialog is still there, even after the do_dialog function has ended.
Then, once the user clicks in an area with the dialog boxes, I’ll toggle the flags and have the dialog boxes show up again. Since the user’s name and passwords are saved to the strings passed into the dialog when its started they will still be there once the focus returns to the dialogs.
Finally, the password box issue. My first thought was to create two dialogs and then change the font as the focus changed back and forth to the password box and the login box. However, I decided that I didn’t want to worry about keeping track of the focus on the other GUI items and the password dialog and the background things I wanted to do as well as switching the fonts back and forth. Instead I’ve decided that as of now I’m going to leave the password box as regular text.