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

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