UINode.coord renamed to UINode.pos
This commit is contained in:
@@ -126,7 +126,7 @@ void GUI::draw(const GfxContext* pctx, Assets* assets) {
|
||||
auto& viewport = pctx->getViewport();
|
||||
glm::vec2 wsize = viewport.size();
|
||||
|
||||
menu->setCoord((wsize - menu->getSize()) / 2.0f);
|
||||
menu->setPos((wsize - menu->getSize()) / 2.0f);
|
||||
uicamera->setFov(wsize.y);
|
||||
|
||||
Shader* uishader = assets->getShader("ui");
|
||||
|
||||
+14
-14
@@ -63,18 +63,18 @@ bool UINode::isFocused() const {
|
||||
return focused;
|
||||
}
|
||||
|
||||
bool UINode::isInside(glm::vec2 pos) {
|
||||
glm::vec2 coord = calcCoord();
|
||||
bool UINode::isInside(glm::vec2 point) {
|
||||
glm::vec2 pos = calcPos();
|
||||
glm::vec2 size = getSize();
|
||||
return (pos.x >= coord.x && pos.y >= coord.y &&
|
||||
pos.x < coord.x + size.x && pos.y < coord.y + size.y);
|
||||
return (point.x >= pos.x && point.y >= pos.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) {
|
||||
return nullptr;
|
||||
}
|
||||
return isInside(pos) ? self : nullptr;
|
||||
return isInside(point) ? self : nullptr;
|
||||
}
|
||||
|
||||
bool UINode::isInteractive() const {
|
||||
@@ -93,11 +93,11 @@ bool UINode::isResizing() const {
|
||||
return resizing;
|
||||
}
|
||||
|
||||
glm::vec2 UINode::calcCoord() const {
|
||||
glm::vec2 UINode::calcPos() const {
|
||||
if (parent) {
|
||||
return coord + parent->calcCoord() + parent->contentOffset();
|
||||
return pos + parent->calcPos() + parent->contentOffset();
|
||||
}
|
||||
return coord;
|
||||
return pos;
|
||||
}
|
||||
|
||||
void UINode::scrolled(int value) {
|
||||
@@ -106,12 +106,12 @@ void UINode::scrolled(int value) {
|
||||
}
|
||||
}
|
||||
|
||||
void UINode::setCoord(glm::vec2 coord) {
|
||||
this->coord = coord;
|
||||
void UINode::setPos(glm::vec2 pos) {
|
||||
this->pos = pos;
|
||||
}
|
||||
|
||||
glm::vec2 UINode::getCoord() const {
|
||||
return coord;
|
||||
glm::vec2 UINode::getPos() const {
|
||||
return pos;
|
||||
}
|
||||
|
||||
glm::vec2 UINode::getSize() const {
|
||||
@@ -187,6 +187,6 @@ const std::string& UINode::getId() const {
|
||||
|
||||
void UINode::reposition() {
|
||||
if (positionfunc) {
|
||||
setCoord(positionfunc());
|
||||
setPos(positionfunc());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace gui {
|
||||
*/
|
||||
std::string id = "";
|
||||
protected:
|
||||
glm::vec2 coord {0.0f};
|
||||
glm::vec2 pos {0.0f};
|
||||
glm::vec2 size;
|
||||
glm::vec2 minSize {1.0f};
|
||||
glm::vec4 color {1.0f};
|
||||
@@ -123,9 +123,9 @@ namespace gui {
|
||||
/* Get inner content offset. Used for scroll */
|
||||
virtual glm::vec2 contentOffset() {return glm::vec2(0.0f);};
|
||||
/* Calculate screen position of the element */
|
||||
virtual glm::vec2 calcCoord() const;
|
||||
virtual void setCoord(glm::vec2 coord);
|
||||
virtual glm::vec2 getCoord() const;
|
||||
virtual glm::vec2 calcPos() const;
|
||||
virtual void setPos(glm::vec2 pos);
|
||||
virtual glm::vec2 getPos() const;
|
||||
virtual glm::vec2 getSize() const;
|
||||
virtual void setSize(glm::vec2 size);
|
||||
virtual glm::vec2 getMinSize() const;
|
||||
@@ -140,7 +140,7 @@ namespace gui {
|
||||
void setId(const std::string& id);
|
||||
const std::string& getId() const;
|
||||
|
||||
/* Fetch coord from positionfunc if assigned */
|
||||
/* Fetch pos from positionfunc if assigned */
|
||||
void reposition();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ void Container::setScrollable(bool flag) {
|
||||
}
|
||||
|
||||
void Container::draw(const GfxContext* pctx, Assets* assets) {
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
glm::vec2 size = getSize();
|
||||
drawBackground(pctx, assets);
|
||||
|
||||
@@ -88,7 +88,7 @@ void Container::draw(const GfxContext* pctx, Assets* assets) {
|
||||
batch->flush();
|
||||
{
|
||||
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) {
|
||||
if (node->isVisible())
|
||||
node->draw(pctx, assets);
|
||||
@@ -100,12 +100,12 @@ void Container::draw(const GfxContext* pctx, Assets* assets) {
|
||||
void Container::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
if (color.a <= 0.0f)
|
||||
return;
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
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) {
|
||||
@@ -115,8 +115,8 @@ void Container::add(std::shared_ptr<UINode> node) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
void Container::add(std::shared_ptr<UINode> node, glm::vec2 coord) {
|
||||
node->setCoord(coord);
|
||||
void Container::add(std::shared_ptr<UINode> node, glm::vec2 pos) {
|
||||
node->setPos(pos);
|
||||
add(node);
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ void Panel::refresh() {
|
||||
y += margin.y;
|
||||
|
||||
float ex = x + margin.x;
|
||||
node->setCoord(glm::vec2(ex, y));
|
||||
node->setPos(glm::vec2(ex, y));
|
||||
y += nodesize.y + margin.w + interval;
|
||||
|
||||
float width = size.x - padding.x - padding.z - margin.x - margin.z;
|
||||
@@ -228,7 +228,7 @@ void Panel::refresh() {
|
||||
glm::vec2 nodesize = node->getSize();
|
||||
const glm::vec4 margin = node->getMargin();
|
||||
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;
|
||||
|
||||
node->refresh();
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace gui {
|
||||
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 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 scrolled(int value) override;
|
||||
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()
|
||||
);
|
||||
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
switch (align) {
|
||||
case Align::left:
|
||||
break;
|
||||
case Align::center:
|
||||
coord.x += (size.x-newsize.x)*0.5f;
|
||||
pos.x += (size.x-newsize.x)*0.5f;
|
||||
break;
|
||||
case Align::right:
|
||||
coord.x += size.x-newsize.x;
|
||||
pos.x += size.x-newsize.x;
|
||||
break;
|
||||
}
|
||||
switch (valign) {
|
||||
case Align::top:
|
||||
break;
|
||||
case Align::center:
|
||||
coord.y += (size.y-newsize.y)*0.5f;
|
||||
pos.y += (size.y-newsize.y)*0.5f;
|
||||
break;
|
||||
case Align::bottom:
|
||||
coord.y += size.y-newsize.y;
|
||||
pos.y += size.y-newsize.y;
|
||||
break;
|
||||
}
|
||||
textYOffset = coord.y-calcCoord().y;
|
||||
textYOffset = pos.y-calcPos().y;
|
||||
totalLineHeight = lineHeight * lineInterval;
|
||||
|
||||
if (multiline) {
|
||||
@@ -172,10 +172,10 @@ void Label::draw(const GfxContext* pctx, Assets* assets) {
|
||||
view = std::wstring_view(text.c_str()+offset, end);
|
||||
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 {
|
||||
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) {
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
glm::vec4 color = getColor();
|
||||
auto batch = pctx->getBatch2D();
|
||||
|
||||
@@ -208,7 +208,7 @@ void Image::draw(const GfxContext* pctx, Assets* assets) {
|
||||
}
|
||||
batch->texture(texture);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -296,11 +296,11 @@ void Button::refresh() {
|
||||
}
|
||||
|
||||
void Button::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
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) {
|
||||
@@ -351,11 +351,11 @@ RichButton* RichButton::listenAction(onaction action) {
|
||||
}
|
||||
|
||||
void RichButton::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
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 ===================================
|
||||
@@ -368,7 +368,7 @@ TextBox::TextBox(std::wstring placeholder, glm::vec4 padding)
|
||||
add(label);
|
||||
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) {
|
||||
@@ -379,14 +379,14 @@ void TextBox::draw(const GfxContext* pctx, Assets* assets) {
|
||||
if (!isFocused())
|
||||
return;
|
||||
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
glm::vec2 size = getSize();
|
||||
|
||||
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();
|
||||
glm::vec2 lcoord = label->calcCoord();
|
||||
glm::vec2 lcoord = label->calcPos();
|
||||
lcoord.y -= 2;
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
@@ -422,7 +422,7 @@ void TextBox::draw(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();
|
||||
batch->texture(nullptr);
|
||||
@@ -439,14 +439,14 @@ void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
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) {
|
||||
input = supplier();
|
||||
}
|
||||
|
||||
if (isFocused() && multiline) {
|
||||
batch->setColor(glm::vec4(1, 1, 1, 0.1f));
|
||||
glm::vec2 lcoord = label->calcCoord();
|
||||
glm::vec2 lcoord = label->calcPos();
|
||||
lcoord.y -= 2;
|
||||
uint line = label->getLineByTextIndex(caret);
|
||||
int lineY = label->getLineYOffset(line);
|
||||
@@ -538,7 +538,7 @@ size_t TextBox::getSelectionLength() const {
|
||||
/// @brief Set scroll offset
|
||||
/// @param x scroll offset
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -613,7 +613,7 @@ size_t TextBox::normalizeIndex(int index) {
|
||||
int TextBox::calcIndexAt(int x, int y) const {
|
||||
if (font == nullptr)
|
||||
return 0;
|
||||
glm::vec2 lcoord = label->calcCoord();
|
||||
glm::vec2 lcoord = label->calcPos();
|
||||
uint line = label->getLineByYOffset(y-lcoord.y);
|
||||
line = std::min(line, label->getLinesNumber()-1);
|
||||
size_t lineLength = getLineLength(line);
|
||||
@@ -885,11 +885,11 @@ InputBindBox::InputBindBox(Binding& binding, glm::vec4 padding)
|
||||
}
|
||||
|
||||
void InputBindBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
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()));
|
||||
}
|
||||
|
||||
@@ -927,18 +927,18 @@ void TrackBar::draw(const GfxContext* pctx, Assets* assets) {
|
||||
if (supplier) {
|
||||
value = supplier();
|
||||
}
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
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 t = (value - min) / (max-min+trackWidth*step);
|
||||
|
||||
batch->setColor(trackColor);
|
||||
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) {
|
||||
@@ -950,9 +950,9 @@ void TrackBar::setConsumer(doubleconsumer consumer) {
|
||||
}
|
||||
|
||||
void TrackBar::mouseMove(GUI*, int x, int y) {
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
value = x;
|
||||
value -= coord.x;
|
||||
value -= pos.x;
|
||||
value = (value)/size.x * (max-min+trackWidth*step);
|
||||
value += min;
|
||||
value = (value > max) ? max : value;
|
||||
@@ -1021,11 +1021,11 @@ void CheckBox::draw(const GfxContext* pctx, Assets* assets) {
|
||||
if (supplier) {
|
||||
checked = supplier();
|
||||
}
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
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) {
|
||||
|
||||
@@ -28,7 +28,7 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
|
||||
node.setId(element->attr("id").getText());
|
||||
}
|
||||
if (element->has("pos")) {
|
||||
node.setCoord(element->attr("pos").asVec2());
|
||||
node.setPos(element->attr("pos").asVec2());
|
||||
}
|
||||
if (element->has("size")) {
|
||||
node.setSize(element->attr("size").asVec2());
|
||||
|
||||
Reference in New Issue
Block a user