PLM Software Multimedia Tools and Games
PLMBase

PLMBase Component : User interface


Overview

In this section, we will find in fact all the classes that do not fit in other sections.

We also find basic data structures like point and rectangle, containers like vector, list, doubly linked list and string.

File utilities, to easily perform simple operations on files and directories in a portable way (linux and win32).

Event system, based on the PLMInput class, who gives access to the main event queue (keyboard, mouse, joystick, window manager, ...). Keys are defined as enums in PLMKey.hpp. A series of structures is defined in PLMEvent.hpp to handle any type of event.

Callbacks, mainly used by the user interface classes.

The SDL session manager helps the hardware-oriented classes by automatically initialising and de-initialising the SDL components (mainly for video, audio, input and timer).

The timer allows to measure time. It can save and compute elapsed time from the last saved time.


Classes

  • PUI1Appli : main application class.
  • PUI1Label : simple label
  • PUI1Label : progress bar
  • PUI1TextButton : clic button, clic on it to execute some action (the black frame around Ok means it has keyboard focus)
  • PUI1TogTextButton : toggle button, with two states (on/off, 0/1, true/false)
  • PUI1Counter : to specify numerical values (bound to some range), you can use the little arrows to modify the value, or clic on the text then move the mouse up/down, and eventually with the keyboard (arrows, page up/down and home/end)
  • PUI1Entry : to type some text on only one line
  • PUI1FileSelector : to select one file or directory from the file system (it's a window, not a widget)
  • PUI1Key : to store key definition, just clic on it like a clic button, then press any key
  • PUI1List : a simple text list, no icons, only one column
  • PUI1MCList : enhanced list, multi-column and icons, with a header
  • PUI1Menu : a menu window containing menu-item widgets (text, icon, separator, toggle)
  • PUI1OutTerm : a console to write some text output (each line can have a different color)
  • PUI1PopupList : a simple list in a popup window (clic with right/middle mouse button to select)
  • PUI1ScrollBar : a scrollbar, can be horizontal or vertical
  • PUI1Slider : to select a value in a range by dragging a cursor
  • PUI1Widget : the abstract class that defines all the widgets properties and methods
  • PUI1WidgetSet : a widget container used by windows to store their widgets
  • PUI1WinMgr : the window manager, handle windows and dispatch events
  • PUI1Window : a window !

Examples

The first example shows how to initialise the window manager :

  // get the screen object
  PLMScreen *screen = PLMScreen::GetInstance ();
  ASSERT (screen);
  // init screen with command-line parameters
  if (! screen->Init (width, height, flags, depth))
    { cerr << "Can not init screen\n";  exit(1); }
  // create the window manager (needs a correctly initialised screen)
  PUI1WinMgr wm (screen);
  wm.PrintInfo ();
  // create a window (no drawable, position=50,50  size=250x100, not modal)
  PUI1Window *w1 = new PUI1Window (0, PLMRect (50, 50, 250, 100),
                                   false, "My window");
  w1->SetColor (COL_BACK);
  w1->SetVisible (true);
  // then add it to the window manager's stack
  wm.AddWin (w1);
  wm.PrintInfo ();
  // later in the application's main loop, call wm.HandleEvent (ev)
  // so that the window manager can dispatch the incoming events to the
  // right window

Now let's take a serious example, we will use the default (root) window, and add some widgets to it :

  // get main window (root)
  PUI1Window *root = (PUI1Window*) winmgr.GetRootWin ();
  // set it not visible to avoid useless refresh when we add widgets
  root->SetVisible (false);
  root->SetColor (COL_BACK);
  root->SetBorder (1);
  // load a font from the resource manager, and set it
  // this way, all the widgets we add now will also use it as default
  PLMFont *font = (PLMFont*) resmgr->Load ("gui.font", ORES_PFONT);
  if (font != NULL)
    root->SetFont (font);
  else
    cerr << "Error loading font.\n";
  // create a text box (30 pixels from screen borders)
  PLMRect sz (30, 30, screen->Width()-30-30, 20);
  PUI1Entry *entry = new PUI1Entry (root, sz, "Default text");
  root->AddWidget (entry);
  // create a text button
  sz.Set (30, 60, 50, 20);
  PUI1TextButton *tbut = new PUI1TextButton (root, sz, "Ok");
  // associate this button with the method 'cb_quit()' of the object 'myapp' of
  // class MyApplication, this way cb_quit() will be called each time the button
  // is clicked.
  tbut->SetCallback ( new PLMCallbackDef<MyApplication>
                         (myapp, &MyApplication::cb_quit) );
  root->AddWidget (tbut);
  // force the window to redraw now then set it visible and refresh the screen
  // (the root window is already in the stack and can not be removed)
  root->Draw (true);
  root->SetVisible (true);
  root->Refresh ();

To see a working example, take a look at testui1.cpp and testui1menu.cpp in example/src.


Copyright 2001-2004 PLMSoft All rights reserved. (last mod.: 15 Oct 2004)