From e6d695c83c83db687c49492f4d646f01b3752b0f Mon Sep 17 00:00:00 2001 From: Imagment Date: Sat, 5 Apr 2025 20:19:24 +0900 Subject: [PATCH 1/5] Update SilverSpriteRendering.cpp --- src/SilverSpriteRendering.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/SilverSpriteRendering.cpp b/src/SilverSpriteRendering.cpp index b95467b..dba5477 100755 --- a/src/SilverSpriteRendering.cpp +++ b/src/SilverSpriteRendering.cpp @@ -367,5 +367,18 @@ void SpriteRenderer::setShape(std::string target) { ansiExtracted = ExtractAnsi(shape); } +void SpriteRenderer::alignShapeTo(double align) { + if (align < 0.0) align = 0.0; + if (align > 1.0) align = 1.0; + 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'; + } + cleanShape = alignedShape.str(); +} From d42021303620dd4765482b1dc6ae3a2bf6e0a2c9 Mon Sep 17 00:00:00 2001 From: imagment Date: Sun, 6 Apr 2025 02:15:28 -0400 Subject: [PATCH 2/5] Fixed sprite rendering logic --- include/Silver.hpp | 6 +++--- src/SilverCamera.cpp | 10 +++++----- src/SilverSpriteRendering.cpp | 16 +++++++--------- src/main.cpp | 31 +++++++++++++++++++------------ 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/include/Silver.hpp b/include/Silver.hpp index 8b075c0..fa08df5 100755 --- a/include/Silver.hpp +++ b/include/Silver.hpp @@ -105,7 +105,7 @@ class SpriteRenderer : public Component { setShape(newShape); cleanShape = newShape; - useRelativePivot = false; + useRelativePivot = true; pivotFactor = Vector2(0.5f, 0.5f); // Default pivot factor } @@ -141,7 +141,7 @@ class SpriteRenderer : public Component { std::string getShape(); void setShape(std::string target); void alignShapeTo(double align); - bool useRelativePivot = false; + bool useRelativePivot = true; Vector2 pivot = Vector2(0, 0); Vector2 pivotFactor = Vector2(0.5, 0.5); @@ -199,7 +199,7 @@ class SpriteRenderer : public Component { } private: - Vector2 RotatePoint(int column, int 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 = ""; int spriteHeight = 0; 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 dba5477..dc1e7bb 100755 --- a/src/SilverSpriteRendering.cpp +++ b/src/SilverSpriteRendering.cpp @@ -132,7 +132,7 @@ Vector2 SpriteRenderer::GetSize() { -Vector2 SpriteRenderer::RotatePoint(int column, int line) { +Vector2 SpriteRenderer::RotatePoint(double column, double line) { Vector2 pivot = this->GetPivot(); int height = 0, width = 0; @@ -355,16 +355,14 @@ std::string SpriteRenderer::getShape() { void SpriteRenderer::setShape(std::string target) { shape = target; cleanShape = StripAnsi(ProcessMarkdown(shape)); - spriteHeight = 0; - spriteWidth = 0; + std::string line; ss.str(cleanShape); - while (std::getline(ss, line, '\n')) { - spriteHeight++; - spriteWidth = std::max(spriteWidth, static_cast(line.size())); - } - - ansiExtracted = ExtractAnsi(shape); + ansiExtracted = ExtractAnsi(ProcessMarkdown(shape)); + + Vector2 size = GetSize(); + spriteHeight = size.y; + spriteWidth = size.x; } void SpriteRenderer::alignShapeTo(double align) { diff --git a/src/main.cpp b/src/main.cpp index 8319f89..04e4716 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,23 @@ #include "Silver.hpp" -#include -#include -#include int main() { - // Use std::shared_ptr for c1 to ensure shared_from_this works - SPActor c1 = std::make_shared(); - c1->AddComponent(); - - SPActor test = std::make_shared("test", "1"); - Rectangle(test, Rect(0,0,5,5), 0); - c1->GetComponent()->RenderFrame(); - Hold(); - return 0; + + Actor c1; + + c1.AddComponent(); + + Actor actor("alert", "Hello World!"); + + actor.GetComponent()->position = Vector3Zero; + + actor.GetComponent()->scale = Vector3(1,1,1); + + actor.AddObject(); + + c1.GetComponent()->RenderFrame(); + + Hold(); + + return 0; + } From 8b3aeab30f57844156dc60ab13d37249e97b03ea Mon Sep 17 00:00:00 2001 From: imagment Date: Sun, 6 Apr 2025 04:58:28 -0400 Subject: [PATCH 3/5] Fixed align function --- src/SilverSpriteRendering.cpp | 55 +++++++++++++++++++++++++++-------- src/main.cpp | 4 +-- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/SilverSpriteRendering.cpp b/src/SilverSpriteRendering.cpp index dc1e7bb..8dd0e0e 100755 --- a/src/SilverSpriteRendering.cpp +++ b/src/SilverSpriteRendering.cpp @@ -356,7 +356,6 @@ void SpriteRenderer::setShape(std::string target) { shape = target; cleanShape = StripAnsi(ProcessMarkdown(shape)); - std::string line; ss.str(cleanShape); ansiExtracted = ExtractAnsi(ProcessMarkdown(shape)); @@ -366,17 +365,49 @@ void SpriteRenderer::setShape(std::string target) { } 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 04e4716..d156f71 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,12 +6,12 @@ int main() { c1.AddComponent(); - Actor actor("alert", "Hello World!"); + Actor actor("alert", "Hello World!\na"); actor.GetComponent()->position = Vector3Zero; actor.GetComponent()->scale = Vector3(1,1,1); - + actor.GetComponent()->alignShapeTo(1); actor.AddObject(); c1.GetComponent()->RenderFrame(); From 1cb691636463f3eaf0e5540b029675c567971732 Mon Sep 17 00:00:00 2001 From: imagment Date: Mon, 14 Apr 2025 09:50:40 -0400 Subject: [PATCH 4/5] Resolved conflicts --- src/main.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d156f71..847b39b 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,23 +1,18 @@ #include "Silver.hpp" int main() { + Actor c1; + c1.AddComponent(); - Actor c1; + Actor actor("alert", "This is your first window\nSILVER!"); + + actor.GetComponent()->position = Vector3Zero; + //actor.GetComponent()->alignShapeTo(1.0f); - c1.AddComponent(); + actor.AddObject(); - Actor actor("alert", "Hello World!\na"); - - actor.GetComponent()->position = Vector3Zero; - - actor.GetComponent()->scale = Vector3(1,1,1); - actor.GetComponent()->alignShapeTo(1); - actor.AddObject(); - - c1.GetComponent()->RenderFrame(); - - Hold(); - - return 0; + c1.GetComponent()->StartVideo(); + Hold(); + return 0; } From 84c2a362775aaaa483c7809d321c7d03dd4d07d5 Mon Sep 17 00:00:00 2001 From: Imagment Date: Thu, 17 Apr 2025 08:20:03 +0900 Subject: [PATCH 5/5] Update README.md --- README.md | 4 ---- 1 file changed, 4 deletions(-) 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