-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain_window.h
More file actions
91 lines (74 loc) · 1.72 KB
/
main_window.h
File metadata and controls
91 lines (74 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Copyright (c) 2019 Ajay Sreedhar
*
* Distributed under MIT License. Please refer the LICENCE file.
*/
#ifndef EXAMPLE_MAIN_WINDOW_H
#define EXAMPLE_MAIN_WINDOW_H
#include <string>
#include <stdexcept>
/* Simple Direct Media Layer to manipulate graphics. */
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
namespace nsdl {
/**
* SDL2 members and methods under a hood.
*/
class MainWindow {
private:
/**
* Flag to determine animation is required or not.
*/
bool shouldAnimate = true;
/**
* The window width.
*/
int width;
/**
* THe window height.
*/
int height;
/**
* Holds an instance of the SDL2 window created.
*/
SDL_Window* window;
/**
* Holds the hardware accelerated window renderer.
*/
SDL_Renderer* renderer;
/**
* Holds the loaded image texture.
*/
SDL_Texture* image {};
/**
* Holds a plain black texture.
*/
SDL_Texture* blank {};
public:
/**
* Creates a window of specified width and height.
*
* @param width the window width
* @param height the window height
* @throws std::runtime_error if window init fails
*/
MainWindow (int width, int height);
/**
* Stops animation.
*/
void stopAnimation ();
/**
* Performs a hardware accelerated rendering of the image texture
* directly on the main window texture and blinks the image.
*
* @param file the absolute path to image file
* @return 1 if blit succeeds, 0 otherwise
*/
int blinkImage (const std::string* file);
/**
* Runs the window. Awaits events.
*/
bool watch ();
};
} /* namespace nsdl */
#endif /* EXAMPLE_MAIN_WINDOW_H */