minor refactor
This commit is contained in:
parent
c6bd52eed2
commit
2aa49c7470
@ -10,5 +10,8 @@ using wstringsupplier = std::function<std::wstring()>;
|
||||
using wstringconsumer = std::function<void(const std::wstring&)>;
|
||||
using doublesupplier = std::function<double()>;
|
||||
using doubleconsumer = std::function<void(double)>;
|
||||
using boolsupplier = std::function<bool()>;
|
||||
using boolconsumer = std::function<void(bool)>;
|
||||
using wstringchecker = std::function<bool(const std::wstring&)>;
|
||||
|
||||
#endif // DELEGATES_H_
|
||||
|
||||
@ -10,24 +10,20 @@
|
||||
#include "../../util/stringutil.h"
|
||||
#include "GUI.h"
|
||||
|
||||
using glm::vec2;
|
||||
using glm::vec3;
|
||||
using glm::vec4;
|
||||
|
||||
using namespace gui;
|
||||
|
||||
Label::Label(std::string text, std::string fontName)
|
||||
: UINode(vec2(), vec2(text.length() * 8, 15)),
|
||||
: UINode(glm::vec2(), glm::vec2(text.length() * 8, 15)),
|
||||
text(util::str2wstr_utf8(text)),
|
||||
fontName_(fontName) {
|
||||
fontName(fontName) {
|
||||
setInteractive(false);
|
||||
}
|
||||
|
||||
|
||||
Label::Label(std::wstring text, std::string fontName)
|
||||
: UINode(vec2(), vec2(text.length() * 8, 15)),
|
||||
: UINode(glm::vec2(), glm::vec2(text.length() * 8, 15)),
|
||||
text(text),
|
||||
fontName_(fontName) {
|
||||
fontName(fontName) {
|
||||
setInteractive(false);
|
||||
}
|
||||
|
||||
@ -46,14 +42,14 @@ void Label::draw(const GfxContext* pctx, Assets* assets) {
|
||||
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->color = getColor();
|
||||
Font* font = assets->getFont(fontName_);
|
||||
vec2 size = getSize();
|
||||
vec2 newsize = vec2(
|
||||
Font* font = assets->getFont(fontName);
|
||||
glm::vec2 size = getSize();
|
||||
glm::vec2 newsize (
|
||||
font->calcWidth(text),
|
||||
font->getLineHeight()+font->getYOffset()
|
||||
);
|
||||
|
||||
vec2 coord = calcCoord();
|
||||
glm::vec2 coord = calcCoord();
|
||||
switch (align) {
|
||||
case Align::left:
|
||||
break;
|
||||
@ -74,13 +70,13 @@ Label* Label::textSupplier(wstringsupplier supplier) {
|
||||
}
|
||||
|
||||
// ================================= Image ====================================
|
||||
Image::Image(std::string texture, vec2 size) : UINode(vec2(), size), texture(texture) {
|
||||
Image::Image(std::string texture, glm::vec2 size) : UINode(glm::vec2(), size), texture(texture) {
|
||||
setInteractive(false);
|
||||
}
|
||||
|
||||
void Image::draw(const GfxContext* pctx, Assets* assets) {
|
||||
vec2 coord = calcCoord();
|
||||
vec4 color = getColor();
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec4 color = getColor();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(assets->getTexture(texture));
|
||||
batch->color = color;
|
||||
@ -90,10 +86,11 @@ void Image::draw(const GfxContext* pctx, Assets* assets) {
|
||||
|
||||
// ================================= Button ===================================
|
||||
Button::Button(std::shared_ptr<UINode> content, glm::vec4 padding)
|
||||
: Panel(vec2(), padding, 0) {
|
||||
vec4 margin = getMargin();
|
||||
setSize(content->getSize()+vec2(padding[0]+padding[2]+margin[0]+margin[2],
|
||||
padding[1]+padding[3]+margin[1]+margin[3]));
|
||||
: Panel(glm::vec2(), padding, 0) {
|
||||
glm::vec4 margin = getMargin();
|
||||
setSize(content->getSize()+
|
||||
glm::vec2(padding[0]+padding[2]+margin[0]+margin[2],
|
||||
padding[1]+padding[3]+margin[1]+margin[3]));
|
||||
add(content);
|
||||
setScrollable(false);
|
||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
|
||||
@ -102,13 +99,13 @@ Button::Button(std::shared_ptr<UINode> content, glm::vec4 padding)
|
||||
|
||||
Button::Button(
|
||||
std::wstring text,
|
||||
vec4 padding,
|
||||
glm::vec4 padding,
|
||||
onaction action,
|
||||
vec2 size
|
||||
glm::vec2 size
|
||||
) : Panel(size, padding, 0)
|
||||
{
|
||||
if (size.y < 0.0f) {
|
||||
size = vec2(
|
||||
size = glm::vec2(
|
||||
glm::max(padding.x + padding.z + text.length()*8, size.x),
|
||||
glm::max(padding.y + padding.w + 16, size.y)
|
||||
);
|
||||
@ -122,7 +119,7 @@ Button::Button(
|
||||
|
||||
label = std::make_shared<Label>(text);
|
||||
label->setAlign(Align::center);
|
||||
label->setSize(size-vec2(padding.z+padding.x, padding.w+padding.y));
|
||||
label->setSize(size-glm::vec2(padding.z+padding.x, padding.w+padding.y));
|
||||
label->setInteractive(false);
|
||||
add(label);
|
||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
|
||||
@ -151,12 +148,12 @@ Button* Button::textSupplier(wstringsupplier supplier) {
|
||||
void Button::refresh() {
|
||||
Panel::refresh();
|
||||
if (label) {
|
||||
label->setSize(size-vec2(padding.z+padding.x, padding.w+padding.y));
|
||||
label->setSize(size-glm::vec2(padding.z+padding.x, padding.w+padding.y));
|
||||
}
|
||||
}
|
||||
|
||||
void Button::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
vec2 coord = calcCoord();
|
||||
glm::vec2 coord = calcCoord();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->color = (isPressed() ? pressedColor : (hover ? hoverColor : color));
|
||||
@ -165,7 +162,7 @@ void Button::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
|
||||
void Button::mouseRelease(GUI* gui, int x, int y) {
|
||||
UINode::mouseRelease(gui, x, y);
|
||||
if (isInside(vec2(x, y))) {
|
||||
if (isInside(glm::vec2(x, y))) {
|
||||
for (auto callback : actions) {
|
||||
callback(gui);
|
||||
}
|
||||
@ -192,13 +189,13 @@ Align Button::getTextAlign() const {
|
||||
}
|
||||
|
||||
// ============================== RichButton ==================================
|
||||
RichButton::RichButton(vec2 size) : Container(vec2(), size) {
|
||||
RichButton::RichButton(glm::vec2 size) : Container(glm::vec2(), size) {
|
||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
|
||||
}
|
||||
|
||||
void RichButton::mouseRelease(GUI* gui, int x, int y) {
|
||||
UINode::mouseRelease(gui, x, y);
|
||||
if (isInside(vec2(x, y))) {
|
||||
if (isInside(glm::vec2(x, y))) {
|
||||
for (auto callback : actions) {
|
||||
callback(gui);
|
||||
}
|
||||
@ -211,7 +208,7 @@ RichButton* RichButton::listenAction(onaction action) {
|
||||
}
|
||||
|
||||
void RichButton::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
vec2 coord = calcCoord();
|
||||
glm::vec2 coord = calcCoord();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->color = (isPressed() ? pressedColor : (hover ? hoverColor : color));
|
||||
@ -219,18 +216,18 @@ void RichButton::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
}
|
||||
|
||||
// ================================ TextBox ===================================
|
||||
TextBox::TextBox(std::wstring placeholder, vec4 padding)
|
||||
: Panel(vec2(200,32), padding, 0),
|
||||
TextBox::TextBox(std::wstring placeholder, glm::vec4 padding)
|
||||
: Panel(glm::vec2(200,32), padding, 0),
|
||||
input(L""),
|
||||
placeholder(placeholder) {
|
||||
label = std::make_shared<Label>(L"");
|
||||
label->setSize(size-vec2(padding.z+padding.x, padding.w+padding.y));
|
||||
label->setSize(size-glm::vec2(padding.z+padding.x, padding.w+padding.y));
|
||||
add(label);
|
||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.2f, 0.75f));
|
||||
}
|
||||
|
||||
void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
vec2 coord = calcCoord();
|
||||
glm::vec2 coord = calcCoord();
|
||||
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
@ -253,10 +250,10 @@ void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
}
|
||||
|
||||
if (input.empty()) {
|
||||
label->setColor(vec4(0.5f));
|
||||
label->setColor(glm::vec4(0.5f));
|
||||
label->setText(placeholder);
|
||||
} else {
|
||||
label->setColor(vec4(1.0f));
|
||||
label->setColor(glm::vec4(1.0f));
|
||||
label->setText(input);
|
||||
}
|
||||
setScrollable(false);
|
||||
@ -297,7 +294,7 @@ void TextBox::focus(GUI* gui) {
|
||||
|
||||
void TextBox::refresh() {
|
||||
Panel::refresh();
|
||||
label->setSize(size-vec2(padding.z+padding.x, padding.w+padding.y));
|
||||
label->setSize(size-glm::vec2(padding.z+padding.x, padding.w+padding.y));
|
||||
}
|
||||
|
||||
void TextBox::keyPressed(int key) {
|
||||
@ -322,7 +319,7 @@ void TextBox::keyPressed(int key) {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<UINode> TextBox::getAt(vec2 pos, std::shared_ptr<UINode> self) {
|
||||
std::shared_ptr<UINode> TextBox::getAt(glm::vec2 pos, std::shared_ptr<UINode> self) {
|
||||
return UINode::getAt(pos, self);
|
||||
}
|
||||
|
||||
@ -349,8 +346,8 @@ void TextBox::setText(std::wstring value) {
|
||||
}
|
||||
|
||||
// ============================== InputBindBox ================================
|
||||
InputBindBox::InputBindBox(Binding& binding, vec4 padding)
|
||||
: Panel(vec2(100,32), padding, 0),
|
||||
InputBindBox::InputBindBox(Binding& binding, glm::vec4 padding)
|
||||
: Panel(glm::vec2(100,32), padding, 0),
|
||||
binding(binding) {
|
||||
label = std::make_shared<Label>(L"");
|
||||
add(label);
|
||||
@ -358,7 +355,7 @@ InputBindBox::InputBindBox(Binding& binding, vec4 padding)
|
||||
}
|
||||
|
||||
void InputBindBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
vec2 coord = calcCoord();
|
||||
glm::vec2 coord = calcCoord();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->color = (isFocused() ? focusedColor : (hover ? hoverColor : color));
|
||||
@ -386,20 +383,20 @@ TrackBar::TrackBar(double min,
|
||||
double value,
|
||||
double step,
|
||||
int trackWidth)
|
||||
: UINode(vec2(), vec2(26)),
|
||||
: UINode(glm::vec2(), glm::vec2(26)),
|
||||
min(min),
|
||||
max(max),
|
||||
value(value),
|
||||
step(step),
|
||||
trackWidth(trackWidth) {
|
||||
setColor(vec4(0.f, 0.f, 0.f, 0.4f));
|
||||
setColor(glm::vec4(0.f, 0.f, 0.f, 0.4f));
|
||||
}
|
||||
|
||||
void TrackBar::draw(const GfxContext* pctx, Assets* assets) {
|
||||
if (supplier_) {
|
||||
value = supplier_();
|
||||
if (supplier) {
|
||||
value = supplier();
|
||||
}
|
||||
vec2 coord = calcCoord();
|
||||
glm::vec2 coord = calcCoord();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->color = (hover ? hoverColor : color);
|
||||
@ -413,16 +410,16 @@ void TrackBar::draw(const GfxContext* pctx, Assets* assets) {
|
||||
batch->rect(coord.x + width * t, coord.y, actualWidth, size.y);
|
||||
}
|
||||
|
||||
void TrackBar::supplier(doublesupplier supplier) {
|
||||
this->supplier_ = supplier;
|
||||
void TrackBar::setSupplier(doublesupplier supplier) {
|
||||
this->supplier = supplier;
|
||||
}
|
||||
|
||||
void TrackBar::consumer(doubleconsumer consumer) {
|
||||
this->consumer_ = consumer;
|
||||
void TrackBar::setConsumer(doubleconsumer consumer) {
|
||||
this->consumer = consumer;
|
||||
}
|
||||
|
||||
void TrackBar::mouseMove(GUI*, int x, int y) {
|
||||
vec2 coord = calcCoord();
|
||||
glm::vec2 coord = calcCoord();
|
||||
value = x;
|
||||
value -= coord.x;
|
||||
value = (value)/size.x * (max-min+trackWidth*step);
|
||||
@ -430,56 +427,56 @@ void TrackBar::mouseMove(GUI*, int x, int y) {
|
||||
value = (value > max) ? max : value;
|
||||
value = (value < min) ? min : value;
|
||||
value = (int)(value / step) * step;
|
||||
if (consumer_) {
|
||||
consumer_(value);
|
||||
if (consumer) {
|
||||
consumer(value);
|
||||
}
|
||||
}
|
||||
|
||||
// ================================ CheckBox ==================================
|
||||
CheckBox::CheckBox(bool checked) : UINode(vec2(), vec2(32.0f)), checked_(checked) {
|
||||
setColor(vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
CheckBox::CheckBox(bool checked) : UINode(glm::vec2(), glm::vec2(32.0f)), checked(checked) {
|
||||
setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
}
|
||||
|
||||
void CheckBox::draw(const GfxContext* pctx, Assets* assets) {
|
||||
if (supplier_) {
|
||||
checked_ = supplier_();
|
||||
if (supplier) {
|
||||
checked = supplier();
|
||||
}
|
||||
vec2 coord = calcCoord();
|
||||
glm::vec2 coord = calcCoord();
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->color = checked_ ? checkColor : (hover ? hoverColor : color);
|
||||
batch->color = checked ? checkColor : (hover ? hoverColor : color);
|
||||
batch->rect(coord.x, coord.y, size.x, size.y);
|
||||
}
|
||||
|
||||
void CheckBox::mouseRelease(GUI*, int x, int y) {
|
||||
checked_ = !checked_;
|
||||
if (consumer_) {
|
||||
consumer_(checked_);
|
||||
checked = !checked;
|
||||
if (consumer) {
|
||||
consumer(checked);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckBox::supplier(boolsupplier supplier) {
|
||||
supplier_ = supplier;
|
||||
void CheckBox::setSupplier(boolsupplier supplier) {
|
||||
this->supplier = supplier;
|
||||
}
|
||||
|
||||
void CheckBox::consumer(boolconsumer consumer) {
|
||||
consumer_ = consumer;
|
||||
void CheckBox::setConsumer(boolconsumer consumer) {
|
||||
this->consumer = consumer;
|
||||
}
|
||||
|
||||
CheckBox* CheckBox::checked(bool flag) {
|
||||
checked_ = flag;
|
||||
CheckBox* CheckBox::setChecked(bool flag) {
|
||||
checked = flag;
|
||||
return this;
|
||||
}
|
||||
|
||||
FullCheckBox::FullCheckBox(std::wstring text, glm::vec2 size, bool checked)
|
||||
: Panel(size),
|
||||
checkbox(std::make_shared<CheckBox>(checked)){
|
||||
setColor(vec4(0.0f));
|
||||
setColor(glm::vec4(0.0f));
|
||||
setOrientation(Orientation::horizontal);
|
||||
|
||||
add(checkbox);
|
||||
|
||||
auto label = std::make_shared<Label>(text);
|
||||
label->setMargin(vec4(5.f, 5.f, 0.f, 0.f));
|
||||
label->setMargin(glm::vec4(5.f, 5.f, 0.f, 0.f));
|
||||
add(label);
|
||||
}
|
||||
|
||||
@ -17,15 +17,10 @@ class Batch2D;
|
||||
class Assets;
|
||||
|
||||
namespace gui {
|
||||
using boolsupplier = std::function<bool()>;
|
||||
using boolconsumer = std::function<void(bool)>;
|
||||
|
||||
using wstringchecker = std::function<bool(const std::wstring&)>;
|
||||
|
||||
class Label : public UINode {
|
||||
protected:
|
||||
std::wstring text;
|
||||
std::string fontName_;
|
||||
std::string fontName;
|
||||
wstringsupplier supplier = nullptr;
|
||||
public:
|
||||
Label(std::string text, std::string fontName="normal");
|
||||
@ -145,8 +140,8 @@ namespace gui {
|
||||
protected:
|
||||
glm::vec4 hoverColor {0.01f, 0.02f, 0.03f, 0.5f};
|
||||
glm::vec4 trackColor {1.0f, 1.0f, 1.0f, 0.4f};
|
||||
doublesupplier supplier_ = nullptr;
|
||||
doubleconsumer consumer_ = nullptr;
|
||||
doublesupplier supplier = nullptr;
|
||||
doubleconsumer consumer = nullptr;
|
||||
double min;
|
||||
double max;
|
||||
double value;
|
||||
@ -160,8 +155,8 @@ namespace gui {
|
||||
int trackWidth=1);
|
||||
virtual void draw(const GfxContext* pctx, Assets* assets) override;
|
||||
|
||||
virtual void supplier(doublesupplier supplier);
|
||||
virtual void consumer(doubleconsumer consumer);
|
||||
virtual void setSupplier(doublesupplier supplier);
|
||||
virtual void setConsumer(doubleconsumer consumer);
|
||||
|
||||
virtual void mouseMove(GUI*, int x, int y) override;
|
||||
};
|
||||
@ -170,9 +165,9 @@ namespace gui {
|
||||
protected:
|
||||
glm::vec4 hoverColor {0.05f, 0.1f, 0.2f, 0.75f};
|
||||
glm::vec4 checkColor {1.0f, 1.0f, 1.0f, 0.4f};
|
||||
boolsupplier supplier_ = nullptr;
|
||||
boolconsumer consumer_ = nullptr;
|
||||
bool checked_ = false;
|
||||
boolsupplier supplier = nullptr;
|
||||
boolconsumer consumer = nullptr;
|
||||
bool checked = false;
|
||||
public:
|
||||
CheckBox(bool checked=false);
|
||||
|
||||
@ -180,15 +175,15 @@ namespace gui {
|
||||
|
||||
virtual void mouseRelease(GUI*, int x, int y) override;
|
||||
|
||||
virtual void supplier(boolsupplier supplier);
|
||||
virtual void consumer(boolconsumer consumer);
|
||||
virtual void setSupplier(boolsupplier supplier);
|
||||
virtual void setConsumer(boolconsumer consumer);
|
||||
|
||||
virtual CheckBox* checked(bool flag);
|
||||
virtual CheckBox* setChecked(bool flag);
|
||||
|
||||
virtual bool checked() const {
|
||||
if (supplier_)
|
||||
return supplier_();
|
||||
return checked_;
|
||||
virtual bool isChecked() const {
|
||||
if (supplier)
|
||||
return supplier();
|
||||
return checked;
|
||||
}
|
||||
};
|
||||
|
||||
@ -198,22 +193,22 @@ namespace gui {
|
||||
public:
|
||||
FullCheckBox(std::wstring text, glm::vec2 size, bool checked=false);
|
||||
|
||||
virtual void supplier(boolsupplier supplier) {
|
||||
checkbox->supplier(supplier);
|
||||
virtual void setSupplier(boolsupplier supplier) {
|
||||
checkbox->setSupplier(supplier);
|
||||
}
|
||||
|
||||
virtual void consumer(boolconsumer consumer) {
|
||||
checkbox->consumer(consumer);
|
||||
virtual void setConsumer(boolconsumer consumer) {
|
||||
checkbox->setConsumer(consumer);
|
||||
}
|
||||
|
||||
virtual void checked(bool flag) {
|
||||
checkbox->checked(flag);
|
||||
virtual void setChecked(bool flag) {
|
||||
checkbox->setChecked(flag);
|
||||
}
|
||||
|
||||
virtual bool checked() const {
|
||||
return checkbox->checked();
|
||||
virtual bool isChecked() const {
|
||||
return checkbox->isChecked();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // FRONTEND_GUI_CONTROLS_H_
|
||||
#endif // FRONTEND_GUI_CONTROLS_H_
|
||||
|
||||
@ -192,7 +192,7 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement
|
||||
element->attr("consumer").getText(),
|
||||
reader.getFilename()+".lua"
|
||||
);
|
||||
bar->consumer(consumer);
|
||||
bar->setConsumer(consumer);
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
|
||||
@ -9,15 +9,12 @@
|
||||
|
||||
using namespace gui;
|
||||
|
||||
using glm::vec2;
|
||||
using glm::vec4;
|
||||
|
||||
Container::Container(vec2 coord, vec2 size) : UINode(coord, size) {
|
||||
Container::Container(glm::vec2 coord, glm::vec2 size) : UINode(coord, size) {
|
||||
actualLength = size.y;
|
||||
setColor(glm::vec4());
|
||||
}
|
||||
|
||||
std::shared_ptr<UINode> Container::getAt(vec2 pos, std::shared_ptr<UINode> self) {
|
||||
std::shared_ptr<UINode> Container::getAt(glm::vec2 pos, std::shared_ptr<UINode> self) {
|
||||
if (!interactive) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -79,8 +76,8 @@ void Container::setScrollable(bool flag) {
|
||||
}
|
||||
|
||||
void Container::draw(const GfxContext* pctx, Assets* assets) {
|
||||
vec2 coord = calcCoord();
|
||||
vec2 size = getSize();
|
||||
glm::vec2 coord = calcCoord();
|
||||
glm::vec2 size = getSize();
|
||||
drawBackground(pctx, assets);
|
||||
|
||||
auto batch = pctx->getBatch2D();
|
||||
@ -88,7 +85,7 @@ void Container::draw(const GfxContext* pctx, Assets* assets) {
|
||||
batch->render();
|
||||
{
|
||||
GfxContext ctx = pctx->sub();
|
||||
ctx.scissors(vec4(coord.x, coord.y, size.x, size.y));
|
||||
ctx.scissors(glm::vec4(coord.x, coord.y, size.x, size.y));
|
||||
for (auto node : nodes) {
|
||||
if (node->isVisible())
|
||||
node->draw(pctx, assets);
|
||||
@ -100,7 +97,7 @@ void Container::draw(const GfxContext* pctx, Assets* assets) {
|
||||
void Container::drawBackground(const GfxContext* pctx, Assets* assets) {
|
||||
if (color.a <= 0.0f)
|
||||
return;
|
||||
vec2 coord = calcCoord();
|
||||
glm::vec2 coord = calcCoord();
|
||||
|
||||
auto batch = pctx->getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
@ -154,11 +151,11 @@ const std::vector<std::shared_ptr<UINode>>& Container::getNodes() const {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
Panel::Panel(vec2 size, glm::vec4 padding, float interval)
|
||||
: Container(vec2(), size),
|
||||
Panel::Panel(glm::vec2 size, glm::vec4 padding, float interval)
|
||||
: Container(glm::vec2(), size),
|
||||
padding(padding),
|
||||
interval(interval) {
|
||||
setColor(vec4(0.0f, 0.0f, 0.0f, 0.75f));
|
||||
setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.75f));
|
||||
}
|
||||
|
||||
Panel::~Panel() {
|
||||
@ -183,9 +180,9 @@ glm::vec4 Panel::getPadding() const {
|
||||
|
||||
void Panel::cropToContent() {
|
||||
if (maxLength > 0.0f) {
|
||||
setSize(vec2(getSize().x, glm::min(maxLength, actualLength)));
|
||||
setSize(glm::vec2(getSize().x, glm::min(maxLength, actualLength)));
|
||||
} else {
|
||||
setSize(vec2(getSize().x, actualLength));
|
||||
setSize(glm::vec2(getSize().x, actualLength));
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,21 +196,21 @@ void Panel::refresh() {
|
||||
UINode::refresh();
|
||||
float x = padding.x;
|
||||
float y = padding.y;
|
||||
vec2 size = getSize();
|
||||
glm::vec2 size = getSize();
|
||||
if (orientation == Orientation::vertical) {
|
||||
float maxw = size.x;
|
||||
for (auto& node : nodes) {
|
||||
vec2 nodesize = node->getSize();
|
||||
const vec4 margin = node->getMargin();
|
||||
glm::vec2 nodesize = node->getSize();
|
||||
const glm::vec4 margin = node->getMargin();
|
||||
y += margin.y;
|
||||
|
||||
float ex = x + margin.x;
|
||||
node->setCoord(vec2(ex, y));
|
||||
node->setCoord(glm::vec2(ex, y));
|
||||
y += nodesize.y + margin.w + interval;
|
||||
|
||||
float width = size.x - padding.x - padding.z - margin.x - margin.z;
|
||||
if (node->isResizing()) {
|
||||
node->setSize(vec2(width, nodesize.y));
|
||||
node->setSize(glm::vec2(width, nodesize.y));
|
||||
}
|
||||
node->refresh();
|
||||
maxw = fmax(maxw, ex+node->getSize().x+margin.z+padding.z);
|
||||
@ -222,10 +219,10 @@ void Panel::refresh() {
|
||||
} else {
|
||||
float maxh = size.y;
|
||||
for (auto& node : nodes) {
|
||||
vec2 nodesize = node->getSize();
|
||||
const vec4 margin = node->getMargin();
|
||||
glm::vec2 nodesize = node->getSize();
|
||||
const glm::vec4 margin = node->getMargin();
|
||||
x += margin.x;
|
||||
node->setCoord(vec2(x, y+margin.y));
|
||||
node->setCoord(glm::vec2(x, y+margin.y));
|
||||
x += nodesize.x + margin.z + interval;
|
||||
|
||||
node->refresh();
|
||||
@ -243,7 +240,7 @@ Orientation Panel::getOrientation() const {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
PagesControl::PagesControl() : Container(vec2(), vec2(1)){
|
||||
PagesControl::PagesControl() : Container(glm::vec2(), glm::vec2(1)){
|
||||
}
|
||||
|
||||
bool PagesControl::has(std::string name) {
|
||||
@ -259,16 +256,16 @@ void PagesControl::setPage(std::string name, bool history) {
|
||||
if (found == pages.end()) {
|
||||
throw std::runtime_error("no page found");
|
||||
}
|
||||
if (current_.panel) {
|
||||
Container::remove(current_.panel);
|
||||
if (current.panel) {
|
||||
Container::remove(current.panel);
|
||||
}
|
||||
if (history) {
|
||||
pageStack.push(curname_);
|
||||
pageStack.push(curname);
|
||||
}
|
||||
curname_ = name;
|
||||
current_ = found->second;
|
||||
Container::add(current_.panel);
|
||||
setSize(current_.panel->getSize());
|
||||
curname = name;
|
||||
current = found->second;
|
||||
Container::add(current.panel);
|
||||
setSize(current.panel->getSize());
|
||||
}
|
||||
|
||||
void PagesControl::back() {
|
||||
@ -279,8 +276,8 @@ void PagesControl::back() {
|
||||
setPage(name, false);
|
||||
}
|
||||
|
||||
Page& PagesControl::current() {
|
||||
return current_;
|
||||
Page& PagesControl::getCurrent() {
|
||||
return current;
|
||||
}
|
||||
|
||||
void PagesControl::clearHistory() {
|
||||
@ -289,9 +286,9 @@ void PagesControl::clearHistory() {
|
||||
|
||||
void PagesControl::reset() {
|
||||
clearHistory();
|
||||
if (current_.panel) {
|
||||
curname_ = "";
|
||||
Container::remove(current_.panel);
|
||||
current_ = Page{nullptr};
|
||||
if (current.panel) {
|
||||
curname = "";
|
||||
Container::remove(current.panel);
|
||||
current = Page{nullptr};
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,8 +94,8 @@ namespace gui {
|
||||
protected:
|
||||
std::unordered_map<std::string, Page> pages;
|
||||
std::stack<std::string> pageStack;
|
||||
Page current_;
|
||||
std::string curname_ = "";
|
||||
Page current;
|
||||
std::string curname = "";
|
||||
public:
|
||||
PagesControl();
|
||||
|
||||
@ -106,7 +106,7 @@ namespace gui {
|
||||
void clearHistory();
|
||||
void reset();
|
||||
|
||||
Page& current();
|
||||
Page& getCurrent();
|
||||
};
|
||||
}
|
||||
#endif // FRONTEND_GUI_PANELS_H_
|
||||
@ -100,13 +100,13 @@ std::shared_ptr<UINode> HudRenderer::createDebugPanel(Engine* engine) {
|
||||
}));
|
||||
|
||||
for (int ax = 0; ax < 3; ax++){
|
||||
auto sub = std::make_shared<Panel>(vec2(10, 27), vec4(0.0f));
|
||||
sub->setOrientation(Orientation::horizontal);
|
||||
auto sub = std::make_shared<Container>(vec2(), vec2(250, 27));
|
||||
|
||||
std::wstring str = L"x: ";
|
||||
str[0] += ax;
|
||||
auto label = std::make_shared<Label>(str);
|
||||
label->setMargin(vec4(2, 3, 2, 3));
|
||||
label->setSize(vec2(20, 27));
|
||||
sub->add(label);
|
||||
sub->setColor(vec4(0.0f));
|
||||
|
||||
@ -128,8 +128,9 @@ std::shared_ptr<UINode> HudRenderer::createDebugPanel(Engine* engine) {
|
||||
Hitbox* hitbox = level->player->hitbox.get();
|
||||
box->setText(std::to_wstring(int(hitbox->position[ax])));
|
||||
});
|
||||
box->setSize(vec2(230, 27));
|
||||
|
||||
sub->add(box);
|
||||
sub->add(box, vec2(20, 0));
|
||||
panel->add(sub);
|
||||
}
|
||||
panel->add(create_label([=](){
|
||||
@ -143,24 +144,24 @@ std::shared_ptr<UINode> HudRenderer::createDebugPanel(Engine* engine) {
|
||||
}));
|
||||
{
|
||||
auto bar = std::make_shared<TrackBar>(0.0f, 1.0f, 1.0f, 0.005f, 8);
|
||||
bar->supplier([=]() {return level->world->daytime;});
|
||||
bar->consumer([=](double val) {level->world->daytime = val;});
|
||||
bar->setSupplier([=]() {return level->world->daytime;});
|
||||
bar->setConsumer([=](double val) {level->world->daytime = val;});
|
||||
panel->add(bar);
|
||||
}
|
||||
{
|
||||
auto bar = std::make_shared<TrackBar>(0.0f, 1.0f, 0.0f, 0.005f, 8);
|
||||
bar->supplier([=]() {return WorldRenderer::fog;});
|
||||
bar->consumer([=](double val) {WorldRenderer::fog = val;});
|
||||
bar->setSupplier([=]() {return WorldRenderer::fog;});
|
||||
bar->setConsumer([=](double val) {WorldRenderer::fog = val;});
|
||||
panel->add(bar);
|
||||
}
|
||||
{
|
||||
auto checkbox = std::make_shared<FullCheckBox>(
|
||||
L"Show Chunk Borders", vec2(400, 24)
|
||||
);
|
||||
checkbox->supplier([=]() {
|
||||
checkbox->setSupplier([=]() {
|
||||
return engine->getSettings().debug.showChunkBorders;
|
||||
});
|
||||
checkbox->consumer([=](bool checked) {
|
||||
checkbox->setConsumer([=](bool checked) {
|
||||
engine->getSettings().debug.showChunkBorders = checked;
|
||||
});
|
||||
panel->add(checkbox);
|
||||
@ -291,7 +292,7 @@ void HudRenderer::update(bool visible) {
|
||||
if (!visible && inventoryOpen) {
|
||||
closeInventory();
|
||||
}
|
||||
if (pause && menu->current().panel == nullptr) {
|
||||
if (pause && menu->getCurrent().panel == nullptr) {
|
||||
pause = false;
|
||||
}
|
||||
if (Events::jpressed(keycode::ESCAPE) && !gui->isFocusCaught()) {
|
||||
|
||||
@ -472,10 +472,10 @@ void create_controls_panel(Engine* engine) {
|
||||
}));
|
||||
|
||||
auto trackbar = std::make_shared<TrackBar>(0.1, 10.0, 2.0, 0.1, 4);
|
||||
trackbar->supplier([=]() {
|
||||
trackbar->setSupplier([=]() {
|
||||
return engine->getSettings().camera.sensitivity;
|
||||
});
|
||||
trackbar->consumer([=](double value) {
|
||||
trackbar->setConsumer([=](double value) {
|
||||
engine->getSettings().camera.sensitivity = value;
|
||||
});
|
||||
panel->add(trackbar);
|
||||
@ -512,10 +512,10 @@ void create_settings_panel(Engine* engine) {
|
||||
}));
|
||||
|
||||
auto trackbar = std::make_shared<TrackBar>(3, 66, 10, 1, 3);
|
||||
trackbar->supplier([=]() {
|
||||
trackbar->setSupplier([=]() {
|
||||
return engine->getSettings().chunks.loadDistance;
|
||||
});
|
||||
trackbar->consumer([=](double value) {
|
||||
trackbar->setConsumer([=](double value) {
|
||||
engine->getSettings().chunks.loadDistance = static_cast<uint>(value);
|
||||
});
|
||||
panel->add(trackbar);
|
||||
@ -528,10 +528,10 @@ void create_settings_panel(Engine* engine) {
|
||||
}));
|
||||
|
||||
auto trackbar = std::make_shared<TrackBar>(1, 32, 10, 1, 1);
|
||||
trackbar->supplier([=]() {
|
||||
trackbar->setSupplier([=]() {
|
||||
return engine->getSettings().chunks.loadSpeed;
|
||||
});
|
||||
trackbar->consumer([=](double value) {
|
||||
trackbar->setConsumer([=](double value) {
|
||||
engine->getSettings().chunks.loadSpeed = static_cast<uint>(value);
|
||||
});
|
||||
panel->add(trackbar);
|
||||
@ -545,10 +545,10 @@ void create_settings_panel(Engine* engine) {
|
||||
}));
|
||||
|
||||
auto trackbar = std::make_shared<TrackBar>(1.0, 6.0, 1.0, 0.1, 2);
|
||||
trackbar->supplier([=]() {
|
||||
trackbar->setSupplier([=]() {
|
||||
return engine->getSettings().graphics.fogCurve;
|
||||
});
|
||||
trackbar->consumer([=](double value) {
|
||||
trackbar->setConsumer([=](double value) {
|
||||
engine->getSettings().graphics.fogCurve = value;
|
||||
});
|
||||
panel->add(trackbar);
|
||||
@ -561,10 +561,10 @@ void create_settings_panel(Engine* engine) {
|
||||
}));
|
||||
|
||||
auto trackbar = std::make_shared<TrackBar>(30.0, 120.0, 90, 1, 4);
|
||||
trackbar->supplier([=]() {
|
||||
trackbar->setSupplier([=]() {
|
||||
return engine->getSettings().camera.fov;
|
||||
});
|
||||
trackbar->consumer([=](double value) {
|
||||
trackbar->setConsumer([=](double value) {
|
||||
engine->getSettings().camera.fov = value;
|
||||
});
|
||||
panel->add(trackbar);
|
||||
@ -574,10 +574,10 @@ void create_settings_panel(Engine* engine) {
|
||||
auto checkbox = std::make_shared<FullCheckBox>(
|
||||
langs::get(L"V-Sync", L"settings"), vec2(400, 32)
|
||||
);
|
||||
checkbox->supplier([=]() {
|
||||
checkbox->setSupplier([=]() {
|
||||
return engine->getSettings().display.swapInterval != 0;
|
||||
});
|
||||
checkbox->consumer([=](bool checked) {
|
||||
checkbox->setConsumer([=](bool checked) {
|
||||
engine->getSettings().display.swapInterval = checked;
|
||||
});
|
||||
panel->add(checkbox);
|
||||
@ -587,10 +587,10 @@ void create_settings_panel(Engine* engine) {
|
||||
auto checkbox = std::make_shared<FullCheckBox>(
|
||||
langs::get(L"Backlight", L"settings"), vec2(400, 32)
|
||||
);
|
||||
checkbox->supplier([=]() {
|
||||
checkbox->setSupplier([=]() {
|
||||
return engine->getSettings().graphics.backlight;
|
||||
});
|
||||
checkbox->consumer([=](bool checked) {
|
||||
checkbox->setConsumer([=](bool checked) {
|
||||
engine->getSettings().graphics.backlight = checked;
|
||||
});
|
||||
panel->add(checkbox);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user