(A1) change render method to now allow arbitary render targets. This is for drawing child elements on a grid
This commit is contained in:
parent
3b86089128
commit
1d852f875b
|
@ -13,10 +13,11 @@ UIDrawable* UICaption::click_at(sf::Vector2f point)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UICaption::render(sf::Vector2f offset)
|
void UICaption::render(sf::Vector2f offset, sf::RenderTarget& target)
|
||||||
{
|
{
|
||||||
text.move(offset);
|
text.move(offset);
|
||||||
Resources::game->getWindow().draw(text);
|
//Resources::game->getWindow().draw(text);
|
||||||
|
target.draw(text);
|
||||||
text.move(-offset);
|
text.move(-offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ class UICaption: public UIDrawable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
sf::Text text;
|
sf::Text text;
|
||||||
void render(sf::Vector2f) override final;
|
void render(sf::Vector2f, sf::RenderTarget&) override final;
|
||||||
PyObjectsEnum derived_type() override final;
|
PyObjectsEnum derived_type() override final;
|
||||||
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "UICaption.h"
|
#include "UICaption.h"
|
||||||
#include "UISprite.h"
|
#include "UISprite.h"
|
||||||
#include "UIGrid.h"
|
#include "UIGrid.h"
|
||||||
|
#include "GameEngine.h"
|
||||||
|
|
||||||
UIDrawable::UIDrawable() { click_callable = NULL; }
|
UIDrawable::UIDrawable() { click_callable = NULL; }
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ void UIDrawable::click_unregister()
|
||||||
|
|
||||||
void UIDrawable::render()
|
void UIDrawable::render()
|
||||||
{
|
{
|
||||||
render(sf::Vector2f());
|
render(sf::Vector2f(), Resources::game->getWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* UIDrawable::get_click(PyObject* self, void* closure) {
|
PyObject* UIDrawable::get_click(PyObject* self, void* closure) {
|
||||||
|
|
|
@ -28,7 +28,8 @@ class UIDrawable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void render();
|
void render();
|
||||||
virtual void render(sf::Vector2f) = 0;
|
//virtual void render(sf::Vector2f) = 0;
|
||||||
|
virtual void render(sf::Vector2f, sf::RenderTarget&) = 0;
|
||||||
virtual PyObjectsEnum derived_type() = 0;
|
virtual PyObjectsEnum derived_type() = 0;
|
||||||
|
|
||||||
// Mouse input handling - callable object, methods to find event's destination
|
// Mouse input handling - callable object, methods to find event's destination
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
std::vector<UIGridPointState> gridstate;
|
std::vector<UIGridPointState> gridstate;
|
||||||
UISprite sprite;
|
UISprite sprite;
|
||||||
sf::Vector2f position; //(x,y) in grid coordinates; float for animation
|
sf::Vector2f position; //(x,y) in grid coordinates; float for animation
|
||||||
void render(sf::Vector2f); //override final;
|
//void render(sf::Vector2f); //override final;
|
||||||
|
|
||||||
UIEntity();
|
UIEntity();
|
||||||
UIEntity(UIGrid&);
|
UIEntity(UIGrid&);
|
||||||
|
|
|
@ -44,14 +44,15 @@ PyObjectsEnum UIFrame::derived_type()
|
||||||
return PyObjectsEnum::UIFRAME;
|
return PyObjectsEnum::UIFRAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIFrame::render(sf::Vector2f offset)
|
void UIFrame::render(sf::Vector2f offset, sf::RenderTarget& target)
|
||||||
{
|
{
|
||||||
box.move(offset);
|
box.move(offset);
|
||||||
Resources::game->getWindow().draw(box);
|
//Resources::game->getWindow().draw(box);
|
||||||
|
target.draw(box);
|
||||||
box.move(-offset);
|
box.move(-offset);
|
||||||
|
|
||||||
for (auto drawable : *children) {
|
for (auto drawable : *children) {
|
||||||
drawable->render(offset + box.getPosition());
|
drawable->render(offset + box.getPosition(), target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
sf::RectangleShape box;
|
sf::RectangleShape box;
|
||||||
float outline;
|
float outline;
|
||||||
std::shared_ptr<std::vector<std::shared_ptr<UIDrawable>>> children;
|
std::shared_ptr<std::vector<std::shared_ptr<UIDrawable>>> children;
|
||||||
void render(sf::Vector2f) override final;
|
void render(sf::Vector2f, sf::RenderTarget&) override final;
|
||||||
void move(sf::Vector2f);
|
void move(sf::Vector2f);
|
||||||
PyObjectsEnum derived_type() override final;
|
PyObjectsEnum derived_type() override final;
|
||||||
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
||||||
|
|
|
@ -32,9 +32,9 @@ UIGrid::UIGrid(int gx, int gy, std::shared_ptr<PyTexture> _ptex, sf::Vector2f _x
|
||||||
void UIGrid::update() {}
|
void UIGrid::update() {}
|
||||||
|
|
||||||
|
|
||||||
void UIGrid::render(sf::Vector2f)
|
void UIGrid::render(sf::Vector2f offset, sf::RenderTarget& target)
|
||||||
{
|
{
|
||||||
output.setPosition(box.getPosition()); // output sprite can move; update position when drawing
|
output.setPosition(box.getPosition() + offset); // output sprite can move; update position when drawing
|
||||||
// output size can change; update size when drawing
|
// output size can change; update size when drawing
|
||||||
output.setTextureRect(
|
output.setTextureRect(
|
||||||
sf::IntRect(0, 0,
|
sf::IntRect(0, 0,
|
||||||
|
@ -172,7 +172,8 @@ void UIGrid::render(sf::Vector2f)
|
||||||
|
|
||||||
// render to window
|
// render to window
|
||||||
renderTexture.display();
|
renderTexture.display();
|
||||||
Resources::game->getWindow().draw(output);
|
//Resources::game->getWindow().draw(output);
|
||||||
|
target.draw(output);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
//UIGrid(int, int, IndexTexture*, float, float, float, float);
|
//UIGrid(int, int, IndexTexture*, float, float, float, float);
|
||||||
UIGrid(int, int, std::shared_ptr<PyTexture>, sf::Vector2f, sf::Vector2f);
|
UIGrid(int, int, std::shared_ptr<PyTexture>, sf::Vector2f, sf::Vector2f);
|
||||||
void update();
|
void update();
|
||||||
void render(sf::Vector2f) override final;
|
void render(sf::Vector2f, sf::RenderTarget&) override final;
|
||||||
UIGridPoint& at(int, int);
|
UIGridPoint& at(int, int);
|
||||||
PyObjectsEnum derived_type() override final;
|
PyObjectsEnum derived_type() override final;
|
||||||
//void setSprite(int);
|
//void setSprite(int);
|
||||||
|
|
|
@ -18,14 +18,16 @@ UISprite::UISprite(std::shared_ptr<PyTexture> _ptex, int _sprite_index, sf::Vect
|
||||||
sprite = ptex->sprite(sprite_index, _pos, sf::Vector2f(_scale, _scale));
|
sprite = ptex->sprite(sprite_index, _pos, sf::Vector2f(_scale, _scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void UISprite::render(sf::Vector2f offset)
|
void UISprite::render(sf::Vector2f offset)
|
||||||
{
|
{
|
||||||
sprite.move(offset);
|
sprite.move(offset);
|
||||||
Resources::game->getWindow().draw(sprite);
|
Resources::game->getWindow().draw(sprite);
|
||||||
sprite.move(-offset);
|
sprite.move(-offset);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void UISprite::render(sf::Vector2f offset, sf::RenderTexture& target)
|
void UISprite::render(sf::Vector2f offset, sf::RenderTarget& target)
|
||||||
{
|
{
|
||||||
sprite.move(offset);
|
sprite.move(offset);
|
||||||
target.draw(sprite);
|
target.draw(sprite);
|
||||||
|
|
|
@ -25,10 +25,10 @@ public:
|
||||||
UISprite();
|
UISprite();
|
||||||
UISprite(std::shared_ptr<PyTexture>, int, sf::Vector2f, float);
|
UISprite(std::shared_ptr<PyTexture>, int, sf::Vector2f, float);
|
||||||
void update();
|
void update();
|
||||||
void render(sf::Vector2f) override final;
|
void render(sf::Vector2f, sf::RenderTarget&) override final;
|
||||||
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
||||||
|
|
||||||
void render(sf::Vector2f, sf::RenderTexture&);
|
//void render(sf::Vector2f, sf::RenderTexture&);
|
||||||
|
|
||||||
void setPosition(sf::Vector2f);
|
void setPosition(sf::Vector2f);
|
||||||
sf::Vector2f getPosition();
|
sf::Vector2f getPosition();
|
||||||
|
|
Loading…
Reference in New Issue