diff --git a/Slang/graphics.h b/Slang/graphics.h index ea6a8e6..857afab 100644 --- a/Slang/graphics.h +++ b/Slang/graphics.h @@ -484,6 +484,145 @@ public: SDL_Texture* texture; }; +class Text +{ +public: + Text(std::string path, Vec2 position, Vec2 scale, double angle) + : position(position), angle(angle), path(path), scale(scale) + { + rect.x = static_cast(position.x); + rect.y = static_cast(position.y); + rect.w = scale.x; + rect.h = scale.y; + + Load(); + } + + int Load() + { + SDL_Surface* surface = loadSurface(path); + texture = SDL_CreateTextureFromSurface(gRenderer, surface); + SDL_FreeSurface(surface); + return 0; + } + + int Draw() + { + rect.x = static_cast(position.x); + rect.y = static_cast(position.y); + SDL_RenderCopy(gRenderer, texture, NULL, &rect); + return 0; + } + + boost::any SubComponent(std::string componentName) + { + if (componentName == "position") + return position; + if (componentName == "position.x") + return position.x; + if (componentName == "position.y") + return position.y; + if (componentName == "scale") + return scale; + if (componentName == "scale.x") + return scale.x; + if (componentName == "scale.y") + return scale.y; + } + + Sprite EditSubComponent(std::string componentName, std::string oper, boost::any otherVal) + { + if (componentName == "position") + { + if (oper == "=") + position = any_cast(otherVal); + else if (oper == "+=") + position += any_cast(otherVal); + else if (oper == "-=") + position -= any_cast(otherVal); + else if (oper == "*=") + position *= AnyAsFloat(otherVal); + else if (oper == "/=") + position /= AnyAsFloat(otherVal); + } + else if (componentName == "position.x") + { + if (oper == "=") + position.x = AnyAsFloat(otherVal); + else if (oper == "+=") + position.x += AnyAsFloat(otherVal); + else if (oper == "-=") + position.x -= AnyAsFloat(otherVal); + else if (oper == "*=") + position.x *= AnyAsFloat(otherVal); + else if (oper == "/=") + position.x /= AnyAsFloat(otherVal); + } + else if (componentName == "position.y") + { + if (oper == "=") + position.y = AnyAsFloat(otherVal); + else if (oper == "+=") + position.y += AnyAsFloat(otherVal); + else if (oper == "-=") + position.y -= AnyAsFloat(otherVal); + else if (oper == "*=") + position.y *= AnyAsFloat(otherVal); + else if (oper == "/=") + position.y /= AnyAsFloat(otherVal); + } + + else if (componentName == "scale") + { + if (oper == "=") + scale = any_cast(otherVal); + else if (oper == "+=") + scale += any_cast(otherVal); + else if (oper == "-=") + scale -= any_cast(otherVal); + else if (oper == "*=") + scale *= AnyAsFloat(otherVal); + else if (oper == "/=") + scale /= AnyAsFloat(otherVal); + } + else if (componentName == "scale.x") + { + if (oper == "=") + scale.x = AnyAsFloat(otherVal); + else if (oper == "+=") + scale.x += AnyAsFloat(otherVal); + else if (oper == "-=") + scale.x -= AnyAsFloat(otherVal); + else if (oper == "*=") + scale.x *= AnyAsFloat(otherVal); + else if (oper == "/=") + scale.x /= AnyAsFloat(otherVal); + } + else if (componentName == "scale.y") + { + if (oper == "=") + scale.y = AnyAsFloat(otherVal); + else if (oper == "+=") + scale.y += AnyAsFloat(otherVal); + else if (oper == "-=") + scale.y -= AnyAsFloat(otherVal); + else if (oper == "*=") + scale.y *= AnyAsFloat(otherVal); + else if (oper == "/=") + scale.y /= AnyAsFloat(otherVal); + } + return *this; + } + + Vec2 position; + Vec2 scale; + double angle; + + std::string path; + SDL_Rect rect{}; + SDL_Texture* texture; +}; + int cleanupGraphics() { // Cleanup