ROVLib Tutorial - The Icon Bar

© Jason Tribbeck 2002

Creating an icon on the icon bar

In this tutorial, we will be creating an icon on the icon bar, which you will be able to click on. When you click on the icon, an error box will appear, and once dismissed, the application will be terminated.

The baricon system

ROVLib is segmented into various core systems, subsystems and helpers. The baricon subsystem uses the canvas core system in order to allow the icon to be clicked on. This means that the canvas core system has to be initialised in order for the baricon subsystem to work properly.

The baricon subsystem provides one call, and we are going to use it in its most basic form.

The source code

/**
 * IconBar.c - Create an icon on the icon bar
 */

/* Include 4 standard C header files */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>

/* Include the RISC OS kernel header file */
#include "kernel.h"

/* Include the ROVLib header files */
#include "main.h"
#include "canvas.h"
#include "baricon.h"
#include "extras.h"

/* Prototype the click function */
void click(int icn);

int main(int argc, char **argv) {
  /* Initialise the ROVLib system */
  main_init("Icon bar test");

  /* Initialise the ROVLib canvas core */
  canvas_init();

  /* Create an icon on the icon bar */
  baricon("file_ff8", click);

  /* Poll forever (or at least until told to quit!) */
  main_poll();
}

/* Actually perform the click function */
void click(int icn) {
  swerr(TRUE, "Boo! And now I'll leave you.");
}

Here, important changes since the basic application have been highlighted in red.

The first set of changes include some new ROVLib headers. canvas is included because we need to initialise the canvas core system. baricon is included for obvious reasons! extras is included because it gives us the error box.

In the main code, after initialising the main system, we initialise the canvas core system. After doing this, we then create an icon on the icon bar. We'll use the application sprite for this, but we could create one and use it here. In creating the icon, we are also telling ROVLib what function to call when the user clicks on the icon, in this case, a function simply called click. We then continue polling as before.

The click function simply calls swerr to produce a simple error box, with the string "Boo! And now I'll leave you.". The first parameter (TRUE) tells ROVLib that this is a fatal error, and ROVLib will automatically exit when the user acknowledges the error box.

Running the application

If you run the application, then you will see a new icon on your icon bar:


Note that this has been shrunk

If you click on the icon, then you will get an error box with the title "Fatal error from Icon bar test", and the message reads "Boo! And now I'll leave you.". If you acknowledge the error box, the application will die - the main thing to look out for is that the icon has been removed from the icon bar. You can also check the Task Manager's window, where the application will not be displayed.

Note that you can always kill the application by using the Task Manager.

Epilogue

In this tutorial, you have seen how to create an icon on the icon bar, and also got a glimpse of how ROVLib uses handlers for key events (in this case, the clicking of an icon). You have also seen how to create simple error boxes, and how to report fatal errors.