Showing posts with label GHangtux. Show all posts
Showing posts with label GHangtux. Show all posts

01 September, 2010

Moving on to gtkmm

I have spent the last weeks trying to improve some parts of GHangtux. One of the improvements (the more obvious and complicated one), came with the code restructuring.

BEFORE, all the code was divided in three different files:
- main.c: all code for the program except for the keyboard widget.
- keyboard.c/.h: keyboard widget code.

This structure made the code easy to read at the very beginning, but was obviously a bad idea for the long term. Actually, you should always divide your program in small modules although you think is going to be a very tiny one. It might be now, but who knows what is going to happen in the future. Also, you help to make this code reusable for other programs or programmers. So, mental note: always use modular code from the beginning!.

NOW, the code is divided in ten different files:
- ghangtux.c/.h: main program and definition of main structures.
- ghangtux_ui.c/.h: user interface.
- ghangtux_management.c/.h: functions for game management.
- ghangtux_utils.c/.h: auxiliary functions.
- ghangtux_keyboard.c/.h: keyboard widget.

After all the new code structure was ready, I decided to set up GTK-Doc to document GHangtux in a proper way (still need to finish commenting the functions), which brought me to the eternal discussion "recursive or non recursive Makefiles?". GTK-Doc documentation gave me the impression that I HAD to use recursive make with no explanation and no other chance. After some research and discussing about it with Dave, we found the way to do it "my way", that means: non recursive. You can read Peter Miller's excellent paper to learn why recursive make invocations are both slow and error-prone.

Happy with the results so far, I moved on to "convert GHangtux" to gtkmm, so now I am busy reading "Accelerated C++" and "Effective C++". Let's wait for the magic to happen soon ;).

Take care!

23 July, 2010

GHangtux 1.0

Wondering, what I have been doing the last few weeks?. GTK+ is the answer, GHangtux 1.0 the result, and since we all know that a picture is worth a thousand words I go just straight to the introductions: "World, this is GHangtux, GHangtux this is the world".


What is GHangtux?
GHangtux is a free program variation of the popular Hangman game. It has been designed for people of all ages and has a simple, easy-to-use interface.

It provides a keyboard and a sentence/word to guess, whose theme, the player is able to select. Current themes are: films, objects and persons.

During the game, a graphic sequence of tux images will be displayed, indicating the player how many attempts he/she has left. 

How to "create life" from some code lines?
1. Getting familiar with GTK+. As I wrote in the last post, I spent my first weeks at Openismus learning GTK+ and to put this into practice, I worked in a very small but helpful project. "Foundations of GTK+ Development" was very useful in this learning process and gave me a good base.

2. Making and correcting mistakes. The next step was to learn about all those mistakes I made, to repeat them and to relearn from them again. This is part of every single step actually.

3. Testing the new knowledge. After the first two steps, it seemed that I was prepare to start my first simple GTK+ application which is the very early version of the game.

4. Creating a custom widget. After playing with GTK+ a few more weeks, I decided to create my own custom widget: the game's keyboard. For this step, I found Davyd Madeley's clock widget tutorial quite handy.

5. Integration of the custom widget in the early version of GHangtux. This is the last version of the game. 

What is coming next?
- Internationalization with i18n.
- More themes.
- More image themes.
- Shortcuts for the menus. 
- Others: clutter, desktop files...

"Side effects" of having developed GHangtux?
- Learning Git and discovering how powerful this tool is.
- Learning Autotools helped by Alexandre Duret-Lutz's tutorial, and some    Openismus manuals.
- Practicing C.
- Practicing Glade.
- Programming style.
- Improving my communication skills.

You can follow the project under the repository in GitHub or download it in .tgz or .zip.  All comments are welcome, as are merge requests.

Enjoy!