2023-11-28 00:44:47 -05:00
|
|
|
#pragma once
|
|
|
|
/*
|
|
|
|
* Created by Brett on 28/11/23.
|
|
|
|
* Licensed under GNU General Public License V3.0
|
|
|
|
* See LICENSE file for license detail
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLT_WITH_GRAPHICS_TEMPLATE_WINDOW_H
|
|
|
|
#define BLT_WITH_GRAPHICS_TEMPLATE_WINDOW_H
|
|
|
|
|
2023-12-16 23:52:18 -05:00
|
|
|
#include <blt/gfx/gl_includes.h>
|
2024-05-03 22:14:48 -04:00
|
|
|
#include <blt/std/types.h>
|
2023-11-28 00:44:47 -05:00
|
|
|
#include <GLFW/glfw3.h>
|
2023-11-28 01:56:10 -05:00
|
|
|
#include <functional>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2023-11-28 00:44:47 -05:00
|
|
|
|
2023-11-28 01:56:10 -05:00
|
|
|
namespace blt::gfx
|
|
|
|
{
|
|
|
|
struct window_context
|
|
|
|
{
|
2024-05-03 22:14:48 -04:00
|
|
|
i32 GL_MAJOR = 4;
|
|
|
|
i32 GL_MINOR = 6;
|
|
|
|
i32 DOUBLE_BUFFER = GLFW_TRUE;
|
|
|
|
i32 GL_PROFILE = GLFW_OPENGL_CORE_PROFILE;
|
2024-05-04 03:15:43 -04:00
|
|
|
i32 SAMPLES = 4;
|
2023-11-28 01:56:10 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct window_data
|
|
|
|
{
|
2024-04-29 21:42:50 -04:00
|
|
|
private:
|
|
|
|
std::function<void(const window_data&)> init;
|
|
|
|
std::function<void(const window_data&)> update;
|
|
|
|
public:
|
|
|
|
std::string title;
|
|
|
|
std::int32_t width;
|
|
|
|
std::int32_t height;
|
2024-10-27 18:10:55 -04:00
|
|
|
GLFWmonitor* monitor = nullptr;
|
|
|
|
GLFWwindow* share = nullptr;
|
|
|
|
GLFWwindow* window = nullptr;
|
|
|
|
std::int32_t maximized = GLFW_FALSE;
|
2024-04-29 21:42:50 -04:00
|
|
|
|
|
|
|
window_context context{};
|
|
|
|
std::int32_t sync_interval = 0;
|
|
|
|
|
2024-05-03 22:14:48 -04:00
|
|
|
window_data(std::string_view title, std::function<void(const window_data&)> init, std::function<void(const window_data&)> update,
|
|
|
|
i32 width = 640, i32 height = 480): init(std::move(init)), update(std::move(update)),
|
|
|
|
title(title), width(width), height(height)
|
2024-04-29 21:42:50 -04:00
|
|
|
{}
|
|
|
|
|
|
|
|
inline void call_init() const
|
|
|
|
{
|
|
|
|
init(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void call_update() const
|
|
|
|
{
|
|
|
|
update(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
window_data& setWindowSize(int32_t new_width, int32_t new_height);
|
|
|
|
|
|
|
|
window_data& setHeight(int32_t new_height)
|
|
|
|
{
|
|
|
|
setWindowSize(width, new_height);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_data& setWidth(int32_t new_width)
|
|
|
|
{
|
|
|
|
setWindowSize(new_width, height);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_data& setTitle(const std::string& title_str)
|
|
|
|
{
|
|
|
|
window_data::title = title_str;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_data& setContext(const window_context& ctx)
|
|
|
|
{
|
|
|
|
context = ctx;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_data& setSyncInterval(std::int32_t sync)
|
|
|
|
{
|
|
|
|
sync_interval = sync;
|
|
|
|
return *this;
|
|
|
|
}
|
2024-10-27 18:10:55 -04:00
|
|
|
|
|
|
|
window_data& setMonitor(GLFWmonitor* monitor);
|
|
|
|
|
|
|
|
window_data& setShare(GLFWwindow* share);
|
|
|
|
|
|
|
|
window_data& setMaximized(bool b);
|
2023-11-28 01:56:10 -05:00
|
|
|
};
|
|
|
|
|
2024-04-29 15:31:47 -04:00
|
|
|
void init(window_data data);
|
2023-11-28 01:56:10 -05:00
|
|
|
|
2023-12-15 17:24:59 -05:00
|
|
|
double getMouseX();
|
|
|
|
|
|
|
|
double getMouseY();
|
|
|
|
|
|
|
|
double getMouseDX();
|
|
|
|
|
|
|
|
double getMouseDY();
|
|
|
|
|
2024-01-02 14:20:34 -05:00
|
|
|
bool mouseMovedLastFrame();
|
|
|
|
|
2023-12-15 17:24:59 -05:00
|
|
|
void lockCursor();
|
|
|
|
|
|
|
|
void unlockCursor();
|
|
|
|
|
|
|
|
bool isCursorLocked();
|
|
|
|
|
|
|
|
bool isCursorInWindow();
|
|
|
|
|
|
|
|
void setRawInput(bool state);
|
|
|
|
|
|
|
|
bool isRawInput();
|
|
|
|
|
|
|
|
void setClipboard(const std::string& str);
|
|
|
|
|
|
|
|
std::string getClipboard();
|
|
|
|
|
2023-12-15 17:43:00 -05:00
|
|
|
bool isMousePressed(int button);
|
|
|
|
|
2024-01-02 16:28:26 -05:00
|
|
|
bool mousePressedLastFrame();
|
|
|
|
|
2024-05-15 14:09:58 -04:00
|
|
|
bool mouseReleaseLastFrame();
|
|
|
|
|
2023-12-15 17:43:00 -05:00
|
|
|
bool isKeyPressed(int key);
|
|
|
|
|
2024-01-02 17:10:29 -05:00
|
|
|
// TODO: maybe make this per key?
|
2024-01-02 16:28:26 -05:00
|
|
|
bool keyPressedLastFrame();
|
|
|
|
|
2024-05-15 14:09:58 -04:00
|
|
|
bool keyReleasedLastFrame();
|
|
|
|
|
2023-12-29 18:38:07 -05:00
|
|
|
double getFrameDeltaSeconds();
|
|
|
|
|
|
|
|
double getFrameDeltaMilliseconds();
|
|
|
|
|
2024-05-03 22:14:48 -04:00
|
|
|
i64 getFrameDelta();
|
|
|
|
|
|
|
|
i32 getWindowWidth();
|
|
|
|
|
|
|
|
i32 getWindowHeight();
|
2023-12-29 18:38:07 -05:00
|
|
|
|
2023-11-28 01:56:10 -05:00
|
|
|
void cleanup();
|
2024-04-29 02:17:22 -04:00
|
|
|
|
|
|
|
|
2023-11-28 01:56:10 -05:00
|
|
|
}
|
2023-11-28 00:44:47 -05:00
|
|
|
|
|
|
|
#endif //BLT_WITH_GRAPHICS_TEMPLATE_WINDOW_H
|