/* * 2D Game Engine * RenderText.h: * Based on pikuma.com 2D game engine in C++ and Lua course * Copyright (c) 2021 986-Studio. All rights reserved. * * Created by Manoƫl Trapier on 27/02/2021. */ #ifndef GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_RENDERTEXT_H #define GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_RENDERTEXT_H #include #include #include #include #include class RenderTextSystem: public System { public: RenderTextSystem() { this->requireComponent(); } void update(SDL_Renderer *renderer, std::unique_ptr &assetStore, SDL_Rect &camera) { for(auto entity: this->getSystemEntities()) { const auto textLabel = entity.getComponent(); TTF_Font *font = assetStore->getFont(textLabel.fontId); SDL_Surface *surface = TTF_RenderText_Blended(font, textLabel.text.c_str(), textLabel.fgColor); SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface); int labelWidth, labelHeight; SDL_QueryTexture(texture, NULL, NULL, &labelWidth, &labelHeight); SDL_Rect destRect = { static_cast(textLabel.position.x - (textLabel.isFixed?0.:camera.x)), static_cast(textLabel.position.y - (textLabel.isFixed?0.:camera.y)), labelWidth, labelHeight }; SDL_RenderCopyEx(renderer, texture, NULL, &destRect,0, NULL, SDL_FLIP_NONE); SDL_FreeSurface(surface); SDL_DestroyTexture(texture); } } }; #endif /* GAMEENGINE_SOURCE_INCLUDE_SYSTEMS_RENDERTEXT_H */