Screen Saver: Screen Saver Add-ons

Screen Saver Table of Contents | Screen Saver Index

# Screen Saver Add-ons

Declared in: be/add-ons/screen_saver/ScreenSaver.h

Library: ScreenSaver

A screen saver add-on embodies a single screen saver module. Each module is represented by a BScreenSaver object. To create this object, the add-on implements and exports the function `instantiate_screen_saver()`. The screen saver system calls the `instantiate_screen_saver()` function when it's time to create and run the add-on's screen saver module.

## Building and Installing your Add-on

When you build your add-on, you need to link against the ScreenSaver preferences application. To do this you...

- Make a symbolic link to the ScreenSaver prefs in your add-on>s source directory, and then rename the link to "_APP_".

- Add _APP_ to the libraries in your BeIDE project file or Makefile.

You install your screen saver add-ons in the Screen Savers directory in `B_USER_ADDONS_DIRECTORY`; you may need to create the Screen Savers directory first. (See `find_directory()` in the Storage Kit if you're not familiar with the `B_USER_ADDONS_DIRECTORY` constant.)

There's also a Screen Savers directory in `B_BEOS_ADDONS_DIRECTORY`. This is reserved for screen savers that come with BeOS. Don't put your screen savers in this directory.

## Global Functions

### instantiate_screen_saver()

BScreenSaver *`instantiate_screen_saver(` BMessage *msg, image_id image`) `

`instantiate_screen_saver()` must be implemented to create an instance of your BScreenSaver-derived class and return it as a BScreenSaver pointer. msg contains the state provided by a previous saver run (via the `SaveState()` function). image is the `image_id` of the add-on. You usually just pass these arguments straight into your BScreenSaver subclass' constructor, like this:

       #include <add-ons/screen_saver/ScreenSaver.h>

       class SpiffySaver : public BScreenSaver
       {
       public:
           SpiffySaver( BMessage *msg, image_id image );
       ...
       };

       BScreenSaver *instantiate_screen_saver(BMessage *msg, image_id image)
       {
           return new SpiffySaver(msg, id);
       }

The screen saver system handles bad object allocations for you. This means you don't have to catch `bad_alloc` exceptions in your own code. (If the system is that low on resources, the user has other things to worry about.)

Screen Saver Table of Contents | Screen Saver Index

The Be Book,
...in lovely HTML...
for BeOS Release 5.

Copyright © 2000 Be, Inc. All rights reserved..