1 /*
2  * Seven Kingdoms: Ancient Adversaries
3  *
4  * Copyright 1997,1998 Enlight Software Ltd.
5  * Copyright 2010,2015 Jesse Allen
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //Filename    : OVGA.H
23 //Description : VGA management class (SDL version)
24 
25 #ifndef __OVGA_H
26 #define __OVGA_H
27 
28 #include <OVGABUF.h>
29 #include <COLOR.h>
30 #include <SDL.h>
31 
32 //----------- define constants ----------//
33 
34 #define VGA_WIDTH             800
35 #define VGA_HEIGHT            600
36 #define VGA_BPP                 8
37 #define VGA_PALETTE_SIZE      256
38 
39 #define MAX_BRIGHTNESS_ADJUST_DEGREE 10
40 
41 #define IF_LIGHT_BORDER_COLOR     V_WHITE
42 #define IF_DARK_BORDER_COLOR      V_BLACK
43 #define IF_UP_BRIGHTNESS_ADJUST   5
44 #define IF_DOWN_BRIGHTNESS_ADJUST 6
45 
46 //-------- Define macro functions ---------//
47 
48 #define get_bitmap_width(bitmapPtr)  (*(short*)bitmapPtr)
49 #define get_bitmap_height(bitmapPtr) (*((short*)bitmapPtr+1))
50 
51 //-------- Define modes --------//
52 
53 enum MouseInputMode
54 {
55 	MOUSE_INPUT_ABS,
56 	MOUSE_INPUT_REL,
57 	MOUSE_INPUT_REL_WARP,
58 };
59 
60 enum WinGrab
61 {
62 	WINGRAB_OFF,
63 	WINGRAB_ON,
64 	WINGRAB_TOGGLE,
65 	WINGRAB_FORCE,
66 	WINGRAB_RESTORE,
67 };
68 
69 //-------- Define class Vga ----------------//
70 
71 class ColorTable;
72 
73 class Vga
74 {
75 private:
76 	SDL_Window*    window;
77 	SDL_Renderer*  renderer;
78 	SDL_Texture*   texture;
79 	SDL_Surface*   target;
80 	SDL_Color      game_pal[VGA_PALETTE_SIZE];
81 	SDL_Color*     custom_pal;
82 
83 	int win_grab_forced;
84 	int win_grab_user_mode;
85 	int bound_x1, bound_y1, bound_x2, bound_y2;
86 	int boundary_set;
87 
88 public:
89 	ColorTable*    vga_color_table;
90 	unsigned char  gray_remap_table[VGA_PALETTE_SIZE];
91 
92 	static VgaBuf* active_buf;
93 	static char    use_back_buf;
94 	static char    opaque_flag;
95 
96 	MouseInputMode mouse_mode;
97 
98 public:
99 	Vga();
100 	~Vga();
101 
102 	int    init();
103 	void   deinit();
104 
is_inited()105 	char   is_inited()  { return window != NULL; }
106 
107 	int    load_pal(const char* fileName);
108 	void   activate_pal(VgaBuf*);
109 
110 	int    set_custom_palette(char*);
111 	void   free_custom_palette();
112 	void   adjust_brightness(int changeValue);
113 
use_front()114 	void use_front() { use_back_buf=0; active_buf = &vga_front; }
use_back()115 	void use_back()  { use_back_buf=1; active_buf = &vga_back;  }
116 
117 	void   handle_messages();
118 	void   flag_redraw();
119 	int    is_full_screen();
120 	int    is_input_grabbed();
121 	void   update_boundary();
122 	void   update_mouse_pos();
123 	void   set_full_screen_mode(int mode);
124 	void   set_mouse_mode(MouseInputMode mode);
125 	void   set_window_grab(WinGrab mode);
126 	void   flip();
127 	void   save_status_report();
128 
129 private:
130 	void   get_window_scale(float *xscale, float *yscale);
131 };
132 
133 extern Vga vga;
134 
135 //--------------------------------------------//
136 
137 #endif
138