refactor: add Window interface
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
#include "graphics/core/Shader.hpp"
|
||||
#include "gui_util.hpp"
|
||||
#include "window/Camera.hpp"
|
||||
#include "window/Events.hpp"
|
||||
#include "window/Window.hpp"
|
||||
#include "window/input.hpp"
|
||||
|
||||
@@ -35,7 +34,8 @@ GUI::GUI(Engine& engine)
|
||||
batch2D(std::make_unique<Batch2D>(1024)),
|
||||
container(std::make_shared<Container>(*this, glm::vec2(1000))) {
|
||||
container->setId("root");
|
||||
uicamera = std::make_unique<Camera>(glm::vec3(), Window::height);
|
||||
uicamera =
|
||||
std::make_unique<Camera>(glm::vec3(), engine.getWindow().getSize().y);
|
||||
uicamera->perspective = false;
|
||||
uicamera->flipped = true;
|
||||
|
||||
@@ -121,7 +121,7 @@ void GUI::actMouse(float delta, const CursorState& cursor) {
|
||||
doubleClicked = false;
|
||||
doubleClickTimer += delta + mouseDelta * 0.1f;
|
||||
|
||||
auto hover = container->getAt(Events::cursor);
|
||||
auto hover = container->getAt(cursor.pos);
|
||||
if (this->hover && this->hover != hover) {
|
||||
this->hover->setHover(false);
|
||||
}
|
||||
@@ -255,7 +255,7 @@ void GUI::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
container->draw(ctx, assets);
|
||||
|
||||
if (hover) {
|
||||
Window::setCursor(hover->getCursor());
|
||||
engine.getWindow().setCursor(hover->getCursor());
|
||||
}
|
||||
if (hover && debug) {
|
||||
auto pos = hover->calcPos();
|
||||
@@ -361,3 +361,7 @@ const Input& GUI::getInput() const {
|
||||
Input& GUI::getInput() {
|
||||
return engine.getInput();
|
||||
}
|
||||
|
||||
Window& GUI::getWindow() {
|
||||
return engine.getWindow();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class Batch2D;
|
||||
struct CursorState;
|
||||
class Engine;
|
||||
class Input;
|
||||
class Window;
|
||||
|
||||
/*
|
||||
Some info about padding and margin.
|
||||
@@ -158,5 +159,6 @@ namespace gui {
|
||||
void toggleDebug();
|
||||
const Input& getInput() const;
|
||||
Input& getInput();
|
||||
Window& getWindow();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "objects/Player.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
#include "voxels/Block.hpp"
|
||||
#include "window/Events.hpp"
|
||||
#include "window/input.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "graphics/core/Atlas.hpp"
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "graphics/core/Font.hpp"
|
||||
#include "graphics/ui/markdown.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
#include "window/Events.hpp"
|
||||
#include "window/Window.hpp"
|
||||
#include "devtools/actions.hpp"
|
||||
#include "../markdown.hpp"
|
||||
@@ -251,7 +250,9 @@ void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
batch->texture(nullptr);
|
||||
batch->setColor(glm::vec4(1.0f));
|
||||
|
||||
if (editable && int((Window::time() - caretLastMove) * 2) % 2 == 0) {
|
||||
float time = gui.getWindow().time();
|
||||
|
||||
if (editable && static_cast<int>((time - caretLastMove) * 2) % 2 == 0) {
|
||||
uint line = rawTextCache.getLineByTextIndex(caret);
|
||||
uint lcaret = caret - rawTextCache.getTextLineOffset(line);
|
||||
int width = font->calcWidth(input, lcaret);
|
||||
@@ -750,7 +751,7 @@ void TextBox::stepRight(bool shiftPressed, bool breakSelection) {
|
||||
size_t caret = breakSelection ? selectionEnd : this->caret;
|
||||
if (caret < input.length()) {
|
||||
setCaret(caret + 1);
|
||||
caretLastMove = Window::time();
|
||||
caretLastMove = gui.getWindow().time();
|
||||
if (shiftPressed) {
|
||||
if (selectionStart == selectionEnd) {
|
||||
selectionOrigin = previousCaret;
|
||||
@@ -883,7 +884,7 @@ void TextBox::keyPressed(keycode key) {
|
||||
if (key == keycode::C || key == keycode::X) {
|
||||
std::string text = util::wstr2str_utf8(getSelection());
|
||||
if (!text.empty()) {
|
||||
Window::setClipboardText(text.c_str());
|
||||
gui.getInput().setClipboardText(text.c_str());
|
||||
}
|
||||
if (editable && key == keycode::X) {
|
||||
eraseSelected();
|
||||
@@ -1070,7 +1071,7 @@ void TextBox::setCaret(size_t position) {
|
||||
rawTextCache.prepare(font, width);
|
||||
rawTextCache.update(input, multiline, label->isTextWrapping());
|
||||
|
||||
caretLastMove = Window::time();
|
||||
caretLastMove = gui.getWindow().time();
|
||||
|
||||
uint line = rawTextCache.getLineByTextIndex(caret);
|
||||
int offset = label->getLineYOffset(line) + getContentOffset().y;
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "maths/voxmaths.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
#include "window/Events.hpp"
|
||||
|
||||
using namespace gui;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user