diff --git a/README.md b/README.md index f05060c..747dc18 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,6 @@ cmake .. make ``` **Important: Compatibility Information**
-<<<<<<< HEAD -Silver C++ is only compatible with **Linux-based** operating systems.
-Windows is *not* supported currently. We are creating another version of Silver C++ that supports Windows. -======= **Silver C++** is compatible with both **Linux-based** and **Windows-based** operating systems. For **Windows** users, you can use the [Silver Windows Edition](https://github.com/imagment/Silver-Windows-Edition/tree/dev). >>>>>>> dev diff --git a/include/Silver.hpp b/include/Silver.hpp index 812f519..e4e16a8 100755 --- a/include/Silver.hpp +++ b/include/Silver.hpp @@ -202,7 +202,8 @@ class SpriteRenderer : public Component { double spriteHeight; double spriteWidth; private: - Vector2 RotatePoint(double column, double line); // Helper function to rotate around the pivot + Vector2 RotatePoint(double column, double line); //Helper function to rotate around the pivot + std::string shape = ""; std::string cleanShape = ""; diff --git a/src/SilverCamera.cpp b/src/SilverCamera.cpp index 4fb75b0..9255fd7 100755 --- a/src/SilverCamera.cpp +++ b/src/SilverCamera.cpp @@ -157,9 +157,8 @@ void Camera::RenderFrame() { if (consoleWidth > maxLeftWidth + maxRightWidth + cameraScale.x) cameraScale -= maxLeftWidth + maxRightWidth; if (consoleHeight > topTextLinesCount + bottomTextLinesCount + cameraScale.y) cameraScale -= topTextLinesCount + bottomTextLinesCount; - - if (cameraScale.x == 0 || cameraScale.y == 0 || - cameraScale.z == 0) + if(!cameraScale.z) cameraScale.z = 1; + if (cameraScale.x == 0 || cameraScale.y == 0) return; // Detect console scale changes @@ -271,8 +270,9 @@ void Camera::RenderFrame() { cameraScale.z == 0) continue; - if (scale.x == 0.0f || scale.y == 0.0f || scale.z == 0.0f) continue; - + if (scale.x == 0.0f || scale.y == 0.0f) continue; + if(scale.z == 0.0f) scale.z = 1; + // Check if the object is part of UI or SpriteRenderer if (obj->GetComponent() != nullptr) { location.x = round(obj->GetComponent()->position.x + position.x - abs(cameraScale.x) / 2); diff --git a/src/SilverSpriteRendering.cpp b/src/SilverSpriteRendering.cpp index 2438e72..01eb736 100755 --- a/src/SilverSpriteRendering.cpp +++ b/src/SilverSpriteRendering.cpp @@ -135,43 +135,36 @@ Vector2 SpriteRenderer::GetSize() { } - Vector2 SpriteRenderer::RotatePoint(double column, double line) { - Vector2 pivot = this->GetPivot(); - int height = 0, width = 0; - - std::string l; - while (std::getline(ss, l, '\n')) { - height++; - width = std::max(width, static_cast(l.size())); - } - if (useRelativePivot) { - pivot = Vector2( - static_cast(std::round(this->pivotFactor.x * width)), - static_cast(std::round(this->pivotFactor.y * height)) - ); - } - - auto transform = (parent->GetComponent()); - double rotation = transform->rotation; + Vector2 pivot = this->GetPivot(); + int height = 0, width = 0; + + std::string l; + while (std::getline(ss, l, '\n')) { + height++; + width = std::max(width, static_cast(l.size())); + } + if(useRelativePivot) pivot = Vector2(static_cast(std::round(this->pivotFactor.x * width)), static_cast(std::round(this->pivotFactor.y * height))); + + auto transform = (parent->GetComponent()); - // Relative position to pivot (in double) - double localX = column - pivot.x; - double localY = line - pivot.y; + double rotation = transform->rotation; + // Calculate local coordinates relative to the pivot + int localX = column - pivot.x; + int localY = line - pivot.y; - // Rotation (clockwise) - double radians = rotation * (M_PI / 180.0); - double rotatedX = localX * cos(radians) - localY * sin(radians); - double rotatedY = localX * sin(radians) + localY * cos(radians); + // Apply clockwise rotation (negative angle for clockwise rotation) + double radians = rotation * (M_PI / 180.0f); // Negative for clockwise + int rotatedX = round(localX * cos(radians) - localY * sin(radians)); + int rotatedY = round(localX * sin(radians) + localY * cos(radians)); - // Add pivot back - rotatedX += pivot.x; - rotatedY += pivot.y; + // Re-adjust for the pivot's fixed position after transformation + rotatedX += pivot.x; + rotatedY += pivot.y; - return Vector2(static_cast(std::round(rotatedX)), static_cast(std::round(rotatedY))); + return Vector2(rotatedX, rotatedY); } - std::tuple SpriteRenderer::CalculatePivotExpansion() { Vector2 pivot = this->GetPivot(); std::string shape = this->shape; @@ -363,28 +356,58 @@ std::string SpriteRenderer::getShape() { void SpriteRenderer::setShape(std::string target) { shape = target; cleanShape = StripAnsi(ProcessMarkdown(shape)); - ss.str(cleanShape); - Vector2 size = GetSize(); - this->spriteHeight = size.y; - this->spriteWidth = size.x; + ss.str(cleanShape); ansiExtracted = ExtractAnsi(ProcessMarkdown(shape)); + + Vector2 size = GetSize(); + spriteHeight = size.y; + spriteWidth = size.x; } - void SpriteRenderer::alignShapeTo(double align) { - if (align < 0.0) align = 0.0; - if (align > 1.0) align = 1.0; + align = std::clamp(align, 0.0, 1.0); + + int spriteWidth = 0; + { + std::stringstream temp(cleanShape); + std::string line; + while (std::getline(temp, line, '\n')) { + spriteWidth = std::max(spriteWidth, static_cast(line.size())); + } + } - std::stringstream alignedShape; - std::string line; - std::stringstream ss(cleanShape); - - while (std::getline(ss, line, '\n')) { - int padding = static_cast((spriteWidth - line.size()) * align); - alignedShape << std::string(padding, ' ') << line << '\n'; + std::stringstream alignedClean; + std::vector> alignedAnsi; + + { + std::stringstream shapeStream(cleanShape); + std::string line; + size_t lineIndex = 0; + + while (std::getline(shapeStream, line, '\n')) { + int padding = static_cast((spriteWidth - line.size()) * align); + alignedClean << std::string(padding, ' ') << line << '\n'; + + if (lineIndex < ansiExtracted.size()) { + const std::vector& ansiLine = ansiExtracted[lineIndex]; + std::vector paddedAnsi; + + // Add empty strings as padding on the left + paddedAnsi.resize(padding, ""); + + // Copy original line + paddedAnsi.insert(paddedAnsi.end(), ansiLine.begin(), ansiLine.end()); + + alignedAnsi.push_back(std::move(paddedAnsi)); + } + + ++lineIndex; + } } - - cleanShape = alignedShape.str(); + + cleanShape = alignedClean.str(); + ss = std::stringstream(cleanShape); + ansiExtracted = std::move(alignedAnsi); } diff --git a/src/main.cpp b/src/main.cpp index fd2bcef..8f47496 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,15 +3,14 @@ int main() { Actor c1; c1.AddComponent(); - - Actor actor("alert"); - - actor.GetComponent()->scale = Vector3Zero; - actor.AddComponent()->setShape("This is your first window!"); + Actor actor("alert", "This is your first window\nSILVER!"); + + actor.GetComponent()->position = Vector3Zero; actor.AddObject(); - c1.GetComponent()->RenderFrame(); + c1.GetComponent()->StartVideo(); + Hold(); return 0; }