1 
2 /**
3  *
4  * @file video.h
5  *
6  * Part of the OpenJazz project
7  *
8  * @par History:
9  * - 23rd August 2005: Created OpenJazz.h
10  * - 13th July 2009: Created graphics.h from parts of OpenJazz.h
11  * - 26th July 2009: Renamed graphics.h to video.h
12  *
13  * @par Licence:
14  * Copyright (c) 2005-2017 Alister Thomson
15  *
16  * OpenJazz is distributed under the terms of
17  * the GNU General Public License, version 2.0
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  */
24 
25 #ifndef _VIDEO_H
26 #define _VIDEO_H
27 
28 
29 #include "paletteeffects.h"
30 
31 #include <SDL.h>
32 
33 
34 // Constants
35 
36 // Original screen dimensions
37 #define SW 320
38 #define SH 200
39 
40 #define MIN_SCALE 1
41 #ifdef SCALE
42 	#define MAX_SCALE 4
43 #else
44 	#define MAX_SCALE 1
45 #endif
46 
47 // Maximum screen dimensions
48 #define MAX_SCREEN_WIDTH (32 * 256 * MAX_SCALE)
49 #define MAX_SCREEN_HEIGHT (32 * 64 * MAX_SCALE)
50 
51 #define WINDOWED_FLAGS (SDL_RESIZABLE | SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_HWPALETTE)
52 
53 #if defined(CAANOO) || defined(WIZ) || defined(GP2X) || defined(GAMESHELL)
54 	#define DEFAULT_SCREEN_WIDTH 320
55 	#define DEFAULT_SCREEN_HEIGHT 240
56 
57 	#define FULLSCREEN_ONLY
58 	#define NO_RESIZE
59 
60 	#define FULLSCREEN_FLAGS (SDL_FULLSCREEN | SDL_SWSURFACE | SDL_HWPALETTE)
61 #elif defined(DINGOO)
62 	#define DEFAULT_SCREEN_WIDTH 320
63 	#define DEFAULT_SCREEN_HEIGHT 240
64 
65 	#define FULLSCREEN_ONLY
66 	#define NO_RESIZE
67 
68 	#define FULLSCREEN_FLAGS 0
69 #elif defined(PSP)
70 	#define DEFAULT_SCREEN_WIDTH 480
71 	#define DEFAULT_SCREEN_HEIGHT 272
72 
73 	#define FULLSCREEN_ONLY
74 	#define NO_RESIZE
75 
76 	#define FULLSCREEN_FLAGS (SDL_FULLSCREEN | SDL_SWSURFACE | SDL_HWPALETTE)
77 #elif defined(_3DS)
78 	#define DEFAULT_SCREEN_WIDTH 400
79 	#define DEFAULT_SCREEN_HEIGHT 240
80 
81 	#define FULLSCREEN_ONLY
82 	#define NO_RESIZE
83 
84 	#define FULLSCREEN_FLAGS (SDL_SWSURFACE | SDL_TOPSCR | SDL_CONSOLEBOTTOM)
85 #else
86 	#define DEFAULT_SCREEN_WIDTH SW
87 	#define DEFAULT_SCREEN_HEIGHT SH
88 
89 	#define FULLSCREEN_FLAGS (SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_HWPALETTE)
90 #endif
91 
92 // Time interval
93 #define T_MENU_FRAME 20
94 
95 
96 // Class
97 
98 /// Video output
99 class Video {
100 
101 	private:
102 		SDL_Surface* screen; ///< Output surface
103 
104 		// Palettes
105 		SDL_Color*   currentPalette; ///< Current palette
106 		SDL_Color    logicalPalette[256]; ///< Logical palette (greyscale)
107 		bool         fakePalette; ///< Whether or not the palette mode is being emulated
108 
109 		int          maxW; ///< Largest possible width
110 		int          maxH; ///< Largest possible height
111 		int          screenW; ///< Real width
112 		int          screenH; ///< Real height
113 #ifdef SCALE
114 		int          scaleFactor; ///< Scaling factor
115 #endif
116 		bool         fullscreen; ///< Full-screen mode
117 
118 		void findMaxResolution ();
119 		void expose            ();
120 
121 	public:
122 		Video ();
123 
124 		bool       init                  (int width, int height, bool startFullscreen);
125 
126 		bool       reset                (int width, int height);
127 
128 		void       setPalette            (SDL_Color *palette);
129 		SDL_Color* getPalette            ();
130 		void       changePalette         (SDL_Color *palette, unsigned char first, unsigned int amount);
131 		void       restoreSurfacePalette (SDL_Surface *surface);
132 
133 		int        getMaxWidth           ();
134 		int        getMaxHeight          ();
135 		int        getWidth              ();
136 		int        getHeight             ();
137 #ifdef SCALE
138 		int        getScaleFactor        ();
139 		int        setScaleFactor        (int newScaleFactor);
140 #endif
141 #ifndef FULLSCREEN_ONLY
142 		bool       isFullscreen          ();
143 #endif
144 
145 		void       update                (SDL_Event *event);
146 		void       flip                  (int mspf, PaletteEffect* paletteEffects);
147 
148 		void       clearScreen           (int index);
149 
150 };
151 
152 
153 // Variables
154 
155 EXTERN SDL_Surface* canvas; ///< Surface used for drawing
156 EXTERN int          canvasW; ///< Drawing surface width
157 EXTERN int          canvasH; ///< Drawing surface height
158 
159 EXTERN Video video; ///< Video output
160 
161 
162 // Functions
163 
164 EXTERN SDL_Surface*   createSurface  (unsigned char* pixels, int width, int height);
165 EXTERN void           drawRect       (int x, int y, int width, int height, int index);
166 
167 #endif
168 
169 
170