minor refactor
This commit is contained in:
+1
-1
@@ -206,7 +206,7 @@ void Engine::renderFrame(Batch2D& batch) {
|
|||||||
|
|
||||||
Viewport viewport(Window::width, Window::height);
|
Viewport viewport(Window::width, Window::height);
|
||||||
DrawContext ctx(nullptr, viewport, &batch);
|
DrawContext ctx(nullptr, viewport, &batch);
|
||||||
gui->draw(&ctx, assets.get());
|
gui->draw(ctx, *assets);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::processPostRunnables() {
|
void Engine::processPostRunnables() {
|
||||||
|
|||||||
@@ -95,16 +95,16 @@ class Hud : public util::ObjectsKeeper {
|
|||||||
/// @brief Inventories interaction agent (grabbed item)
|
/// @brief Inventories interaction agent (grabbed item)
|
||||||
std::shared_ptr<gui::SlotView> exchangeSlot;
|
std::shared_ptr<gui::SlotView> exchangeSlot;
|
||||||
/// @brief Exchange slot inventory (1 slot only)
|
/// @brief Exchange slot inventory (1 slot only)
|
||||||
std::shared_ptr<Inventory> exchangeSlotInv = nullptr;
|
std::shared_ptr<Inventory> exchangeSlotInv;
|
||||||
/// @brief List of all controlled hud elements
|
/// @brief List of all controlled hud elements
|
||||||
std::vector<HudElement> elements;
|
std::vector<HudElement> elements;
|
||||||
|
|
||||||
/// @brief Player inventory view
|
/// @brief Player inventory view
|
||||||
std::shared_ptr<gui::InventoryView> inventoryView = nullptr;
|
std::shared_ptr<gui::InventoryView> inventoryView;
|
||||||
/// @brief Block inventory view
|
/// @brief Block inventory view
|
||||||
std::shared_ptr<gui::InventoryView> blockUI = nullptr;
|
std::shared_ptr<gui::InventoryView> blockUI;
|
||||||
/// @brief Secondary inventory view
|
/// @brief Secondary inventory view
|
||||||
std::shared_ptr<gui::InventoryView> secondInvView = nullptr;
|
std::shared_ptr<gui::InventoryView> secondInvView;
|
||||||
/// @brief Position of the block open
|
/// @brief Position of the block open
|
||||||
glm::ivec3 blockPos {};
|
glm::ivec3 blockPos {};
|
||||||
/// @brief Id of the block open (used to detect block destruction or replacement)
|
/// @brief Id of the block open (used to detect block destruction or replacement)
|
||||||
@@ -114,9 +114,9 @@ class Hud : public util::ObjectsKeeper {
|
|||||||
/// @brief Provide cheat controllers to the debug panel
|
/// @brief Provide cheat controllers to the debug panel
|
||||||
bool allowDebugCheats = true;
|
bool allowDebugCheats = true;
|
||||||
/// @brief UI element will be dynamicly positioned near to inventory or in screen center
|
/// @brief UI element will be dynamicly positioned near to inventory or in screen center
|
||||||
std::shared_ptr<gui::UINode> secondUI = nullptr;
|
std::shared_ptr<gui::UINode> secondUI;
|
||||||
|
|
||||||
std::shared_ptr<gui::UINode> debugMinimap = nullptr;
|
std::shared_ptr<gui::UINode> debugMinimap;
|
||||||
|
|
||||||
std::unique_ptr<ImageData> debugImgWorldGen;
|
std::unique_ptr<ImageData> debugImgWorldGen;
|
||||||
|
|
||||||
|
|||||||
@@ -197,18 +197,18 @@ void GUI::act(float delta, const Viewport& vp) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::draw(const DrawContext* pctx, Assets* assets) {
|
void GUI::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
auto& viewport = pctx->getViewport();
|
auto& viewport = pctx.getViewport();
|
||||||
glm::vec2 wsize = viewport.size();
|
glm::vec2 wsize = viewport.size();
|
||||||
|
|
||||||
menu->setPos((wsize - menu->getSize()) / 2.0f);
|
menu->setPos((wsize - menu->getSize()) / 2.0f);
|
||||||
uicamera->setFov(wsize.y);
|
uicamera->setFov(wsize.y);
|
||||||
|
|
||||||
auto uishader = assets->get<Shader>("ui");
|
auto uishader = assets.get<Shader>("ui");
|
||||||
uishader->use();
|
uishader->use();
|
||||||
uishader->uniformMatrix("u_projview", uicamera->getProjView());
|
uishader->uniformMatrix("u_projview", uicamera->getProjView());
|
||||||
|
|
||||||
pctx->getBatch2D()->begin();
|
pctx.getBatch2D()->begin();
|
||||||
container->draw(pctx, assets);
|
container->draw(pctx, assets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ namespace gui {
|
|||||||
/// @brief Draw all visible elements on main container
|
/// @brief Draw all visible elements on main container
|
||||||
/// @param pctx parent graphics context
|
/// @param pctx parent graphics context
|
||||||
/// @param assets active assets storage
|
/// @param assets active assets storage
|
||||||
void draw(const DrawContext* pctx, Assets* assets);
|
void draw(const DrawContext& pctx, const Assets& assets);
|
||||||
|
|
||||||
/// @brief Add element to the main container
|
/// @brief Add element to the main container
|
||||||
/// @param node UI element
|
/// @param node UI element
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ Button::Button(
|
|||||||
|
|
||||||
void Button::setText(std::wstring text) {
|
void Button::setText(std::wstring text) {
|
||||||
if (label) {
|
if (label) {
|
||||||
label->setText(text);
|
label->setText(std::move(text));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,9 +77,9 @@ void Button::refresh() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::drawBackground(const DrawContext* pctx, Assets*) {
|
void Button::drawBackground(const DrawContext& pctx, const Assets&) {
|
||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx.getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->setColor(calcColor());
|
batch->setColor(calcColor());
|
||||||
batch->rect(pos.x, pos.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace gui {
|
|||||||
|
|
||||||
class Button : public Panel {
|
class Button : public Panel {
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<Label> label = nullptr;
|
std::shared_ptr<Label> label;
|
||||||
public:
|
public:
|
||||||
Button(const std::shared_ptr<UINode>& content,
|
Button(const std::shared_ptr<UINode>& content,
|
||||||
glm::vec4 padding=glm::vec4(2.0f));
|
glm::vec4 padding=glm::vec4(2.0f));
|
||||||
@@ -17,7 +17,9 @@ namespace gui {
|
|||||||
const onaction& action,
|
const onaction& action,
|
||||||
glm::vec2 size=glm::vec2(-1));
|
glm::vec2 size=glm::vec2(-1));
|
||||||
|
|
||||||
virtual void drawBackground(const DrawContext* pctx, Assets* assets) override;
|
virtual void drawBackground(
|
||||||
|
const DrawContext& pctx, const Assets& assets
|
||||||
|
) override;
|
||||||
|
|
||||||
virtual Align getTextAlign() const;
|
virtual Align getTextAlign() const;
|
||||||
virtual void setTextAlign(Align align);
|
virtual void setTextAlign(Align align);
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ CheckBox::CheckBox(bool checked) : UINode(glm::vec2(32.0f)), checked(checked) {
|
|||||||
setHoverColor({0.05f, 0.1f, 0.2f, 0.75f});
|
setHoverColor({0.05f, 0.1f, 0.2f, 0.75f});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::draw(const DrawContext* pctx, Assets*) {
|
void CheckBox::draw(const DrawContext& pctx, const Assets&) {
|
||||||
if (supplier) {
|
if (supplier) {
|
||||||
checked = supplier();
|
checked = supplier();
|
||||||
}
|
}
|
||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx.getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->setColor(checked ? checkColor : calcColor());
|
batch->setColor(checked ? checkColor : calcColor());
|
||||||
batch->rect(pos.x, pos.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace gui {
|
|||||||
public:
|
public:
|
||||||
CheckBox(bool checked=false);
|
CheckBox(bool checked=false);
|
||||||
|
|
||||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
|
|
||||||
virtual void mouseRelease(GUI*, int x, int y) override;
|
virtual void mouseRelease(GUI*, int x, int y) override;
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,15 @@ Container::~Container() {
|
|||||||
Container::clear();
|
Container::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<UINode> Container::getAt(glm::vec2 pos, std::shared_ptr<UINode> self) {
|
std::shared_ptr<UINode> Container::getAt(
|
||||||
|
const glm::vec2& pos, const std::shared_ptr<UINode>& self
|
||||||
|
) {
|
||||||
if (!isInteractive() || !isEnabled()) {
|
if (!isInteractive() || !isEnabled()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!isInside(pos)) return nullptr;
|
if (!isInside(pos)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
int diff = (actualLength-size.y);
|
int diff = (actualLength-size.y);
|
||||||
if (scrollable && diff > 0 && pos.x > calcPos().x + getSize().x - scrollBarWidth) {
|
if (scrollable && diff > 0 && pos.x > calcPos().x + getSize().x - scrollBarWidth) {
|
||||||
return UINode::getAt(pos, self);
|
return UINode::getAt(pos, self);
|
||||||
@@ -114,16 +117,16 @@ void Container::setScrollable(bool flag) {
|
|||||||
scrollable = flag;
|
scrollable = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::draw(const DrawContext* pctx, Assets* assets) {
|
void Container::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
glm::vec2 size = getSize();
|
glm::vec2 size = getSize();
|
||||||
drawBackground(pctx, assets);
|
drawBackground(pctx, assets);
|
||||||
|
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx.getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
if (!nodes.empty()) {
|
if (!nodes.empty()) {
|
||||||
batch->flush();
|
batch->flush();
|
||||||
DrawContext ctx = pctx->sub();
|
DrawContext ctx = pctx.sub();
|
||||||
ctx.setScissors(glm::vec4(pos.x, pos.y, glm::ceil(size.x), glm::ceil(size.y)));
|
ctx.setScissors(glm::vec4(pos.x, pos.y, glm::ceil(size.x), glm::ceil(size.y)));
|
||||||
for (const auto& node : nodes) {
|
for (const auto& node : nodes) {
|
||||||
if (node->isVisible())
|
if (node->isVisible())
|
||||||
@@ -145,19 +148,19 @@ void Container::draw(const DrawContext* pctx, Assets* assets) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::drawBackground(const DrawContext* pctx, Assets*) {
|
void Container::drawBackground(const DrawContext& pctx, const Assets&) {
|
||||||
glm::vec4 color = calcColor();
|
glm::vec4 color = calcColor();
|
||||||
if (color.a <= 0.001f)
|
if (color.a <= 0.001f)
|
||||||
return;
|
return;
|
||||||
glm::vec2 pos = calcPos();
|
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(pos.x, pos.y, glm::ceil(size.x), glm::ceil(size.y));
|
batch->rect(pos.x, pos.y, glm::ceil(size.x), glm::ceil(size.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::add(const std::shared_ptr<UINode> &node) {
|
void Container::add(const std::shared_ptr<UINode>& node) {
|
||||||
nodes.push_back(node);
|
nodes.push_back(node);
|
||||||
node->setParent(this);
|
node->setParent(this);
|
||||||
node->reposition();
|
node->reposition();
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ namespace gui {
|
|||||||
virtual ~Container();
|
virtual ~Container();
|
||||||
|
|
||||||
virtual void act(float delta) override;
|
virtual void act(float delta) override;
|
||||||
virtual void drawBackground(const DrawContext* pctx, Assets* assets);
|
virtual void drawBackground(const DrawContext& pctx, const Assets& assets);
|
||||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
virtual std::shared_ptr<UINode> getAt(const glm::vec2& pos, const std::shared_ptr<UINode>& self) override;
|
||||||
virtual void add(const std::shared_ptr<UINode> &node);
|
virtual void add(const std::shared_ptr<UINode>& node);
|
||||||
virtual void add(const std::shared_ptr<UINode> &node, glm::vec2 pos);
|
virtual void add(const std::shared_ptr<UINode>& node, glm::vec2 pos);
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
virtual void remove(const std::shared_ptr<UINode>& node);
|
virtual void remove(const std::shared_ptr<UINode>& node);
|
||||||
virtual void remove(const std::string& id);
|
virtual void remove(const std::string& id);
|
||||||
|
|||||||
@@ -15,21 +15,21 @@ Image::Image(std::string texture, glm::vec2 size) : UINode(size), texture(std::m
|
|||||||
setInteractive(false);
|
setInteractive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::draw(const DrawContext* pctx, Assets* assets) {
|
void Image::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx.getBatch2D();
|
||||||
|
|
||||||
Texture* texture = nullptr;
|
Texture* texture = nullptr;
|
||||||
auto separator = this->texture.find(':');
|
auto separator = this->texture.find(':');
|
||||||
if (separator == std::string::npos) {
|
if (separator == std::string::npos) {
|
||||||
texture = assets->get<Texture>(this->texture);
|
texture = assets.get<Texture>(this->texture);
|
||||||
batch->texture(texture);
|
batch->texture(texture);
|
||||||
if (texture && autoresize) {
|
if (texture && autoresize) {
|
||||||
setSize(glm::vec2(texture->getWidth(), texture->getHeight()));
|
setSize(glm::vec2(texture->getWidth(), texture->getHeight()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto atlasName = this->texture.substr(0, separator);
|
auto atlasName = this->texture.substr(0, separator);
|
||||||
if (auto atlas = assets->get<Atlas>(atlasName)) {
|
if (auto atlas = assets.get<Atlas>(atlasName)) {
|
||||||
if (auto region = atlas->getIf(this->texture.substr(separator+1))) {
|
if (auto region = atlas->getIf(this->texture.substr(separator+1))) {
|
||||||
texture = atlas->getTexture();
|
texture = atlas->getTexture();
|
||||||
batch->texture(atlas->getTexture());
|
batch->texture(atlas->getTexture());
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace gui {
|
|||||||
public:
|
public:
|
||||||
Image(std::string texture, glm::vec2 size=glm::vec2(32,32));
|
Image(std::string texture, glm::vec2 size=glm::vec2(32,32));
|
||||||
|
|
||||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
|
|
||||||
virtual void setAutoResize(bool flag);
|
virtual void setAutoResize(bool flag);
|
||||||
virtual bool isAutoResize() const;
|
virtual bool isAutoResize() const;
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ using namespace gui;
|
|||||||
|
|
||||||
InputBindBox::InputBindBox(Binding& binding, glm::vec4 padding)
|
InputBindBox::InputBindBox(Binding& binding, glm::vec4 padding)
|
||||||
: Panel(glm::vec2(100,32), padding, 0),
|
: Panel(glm::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);
|
||||||
setScrollable(false);
|
setScrollable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputBindBox::drawBackground(const DrawContext* pctx, Assets*) {
|
void InputBindBox::drawBackground(const DrawContext& pctx, const Assets&) {
|
||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx.getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->setColor(isFocused() ? focusedColor : calcColor());
|
batch->setColor(isFocused() ? focusedColor : calcColor());
|
||||||
batch->rect(pos.x, pos.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ namespace gui {
|
|||||||
Binding& binding;
|
Binding& binding;
|
||||||
public:
|
public:
|
||||||
InputBindBox(Binding& binding, glm::vec4 padding=glm::vec4(6.0f));
|
InputBindBox(Binding& binding, glm::vec4 padding=glm::vec4(6.0f));
|
||||||
virtual void drawBackground(const DrawContext* pctx, Assets* assets) override;
|
|
||||||
|
virtual void drawBackground(
|
||||||
|
const DrawContext& pctx, const Assets& assets
|
||||||
|
) override;
|
||||||
|
|
||||||
virtual void clicked(GUI*, mousecode button) override;
|
virtual void clicked(GUI*, mousecode button) override;
|
||||||
virtual void keyPressed(keycode key) override;
|
virtual void keyPressed(keycode key) override;
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ SlotView::SlotView(
|
|||||||
setTooltipDelay(0.0f);
|
setTooltipDelay(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
void SlotView::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
if (bound == nullptr) {
|
if (bound == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
|||||||
color = glm::vec4(1, 1, 1, 0.2f);
|
color = glm::vec4(1, 1, 1, 0.2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx.getBatch2D();
|
||||||
batch->setColor(color);
|
batch->setColor(color);
|
||||||
if (color.a > 0.0) {
|
if (color.a > 0.0) {
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
@@ -157,7 +157,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
|||||||
|
|
||||||
batch->setColor(glm::vec4(1.0f));
|
batch->setColor(glm::vec4(1.0f));
|
||||||
|
|
||||||
auto previews = assets->get<Atlas>("block-previews");
|
auto previews = assets.get<Atlas>("block-previews");
|
||||||
auto indices = content->getIndices();
|
auto indices = content->getIndices();
|
||||||
|
|
||||||
auto& item = indices->items.require(stack.getItemId());
|
auto& item = indices->items.require(stack.getItemId());
|
||||||
@@ -176,7 +176,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
|||||||
}
|
}
|
||||||
case ItemIconType::SPRITE: {
|
case ItemIconType::SPRITE: {
|
||||||
auto textureRegion =
|
auto textureRegion =
|
||||||
util::get_texture_region(*assets, item.icon, "blocks:notfound");
|
util::get_texture_region(assets, item.icon, "blocks:notfound");
|
||||||
|
|
||||||
batch->texture(textureRegion.texture);
|
batch->texture(textureRegion.texture);
|
||||||
batch->rect(
|
batch->rect(
|
||||||
@@ -187,7 +187,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getCount() > 1) {
|
if (stack.getCount() > 1) {
|
||||||
auto font = assets->get<Font>("normal");
|
auto font = assets.get<Font>("normal");
|
||||||
std::wstring text = std::to_wstring(stack.getCount());
|
std::wstring text = std::to_wstring(stack.getCount());
|
||||||
|
|
||||||
int x = pos.x+slotSize-text.length()*8;
|
int x = pos.x+slotSize-text.length()*8;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace gui {
|
|||||||
public:
|
public:
|
||||||
SlotView(SlotLayout layout);
|
SlotView(SlotLayout layout);
|
||||||
|
|
||||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
|
|
||||||
void setHighlighted(bool flag);
|
void setHighlighted(bool flag);
|
||||||
bool isHighlighted() const;
|
bool isHighlighted() const;
|
||||||
|
|||||||
@@ -158,9 +158,9 @@ uint Label::getLinesNumber() const {
|
|||||||
return cache.lines.size();
|
return cache.lines.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::draw(const DrawContext* pctx, Assets* assets) {
|
void Label::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx.getBatch2D();
|
||||||
auto font = assets->get<Font>(fontName);
|
auto font = assets.get<Font>(fontName);
|
||||||
cache.prepare(font, static_cast<size_t>(glm::abs(getSize().x)));
|
cache.prepare(font, static_cast<size_t>(glm::abs(getSize().x)));
|
||||||
|
|
||||||
if (supplier) {
|
if (supplier) {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ namespace gui {
|
|||||||
virtual uint getLinesNumber() const;
|
virtual uint getLinesNumber() const;
|
||||||
virtual bool isFakeLine(size_t line) const;
|
virtual bool isFakeLine(size_t line) const;
|
||||||
|
|
||||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
|
|
||||||
virtual void textSupplier(wstringsupplier supplier);
|
virtual void textSupplier(wstringsupplier supplier);
|
||||||
|
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ namespace gui {
|
|||||||
/// @param history previous page will not be saved in history if false
|
/// @param history previous page will not be saved in history if false
|
||||||
void setPage(const std::string &name, bool history=true);
|
void setPage(const std::string &name, bool history=true);
|
||||||
void setPage(Page page, bool history=true);
|
void setPage(Page page, bool history=true);
|
||||||
void addPage(const std::string& name, const std::shared_ptr<UINode> &panel);
|
void addPage(const std::string& name, const std::shared_ptr<UINode>& panel);
|
||||||
std::shared_ptr<UINode> fetchPage(const std::string& name);
|
std::shared_ptr<UINode> fetchPage(const std::string& name);
|
||||||
|
|
||||||
/// @brief Add page supplier used if page is not found
|
/// @brief Add page supplier used if page is not found
|
||||||
/// @param name page name
|
/// @param name page name
|
||||||
/// @param pageSupplier page supplier function
|
/// @param pageSupplier page supplier function
|
||||||
void addSupplier(const std::string &name, const supplier<std::shared_ptr<UINode>> &pageSupplier);
|
void addSupplier(const std::string& name, const supplier<std::shared_ptr<UINode>>& pageSupplier);
|
||||||
|
|
||||||
/// @brief Page loader is called if accessed page is not found
|
/// @brief Page loader is called if accessed page is not found
|
||||||
void setPageLoader(page_loader_func loader);
|
void setPageLoader(page_loader_func loader);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace gui {
|
|||||||
virtual void setOrientation(Orientation orientation);
|
virtual void setOrientation(Orientation orientation);
|
||||||
Orientation getOrientation() const;
|
Orientation getOrientation() const;
|
||||||
|
|
||||||
virtual void add(const std::shared_ptr<UINode> &node) override;
|
virtual void add(const std::shared_ptr<UINode>& node) override;
|
||||||
|
|
||||||
virtual void refresh() override;
|
virtual void refresh() override;
|
||||||
virtual void fullRefresh() override;
|
virtual void fullRefresh() override;
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ void Plotter::act(float delta) {
|
|||||||
points[index % dmwidth] = std::min(value, dmheight);
|
points[index % dmwidth] = std::min(value, dmheight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plotter::draw(const DrawContext* pctx, Assets* assets) {
|
void Plotter::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx.getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->lineWidth(1);
|
batch->lineWidth(1);
|
||||||
for (int i = index+1; i < index+dmwidth; i++) {
|
for (int i = index+1; i < index+dmwidth; i++) {
|
||||||
@@ -37,7 +37,7 @@ void Plotter::draw(const DrawContext* pctx, Assets* assets) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int current_point = static_cast<int>(points[index % dmwidth]);
|
int current_point = static_cast<int>(points[index % dmwidth]);
|
||||||
auto font = assets->get<Font>("normal");
|
auto font = assets.get<Font>("normal");
|
||||||
for (int y = 0; y < dmheight; y += labelsInterval) {
|
for (int y = 0; y < dmheight; y += labelsInterval) {
|
||||||
std::wstring string;
|
std::wstring string;
|
||||||
if (current_point/16 == y/labelsInterval) {
|
if (current_point/16 == y/labelsInterval) {
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ namespace gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void act(float delta) override;
|
void act(float delta) override;
|
||||||
void draw(const DrawContext* pctx, Assets* assets) override;
|
void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ TextBox::TextBox(std::wstring placeholder, glm::vec4 padding)
|
|||||||
scrollStep = 0;
|
scrollStep = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::draw(const DrawContext* pctx, Assets* assets) {
|
void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
Container::draw(pctx, assets);
|
Container::draw(pctx, assets);
|
||||||
|
|
||||||
font = assets->get<Font>(label->getFontName());
|
font = assets.get<Font>(label->getFontName());
|
||||||
|
|
||||||
if (!isFocused()) {
|
if (!isFocused()) {
|
||||||
return;
|
return;
|
||||||
@@ -58,41 +58,67 @@ void TextBox::draw(const DrawContext* pctx, Assets* assets) {
|
|||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
glm::vec2 size = getSize();
|
glm::vec2 size = getSize();
|
||||||
|
|
||||||
auto subctx = pctx->sub();
|
auto subctx = pctx.sub();
|
||||||
subctx.setScissors(glm::vec4(pos.x, pos.y, size.x, size.y));
|
subctx.setScissors(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->calcPos();
|
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);
|
||||||
batch->setColor(glm::vec4(1.0f));
|
batch->setColor(glm::vec4(1.0f));
|
||||||
if (editable && int((Window::time() - caretLastMove) * 2) % 2 == 0) {
|
if (editable && int((Window::time() - caretLastMove) * 2) % 2 == 0) {
|
||||||
uint line = label->getLineByTextIndex(caret);
|
uint line = label->getLineByTextIndex(caret);
|
||||||
uint lcaret = caret - label->getTextLineOffset(line);
|
uint lcaret = caret - label->getTextLineOffset(line);
|
||||||
int width = font->calcWidth(input, lcaret);
|
int width = font->calcWidth(input, lcaret);
|
||||||
batch->rect(lcoord.x + width, lcoord.y+label->getLineYOffset(line), 2, lineHeight);
|
batch->rect(
|
||||||
|
lcoord.x + width,
|
||||||
|
lcoord.y + label->getLineYOffset(line),
|
||||||
|
2,
|
||||||
|
lineHeight
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (selectionStart != selectionEnd) {
|
if (selectionStart != selectionEnd) {
|
||||||
auto selectionCtx = subctx.sub(batch);
|
auto selectionCtx = subctx.sub(batch);
|
||||||
selectionCtx.setBlendMode(BlendMode::addition);
|
selectionCtx.setBlendMode(BlendMode::addition);
|
||||||
|
|
||||||
uint startLine = label->getLineByTextIndex(selectionStart);
|
uint startLine = label->getLineByTextIndex(selectionStart);
|
||||||
uint endLine = label->getLineByTextIndex(selectionEnd);
|
uint endLine = label->getLineByTextIndex(selectionEnd);
|
||||||
|
|
||||||
batch->setColor(glm::vec4(0.8f, 0.9f, 1.0f, 0.25f));
|
batch->setColor(glm::vec4(0.8f, 0.9f, 1.0f, 0.25f));
|
||||||
int start = font->calcWidth(input, selectionStart-label->getTextLineOffset(startLine));
|
int start = font->calcWidth(
|
||||||
int end = font->calcWidth(input, selectionEnd-label->getTextLineOffset(endLine));
|
input, selectionStart - label->getTextLineOffset(startLine)
|
||||||
|
);
|
||||||
|
int end = font->calcWidth(
|
||||||
|
input, selectionEnd - label->getTextLineOffset(endLine)
|
||||||
|
);
|
||||||
int lineY = label->getLineYOffset(startLine);
|
int lineY = label->getLineYOffset(startLine);
|
||||||
|
|
||||||
if (startLine == endLine) {
|
if (startLine == endLine) {
|
||||||
batch->rect(lcoord.x + start, lcoord.y+lineY, end-start, lineHeight);
|
batch->rect(
|
||||||
|
lcoord.x + start, lcoord.y + lineY, end - start, lineHeight
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
batch->rect(lcoord.x + start, lcoord.y+lineY, label->getSize().x-start-padding.z-padding.x-2, lineHeight);
|
batch->rect(
|
||||||
for (uint i = startLine+1; i < endLine; i++) {
|
lcoord.x + start,
|
||||||
batch->rect(lcoord.x, lcoord.y+label->getLineYOffset(i), label->getSize().x-padding.z-padding.x-2, lineHeight);
|
lcoord.y + lineY,
|
||||||
|
label->getSize().x - start - padding.z - padding.x - 2,
|
||||||
|
lineHeight
|
||||||
|
);
|
||||||
|
for (uint i = startLine + 1; i < endLine; i++) {
|
||||||
|
batch->rect(
|
||||||
|
lcoord.x,
|
||||||
|
lcoord.y + label->getLineYOffset(i),
|
||||||
|
label->getSize().x - padding.z - padding.x - 2,
|
||||||
|
lineHeight
|
||||||
|
);
|
||||||
}
|
}
|
||||||
batch->rect(lcoord.x, lcoord.y+label->getLineYOffset(endLine), end, lineHeight);
|
batch->rect(
|
||||||
|
lcoord.x,
|
||||||
|
lcoord.y + label->getLineYOffset(endLine),
|
||||||
|
end,
|
||||||
|
lineHeight
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,13 +161,13 @@ void TextBox::draw(const DrawContext* pctx, Assets* assets) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::drawBackground(const DrawContext* pctx, Assets*) {
|
void TextBox::drawBackground(const DrawContext& pctx, const Assets&) {
|
||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
|
|
||||||
auto batch = pctx->getBatch2D();
|
auto batch = pctx.getBatch2D();
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
|
|
||||||
auto subctx = pctx->sub();
|
auto subctx = pctx.sub();
|
||||||
subctx.setScissors(glm::vec4(pos.x, pos.y-0.5, size.x, size.y+1));
|
subctx.setScissors(glm::vec4(pos.x, pos.y-0.5, size.x, size.y+1));
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
@@ -205,7 +231,8 @@ void TextBox::refreshLabel() {
|
|||||||
|
|
||||||
if (multiline && font) {
|
if (multiline && font) {
|
||||||
setScrollable(true);
|
setScrollable(true);
|
||||||
uint height = label->getLinesNumber() * font->getLineHeight() * label->getLineInterval();
|
uint height = label->getLinesNumber() * font->getLineHeight() *
|
||||||
|
label->getLineInterval();
|
||||||
label->setSize(glm::vec2(label->getSize().x, height));
|
label->setSize(glm::vec2(label->getSize().x, height));
|
||||||
actualLength = height;
|
actualLength = height;
|
||||||
} else {
|
} else {
|
||||||
@@ -391,7 +418,7 @@ int TextBox::calcIndexAt(int x, int y) const {
|
|||||||
return std::min(offset+label->getTextLineOffset(line), input.length());
|
return std::min(offset+label->getTextLineOffset(line), input.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::wstring get_alphabet(wchar_t c) {
|
static inline std::wstring get_alphabet(wchar_t c) {
|
||||||
std::wstring alphabet {c};
|
std::wstring alphabet {c};
|
||||||
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') {
|
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') {
|
||||||
return L"abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
return L"abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
@@ -650,7 +677,9 @@ size_t TextBox::getLinePos(uint line) const {
|
|||||||
return label->getTextLineOffset(line);
|
return label->getTextLineOffset(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<UINode> TextBox::getAt(glm::vec2 pos, std::shared_ptr<UINode> self) {
|
std::shared_ptr<UINode> TextBox::getAt(
|
||||||
|
const glm::vec2& pos, const std::shared_ptr<UINode>& self
|
||||||
|
) {
|
||||||
return UINode::getAt(pos, self);
|
return UINode::getAt(pos, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -216,11 +216,13 @@ namespace gui {
|
|||||||
virtual void click(GUI*, int, int) override;
|
virtual void click(GUI*, int, int) override;
|
||||||
virtual void mouseMove(GUI*, int x, int y) override;
|
virtual void mouseMove(GUI*, int x, int y) override;
|
||||||
virtual bool isFocuskeeper() const override {return true;}
|
virtual bool isFocuskeeper() const override {return true;}
|
||||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
virtual void drawBackground(const DrawContext* pctx, Assets* assets) override;
|
virtual void drawBackground(const DrawContext& pctx, const Assets& assets) override;
|
||||||
virtual void typed(unsigned int codepoint) override;
|
virtual void typed(unsigned int codepoint) override;
|
||||||
virtual void keyPressed(keycode key) override;
|
virtual void keyPressed(keycode key) override;
|
||||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
virtual std::shared_ptr<UINode> getAt(
|
||||||
|
const glm::vec2& pos, const std::shared_ptr<UINode>& self
|
||||||
|
) override;
|
||||||
virtual void setOnUpPressed(const runnable &callback);
|
virtual void setOnUpPressed(const runnable &callback);
|
||||||
virtual void setOnDownPressed(const runnable &callback);
|
virtual void setOnDownPressed(const runnable &callback);
|
||||||
|
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ TrackBar::TrackBar(
|
|||||||
setHoverColor(glm::vec4(0.01f, 0.02f, 0.03f, 0.5f));
|
setHoverColor(glm::vec4(0.01f, 0.02f, 0.03f, 0.5f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackBar::draw(const DrawContext* pctx, Assets*) {
|
void TrackBar::draw(const DrawContext& pctx, const Assets&) {
|
||||||
if (supplier) {
|
if (supplier) {
|
||||||
value = supplier();
|
value = supplier();
|
||||||
}
|
}
|
||||||
glm::vec2 pos = calcPos();
|
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(pos.x, pos.y, size.x, size.y);
|
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace gui {
|
|||||||
double value,
|
double value,
|
||||||
double step=1.0,
|
double step=1.0,
|
||||||
int trackWidth=12);
|
int trackWidth=12);
|
||||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
|
|
||||||
virtual void setSupplier(doublesupplier);
|
virtual void setSupplier(doublesupplier);
|
||||||
virtual void setConsumer(doubleconsumer);
|
virtual void setConsumer(doubleconsumer);
|
||||||
|
|||||||
@@ -111,11 +111,11 @@ bool UINode::isInside(glm::vec2 point) {
|
|||||||
point.x < pos.x + size.x && point.y < pos.y + size.y);
|
point.x < pos.x + size.x && point.y < pos.y + size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<UINode> UINode::getAt(glm::vec2 point, std::shared_ptr<UINode> self) {
|
std::shared_ptr<UINode> UINode::getAt(const glm::vec2& point, const std::shared_ptr<UINode>& self) {
|
||||||
if (!isInteractive() || !enabled) {
|
if (!isInteractive() || !enabled) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return isInside(point) ? std::move(self) : nullptr;
|
return isInside(point) ? self : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UINode::isInteractive() const {
|
bool UINode::isInteractive() const {
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ namespace gui {
|
|||||||
/// @brief Called every frame for all visible elements
|
/// @brief Called every frame for all visible elements
|
||||||
/// @param delta delta timУ
|
/// @param delta delta timУ
|
||||||
virtual void act(float delta) {};
|
virtual void act(float delta) {};
|
||||||
virtual void draw(const DrawContext* pctx, Assets* assets) = 0;
|
virtual void draw(const DrawContext& pctx, const Assets& assets) = 0;
|
||||||
|
|
||||||
virtual void setVisible(bool flag);
|
virtual void setVisible(bool flag);
|
||||||
bool isVisible() const;
|
bool isVisible() const;
|
||||||
@@ -190,7 +190,7 @@ namespace gui {
|
|||||||
/// @param pos cursor screen position
|
/// @param pos cursor screen position
|
||||||
/// @param self shared pointer to element
|
/// @param self shared pointer to element
|
||||||
/// @return self, sub-element or nullptr if element is not interractive
|
/// @return self, sub-element or nullptr if element is not interractive
|
||||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self);
|
virtual std::shared_ptr<UINode> getAt(const glm::vec2& pos, const std::shared_ptr<UINode>& self);
|
||||||
|
|
||||||
/// @brief Check if element is opaque for cursor
|
/// @brief Check if element is opaque for cursor
|
||||||
virtual bool isInteractive() const;
|
virtual bool isInteractive() const;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ struct ParticlesPreset : public Serializable {
|
|||||||
/// @brief Size of random sub-uv region
|
/// @brief Size of random sub-uv region
|
||||||
float randomSubUV = 1.0f;
|
float randomSubUV = 1.0f;
|
||||||
/// @brief Animation frames
|
/// @brief Animation frames
|
||||||
std::vector<std::string> frames {};
|
std::vector<std::string> frames;
|
||||||
|
|
||||||
dv::value serialize() const override;
|
dv::value serialize() const override;
|
||||||
void deserialize(const dv::value& src) override;
|
void deserialize(const dv::value& src) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user