refactor: add Window interface
This commit is contained in:
@@ -25,10 +25,11 @@ static void set_blend_mode(BlendMode mode) {
|
||||
|
||||
DrawContext::DrawContext(
|
||||
const DrawContext* parent,
|
||||
Viewport viewport,
|
||||
Window& window,
|
||||
Batch2D* g2d
|
||||
) : parent(parent),
|
||||
viewport(std::move(viewport)),
|
||||
) : window(window),
|
||||
parent(parent),
|
||||
viewport({window.getSize()}),
|
||||
g2d(g2d),
|
||||
flushable(g2d)
|
||||
{}
|
||||
@@ -39,7 +40,7 @@ DrawContext::~DrawContext() {
|
||||
}
|
||||
|
||||
while (scissorsCount--) {
|
||||
Window::popScissor();
|
||||
window.popScissor();
|
||||
}
|
||||
|
||||
if (parent == nullptr)
|
||||
@@ -54,7 +55,7 @@ DrawContext::~DrawContext() {
|
||||
}
|
||||
}
|
||||
|
||||
Window::viewport(
|
||||
glViewport(
|
||||
0, 0,
|
||||
parent->viewport.getWidth(),
|
||||
parent->viewport.getHeight()
|
||||
@@ -100,7 +101,7 @@ DrawContext DrawContext::sub(Flushable* flushable) const {
|
||||
|
||||
void DrawContext::setViewport(const Viewport& viewport) {
|
||||
this->viewport = viewport;
|
||||
Window::viewport(
|
||||
glViewport(
|
||||
0, 0,
|
||||
viewport.getWidth(),
|
||||
viewport.getHeight()
|
||||
@@ -153,7 +154,7 @@ void DrawContext::setBlendMode(BlendMode mode) {
|
||||
}
|
||||
|
||||
void DrawContext::setScissors(const glm::vec4& area) {
|
||||
Window::pushScissor(area);
|
||||
window.pushScissor(area);
|
||||
scissorsCount++;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
#include "Viewport.hpp"
|
||||
#include "typedefs.hpp"
|
||||
|
||||
class Window;
|
||||
class Batch2D;
|
||||
class Framebuffer;
|
||||
|
||||
class DrawContext {
|
||||
Window& window;
|
||||
const DrawContext* parent;
|
||||
Viewport viewport;
|
||||
Batch2D* g2d;
|
||||
@@ -20,7 +22,11 @@ class DrawContext {
|
||||
int scissorsCount = 0;
|
||||
float lineWidth = 1.0f;
|
||||
public:
|
||||
DrawContext(const DrawContext* parent, Viewport viewport, Batch2D* g2d);
|
||||
DrawContext(
|
||||
const DrawContext* parent,
|
||||
Window& window,
|
||||
Batch2D* g2d
|
||||
);
|
||||
~DrawContext();
|
||||
|
||||
Batch2D* getBatch2D() const;
|
||||
|
||||
@@ -4,6 +4,9 @@ Viewport::Viewport(uint width, uint height)
|
||||
: width(width), height(height) {
|
||||
}
|
||||
|
||||
Viewport::Viewport(const glm::ivec2& size) : width(size.x), height(size.y) {
|
||||
}
|
||||
|
||||
uint Viewport::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ class Viewport {
|
||||
uint height;
|
||||
public:
|
||||
Viewport(uint width, uint height);
|
||||
Viewport(const glm::ivec2& size);
|
||||
|
||||
virtual uint getWidth() const;
|
||||
virtual uint getHeight() const;
|
||||
|
||||
@@ -26,7 +26,7 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
|
||||
const Block& def,
|
||||
int size
|
||||
){
|
||||
Window::clear();
|
||||
display::clear();
|
||||
blockid_t id = def.rt.id;
|
||||
const UVRegion texfaces[6]{cache.getRegion(id, 0), cache.getRegion(id, 1),
|
||||
cache.getRegion(id, 2), cache.getRegion(id, 3),
|
||||
@@ -98,6 +98,7 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
|
||||
}
|
||||
|
||||
std::unique_ptr<Atlas> BlocksPreview::build(
|
||||
Window& window,
|
||||
const ContentGfxCache& cache,
|
||||
const Assets& assets,
|
||||
const ContentIndices& indices
|
||||
@@ -108,8 +109,7 @@ std::unique_ptr<Atlas> BlocksPreview::build(
|
||||
auto& shader = assets.require<Shader>("ui3d");
|
||||
const auto& atlas = assets.require<Atlas>("blocks");
|
||||
|
||||
Viewport viewport(iconSize, iconSize);
|
||||
DrawContext pctx(nullptr, viewport, nullptr);
|
||||
DrawContext pctx(nullptr, window, nullptr);
|
||||
DrawContext ctx = pctx.sub();
|
||||
ctx.setCullFace(true);
|
||||
ctx.setDepthTest(true);
|
||||
@@ -127,8 +127,8 @@ std::unique_ptr<Atlas> BlocksPreview::build(
|
||||
glm::vec3(0, 1, 0)));
|
||||
|
||||
AtlasBuilder builder;
|
||||
Window::viewport(0, 0, iconSize, iconSize);
|
||||
Window::setBgColor(glm::vec4(0.0f));
|
||||
ctx.setViewport(Viewport(iconSize, iconSize));
|
||||
display::setBgColor(glm::vec4(0.0f));
|
||||
|
||||
fbo.bind();
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
@@ -137,7 +137,5 @@ std::unique_ptr<Atlas> BlocksPreview::build(
|
||||
builder.add(def.name, draw(cache, shader, fbo, batch, def, iconSize));
|
||||
}
|
||||
fbo.unbind();
|
||||
|
||||
Window::viewport(0, 0, Window::width, Window::height);
|
||||
return builder.build(2);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ class Batch3D;
|
||||
class Block;
|
||||
class ContentIndices;
|
||||
class Shader;
|
||||
class Window;
|
||||
class ContentGfxCache;
|
||||
|
||||
class BlocksPreview {
|
||||
@@ -26,6 +27,7 @@ class BlocksPreview {
|
||||
);
|
||||
public:
|
||||
static std::unique_ptr<Atlas> build(
|
||||
Window& window,
|
||||
const ContentGfxCache& cache,
|
||||
const Assets& assets,
|
||||
const ContentIndices& indices
|
||||
|
||||
@@ -316,7 +316,7 @@ void WorldRenderer::renderHands(
|
||||
assets.get<model::Model>(def.modelName),
|
||||
nullptr
|
||||
);
|
||||
Window::clearDepth();
|
||||
display::clearDepth();
|
||||
setupWorldShader(entityShader, hudcam, engine.getSettings(), 0.0f);
|
||||
skybox->bind();
|
||||
modelBatch->render();
|
||||
@@ -359,7 +359,7 @@ void WorldRenderer::draw(
|
||||
DrawContext wctx = pctx.sub();
|
||||
postProcessing.use(wctx);
|
||||
|
||||
Window::clearDepth();
|
||||
display::clearDepth();
|
||||
|
||||
// Drawing background sky plane
|
||||
skybox->draw(pctx, camera, assets, worldInfo.daytime, clouds);
|
||||
|
||||
@@ -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