Bunch-a-bugfixes!
[ipdf/code.git] / src / screen.h
1 #ifndef _SCREEN_H
2 #define _SCREEN_H
3
4 #include <SDL.h>
5
6 #include <functional>
7
8 namespace IPDF
9 {
10         /*
11          * The "Screen" class handles managing the OS window (using SDL2).
12          */
13         class Screen
14         {
15         public:
16                 Screen();
17                 ~Screen();
18
19                 // 'Pumps' the system event queue.
20                 // Returns 'false' if the program should quit.
21                 bool PumpEvents();
22
23                 // Clears the screen to a given colour.
24                 void Clear(float r=1.0, float g=1.0, float b=1.0, float a=1.0);
25
26                 // Finishes rendering a frame, and presents it on the screen.
27                 void Present();
28
29                 // Get the current width/height of the window's viewport.
30                 int ViewportWidth() const { return m_viewport_width; }
31                 int ViewportHeight() const { return m_viewport_height; }
32                 
33                 // Handle mouse input.
34                 typedef std::function<void(int x, int y, int button, int wheel)> MouseHandler;
35                 void SetMouseHandler(MouseHandler handler)
36                 {
37                         m_mouse_handler = handler;
38                 }
39                 
40                 enum MouseCursors
41                 {
42                         CursorArrow,
43                         CursorWait,
44                         CursorWaitArrow,
45                         CursorMove,
46                         CursorHand
47                 };
48                 void SetMouseCursor(MouseCursors cursor);
49
50                 void ScreenShot(const char * filename) const;
51                 void RenderBMP(const char * filename) const;
52         private:
53                 void ResizeViewport(int width, int height);
54                 
55                 MouseHandler m_mouse_handler;
56                 int m_last_mouse_x;
57                 int m_last_mouse_y;
58
59                 int m_viewport_width;
60                 int m_viewport_height;
61                 SDL_Window *m_window;
62                 SDL_GLContext m_gl_context;
63         };
64
65 }
66
67 #endif // _SCREEN_H

UCC git Repository :: git.ucc.asn.au