#include "util.h" #include #include #include "mazeoflife.h" #include "sdl.h" void wrap(int& x, int& y) { if (x < 0) { x = WIDTH + x; } else if (x >= WIDTH) { x = x - WIDTH; } if (y < 0) { y = HEIGHT + y; } else if (y >= HEIGHT) { y = y - HEIGHT; } } font_ptr loadFont(int size) { font_ptr font = font_ptr(TTF_OpenFont("resources/mono.ttf", size)); if (!font) { throw ttf_error(); } return font; } std::string getDataFile() { #ifdef WINDOWS char* dir = getenv("USERPROFILE"); #else char* dir = getenv("HOME"); #endif return std::string(std::filesystem::path(dir) / ".molhslist"); } texture_ptr loadImage(SDL_Renderer* renderer, std::string file) { surface_ptr surface = surface_ptr(SDL_LoadBMP(file.c_str())); if (!surface) { throw sdl_error(); } return texture_ptr(SDL_CreateTextureFromSurface(renderer, surface.get())); } void applyTexture(SDL_Renderer* renderer, SDL_Texture* tex, int x, int y) { SDL_Rect pos; pos.x = x; pos.y = y; SDL_QueryTexture(tex, NULL, NULL, &pos.w, &pos.h); SDL_RenderCopy(renderer, tex, NULL, &pos); }