Switching UIFrame to sf::Color* for outline and fill members. Haven't tested with Python integration, but I wrote the methods to take a crack at it

This commit is contained in:
John McCardle 2023-08-30 14:38:49 -04:00
commit 884a49a63a
3 changed files with 114 additions and 24 deletions

View file

@ -8,12 +8,86 @@ void UIDrawable::render()
render(sf::Vector2f());
}
UIFrame::UIFrame():
x(0), y(0), w(0), h(0), outline(0), fillColor(0,0,0,255), outlineColor(0,0,0,0)
{}
x(0), y(0), w(0), h(0), outline(0)
{
pyOutlineColor = NULL;
pyFillColor = NULL;
_outlineColor = NULL;
_fillColor = NULL;
}
UIFrame::UIFrame(float _x, float _y, float _w, float _h):
x(_x), y(_y), w(_w), h(_h), outline(0), fillColor(0,0,0,255), outlineColor(0,0,0,0)
{}
x(_x), y(_y), w(_w), h(_h), outline(0)
{
pyOutlineColor = NULL;
pyFillColor = NULL;
_outlineColor = NULL;
_fillColor = NULL;
}
UIFrame::~UIFrame()
{
if (pyOutlineColor) { Py_DECREF(pyOutlineColor); }
else { if (_outlineColor) { delete _outlineColor; } }
if (pyFillColor) { Py_DECREF(pyFillColor); }
else { if (_fillColor) { delete _fillColor; } }
}
/*
sf::Color& fillColor(); // getter
void fillColor(sf::Color c); // C++ setter
void fillColor(PyObject* pyColor); // Python setter
sf::Color& outlineColor(); // getter
void outlineColor(sf::Color c); // C++ setter
void outlineColor(PyObject* pyColor); // Python setter
*/
sf::Color UIFrame::fillColor()
{
if (_fillColor == NULL) return sf::Color();
return *_fillColor;
}
void UIFrame::fillColor(sf::Color c)
{
if (pyFillColor) { Py_DECREF(pyFillColor); }
else { delete _fillColor; }
_fillColor = new sf::Color(c.r, c.g, c.b, c.a);
pyFillColor = NULL;
}
void UIFrame::fillColor(PyColorObject* pyColor)
{
if (pyFillColor) { Py_DECREF(pyFillColor); }
else { delete _fillColor; }
Py_INCREF(pyColor);
pyFillColor = pyColor;
_fillColor = &(pyFillColor->color);
}
sf::Color UIFrame::outlineColor()
{
if (_outlineColor == NULL) return sf::Color();
return *_outlineColor;
}
void UIFrame::outlineColor(sf::Color c)
{
if (pyOutlineColor) { Py_DECREF(pyOutlineColor); }
else { delete _outlineColor; }
_outlineColor = new sf::Color(c.r, c.g, c.b, c.a);
pyOutlineColor = NULL;
}
void UIFrame::outlineColor(PyColorObject* pyColor)
{
if (pyOutlineColor) { Py_DECREF(pyOutlineColor); }
else { delete _outlineColor; }
Py_INCREF(pyColor);
pyOutlineColor = pyColor;
_outlineColor = &(pyOutlineColor->color);
}
void UIFrame::render(sf::Vector2f offset)
{
@ -25,8 +99,8 @@ void UIFrame::render(sf::Vector2f offset)
sf::RectangleShape box = sf::RectangleShape(sf::Vector2f(w,h));
sf::Vector2f pos = sf::Vector2f(x, y);
box.setPosition(offset + pos);
box.setFillColor(fillColor);
box.setOutlineColor(outlineColor);
if (_fillColor) { box.setFillColor(fillColor()); }
if (_outlineColor) { box.setOutlineColor(outlineColor()); }
box.setOutlineThickness(outline);
Resources::game->getWindow().draw(box);
for (auto drawable : children) {