simple level implementation
principles described in the Introduction, what we need to handle is a
list of views. In the most
simple case where the number of GUI components is fixed, an array will
suffice. The index to the array can be used as the identifier. The
minimum content of the array would be the size and location of the
views. Other data such as type (button, slider, label..),
color, event handler, component text and so on can be added as
linked list structure can be used and the identifier would be the
pointer to an element of the list. If the list is able to grow
dynamically, the application itself can generate new views. This is not
as odd as it sounds since an application might want to
generate an alert window in the event of an error. Similarly in a game
application, objects may
created and destroyed as part of the game. In the following we will use
the term "view pointer " to designate the view identifier, irrespective
of which data structure is used to store the views.
implement a minimum
Level of our GUI system we use the following data structures and
contains all the parameters of a view
declaration for view pointers,
A list that
holds the views,
that inserts a new view on the list and returns with the view pointer.
The arguments to this function are the size and position of the view,
that returns the number of views in viewList,
that returns a pointer to view #n,
that returns the view pointer of the last view in the list that
embraces a specified position on the screen.
interrupt function that is called whenever the screen is touched. Input
arguments are the screen coordinates of the touch event,
that runs while waiting for interrupts. If there is no background
processing this function is an empty infinite loop.
function that initializes the graphics hardware. This function is
function that prepares for writing in the graphics memory. This
function is platform-specific,
functions that shows the content of the graphics memory. This function
that writes a pixel in the screen buffer. Arguments are pixel position
(x,y) and color (c),
that fills the rectangular area of a view with a given color.
functions require less than 150 lines of C code.
to use these functions in an application
example that shows how to use the Simple Level of the GUI. C
language notion is assumed.
level ot the
GUI a view has only the following attributes: size (sizex,sizey)
and position (posx, posy). These data are of integer type and are
defined by a struct in C.
WIDTH 400 // Screen width
HEIGHT 600 // Screen height
background, display; // define the names of 6 views
button1, button2, button3, button4;
quit = 0;
touchDownEvent(int x, int y)
where we land when touching a view
v = findView(x,y); // Find which view was touched
if (v == background) quit = 1; // end program
if background is touched
if (v == display) fillView(display, WHITE); // otherwise
color the display
if (v == button1) fillView(display, RED);
if (v == nutton2) fillView(display, GREEN);
if (v == button3) fillView(display, BLUE);
if (v == button4) fillView(display, LIGHTGREY);
argc, char *argv)
// Define GUI
background = insertView(WIDTH, HEIGHT, 0, 0); // this
defines the entire screen as one view
display = insertView(350, 80, 30, 150); // this defines a
button1 = insertView(80, 80, 30, 250); // below follows
button2 = insertView(80, 80, 120, 250);
button3 = insertView(80, 80, 210, 250);
button4 = insertView(80, 80, 300, 250);
// Start of application
while (!quit) eventLoop();
program produces a
rectangular "display" area at the top of the screen and four colored
"buttons". Touching one of the buttons copies the button color to the
display area. Touching the background will cause the program to exit.
This site is © Copyright Robert Forchheimer
2011-2012, All Rights Reserved.