Cleanup window and add more useful functions
parent
3cf601b78b
commit
606e554f6c
|
@ -11,41 +11,59 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifndef BLT_MAP_FUNC
|
#ifndef BLT_MAP_FUNC
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#define BLT_MAP_FUNC std::unordered_map
|
#define BLT_MAP_FUNC std::unordered_map
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define KEY_MAP BLT_MAP_FUNC<integer, bool>
|
#define KEY_MAP BLT_MAP_FUNC<int, bool>
|
||||||
|
|
||||||
namespace blt {
|
namespace blt {
|
||||||
|
|
||||||
class window {
|
class window {
|
||||||
protected:
|
protected:
|
||||||
bool windowOpen = true;
|
bool m_windowOpen = true;
|
||||||
std::vector<std::function<void()>> renderFunctions;
|
int m_width, m_height;
|
||||||
|
|
||||||
|
std::vector<std::function<void()>> renderFunctions{};
|
||||||
|
std::vector<std::function<void(window*, int, bool)>> keyListeners{};
|
||||||
|
std::vector<std::function<void(window*, int, bool)>> mouseListeners{};
|
||||||
|
|
||||||
|
KEY_MAP keysDown{};
|
||||||
|
KEY_MAP mouseDown{};
|
||||||
public:
|
public:
|
||||||
window() = default;
|
window() = default;
|
||||||
|
window(int width, int height) {
|
||||||
|
m_width = width;
|
||||||
|
m_height = height;
|
||||||
|
}
|
||||||
virtual void createWindow() = 0;
|
virtual void createWindow() = 0;
|
||||||
virtual void startMainLoop() = 0;
|
virtual void startMainLoop() = 0;
|
||||||
virtual void destroyWindow() = 0;
|
virtual void destroyWindow() = 0;
|
||||||
virtual ~window() = 0;
|
virtual ~window() = 0;
|
||||||
|
|
||||||
virtual bool setResizeable(bool resizeEnabled) = 0;
|
virtual inline bool setResizeable(bool resizeEnabled) = 0;
|
||||||
virtual bool setWindowSize(int width, int height) = 0;
|
virtual inline bool setWindowSize(int width, int height) = 0;
|
||||||
virtual int getWidth() = 0;
|
[[nodiscard]] inline int getWidth() const {return m_width;};
|
||||||
virtual int getHeight() = 0;
|
[[nodiscard]] inline int getHeight() const {return m_height;};
|
||||||
|
|
||||||
virtual bool isWindowOpen() {return windowOpen;};
|
[[nodiscard]] virtual inline bool isWindowOpen() const {return m_windowOpen;};
|
||||||
virtual void registerLoopFunction(std::function<void()> func) {
|
virtual inline void closeWindow(){
|
||||||
|
m_windowOpen = false;
|
||||||
|
}
|
||||||
|
virtual inline void registerLoopFunction(std::function<void()> func) {
|
||||||
renderFunctions.push_back(func);
|
renderFunctions.push_back(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool isKeyDown(int key) = 0;
|
virtual inline bool isKeyDown(int key) const { return keysDown.at(key); }
|
||||||
virtual bool isMouseDown(int button) = 0;
|
virtual inline bool isMouseDown(int button) const {return mouseDown.at(button);};
|
||||||
// Function signature is window pointer to this, key press, pressed/released (true/false)
|
// Function signature is window pointer to this, key press, pressed/released (true/false)
|
||||||
virtual void registerKeyListener(std::function<void(window*, int, bool)> listener) = 0;
|
virtual inline void registerKeyListener(std::function<void(window*, int, bool)> listener) {
|
||||||
|
keyListeners.push_back(listener);
|
||||||
|
}
|
||||||
// Function signature is window pointer to this, mouse button press, pressed/released (true/false)
|
// Function signature is window pointer to this, mouse button press, pressed/released (true/false)
|
||||||
virtual void registerMouseListener(std::function<void(window*, int, bool)> listener) = 0;
|
virtual inline void registerMouseListener(std::function<void(window*, int, bool)> listener) {
|
||||||
|
mouseListeners.push_back(listener);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue