#include "global.hpp" // Rendering void Renderer::prepareTextures() { const char* paths[] = {"img/circle.png", "img/cross.png"}; for(int i = 0; i < IMG_COUNT; i++) { Image img; img = LoadImage(paths[i]); textures[i] = LoadTextureFromImage(img); } } void Renderer::renderImage(tile t, Rectangle dst, Color color) { if(t == empty || t == tie) return; Texture tex = textures[t-1]; Rectangle src = {0, 0, (float)tex.width, (float)tex.height}; DrawTexturePro(textures[t-1], src, dst, {0,0}, 0, color); } void Renderer::render_block(Block *b) { if(b->depth > 0) DrawRectangleLinesEx(b->place, b->depth, BLACK); renderImage(b->t, b->place); if(b->depth == 0 || (b->t != empty && b->t != tie)) return; for(int i = 0; i < 9; i++) render_block(b->sons[i]); } void Renderer::render_all(Block* root, int time, Rectangle play_area, deque highlight) { BeginDrawing(); ClearBackground(RAYWHITE); render_block(root); if(valid(root, play_area, highlight)) renderImage(act(time), root->getRect(highlight), BLACK); DrawRectangleLinesEx(play_area, 3*LINE_W, col(time+1)); EndDrawing(); } int Renderer::update_board_size(int depth) { int max_size = std::min(GetScreenWidth(), GetScreenHeight()); int size = 1; for(int i = 0; i < depth; i++) size *= 3; max_size -= max_size % size; return max_size; } void Renderer::prepare_screen(Block* root, int time, Rectangle dst) { SetConfigFlags(FLAG_WINDOW_RESIZABLE); InitWindow(SCREEN, SCREEN, "Rekurze"); SetTargetFPS(FPS); prepareTextures(); render_all(root, time, dst); }