Aug 30/31 updates. Tinkering with shared_ptr. Working towards exposing UI objects to Python UI. Color object updated for shared_ptr structure that will be repeated for the rest of the UI objects. Still a lot of open questions, but committing here to get back on track after a few hours wasted trying to solve this problem too generally via templates.
This commit is contained in:
parent
795701c986
commit
50d926fe37
11 changed files with 293 additions and 137 deletions
73
src/UI.cpp
73
src/UI.cpp
|
|
@ -10,27 +10,33 @@ void UIDrawable::render()
|
|||
UIFrame::UIFrame():
|
||||
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)
|
||||
{
|
||||
/*
|
||||
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;
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -43,68 +49,23 @@ UIFrame::~UIFrame()
|
|||
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)
|
||||
{
|
||||
//std::cout << "Rendering UIFrame w/ offset " << offset.x << ", " << offset.y << "\n";
|
||||
//std::cout << "position = " << x << ", " << y << "\n";
|
||||
//box.move(offset);
|
||||
//Resources::game->getWindow().draw(box);
|
||||
//box.move(-offset);
|
||||
sf::RectangleShape box = sf::RectangleShape(sf::Vector2f(w,h));
|
||||
sf::Vector2f pos = sf::Vector2f(x, y);
|
||||
box.setPosition(offset + pos);
|
||||
if (_fillColor) { box.setFillColor(fillColor()); }
|
||||
if (_outlineColor) { box.setOutlineColor(outlineColor()); }
|
||||
box.setOutlineThickness(outline);
|
||||
box.move(offset);
|
||||
Resources::game->getWindow().draw(box);
|
||||
box.move(-offset);
|
||||
//sf::RectangleShape box = sf::RectangleShape(sf::Vector2f(w,h));
|
||||
//sf::Vector2f pos = sf::Vector2f(x, y);
|
||||
//box.setPosition(offset + pos);
|
||||
//if (_fillColor) { box.setFillColor(fillColor()); }
|
||||
//if (_outlineColor) { box.setOutlineColor(outlineColor()); }
|
||||
//box.setOutlineThickness(outline);
|
||||
//Resources::game->getWindow().draw(box);
|
||||
for (auto drawable : children) {
|
||||
drawable->render(offset + pos);
|
||||
drawable->render(offset + box.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -121,4 +82,4 @@ void UISprite::render(sf::Vector2f offset)
|
|||
sprite.move(offset);
|
||||
Resources::game->getWindow().draw(sprite);
|
||||
sprite.move(-offset);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue