2019-04-08 18:44:05 +02:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* OpenMiner
|
2020-02-25 01:42:10 +09:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
|
2020-02-25 01:42:10 +09:00
|
|
|
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
|
|
|
|
*
|
|
|
|
* This file is part of OpenMiner.
|
2019-04-08 18:44:05 +02:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is free software; you can redistribute it and/or
|
2020-02-08 18:34:26 +09:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2019-04-08 18:44:05 +02:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is distributed in the hope that it will be useful,
|
2020-02-08 18:34:26 +09:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2019-04-08 18:44:05 +02:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2020-02-25 01:42:10 +09:00
|
|
|
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
|
2020-02-08 18:34:26 +09:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2019-04-08 18:44:05 +02:00
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
2019-04-13 15:45:44 +02:00
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
2020-02-25 22:11:02 +09:00
|
|
|
#include <gk/core/ApplicationStateStack.hpp>
|
|
|
|
|
2019-04-08 18:44:05 +02:00
|
|
|
#include "Config.hpp"
|
2020-03-11 03:53:04 +01:00
|
|
|
#include "EngineConfig.hpp"
|
2019-04-08 18:44:05 +02:00
|
|
|
#include "InterfaceState.hpp"
|
|
|
|
|
|
|
|
InterfaceState::InterfaceState(gk::ApplicationState *parent) : gk::ApplicationState(parent) {
|
|
|
|
m_shader.createProgram();
|
|
|
|
m_shader.addShader(GL_VERTEX_SHADER, "resources/shaders/basic.v.glsl");
|
|
|
|
m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/basic.f.glsl");
|
|
|
|
m_shader.linkProgram();
|
|
|
|
|
2020-01-27 15:33:06 +09:00
|
|
|
m_background.setFillColor(gk::Color{0, 0, 0, 127});
|
|
|
|
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceState::setup() {
|
2020-03-11 03:53:04 +01:00
|
|
|
m_projectionMatrix = glm::ortho(0.0f, (float)Config::screenWidth, (float)Config::screenHeight, 0.0f, DIST_2D_FAR, DIST_2D_NEAR);
|
2019-04-08 18:44:05 +02:00
|
|
|
|
2020-02-15 22:48:56 +09:00
|
|
|
m_background.setSize(Config::screenWidth, Config::screenHeight);
|
2020-01-27 15:33:06 +09:00
|
|
|
|
2020-02-15 22:48:56 +09:00
|
|
|
// m_view.setSize(Config::screenWidth, Config::screenHeight);
|
|
|
|
// m_view.setCenter(Config::screenWidth / 2.0f, Config::screenHeight / 2.0f);
|
2019-04-08 18:44:05 +02:00
|
|
|
}
|
|
|
|
|
2020-05-11 17:30:54 +02:00
|
|
|
void InterfaceState::onEvent(const sf::Event &event) {
|
2020-02-25 22:11:02 +09:00
|
|
|
if (m_parent) {
|
|
|
|
m_parent->onEvent(event);
|
|
|
|
}
|
2020-05-11 17:30:54 +02:00
|
|
|
else if (event.type == sf::Event::Closed) {
|
2020-02-25 22:11:02 +09:00
|
|
|
m_stateStack->clear();
|
|
|
|
}
|
|
|
|
|
2020-05-11 17:30:54 +02:00
|
|
|
if (event.type == sf::Event::Resized) {
|
2020-02-25 22:11:02 +09:00
|
|
|
if (!m_parent) {
|
2020-05-11 17:30:54 +02:00
|
|
|
Config::screenWidth = event.size.width;
|
|
|
|
Config::screenHeight = event.size.height;
|
2020-01-27 15:33:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 10:03:56 +09:00
|
|
|
void InterfaceState::update() {
|
|
|
|
if (m_parent)
|
|
|
|
m_parent->update();
|
|
|
|
}
|
|
|
|
|
2020-01-27 15:33:06 +09:00
|
|
|
void InterfaceState::prepareDraw(gk::RenderTarget &target, gk::RenderStates &states) const {
|
2019-04-08 18:44:05 +02:00
|
|
|
states.transform *= getTransform();
|
|
|
|
states.shader = &m_shader;
|
|
|
|
// states.vertexAttributes = gk::VertexAttribute::Only2d;
|
|
|
|
|
|
|
|
states.projectionMatrix = m_projectionMatrix;
|
|
|
|
|
|
|
|
// target.setView(m_view);
|
2020-01-27 15:33:06 +09:00
|
|
|
|
2020-02-20 17:07:45 +09:00
|
|
|
if (m_parent && m_drawBackground)
|
2020-01-27 15:33:06 +09:00
|
|
|
target.draw(m_background, states);
|
2019-04-08 18:44:05 +02:00
|
|
|
}
|
|
|
|
|