From bf34f891c5c09e6c8a42797085860fa80ab53814 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 24 Feb 2019 13:11:12 -0500 Subject: Editor now renders a tiled background image --- src/editor.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/editor.cpp') diff --git a/src/editor.cpp b/src/editor.cpp index 6e53ac3..92c6b67 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1,4 +1,5 @@ #include "editor.h" +#include "consts.h" void Editor::tick( double dt, @@ -9,5 +10,31 @@ void Editor::tick( void Editor::render(SDL_Renderer* ren) { + if (!background_) + { + surface_ptr bgSurf(IMG_Load("../res/editor_bg.png")); + if (!bgSurf) + { + throw img_error(); + } + + background_.reset(SDL_CreateTextureFromSurface(ren, bgSurf.get())); + bgSize_ = { bgSurf->w, bgSurf->h }; + } + + for (int y = 0; y < WINDOW_SIZE.h() / bgSize_.h(); y++) + { + for (int x = 0; x < WINDOW_SIZE.w() / bgSize_.w(); x++) + { + SDL_Rect rect { + x * bgSize_.w(), + y * bgSize_.h(), + bgSize_.w(), + bgSize_.h() + }; + + SDL_RenderCopy(ren, background_.get(), nullptr, &rect); + } + } } -- cgit 1.4.1