mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-13 09:02:10 +00:00
worked on text more and possibly fixed accuracy
This commit is contained in:
parent
1e21459376
commit
69afbf0be8
107
Slang/graphics.h
107
Slang/graphics.h
@ -369,8 +369,9 @@ public:
|
|||||||
|
|
||||||
int Draw()
|
int Draw()
|
||||||
{
|
{
|
||||||
rect.x = static_cast<int>(position.x);
|
// rect.x = static_cast<int>(position.x);
|
||||||
rect.y = static_cast<int>(position.y);
|
rect.x = position.x;
|
||||||
|
rect.y = position.y;
|
||||||
SDL_RenderCopy(gRenderer, texture, NULL, &rect);
|
SDL_RenderCopy(gRenderer, texture, NULL, &rect);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -487,29 +488,36 @@ public:
|
|||||||
class Text
|
class Text
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Text(std::string path, Vec2 position, Vec2 scale, double angle)
|
Text(std::string content, std::string pathToFont, Vec2 position, float fontSize, double angle, int r, int g, int b)
|
||||||
: position(position), angle(angle), path(path), scale(scale)
|
: position(position), angle(angle), content(content), pathToFont(pathToFont), fontSize(fontSize), r(r), g(g), b(b)
|
||||||
{
|
{
|
||||||
rect.x = static_cast<int>(position.x);
|
rect.x = position.x;
|
||||||
rect.y = static_cast<int>(position.y);
|
rect.y = position.y;
|
||||||
rect.w = scale.x;
|
// rect.y = static_cast<int>(position.y);
|
||||||
rect.h = scale.y;
|
|
||||||
|
|
||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Load()
|
int Load()
|
||||||
{
|
{
|
||||||
SDL_Surface* surface = loadSurface(path);
|
TTF_Font* font = TTF_OpenFont(pathToFont, fontSize);
|
||||||
|
|
||||||
|
SDL_Color color = {r, g, b};
|
||||||
|
|
||||||
|
SDL_Surface* surface = TTF_RenderText_Solid(font, content, color);
|
||||||
|
|
||||||
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
||||||
|
|
||||||
|
TTF_SizeText(font, Message, &rect.w, &rect.h);
|
||||||
|
|
||||||
SDL_FreeSurface(surface);
|
SDL_FreeSurface(surface);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Draw()
|
int Draw()
|
||||||
{
|
{
|
||||||
rect.x = static_cast<int>(position.x);
|
rect.x = position.x;
|
||||||
rect.y = static_cast<int>(position.y);
|
rect.y = position.y;
|
||||||
SDL_RenderCopy(gRenderer, texture, NULL, &rect);
|
SDL_RenderCopy(gRenderer, texture, NULL, &rect);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -522,12 +530,12 @@ public:
|
|||||||
return position.x;
|
return position.x;
|
||||||
if (componentName == "position.y")
|
if (componentName == "position.y")
|
||||||
return position.y;
|
return position.y;
|
||||||
if (componentName == "scale")
|
if (componentName == "fontSize")
|
||||||
return scale;
|
return fontSize;
|
||||||
if (componentName == "scale.x")
|
if (componentName == "content")
|
||||||
return scale.x;
|
return content;
|
||||||
if (componentName == "scale.y")
|
if (componentName == "pathToFont")
|
||||||
return scale.y;
|
return pathToFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprite EditSubComponent(std::string componentName, std::string oper, boost::any otherVal)
|
Sprite EditSubComponent(std::string componentName, std::string oper, boost::any otherVal)
|
||||||
@ -572,51 +580,78 @@ public:
|
|||||||
position.y /= AnyAsFloat(otherVal);
|
position.y /= AnyAsFloat(otherVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (componentName == "scale")
|
else if (componentName == "fontSize")
|
||||||
{
|
{
|
||||||
if (oper == "=")
|
if (oper == "=")
|
||||||
scale = any_cast<Vec2>(otherVal);
|
fontSize = AnyAsFloat(otherVal);
|
||||||
else if (oper == "+=")
|
else if (oper == "+=")
|
||||||
scale += any_cast<Vec2>(otherVal);
|
fontSize += AnyAsFloat(otherVal);
|
||||||
else if (oper == "-=")
|
else if (oper == "-=")
|
||||||
scale -= any_cast<Vec2>(otherVal);
|
fontSize -= AnyAsFloat(otherVal);
|
||||||
else if (oper == "*=")
|
else if (oper == "*=")
|
||||||
scale *= AnyAsFloat(otherVal);
|
fontSize *= AnyAsFloat(otherVal);
|
||||||
else if (oper == "/=")
|
else if (oper == "/=")
|
||||||
scale /= AnyAsFloat(otherVal);
|
fontSize /= AnyAsFloat(otherVal);
|
||||||
}
|
}
|
||||||
else if (componentName == "scale.x")
|
|
||||||
|
else if (componentName == "r")
|
||||||
{
|
{
|
||||||
if (oper == "=")
|
if (oper == "=")
|
||||||
scale.x = AnyAsFloat(otherVal);
|
r = AnyAsFloat(otherVal);
|
||||||
else if (oper == "+=")
|
else if (oper == "+=")
|
||||||
scale.x += AnyAsFloat(otherVal);
|
r += AnyAsFloat(otherVal);
|
||||||
else if (oper == "-=")
|
else if (oper == "-=")
|
||||||
scale.x -= AnyAsFloat(otherVal);
|
r -= AnyAsFloat(otherVal);
|
||||||
else if (oper == "*=")
|
else if (oper == "*=")
|
||||||
scale.x *= AnyAsFloat(otherVal);
|
r *= AnyAsFloat(otherVal);
|
||||||
else if (oper == "/=")
|
else if (oper == "/=")
|
||||||
scale.x /= AnyAsFloat(otherVal);
|
r /= AnyAsFloat(otherVal);
|
||||||
}
|
}
|
||||||
else if (componentName == "scale.y")
|
else if (componentName == "g")
|
||||||
{
|
{
|
||||||
if (oper == "=")
|
if (oper == "=")
|
||||||
scale.y = AnyAsFloat(otherVal);
|
g = AnyAsFloat(otherVal);
|
||||||
else if (oper == "+=")
|
else if (oper == "+=")
|
||||||
scale.y += AnyAsFloat(otherVal);
|
g += AnyAsFloat(otherVal);
|
||||||
else if (oper == "-=")
|
else if (oper == "-=")
|
||||||
scale.y -= AnyAsFloat(otherVal);
|
g -= AnyAsFloat(otherVal);
|
||||||
else if (oper == "*=")
|
else if (oper == "*=")
|
||||||
scale.y *= AnyAsFloat(otherVal);
|
g *= AnyAsFloat(otherVal);
|
||||||
else if (oper == "/=")
|
else if (oper == "/=")
|
||||||
scale.y /= AnyAsFloat(otherVal);
|
g /= AnyAsFloat(otherVal);
|
||||||
|
}
|
||||||
|
else if (componentName == "b")
|
||||||
|
{
|
||||||
|
if (oper == "=")
|
||||||
|
b = AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "+=")
|
||||||
|
b += AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "-=")
|
||||||
|
b -= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "*=")
|
||||||
|
b *= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "/=")
|
||||||
|
b /= AnyAsFloat(otherVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (componentName == "content")
|
||||||
|
{
|
||||||
|
if (oper == "=")
|
||||||
|
content = AnyAsString(otherVal);
|
||||||
|
else if (oper == "+=")
|
||||||
|
content += AnyAsString(otherVal);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2 position;
|
Vec2 position;
|
||||||
Vec2 scale;
|
float fontSize;
|
||||||
double angle;
|
double angle;
|
||||||
|
int r;
|
||||||
|
int g;
|
||||||
|
int b;
|
||||||
|
std::string content;
|
||||||
|
std::string pathToFont;
|
||||||
|
|
||||||
std::string path;
|
std::string path;
|
||||||
SDL_Rect rect{};
|
SDL_Rect rect{};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user