// // Window.hpp // gui // // Created by Bob Polis at 2020-10-14 // Copyright (c) 2020 SwiftCoder. All rights reserved. // #ifndef __WINDOW_H_ #define __WINDOW_H_ #include #include #include #include #include #include namespace sc { namespace gui { using WindowEventHandler = bool(*)(const SDL_Event&, bool quit); class Window { public: static std::vector& windows() { return _windows; } static bool handle_window_event(const SDL_Event& event); static bool handle_global_event(const SDL_Event& event); static void add_global_event_handler(WindowEventHandler handler, SDL_WindowEventID type); static Window* from_sdl(Uint32 window_id); Window(const char* title); void add_event_handler(WindowEventHandler handler, SDL_WindowEventID type); bool handle_event(const SDL_Event& event, bool quit); SDL_Window* get_window() const { return _w.get(); } void set_size(int w, int h); void update() const; void load_image(); private: static std::vector _windows; static std::map> _global_event_handlers; std::string _title; std::unique_ptr _w {nullptr, SDL_DestroyWindow}; std::unique_ptr _r {nullptr, SDL_DestroyRenderer}; std::unique_ptr _t {nullptr, SDL_DestroyTexture}; std::map> _event_handlers; }; } } #endif // __WINDOW_H_