Skip to content
Gwilherm Baudic edited this page Oct 20, 2016 · 5 revisions

Welcome to the guisan wiki!

Guisan is an updated version of Guichan for SDL2.

Installation

Once you have cloned the repository, build the library and its examples by typing

scons

Note: this will not build the demo. To install, type

sudo scons install

which will install the library, its header files and the pkg-config file at the appropriate places. The authors of Guichan have made an amazing work in documenting their code, but to generate a more user-friendly documentation in HTML, type

doxygen Doxyfile

Adding guisan to your project

As is the case with most libraries, make sure you link your program with the -lguisan option. Because guisan requires SDL2, SDL2_image and SDL2_ttf, guisan needs to appear before them in the compilation command. It may also be necessary to indicate the correct directory where the headers are installed.

If your project uses autotools, you can check for the presence of guisan on the system with pkg-config using the PKG_CHECK_MODULES macro in your configure.ac file.

Using guisan

Note: this part builds upon the knowledge gained from reading the examples provided.

The first step is to add the necessary headers in your source file:

#include <guisan.hpp> /* mandatory */
#include <guisan/sdl.hpp> /* needed for SDL-specific implementations */

Pay attention to the fact that in the case of errors, guisan uses C++ exceptions instead of the integer return codes and SDL_Set/GetError combo used by other SDL libraries.

Library initialization

Several objects need to be created to be able to use guisan in your project. According to the examples provided, the required parts are:

  • a Graphics object, like an SDLGraphics to handle widget drawing
  • an Input object to manage events
  • an ImageLoader, which is used internally to... load images, for example to create Icons or ImageButtons
  • a GUI object
  • a Font object to draw texts such as Labels or captions. Guisan provides ImageFont out of the box, but if you prefer to use TrueType fonts, SDLTrueTypeFont is also available (imported from Guichan, justifies the SDL2_ttf dependency).
  • a Container object. Indeed, the GUI object can only contain one widget, so if you plan to use more than one at the same time, the Container is the only way to go.

Please note: guisan is not compatible (yet) with the new SDL2 Render API!

Event loop

The next step is to include guisan in your game event loop.

  • At the end of your event processing code, add a call to the pushInput(SDL_Event event) method of the gcn::SDLInput object to make guisan aware of this event.
  • Then, we would like the GUI to process this event. To do so, call the logic() method of the Gui object. No parameter is needed.
  • Next, it is time to draw the updates to the target surface, using the draw() method of the Gui object. Again, no parameter is needed.
  • Finally, we tell SDL to display the changes on the screen with a call to SDL_UpdateWindowSurface().
Clone this wiki locally