2023-01-16 14:08:28 -05:00
|
|
|
/*
|
|
|
|
* Created by Brett on 16/01/23.
|
|
|
|
* Licensed under GNU General Public License V3.0
|
|
|
|
* See LICENSE file for license detail
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLT_WINDOW_H
|
|
|
|
#define BLT_WINDOW_H
|
|
|
|
|
|
|
|
#include <functional>
|
2023-01-17 10:11:35 -05:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#ifndef BLT_MAP_FUNC
|
2023-01-17 10:33:27 -05:00
|
|
|
#include <unordered_map>
|
|
|
|
#define BLT_MAP_FUNC std::unordered_map
|
2023-01-17 10:11:35 -05:00
|
|
|
#endif
|
|
|
|
|
2023-01-17 10:33:27 -05:00
|
|
|
#define KEY_MAP BLT_MAP_FUNC<int, bool>
|
2023-01-16 14:08:28 -05:00
|
|
|
|
|
|
|
namespace blt {
|
|
|
|
|
|
|
|
class window {
|
2023-01-17 10:11:35 -05:00
|
|
|
protected:
|
2023-01-17 10:33:27 -05:00
|
|
|
bool m_windowOpen = true;
|
2023-01-17 11:13:25 -05:00
|
|
|
int m_width = 800, m_height = 600;
|
2023-01-17 10:33:27 -05:00
|
|
|
|
2023-01-17 11:09:25 -05:00
|
|
|
std::vector<std::function<void(window*)>> renderFunctions{};
|
2023-01-17 10:33:27 -05:00
|
|
|
std::vector<std::function<void(window*, int, bool)>> keyListeners{};
|
|
|
|
std::vector<std::function<void(window*, int, bool)>> mouseListeners{};
|
|
|
|
|
|
|
|
KEY_MAP keysDown{};
|
|
|
|
KEY_MAP mouseDown{};
|
2023-01-16 14:08:28 -05:00
|
|
|
public:
|
2023-01-17 11:13:25 -05:00
|
|
|
window() = default;
|
2023-12-11 14:57:10 -05:00
|
|
|
window(int width_, int height_) {
|
|
|
|
m_width = width_;
|
|
|
|
m_height = height_;
|
2023-01-17 10:33:27 -05:00
|
|
|
}
|
2023-01-16 14:08:28 -05:00
|
|
|
virtual void createWindow() = 0;
|
2023-01-17 10:11:35 -05:00
|
|
|
virtual void startMainLoop() = 0;
|
2023-01-16 14:08:28 -05:00
|
|
|
virtual void destroyWindow() = 0;
|
2023-01-17 11:13:25 -05:00
|
|
|
virtual ~window() = 0;
|
2023-01-16 14:08:28 -05:00
|
|
|
|
2023-01-17 10:33:27 -05:00
|
|
|
virtual inline bool setResizeable(bool resizeEnabled) = 0;
|
2023-12-11 14:57:10 -05:00
|
|
|
virtual inline bool setWindowSize(int width_, int height_) = 0;
|
2023-01-17 10:33:27 -05:00
|
|
|
[[nodiscard]] inline int getWidth() const {return m_width;};
|
|
|
|
[[nodiscard]] inline int getHeight() const {return m_height;};
|
2023-01-16 14:08:28 -05:00
|
|
|
|
2023-01-17 10:33:27 -05:00
|
|
|
[[nodiscard]] virtual inline bool isWindowOpen() const {return m_windowOpen;};
|
|
|
|
virtual inline void closeWindow(){
|
|
|
|
m_windowOpen = false;
|
|
|
|
}
|
2023-01-17 11:13:48 -05:00
|
|
|
virtual inline void registerLoopFunction(const std::function<void(window*)>& func) {
|
2023-01-17 10:11:35 -05:00
|
|
|
renderFunctions.push_back(func);
|
|
|
|
}
|
|
|
|
|
2023-01-17 10:33:27 -05:00
|
|
|
virtual inline bool isKeyDown(int key) const { return keysDown.at(key); }
|
|
|
|
virtual inline bool isMouseDown(int button) const {return mouseDown.at(button);};
|
2023-01-16 14:08:28 -05:00
|
|
|
// Function signature is window pointer to this, key press, pressed/released (true/false)
|
2023-01-17 10:35:01 -05:00
|
|
|
virtual inline void registerKeyListener(const std::function<void(window*, int, bool)>& listener) {
|
2023-01-17 10:33:27 -05:00
|
|
|
keyListeners.push_back(listener);
|
|
|
|
}
|
2023-01-16 14:08:28 -05:00
|
|
|
// Function signature is window pointer to this, mouse button press, pressed/released (true/false)
|
2023-01-17 10:35:01 -05:00
|
|
|
virtual inline void registerMouseListener(const std::function<void(window*, int, bool)>& listener) {
|
2023-01-17 10:33:27 -05:00
|
|
|
mouseListeners.push_back(listener);
|
|
|
|
}
|
2023-01-16 14:08:28 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|