Hello World

In a first step we are going through the minimal needed application initialization to display some content using disko. To download the code for this tutorial, fetch it from the git-repository by issuing:

git clone git://www.diskohq.org/disko-tutorials.git

Then you can follow this part by having a look at the tutorials firststeps/01 folder.

Needed files

During initialization disko assumes that there are some files existent, that make things a little easier to maintain later on. These files are:

  • diskorc.xml
  • theme.xml
  • inputmap.xml

Application initialization

The function mmsInit() is used to initialize a disko application.

bool mmsInit(MMSINIT_FLAGS flags, int argc = 0, char *argv[] = NULL,
		string configfile = "",
		string appl_name = "Disko Application",
		string appl_icon_name = "Disko Application");

The parameters are used as follows:

flags
decide which different systems should be initialized, i.e. plugin manager, window manager, event manager etc.
argc and argv
are mainly used to deliver parameters to underlying frameworks, especially DirectFB.
configfile
is the filename of disko configuration file.
appl_name
is the name of your application and will be used for the window title of the X11 window if using the disko X11 backend.
appl_icon_name
is the icon text which will be displayed if using the disko X11 backend.

The configfile contains the configuration to the different systems provided by disko. If empty, disko will search /etc/ and ~./disko/ for diskorc.xml. You can also set the configfile with the commandline parameter --disko:config=<configfile> like this

./01 --disko:config=diskorc-vesafb.xml

to run the tutorial 1 demo within vesa framebuffer (defined in diskorc-vesafb.xml file).

Most important for now are the graphic settings. In this example these settings are configured to use the Disko X11 backend in 800x600 and YV12 for pixelformat.

<graphics>
	<!-- initializing the framebuffer with following value -->
	<parameter name="xres"                       value="800"/>
	<parameter name="yres"                       value="600"/>
	<parameter name="outputtype"                 value="x11"/>
	<parameter name="videolayerid"               value="0"/>
	<parameter name="videolayerpixelformat"      value="YV12"/>
	<parameter name="videolayeroptions"          value=""/>
	<parameter name="videolayerbuffermode"       value="BACKSYSTEM"/>
	<parameter name="graphicslayerid"            value="0"/>
	<parameter name="graphicslayerpixelformat"   value="YV12"/>
	<parameter name="graphicslayeroptions"       value=""/>
	<parameter name="graphicslayerbuffermode"    value="BACKSYSTEM"/>
	<!-- set the visible rectangle to handle TV over scan
	     Please note: if you set vrect.w and vrect.h to "0"
	                  the visible screen area will be set to
	                  0,0,xres,yres -->
	<parameter name="vrect.x"                    value="0"/>
	<parameter name="vrect.y"                    value="0"/>
	<parameter name="vrect.w"                    value="0"/>
	<parameter name="vrect.h"                    value="0"/>
	<!-- handle touchpad resolution -->
	<parameter name="touchrect.x"                value="0"/>
	<parameter name="touchrect.y"                value="0"/>
	<parameter name="touchrect.w"                value="0"/>
	<parameter name="touchrect.h"                value="0"/>
	<!-- show diskos mouse pointer? -->
	<parameter name="pointer"                    value="true"/>
	<!-- for optimization, set the pixelformat for Root, Main and Popup
	     Windows (ARGB, AiRGB, AYUV, auto) -->
	<parameter name="graphicswindowpixelformat"  value="auto"/>
	<!-- for optimization, set the pixelformat for Disko internal surfaces
	     (ARGB, AiRGB, AYUV, auto) -->
	<parameter name="graphicssurfacepixelformat" value="ARGB"/>
	<!-- enable extended graphic acceleration routines
	     which are part of Disko -->
	<parameter name="extendedaccel"              value="true"/>
	<!-- set the allocation method which is used to allocate surface memory
	     ("malloc" - Disko allocates surface memory with malloc(),
	      "dfb"    - surfaces will be allocated by directfb)
	     Please note: if you want to use the Disko X11 backend you have to set
	                  extendedaccel="true" and allocmethod="malloc" -->
	<parameter name="allocmethod"                value="malloc"/>
	<!-- the Disko X11 backend can switch to full screen
	     if set to true -->
	<parameter name="fullscreen"                 value="false"/>
</graphics>

To see the full file, just have a look into the diskorc.xml in the tutorials/01 folder.

We use mmsInit() to just initialize the disko system with the window and input manager and a local diskorc.xml.

mmsInit(MMSINIT_WINDOWS, argc, argv, "./diskorc.xml",
           "Disko Tutorial: firststeps/01", "DT: firststeps/01");

Get something on the screen

To see something happen on the screen we will have to create a window first, and add a basic label to that window. This is achieved by following code.

// create a root window
MMSRootWindow *window = new MMSRootWindow("","100%","100%");

// create and add hello world label
MMSLabel *mylabel = new MMSLabel(window, "");
mylabel->setFont("./","DejaVuSansMono.ttf",16);
mylabel->setText("Hello World");
window->add(mylabel);

As you can see we chose to create a RootWindow. Disko knows three different types of windows RootWindow, Mainwindow and OSDWindow. RootWindows are windows that should be used for the main application windows. More information on that topic will follow in a later tutorial.

Windows can be shown or hided. To see the window on the screen we will show this window by a simple

// show the window
window->show();

After that, the application has nothing to do in peculiar.

// until user press <ctrl+c> or <power> button on the remote control
pause();
return 0;

After startup the application could be stopped by pressing Ctrl+C.

This is how it should look like: Hello world screenshot