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
|
|
@ -1,5 +1,6 @@
|
|||
#include "UITestScene.h"
|
||||
#include "ActionCode.h"
|
||||
#include "Resources.h"
|
||||
|
||||
UITestScene::UITestScene(GameEngine* g) : Scene(g)
|
||||
{
|
||||
|
|
@ -12,37 +13,50 @@ UITestScene::UITestScene(GameEngine* g) : Scene(g)
|
|||
//registerAction(ActionCode::KEY + sf::Keyboard::Up, "up");
|
||||
//registerAction(ActionCode::KEY + sf::Keyboard::Down, "down");
|
||||
|
||||
|
||||
auto ui = Resources::game->scene_ui("uitest");
|
||||
if (ui)
|
||||
{
|
||||
std::cout << "Got back a UI vector from Resources::game.\n";
|
||||
} else {
|
||||
std::cout << "No UI vector was returned.\n";
|
||||
}
|
||||
|
||||
// Create a UI element or three?
|
||||
e1 = UIFrame(100,150,400,400);
|
||||
//e1.box.setPosition(100, 150);
|
||||
//e1.box.setSize(sf::Vector2f(400,400));
|
||||
//e1.box.setFillColor(sf::Color(255, 0, 0));
|
||||
e1.fillColor(sf::Color(255,0,0));
|
||||
auto e1 = std::make_shared<UIFrame>(100,150,400,400);
|
||||
e1->box.setPosition(100, 150);
|
||||
e1->box.setSize(sf::Vector2f(400,400));
|
||||
e1->box.setFillColor(sf::Color(255, 0, 0));
|
||||
//e1.fillColor(sf::Color(255,0,0));
|
||||
//if (ui) ui->push_back(e1);
|
||||
ui_elements.push_back(e1);
|
||||
|
||||
auto e1a = std::make_shared<UIFrame>(50,50,200,200);
|
||||
e1a->box.setPosition(50, 50);
|
||||
e1a->box.setSize(sf::Vector2f(200,200));
|
||||
e1a->box.setFillColor(sf::Color(0, 255, 0));
|
||||
//e1a.fillColor(sf::Color(0, 255, 0));
|
||||
e1->children.push_back(e1a);
|
||||
|
||||
e1a = UIFrame(50,50,200,200);
|
||||
//e1a.box.setPosition(50, 50);
|
||||
//e1a.box.setSize(sf::Vector2f(200,200));
|
||||
//e1a.box.setFillColor(sf::Color(0, 255, 0));
|
||||
e1a.fillColor(sf::Color(0, 255, 0));
|
||||
e1.children.push_back(&e1a);
|
||||
auto e1aa = std::make_shared<UIFrame>(5,5,100,100);
|
||||
e1aa->box.setPosition(5, 5);
|
||||
e1aa->box.setSize(sf::Vector2f(100,100));
|
||||
e1aa->box.setFillColor(sf::Color(0, 0, 255));
|
||||
//e1aa.fillColor(sf::Color(0, 0, 255));
|
||||
e1a->children.push_back(e1aa);
|
||||
|
||||
e1aa = UIFrame(5,5,100,100);
|
||||
//e1aa.box.setPosition(5, 5);
|
||||
//e1aa.box.setSize(sf::Vector2f(100,100));
|
||||
//e1aa.box.setFillColor(sf::Color(0, 0, 255));
|
||||
e1aa.fillColor(sf::Color(0, 0, 255));
|
||||
e1a.children.push_back(&e1aa);
|
||||
|
||||
e2 = UICaption();
|
||||
e2.text.setFont(game->getFont());
|
||||
e2.text.setString("Hello World.");
|
||||
auto e2 = std::make_shared<UICaption>();
|
||||
e2->text.setFont(game->getFont());
|
||||
e2->text.setString("Hello World.");
|
||||
//e2.text.setColor(sf::Color(255, 255, 255));
|
||||
e2.text.setPosition(50, 250);
|
||||
e2->text.setPosition(50, 250);
|
||||
|
||||
ui_elements.push_back(&e1);
|
||||
ui_elements.push_back(&e2);
|
||||
//if (ui) ui->push_back(e2);
|
||||
ui_elements.push_back(e2);
|
||||
//ui_elements.push_back(&e1);
|
||||
//ui_elements.push_back(&e2);
|
||||
|
||||
if (ui)
|
||||
std::cout << "pointer to ui_elements now shows size=" << ui->size() << std::endl;
|
||||
}
|
||||
|
||||
void UITestScene::update()
|
||||
|
|
@ -70,10 +84,14 @@ void UITestScene::sRender()
|
|||
game->getWindow().draw(text);
|
||||
|
||||
// draw all UI elements
|
||||
//for (auto e: ui_elements)
|
||||
//auto ui = Resources::game->scene_ui("uitest");
|
||||
//if (ui)
|
||||
for (auto e: ui_elements)
|
||||
{
|
||||
//std::cout << "Rendering element\n";
|
||||
e->render();
|
||||
if (e)
|
||||
e->render();
|
||||
}
|
||||
|
||||
//e1.render(sf::Vector2f(0, 0));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue