The Be Book Screen Saver Screen Saver Index

An Example Screen Saver

Here's sample code that implements a screen saver that blanks the screen. This is pretty boring, so you'll probably want to change the Draw() function to do something cute.

/* Minimal screen saver example. */

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

extern "C" {
_EXPORT
BScreenSaver *instantiate_screen_saver( BMessage *msg, image_id id );
}

class MinimalSaver : public BScreenSaver
{
public:
   MinimalSaver( BMessage *archive, image_id image );
   virtual ~MinimalSaver( void );
   
   virtual void StartConfig( BView *view );
   virtual status_t StartSaver( BView *view, bool preview );
   virtual void Draw( BView *view, int32 frame );
};

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

MinimalSaver::MinimalSaver( BMessage *archive, image_id image )
   : BScreenSaver( archive, image )
{
   /* Nothing else to do here... */
}

MinimalSaver::~MinimalSaver( void )
{
   /* Nothing else to do here... */
}

void MinimalSaver::StartConfig( BView *view )
{
   view->AddChild( new BStringView( BRect( 10, 10, 200, 35 ),
                                    B_EMPTY_STRING,
                                    "Minimal Saver" ) );
}

status_t MinimalSaver::StartSaver( BView *view, bool preview )
{
   /* We're so minimal, we don't have a preview. */
   if( preview ) return B_ERROR;

   return B_OK;
}

void MinimalSaver::Draw( BView *view, int32 frame )
{
   if( frame == 0 ) {
      /* Fill the screen with black on the first frame: */
      view->SetLowColor( 0, 0, 0 );
      view->FillRect( view->Bounds(), B_SOLID_LOW );
   }
}


The Be Book Screen Saver Screen Saver Index

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

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