emptied textcomponent for rewriting

This commit is contained in:
2025-07-14 00:36:57 +02:00
parent f2958fa9fa
commit 1060809f22
11 changed files with 14 additions and 45 deletions

Binary file not shown.

View File

@ -60,7 +60,7 @@
"RelativeDocumentMoniker": "src\\game\\components\\TextComponent.cpp",
"ToolTip": "C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\game\\components\\TextComponent.cpp",
"RelativeToolTip": "src\\game\\components\\TextComponent.cpp",
"ViewState": "AgIAAAAAAAAAAAAAAAAAABAAAAAPAAAAAAAAAA==",
"ViewState": "AgIAAAAAAAAAAAAAAAAAABkAAAAAAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2025-07-13T20:09:50.139Z",
"EditorCaption": ""

View File

@ -6,6 +6,10 @@
"AbsoluteMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\game\\components\\TextComponent.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|solutionrelative:src\\game\\components\\TextComponent.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
},
{
"AbsoluteMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\core\\Engine.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|solutionrelative:src\\core\\Engine.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
},
{
"AbsoluteMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\core\\Engine.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|solutionrelative:src\\core\\Engine.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
@ -18,10 +22,6 @@
"AbsoluteMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\game\\components\\Component.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|solutionrelative:src\\game\\components\\Component.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
},
{
"AbsoluteMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\core\\Engine.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|solutionrelative:src\\core\\Engine.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
},
{
"AbsoluteMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\game\\components\\TransformComponent.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{5653811A-38D1-4D9D-9446-A417E8557584}|ShadowCrestGameEngine.vcxproj|solutionrelative:src\\game\\components\\TransformComponent.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
@ -60,7 +60,7 @@
"RelativeDocumentMoniker": "src\\game\\components\\TextComponent.cpp",
"ToolTip": "C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\game\\components\\TextComponent.cpp",
"RelativeToolTip": "src\\game\\components\\TextComponent.cpp",
"ViewState": "AgIAAAAAAAAAAAAAAAAAABkAAAAAAAAAAAAAAA==",
"ViewState": "AgIAAAAAAAAAAAAAAAAAABIAAAA5AAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2025-07-13T20:09:50.139Z",
"EditorCaption": ""
@ -79,7 +79,7 @@
},
{
"$type": "Document",
"DocumentIndex": 3,
"DocumentIndex": 4,
"Title": "Component.hpp",
"DocumentMoniker": "C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\game\\components\\Component.hpp",
"RelativeDocumentMoniker": "src\\game\\components\\Component.hpp",
@ -87,12 +87,11 @@
"RelativeToolTip": "src\\game\\components\\Component.hpp",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAAAZAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
"WhenOpened": "2025-07-13T19:24:03.306Z",
"EditorCaption": ""
"WhenOpened": "2025-07-13T19:24:03.306Z"
},
{
"$type": "Document",
"DocumentIndex": 2,
"DocumentIndex": 3,
"Title": "TextComponent.hpp",
"DocumentMoniker": "C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\game\\components\\TextComponent.hpp",
"RelativeDocumentMoniker": "src\\game\\components\\TextComponent.hpp",
@ -100,12 +99,11 @@
"RelativeToolTip": "src\\game\\components\\TextComponent.hpp",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAwAAAAZAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
"WhenOpened": "2025-07-13T19:18:06.662Z",
"EditorCaption": ""
"WhenOpened": "2025-07-13T19:18:06.662Z"
},
{
"$type": "Document",
"DocumentIndex": 1,
"DocumentIndex": 2,
"Title": "Engine.cpp",
"DocumentMoniker": "C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\core\\Engine.cpp",
"RelativeDocumentMoniker": "src\\core\\Engine.cpp",
@ -113,8 +111,7 @@
"RelativeToolTip": "src\\core\\Engine.cpp",
"ViewState": "AgIAAEsAAAAAAAAAAAAAAFkAAAAAAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2025-07-13T18:23:56.384Z",
"EditorCaption": ""
"WhenOpened": "2025-07-13T18:23:56.384Z"
}
]
}
@ -139,7 +136,7 @@
"Children": [
{
"$type": "Document",
"DocumentIndex": 4,
"DocumentIndex": 1,
"Title": "Engine.hpp",
"DocumentMoniker": "C:\\Users\\steev\\Desktop\\ShadowCrestGameEngine\\src\\core\\Engine.hpp",
"RelativeDocumentMoniker": "src\\core\\Engine.hpp",

View File

@ -1,48 +1,20 @@
#include "TextComponent.hpp"
#include <SDL3_ttf/SDL_ttf.h>
TextComponent::TextComponent(const std::string& text, const std::string& fontPath, int fontSize, SDL_Color color)
: text(text), fontPath(fontPath), fontSize(fontSize), color(color) {
TextComponent::TextComponent(const std::string& text, const std::string& fontPath, int fontSize, SDL_Color color) : text(text), fontPath(fontPath), fontSize(fontSize), color(color) {
}
TextComponent::~TextComponent() {
if (texture) SDL_DestroyTexture(texture);
if (font) TTF_CloseFont(font);
}
void TextComponent::Init(SDL_Renderer* renderer) {
font = TTF_OpenFont(fontPath.c_str(), fontSize);
if (!font) {
SDL_Log("Failed to load font: %s", SDL_GetError());
return;
}
// TODO: implement a way to resize
SDL_Surface* surface = TTF_RenderText_Blended(font, text.c_str(), 10, color);
if (!surface) {
SDL_Log("Failed to render text surface: %s", SDL_GetError());
return;
}
texture = SDL_CreateTextureFromSurface(renderer, surface);
destRect = { 0, 0, (float)surface->w, (float)surface->h };
SDL_DestroySurface(surface);
}
void TextComponent::Update(float dt) {
// nothing dynamic for now
}
void TextComponent::Render(SDL_Renderer* renderer) {
if (texture) {
SDL_RenderTexture(renderer, texture, nullptr, &destRect);
}
}
void TextComponent::SetText(const std::string& newText) {
if (newText != text) {
text = newText;
// Re-render in Init() or a helper function you could create
}
}