GSoC/GCI Archive
Google Code-in 2010 Tux4Kids

Improve the ShowMessage() function in TuxMath

completed by: Johndhel Maceda

mentors: David Bruce

ShowMessage() is a GUI function used to display generic messages to the user, without any buttons or controls.  In its current form it takes a font size, font color, and 4 strings as arguments.


However, the function doesn't wrap text, so if the strings are too long, they go beyond the shaded box and (to quote my daughter) "look stupid".

For this task, re-write this function to take a single string argument that can contain newline ('\n') characters for hard line breaks.  Also, TuxMath already contains very robust third-party code (in linebreak/) that can break text into lines of a given number of characters.  I would suggest that the new function should:

1. See how many pixels are available for the text, based on the screen size

2. Figure out how many characters this corresponds to, using an uppercase 'M' as a unit

3. Break the text into as many lines as needed with the functions in linebreak/

4. Draw the shaded outline big enough for the text to fit.

5. Draw the lines of text within the box

6. If there are more lines than fit on one page, provide arrow keys for the user to view the rest of the text.

7. Adapt the function calls to ShowMessage() to use a single long string, rather than the four hard-coded strings.


Note - the linebreak code is currently used in credits.c, which can be used as an example.