mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-13 09:02:10 +00:00
started on textbox
This commit is contained in:
parent
128c5f4221
commit
1e21459376
139
Slang/graphics.h
139
Slang/graphics.h
@ -484,6 +484,145 @@ public:
|
|||||||
SDL_Texture* texture;
|
SDL_Texture* texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Text
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Text(std::string path, Vec2 position, Vec2 scale, double angle)
|
||||||
|
: position(position), angle(angle), path(path), scale(scale)
|
||||||
|
{
|
||||||
|
rect.x = static_cast<int>(position.x);
|
||||||
|
rect.y = static_cast<int>(position.y);
|
||||||
|
rect.w = scale.x;
|
||||||
|
rect.h = scale.y;
|
||||||
|
|
||||||
|
Load();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Load()
|
||||||
|
{
|
||||||
|
SDL_Surface* surface = loadSurface(path);
|
||||||
|
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Draw()
|
||||||
|
{
|
||||||
|
rect.x = static_cast<int>(position.x);
|
||||||
|
rect.y = static_cast<int>(position.y);
|
||||||
|
SDL_RenderCopy(gRenderer, texture, NULL, &rect);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::any SubComponent(std::string componentName)
|
||||||
|
{
|
||||||
|
if (componentName == "position")
|
||||||
|
return position;
|
||||||
|
if (componentName == "position.x")
|
||||||
|
return position.x;
|
||||||
|
if (componentName == "position.y")
|
||||||
|
return position.y;
|
||||||
|
if (componentName == "scale")
|
||||||
|
return scale;
|
||||||
|
if (componentName == "scale.x")
|
||||||
|
return scale.x;
|
||||||
|
if (componentName == "scale.y")
|
||||||
|
return scale.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
Sprite EditSubComponent(std::string componentName, std::string oper, boost::any otherVal)
|
||||||
|
{
|
||||||
|
if (componentName == "position")
|
||||||
|
{
|
||||||
|
if (oper == "=")
|
||||||
|
position = any_cast<Vec2>(otherVal);
|
||||||
|
else if (oper == "+=")
|
||||||
|
position += any_cast<Vec2>(otherVal);
|
||||||
|
else if (oper == "-=")
|
||||||
|
position -= any_cast<Vec2>(otherVal);
|
||||||
|
else if (oper == "*=")
|
||||||
|
position *= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "/=")
|
||||||
|
position /= AnyAsFloat(otherVal);
|
||||||
|
}
|
||||||
|
else if (componentName == "position.x")
|
||||||
|
{
|
||||||
|
if (oper == "=")
|
||||||
|
position.x = AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "+=")
|
||||||
|
position.x += AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "-=")
|
||||||
|
position.x -= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "*=")
|
||||||
|
position.x *= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "/=")
|
||||||
|
position.x /= AnyAsFloat(otherVal);
|
||||||
|
}
|
||||||
|
else if (componentName == "position.y")
|
||||||
|
{
|
||||||
|
if (oper == "=")
|
||||||
|
position.y = AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "+=")
|
||||||
|
position.y += AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "-=")
|
||||||
|
position.y -= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "*=")
|
||||||
|
position.y *= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "/=")
|
||||||
|
position.y /= AnyAsFloat(otherVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (componentName == "scale")
|
||||||
|
{
|
||||||
|
if (oper == "=")
|
||||||
|
scale = any_cast<Vec2>(otherVal);
|
||||||
|
else if (oper == "+=")
|
||||||
|
scale += any_cast<Vec2>(otherVal);
|
||||||
|
else if (oper == "-=")
|
||||||
|
scale -= any_cast<Vec2>(otherVal);
|
||||||
|
else if (oper == "*=")
|
||||||
|
scale *= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "/=")
|
||||||
|
scale /= AnyAsFloat(otherVal);
|
||||||
|
}
|
||||||
|
else if (componentName == "scale.x")
|
||||||
|
{
|
||||||
|
if (oper == "=")
|
||||||
|
scale.x = AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "+=")
|
||||||
|
scale.x += AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "-=")
|
||||||
|
scale.x -= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "*=")
|
||||||
|
scale.x *= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "/=")
|
||||||
|
scale.x /= AnyAsFloat(otherVal);
|
||||||
|
}
|
||||||
|
else if (componentName == "scale.y")
|
||||||
|
{
|
||||||
|
if (oper == "=")
|
||||||
|
scale.y = AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "+=")
|
||||||
|
scale.y += AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "-=")
|
||||||
|
scale.y -= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "*=")
|
||||||
|
scale.y *= AnyAsFloat(otherVal);
|
||||||
|
else if (oper == "/=")
|
||||||
|
scale.y /= AnyAsFloat(otherVal);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 position;
|
||||||
|
Vec2 scale;
|
||||||
|
double angle;
|
||||||
|
|
||||||
|
std::string path;
|
||||||
|
SDL_Rect rect{};
|
||||||
|
SDL_Texture* texture;
|
||||||
|
};
|
||||||
|
|
||||||
int cleanupGraphics()
|
int cleanupGraphics()
|
||||||
{
|
{
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user