aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-16 11:07:49 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-16 11:07:49 +0100
commit3a29b9984760af0b3a85e35190e1dede39e13891 (patch)
treec9baa5cb9204d15d081ef73a82729b493e6898fb /src/window
parent01e3403abf86050e4096ecf60466de4139ac78e2 (diff)
Implement all interfaces to mgl
Diffstat (limited to 'src/window')
-rw-r--r--src/window/Clipboard.cpp15
-rw-r--r--src/window/Window.cpp69
2 files changed, 43 insertions, 41 deletions
diff --git a/src/window/Clipboard.cpp b/src/window/Clipboard.cpp
deleted file mode 100644
index b5b156e..0000000
--- a/src/window/Clipboard.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "../../include/mglpp/window/Clipboard.hpp"
-
-namespace mgl {
- // TODO: Implement
- // static
- void Clipboard::set_string(std::string str) {
-
- }
-
- // TODO: Implement
- // static
- std::string Clipboard::get_string() {
- return "";
- }
-} \ No newline at end of file
diff --git a/src/window/Window.cpp b/src/window/Window.cpp
index 5dbbe5a..ee984fd 100644
--- a/src/window/Window.cpp
+++ b/src/window/Window.cpp
@@ -18,10 +18,10 @@ namespace mgl {
mgl_window_deinit(&window);
}
- bool Window::create(const char *title, int width, int height) {
+ bool Window::create(const char *title, CreateParams create_params) {
if(window.window)
return false;
- return mgl_window_create_with_params(&window, title, width, height, 0) == 0;
+ return mgl_window_create(&window, title, (mgl_window_create_params*)&create_params) == 0;
}
bool Window::create(WindowHandle existing_window) {
@@ -31,14 +31,10 @@ namespace mgl {
}
bool Window::poll_event(Event &event) {
- if(!window.window)
- return false;
return mgl_window_poll_event(&window, (mgl_event*)&event);
}
void Window::clear(Color color) {
- if(!window.window)
- return;
mgl_window_clear(&window, mgl_color{color.r, color.g, color.b, color.a});
}
@@ -64,36 +60,27 @@ namespace mgl {
}
void Window::display() {
- if(!window.window)
- return;
mgl_window_display(&window);
}
- // TODO: Implement
bool Window::is_open() const {
- if(!window.window)
- return false;
return mgl_window_is_open(&window);
}
- // TODO: Implement
bool Window::has_focus() const {
- return true;
+ return mgl_window_has_focus(&window);
}
- // TODO: Implement
void Window::close() {
-
+ mgl_window_close(&window);
}
- // TODO: Implement
void Window::set_title(const char *title) {
-
+ mgl_window_set_title(&window, title);
}
- // TODO: Implement
void Window::set_framerate_limit(unsigned int fps) {
-
+ mgl_window_set_framerate_limit(&window, fps);
}
// TODO: Implement
@@ -101,33 +88,63 @@ namespace mgl {
}
- // TODO: Implement
void Window::set_cursor_visible(bool visible) {
-
+ mgl_window_set_cursor_visible(&window, visible);
}
vec2i Window::get_size() const {
return { window.size.x, window.size.y };
}
- vec2i Window::get_cursor_position() const {
+ void Window::set_size(mgl::vec2i size) {
+ mgl_window_set_size(&window, { size.x, size.y });
+ }
+
+ void Window::set_position(mgl::vec2i position) {
+ mgl_window_set_position(&window, { position.x, position.y });
+ }
+
+ void Window::set_size_limits(mgl::vec2i minimum, mgl::vec2i maximum) {
+ mgl_window_set_size_limits(&window, { minimum.x, minimum.y }, { maximum.x, maximum.y });
+ }
+
+ vec2i Window::get_mouse_position() const {
return { window.cursor_position.x, window.cursor_position.y };
}
void Window::set_view(const View &new_view) {
- if(!window.window)
- return;
mgl_window_set_view(&window, (mgl_view*)&new_view);
}
View Window::get_view() {
View view;
- if(!window.window)
- return view;
mgl_window_get_view(&window, (mgl_view*)&view);
return view;
}
+ bool Window::is_key_pressed(Keyboard::Key key) const {
+ return mgl_window_is_key_pressed(&window, (mgl_key)key);
+ }
+
+ bool Window::is_mouse_button_pressed(Mouse::Button button) const {
+ return mgl_window_is_mouse_button_pressed(&window, (mgl_mouse_button)button);
+ }
+
+ void Window::set_clipboard(const std::string &str) {
+ mgl_window_set_clipboard(&window, str.c_str(), str.size());
+ }
+
+ std::string Window::get_clipboard() {
+ std::string result;
+ char *str = nullptr;
+ size_t size = 0;
+ if(mgl_window_get_clipboard(&window, &str, &size)) {
+ result.assign(str, size);
+ free(str);
+ }
+ return result;
+ }
+
WindowHandle Window::get_system_handle() const {
return window.window;
}