Showing posts with label gtkmm. Show all posts
Showing posts with label gtkmm. Show all posts

08 November, 2010

GHangtuxmm.


As I wrote in one of my previous posts, I have been working on the  conversion of GHangtux to GHangtuxmm, or in other words, on the conversion from C/GTK+ to C++/gtkmm.

For those of you who do not know about gtkmm (taken from the gtkmm project website): 
"gtkmm is the official C++ interface for the popular GUI library GTK+. Highlights include typesafe callbacks, and a comprehensive set of widgets that are easily extensible via inheritance. You can create user interfaces either in code or with the Glade User Interface designer, using Gtk::Builder. There's extensive documentation, including API reference and a tutorial. 

gtkmm is free software distributed under the GNU Library General Public License (LGPL).

gtkmm follows the official GNOME Platform Bindings release schedule. This guarantees API/ABI-stability and new releases on a predictable schedule, delivering C++ API for the underlying GTK+ and GNOME APIs as soon as possible." (from gtkmm project's website).

This has been fun again. Working on the project made me realize how laborious it can be to:
    - learn C++. What a monster!. This is all about experience, so my hope is that one day I will be the monster here, the C++ monster ;-).
    - convert an app that you have already developed into another language. The appropriate word here would actually be "rewrite" and not "convert", since you have to consider it as an entirely new project. Forget about what you did and focus on the new structure and libraries. This is a new project!
    - have a nice history in your repository... This takes practice, practice and more practice.

I am happy with the results so far although improvements are still being made. You can find and follow the project on GitHub where all comments and merge requests are welcome. Do not hesitate to do this.

Thanks for reading!

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!