dosbox  0.74
About: DOSBox emulates a full x86 PC with sound and DOS (for e.g. to run old DOS games).
  Fossies Dox: dosbox-0.74.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gui::tk - framework-agnostic C++ GUI toolkit


gui::tk is a simple one-file C++ GUI toolkit for use with arbitrary memory framebuffers.


  • small source and binary code size
  • reasonable performance and memory usage
  • comfortable usage
  • suitable for embedded usage: integer math only
  • extensibility via OO
  • non-intrusive: can be integrated with any event mechanism of your liking
  • no dependencies apart from standards-conformant ANSI C++ (including a little STL)
  • support for different encodings, single- and multibyte
  • flexible font support


The toolkit draws on a surface you provide, using any size or pixel format. Create a GUI::Screen with the buffer to draw on, then pass that object (or a GUI::Window created from it) to all other widgets' constructors.

It doesn't provide an own event loop. Instead, it relies on you passing events and updating the screen regularly. This way, it can easily be integrated with any event loop available (SDL, Qt, glib, X11, Win32, selfmade, ...)

Many functions and concepts were taken from other well-known toolkits, so if you know Qt, Java or wxWindows, you may encounter (intentional) similarities. However, simplicity of code has been given priority over maximum optimization and pixel-exact replication of their appearance.

A note about font support and encodings: All text-related functions use templates to support any encoding. Fonts define the charset.

Getting Started

gui::tk contains an SDL adapter, so if your program is already using SDL, things are really easy. The rough sequence to get up and running is:

// setup a suitable video mode with SDL
SDL_surface *screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
// add a default font, you will most probably need it
GUI::Font::addFont("default",new GUI::BitmapFont(testfont,14,10));
// create the root-level screen object, the parent of all top-level windows
GUI::ScreenSDL guiscreen(screen);
// create any amount of toplevel windows you like
GUI::ToplevelWindow *frame = new GUI::ToplevelWindow(&guiscreen, 205, 100, 380, 250, "gui::tk example");
// add some GUI elements to the toplevel window
GUI::Button *b = new GUI::Button(frame,8,20,"Quit");
// Define and add an event handler
struct quit : public GUI::ActionEventSource_Callback {
} ex;
// Enter an event loop, calling update() regularly.
SDL_Event event;
while (1) {
while (SDL_PollEvent(&event)) {
if (!guiscreen.event(event)) { // gui::tk didn't handle that event
if (event.type == SDL_QUIT) exit(0);
guiscreen.update(4); // 4 ticks = 40ms
SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
SDL_Delay(40); // wait 40ms

Look at gui_tk.h for more detailed documentation and reference of all classes.

A test program that shows off the capabilities of gui::tk is available as part of gui_tk.cpp.


Copyright (C) 2005-2007 Jörg Walter

gui::tk is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

gui::tk is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see