66590e717bd238046d30b27f3ac18cbe08ebf70e
[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 #include "stb_truetype.h"
9
10 namespace IPDF
11 {
12         /*
13          * The "Screen" class handles managing the OS window (using SDL2).
14          */
15         class Screen
16         {
17         public:
18                 Screen();
19                 ~Screen();
20
21                 // 'Pumps' the system event queue.
22                 // Returns 'false' if the program should quit.
23                 bool PumpEvents();
24
25                 // Clears the screen to a given colour.
26                 void Clear(float r=1.0, float g=1.0, float b=1.0, float a=1.0);
27
28                 // Finishes rendering a frame, and presents it on the screen.
29                 void Present();
30
31                 // Get the current width/height of the window's viewport.
32                 int ViewportWidth() const { return m_viewport_width; }
33                 int ViewportHeight() const { return m_viewport_height; }
34                 
35                 // Debug Font handling
36                 void DebugFontInit(const char *font_name, float font_size = 12);
37                 void DebugFontClear();
38                 void DebugFontPrint(const char *str);
39                 void DebugFontPrintF(const char *fmt, ...);
40                 
41                 // Handle mouse input.
42                 typedef std::function<void(int x, int y, int button, int wheel)> MouseHandler;
43                 void SetMouseHandler(MouseHandler handler)
44                 {
45                         m_mouse_handler = handler;
46                 }
47                 
48                 enum MouseCursors
49                 {
50                         CursorArrow,
51                         CursorWait,
52                         CursorWaitArrow,
53                         CursorMove,
54                         CursorHand
55                 };
56                 void SetMouseCursor(MouseCursors cursor);
57
58                 void ScreenShot(const char * filename) const;
59                 void RenderBMP(const char * filename) const;
60         private:
61                 void ResizeViewport(int width, int height);
62                 
63                 MouseHandler m_mouse_handler;
64                 int m_last_mouse_x;
65                 int m_last_mouse_y;
66
67                 int m_viewport_width;
68                 int m_viewport_height;
69                 SDL_Window *m_window;
70                 SDL_GLContext m_gl_context;
71                 stbtt_bakedchar m_debug_font_rects[96];
72                 unsigned int m_debug_font_atlas;
73                 float m_debug_font_x;
74                 float m_debug_font_y;
75                 float m_debug_font_size;
76         };
77
78 }
79
80 #endif // _SCREEN_H

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