First Commit
This commit is contained in:
61
Window.cpp
Normal file
61
Window.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "Window.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <iostream>
|
||||
|
||||
void Window::Draw(std::function<bool(Window*)> 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;
|
||||
}
|
||||
Reference in New Issue
Block a user