1 #pragma once
2 
3 /** Class for managing the display. There shouldn't be anything specific to a
4 *   particlar game in this class.
5 */
6 
7 namespace Gigalomania {
8 	class Screen {
9 #if SDL_MAJOR_VERSION == 1
10 		SDL_Surface *surface;
11 #else
12 		SDL_Window *sdlWindow;
13 		SDL_Renderer *sdlRenderer;
14 		int width, height; // this stores the logical size rather than the window size
15 #endif
16 		int m_pos_x;
17 		int m_pos_y;
18 		bool m_down_left;
19 		bool m_down_middle;
20 		bool m_down_right;
21 
22 	public:
23 		Screen();
24 		~Screen();
25 
26 		static bool canOpenFullscreen(int width, int height);
27 		bool open(int screen_width, int screen_height, bool fullscreen);
28 #if SDL_MAJOR_VERSION == 1
29 #else
30 		void setLogicalSize(int width, int height, bool smooth);
31 #endif
32 		void setTitle(const char *title);
33 		void clear();
34 		void refresh();
35 		// in SDL2, these return the logical size rather than the window size
36 		int getWidth() const;
37 		int getHeight() const;
38 		void fillRect(short x, short y, short w, short h, unsigned char r, unsigned char g, unsigned char b);
39 #if SDL_MAJOR_VERSION == 1
40 		// not supported with SDL 1.2
fillRectWithAlpha(short x,short y,short w,short h,unsigned char r,unsigned char g,unsigned char b,unsigned char alpha)41 		void fillRectWithAlpha(short x, short y, short w, short h, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha) {
42 		}
drawLine(short x1,short y1,short x2,short y2,unsigned char r,unsigned char g,unsigned char b)43 		void drawLine(short x1, short y1, short x2, short y2, unsigned char r, unsigned char g, unsigned char b) {
44 		}
45 #else
46 		void fillRectWithAlpha(short x, short y, short w, short h, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha);
47 		void drawLine(short x0, short y0, short x1, short y1, unsigned char r, unsigned char g, unsigned char b);
48 		void convertWindowToLogical(int *m_x, int *m_y) const;
49 		void getWindowSize(int *window_width, int *window_height) const;
50 #endif
setMousePos(int x,int y)51 		void setMousePos(int x, int y) {
52 			this->m_pos_x = x;
53 			this->m_pos_y = y;
54 		}
setMouseLeft(bool down)55 		void setMouseLeft(bool down) {
56 			this->m_down_left = down;
57 		}
setMouseMiddle(bool down)58 		void setMouseMiddle(bool down) {
59 			this->m_down_middle = down;
60 		}
setMouseRight(bool down)61 		void setMouseRight(bool down) {
62 			this->m_down_right = down;
63 		}
64 		void getMouseCoords(int *m_x, int *m_y) const;
65 		bool getMouseState(int *m_x, int *m_y, bool *m_left, bool *m_middle, bool *m_right) const;
66 	};
67 }
68 
69 class Application {
70 	bool quit;
71 	bool blank_mouse;
72 	bool compute_fps;
73 	float fps;
74 	unsigned int last_time;
75 
76 public:
77 	Application();
78 	~Application();
79 
80 	bool init();
81 
82 	unsigned int getTicks() const;
83 	void delay(unsigned int time);
84 	void wait();
85 	void runMainLoop();
setQuit()86 	void setQuit() {
87 		quit = true;
88 	}
hasFPS()89 	bool hasFPS() const {
90 		return compute_fps;
91 	}
getFPS()92 	float getFPS() const {
93 		return fps;
94 	}
isBlankMouse()95 	bool isBlankMouse() const {
96 		return this->blank_mouse;
97 	}
98 };
99