50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
|
//
|
||
|
// Application.hpp
|
||
|
// libscgui
|
||
|
//
|
||
|
// Created by Bob Polis at 2020-10-23
|
||
|
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#ifndef _Application_H_
|
||
|
#define _Application_H_
|
||
|
|
||
|
#include <SDL2/SDL.h>
|
||
|
#include <map>
|
||
|
#include <vector>
|
||
|
|
||
|
namespace sc {
|
||
|
namespace gui {
|
||
|
using EventHandler = bool(*)(const SDL_Event&);
|
||
|
|
||
|
class Application {
|
||
|
public:
|
||
|
static Application& instance() { return app; }
|
||
|
|
||
|
Application() = default;
|
||
|
~Application() = default;
|
||
|
|
||
|
// prohibit copying and moving
|
||
|
Application(const Application&) = delete;
|
||
|
Application& operator=(const Application&) = delete;
|
||
|
Application(Application&&) = delete;
|
||
|
Application& operator=(Application&&) = delete;
|
||
|
|
||
|
void run();
|
||
|
void add_event_handler(EventHandler handler, SDL_EventType event);
|
||
|
|
||
|
private:
|
||
|
static Application app;
|
||
|
|
||
|
std::map<SDL_EventType, std::vector<EventHandler>> _event_handlers;
|
||
|
|
||
|
bool handle_event(const SDL_Event& event);
|
||
|
};
|
||
|
|
||
|
// convenience function
|
||
|
Application& app() { return Application::instance(); }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif // _Application_H_
|