From http://www.jwz.org/xscreensaver/xscreensaver-5.32.tar.gz
[xscreensaver] / OSX / XScreenSaverView.h
1 /* xscreensaver, Copyright (c) 2006-2014 Jamie Zawinski <jwz@jwz.org>
2  *
3  * Permission to use, copy, modify, distribute, and sell this software and its
4  * documentation for any purpose is hereby granted without fee, provided that
5  * the above copyright notice appear in all copies and that both that
6  * copyright notice and this permission notice appear in supporting
7  * documentation.  No representations are made about the suitability of this
8  * software for any purpose.  It is provided "as is" without express or 
9  * implied warranty.
10  */
11
12 /* This is a subclass of Apple's ScreenSaverView that knows how to run
13    xscreensaver programs without X11 via the dark magic of the "jwxyz"
14    library.  In xscreensaver terminology, this is the replacement for
15    the "screenhack.c" module.
16  */
17
18 #ifdef USE_IPHONE
19 # import <Foundation/Foundation.h>
20 # import <UIKit/UIKit.h>
21 # define NSView  UIView
22 # define NSRect  CGRect
23 # define NSSize  CGSize
24 # define NSColor UIColor
25 # define NSImage UIImage
26 # define NSEvent UIEvent
27 # define NSWindow UIWindow
28 #else
29 # import <Cocoa/Cocoa.h>
30 # import <ScreenSaver/ScreenSaver.h>
31 #endif
32
33
34 #import "screenhackI.h"
35 #import "PrefsReader.h"
36
37 #ifdef USE_IPHONE
38 @interface ScreenSaverView : NSView
39 - (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview;
40 - (NSTimeInterval)animationTimeInterval;
41 - (void)setAnimationTimeInterval:(NSTimeInterval)timeInterval;
42 - (void)startAnimation;
43 - (void)stopAnimation;
44 - (BOOL)isAnimating;
45 - (void)animateOneFrame;
46 - (BOOL)hasConfigureSheet;
47 //- (NSWindow*)configureSheet;
48 - (UIViewController*)configureView;
49 - (BOOL)isPreview;
50 @end
51
52 #endif // USE_IPHONE
53
54
55 #define USE_BACKBUFFER  // must be in sync with jwxyz.m
56
57 // If USE_BACKBUFFER is enabled, one of these must also be enabled.
58 // #define BACKBUFFER_CGCONTEXT   // Not supported by iOS.
59 #define BACKBUFFER_CALAYER
60
61 @interface XScreenSaverView : ScreenSaverView
62 # ifdef USE_IPHONE
63                               <UIAlertViewDelegate>
64 # endif
65 {
66   struct xscreensaver_function_table *xsft;
67   PrefsReader *prefsReader;
68
69   BOOL setup_p;            // whether xsft->setup_cb() has been run
70   BOOL initted_p;          // whether xsft->init_cb() has been run
71   BOOL resized_p;          // whether to run the xsft->reshape_cb() soon
72   double next_frame_time;  // time_t in milliseconds of when to tick the frame
73
74   // Data used by the Xlib-flavored screensaver
75   Display *xdpy;
76   Window xwindow;
77   void *xdata;
78   fps_state *fpst;
79
80 # ifdef USE_IPHONE
81   UIDeviceOrientation orientation, new_orientation;
82   BOOL screenLocked;
83
84   CGSize initial_bounds;        // portrait-mode size (pixels, not points).
85         
86   GLfloat rotation_ratio;       // ratio [0-1] thru rotation anim, or -1
87   NSSize rot_current_size;      // intermediate or at-rest orientation.
88   NSSize rot_from, rot_to;      // start/end size rect (pixels, not points)
89   GLfloat rot_current_angle;    // only right angles when rotation complete.
90   GLfloat angle_from, angle_to; // start angle, end angle (degrees)
91   double rot_start_time;
92
93   BOOL ignore_rotation_p;       // whether hack requested "always portrait".
94                                 // some want this, some do not.
95
96   NSTimer *crash_timer;
97
98   NSDictionary *function_tables;
99
100 # endif // USE_IPHONE
101
102 # ifdef USE_BACKBUFFER
103   CGContextRef backbuffer;
104   CGSize backbuffer_size;       // pixels, not points.
105   CGColorSpaceRef colorspace;
106
107 #  ifdef BACKBUFFER_CGCONTEXT
108   CGContextRef window_ctx;
109 #  endif
110
111 # endif // USE_BACKBUFFER
112 }
113
114 - (id)initWithFrame:(NSRect)frame saverName:(NSString*)n isPreview:(BOOL)p;
115
116 - (void) render_x11;
117 - (void) prepareContext;
118 - (void) resizeContext;
119 - (NSUserDefaultsController *) userDefaultsController;
120 + (NSString *) decompressXML:(NSData *)xml;
121
122 #ifdef USE_IPHONE
123 - (void)didRotate:(NSNotification *)notification;
124 - (BOOL)reshapeRotatedWindow;
125 - (void)setScreenLocked:(BOOL)locked;
126 #endif // USE_IPHONE
127
128 #ifdef USE_BACKBUFFER
129 - (void)initLayer;
130 - (void)createBackbuffer:(CGSize)s;
131 #endif // USE_BACKBUFFER
132
133 @end