Skip to content
Open

Dev #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ cmake ..
make
```
**Important: Compatibility Information** <br>
<<<<<<< HEAD
Silver C++ is only compatible with **Linux-based** operating systems. <br>
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
Expand Down
3 changes: 2 additions & 1 deletion include/Silver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down
10 changes: 5 additions & 5 deletions src/SilverCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<UI>() != nullptr) {
location.x = round(obj->GetComponent<Transform>()->position.x + position.x - abs(cameraScale.x) / 2);
Expand Down
115 changes: 69 additions & 46 deletions src/SilverSpriteRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(l.size()));
}
if (useRelativePivot) {
pivot = Vector2(
static_cast<int>(std::round(this->pivotFactor.x * width)),
static_cast<int>(std::round(this->pivotFactor.y * height))
);
}

auto transform = (parent->GetComponent<Transform>());
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<int>(l.size()));
}
if(useRelativePivot) pivot = Vector2(static_cast<int>(std::round(this->pivotFactor.x * width)), static_cast<int>(std::round(this->pivotFactor.y * height)));

auto transform = (parent->GetComponent<Transform>());

// 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<int>(std::round(rotatedX)), static_cast<int>(std::round(rotatedY)));
return Vector2(rotatedX, rotatedY);
}


std::tuple<int, int, int, int> SpriteRenderer::CalculatePivotExpansion() {
Vector2 pivot = this->GetPivot();
std::string shape = this->shape;
Expand Down Expand Up @@ -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<int>(line.size()));
}
}

std::stringstream alignedShape;
std::string line;
std::stringstream ss(cleanShape);

while (std::getline(ss, line, '\n')) {
int padding = static_cast<int>((spriteWidth - line.size()) * align);
alignedShape << std::string(padding, ' ') << line << '\n';
std::stringstream alignedClean;
std::vector<std::vector<std::string>> alignedAnsi;

{
std::stringstream shapeStream(cleanShape);
std::string line;
size_t lineIndex = 0;

while (std::getline(shapeStream, line, '\n')) {
int padding = static_cast<int>((spriteWidth - line.size()) * align);
alignedClean << std::string(padding, ' ') << line << '\n';

if (lineIndex < ansiExtracted.size()) {
const std::vector<std::string>& ansiLine = ansiExtracted[lineIndex];
std::vector<std::string> 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);
}

11 changes: 5 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
int main() {
Actor c1;
c1.AddComponent<Camera>();

Actor actor("alert");

actor.GetComponent<Transform>()->scale = Vector3Zero;
actor.AddComponent<SpriteRenderer>()->setShape("This is your first window!");
Actor actor("alert", "This is your first window\n<red>SILVER!</red>");

actor.GetComponent<Transform>()->position = Vector3Zero;

actor.AddObject();

c1.GetComponent<Camera>()->RenderFrame();
c1.GetComponent<Camera>()->StartVideo();
Hold();

return 0;
}