#include "Window.h" #include "ErrorHandler.h" #include #include void Window::Draw(std::function f){ while(Running){ Running = f(this); SDL_RenderClear(ren); SDL_RenderPresent(ren); Events(); } } void Window::Events(){ while(SDL_PollEvent(e)){ if(e->type == SDL_QUIT){ Running = false; } if(e->type == SDL_KEYDOWN){ switch(e->key.keysym.sym){ case SDLK_a: Running = false; break; } } } } Window::Window(std::string title, int width, int height) : Running(true) { if(SDL_Init(SDL_INIT_VIDEO) != 0){ ErrorHandler::send(ErrorType::SDL_ERROR, "SDL_Init"); } win = SDL_CreateWindow("test", 0,0, width, height, SDL_WINDOW_SHOWN); if(win == NULL){ ErrorHandler::send(ErrorType::SDL_ERROR, "SDL_CreateWindow"); } ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_SOFTWARE); if(ren == NULL){ ErrorHandler::send(ErrorType::SDL_ERROR, "SDL_CreateRenderer"); } } Window::~Window(){ SDL_DestroyWindow(win); SDL_DestroyRenderer(ren); SDL_Quit(); } SDL_Renderer* Window::GetRenderer(){ return ren; }