Once I realized the power of this hardware I decided to implement a window manager like you would expect on any standard desktop PC. I have used a mouse for user input to the system.
|Close-up of the Default Configuration|
|Slightly Blue Theme, More Windows|
I have tried to maintain layers of abstraction within this software. I will start by explaining the layered approach that I have taken for the drivers, window manager and user application.
Unfortunately I have fallen into the trap of trying to write good code and there is a blur between the layers. The Window Manager makes calls directly to the uVGA-II layer which means that it would be difficult to port this window manager to another VGA controller. This can be resolved by creating an intermediate, platform independent hardware interface layer. If a user wished to run AVRDE using another VGA controller they would change the hardware abstraction layer rather than the window manager itself.
Despite the blur between the layers, I find it easy to maintain. I was able to add a new widget (the slider) within a couple of hours.
Modelling a GUI Toolkit in C
This is my first attempt at using C to model complex abstraction. Typically I am using C to control hardware, registers and other low-level hardware concepts. This project takes a completely different direction and attempts to model the desktop metaphor. I do not claim to know C++ so I have decided to stay within my element and use structs and unions in C.
|All On-Screen objects are descendants of the Widget|
In addition to the dWidget_t type, I have implemented a dManager_t. This struct is used to maintain the windows and associated function callbacks.
Drawing the Desktop
I have employed the Painter's algorithm to handle the drawing of windows. This means that I sort the windows by Z-Index and then draw them from lowest to highest such that the foreground window is always on top.
I have borrowed a concept from Android that I am quite fond of. I am using a repaint flag to handle repainting when necessary. This means that if I make a modification to a widget (change the text of a Label, for example), I must call dInvalidate() on that widget to have it painted onto the screen. This minimizes the amount of total repaints necessary.
I also have a repaint flag in the manager. This flag is set when a window is moved, the theme is changed or a window is minimized. The manager.repaint flag results in a complete repaint of the desktop environment.
|Lots of Windows!|
Each widget contains a pointer to a theme. This makes it possible for different windows to have different themes or for applications to maintain their own appearance. I have not exploited this functionality in the demonstration video.
The manager also has a reference to the system theme for drawing the taskbar.
The taskbar is quite simple. It is not implemented as a widget, it is simply drawn on top of the window manager when necessary and the locations of the buttons are stored for window switching.
When the titles of windows are too long for the button, the final 2 characters are replaced with "..".
There isn't too much to the hardware. I have an ATmega1284p microcontroller, a uVGA-II VGA controller, a MAX233 level converter and a Microsoft Serial Mouse.
|Hardware Overview w/ Headphone Splitter-Coupler :)|
I have maintained a Git repo on my laptop containing all of this code. I am not 100% happy with it yet. I need to work on the UART driver some more and polish up some documentation before uploading it.
I will post another blog soon with a link to the Github and a bit of a tour through the repo.
Thanks for reading!