| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#pragma once |
| 50 |
|
| 51 |
#include <stdbool.h> |
| 52 |
|
| 53 |
#include <SDL.h> |
| 54 |
|
| 55 |
#include "c_array.h" |
| 56 |
#include "color.h" |
| 57 |
#include "config.h" |
| 58 |
#include "sys_specifics.h" |
| 59 |
#include "window_context.h" |
| 60 |
|
| 61 |
|
| 62 |
#define RESTART_WINDOW 1 |
| 63 |
#define RESTART_SCALE_MODE 2 |
| 64 |
#define RESTART_BRIGHTNESS 4 |
| 65 |
#define RESTART_ALL -1 |
| 66 |
typedef struct |
| 67 |
{ |
| 68 |
struct vec2i Res; |
| 69 |
bool Fullscreen; |
| 70 |
int ScaleFactor; |
| 71 |
ScaleMode ScaleMode; |
| 72 |
int Brightness; |
| 73 |
bool SecondWindow; |
| 74 |
bool IsEditor; |
| 75 |
|
| 76 |
int RestartFlags; |
| 77 |
} GraphicsConfig; |
| 78 |
|
| 79 |
typedef struct |
| 80 |
{ |
| 81 |
int IsInitialized; |
| 82 |
int IsWindowInitialized; |
| 83 |
SDL_Surface *icon; |
| 84 |
SDL_Texture *screen; |
| 85 |
SDL_Texture *hud; |
| 86 |
SDL_Texture *hud2; |
| 87 |
WindowContext gameWindow; |
| 88 |
WindowContext secondWindow; |
| 89 |
SDL_PixelFormat *Format; |
| 90 |
GraphicsConfig cachedConfig; |
| 91 |
Uint32 *buf; |
| 92 |
SDL_Texture *bkg; |
| 93 |
SDL_Texture *bkg2; |
| 94 |
SDL_Texture *bkgTgt; |
| 95 |
SDL_Texture *bkgTgt2; |
| 96 |
SDL_Texture *brightnessOverlay; |
| 97 |
} GraphicsDevice; |
| 98 |
|
| 99 |
extern GraphicsDevice gGraphicsDevice; |
| 100 |
|
| 101 |
void GraphicsInit(GraphicsDevice *device, Config *c); |
| 102 |
void GraphicsInitialize(GraphicsDevice *g); |
| 103 |
void GraphicsTerminate(GraphicsDevice *g); |
| 104 |
int GraphicsGetScreenSize(GraphicsConfig *config); |
| 105 |
int GraphicsGetMemSize(GraphicsConfig *config); |
| 106 |
void GraphicsConfigSet( |
| 107 |
GraphicsConfig *c, |
| 108 |
struct vec2i res, const bool fullscreen, |
| 109 |
const int scaleFactor, const ScaleMode scaleMode, const int brightness, |
| 110 |
const bool secondWindow); |
| 111 |
void GraphicsConfigSetFromConfig(GraphicsConfig *gc, Config *c); |
| 112 |
|
| 113 |
void GraphicsSetClip(SDL_Renderer *renderer, const Rect2i r); |
| 114 |
Rect2i GraphicsGetClip(SDL_Renderer *renderer); |
| 115 |
void GraphicsResetClip(SDL_Renderer *renderer); |
| 116 |
|
| 117 |
#define CenterX(w) ((gGraphicsDevice.cachedConfig.Res.x - w) / 2) |
| 118 |
#define CenterY(h) ((gGraphicsDevice.cachedConfig.Res.y - h) / 2) |
| 119 |
|
| 120 |
#define CenterOf(a, b, w) ((a + (((b - a) - w) / 2))) |
| 121 |
|
| 122 |
#define CenterOfRight(w) CenterOf((gGraphicsDevice.cachedConfig.Res.x / 2), (gGraphicsDevice.cachedConfig.Res.x), w) |
| 123 |
#define CenterOfLeft(w) CenterOf(0, (gGraphicsDevice.cachedConfig.Res.x / 2), w) |