minor refactor
This commit is contained in:
parent
69779f0cc0
commit
04b6b6b546
@ -206,7 +206,7 @@ void Engine::renderFrame(Batch2D& batch) {
|
||||
|
||||
Viewport viewport(Window::width, Window::height);
|
||||
DrawContext ctx(nullptr, viewport, &batch);
|
||||
gui->draw(&ctx, assets.get());
|
||||
gui->draw(ctx, *assets);
|
||||
}
|
||||
|
||||
void Engine::processPostRunnables() {
|
||||
|
||||
@ -95,16 +95,16 @@ class Hud : public util::ObjectsKeeper {
|
||||
/// @brief Inventories interaction agent (grabbed item)
|
||||
std::shared_ptr<gui::SlotView> exchangeSlot;
|
||||
/// @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
|
||||
std::vector<HudElement> elements;
|
||||
|
||||
/// @brief Player inventory view
|
||||
std::shared_ptr<gui::InventoryView> inventoryView = nullptr;
|
||||
std::shared_ptr<gui::InventoryView> inventoryView;
|
||||
/// @brief Block inventory view
|
||||
std::shared_ptr<gui::InventoryView> blockUI = nullptr;
|
||||
std::shared_ptr<gui::InventoryView> blockUI;
|
||||
/// @brief Secondary inventory view
|
||||
std::shared_ptr<gui::InventoryView> secondInvView = nullptr;
|
||||
std::shared_ptr<gui::InventoryView> secondInvView;
|
||||
/// @brief Position of the block open
|
||||
glm::ivec3 blockPos {};
|
||||
/// @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
|
||||
bool allowDebugCheats = true;
|
||||
/// @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;
|
||||
|
||||
|
||||
@ -197,18 +197,18 @@ void GUI::act(float delta, const Viewport& vp) {
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::draw(const DrawContext* pctx, Assets* assets) {
|
||||
auto& viewport = pctx->getViewport();
|
||||
void GUI::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
auto& viewport = pctx.getViewport();
|
||||
glm::vec2 wsize = viewport.size();
|
||||
|
||||
menu->setPos((wsize - menu->getSize()) / 2.0f);
|
||||
uicamera->setFov(wsize.y);
|
||||
|
||||
auto uishader = assets->get<Shader>("ui");
|
||||
auto uishader = assets.get<Shader>("ui");
|
||||
uishader->use();
|
||||
uishader->uniformMatrix("u_projview", uicamera->getProjView());
|
||||
|
||||
pctx->getBatch2D()->begin();
|
||||
pctx.getBatch2D()->begin();
|
||||
container->draw(pctx, assets);
|
||||
}
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ namespace gui {
|
||||
/// @brief Draw all visible elements on main container
|
||||
/// @param pctx parent graphics context
|
||||
/// @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
|
||||
/// @param node UI element
|
||||
|
||||
@ -52,7 +52,7 @@ Button::Button(
|
||||
|
||||
void Button::setText(std::wstring text) {
|
||||
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();
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->setColor(calcColor());
|
||||
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||
|
||||
@ -7,7 +7,7 @@ namespace gui {
|
||||
|
||||
class Button : public Panel {
|
||||
protected:
|
||||
std::shared_ptr<Label> label = nullptr;
|
||||
std::shared_ptr<Label> label;
|
||||
public:
|
||||
Button(const std::shared_ptr<UINode>& content,
|
||||
glm::vec4 padding=glm::vec4(2.0f));
|
||||
@ -17,7 +17,9 @@ namespace gui {
|
||||
const onaction& action,
|
||||
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 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});
|
||||
}
|
||||
|
||||
void CheckBox::draw(const DrawContext* pctx, Assets*) {
|
||||
void CheckBox::draw(const DrawContext& pctx, const Assets&) {
|
||||
if (supplier) {
|
||||
checked = supplier();
|
||||
}
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->setColor(checked ? checkColor : calcColor());
|
||||
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||
|
||||
@ -15,7 +15,7 @@ namespace gui {
|
||||
public:
|
||||
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;
|
||||
|
||||
|
||||
@ -17,12 +17,15 @@ Container::~Container() {
|
||||
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()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!isInside(pos)) return nullptr;
|
||||
|
||||
if (!isInside(pos)) {
|
||||
return nullptr;
|
||||
}
|
||||
int diff = (actualLength-size.y);
|
||||
if (scrollable && diff > 0 && pos.x > calcPos().x + getSize().x - scrollBarWidth) {
|
||||
return UINode::getAt(pos, self);
|
||||
@ -114,16 +117,16 @@ void Container::setScrollable(bool 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 size = getSize();
|
||||
drawBackground(pctx, assets);
|
||||
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
if (!nodes.empty()) {
|
||||
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)));
|
||||
for (const auto& node : nodes) {
|
||||
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();
|
||||
if (color.a <= 0.001f)
|
||||
return;
|
||||
glm::vec2 pos = calcPos();
|
||||
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->setColor(color);
|
||||
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);
|
||||
node->setParent(this);
|
||||
node->reposition();
|
||||
|
||||
@ -25,11 +25,11 @@ namespace gui {
|
||||
virtual ~Container();
|
||||
|
||||
virtual void act(float delta) override;
|
||||
virtual void drawBackground(const DrawContext* pctx, Assets* assets);
|
||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||
virtual void add(const std::shared_ptr<UINode> &node);
|
||||
virtual void add(const std::shared_ptr<UINode> &node, glm::vec2 pos);
|
||||
virtual void drawBackground(const DrawContext& pctx, const Assets& assets);
|
||||
virtual void draw(const DrawContext& pctx, const Assets& assets) 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, glm::vec2 pos);
|
||||
virtual void clear();
|
||||
virtual void remove(const std::shared_ptr<UINode>& node);
|
||||
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);
|
||||
}
|
||||
|
||||
void Image::draw(const DrawContext* pctx, Assets* assets) {
|
||||
void Image::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
|
||||
Texture* texture = nullptr;
|
||||
auto separator = this->texture.find(':');
|
||||
if (separator == std::string::npos) {
|
||||
texture = assets->get<Texture>(this->texture);
|
||||
texture = assets.get<Texture>(this->texture);
|
||||
batch->texture(texture);
|
||||
if (texture && autoresize) {
|
||||
setSize(glm::vec2(texture->getWidth(), texture->getHeight()));
|
||||
}
|
||||
} else {
|
||||
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))) {
|
||||
texture = atlas->getTexture();
|
||||
batch->texture(atlas->getTexture());
|
||||
|
||||
@ -10,7 +10,7 @@ namespace gui {
|
||||
public:
|
||||
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 bool isAutoResize() const;
|
||||
|
||||
@ -9,15 +9,15 @@ using namespace gui;
|
||||
|
||||
InputBindBox::InputBindBox(Binding& binding, glm::vec4 padding)
|
||||
: Panel(glm::vec2(100,32), padding, 0),
|
||||
binding(binding) {
|
||||
label = std::make_shared<Label>(L"");
|
||||
binding(binding),
|
||||
label(std::make_shared<Label>(L"")) {
|
||||
add(label);
|
||||
setScrollable(false);
|
||||
}
|
||||
|
||||
void InputBindBox::drawBackground(const DrawContext* pctx, Assets*) {
|
||||
void InputBindBox::drawBackground(const DrawContext& pctx, const Assets&) {
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->setColor(isFocused() ? focusedColor : calcColor());
|
||||
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||
|
||||
@ -13,7 +13,10 @@ namespace gui {
|
||||
Binding& binding;
|
||||
public:
|
||||
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 keyPressed(keycode key) override;
|
||||
|
||||
@ -115,7 +115,7 @@ SlotView::SlotView(
|
||||
setTooltipDelay(0.0f);
|
||||
}
|
||||
|
||||
void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
void SlotView::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
if (bound == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -144,7 +144,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
color = glm::vec4(1, 1, 1, 0.2f);
|
||||
}
|
||||
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
batch->setColor(color);
|
||||
if (color.a > 0.0) {
|
||||
batch->texture(nullptr);
|
||||
@ -157,7 +157,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
|
||||
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& item = indices->items.require(stack.getItemId());
|
||||
@ -176,7 +176,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
}
|
||||
case ItemIconType::SPRITE: {
|
||||
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->rect(
|
||||
@ -187,7 +187,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
}
|
||||
|
||||
if (stack.getCount() > 1) {
|
||||
auto font = assets->get<Font>("normal");
|
||||
auto font = assets.get<Font>("normal");
|
||||
std::wstring text = std::to_wstring(stack.getCount());
|
||||
|
||||
int x = pos.x+slotSize-text.length()*8;
|
||||
|
||||
@ -64,7 +64,7 @@ namespace gui {
|
||||
public:
|
||||
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);
|
||||
bool isHighlighted() const;
|
||||
|
||||
@ -158,9 +158,9 @@ uint Label::getLinesNumber() const {
|
||||
return cache.lines.size();
|
||||
}
|
||||
|
||||
void Label::draw(const DrawContext* pctx, Assets* assets) {
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto font = assets->get<Font>(fontName);
|
||||
void Label::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
auto batch = pctx.getBatch2D();
|
||||
auto font = assets.get<Font>(fontName);
|
||||
cache.prepare(font, static_cast<size_t>(glm::abs(getSize().x)));
|
||||
|
||||
if (supplier) {
|
||||
|
||||
@ -100,7 +100,7 @@ namespace gui {
|
||||
virtual uint getLinesNumber() 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);
|
||||
|
||||
|
||||
@ -31,13 +31,13 @@ namespace gui {
|
||||
/// @param history previous page will not be saved in history if false
|
||||
void setPage(const std::string &name, 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);
|
||||
|
||||
/// @brief Add page supplier used if page is not found
|
||||
/// @param name page name
|
||||
/// @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
|
||||
void setPageLoader(page_loader_func loader);
|
||||
|
||||
@ -23,7 +23,7 @@ namespace gui {
|
||||
virtual void setOrientation(Orientation orientation);
|
||||
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 fullRefresh() override;
|
||||
|
||||
@ -14,9 +14,9 @@ void Plotter::act(float delta) {
|
||||
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();
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->lineWidth(1);
|
||||
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]);
|
||||
auto font = assets->get<Font>("normal");
|
||||
auto font = assets.get<Font>("normal");
|
||||
for (int y = 0; y < dmheight; y += labelsInterval) {
|
||||
std::wstring string;
|
||||
if (current_point/16 == y/labelsInterval) {
|
||||
|
||||
@ -29,6 +29,6 @@ namespace gui {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void TextBox::draw(const DrawContext* pctx, Assets* assets) {
|
||||
void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
Container::draw(pctx, assets);
|
||||
|
||||
font = assets->get<Font>(label->getFontName());
|
||||
font = assets.get<Font>(label->getFontName());
|
||||
|
||||
if (!isFocused()) {
|
||||
return;
|
||||
@ -58,41 +58,67 @@ void TextBox::draw(const DrawContext* pctx, Assets* assets) {
|
||||
glm::vec2 pos = calcPos();
|
||||
glm::vec2 size = getSize();
|
||||
|
||||
auto subctx = pctx->sub();
|
||||
auto subctx = pctx.sub();
|
||||
subctx.setScissors(glm::vec4(pos.x, pos.y, size.x, size.y));
|
||||
|
||||
const int lineHeight = font->getLineHeight() * label->getLineInterval();
|
||||
glm::vec2 lcoord = label->calcPos();
|
||||
lcoord.y -= 2;
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->setColor(glm::vec4(1.0f));
|
||||
if (editable && int((Window::time() - caretLastMove) * 2) % 2 == 0) {
|
||||
uint line = label->getLineByTextIndex(caret);
|
||||
uint lcaret = caret - label->getTextLineOffset(line);
|
||||
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) {
|
||||
auto selectionCtx = subctx.sub(batch);
|
||||
selectionCtx.setBlendMode(BlendMode::addition);
|
||||
|
||||
|
||||
uint startLine = label->getLineByTextIndex(selectionStart);
|
||||
uint endLine = label->getLineByTextIndex(selectionEnd);
|
||||
|
||||
batch->setColor(glm::vec4(0.8f, 0.9f, 1.0f, 0.25f));
|
||||
int start = font->calcWidth(input, selectionStart-label->getTextLineOffset(startLine));
|
||||
int end = font->calcWidth(input, selectionEnd-label->getTextLineOffset(endLine));
|
||||
int start = font->calcWidth(
|
||||
input, selectionStart - label->getTextLineOffset(startLine)
|
||||
);
|
||||
int end = font->calcWidth(
|
||||
input, selectionEnd - label->getTextLineOffset(endLine)
|
||||
);
|
||||
int lineY = label->getLineYOffset(startLine);
|
||||
|
||||
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 {
|
||||
batch->rect(lcoord.x + start, 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 + start,
|
||||
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();
|
||||
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
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));
|
||||
|
||||
if (valid) {
|
||||
@ -205,7 +231,8 @@ void TextBox::refreshLabel() {
|
||||
|
||||
if (multiline && font) {
|
||||
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));
|
||||
actualLength = height;
|
||||
} else {
|
||||
@ -391,7 +418,7 @@ int TextBox::calcIndexAt(int x, int y) const {
|
||||
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};
|
||||
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') {
|
||||
return L"abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
@ -650,7 +677,9 @@ size_t TextBox::getLinePos(uint line) const {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -216,11 +216,13 @@ namespace gui {
|
||||
virtual void click(GUI*, int, int) override;
|
||||
virtual void mouseMove(GUI*, int x, int y) override;
|
||||
virtual bool isFocuskeeper() const override {return true;}
|
||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
||||
virtual void drawBackground(const DrawContext* pctx, Assets* assets) override;
|
||||
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||
virtual void drawBackground(const DrawContext& pctx, const Assets& assets) override;
|
||||
virtual void typed(unsigned int codepoint) 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 setOnDownPressed(const runnable &callback);
|
||||
|
||||
|
||||
@ -25,12 +25,12 @@ TrackBar::TrackBar(
|
||||
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) {
|
||||
value = supplier();
|
||||
}
|
||||
glm::vec2 pos = calcPos();
|
||||
auto batch = pctx->getBatch2D();
|
||||
auto batch = pctx.getBatch2D();
|
||||
batch->texture(nullptr);
|
||||
batch->setColor(hover ? hoverColor : color);
|
||||
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||
|
||||
@ -21,7 +21,7 @@ namespace gui {
|
||||
double value,
|
||||
double step=1.0,
|
||||
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 setConsumer(doubleconsumer);
|
||||
|
||||
@ -111,11 +111,11 @@ bool UINode::isInside(glm::vec2 point) {
|
||||
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) {
|
||||
return nullptr;
|
||||
}
|
||||
return isInside(point) ? std::move(self) : nullptr;
|
||||
return isInside(point) ? self : nullptr;
|
||||
}
|
||||
|
||||
bool UINode::isInteractive() const {
|
||||
|
||||
@ -120,7 +120,7 @@ namespace gui {
|
||||
/// @brief Called every frame for all visible elements
|
||||
/// @param delta delta timУ
|
||||
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);
|
||||
bool isVisible() const;
|
||||
@ -190,7 +190,7 @@ namespace gui {
|
||||
/// @param pos cursor screen position
|
||||
/// @param self shared pointer to element
|
||||
/// @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
|
||||
virtual bool isInteractive() const;
|
||||
|
||||
@ -53,7 +53,7 @@ struct ParticlesPreset : public Serializable {
|
||||
/// @brief Size of random sub-uv region
|
||||
float randomSubUV = 1.0f;
|
||||
/// @brief Animation frames
|
||||
std::vector<std::string> frames {};
|
||||
std::vector<std::string> frames;
|
||||
|
||||
dv::value serialize() const override;
|
||||
void deserialize(const dv::value& src) override;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user