// ----------------------------------------------------------------------------- // https://dataswamp.org/~incal/emacs-init/draw/new.c // ----------------------------------------------------------------------------- #include "new.h" #include #include #include #include // ----------------------------------------------------------------------------- void delay (Uint64 to) { Uint64 now = SDL_GetTicks64(); if (now < to) { SDL_Delay(to - now); } } /* ----------------------------------------------------------------------------- */ SDL_Renderer* new_renderer(SDL_Window* win) { SDL_Renderer* rend = SDL_CreateRenderer(win, -1, SDL_RENDERER_SOFTWARE); if (!rend) { printf("[renderer] error\n"); exit(EXIT_FAILURE); } return rend; } SDL_Surface* new_screen(SDL_Window* win) { SDL_Surface* screen = SDL_GetWindowSurface(win); if (!screen) { printf("[screen] error\n"); exit(EXIT_FAILURE); } return screen; } SDL_Surface* new_surface(int w, int h) { SDL_Surface* sur = SDL_CreateRGBSurface(0, w, h, 32, 0, 0, 0, 0); if (!sur) { printf("[surface] error\n"); exit(EXIT_FAILURE); } return sur; } SDL_Thread* new_thread(char* name, SDL_ThreadFunction fun) { SDL_Thread* thr = SDL_CreateThread(fun, name, NULL); if (!thr) { printf("[thread] error\n"); exit(EXIT_FAILURE); } return thr; } SDL_Window* new_window(char* name, int w, int h) { int pos = SDL_WINDOWPOS_CENTERED; SDL_Window* win = SDL_CreateWindow(name, pos, pos, w, h, SDL_WINDOW_SHOWN); if (!win) { printf("[window] error\n"); exit(EXIT_FAILURE); } return win; } SDL_mutex* new_mutex() { SDL_mutex* mtx = SDL_CreateMutex(); if (!mtx) { printf("[mutex] error\n"); exit(EXIT_FAILURE); } return mtx; } TTF_Font* new_font (const char* font_file, int size) { TTF_Font* fnt = TTF_OpenFont(font_file, size); if (!fnt) { printf("[font] error\n"); exit(EXIT_FAILURE); } return fnt; }