-
Notifications
You must be signed in to change notification settings - Fork 0
/
byteimage_sdl2.h
52 lines (41 loc) · 1.56 KB
/
byteimage_sdl2.h
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
#ifndef _BPJ_BYTEIMAGE_SDL2_H
#define _BPJ_BYTEIMAGE_SDL2_H
#include "byteimage.h"
#include <SDL2/SDL.h>
namespace byteimage {
class Display {
protected:
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Texture* texture;
Uint32* px;
bool exitflag, drawflag;
void init(const ByteImage& img, const char* title);
/*
* These methods can all be overridden.
* In general, you'll want to call the parent
* member function last in the overrides.
* If you want to suppress the default
* texture-overwrites-display behavior,
* set drawflag = 0 in your update function.
*/
virtual void handleEvent(SDL_Event event); //Called per event to respond to UI events
virtual void updateImage(const ByteImage& img); //Call this to update the background texture and set draw flag
virtual void update(); //Override this for per-frame behavior. It is responsible for redraw and timing.
public:
unsigned int frameDelay;
Display(int nr, int nc, const char* title = NULL);
Display(const ByteImage& img, const char* title = NULL);
Display(const Display&) = delete;
Display(Display&& disp);
virtual ~Display();
Display& operator=(const Display&) = delete;
Display& operator=(Display&&);
void setTitle(const char* title);
void main();
int show(const ByteImage& img);//Returns nonzero if exit event is caught
};
void writePixelArray(Uint32* dest, const ByteImage& img);
SDL_Texture* toTexture(SDL_Renderer* renderer, const ByteImage& img);
}
#endif