SdlWidgets

From thelas.dk

Jump to: navigation, search
A screenshot of the upcomming version of Ucom which uses SdlWidgets
A screenshot of the upcomming version of Ucom which uses SdlWidgets

Sad news. I have to mark this project as unmaintained because I have not found time to develop this project for a while now, and I do not see how I would get the time to maintain this project in the forseeable future.

SdlWidgets is a library for creating GUI applications.
It is written in C++, it only uses POSIX and SDL, and has a nice object oriented design.
It currently compiles for OSX and Linux.

Contents

Features

  • A simple but powerfull API (A GUI can be expressed in very few lines)
  • Multiple windows (this is not usually supported by SDL projects, since it requires a massive hack to accomplish)
  • Portable (Currently Linux and OS X is supported, but other platformes are scheduled to be suported. Watch the roadmap)
  • Efficient (Practically no startup time. Memmory light. Only few efficiency problems, and they can be avoided)
  • Includes basic widgets (Currently the following widgets are included)
    • Labels
    • Checkboxes
    • Radio buttons
    • Buttons
    • Collection Widgets (Vertical list, Horizontal list, Tab list)
    • Input Widgets (String)
    • Images
  • Extendable (It is easy to write your own widgets. Just write a class that inharits from the Widget class)

Roadmap

  • Now that DynParser has been developed, the future releases will have support for configuration files.
  • Version 1.0.4: Change all surfaces to use 32 bit per pixel, to alow alpha blending (and hopefully transparrent windows).
  • Version 1.0.5: Introduce themes and more dynamic displays.
  • Version 1.1.0: Port to Windows (as much as possible), such that it works for Linux, OSX and Windows.

Versions / Download

Stable release Stable release

Requirements

SdlWidgets depends on the SDL project. In order to compile SdlWidgets it is necessary to install the SDL development-packages.
In Ubuntu the required packages are

  • libsdl1.2debian-all
  • libsdl1.2-dev
  • libsdl-ttf2.0
  • libsdl-ttf2.0-dev
  • libsdl-gfx1.2-4
  • libsdl-gfx1.2-dev
  • libsdl-image1.2
  • libsdl-image1.2-dev

Installation Instructions

The usual installation procedure is as follows
tar -xvzf sdlwidgets-1.0.3.tgz
cd sdlwidgets-1.0.3
make config
make build
sudo make install
Now the installation procedure will be explained in more detail.

Before installing SdlWidgets project, make sure you have installed the requirements.

When the necessary dependencies have been installed, SdlWidgets is downloaded using the above link.
The rest of the installation is done using a shell or terminal.

To unpack the downloaded file, go to the directory containing the downloaded file and execute tar -xvzf sdlwidgets-1.0.3.
enter the created folder by typing cd sdlwidgets-1.0.3.
Now it is time to create a Makefile from the Makefile.in by typing make config.
SdlWidgets can now be compiled by typing make build.
Finally install the library by executing make install as root.

If no errors were encountered the project is now installed, and you can begin writing graphical applications using the SdlWidgets API.

API Examples

Screenshot of Hello World example
Screenshot of Hello World example

We start with a simple Hello World program.
This program will show a window with the text "Hello World" for 10 seconds.

#include <sdlwidgets/Widgets.hpp>
#include <unistd.h>

using namespace SdlWidgets;

int main(int argc, char **argv)
{
  Window win(800,100,new Label("Hello World"));
  usleep(10000000);
}

The program is compiled by the command
g++ hello.cpp -o hello -lsdlwidgets `sdl-config --cflags`

This is how the program works.

  • The application creates a window containing a label with the hello world text.
  • Then the application sleeps for 10 seconds.
  • When the application quits the window object is automatically destroyed, which means that the window is closed.

Screenshot of the collection example
Screenshot of the collection example

The next example includes checkboxes, radiobuttons, and shows what horizontal- and vertical collections are and how to use them.

#include <sdlwidgets/Widgets.hpp>
#include <unistd.h>

using namespace SdlWidgets;

int main(int argc, char **argv)
{
  VCol *checkboxes = new VCol();
  checkboxes->AddWidget(new CheckBox(new Label("Check One"),true),2);
  checkboxes->AddWidget(new CheckBox(new Label("Check Two"),false),1);
  checkboxes->AddWidget(new CheckBox(new Label("Check Three"),true),1);
  VCol *radiobuttons = new VCol();
  RadioButton *rb = new RadioButton(NULL,new Label("Option One"));
  radiobuttons->AddWidget(rb,1);
  radiobuttons->AddWidget(new RadioButton(rb,new Label("Option Two")),1);
  radiobuttons->AddWidget(new RadioButton(rb,new Label("Option Three")),2);
  HCol *choices = new HCol(50,50);
  choices->AddWidget(checkboxes,2);
  choices->AddWidget(radiobuttons,3);
  Window win(800,100,choices);
  usleep(10000000);
}

The program is compiled by the command
g++ example.cpp -o example -lsdlwidgets `sdl-config --cflags`

This is how the program works.

  • The application creates two vertical collections, and adds three checkboxes to the first collection, and three radiobuttons to the second.
  • Then the application creates a horizontal collection, and adds the two vertical collections to that.
  • Then the application creates a window containing the horizontal collection.
  • Then the application sleeps for 10 seconds.
  • When the application quits the window object is automatically destroyed, which means that the window is closed.

Please notice that the difference in size is a feature and not a bug, since the second element of AddWidget describes how much room the widget is given.
Suppose a vertical collection contains two widgets, one with size 2 and one with size 3.
Then the first widget is given 2/5 of the space, and the second widget is given 3/5 of the space.

Another thing to notice is that in stead of giving the checkboxes and radiobuttons a text to display, they are given a Label.
In fact we could have given them any widget (an image, a checkbox, a radiobutton, a collection... or a widget you have made yourself).
This is one of the strengths of SdlWidgets, and we will investigate this in future examples.

More examples will follow.

Personal tools