Mac OS X Reference Library Apple Developer Connection spyglass button

ScreenSaverView Class Reference

Inherits from
Conforms to
Framework
Library/Frameworks/ScreenSaver.framework
Availability
Available in Mac OS X v10.0 and later.
Declared in
ScreenSaverView.h
Related sample code

Overview

ScreenSaverView is an abstract class that defines the interface for subclassers to interact with the screen saver infrastructure.

Screen savers are subclasses of ScreenSaverView, packaged up in bundles and loaded by the screen saver application. (These bundles have a suffix of .saver and are located in the Library/Screen Savers directories of the various file system domains. See File System Overview for information about domains.) ScreenSaverView defines an interface for animating screen savers, instantiating small preview versions of the screen saver view (for display in the system preferences, for example), and for providing a configuration sheet to set various properties of the screen saver. In addition, subclasses can set the animation interval, the backing store of their window, and how the screen transitions to the animation.

There are two main ways to do drawing in a screen saver. You can either do your drawing in the normal NSView drawRect: method, or you can do your drawing in ScreenSaverView’s animateOneFrame method. If you do drawing in drawRect:, you should call setNeedsDisplay: with an argument of YES in animateOneFrame.

Tasks

Initializing a ScreenSaverView

Getting the Preferred Window Behavior

Setting and Getting the Animation Time Interval

Animating the ScreenSaverView

Drawing the ScreenSaverView

Accessing the Configuration Sheet

Class Methods

backingStoreType

Returns the desired backing store for windows in which the screen saver view will be instantiated.

+ (NSBackingStoreType)backingStoreType

Discussion

Subclasses should override this method to return the desired backing store. The default is NSBackingStoreBuffered.

Availability
Declared In
ScreenSaverView.h

performGammaFade

Indicates whether the screen saver application should perform a gradual screen fade when it starts and stops the animation.

+ (BOOL)performGammaFade

Discussion

This class method allows the screen saver view to select how the desktop visibly transitions to the screen saver view. If this method returns YES, the screen will gradually darken before the animation begins. If it returns NO, the transition will be immediate. The latter behavior is more appropriate if the screen saver animates a screen shot of the desktop, as is the case for optical lens effects. The default is YES.

Availability
Declared In
ScreenSaverView.h

Instance Methods

animateOneFrame

Advances the screen saver’s animation by a single frame.

- (void)animateOneFrame

Discussion

This method is called each time the timer animating the screen saver fires. The time between calls to this method is always at least animationTimeInterval. It is guaranteed that the focus is locked when this method is called, so subclasses may do drawing in this method. The subclass can also let drawRect: perform the drawing, in which case animateOneFrame needs to call setNeedsDisplay: with an argument of YES. The default implementation does nothing.

Availability
  • Available in Mac OS X v10.0 and later.
See Also
Related Sample Code
Declared In
ScreenSaverView.h

animationTimeInterval

Returns the minimum time between animation frames of the screen saver.

- (NSTimeInterval)animationTimeInterval

Availability
  • Available in Mac OS X v10.0 and later.
See Also
Declared In
ScreenSaverView.h

configureSheet

Returns the window containing all of the controls to be used for configuring the screen saver.

- (NSWindow *)configureSheet

Discussion

This window will be run as a sheet, so it must include buttons that allow the user to end the modal session in which the sheet runs. When the user dismisses the sheet, the controller in charge of the sheet must end the document modal session by calling NSApplication’s endSheet: with the sheet’s window as the argument.

Availability
  • Available in Mac OS X v10.0 and later.
See Also
Related Sample Code
Declared In
ScreenSaverView.h

drawRect:

Draws the screen saver view.

- (void)drawRect:(NSRect)rect

Discussion

ScreenSaverView implements drawRect: to draw a black background. Subclasses can do their drawing here or in animateOneFrame.

Availability
  • Available in Mac OS X v10.0 and later.
See Also
Declared In
ScreenSaverView.h

hasConfigureSheet

Returns whether the screen saver has an associated configuration sheet.

- (BOOL)hasConfigureSheet

Discussion

Subclasses that provide configure sheets as part of their bundle should override this method to return YES.

Availability
  • Available in Mac OS X v10.0 and later.
See Also
Related Sample Code
Declared In
ScreenSaverView.h

initWithFrame:

Calls initWithFrame:isPreview: with an argument of NO.

- (id)initWithFrame:(NSRect)frame

Availability
  • Available in Mac OS X v10.0 and later.
Declared In
ScreenSaverView.h

initWithFrame:isPreview:

Initializes a newly allocated ScreenSaverView with frame as its frame rectangle, and sets the value returned by isPreview to isPreview.

- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview

Discussion

The screen saver application will install the new view object into the view hierarchy of an NSWindow before the animation begins. This method is the designated initializer for the ScreenSaverView class. Returns self.

Availability
  • Available in Mac OS X v10.0 and later.
See Also
Declared In
ScreenSaverView.h

isAnimating

Returns YES if the screen saver is currently animating, NO otherwise.

- (BOOL)isAnimating

Availability
  • Available in Mac OS X v10.0 and later.
See Also
Declared In
ScreenSaverView.h

isPreview

Returns YES if the screen saver view was created in a smaller size to be used as a preview, NO if it was created full-screen for use as a screen saver.

- (BOOL)isPreview

Discussion

Subclasses can use the return value of isPreview to determine if they should change their drawing parameters to something more suitable for display in a smaller frame.

Availability
  • Available in Mac OS X v10.0 and later.
Declared In
ScreenSaverView.h

setAnimationTimeInterval:

Sets the time interval between animation frames.

- (void)setAnimationTimeInterval:(NSTimeInterval)timeInterval

Discussion

Subclasses with particular requirements for time between animation frames should call this method to set the animation rate to a reasonable value.

Availability
  • Available in Mac OS X v10.0 and later.
See Also
Declared In
ScreenSaverView.h

startAnimation

Activates the periodic timer that animates the screen saver.

- (void)startAnimation

Discussion

This method is called when the screen saver view should begin animating. Subclasses can implement this method to set up initial state or allocate expensive resources that should be loaded lazily. Subclasses must call the inherited implementation.

Availability
  • Available in Mac OS X v10.0 and later.
See Also
Related Sample Code
Declared In
ScreenSaverView.h

stopAnimation

Deactivates the timer that advances the animation.

- (void)stopAnimation

Discussion

This method is called when the screen saver view should stop animating. Subclasses can implement this method to unload expensive resources or reset state to original parameters. Subclasses must call the inherited implementation.

Availability
  • Available in Mac OS X v10.0 and later.
See Also
Related Sample Code
Declared In
ScreenSaverView.h


Last updated: 2006-05-23

Did this document help you? Yes It's good, but... Not helpful...