UINode.coord renamed to UINode.pos
This commit is contained in:
parent
a80e7e4220
commit
f428a24a16
@ -47,7 +47,7 @@ InventoryBuilder::InventoryBuilder() {
|
|||||||
/** Add slots grid to inventory view
|
/** Add slots grid to inventory view
|
||||||
* @param cols grid columns
|
* @param cols grid columns
|
||||||
* @param count total number of grid slots
|
* @param count total number of grid slots
|
||||||
* @param coord position of the first slot of the grid
|
* @param pos position of the first slot of the grid
|
||||||
* @param padding additional space around the grid
|
* @param padding additional space around the grid
|
||||||
* @param addpanel automatically create panel behind the grid
|
* @param addpanel automatically create panel behind the grid
|
||||||
* with size including padding
|
* with size including padding
|
||||||
@ -55,7 +55,7 @@ InventoryBuilder::InventoryBuilder() {
|
|||||||
*/
|
*/
|
||||||
void InventoryBuilder::addGrid(
|
void InventoryBuilder::addGrid(
|
||||||
int cols, int count,
|
int cols, int count,
|
||||||
glm::vec2 coord,
|
glm::vec2 pos,
|
||||||
int padding,
|
int padding,
|
||||||
bool addpanel,
|
bool addpanel,
|
||||||
SlotLayout slotLayout)
|
SlotLayout slotLayout)
|
||||||
@ -69,18 +69,18 @@ void InventoryBuilder::addGrid(
|
|||||||
uint height = rows * (slotSize + interval) - interval + padding*2;
|
uint height = rows * (slotSize + interval) - interval + padding*2;
|
||||||
|
|
||||||
glm::vec2 vsize = view->getSize();
|
glm::vec2 vsize = view->getSize();
|
||||||
if (coord.x + width > vsize.x) {
|
if (pos.x + width > vsize.x) {
|
||||||
vsize.x = coord.x + width;
|
vsize.x = pos.x + width;
|
||||||
}
|
}
|
||||||
if (coord.y + height > vsize.y) {
|
if (pos.y + height > vsize.y) {
|
||||||
vsize.y = coord.y + height;
|
vsize.y = pos.y + height;
|
||||||
}
|
}
|
||||||
view->setSize(vsize);
|
view->setSize(vsize);
|
||||||
|
|
||||||
if (addpanel) {
|
if (addpanel) {
|
||||||
auto panel = std::make_shared<gui::Container>(glm::vec2(width, height));
|
auto panel = std::make_shared<gui::Container>(glm::vec2(width, height));
|
||||||
view->setColor(glm::vec4(0.122f, 0.122f, 0.122f, 0.878f));
|
view->setColor(glm::vec4(0.122f, 0.122f, 0.122f, 0.878f));
|
||||||
view->add(panel, coord);
|
view->add(panel, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int row = 0; row < rows; row++) {
|
for (int row = 0; row < rows; row++) {
|
||||||
@ -121,7 +121,7 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
|
|
||||||
ItemStack& stack = *bound;
|
ItemStack& stack = *bound;
|
||||||
|
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
|
|
||||||
int slotSize = InventoryView::SLOT_SIZE;
|
int slotSize = InventoryView::SLOT_SIZE;
|
||||||
|
|
||||||
@ -137,9 +137,9 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
if (color.a > 0.0) {
|
if (color.a > 0.0) {
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
if (highlighted) {
|
if (highlighted) {
|
||||||
batch->rect(coord.x-4, coord.y-4, slotSize+8, slotSize+8);
|
batch->rect(pos.x-4, pos.y-4, slotSize+8, slotSize+8);
|
||||||
} else {
|
} else {
|
||||||
batch->rect(coord.x, coord.y, slotSize, slotSize);
|
batch->rect(pos.x, pos.y, slotSize, slotSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
|
|
||||||
UVRegion region = previews->get(cblock.name);
|
UVRegion region = previews->get(cblock.name);
|
||||||
batch->rect(
|
batch->rect(
|
||||||
coord.x, coord.y, slotSize, slotSize,
|
pos.x, pos.y, slotSize, slotSize,
|
||||||
0, 0, 0, region, false, true, tint);
|
0, 0, 0, region, false, true, tint);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
batch->rect(
|
batch->rect(
|
||||||
coord.x, coord.y, slotSize, slotSize,
|
pos.x, pos.y, slotSize, slotSize,
|
||||||
0, 0, 0, region, false, true, tint);
|
0, 0, 0, region, false, true, tint);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -187,8 +187,8 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
auto font = assets->getFont("normal");
|
auto font = assets->getFont("normal");
|
||||||
std::wstring text = std::to_wstring(stack.getCount());
|
std::wstring text = std::to_wstring(stack.getCount());
|
||||||
|
|
||||||
int x = coord.x+slotSize-text.length()*8;
|
int x = pos.x+slotSize-text.length()*8;
|
||||||
int y = coord.y+slotSize-16;
|
int y = pos.y+slotSize-16;
|
||||||
|
|
||||||
batch->setColor(glm::vec4(0, 0, 0, 1.0f));
|
batch->setColor(glm::vec4(0, 0, 0, 1.0f));
|
||||||
font->draw(batch, text, x+1, y+1);
|
font->draw(batch, text, x+1, y+1);
|
||||||
@ -291,13 +291,13 @@ std::shared_ptr<SlotView> InventoryView::addSlot(SlotLayout layout) {
|
|||||||
uint width = InventoryView::SLOT_SIZE + layout.padding;
|
uint width = InventoryView::SLOT_SIZE + layout.padding;
|
||||||
uint height = InventoryView::SLOT_SIZE + layout.padding;
|
uint height = InventoryView::SLOT_SIZE + layout.padding;
|
||||||
|
|
||||||
auto coord = layout.position;
|
auto pos = layout.position;
|
||||||
auto vsize = getSize();
|
auto vsize = getSize();
|
||||||
if (coord.x + width > vsize.x) {
|
if (pos.x + width > vsize.x) {
|
||||||
vsize.x = coord.x + width;
|
vsize.x = pos.x + width;
|
||||||
}
|
}
|
||||||
if (coord.y + height > vsize.y) {
|
if (pos.y + height > vsize.y) {
|
||||||
vsize.y = coord.y + height;
|
vsize.y = pos.y + height;
|
||||||
}
|
}
|
||||||
setSize(vsize);
|
setSize(vsize);
|
||||||
|
|
||||||
@ -344,8 +344,8 @@ void InventoryView::setSelected(int index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryView::setCoord(glm::vec2 coord) {
|
void InventoryView::setPos(glm::vec2 pos) {
|
||||||
Container::setCoord(coord - origin);
|
Container::setPos(pos - origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryView::setOrigin(glm::vec2 origin) {
|
void InventoryView::setOrigin(glm::vec2 origin) {
|
||||||
@ -378,8 +378,8 @@ static void readSlot(InventoryView* view, gui::UiXmlReader& reader, xml::xmlelem
|
|||||||
int index = element->attr("index", "0").asInt();
|
int index = element->attr("index", "0").asInt();
|
||||||
bool itemSource = element->attr("item-source", "false").asBool();
|
bool itemSource = element->attr("item-source", "false").asBool();
|
||||||
SlotLayout layout(index, glm::vec2(), true, itemSource, nullptr, nullptr);
|
SlotLayout layout(index, glm::vec2(), true, itemSource, nullptr, nullptr);
|
||||||
if (element->has("coord")) {
|
if (element->has("pos")) {
|
||||||
layout.position = element->attr("coord").asVec2();
|
layout.position = element->attr("pos").asVec2();
|
||||||
}
|
}
|
||||||
if (element->has("sharefunc")) {
|
if (element->has("sharefunc")) {
|
||||||
layout.shareFunc = readSlotFunc(view, reader, element, "sharefunc");
|
layout.shareFunc = readSlotFunc(view, reader, element, "sharefunc");
|
||||||
|
|||||||
@ -101,7 +101,7 @@ public:
|
|||||||
|
|
||||||
void setInventory(std::shared_ptr<Inventory> inventory);
|
void setInventory(std::shared_ptr<Inventory> inventory);
|
||||||
|
|
||||||
virtual void setCoord(glm::vec2 coord) override;
|
virtual void setPos(glm::vec2 pos) override;
|
||||||
|
|
||||||
void setOrigin(glm::vec2 origin);
|
void setOrigin(glm::vec2 origin);
|
||||||
glm::vec2 getOrigin() const;
|
glm::vec2 getOrigin() const;
|
||||||
@ -133,7 +133,7 @@ public:
|
|||||||
|
|
||||||
void addGrid(
|
void addGrid(
|
||||||
int cols, int count,
|
int cols, int count,
|
||||||
glm::vec2 coord,
|
glm::vec2 pos,
|
||||||
int padding,
|
int padding,
|
||||||
bool addpanel,
|
bool addpanel,
|
||||||
SlotLayout slotLayout
|
SlotLayout slotLayout
|
||||||
|
|||||||
@ -29,7 +29,7 @@ std::shared_ptr<UINode> create_debug_panel(
|
|||||||
Player* player
|
Player* player
|
||||||
) {
|
) {
|
||||||
auto panel = std::make_shared<Panel>(glm::vec2(250, 200), glm::vec4(5.0f), 2.0f);
|
auto panel = std::make_shared<Panel>(glm::vec2(250, 200), glm::vec4(5.0f), 2.0f);
|
||||||
panel->setCoord(glm::vec2(10, 10));
|
panel->setPos(glm::vec2(10, 10));
|
||||||
|
|
||||||
static int fps = 0;
|
static int fps = 0;
|
||||||
static int fpsMin = fps;
|
static int fpsMin = fps;
|
||||||
|
|||||||
@ -126,7 +126,7 @@ void GUI::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
auto& viewport = pctx->getViewport();
|
auto& viewport = pctx->getViewport();
|
||||||
glm::vec2 wsize = viewport.size();
|
glm::vec2 wsize = viewport.size();
|
||||||
|
|
||||||
menu->setCoord((wsize - menu->getSize()) / 2.0f);
|
menu->setPos((wsize - menu->getSize()) / 2.0f);
|
||||||
uicamera->setFov(wsize.y);
|
uicamera->setFov(wsize.y);
|
||||||
|
|
||||||
Shader* uishader = assets->getShader("ui");
|
Shader* uishader = assets->getShader("ui");
|
||||||
|
|||||||
@ -63,18 +63,18 @@ bool UINode::isFocused() const {
|
|||||||
return focused;
|
return focused;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UINode::isInside(glm::vec2 pos) {
|
bool UINode::isInside(glm::vec2 point) {
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
glm::vec2 size = getSize();
|
glm::vec2 size = getSize();
|
||||||
return (pos.x >= coord.x && pos.y >= coord.y &&
|
return (point.x >= pos.x && point.y >= pos.y &&
|
||||||
pos.x < coord.x + size.x && pos.y < coord.y + size.y);
|
point.x < pos.x + size.x && point.y < pos.y + size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<UINode> UINode::getAt(glm::vec2 pos, std::shared_ptr<UINode> self) {
|
std::shared_ptr<UINode> UINode::getAt(glm::vec2 point, std::shared_ptr<UINode> self) {
|
||||||
if (!interactive) {
|
if (!interactive) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return isInside(pos) ? self : nullptr;
|
return isInside(point) ? self : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UINode::isInteractive() const {
|
bool UINode::isInteractive() const {
|
||||||
@ -93,11 +93,11 @@ bool UINode::isResizing() const {
|
|||||||
return resizing;
|
return resizing;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 UINode::calcCoord() const {
|
glm::vec2 UINode::calcPos() const {
|
||||||
if (parent) {
|
if (parent) {
|
||||||
return coord + parent->calcCoord() + parent->contentOffset();
|
return pos + parent->calcPos() + parent->contentOffset();
|
||||||
}
|
}
|
||||||
return coord;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UINode::scrolled(int value) {
|
void UINode::scrolled(int value) {
|
||||||
@ -106,12 +106,12 @@ void UINode::scrolled(int value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UINode::setCoord(glm::vec2 coord) {
|
void UINode::setPos(glm::vec2 pos) {
|
||||||
this->coord = coord;
|
this->pos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 UINode::getCoord() const {
|
glm::vec2 UINode::getPos() const {
|
||||||
return coord;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 UINode::getSize() const {
|
glm::vec2 UINode::getSize() const {
|
||||||
@ -187,6 +187,6 @@ const std::string& UINode::getId() const {
|
|||||||
|
|
||||||
void UINode::reposition() {
|
void UINode::reposition() {
|
||||||
if (positionfunc) {
|
if (positionfunc) {
|
||||||
setCoord(positionfunc());
|
setPos(positionfunc());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ namespace gui {
|
|||||||
*/
|
*/
|
||||||
std::string id = "";
|
std::string id = "";
|
||||||
protected:
|
protected:
|
||||||
glm::vec2 coord {0.0f};
|
glm::vec2 pos {0.0f};
|
||||||
glm::vec2 size;
|
glm::vec2 size;
|
||||||
glm::vec2 minSize {1.0f};
|
glm::vec2 minSize {1.0f};
|
||||||
glm::vec4 color {1.0f};
|
glm::vec4 color {1.0f};
|
||||||
@ -123,9 +123,9 @@ namespace gui {
|
|||||||
/* Get inner content offset. Used for scroll */
|
/* Get inner content offset. Used for scroll */
|
||||||
virtual glm::vec2 contentOffset() {return glm::vec2(0.0f);};
|
virtual glm::vec2 contentOffset() {return glm::vec2(0.0f);};
|
||||||
/* Calculate screen position of the element */
|
/* Calculate screen position of the element */
|
||||||
virtual glm::vec2 calcCoord() const;
|
virtual glm::vec2 calcPos() const;
|
||||||
virtual void setCoord(glm::vec2 coord);
|
virtual void setPos(glm::vec2 pos);
|
||||||
virtual glm::vec2 getCoord() const;
|
virtual glm::vec2 getPos() const;
|
||||||
virtual glm::vec2 getSize() const;
|
virtual glm::vec2 getSize() const;
|
||||||
virtual void setSize(glm::vec2 size);
|
virtual void setSize(glm::vec2 size);
|
||||||
virtual glm::vec2 getMinSize() const;
|
virtual glm::vec2 getMinSize() const;
|
||||||
@ -140,7 +140,7 @@ namespace gui {
|
|||||||
void setId(const std::string& id);
|
void setId(const std::string& id);
|
||||||
const std::string& getId() const;
|
const std::string& getId() const;
|
||||||
|
|
||||||
/* Fetch coord from positionfunc if assigned */
|
/* Fetch pos from positionfunc if assigned */
|
||||||
void reposition();
|
void reposition();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,7 @@ void Container::setScrollable(bool flag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Container::draw(const GfxContext* pctx, Assets* assets) {
|
void Container::draw(const GfxContext* pctx, Assets* assets) {
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
glm::vec2 size = getSize();
|
glm::vec2 size = getSize();
|
||||||
drawBackground(pctx, assets);
|
drawBackground(pctx, assets);
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ void Container::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
batch->flush();
|
batch->flush();
|
||||||
{
|
{
|
||||||
GfxContext ctx = pctx->sub();
|
GfxContext ctx = pctx->sub();
|
||||||
ctx.scissors(glm::vec4(coord.x, coord.y, size.x, size.y));
|
ctx.scissors(glm::vec4(pos.x, pos.y, size.x, size.y));
|
||||||
for (auto node : nodes) {
|
for (auto node : nodes) {
|
||||||
if (node->isVisible())
|
if (node->isVisible())
|
||||||
node->draw(pctx, assets);
|
node->draw(pctx, assets);
|
||||||
@ -100,12 +100,12 @@ void Container::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
void Container::drawBackground(const GfxContext* pctx, Assets* assets) {
|
void Container::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||||
if (color.a <= 0.0f)
|
if (color.a <= 0.0f)
|
||||||
return;
|
return;
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
|
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx->getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->setColor(color);
|
batch->setColor(color);
|
||||||
batch->rect(coord.x, coord.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::add(std::shared_ptr<UINode> node) {
|
void Container::add(std::shared_ptr<UINode> node) {
|
||||||
@ -115,8 +115,8 @@ void Container::add(std::shared_ptr<UINode> node) {
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::add(std::shared_ptr<UINode> node, glm::vec2 coord) {
|
void Container::add(std::shared_ptr<UINode> node, glm::vec2 pos) {
|
||||||
node->setCoord(coord);
|
node->setPos(pos);
|
||||||
add(node);
|
add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ void Panel::refresh() {
|
|||||||
y += margin.y;
|
y += margin.y;
|
||||||
|
|
||||||
float ex = x + margin.x;
|
float ex = x + margin.x;
|
||||||
node->setCoord(glm::vec2(ex, y));
|
node->setPos(glm::vec2(ex, y));
|
||||||
y += nodesize.y + margin.w + interval;
|
y += nodesize.y + margin.w + interval;
|
||||||
|
|
||||||
float width = size.x - padding.x - padding.z - margin.x - margin.z;
|
float width = size.x - padding.x - padding.z - margin.x - margin.z;
|
||||||
@ -228,7 +228,7 @@ void Panel::refresh() {
|
|||||||
glm::vec2 nodesize = node->getSize();
|
glm::vec2 nodesize = node->getSize();
|
||||||
const glm::vec4 margin = node->getMargin();
|
const glm::vec4 margin = node->getMargin();
|
||||||
x += margin.x;
|
x += margin.x;
|
||||||
node->setCoord(glm::vec2(x, y+margin.y));
|
node->setPos(glm::vec2(x, y+margin.y));
|
||||||
x += nodesize.x + margin.z + interval;
|
x += nodesize.x + margin.z + interval;
|
||||||
|
|
||||||
node->refresh();
|
node->refresh();
|
||||||
|
|||||||
@ -40,7 +40,7 @@ namespace gui {
|
|||||||
virtual void draw(const GfxContext* pctx, Assets* assets) override;
|
virtual void draw(const GfxContext* pctx, Assets* assets) override;
|
||||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||||
virtual void add(std::shared_ptr<UINode> node);
|
virtual void add(std::shared_ptr<UINode> node);
|
||||||
virtual void add(std::shared_ptr<UINode> node, glm::vec2 coord);
|
virtual void add(std::shared_ptr<UINode> node, glm::vec2 pos);
|
||||||
virtual void remove(std::shared_ptr<UINode> node);
|
virtual void remove(std::shared_ptr<UINode> node);
|
||||||
virtual void scrolled(int value) override;
|
virtual void scrolled(int value) override;
|
||||||
virtual void setScrollable(bool flag);
|
virtual void setScrollable(bool flag);
|
||||||
|
|||||||
@ -139,28 +139,28 @@ void Label::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
(lines == 1 ? lineHeight : lineHeight*lineInterval)*lines + font->getYOffset()
|
(lines == 1 ? lineHeight : lineHeight*lineInterval)*lines + font->getYOffset()
|
||||||
);
|
);
|
||||||
|
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
switch (align) {
|
switch (align) {
|
||||||
case Align::left:
|
case Align::left:
|
||||||
break;
|
break;
|
||||||
case Align::center:
|
case Align::center:
|
||||||
coord.x += (size.x-newsize.x)*0.5f;
|
pos.x += (size.x-newsize.x)*0.5f;
|
||||||
break;
|
break;
|
||||||
case Align::right:
|
case Align::right:
|
||||||
coord.x += size.x-newsize.x;
|
pos.x += size.x-newsize.x;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (valign) {
|
switch (valign) {
|
||||||
case Align::top:
|
case Align::top:
|
||||||
break;
|
break;
|
||||||
case Align::center:
|
case Align::center:
|
||||||
coord.y += (size.y-newsize.y)*0.5f;
|
pos.y += (size.y-newsize.y)*0.5f;
|
||||||
break;
|
break;
|
||||||
case Align::bottom:
|
case Align::bottom:
|
||||||
coord.y += size.y-newsize.y;
|
pos.y += size.y-newsize.y;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
textYOffset = coord.y-calcCoord().y;
|
textYOffset = pos.y-calcPos().y;
|
||||||
totalLineHeight = lineHeight * lineInterval;
|
totalLineHeight = lineHeight * lineInterval;
|
||||||
|
|
||||||
if (multiline) {
|
if (multiline) {
|
||||||
@ -172,10 +172,10 @@ void Label::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
view = std::wstring_view(text.c_str()+offset, end);
|
view = std::wstring_view(text.c_str()+offset, end);
|
||||||
offset += end + 1;
|
offset += end + 1;
|
||||||
}
|
}
|
||||||
font->draw(batch, view, coord.x, coord.y + i * totalLineHeight, FontStyle::none);
|
font->draw(batch, view, pos.x, pos.y + i * totalLineHeight, FontStyle::none);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
font->draw(batch, text, coord.x, coord.y, FontStyle::none);
|
font->draw(batch, text, pos.x, pos.y, FontStyle::none);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ Image::Image(std::string texture, glm::vec2 size) : UINode(size), texture(textur
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Image::draw(const GfxContext* pctx, Assets* assets) {
|
void Image::draw(const GfxContext* pctx, Assets* assets) {
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
glm::vec4 color = getColor();
|
glm::vec4 color = getColor();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx->getBatch2D();
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ void Image::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
}
|
}
|
||||||
batch->texture(texture);
|
batch->texture(texture);
|
||||||
batch->setColor(color);
|
batch->setColor(color);
|
||||||
batch->rect(coord.x, coord.y, size.x, size.y,
|
batch->rect(pos.x, pos.y, size.x, size.y,
|
||||||
0, 0, 0, UVRegion(), false, true, color);
|
0, 0, 0, UVRegion(), false, true, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,11 +296,11 @@ void Button::refresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Button::drawBackground(const GfxContext* pctx, Assets* assets) {
|
void Button::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx->getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color));
|
batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color));
|
||||||
batch->rect(coord.x, coord.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::mouseRelease(GUI* gui, int x, int y) {
|
void Button::mouseRelease(GUI* gui, int x, int y) {
|
||||||
@ -351,11 +351,11 @@ RichButton* RichButton::listenAction(onaction action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RichButton::drawBackground(const GfxContext* pctx, Assets* assets) {
|
void RichButton::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx->getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color));
|
batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color));
|
||||||
batch->rect(coord.x, coord.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================ TextBox ===================================
|
// ================================ TextBox ===================================
|
||||||
@ -368,7 +368,7 @@ TextBox::TextBox(std::wstring placeholder, glm::vec4 padding)
|
|||||||
add(label);
|
add(label);
|
||||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.2f, 0.75f));
|
setHoverColor(glm::vec4(0.05f, 0.1f, 0.2f, 0.75f));
|
||||||
|
|
||||||
textInitX = label->getCoord().x;
|
textInitX = label->getPos().x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::draw(const GfxContext* pctx, Assets* assets) {
|
void TextBox::draw(const GfxContext* pctx, Assets* assets) {
|
||||||
@ -379,14 +379,14 @@ void TextBox::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
if (!isFocused())
|
if (!isFocused())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
glm::vec2 size = getSize();
|
glm::vec2 size = getSize();
|
||||||
|
|
||||||
auto subctx = pctx->sub();
|
auto subctx = pctx->sub();
|
||||||
subctx.scissors(glm::vec4(coord.x, coord.y, size.x, size.y));
|
subctx.scissors(glm::vec4(pos.x, pos.y, size.x, size.y));
|
||||||
|
|
||||||
const int lineHeight = font->getLineHeight() * label->getLineInterval();
|
const int lineHeight = font->getLineHeight() * label->getLineInterval();
|
||||||
glm::vec2 lcoord = label->calcCoord();
|
glm::vec2 lcoord = label->calcPos();
|
||||||
lcoord.y -= 2;
|
lcoord.y -= 2;
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx->getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
@ -422,7 +422,7 @@ void TextBox::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
|
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx->getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
@ -439,14 +439,14 @@ void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
|||||||
batch->setColor(invalidColor);
|
batch->setColor(invalidColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
batch->rect(coord.x, coord.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
if (!isFocused() && supplier) {
|
if (!isFocused() && supplier) {
|
||||||
input = supplier();
|
input = supplier();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFocused() && multiline) {
|
if (isFocused() && multiline) {
|
||||||
batch->setColor(glm::vec4(1, 1, 1, 0.1f));
|
batch->setColor(glm::vec4(1, 1, 1, 0.1f));
|
||||||
glm::vec2 lcoord = label->calcCoord();
|
glm::vec2 lcoord = label->calcPos();
|
||||||
lcoord.y -= 2;
|
lcoord.y -= 2;
|
||||||
uint line = label->getLineByTextIndex(caret);
|
uint line = label->getLineByTextIndex(caret);
|
||||||
int lineY = label->getLineYOffset(line);
|
int lineY = label->getLineYOffset(line);
|
||||||
@ -538,7 +538,7 @@ size_t TextBox::getSelectionLength() const {
|
|||||||
/// @brief Set scroll offset
|
/// @brief Set scroll offset
|
||||||
/// @param x scroll offset
|
/// @param x scroll offset
|
||||||
void TextBox::setTextOffset(uint x) {
|
void TextBox::setTextOffset(uint x) {
|
||||||
label->setCoord(glm::vec2(textInitX - int(x), label->getCoord().y));
|
label->setPos(glm::vec2(textInitX - int(x), label->getPos().y));
|
||||||
textOffset = x;
|
textOffset = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,7 +613,7 @@ size_t TextBox::normalizeIndex(int index) {
|
|||||||
int TextBox::calcIndexAt(int x, int y) const {
|
int TextBox::calcIndexAt(int x, int y) const {
|
||||||
if (font == nullptr)
|
if (font == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
glm::vec2 lcoord = label->calcCoord();
|
glm::vec2 lcoord = label->calcPos();
|
||||||
uint line = label->getLineByYOffset(y-lcoord.y);
|
uint line = label->getLineByYOffset(y-lcoord.y);
|
||||||
line = std::min(line, label->getLinesNumber()-1);
|
line = std::min(line, label->getLinesNumber()-1);
|
||||||
size_t lineLength = getLineLength(line);
|
size_t lineLength = getLineLength(line);
|
||||||
@ -885,11 +885,11 @@ InputBindBox::InputBindBox(Binding& binding, glm::vec4 padding)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InputBindBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
void InputBindBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx->getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->setColor(isFocused() ? focusedColor : (hover ? hoverColor : color));
|
batch->setColor(isFocused() ? focusedColor : (hover ? hoverColor : color));
|
||||||
batch->rect(coord.x, coord.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
label->setText(util::str2wstr_utf8(binding.text()));
|
label->setText(util::str2wstr_utf8(binding.text()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -927,18 +927,18 @@ void TrackBar::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
if (supplier) {
|
if (supplier) {
|
||||||
value = supplier();
|
value = supplier();
|
||||||
}
|
}
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx->getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->setColor(hover ? hoverColor : color);
|
batch->setColor(hover ? hoverColor : color);
|
||||||
batch->rect(coord.x, coord.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
|
|
||||||
float width = size.x;
|
float width = size.x;
|
||||||
float t = (value - min) / (max-min+trackWidth*step);
|
float t = (value - min) / (max-min+trackWidth*step);
|
||||||
|
|
||||||
batch->setColor(trackColor);
|
batch->setColor(trackColor);
|
||||||
int actualWidth = size.x * (trackWidth / (max-min+trackWidth*step) * step);
|
int actualWidth = size.x * (trackWidth / (max-min+trackWidth*step) * step);
|
||||||
batch->rect(coord.x + width * t, coord.y, actualWidth, size.y);
|
batch->rect(pos.x + width * t, pos.y, actualWidth, size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackBar::setSupplier(doublesupplier supplier) {
|
void TrackBar::setSupplier(doublesupplier supplier) {
|
||||||
@ -950,9 +950,9 @@ void TrackBar::setConsumer(doubleconsumer consumer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TrackBar::mouseMove(GUI*, int x, int y) {
|
void TrackBar::mouseMove(GUI*, int x, int y) {
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
value = x;
|
value = x;
|
||||||
value -= coord.x;
|
value -= pos.x;
|
||||||
value = (value)/size.x * (max-min+trackWidth*step);
|
value = (value)/size.x * (max-min+trackWidth*step);
|
||||||
value += min;
|
value += min;
|
||||||
value = (value > max) ? max : value;
|
value = (value > max) ? max : value;
|
||||||
@ -1021,11 +1021,11 @@ void CheckBox::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
if (supplier) {
|
if (supplier) {
|
||||||
checked = supplier();
|
checked = supplier();
|
||||||
}
|
}
|
||||||
glm::vec2 coord = calcCoord();
|
glm::vec2 pos = calcPos();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx->getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->setColor(checked ? checkColor : (hover ? hoverColor : color));
|
batch->setColor(checked ? checkColor : (hover ? hoverColor : color));
|
||||||
batch->rect(coord.x, coord.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::mouseRelease(GUI*, int x, int y) {
|
void CheckBox::mouseRelease(GUI*, int x, int y) {
|
||||||
|
|||||||
@ -28,7 +28,7 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
|
|||||||
node.setId(element->attr("id").getText());
|
node.setId(element->attr("id").getText());
|
||||||
}
|
}
|
||||||
if (element->has("pos")) {
|
if (element->has("pos")) {
|
||||||
node.setCoord(element->attr("pos").asVec2());
|
node.setPos(element->attr("pos").asVec2());
|
||||||
}
|
}
|
||||||
if (element->has("size")) {
|
if (element->has("size")) {
|
||||||
node.setSize(element->attr("size").asVec2());
|
node.setSize(element->attr("size").asVec2());
|
||||||
|
|||||||
@ -351,8 +351,6 @@ void Hud::showOverlay(UiDocument* doc, bool playerInventory) {
|
|||||||
add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false));
|
add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Add element as permanent overlay
|
|
||||||
/// @param doc element layout document
|
|
||||||
void Hud::openPermanent(UiDocument* doc) {
|
void Hud::openPermanent(UiDocument* doc) {
|
||||||
auto root = doc->getRoot();
|
auto root = doc->getRoot();
|
||||||
remove(root);
|
remove(root);
|
||||||
@ -365,7 +363,6 @@ void Hud::openPermanent(UiDocument* doc) {
|
|||||||
add(HudElement(hud_element_mode::permanent, doc, doc->getRoot(), false));
|
add(HudElement(hud_element_mode::permanent, doc, doc->getRoot(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Hide inventory and turn off inventory mode
|
|
||||||
void Hud::closeInventory() {
|
void Hud::closeInventory() {
|
||||||
auto level = frontend->getLevel();
|
auto level = frontend->getLevel();
|
||||||
|
|
||||||
@ -431,6 +428,11 @@ void Hud::remove(std::shared_ptr<gui::UINode> node) {
|
|||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DeltaGrapher : gui::UINode {
|
||||||
|
|
||||||
|
public:
|
||||||
|
};
|
||||||
|
|
||||||
void Hud::draw(const GfxContext& ctx){
|
void Hud::draw(const GfxContext& ctx){
|
||||||
const Viewport& viewport = ctx.getViewport();
|
const Viewport& viewport = ctx.getViewport();
|
||||||
const uint width = viewport.getWidth();
|
const uint width = viewport.getWidth();
|
||||||
@ -445,7 +447,7 @@ void Hud::draw(const GfxContext& ctx){
|
|||||||
uishader->use();
|
uishader->use();
|
||||||
uishader->uniformMatrix("u_projview", uicamera->getProjView());
|
uishader->uniformMatrix("u_projview", uicamera->getProjView());
|
||||||
|
|
||||||
hotbarView->setCoord(glm::vec2(width/2, height-65));
|
hotbarView->setPos(glm::vec2(width/2, height-65));
|
||||||
hotbarView->setSelected(player->getChosenSlot());
|
hotbarView->setSelected(player->getChosenSlot());
|
||||||
|
|
||||||
// Crosshair
|
// Crosshair
|
||||||
@ -485,12 +487,12 @@ void Hud::draw(const GfxContext& ctx){
|
|||||||
|
|
||||||
if (inventoryOpen) {
|
if (inventoryOpen) {
|
||||||
float caWidth = inventoryView ? contentAccess->getSize().x : 0.0f;
|
float caWidth = inventoryView ? contentAccess->getSize().x : 0.0f;
|
||||||
contentAccessPanel->setCoord(glm::vec2(width-caWidth, 0));
|
contentAccessPanel->setPos(glm::vec2(width-caWidth, 0));
|
||||||
|
|
||||||
glm::vec2 invSize = inventoryView ? inventoryView->getSize() : glm::vec2();
|
glm::vec2 invSize = inventoryView ? inventoryView->getSize() : glm::vec2();
|
||||||
if (secondUI == nullptr) {
|
if (secondUI == nullptr) {
|
||||||
if (inventoryView) {
|
if (inventoryView) {
|
||||||
inventoryView->setCoord(glm::vec2(
|
inventoryView->setPos(glm::vec2(
|
||||||
glm::min(width/2-invSize.x/2, width-caWidth-10-invSize.x),
|
glm::min(width/2-invSize.x/2, width-caWidth-10-invSize.x),
|
||||||
height/2-invSize.y/2
|
height/2-invSize.y/2
|
||||||
));
|
));
|
||||||
@ -501,18 +503,18 @@ void Hud::draw(const GfxContext& ctx){
|
|||||||
int interval = invSize.y > 0.0 ? 5 : 0;
|
int interval = invSize.y > 0.0 ? 5 : 0;
|
||||||
float totalHeight = invSize.y + blockInvSize.y + interval;
|
float totalHeight = invSize.y + blockInvSize.y + interval;
|
||||||
if (inventoryView) {
|
if (inventoryView) {
|
||||||
inventoryView->setCoord(glm::vec2(
|
inventoryView->setPos(glm::vec2(
|
||||||
glm::min(width/2-invwidth/2, width-caWidth-10-invwidth),
|
glm::min(width/2-invwidth/2, width-caWidth-10-invwidth),
|
||||||
height/2+totalHeight/2-invSize.y
|
height/2+totalHeight/2-invSize.y
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
secondUI->setCoord(glm::vec2(
|
secondUI->setPos(glm::vec2(
|
||||||
glm::min(width/2-invwidth/2, width-caWidth-10-invwidth),
|
glm::min(width/2-invwidth/2, width-caWidth-10-invwidth),
|
||||||
height/2-totalHeight/2
|
height/2-totalHeight/2
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
grabbedItemView->setCoord(glm::vec2(Events::cursor));
|
grabbedItemView->setPos(glm::vec2(Events::cursor));
|
||||||
batch->flush();
|
batch->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -171,7 +171,7 @@ static int l_gui_getattr(lua_State* L) {
|
|||||||
if (attr == "color") {
|
if (attr == "color") {
|
||||||
return lua::pushcolor_arr(L, node->getColor());
|
return lua::pushcolor_arr(L, node->getColor());
|
||||||
} else if (attr == "pos") {
|
} else if (attr == "pos") {
|
||||||
return lua::pushvec2_arr(L, node->getCoord());
|
return lua::pushvec2_arr(L, node->getPos());
|
||||||
} else if (attr == "size") {
|
} else if (attr == "size") {
|
||||||
return lua::pushvec2_arr(L, node->getSize());
|
return lua::pushvec2_arr(L, node->getSize());
|
||||||
} else if (attr == "hoverColor") {
|
} else if (attr == "hoverColor") {
|
||||||
@ -210,7 +210,7 @@ static int l_gui_setattr(lua_State* L) {
|
|||||||
|
|
||||||
auto node = getDocumentNode(L, docname, element);
|
auto node = getDocumentNode(L, docname, element);
|
||||||
if (attr == "pos") {
|
if (attr == "pos") {
|
||||||
node->setCoord(lua::tovec2(L, 4));
|
node->setPos(lua::tovec2(L, 4));
|
||||||
} else if (attr == "size") {
|
} else if (attr == "size") {
|
||||||
node->setSize(lua::tovec2(L, 4));
|
node->setSize(lua::tovec2(L, 4));
|
||||||
} else if (attr == "color") {
|
} else if (attr == "color") {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user