refactor: add GUI instance reference to UI nodes
This commit is contained in:
@@ -2,23 +2,24 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "graphics/core/DrawContext.hpp"
|
||||
#include "graphics/core/Batch2D.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "graphics/core/Atlas.hpp"
|
||||
#include "assets/Assets.hpp"
|
||||
#include "graphics/core/Atlas.hpp"
|
||||
#include "graphics/core/Batch2D.hpp"
|
||||
#include "graphics/core/DrawContext.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "maths/UVRegion.hpp"
|
||||
|
||||
using namespace gui;
|
||||
|
||||
Image::Image(std::string texture, glm::vec2 size) : UINode(size), texture(std::move(texture)) {
|
||||
Image::Image(GUI& gui, std::string texture, glm::vec2 size)
|
||||
: UINode(gui, size), texture(std::move(texture)) {
|
||||
setInteractive(false);
|
||||
}
|
||||
|
||||
void Image::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx.getBatch2D();
|
||||
|
||||
|
||||
Texture* texture = nullptr;
|
||||
auto separator = this->texture.find(':');
|
||||
if (separator == std::string::npos) {
|
||||
@@ -30,14 +31,16 @@ void Image::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
} else {
|
||||
auto atlasName = this->texture.substr(0, separator);
|
||||
if (auto atlas = assets.get<Atlas>(atlasName)) {
|
||||
if (auto region = atlas->getIf(this->texture.substr(separator+1))) {
|
||||
if (auto region =
|
||||
atlas->getIf(this->texture.substr(separator + 1))) {
|
||||
texture = atlas->getTexture();
|
||||
batch->texture(atlas->getTexture());
|
||||
batch->setRegion(*region);
|
||||
if (autoresize) {
|
||||
setSize(glm::vec2(
|
||||
texture->getWidth()*region->getWidth(),
|
||||
texture->getHeight()*region->getHeight()));
|
||||
texture->getWidth() * region->getWidth(),
|
||||
texture->getHeight() * region->getHeight()
|
||||
));
|
||||
}
|
||||
} else {
|
||||
batch->texture(nullptr);
|
||||
@@ -45,8 +48,17 @@ void Image::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
}
|
||||
}
|
||||
batch->rect(
|
||||
pos.x, pos.y, size.x, size.y,
|
||||
0, 0, 0, UVRegion(), false, true, calcColor()
|
||||
pos.x,
|
||||
pos.y,
|
||||
size.x,
|
||||
size.y,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
UVRegion(),
|
||||
false,
|
||||
true,
|
||||
calcColor()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user