buttons-related semantics update + refactor
This commit is contained in:
parent
537a0ca358
commit
6cdb45485b
@ -9,7 +9,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
typedef std::set<unsigned char> DrawGroups;
|
using DrawGroups = std::set<unsigned char>;
|
||||||
|
|
||||||
class Block;
|
class Block;
|
||||||
class ItemDef;
|
class ItemDef;
|
||||||
|
|||||||
@ -13,16 +13,11 @@
|
|||||||
#include "../../window/input.h"
|
#include "../../window/input.h"
|
||||||
#include "../../window/Camera.h"
|
#include "../../window/Camera.h"
|
||||||
|
|
||||||
using glm::vec2;
|
|
||||||
using glm::vec3;
|
|
||||||
using std::string;
|
|
||||||
using std::shared_ptr;
|
|
||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
GUI::GUI() {
|
GUI::GUI() {
|
||||||
container = new Container(vec2(0, 0), vec2(1000));
|
container = std::make_shared<Container>(glm::vec2(0, 0), glm::vec2(1000));
|
||||||
|
uicamera = std::make_unique<Camera>(glm::vec3(), Window::height);
|
||||||
uicamera = new Camera(vec3(), Window::height);
|
|
||||||
uicamera->perspective = false;
|
uicamera->perspective = false;
|
||||||
uicamera->flipped = true;
|
uicamera->flipped = true;
|
||||||
|
|
||||||
@ -32,8 +27,6 @@ GUI::GUI() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GUI::~GUI() {
|
GUI::~GUI() {
|
||||||
delete uicamera;
|
|
||||||
delete container;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<PagesControl> GUI::getMenu() {
|
std::shared_ptr<PagesControl> GUI::getMenu() {
|
||||||
@ -85,7 +78,7 @@ void GUI::actMouse(float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GUI::act(float delta) {
|
void GUI::act(float delta) {
|
||||||
container->setSize(vec2(Window::width, Window::height));
|
container->setSize(glm::vec2(Window::width, Window::height));
|
||||||
container->act(delta);
|
container->act(delta);
|
||||||
auto prevfocus = focus;
|
auto prevfocus = focus;
|
||||||
|
|
||||||
@ -132,7 +125,7 @@ void GUI::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
container->draw(pctx, assets);
|
container->draw(pctx, assets);
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<UINode> GUI::getFocused() const {
|
std::shared_ptr<UINode> GUI::getFocused() const {
|
||||||
return focus;
|
return focus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,19 +137,19 @@ void GUI::addBack(std::shared_ptr<UINode> panel) {
|
|||||||
container->addBack(panel);
|
container->addBack(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::add(shared_ptr<UINode> panel) {
|
void GUI::add(std::shared_ptr<UINode> panel) {
|
||||||
container->add(panel);
|
container->add(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::remove(shared_ptr<UINode> panel) {
|
void GUI::remove(std::shared_ptr<UINode> panel) {
|
||||||
container->remove(panel);
|
container->remove(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::store(string name, shared_ptr<UINode> node) {
|
void GUI::store(std::string name, std::shared_ptr<UINode> node) {
|
||||||
storage[name] = node;
|
storage[name] = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<UINode> GUI::get(string name) {
|
std::shared_ptr<UINode> GUI::get(std::string name) {
|
||||||
auto found = storage.find(name);
|
auto found = storage.find(name);
|
||||||
if (found == storage.end()) {
|
if (found == storage.end()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -164,11 +157,11 @@ shared_ptr<UINode> GUI::get(string name) {
|
|||||||
return found->second;
|
return found->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::remove(string name) {
|
void GUI::remove(std::string name) {
|
||||||
storage.erase(name);
|
storage.erase(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::setFocus(shared_ptr<UINode> node) {
|
void GUI::setFocus(std::shared_ptr<UINode> node) {
|
||||||
if (focus) {
|
if (focus) {
|
||||||
focus->defocus();
|
focus->defocus();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,13 +49,13 @@ namespace gui {
|
|||||||
class PagesControl;
|
class PagesControl;
|
||||||
|
|
||||||
class GUI {
|
class GUI {
|
||||||
Container* container;
|
std::shared_ptr<Container> container;
|
||||||
std::shared_ptr<UINode> hover = nullptr;
|
std::shared_ptr<UINode> hover = nullptr;
|
||||||
std::shared_ptr<UINode> pressed = nullptr;
|
std::shared_ptr<UINode> pressed = nullptr;
|
||||||
std::shared_ptr<UINode> focus = nullptr;
|
std::shared_ptr<UINode> focus = nullptr;
|
||||||
std::unordered_map<std::string, std::shared_ptr<UINode>> storage;
|
std::unordered_map<std::string, std::shared_ptr<UINode>> storage;
|
||||||
|
|
||||||
Camera* uicamera;
|
std::unique_ptr<Camera> uicamera;
|
||||||
std::shared_ptr<PagesControl> menu;
|
std::shared_ptr<PagesControl> menu;
|
||||||
void actMouse(float delta);
|
void actMouse(float delta);
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -88,6 +88,14 @@ void UINode::setInteractive(bool flag) {
|
|||||||
interactive = flag;
|
interactive = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UINode::setResizing(bool flag) {
|
||||||
|
resizing = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UINode::isResizing() const {
|
||||||
|
return resizing;
|
||||||
|
}
|
||||||
|
|
||||||
vec2 UINode::calcCoord() const {
|
vec2 UINode::calcCoord() const {
|
||||||
if (parent) {
|
if (parent) {
|
||||||
return coord + parent->calcCoord() + parent->contentOffset();
|
return coord + parent->calcCoord() + parent->contentOffset();
|
||||||
|
|||||||
@ -13,12 +13,13 @@ namespace gui {
|
|||||||
class UINode;
|
class UINode;
|
||||||
class GUI;
|
class GUI;
|
||||||
|
|
||||||
typedef std::function<void(GUI*)> onaction;
|
using onaction = std::function<void(GUI*)>;
|
||||||
typedef std::function<void(GUI*, double)> onnumberchange;
|
using onnumberchange = std::function<void(GUI*, double)>;
|
||||||
|
|
||||||
enum class Align {
|
enum class Align {
|
||||||
left, center, right
|
left, center, right
|
||||||
};
|
};
|
||||||
|
|
||||||
class UINode {
|
class UINode {
|
||||||
protected:
|
protected:
|
||||||
glm::vec2 coord;
|
glm::vec2 coord;
|
||||||
@ -31,6 +32,7 @@ namespace gui {
|
|||||||
bool pressed = false;
|
bool pressed = false;
|
||||||
bool focused = false;
|
bool focused = false;
|
||||||
bool interactive = true;
|
bool interactive = true;
|
||||||
|
bool resizing = true;
|
||||||
Align align = Align::left;
|
Align align = Align::left;
|
||||||
UINode* parent = nullptr;
|
UINode* parent = nullptr;
|
||||||
UINode(glm::vec2 coord, glm::vec2 size);
|
UINode(glm::vec2 coord, glm::vec2 size);
|
||||||
@ -96,6 +98,9 @@ namespace gui {
|
|||||||
/* Make the element opaque (true) or transparent (false) for cursor */
|
/* Make the element opaque (true) or transparent (false) for cursor */
|
||||||
virtual void setInteractive(bool flag);
|
virtual void setInteractive(bool flag);
|
||||||
|
|
||||||
|
virtual void setResizing(bool flag);
|
||||||
|
virtual bool isResizing() const;
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
|||||||
@ -49,11 +49,19 @@ void Label::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
Font* font = assets->getFont(fontName_);
|
Font* font = assets->getFont(fontName_);
|
||||||
vec2 size = getSize();
|
vec2 size = getSize();
|
||||||
vec2 newsize = vec2(font->calcWidth(text), font->lineHeight());
|
vec2 newsize = vec2(font->calcWidth(text), font->lineHeight());
|
||||||
if (newsize.x > size.x) {
|
|
||||||
setSize(newsize);
|
|
||||||
size = newsize;
|
|
||||||
}
|
|
||||||
vec2 coord = calcCoord();
|
vec2 coord = calcCoord();
|
||||||
|
switch (align) {
|
||||||
|
case Align::left:
|
||||||
|
break;
|
||||||
|
case Align::center:
|
||||||
|
coord.x += (size.x-newsize.x)*0.5f;
|
||||||
|
break;
|
||||||
|
case Align::right:
|
||||||
|
coord.x += size.x-newsize.x;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
font->draw(batch, text, coord.x, coord.y);
|
font->draw(batch, text, coord.x, coord.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,10 +70,6 @@ Label* Label::textSupplier(wstringsupplier supplier) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::setSize(vec2 sizenew) {
|
|
||||||
UINode::setSize(vec2(UINode::getSize().x, sizenew.y));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ================================= Image ====================================
|
// ================================= Image ====================================
|
||||||
Image::Image(std::string texture, vec2 size) : UINode(vec2(), size), texture(texture) {
|
Image::Image(std::string texture, vec2 size) : UINode(vec2(), size), texture(texture) {
|
||||||
setInteractive(false);
|
setInteractive(false);
|
||||||
@ -92,9 +96,19 @@ Button::Button(std::shared_ptr<UINode> content, glm::vec4 padding)
|
|||||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
|
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::Button(std::wstring text, glm::vec4 padding, onaction action)
|
Button::Button(
|
||||||
: Panel(vec2(32,32), padding, 0)
|
std::wstring text,
|
||||||
|
vec4 padding,
|
||||||
|
onaction action,
|
||||||
|
vec2 size
|
||||||
|
) : Panel(size, padding, 0)
|
||||||
{
|
{
|
||||||
|
size = vec2(
|
||||||
|
glm::max(padding.x + padding.z + text.length()*8, size.x),
|
||||||
|
glm::max(padding.y + padding.w + 16, size.y)
|
||||||
|
);
|
||||||
|
setSize(size);
|
||||||
|
|
||||||
if (action) {
|
if (action) {
|
||||||
listenAction(action);
|
listenAction(action);
|
||||||
}
|
}
|
||||||
@ -102,6 +116,7 @@ Button::Button(std::wstring text, glm::vec4 padding, onaction action)
|
|||||||
|
|
||||||
label = std::make_shared<Label>(text);
|
label = std::make_shared<Label>(text);
|
||||||
label->setAlign(Align::center);
|
label->setAlign(Align::center);
|
||||||
|
label->setSize(size-vec2(padding.z+padding.x, padding.w+padding.y));
|
||||||
add(label);
|
add(label);
|
||||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
|
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
|
||||||
}
|
}
|
||||||
@ -188,7 +203,7 @@ void RichButton::drawBackground(const GfxContext* pctx, Assets* assets) {
|
|||||||
|
|
||||||
// ================================ TextBox ===================================
|
// ================================ TextBox ===================================
|
||||||
TextBox::TextBox(std::wstring placeholder, vec4 padding)
|
TextBox::TextBox(std::wstring placeholder, vec4 padding)
|
||||||
: Panel(vec2(200,32), padding, 0, false),
|
: Panel(vec2(200,32), padding, 0),
|
||||||
input(L""),
|
input(L""),
|
||||||
placeholder(placeholder) {
|
placeholder(placeholder) {
|
||||||
label = std::make_shared<Label>(L"");
|
label = std::make_shared<Label>(L"");
|
||||||
@ -312,7 +327,7 @@ void TextBox::text(std::wstring value) {
|
|||||||
|
|
||||||
// ============================== InputBindBox ================================
|
// ============================== InputBindBox ================================
|
||||||
InputBindBox::InputBindBox(Binding& binding, vec4 padding)
|
InputBindBox::InputBindBox(Binding& binding, vec4 padding)
|
||||||
: Panel(vec2(100,32), padding, 0, false),
|
: Panel(vec2(100,32), padding, 0),
|
||||||
binding(binding) {
|
binding(binding) {
|
||||||
label = std::make_shared<Label>(L"");
|
label = std::make_shared<Label>(L"");
|
||||||
add(label);
|
add(label);
|
||||||
@ -437,7 +452,7 @@ FullCheckBox::FullCheckBox(std::wstring text, glm::vec2 size, bool checked)
|
|||||||
: Panel(size),
|
: Panel(size),
|
||||||
checkbox(std::make_shared<CheckBox>(checked)){
|
checkbox(std::make_shared<CheckBox>(checked)){
|
||||||
setColor(vec4(0.0f));
|
setColor(vec4(0.0f));
|
||||||
orientation(Orientation::horizontal);
|
setOrientation(Orientation::horizontal);
|
||||||
|
|
||||||
add(checkbox);
|
add(checkbox);
|
||||||
|
|
||||||
|
|||||||
@ -17,16 +17,16 @@ class Batch2D;
|
|||||||
class Assets;
|
class Assets;
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
typedef std::function<std::wstring()> wstringsupplier;
|
using wstringsupplier = std::function<std::wstring()>;
|
||||||
typedef std::function<void(std::wstring)> wstringconsumer;
|
using wstringconsumer = std::function<void(std::wstring)>;
|
||||||
|
|
||||||
typedef std::function<double()> doublesupplier;
|
using doublesupplier = std::function<double()>;
|
||||||
typedef std::function<void(double)> doubleconsumer;
|
using doubleconsumer = std::function<void(double)>;
|
||||||
|
|
||||||
typedef std::function<bool()> boolsupplier;
|
using boolsupplier = std::function<bool()>;
|
||||||
typedef std::function<void(bool)> boolconsumer;
|
using boolconsumer = std::function<void(bool)>;
|
||||||
|
|
||||||
typedef std::function<bool(const std::wstring&)> wstringchecker;
|
using wstringchecker = std::function<bool(const std::wstring&)>;
|
||||||
|
|
||||||
class Label : public UINode {
|
class Label : public UINode {
|
||||||
protected:
|
protected:
|
||||||
@ -43,7 +43,6 @@ namespace gui {
|
|||||||
virtual void draw(const GfxContext* pctx, Assets* assets) override;
|
virtual void draw(const GfxContext* pctx, Assets* assets) override;
|
||||||
|
|
||||||
virtual Label* textSupplier(wstringsupplier supplier);
|
virtual Label* textSupplier(wstringsupplier supplier);
|
||||||
virtual void setSize(glm::vec2 size) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Image : public UINode {
|
class Image : public UINode {
|
||||||
@ -66,7 +65,8 @@ namespace gui {
|
|||||||
|
|
||||||
Button(std::wstring text,
|
Button(std::wstring text,
|
||||||
glm::vec4 padding,
|
glm::vec4 padding,
|
||||||
onaction action);
|
onaction action,
|
||||||
|
glm::vec2 size=glm::vec2(-1));
|
||||||
|
|
||||||
virtual void drawBackground(const GfxContext* pctx, Assets* assets) override;
|
virtual void drawBackground(const GfxContext* pctx, Assets* assets) override;
|
||||||
|
|
||||||
@ -85,7 +85,6 @@ namespace gui {
|
|||||||
|
|
||||||
class RichButton : public Container {
|
class RichButton : public Container {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
glm::vec4 pressedColor {0.0f, 0.0f, 0.0f, 0.95f};
|
glm::vec4 pressedColor {0.0f, 0.0f, 0.0f, 0.95f};
|
||||||
std::vector<onaction> actions;
|
std::vector<onaction> actions;
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -139,23 +139,27 @@ void Container::listenInterval(float interval, ontimeout callback, int repeat) {
|
|||||||
intervalEvents.push_back({callback, interval, 0.0f, repeat});
|
intervalEvents.push_back({callback, interval, 0.0f, repeat});
|
||||||
}
|
}
|
||||||
|
|
||||||
Panel::Panel(vec2 size, glm::vec4 padding, float interval, bool resizing)
|
void Container::setSize(glm::vec2 size) {
|
||||||
|
UINode::setSize(size);
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
Panel::Panel(vec2 size, glm::vec4 padding, float interval)
|
||||||
: Container(vec2(), size),
|
: Container(vec2(), size),
|
||||||
padding(padding),
|
padding(padding),
|
||||||
interval(interval),
|
interval(interval) {
|
||||||
resizing_(resizing) {
|
|
||||||
setColor(vec4(0.0f, 0.0f, 0.0f, 0.75f));
|
setColor(vec4(0.0f, 0.0f, 0.0f, 0.75f));
|
||||||
}
|
}
|
||||||
|
|
||||||
Panel::~Panel() {
|
Panel::~Panel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::maxLength(int value) {
|
void Panel::setMaxLength(int value) {
|
||||||
maxLength_ = value;
|
maxLength = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Panel::maxLength() const {
|
int Panel::getMaxLength() const {
|
||||||
return maxLength_;
|
return maxLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::setPadding(glm::vec4 padding) {
|
void Panel::setPadding(glm::vec4 padding) {
|
||||||
@ -166,43 +170,42 @@ glm::vec4 Panel::getPadding() const {
|
|||||||
return padding;
|
return padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Panel::cropToContent() {
|
||||||
|
if (maxLength > 0.0f) {
|
||||||
|
setSize(vec2(getSize().x, glm::min(maxLength, actualLength)));
|
||||||
|
} else {
|
||||||
|
setSize(vec2(getSize().x, actualLength));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Panel::add(std::shared_ptr<UINode> node) {
|
||||||
|
Container::add(node);
|
||||||
|
refresh();
|
||||||
|
cropToContent();
|
||||||
|
}
|
||||||
|
|
||||||
void Panel::refresh() {
|
void Panel::refresh() {
|
||||||
float x = padding.x;
|
float x = padding.x;
|
||||||
float y = padding.y;
|
float y = padding.y;
|
||||||
vec2 size = getSize();
|
vec2 size = getSize();
|
||||||
if (orientation_ == Orientation::vertical) {
|
if (orientation == Orientation::vertical) {
|
||||||
float maxw = size.x;
|
float maxw = size.x;
|
||||||
for (auto& node : nodes) {
|
for (auto& node : nodes) {
|
||||||
vec2 nodesize = node->getSize();
|
vec2 nodesize = node->getSize();
|
||||||
const vec4 margin = node->getMargin();
|
const vec4 margin = node->getMargin();
|
||||||
y += margin.y;
|
y += margin.y;
|
||||||
|
|
||||||
float ex;
|
float ex = x + margin.x;
|
||||||
float spacex = size.x - margin.z - padding.z;
|
|
||||||
switch (node->getAlign()) {
|
|
||||||
case Align::center:
|
|
||||||
ex = x + fmax(0.0f, spacex - nodesize.x) / 2.0f;
|
|
||||||
break;
|
|
||||||
case Align::right:
|
|
||||||
ex = x + spacex - nodesize.x;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ex = x + margin.x;
|
|
||||||
}
|
|
||||||
node->setCoord(vec2(ex, y));
|
node->setCoord(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;
|
||||||
node->setSize(vec2(width, nodesize.y));;
|
if (node->isResizing()) {
|
||||||
|
node->setSize(vec2(width, nodesize.y));
|
||||||
|
}
|
||||||
node->refresh();
|
node->refresh();
|
||||||
maxw = fmax(maxw, ex+node->getSize().x+margin.z+padding.z);
|
maxw = fmax(maxw, ex+node->getSize().x+margin.z+padding.z);
|
||||||
}
|
}
|
||||||
if (resizing_) {
|
|
||||||
if (maxLength_)
|
|
||||||
setSize(vec2(size.x, glm::min(maxLength_, (int)(y+padding.w))));
|
|
||||||
else
|
|
||||||
setSize(vec2(size.x, y+padding.w));
|
|
||||||
}
|
|
||||||
actualLength = y + padding.w;
|
actualLength = y + padding.w;
|
||||||
} else {
|
} else {
|
||||||
float maxh = size.y;
|
float maxh = size.y;
|
||||||
@ -216,22 +219,16 @@ void Panel::refresh() {
|
|||||||
node->refresh();
|
node->refresh();
|
||||||
maxh = fmax(maxh, y+margin.y+node->getSize().y+margin.w+padding.w);
|
maxh = fmax(maxh, y+margin.y+node->getSize().y+margin.w+padding.w);
|
||||||
}
|
}
|
||||||
if (resizing_) {
|
|
||||||
if (maxLength_)
|
|
||||||
setSize(vec2(glm::min(maxLength_, (int)(x+padding.z)), size.y));
|
|
||||||
else
|
|
||||||
setSize(vec2(x+padding.z, size.y));
|
|
||||||
}
|
|
||||||
actualLength = size.y;
|
actualLength = size.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::orientation(Orientation orientation) {
|
void Panel::setOrientation(Orientation orientation) {
|
||||||
this->orientation_ = orientation;
|
this->orientation = orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
Orientation Panel::orientation() const {
|
Orientation Panel::getOrientation() const {
|
||||||
return orientation_;
|
return orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
PagesControl::PagesControl() : Container(vec2(), vec2(1)){
|
PagesControl::PagesControl() : Container(vec2(), vec2(1)){
|
||||||
|
|||||||
@ -12,7 +12,8 @@ class Batch2D;
|
|||||||
class Assets;
|
class Assets;
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
typedef std::function<void()> ontimeout;
|
using ontimeout = std::function<void()>;
|
||||||
|
|
||||||
struct IntervalEvent {
|
struct IntervalEvent {
|
||||||
ontimeout callback;
|
ontimeout callback;
|
||||||
float interval;
|
float interval;
|
||||||
@ -45,31 +46,34 @@ namespace gui {
|
|||||||
virtual void scrollable(bool flag);
|
virtual void scrollable(bool flag);
|
||||||
void listenInterval(float interval, ontimeout callback, int repeat=-1);
|
void listenInterval(float interval, ontimeout callback, int repeat=-1);
|
||||||
virtual glm::vec2 contentOffset() override {return glm::vec2(0.0f, scroll);};
|
virtual glm::vec2 contentOffset() override {return glm::vec2(0.0f, scroll);};
|
||||||
|
virtual void setSize(glm::vec2 size);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Panel : public Container {
|
class Panel : public Container {
|
||||||
protected:
|
protected:
|
||||||
Orientation orientation_ = Orientation::vertical;
|
Orientation orientation = Orientation::vertical;
|
||||||
glm::vec4 padding {2.0f};
|
glm::vec4 padding {2.0f};
|
||||||
float interval = 2.0f;
|
float interval = 2.0f;
|
||||||
bool resizing_;
|
int maxLength = 0;
|
||||||
int maxLength_ = 0;
|
|
||||||
public:
|
public:
|
||||||
Panel(
|
Panel(
|
||||||
glm::vec2 size,
|
glm::vec2 size,
|
||||||
glm::vec4 padding=glm::vec4(2.0f),
|
glm::vec4 padding=glm::vec4(2.0f),
|
||||||
float interval=2.0f,
|
float interval=2.0f
|
||||||
bool resizing=true
|
|
||||||
);
|
);
|
||||||
virtual ~Panel();
|
virtual ~Panel();
|
||||||
|
|
||||||
virtual void orientation(Orientation orientation);
|
virtual void cropToContent();
|
||||||
Orientation orientation() const;
|
|
||||||
|
virtual void setOrientation(Orientation orientation);
|
||||||
|
Orientation getOrientation() const;
|
||||||
|
|
||||||
|
virtual void add(std::shared_ptr<UINode> node) override;
|
||||||
|
|
||||||
virtual void refresh() override;
|
virtual void refresh() override;
|
||||||
|
|
||||||
virtual void maxLength(int value);
|
virtual void setMaxLength(int value);
|
||||||
int maxLength() const;
|
int getMaxLength() const;
|
||||||
|
|
||||||
virtual void setPadding(glm::vec4 padding);
|
virtual void setPadding(glm::vec4 padding);
|
||||||
glm::vec4 getPadding() const;
|
glm::vec4 getPadding() const;
|
||||||
|
|||||||
@ -98,7 +98,7 @@ std::shared_ptr<UINode> HudRenderer::createDebugPanel(Engine* engine) {
|
|||||||
|
|
||||||
for (int ax = 0; ax < 3; ax++){
|
for (int ax = 0; ax < 3; ax++){
|
||||||
auto sub = std::make_shared<Panel>(vec2(10, 27), vec4(0.0f));
|
auto sub = std::make_shared<Panel>(vec2(10, 27), vec4(0.0f));
|
||||||
sub->orientation(Orientation::horizontal);
|
sub->setOrientation(Orientation::horizontal);
|
||||||
|
|
||||||
std::wstring str = L"x: ";
|
std::wstring str = L"x: ";
|
||||||
str[0] += ax;
|
str[0] += ax;
|
||||||
|
|||||||
@ -72,8 +72,8 @@ static std::shared_ptr<Panel> create_page(
|
|||||||
|
|
||||||
static std::shared_ptr<Button> create_button(
|
static std::shared_ptr<Button> create_button(
|
||||||
std::wstring text,
|
std::wstring text,
|
||||||
glm::vec4 padding,
|
vec4 padding,
|
||||||
glm::vec4 margin,
|
vec4 margin,
|
||||||
gui::onaction action
|
gui::onaction action
|
||||||
) {
|
) {
|
||||||
auto btn = std::make_shared<Button>(
|
auto btn = std::make_shared<Button>(
|
||||||
@ -100,7 +100,7 @@ static void show_content_missing(
|
|||||||
for (auto& entry : lut->getMissingContent()) {
|
for (auto& entry : lut->getMissingContent()) {
|
||||||
auto hpanel = std::make_shared<Panel>(vec2(500, 30));
|
auto hpanel = std::make_shared<Panel>(vec2(500, 30));
|
||||||
hpanel->setColor(vec4(0.0f));
|
hpanel->setColor(vec4(0.0f));
|
||||||
hpanel->orientation(Orientation::horizontal);
|
hpanel->setOrientation(Orientation::horizontal);
|
||||||
|
|
||||||
auto namelabel = std::make_shared<Label>(util::str2wstr_utf8(entry.name));
|
auto namelabel = std::make_shared<Label>(util::str2wstr_utf8(entry.name));
|
||||||
namelabel->setColor(vec4(1.0f, 0.2f, 0.2f, 0.5f));
|
namelabel->setColor(vec4(1.0f, 0.2f, 0.2f, 0.5f));
|
||||||
@ -112,7 +112,7 @@ static void show_content_missing(
|
|||||||
hpanel->add(namelabel);
|
hpanel->add(namelabel);
|
||||||
subpanel->add(hpanel);
|
subpanel->add(hpanel);
|
||||||
}
|
}
|
||||||
subpanel->maxLength(400);
|
subpanel->setMaxLength(400);
|
||||||
panel->add(subpanel);
|
panel->add(subpanel);
|
||||||
|
|
||||||
panel->add(std::make_shared<Button>(
|
panel->add(std::make_shared<Button>(
|
||||||
@ -213,7 +213,7 @@ void open_world(std::string name, Engine* engine) {
|
|||||||
std::shared_ptr<Panel> create_worlds_panel(Engine* engine) {
|
std::shared_ptr<Panel> create_worlds_panel(Engine* engine) {
|
||||||
auto panel = std::make_shared<Panel>(vec2(390, 200), vec4(5.0f));
|
auto panel = std::make_shared<Panel>(vec2(390, 200), vec4(5.0f));
|
||||||
panel->setColor(vec4(1.0f, 1.0f, 1.0f, 0.07f));
|
panel->setColor(vec4(1.0f, 1.0f, 1.0f, 0.07f));
|
||||||
panel->maxLength(400);
|
panel->setMaxLength(400);
|
||||||
|
|
||||||
auto paths = engine->getPaths();
|
auto paths = engine->getPaths();
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ std::shared_ptr<Panel> create_packs_panel(
|
|||||||
auto assets = engine->getAssets();
|
auto assets = engine->getAssets();
|
||||||
auto panel = std::make_shared<Panel>(vec2(PACKS_PANEL_WIDTH, 200), vec4(5.0f));
|
auto panel = std::make_shared<Panel>(vec2(PACKS_PANEL_WIDTH, 200), vec4(5.0f));
|
||||||
panel->setColor(vec4(1.0f, 1.0f, 1.0f, 0.07f));
|
panel->setColor(vec4(1.0f, 1.0f, 1.0f, 0.07f));
|
||||||
panel->maxLength(400);
|
panel->setMaxLength(400);
|
||||||
panel->scrollable(true);
|
panel->scrollable(true);
|
||||||
|
|
||||||
for (auto& pack : packs) {
|
for (auto& pack : packs) {
|
||||||
@ -314,7 +314,7 @@ std::shared_ptr<Panel> create_packs_panel(
|
|||||||
descriptionlabel->setColor(vec4(1, 1, 1, 0.7f));
|
descriptionlabel->setColor(vec4(1, 1, 1, 0.7f));
|
||||||
packpanel->add(descriptionlabel, vec2(80, 28));
|
packpanel->add(descriptionlabel, vec2(80, 28));
|
||||||
|
|
||||||
packpanel->add(std::make_shared<Image>(icon, glm::vec2(64)), vec2(8));
|
packpanel->add(std::make_shared<Image>(icon, vec2(64)), vec2(8));
|
||||||
|
|
||||||
packpanel->setColor(vec4(0.06f, 0.12f, 0.18f, 0.7f));
|
packpanel->setColor(vec4(0.06f, 0.12f, 0.18f, 0.7f));
|
||||||
panel->add(packpanel);
|
panel->add(packpanel);
|
||||||
@ -479,13 +479,13 @@ void create_controls_panel(Engine* engine) {
|
|||||||
|
|
||||||
auto scrollPanel = std::make_shared<Panel>(vec2(400, 200), vec4(2.0f), 1.0f);
|
auto scrollPanel = std::make_shared<Panel>(vec2(400, 200), vec4(2.0f), 1.0f);
|
||||||
scrollPanel->setColor(vec4(0.0f, 0.0f, 0.0f, 0.3f));
|
scrollPanel->setColor(vec4(0.0f, 0.0f, 0.0f, 0.3f));
|
||||||
scrollPanel->maxLength(400);
|
scrollPanel->setMaxLength(400);
|
||||||
for (auto& entry : Events::bindings){
|
for (auto& entry : Events::bindings){
|
||||||
std::string bindname = entry.first;
|
std::string bindname = entry.first;
|
||||||
|
|
||||||
auto subpanel = std::make_shared<Panel>(vec2(400, 40), vec4(5.0f), 1.0f);
|
auto subpanel = std::make_shared<Panel>(vec2(400, 40), vec4(5.0f), 1.0f);
|
||||||
subpanel->setColor(vec4(0.0f));
|
subpanel->setColor(vec4(0.0f));
|
||||||
subpanel->orientation(Orientation::horizontal);
|
subpanel->setOrientation(Orientation::horizontal);
|
||||||
subpanel->add(std::make_shared<InputBindBox>(entry.second));
|
subpanel->add(std::make_shared<InputBindBox>(entry.second));
|
||||||
|
|
||||||
auto label = std::make_shared<Label>(langs::get(util::str2wstr_utf8(bindname)));
|
auto label = std::make_shared<Label>(langs::get(util::str2wstr_utf8(bindname)));
|
||||||
|
|||||||
@ -4,18 +4,17 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef unsigned int uint;
|
using uint = unsigned int;
|
||||||
|
|
||||||
// use for bytes arrays
|
// use for bytes arrays
|
||||||
typedef uint8_t ubyte;
|
using ubyte = uint8_t;
|
||||||
|
|
||||||
// content indices
|
// content indices
|
||||||
typedef uint32_t itemid_t;
|
using itemid_t = uint32_t;
|
||||||
typedef uint16_t blockid_t;
|
using blockid_t = uint16_t;
|
||||||
|
|
||||||
typedef uint32_t itemcount_t;
|
using itemcount_t = uint32_t;
|
||||||
|
using blockstate_t = uint16_t;
|
||||||
typedef uint16_t blockstate_t;
|
using light_t = uint16_t;
|
||||||
typedef uint16_t light_t;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user