Browse Source

Add mouse window lock

master
Riyyi 4 years ago
parent
commit
1a9a618ab1
  1. 4
      inferno/src/inferno/render/context.cpp
  2. 2
      inferno/src/inferno/render/context.h
  3. 35
      inferno/src/inferno/window.cpp
  4. 11
      inferno/src/inferno/window.h

4
inferno/src/inferno/render/context.cpp

@ -53,6 +53,10 @@ namespace Inferno {
} }
void Context::update() void Context::update()
{
}
void Context::render()
{ {
glfwSwapBuffers(m_window); glfwSwapBuffers(m_window);
} }

2
inferno/src/inferno/render/context.h

@ -14,7 +14,7 @@ namespace Inferno {
void initialize(); void initialize();
void update(); void update();
// void render(); void render();
void destroy(); void destroy();
// ----------------------------------------- // -----------------------------------------

35
inferno/src/inferno/window.cpp

@ -7,6 +7,8 @@
#include "inferno/event/applicationevent.h" #include "inferno/event/applicationevent.h"
#include "inferno/event/keyevent.h" #include "inferno/event/keyevent.h"
#include "inferno/event/mouseevent.h" #include "inferno/event/mouseevent.h"
#include "inferno/input.h"
#include "inferno/inputcodes.h"
#include "inferno/log.h" #include "inferno/log.h"
#include "inferno/render/context.h" #include "inferno/render/context.h"
#include "inferno/settings.h" #include "inferno/settings.h"
@ -18,7 +20,7 @@ namespace Inferno {
Window::Window() Window::Window()
{ {
m_windowProperties = { m_properties = {
Settings::get().window.title, Settings::get().window.title,
Settings::get().window.width, Settings::get().window.width,
Settings::get().window.height, Settings::get().window.height,
@ -38,9 +40,9 @@ namespace Inferno {
void Window::initialize() void Window::initialize()
{ {
const char* title = m_windowProperties.title; const char* title = m_properties.title;
unsigned int width = m_windowProperties.width; unsigned int width = m_properties.width;
unsigned int height = m_windowProperties.height; unsigned int height = m_properties.height;
// Only init once // Only init once
if (s_windowCount == 0) { if (s_windowCount == 0) {
@ -88,8 +90,8 @@ namespace Inferno {
glfwSetWindowSizeCallback(m_window, [](GLFWwindow* window, int width, int height) { glfwSetWindowSizeCallback(m_window, [](GLFWwindow* window, int width, int height) {
Window& w = *(Window*)glfwGetWindowUserPointer(window); Window& w = *(Window*)glfwGetWindowUserPointer(window);
w.m_windowProperties.width = width; w.m_properties.width = width;
w.m_windowProperties.height = height; w.m_properties.height = height;
WindowResizeEvent event(width, height); WindowResizeEvent event(width, height);
w.m_eventCallback(event); w.m_eventCallback(event);
@ -163,7 +165,20 @@ namespace Inferno {
void Window::update() void Window::update()
{ {
glfwPollEvents(); glfwPollEvents();
m_context->update();
// Lock mouse in window
if (Input::isKeyPressed(KeyCode("GLFW_KEY_LEFT_SUPER"))) {
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
else {
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
}
}
void Window::render()
{
m_context->render();
} }
void Window::destroy() void Window::destroy()
@ -183,11 +198,11 @@ namespace Inferno {
GLFWmonitor* monitor = glfwGetPrimaryMonitor(); GLFWmonitor* monitor = glfwGetPrimaryMonitor();
int xPos = 0; int xPos = 0;
int yPos = 0; int yPos = 0;
unsigned int width = m_windowProperties.width; unsigned int width = m_properties.width;
unsigned int height = m_windowProperties.height; unsigned int height = m_properties.height;
int refresh = GLFW_DONT_CARE; int refresh = GLFW_DONT_CARE;
const char* fullscreen = m_windowProperties.fullscreen; const char* fullscreen = m_properties.fullscreen;
const GLFWvidmode* mode = glfwGetVideoMode(monitor); const GLFWvidmode* mode = glfwGetVideoMode(monitor);
if (strcmp(fullscreen, "fullscreen") == 0) { if (strcmp(fullscreen, "fullscreen") == 0) {

11
inferno/src/inferno/window.h

@ -27,7 +27,7 @@ namespace Inferno {
void initialize(); void initialize();
void update(); void update();
// void render(); void render();
void destroy(); void destroy();
// ----------------------------------------- // -----------------------------------------
@ -36,9 +36,10 @@ namespace Inferno {
bool shouldClose() const; bool shouldClose() const;
void setShouldClose(bool close) const; void setShouldClose(bool close) const;
inline int getWidth() const { return m_windowProperties.width; } inline int getAspect() const { return m_properties.width / m_properties.height; }
inline int getHeight() const { return m_windowProperties.height; } inline int getWidth() const { return m_properties.width; }
inline bool isVSync() const { return m_windowProperties.vsync; } inline int getHeight() const { return m_properties.height; }
inline bool isVSync() const { return m_properties.vsync; }
inline GLFWwindow* getWindow() const { return m_window; } inline GLFWwindow* getWindow() const { return m_window; }
inline Context* getContext() const { return m_context; } inline Context* getContext() const { return m_context; }
@ -46,7 +47,7 @@ namespace Inferno {
inline void setEventCallback(std::function<void(Event&)> callback) { m_eventCallback = callback; } inline void setEventCallback(std::function<void(Event&)> callback) { m_eventCallback = callback; }
private: private:
WindowProperties m_windowProperties; WindowProperties m_properties;
GLFWwindow* m_window; GLFWwindow* m_window;
Context* m_context; Context* m_context;

Loading…
Cancel
Save