remove Viewport class
This commit is contained in:
parent
105561ad77
commit
9843a1fc27
@ -211,7 +211,7 @@ void Engine::updateFrontend() {
|
|||||||
double delta = time.getDelta();
|
double delta = time.getDelta();
|
||||||
updateHotkeys();
|
updateHotkeys();
|
||||||
audio::update(delta);
|
audio::update(delta);
|
||||||
gui->act(delta, Viewport(window->getSize()));
|
gui->act(delta, window->getSize());
|
||||||
screen->update(delta);
|
screen->update(delta);
|
||||||
gui->postAct();
|
gui->postAct();
|
||||||
}
|
}
|
||||||
@ -229,7 +229,6 @@ void Engine::nextFrame() {
|
|||||||
void Engine::renderFrame() {
|
void Engine::renderFrame() {
|
||||||
screen->draw(time.getDelta());
|
screen->draw(time.getDelta());
|
||||||
|
|
||||||
Viewport viewport(window->getSize());
|
|
||||||
DrawContext ctx(nullptr, *window, nullptr);
|
DrawContext ctx(nullptr, *window, nullptr);
|
||||||
gui->draw(ctx, *assets);
|
gui->draw(ctx, *assets);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -591,9 +591,7 @@ void Hud::setDebug(bool flag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Hud::draw(const DrawContext& ctx){
|
void Hud::draw(const DrawContext& ctx){
|
||||||
const Viewport& viewport = ctx.getViewport();
|
const auto& viewport = ctx.getViewport();
|
||||||
const uint width = viewport.getWidth();
|
|
||||||
const uint height = viewport.getHeight();
|
|
||||||
|
|
||||||
bool is_menu_open = menu.hasOpenPage();
|
bool is_menu_open = menu.hasOpenPage();
|
||||||
darkOverlay->setVisible(is_menu_open);
|
darkOverlay->setVisible(is_menu_open);
|
||||||
@ -601,8 +599,8 @@ void Hud::draw(const DrawContext& ctx){
|
|||||||
|
|
||||||
updateElementsPosition(viewport);
|
updateElementsPosition(viewport);
|
||||||
|
|
||||||
uicamera->setFov(height);
|
uicamera->setFov(viewport.y);
|
||||||
uicamera->setAspectRatio(viewport.getRatio());
|
uicamera->setAspectRatio(viewport.x / static_cast<float>(viewport.y));
|
||||||
|
|
||||||
auto batch = ctx.getBatch2D();
|
auto batch = ctx.getBatch2D();
|
||||||
batch->begin();
|
batch->begin();
|
||||||
@ -620,28 +618,28 @@ void Hud::draw(const DrawContext& ctx){
|
|||||||
int chsizex = texture != nullptr ? texture->getWidth() : 16;
|
int chsizex = texture != nullptr ? texture->getWidth() : 16;
|
||||||
int chsizey = texture != nullptr ? texture->getHeight() : 16;
|
int chsizey = texture != nullptr ? texture->getHeight() : 16;
|
||||||
batch->rect(
|
batch->rect(
|
||||||
(width-chsizex)/2, (height-chsizey)/2,
|
(viewport.x - chsizex) / 2, (viewport.y - chsizey) / 2,
|
||||||
chsizex, chsizey, 0,0, 1,1, 1,1,1,1
|
chsizex, chsizey, 0, 0, 1, 1, 1, 1, 1, 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hud::updateElementsPosition(const Viewport& viewport) {
|
void Hud::updateElementsPosition(const glm::uvec2& viewport) {
|
||||||
const uint width = viewport.getWidth();
|
|
||||||
const uint height = viewport.getHeight();
|
|
||||||
|
|
||||||
if (inventoryOpen) {
|
if (inventoryOpen) {
|
||||||
float caWidth = inventoryView && showContentPanel
|
float caWidth = inventoryView && showContentPanel
|
||||||
? contentAccess->getSize().x
|
? contentAccess->getSize().x
|
||||||
: 0.0f;
|
: 0.0f;
|
||||||
contentAccessPanel->setPos(glm::vec2(width-caWidth, 0));
|
contentAccessPanel->setPos(glm::vec2(viewport.x - caWidth, 0));
|
||||||
|
|
||||||
glm::vec2 invSize = inventoryView ? inventoryView->getSize() : glm::vec2();
|
glm::vec2 invSize = inventoryView ? inventoryView->getSize() : glm::vec2();
|
||||||
if (secondUI == nullptr) {
|
if (secondUI == nullptr) {
|
||||||
if (inventoryView) {
|
if (inventoryView) {
|
||||||
inventoryView->setPos(glm::vec2(
|
inventoryView->setPos(glm::vec2(
|
||||||
glm::min(width/2-invSize.x/2, width-caWidth-10-invSize.x),
|
glm::min(
|
||||||
height/2-invSize.y/2
|
viewport.x / 2 - invSize.x / 2,
|
||||||
|
viewport.x - caWidth - 10 - invSize.x
|
||||||
|
),
|
||||||
|
viewport.y / 2 - invSize.y / 2
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -651,17 +649,21 @@ void Hud::updateElementsPosition(const Viewport& viewport) {
|
|||||||
float totalHeight = invSize.y + secondUISize.y + interval;
|
float totalHeight = invSize.y + secondUISize.y + interval;
|
||||||
if (inventoryView) {
|
if (inventoryView) {
|
||||||
inventoryView->setPos(glm::vec2(
|
inventoryView->setPos(glm::vec2(
|
||||||
glm::min(width/2-invwidth/2, width-caWidth-10-invwidth),
|
glm::min(
|
||||||
height/2+totalHeight/2-invSize.y
|
viewport.x / 2 - invwidth / 2,
|
||||||
|
viewport.x - caWidth - 10 - invwidth
|
||||||
|
),
|
||||||
|
viewport.y / 2 + totalHeight / 2 - invSize.y
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (secondUI->getPositionFunc() == nullptr) {
|
if (secondUI->getPositionFunc() == nullptr) {
|
||||||
secondUI->setPos(glm::vec2(
|
secondUI->setPos(glm::vec2(
|
||||||
glm::min(
|
glm::min(
|
||||||
width / 2.f - invwidth / 2.f,
|
viewport.x / 2.f - invwidth / 2.f,
|
||||||
width - caWidth - (inventoryView ? 10 : 0) - invwidth
|
viewport.x - caWidth - (inventoryView ? 10 : 0) -
|
||||||
|
invwidth
|
||||||
),
|
),
|
||||||
height / 2.f - totalHeight / 2.f
|
viewport.y / 2.f - totalHeight / 2.f
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -669,7 +671,7 @@ void Hud::updateElementsPosition(const Viewport& viewport) {
|
|||||||
if (exchangeSlot != nullptr) {
|
if (exchangeSlot != nullptr) {
|
||||||
exchangeSlot->setPos(input.getCursor().pos);
|
exchangeSlot->setPos(input.getCursor().pos);
|
||||||
}
|
}
|
||||||
hotbarView->setPos(glm::vec2(width/2, height-65));
|
hotbarView->setPos(glm::vec2(viewport.x / 2, viewport.y - 65));
|
||||||
hotbarView->setSelected(player.getChosenSlot());
|
hotbarView->setSelected(player.getChosenSlot());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,6 @@ class Inventory;
|
|||||||
class LevelFrontend;
|
class LevelFrontend;
|
||||||
class UiDocument;
|
class UiDocument;
|
||||||
class DrawContext;
|
class DrawContext;
|
||||||
class Viewport;
|
|
||||||
class ImageData;
|
class ImageData;
|
||||||
class Input;
|
class Input;
|
||||||
|
|
||||||
@ -131,7 +130,7 @@ class Hud : public util::ObjectsKeeper {
|
|||||||
std::shared_ptr<gui::InventoryView> createHotbar();
|
std::shared_ptr<gui::InventoryView> createHotbar();
|
||||||
|
|
||||||
void processInput(bool visible);
|
void processInput(bool visible);
|
||||||
void updateElementsPosition(const Viewport& viewport);
|
void updateElementsPosition(const glm::uvec2& viewport);
|
||||||
void updateHotbarControl();
|
void updateHotbarControl();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,6 @@
|
|||||||
#include "graphics/core/DrawContext.hpp"
|
#include "graphics/core/DrawContext.hpp"
|
||||||
#include "graphics/core/ImageData.hpp"
|
#include "graphics/core/ImageData.hpp"
|
||||||
#include "graphics/core/PostProcessing.hpp"
|
#include "graphics/core/PostProcessing.hpp"
|
||||||
#include "graphics/core/Viewport.hpp"
|
|
||||||
#include "graphics/render/Decorator.hpp"
|
#include "graphics/render/Decorator.hpp"
|
||||||
#include "graphics/render/WorldRenderer.hpp"
|
#include "graphics/render/WorldRenderer.hpp"
|
||||||
#include "graphics/ui/GUI.hpp"
|
#include "graphics/ui/GUI.hpp"
|
||||||
|
|||||||
@ -29,7 +29,7 @@ DrawContext::DrawContext(
|
|||||||
Batch2D* g2d
|
Batch2D* g2d
|
||||||
) : window(window),
|
) : window(window),
|
||||||
parent(parent),
|
parent(parent),
|
||||||
viewport({window.getSize()}),
|
viewport(window.getSize()),
|
||||||
g2d(g2d),
|
g2d(g2d),
|
||||||
flushable(g2d)
|
flushable(g2d)
|
||||||
{}
|
{}
|
||||||
@ -55,11 +55,7 @@ DrawContext::~DrawContext() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glViewport(
|
glViewport(0, 0, parent->viewport.x, parent->viewport.y);
|
||||||
0, 0,
|
|
||||||
parent->viewport.getWidth(),
|
|
||||||
parent->viewport.getHeight()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (depthMask != parent->depthMask) {
|
if (depthMask != parent->depthMask) {
|
||||||
glDepthMask(parent->depthMask);
|
glDepthMask(parent->depthMask);
|
||||||
@ -80,7 +76,7 @@ DrawContext::~DrawContext() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Viewport& DrawContext::getViewport() const {
|
const glm::uvec2& DrawContext::getViewport() const {
|
||||||
return viewport;
|
return viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,13 +95,9 @@ DrawContext DrawContext::sub(Flushable* flushable) const {
|
|||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawContext::setViewport(const Viewport& viewport) {
|
void DrawContext::setViewport(const glm::uvec2& viewport) {
|
||||||
this->viewport = viewport;
|
this->viewport = viewport;
|
||||||
glViewport(
|
glViewport(0, 0, viewport.x, viewport.y);
|
||||||
0, 0,
|
|
||||||
viewport.getWidth(),
|
|
||||||
viewport.getHeight()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawContext::setFramebuffer(Framebuffer* fbo) {
|
void DrawContext::setFramebuffer(Framebuffer* fbo) {
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <glm/vec2.hpp>
|
||||||
|
#include <glm/vec4.hpp>
|
||||||
|
|
||||||
#include "commons.hpp"
|
#include "commons.hpp"
|
||||||
#include "Viewport.hpp"
|
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
|
|
||||||
class Window;
|
class Window;
|
||||||
@ -11,7 +13,7 @@ class Framebuffer;
|
|||||||
class DrawContext {
|
class DrawContext {
|
||||||
Window& window;
|
Window& window;
|
||||||
const DrawContext* parent;
|
const DrawContext* parent;
|
||||||
Viewport viewport;
|
glm::uvec2 viewport;
|
||||||
Batch2D* g2d;
|
Batch2D* g2d;
|
||||||
Flushable* flushable = nullptr;
|
Flushable* flushable = nullptr;
|
||||||
Framebuffer* fbo = nullptr;
|
Framebuffer* fbo = nullptr;
|
||||||
@ -31,10 +33,10 @@ public:
|
|||||||
|
|
||||||
Batch2D* getBatch2D() const;
|
Batch2D* getBatch2D() const;
|
||||||
|
|
||||||
const Viewport& getViewport() const;
|
const glm::uvec2& getViewport() const;
|
||||||
DrawContext sub(Flushable* flushable=nullptr) const;
|
DrawContext sub(Flushable* flushable=nullptr) const;
|
||||||
|
|
||||||
void setViewport(const Viewport& viewport);
|
void setViewport(const glm::uvec2& viewport);
|
||||||
void setFramebuffer(Framebuffer* fbo);
|
void setFramebuffer(Framebuffer* fbo);
|
||||||
void setDepthMask(bool flag);
|
void setDepthMask(bool flag);
|
||||||
void setDepthTest(bool flag);
|
void setDepthTest(bool flag);
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
#include "Shader.hpp"
|
#include "Shader.hpp"
|
||||||
#include "Texture.hpp"
|
#include "Texture.hpp"
|
||||||
#include "Framebuffer.hpp"
|
#include "Framebuffer.hpp"
|
||||||
#include "Viewport.hpp"
|
|
||||||
#include "DrawContext.hpp"
|
#include "DrawContext.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@ -23,9 +22,9 @@ PostProcessing::~PostProcessing() = default;
|
|||||||
void PostProcessing::use(DrawContext& context) {
|
void PostProcessing::use(DrawContext& context) {
|
||||||
const auto& vp = context.getViewport();
|
const auto& vp = context.getViewport();
|
||||||
if (fbo) {
|
if (fbo) {
|
||||||
fbo->resize(vp.getWidth(), vp.getHeight());
|
fbo->resize(vp.x, vp.y);
|
||||||
} else {
|
} else {
|
||||||
fbo = std::make_unique<Framebuffer>(vp.getWidth(), vp.getHeight());
|
fbo = std::make_unique<Framebuffer>(vp.x, vp.y);
|
||||||
}
|
}
|
||||||
context.setFramebuffer(fbo.get());
|
context.setFramebuffer(fbo.get());
|
||||||
}
|
}
|
||||||
@ -37,7 +36,7 @@ void PostProcessing::render(const DrawContext& context, Shader* screenShader) {
|
|||||||
|
|
||||||
const auto& viewport = context.getViewport();
|
const auto& viewport = context.getViewport();
|
||||||
screenShader->use();
|
screenShader->use();
|
||||||
screenShader->uniform2i("u_screenSize", viewport.size());
|
screenShader->uniform2i("u_screenSize", viewport);
|
||||||
fbo->getTexture()->bind();
|
fbo->getTexture()->bind();
|
||||||
quadMesh->draw();
|
quadMesh->draw();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
#include "Viewport.hpp"
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint Viewport::getHeight() const {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
#include "typedefs.hpp"
|
|
||||||
|
|
||||||
class Viewport {
|
|
||||||
uint width;
|
|
||||||
uint height;
|
|
||||||
public:
|
|
||||||
Viewport(uint width, uint height);
|
|
||||||
Viewport(const glm::ivec2& size);
|
|
||||||
|
|
||||||
virtual uint getWidth() const;
|
|
||||||
virtual uint getHeight() const;
|
|
||||||
|
|
||||||
glm::ivec2 size() const {
|
|
||||||
return glm::ivec2(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
float getRatio() const {
|
|
||||||
return width / static_cast<float>(height);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -13,7 +13,6 @@
|
|||||||
#include "graphics/core/DrawContext.hpp"
|
#include "graphics/core/DrawContext.hpp"
|
||||||
#include "graphics/core/Shader.hpp"
|
#include "graphics/core/Shader.hpp"
|
||||||
#include "graphics/core/Texture.hpp"
|
#include "graphics/core/Texture.hpp"
|
||||||
#include "graphics/core/Viewport.hpp"
|
|
||||||
#include "graphics/commons/Model.hpp"
|
#include "graphics/commons/Model.hpp"
|
||||||
|
|
||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
@ -127,7 +126,7 @@ std::unique_ptr<Atlas> BlocksPreview::build(
|
|||||||
glm::vec3(0, 1, 0)));
|
glm::vec3(0, 1, 0)));
|
||||||
|
|
||||||
AtlasBuilder builder;
|
AtlasBuilder builder;
|
||||||
ctx.setViewport(Viewport(iconSize, iconSize));
|
ctx.setViewport({iconSize, iconSize});
|
||||||
display::setBgColor(glm::vec4(0.0f));
|
display::setBgColor(glm::vec4(0.0f));
|
||||||
|
|
||||||
fbo.bind();
|
fbo.bind();
|
||||||
|
|||||||
@ -64,8 +64,6 @@ void GuidesRenderer::renderDebugLines(
|
|||||||
) {
|
) {
|
||||||
DrawContext ctx = pctx.sub(&batch);
|
DrawContext ctx = pctx.sub(&batch);
|
||||||
const auto& viewport = ctx.getViewport();
|
const auto& viewport = ctx.getViewport();
|
||||||
uint displayWidth = viewport.getWidth();
|
|
||||||
uint displayHeight = viewport.getHeight();
|
|
||||||
|
|
||||||
ctx.setDepthTest(true);
|
ctx.setDepthTest(true);
|
||||||
|
|
||||||
@ -91,15 +89,15 @@ void GuidesRenderer::renderDebugLines(
|
|||||||
}
|
}
|
||||||
|
|
||||||
float length = 40.f;
|
float length = 40.f;
|
||||||
glm::vec3 tsl(displayWidth / 2, displayHeight / 2, 0.f);
|
glm::vec3 tsl(viewport.x / 2, viewport.y / 2, 0.f);
|
||||||
glm::mat4 model(glm::translate(glm::mat4(1.f), tsl));
|
glm::mat4 model(glm::translate(glm::mat4(1.f), tsl));
|
||||||
linesShader.uniformMatrix(
|
linesShader.uniformMatrix(
|
||||||
"u_projview",
|
"u_projview",
|
||||||
glm::ortho(
|
glm::ortho(
|
||||||
0.f,
|
0.f,
|
||||||
static_cast<float>(displayWidth),
|
static_cast<float>(viewport.x),
|
||||||
0.f,
|
0.f,
|
||||||
static_cast<float>(displayHeight),
|
static_cast<float>(viewport.y),
|
||||||
-length,
|
-length,
|
||||||
length
|
length
|
||||||
) * model *
|
) * model *
|
||||||
|
|||||||
@ -101,11 +101,9 @@ void Skybox::draw(
|
|||||||
float daytime,
|
float daytime,
|
||||||
float fog)
|
float fog)
|
||||||
{
|
{
|
||||||
const Viewport& viewport = pctx.getViewport();
|
const glm::uvec2& viewport = pctx.getViewport();
|
||||||
int width = viewport.getWidth();
|
|
||||||
int height = viewport.getHeight();
|
|
||||||
|
|
||||||
drawBackground(camera, assets, width, height);
|
drawBackground(camera, assets, viewport.x, viewport.y);
|
||||||
|
|
||||||
DrawContext ctx = pctx.sub();
|
DrawContext ctx = pctx.sub();
|
||||||
ctx.setBlendMode(BlendMode::addition);
|
ctx.setBlendMode(BlendMode::addition);
|
||||||
@ -145,7 +143,7 @@ void Skybox::refresh(const DrawContext& pctx, float t, float mie, uint quality)
|
|||||||
ctx.setDepthMask(false);
|
ctx.setDepthMask(false);
|
||||||
ctx.setDepthTest(false);
|
ctx.setDepthTest(false);
|
||||||
ctx.setFramebuffer(fbo.get());
|
ctx.setFramebuffer(fbo.get());
|
||||||
ctx.setViewport(Viewport(size, size));
|
ctx.setViewport({size, size});
|
||||||
|
|
||||||
auto cubemap = dynamic_cast<Cubemap*>(fbo->getTexture());
|
auto cubemap = dynamic_cast<Cubemap*>(fbo->getTexture());
|
||||||
assert(cubemap != nullptr);
|
assert(cubemap != nullptr);
|
||||||
|
|||||||
@ -85,14 +85,14 @@ void TextsRenderer::renderNote(
|
|||||||
}
|
}
|
||||||
pos /= projpos.w;
|
pos /= projpos.w;
|
||||||
pos.z = 0;
|
pos.z = 0;
|
||||||
xvec = {2.0f / viewport.getWidth() * scale, 0, 0};
|
xvec = {2.0f / viewport.x * scale, 0, 0};
|
||||||
yvec = {0, 2.0f / viewport.getHeight() * scale, 0};
|
yvec = {0, 2.0f / viewport.y * scale, 0};
|
||||||
} else {
|
} else {
|
||||||
auto matrix = camera.getProjView();
|
auto matrix = camera.getProjView();
|
||||||
auto screenPos = matrix * glm::vec4(pos, 1.0f);
|
auto screenPos = matrix * glm::vec4(pos, 1.0f);
|
||||||
|
|
||||||
xvec = glm::vec3(2.0f / viewport.getWidth() * scale, 0, 0);
|
xvec = glm::vec3(2.0f / viewport.x * scale, 0, 0);
|
||||||
yvec = glm::vec3(0, 2.0f / viewport.getHeight() * scale, 0);
|
yvec = glm::vec3(0, 2.0f / viewport.y * scale, 0);
|
||||||
|
|
||||||
pos = screenPos / screenPos.w;
|
pos = screenPos / screenPos.w;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -339,7 +339,7 @@ void WorldRenderer::draw(
|
|||||||
auto world = level.getWorld();
|
auto world = level.getWorld();
|
||||||
|
|
||||||
const auto& vp = pctx.getViewport();
|
const auto& vp = pctx.getViewport();
|
||||||
camera.setAspectRatio(vp.getRatio());
|
camera.setAspectRatio(vp.x / static_cast<float>(vp.y));
|
||||||
|
|
||||||
const auto& settings = engine.getSettings();
|
const auto& settings = engine.getSettings();
|
||||||
const auto& worldInfo = world->getInfo();
|
const auto& worldInfo = world->getInfo();
|
||||||
|
|||||||
@ -197,8 +197,8 @@ void GUI::actFocused() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::act(float delta, const Viewport& vp) {
|
void GUI::act(float delta, const glm::uvec2& vp) {
|
||||||
container->setSize(vp.size());
|
container->setSize(vp);
|
||||||
container->act(delta);
|
container->act(delta);
|
||||||
auto prevfocus = focus;
|
auto prevfocus = focus;
|
||||||
|
|
||||||
@ -233,7 +233,6 @@ void GUI::draw(const DrawContext& pctx, const Assets& assets) {
|
|||||||
auto ctx = pctx.sub(batch2D.get());
|
auto ctx = pctx.sub(batch2D.get());
|
||||||
|
|
||||||
auto& viewport = ctx.getViewport();
|
auto& viewport = ctx.getViewport();
|
||||||
glm::vec2 wsize = viewport.size();
|
|
||||||
|
|
||||||
auto& page = menu->getCurrent();
|
auto& page = menu->getCurrent();
|
||||||
if (page.panel) {
|
if (page.panel) {
|
||||||
@ -243,9 +242,9 @@ void GUI::draw(const DrawContext& pctx, const Assets& assets) {
|
|||||||
panel->cropToContent();
|
panel->cropToContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu->setPos((wsize - menu->getSize()) / 2.0f);
|
menu->setPos((glm::vec2(viewport) - menu->getSize()) / 2.0f);
|
||||||
uicamera->setFov(wsize.y);
|
uicamera->setFov(viewport.y);
|
||||||
uicamera->setAspectRatio(viewport.getRatio());
|
uicamera->setAspectRatio(viewport.x / static_cast<float>(viewport.y));
|
||||||
|
|
||||||
auto uishader = assets.get<Shader>("ui");
|
auto uishader = assets.get<Shader>("ui");
|
||||||
uishader->use();
|
uishader->use();
|
||||||
@ -277,11 +276,11 @@ void GUI::draw(const DrawContext& pctx, const Assets& assets) {
|
|||||||
batch2D->untexture();
|
batch2D->untexture();
|
||||||
auto node = hover->getParent();
|
auto node = hover->getParent();
|
||||||
while (node) {
|
while (node) {
|
||||||
auto pos = node->calcPos();
|
auto parentPos = node->calcPos();
|
||||||
auto size = node->getSize();
|
auto size = node->getSize();
|
||||||
|
|
||||||
batch2D->setColor(0, 255, 255);
|
batch2D->setColor(0, 255, 255);
|
||||||
batch2D->lineRect(pos.x, pos.y, size.x-1, size.y-1);
|
batch2D->lineRect(parentPos.x, parentPos.y, size.x-1, size.y-1);
|
||||||
|
|
||||||
node = node->getParent();
|
node = node->getParent();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,6 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
class Viewport;
|
|
||||||
class DrawContext;
|
class DrawContext;
|
||||||
class Assets;
|
class Assets;
|
||||||
class Camera;
|
class Camera;
|
||||||
@ -106,7 +105,7 @@ namespace gui {
|
|||||||
/// @brief Main input handling and logic update method
|
/// @brief Main input handling and logic update method
|
||||||
/// @param delta delta time
|
/// @param delta delta time
|
||||||
/// @param viewport window size
|
/// @param viewport window size
|
||||||
void act(float delta, const Viewport& viewport);
|
void act(float delta, const glm::uvec2& viewport);
|
||||||
|
|
||||||
/// @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
|
||||||
|
|||||||
@ -237,8 +237,8 @@ void Label::draw(const DrawContext& pctx, const Assets& assets) {
|
|||||||
textYOffset = pos.y-calcPos().y;
|
textYOffset = pos.y-calcPos().y;
|
||||||
totalLineHeight = lineHeight;
|
totalLineHeight = lineHeight;
|
||||||
|
|
||||||
auto& viewport = pctx.getViewport();
|
const auto& viewport = pctx.getViewport();
|
||||||
glm::vec4 bounds {0, 0, viewport.getWidth(), viewport.getHeight()};
|
glm::vec4 bounds {0, 0, viewport.x, viewport.y};
|
||||||
if (parent) {
|
if (parent) {
|
||||||
auto ppos = parent->calcPos();
|
auto ppos = parent->calcPos();
|
||||||
auto psize = parent->getSize();
|
auto psize = parent->getSize();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user