diff options
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | TODO | 1 | ||||
m--------- | depends/mgl | 0 | ||||
-rw-r--r-- | include/mglpp/graphics/Texture.hpp | 11 | ||||
-rw-r--r-- | include/mglpp/mglpp.hpp | 12 | ||||
-rw-r--r-- | include/mglpp/system/vec.hpp | 4 | ||||
-rw-r--r-- | include/mglpp/window/Event.hpp | 12 | ||||
-rw-r--r-- | include/mglpp/window/Keyboard.hpp | 30 | ||||
-rw-r--r-- | include/mglpp/window/Window.hpp | 13 | ||||
-rw-r--r-- | meson.build | 27 | ||||
-rw-r--r-- | src/graphics/Texture.cpp | 9 | ||||
-rw-r--r-- | src/mglpp.cpp | 4 | ||||
-rw-r--r-- | src/window/Keyboard.cpp | 22 | ||||
-rw-r--r-- | src/window/Window.cpp | 34 |
14 files changed, 137 insertions, 53 deletions
@@ -2,10 +2,13 @@ C++ wrapper for [mgl](https://git.dec05eba.com/mgl/about/) # Dependencies ## Build -`x11, libxrender, libxrandr` +`libx11, libxrender, libxrandr`\ +`wayland-client, wayland-egl, wayland-scanner` ## Runtime -`libglvnd (libGL.so, libEGL.so)` +`libglvnd (libGL.so, libGLX.so, libEGL.so)` # Notes -Every window _get_ function is cached from the last event poll, no calls to x11 is made. +Every window _get_ function is cached from the last event poll, no calls to x11/wayland is made.\ Only one window can be created and used at once.\ -mglpp needs to be initialized first and then a window created, before other functions are called. +mglpp needs to be initialized first and then a window has to be created before other functions are called. +# TODO +Wayland support is not finished yet. Use MGL_WINDOW_SYSTEM_X11 for now in mgl::Init.
\ No newline at end of file @@ -0,0 +1 @@ +Change Init(window_system) default value to WindowSystem::NATIVE. diff --git a/depends/mgl b/depends/mgl -Subproject 97d24e6a1b1fe8d2a4e217f9ee3f82a1accf468 +Subproject c990594a93e953854b0a224a22f7e0a7db8ffe1 diff --git a/include/mglpp/graphics/Texture.hpp b/include/mglpp/graphics/Texture.hpp index 1ea040e..6ab1fb4 100644 --- a/include/mglpp/graphics/Texture.hpp +++ b/include/mglpp/graphics/Texture.hpp @@ -14,24 +14,25 @@ namespace mgl { struct LoadOptions { bool compressed = false; bool pixel_coordinates = false; - bool mipmap = false; /* available since opengl 3.0 */ + mgl_texture_scale_type scale_type = MGL_TEXTURE_SCALE_LINEAR; }; struct ReferenceOptions { bool pixel_coordinates = false; + mgl_texture_scale_type scale_type = MGL_TEXTURE_SCALE_LINEAR; }; Texture(); - Texture(unsigned int gl_texture_id, mgl_texture_format format, const ReferenceOptions reference_options = {false}); + Texture(unsigned int gl_texture_id, mgl_texture_format format, const ReferenceOptions reference_options = {false, MGL_TEXTURE_SCALE_LINEAR}); Texture(Texture &&other); Texture& operator=(Texture &&other); ~Texture(); static Texture reference(mgl_texture ref); - bool load_from_file(const char *filepath, const LoadOptions load_options = {false, false, false}); - bool load_from_image(Image &image, const LoadOptions load_options = {false, false, false}); - bool load_from_memory(const unsigned char *data, int width, int height, mgl_image_format format, LoadOptions load_options = {false, false, false}); + bool load_from_file(const char *filepath, const LoadOptions load_options = {false, false, MGL_TEXTURE_SCALE_LINEAR}); + bool load_from_image(Image &image, const LoadOptions load_options = {false, false, MGL_TEXTURE_SCALE_LINEAR}); + bool load_from_memory(const unsigned char *data, int width, int height, mgl_image_format format, LoadOptions load_options = {false, false, MGL_TEXTURE_SCALE_LINEAR}); void clear(); vec2i get_size() const; bool is_valid() const; diff --git a/include/mglpp/mglpp.hpp b/include/mglpp/mglpp.hpp index 2e49da5..730ddf5 100644 --- a/include/mglpp/mglpp.hpp +++ b/include/mglpp/mglpp.hpp @@ -1,9 +1,15 @@ #ifndef MGLPP_MGLPP_HPP #define MGLPP_MGLPP_HPP -#include <stdexcept> +#include <exception> namespace mgl { + enum class WindowSystem { + NATIVE, // Use X11 on X11 and Wayland on Wayland + X11, // Use X11 on X11 and XWayland on Wayland + WAYLAND, // Use Wayland. If user runs on X11 then it fails to connect + }; + class InitException : public std::exception { public: const char* what() const noexcept override { @@ -13,8 +19,8 @@ namespace mgl { class Init { public: - // Throws InitException on failure - Init(); + // Throws InitException on failure. + Init(WindowSystem window_system = WindowSystem::X11); ~Init(); bool is_connected_to_display_server(); diff --git a/include/mglpp/system/vec.hpp b/include/mglpp/system/vec.hpp index 23ef935..d424f42 100644 --- a/include/mglpp/system/vec.hpp +++ b/include/mglpp/system/vec.hpp @@ -61,6 +61,10 @@ namespace mgl { return { static_cast<float>(x), static_cast<float>(y) }; } + vec2<int> to_vec2i() const { + return { static_cast<int>(x), static_cast<int>(y) }; + } + vec2<T> floor() const { return { static_cast<T>(static_cast<int>(x)), static_cast<T>(static_cast<int>(y)) }; } diff --git a/include/mglpp/window/Event.hpp b/include/mglpp/window/Event.hpp index bcd1e91..35b83a4 100644 --- a/include/mglpp/window/Event.hpp +++ b/include/mglpp/window/Event.hpp @@ -63,6 +63,16 @@ namespace mgl { int id; }; + enum class MappingChangedType : int { + MODIFIER, + KEYBOARD, + POINTER + }; + + struct MappingChangedEvent { + MappingChangedType type; + }; + enum Type : int { Unknown, Closed, /* Window closed */ @@ -79,6 +89,7 @@ namespace mgl { MonitorConnected, MonitorDisconnected, MonitorPropertyChanged, + MappingChanged }; Type type; @@ -93,6 +104,7 @@ namespace mgl { MonitorConnectedEvent monitor_connected; MonitorDisconnectedEvent monitor_disconnected; MonitorPropertyChangedEvent monitor_property_changed; + MappingChangedEvent mapping_changed; }; }; } diff --git a/include/mglpp/window/Keyboard.hpp b/include/mglpp/window/Keyboard.hpp index 17c4d7c..2cb6c0a 100644 --- a/include/mglpp/window/Keyboard.hpp +++ b/include/mglpp/window/Keyboard.hpp @@ -1,6 +1,8 @@ #ifndef MGLPP_KEYBOARD_HPP #define MGLPP_KEYBOARD_HPP +#include <stdint.h> + namespace mgl { class Keyboard { public: @@ -108,10 +110,38 @@ namespace mgl { F14, F15, Pause, + Printscreen, + NumpadEnter, + AudioLowerVolume, + AudioRaiseVolume, + AudioPlay, + AudioStop, + AudioPause, + AudioMute, + AudioPrev, + AudioNext, + AudioRewind, + AudioForward, + DeadAcute, + Apostrophe, + F16, + F17, + F18, + F19, + F20, + F21, + F22, + F23, + F24, /* This should always be the last key */ __NumKeys__ }; + + /* Returns nullptr if unknown key */ + static const char* key_to_string(Key key); + static bool key_is_modifier(Key key); + static uint64_t key_to_x11_keysym(Key key); }; } diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp index 2c179a8..8458d71 100644 --- a/include/mglpp/window/Window.hpp +++ b/include/mglpp/window/Window.hpp @@ -27,6 +27,11 @@ namespace mgl { vec2i size; }; + struct Scissor { + vec2i position; + vec2i size; + }; + /* Return true to continue. |get_clipboard| returns false if this returns false. Note: |size| is the size of the current data, not the total data (if the callback only contains a part of the data). @@ -46,11 +51,11 @@ namespace mgl { bool override_redirect = false; bool support_alpha = false; /* support alpha for the window */ bool hide_decorations = false; /* this is a hint, it may be ignored by the window manager */ - Color background_color = {0, 0, 0, 0}; + Color background_color = {0, 0, 0, 255}; const char *class_name = nullptr; mgl_window_type window_type = MGL_WINDOW_TYPE_NORMAL; WindowHandle transient_for_window = 0; /* 0 = none */ - mgl_render_api render_api = MGL_RENDER_API_GLX; + mgl_graphics_api graphics_api = MGL_GRAPHICS_API_EGL; }; Window(); @@ -103,6 +108,9 @@ namespace mgl { void set_view(const View &new_view); View get_view(); + void set_scissor(const Scissor &scissor); + Scissor get_scissor(); + bool is_key_pressed(Keyboard::Key key) const; bool is_mouse_button_pressed(Mouse::Button button) const; @@ -115,6 +123,7 @@ namespace mgl { mgl_window* internal_window(); private: mgl_window window; + bool window_created = false; }; } diff --git a/meson.build b/meson.build index 214ef63..829957c 100644 --- a/meson.build +++ b/meson.build @@ -19,35 +19,10 @@ src = [ 'src/system/Clock.cpp', 'src/system/Utf8.cpp', 'src/window/Window.cpp', + 'src/window/Keyboard.cpp', 'src/mglpp.cpp', ] -project_headers = [ - 'include/mglpp/graphics/Text.hpp', - 'include/mglpp/graphics/PrimitiveType.hpp', - 'include/mglpp/graphics/Vertex.hpp', - 'include/mglpp/graphics/Drawable.hpp', - 'include/mglpp/graphics/Texture.hpp', - 'include/mglpp/graphics/Shader.hpp', - 'include/mglpp/graphics/Sprite.hpp', - 'include/mglpp/graphics/Color.hpp', - 'include/mglpp/graphics/VertexBuffer.hpp', - 'include/mglpp/graphics/Image.hpp', - 'include/mglpp/graphics/Font.hpp', - 'include/mglpp/graphics/Rectangle.hpp', - 'include/mglpp/system/Utf8.hpp', - 'include/mglpp/system/vec.hpp', - 'include/mglpp/system/Clock.hpp', - 'include/mglpp/system/MemoryMappedFile.hpp', - 'include/mglpp/system/FloatRect.hpp', - 'include/mglpp/mglpp.hpp', - 'include/mglpp/window/Window.hpp', - 'include/mglpp/window/Mouse.hpp', - 'include/mglpp/window/Event.hpp', - 'include/mglpp/window/Keyboard.hpp', - 'include/mglpp/window/Clipboard.hpp', -] - mgl_proj = subproject('mgl') mgl_dep = mgl_proj.get_variable('mgl_dep') diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp index 3b1f410..e22bcfb 100644 --- a/src/graphics/Texture.cpp +++ b/src/graphics/Texture.cpp @@ -10,7 +10,8 @@ namespace mgl { Texture::Texture(unsigned int gl_texture_id, mgl_texture_format format, const ReferenceOptions reference_options) { memset(&texture, 0, sizeof(mgl_texture)); const mgl_texture_reference_options texture_reference_options = { - reference_options.pixel_coordinates + reference_options.pixel_coordinates, + reference_options.scale_type }; mgl_texture_init_reference_existing_gl_texture(&texture, gl_texture_id, format, &texture_reference_options); } @@ -58,7 +59,7 @@ namespace mgl { const mgl_texture_load_options texture_load_options = { load_options.compressed, load_options.pixel_coordinates, - load_options.mipmap + load_options.scale_type }; if(mgl_texture_load_from_file(&texture, filepath, &texture_load_options) == 0) { @@ -79,7 +80,7 @@ namespace mgl { const mgl_texture_load_options texture_load_options = { load_options.compressed, load_options.pixel_coordinates, - load_options.mipmap + load_options.scale_type }; if(mgl_texture_load_from_image(&texture, image.internal_image(), &texture_load_options) == 0) { @@ -100,7 +101,7 @@ namespace mgl { const mgl_texture_load_options texture_load_options = { load_options.compressed, load_options.pixel_coordinates, - load_options.mipmap + load_options.scale_type }; if(mgl_texture_load_from_memory(&texture, data, width, height, format, &texture_load_options) == 0) { diff --git a/src/mglpp.cpp b/src/mglpp.cpp index ca0845d..2f0670a 100644 --- a/src/mglpp.cpp +++ b/src/mglpp.cpp @@ -4,8 +4,8 @@ extern "C" { } namespace mgl { - Init::Init() { - if(mgl_init() != 0) + Init::Init(WindowSystem window_system) { + if(mgl_init((mgl_window_system)window_system) != 0) throw InitException(); } diff --git a/src/window/Keyboard.cpp b/src/window/Keyboard.cpp new file mode 100644 index 0000000..34d28be --- /dev/null +++ b/src/window/Keyboard.cpp @@ -0,0 +1,22 @@ +#include "../../include/mglpp/window/Keyboard.hpp" + +extern "C" { +#include <mgl/window/key.h> +} + +namespace mgl { + // static + const char* Keyboard::key_to_string(Key key) { + return mgl_key_to_string((mgl_key)key); + } + + // static + bool Keyboard::key_is_modifier(Key key) { + return mgl_key_is_modifier((mgl_key)key); + } + + // static + uint64_t Keyboard::key_to_x11_keysym(Key key) { + return mgl_key_to_x11_keysym((mgl_key)key); + } +}
\ No newline at end of file diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 731ca8e..fffacca 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -16,24 +16,34 @@ namespace mgl { } Window::Window() { - window.window = 0; + } Window::~Window() { - if(window.window) + if(window_created) mgl_window_deinit(&window); } bool Window::create(const char *title, CreateParams create_params) { - if(window.window) + if(window_created) return false; - return mgl_window_create(&window, title, (const mgl_window_create_params*)&create_params) == 0; + + if(mgl_window_create(&window, title, (const mgl_window_create_params*)&create_params) == 0) { + window_created = true; + return true; + } + return false; } bool Window::create(WindowHandle existing_window) { - if(window.window) + if(window_created) return false; - return mgl_window_init_from_existing_window(&window, existing_window) == 0; + + if(mgl_window_init_from_existing_window(&window, existing_window) == 0) { + window_created = true; + return true; + } + return false; } bool Window::poll_event(Event &event) { @@ -159,6 +169,16 @@ namespace mgl { return view; } + void Window::set_scissor(const Scissor &scissor) { + mgl_window_set_scissor(&window, (mgl_scissor*)&scissor); + } + + Scissor Window::get_scissor() { + Scissor scissor; + mgl_window_get_scissor(&window, (mgl_scissor*)&scissor); + return scissor; + } + bool Window::is_key_pressed(Keyboard::Key key) const { return mgl_window_is_key_pressed(&window, (mgl_key)key); } @@ -187,7 +207,7 @@ namespace mgl { } WindowHandle Window::get_system_handle() const { - return window.window; + return mgl_window_get_system_handle(&window); } mgl_window* Window::internal_window() { |