Debian Codegraph @

src/io/gfx/video.h

raw symbols SCIP
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 AJ Thomson
15 * Copyright (c) 2015-2026 Carsten Teibes
16 *
17 * OpenJazz is distributed under the terms of
18 * the GNU General Public License, version 2.0
19 *
20 */
21
22 #ifndef OJ_VIDEO_H
23 #define OJ_VIDEO_H
24
25 #include "setup.h"
26 #include "paletteeffects.h"
27 #include "platforms/platforms.h"
28
29 #ifdef OJ_SDL3
30 #include <SDL3/SDL.h>
31 #else
32 #include <SDL.h>
33 #endif
34
35 // Constants
36
37 // Original screen dimensions
38 #define SW 320
39 #define SH 200
40
41 #define MIN_SCALE 1
42 #ifdef SCALE
43 #define MAX_SCALE 4
44 #else
45 #define MAX_SCALE 1
46 #endif
47
48 // Maximum screen dimensions
49 #define MAX_SCREEN_WIDTH (32 * 256 * MAX_SCALE)
50 #define MAX_SCREEN_HEIGHT (32 * 64 * MAX_SCALE)
51
52 // Default configuration
53 #ifndef DEFAULT_SCREEN_WIDTH
54 #define DEFAULT_SCREEN_WIDTH SW
55 #endif
56 #ifndef DEFAULT_SCREEN_HEIGHT
57 #define DEFAULT_SCREEN_HEIGHT SH
58 #endif
59
60 // Fullscreen and Window flags are only for SDL1.2
61 #if OJ_SDL2 || OJ_SDL3
62 #ifdef WINDOWED_FLAGS
63 #pragma message "Ignoring WINDOWED_FLAGS when not building with SDL 1.2"
64 #endif
65 #ifdef FULLSCREEN_FLAGS
66 #pragma message "Ignoring FULLSCREEN_FLAGS when not building with SDL 1.2"
67 #endif
68 #else
69 #ifndef WINDOWED_FLAGS
70 #define WINDOWED_FLAGS (SDL_RESIZABLE | SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_HWPALETTE)
71 #endif
72 #ifndef FULLSCREEN_FLAGS
73 #define FULLSCREEN_FLAGS (SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_HWPALETTE)
74 #endif
75 #endif
76
77 // Time interval
78 #define T_MENU_FRAME 20
79
80 // Class
81
82 /// Video output
83 class Video {
84 public:
85 Video ();
86
87 bool init (SetupOptions cfg);
88 void deinit ();
89 bool reset (int width, int height);
90
91 void setPalette (SDL_Color *palette);
92 SDL_Color* getPalette () const;
93 void changePalette (SDL_Color *palette, unsigned char first, unsigned int amount);
94
95 // Surface
96 SDL_Surface* createSurface (const unsigned char* pixels, int width, int height);
97 void destroySurface (SDL_Surface *surface);
98 void setSurfacePalette (SDL_Surface *surface, SDL_Color *palette, int start, int length);
99 void restoreSurfacePalette (SDL_Surface *surface);
100 void enableColorKey (SDL_Surface *surface, unsigned int index);
101 unsigned int getColorKey (SDL_Surface *surface);
102 void setClipRect (SDL_Surface *surface, const SDL_Rect *rect);
103
104 void drawRect (int x, int y, int width, int height, int index, bool fill = true);
105
106 int getMinWidth () const;
107 int getMaxWidth () const;
108 int getMinHeight () const;
109 int getMaxHeight () const;
110 int getWidth () const;
111 int getHeight () const;
112 void setTitle (const char *title);
113 int getScaleFactor () const;
114 scalerType getScaleMethod () const;
115 void setScaling (int newScaleFactor, scalerType newScaleMethod);
116 bool isFullscreen () const;
117
118 void moviePlayback (bool status);
119
120 void update (SDL_Event *event);
121 void flip (int mspf, PaletteEffect* paletteEffects = NULL, bool effectsStopped = false);
122
123 void clearScreen (int index);
124
125 private:
126 void findResolutions ();
127 void expose ();
128 void commonDeinit ();
129
130 #if OJ_SDL3 || OJ_SDL2
131 SDL_Window* window; ///< Output window
132 SDL_Renderer* renderer; ///< Output renderer
133 SDL_Texture* texture; ///< Output texture
134 #endif
135 #if OJ_SDL2
136 SDL_Surface* textureSurface;
137 #endif
138 SDL_Surface* screen; ///< Output surface
139
140 // Palettes
141 SDL_Color* currentPalette; ///< Current palette
142 #if OJ_SDL3
143 SDL_Palette* texturePalette; ///< Screen palette
144 SDL_Palette* logicalPalette; ///< Logical palette (greyscale)
145 #else
146 SDL_Color logicalPalette[MAX_PALETTE_COLORS]; ///< Logical palette (greyscale)
147 #endif
148
149 int minW; ///< Smallest possible width
150 int maxW; ///< Largest possible width
151 int minH; ///< Smallest possible height
152 int maxH; ///< Largest possible height
153 int screenW; ///< Real width
154 int screenH; ///< Real height
155 int scaleFactor; ///< Scaling factor
156 scalerType scaleMethod; ///< Filtering
157 bool fullscreen; ///< Full-screen mode
158 bool isPlayingMovie;
159 };
160
161 // Inline functions
162
163 inline SDL_Color* Video::getPalette () const { return currentPalette; } ///< Returns the current display palette.
164 inline int Video::getMinWidth () const { return minW; } ///< Returns the minimum possible screen width.
165 inline int Video::getMaxWidth () const { return maxW; } ///< Returns the maximum possible screen width.
166 inline int Video::getMinHeight () const { return minH; } ///< Returns the minimum possible screen height.
167 inline int Video::getMaxHeight () const { return maxH; } ///< Returns the maximum possible screen height.
168 inline int Video::getWidth () const { return screenW; } ///< Returns the current width of the window or screen.
169 inline int Video::getHeight () const { return screenH; } ///< Returns the current height of the window or screen.
170 inline int Video::getScaleFactor () const { return scaleFactor;} ///< Returns the current scaling factor.
171 inline scalerType Video::getScaleMethod () const { return scaleMethod; } ///< Returns the current scaling method.
172 inline bool Video::isFullscreen () const { return fullscreen; } ///< Determines whether or not full-screen mode is being used.
173
174 // Variables
175
176 EXTERN SDL_Surface* canvas; ///< Surface used for drawing
177 EXTERN int canvasW; ///< Drawing surface width
178 EXTERN int canvasH; ///< Drawing surface height
179
180 EXTERN Video video; ///< Video output
181
182 #endif