summaryrefslogtreecommitdiff
path: root/ui/window.h
blob: 9c6d023211a847479602d3c7950b7f5a2169145f (plain)
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
#ifndef DISPLAY_INCLUDED_H
#define DISPLAY_INCLUDED_H

#include "chronology.hpp"
#include "collection.hpp"
#include "gfx/gl/uiShader.h"
#include "inputHandler.h" // IWYU pragma: keep
#include "ptr.hpp"
#include <SDL2/SDL.h>
#include <special_members.hpp>
#include <string>
#include <type_traits>

class GameState;

class Window {
public:
	Window(size_t width, size_t height, const std::string & title);
	virtual ~Window() = default;

	NO_COPY(Window);
	NO_MOVE(Window);

	virtual void tick(TickDuration elapsed) = 0;
	void refresh(const GameState *) const;
	bool handleInput(const SDL_Event & e);

	void clear(float r, float g, float b, float a) const;
	void swapBuffers() const;

protected:
	SDL_GLContext glContext() const;
	virtual void render(const GameState *) const;

	using SDL_WindowPtr = wrapped_ptrt<SDL_Window, SDL_CreateWindow, SDL_DestroyWindow>;
	SDL_WindowPtr m_window;
	Collection<InputHandler> inputStack;
	UIShader uiShader;
};

#endif