add 'region' image property
This commit is contained in:
parent
032b5ae9dc
commit
79528a44ea
@ -55,7 +55,7 @@ void Image::draw(const DrawContext& pctx, const Assets& assets) {
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
UVRegion(),
|
region,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
calcColor()
|
calcColor()
|
||||||
@ -76,3 +76,7 @@ const std::string& Image::getTexture() const {
|
|||||||
void Image::setTexture(const std::string& name) {
|
void Image::setTexture(const std::string& name) {
|
||||||
texture = name;
|
texture = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Image::setRegion(const UVRegion& region) {
|
||||||
|
this->region = region;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "UINode.hpp"
|
#include "UINode.hpp"
|
||||||
|
#include "maths/UVRegion.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class Image : public UINode {
|
class Image : public UINode {
|
||||||
protected:
|
protected:
|
||||||
std::string texture;
|
std::string texture;
|
||||||
|
UVRegion region {};
|
||||||
bool autoresize = false;
|
bool autoresize = false;
|
||||||
public:
|
public:
|
||||||
Image(GUI& gui, std::string texture, glm::vec2 size=glm::vec2(32,32));
|
Image(GUI& gui, std::string texture, glm::vec2 size=glm::vec2(32,32));
|
||||||
@ -16,5 +18,6 @@ namespace gui {
|
|||||||
virtual bool isAutoResize() const;
|
virtual bool isAutoResize() const;
|
||||||
virtual const std::string& getTexture() const;
|
virtual const std::string& getTexture() const;
|
||||||
virtual void setTexture(const std::string& name);
|
virtual void setTexture(const std::string& name);
|
||||||
|
void setRegion(const UVRegion& region);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -544,6 +544,11 @@ static std::shared_ptr<UINode> read_image(
|
|||||||
std::string src = element.attr("src", "").getText();
|
std::string src = element.attr("src", "").getText();
|
||||||
auto image = std::make_shared<Image>(reader.getGUI(), src);
|
auto image = std::make_shared<Image>(reader.getGUI(), src);
|
||||||
read_uinode(reader, element, *image);
|
read_uinode(reader, element, *image);
|
||||||
|
|
||||||
|
if (element.has("region")) {
|
||||||
|
auto vec = element.attr("region").asVec4();
|
||||||
|
image->setRegion(UVRegion(vec.x, vec.y, vec.z, vec.w));
|
||||||
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -659,6 +659,12 @@ static void p_set_src(UINode* node, lua::State* L, int idx) {
|
|||||||
iframe->setSrc(lua::require_string(L, idx));
|
iframe->setSrc(lua::require_string(L, idx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void p_set_region(UINode* node, lua::State* L, int idx) {
|
||||||
|
if (auto image = dynamic_cast<Image*>(node)) {
|
||||||
|
auto vec = lua::tovec4(L, idx);
|
||||||
|
image->setRegion(UVRegion(vec.x, vec.y, vec.z, vec.w));
|
||||||
|
}
|
||||||
|
}
|
||||||
static void p_set_value(UINode* node, lua::State* L, int idx) {
|
static void p_set_value(UINode* node, lua::State* L, int idx) {
|
||||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||||
bar->setValue(lua::tonumber(L, idx));
|
bar->setValue(lua::tonumber(L, idx));
|
||||||
@ -785,6 +791,7 @@ static int l_gui_setattr(lua::State* L) {
|
|||||||
{"inventory", p_set_inventory},
|
{"inventory", p_set_inventory},
|
||||||
{"cursor", p_set_cursor},
|
{"cursor", p_set_cursor},
|
||||||
{"focused", p_set_focused},
|
{"focused", p_set_focused},
|
||||||
|
{"region", p_set_region},
|
||||||
};
|
};
|
||||||
auto func = setters.find(attr);
|
auto func = setters.find(attr);
|
||||||
if (func != setters.end()) {
|
if (func != setters.end()) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user