aboutsummaryrefslogtreecommitdiff
path: root/include
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 /include
parent01e3403abf86050e4096ecf60466de4139ac78e2 (diff)
Implement all interfaces to mgl
Diffstat (limited to 'include')
-rw-r--r--include/mglpp/graphics/Font.hpp16
-rw-r--r--include/mglpp/graphics/Texture.hpp9
-rw-r--r--include/mglpp/system/MemoryMappedFile.hpp30
-rw-r--r--include/mglpp/system/Utf8.hpp11
-rw-r--r--include/mglpp/window/Clipboard.hpp2
-rw-r--r--include/mglpp/window/Event.hpp22
-rw-r--r--include/mglpp/window/Keyboard.hpp5
-rw-r--r--include/mglpp/window/Mouse.hpp5
-rw-r--r--include/mglpp/window/Window.hpp28
9 files changed, 104 insertions, 24 deletions
diff --git a/include/mglpp/graphics/Font.hpp b/include/mglpp/graphics/Font.hpp
index b032e13..440dabe 100644
--- a/include/mglpp/graphics/Font.hpp
+++ b/include/mglpp/graphics/Font.hpp
@@ -9,13 +9,14 @@ extern "C" {
namespace mgl {
class Texture;
+ class MemoryMappedFile;
struct FontGlyph {
- vec2f position;
- vec2f size;
- vec2f texture_position;
- vec2f texture_size;
- float advance = 0.0f;
+ vec2i position;
+ vec2i size;
+ vec2i texture_position; /* In pixel space */
+ vec2i texture_size; /* In pixel space */
+ int advance = 0;
};
class Font {
@@ -23,10 +24,11 @@ namespace mgl {
Font();
~Font();
- bool load_from_file(const char *filepath, unsigned int character_size);
+ bool load_from_file(const MemoryMappedFile &mapped_file, unsigned int character_size);
unsigned int get_character_size() const;
// Returns 0 sized glyph if the font doesn't have the codepoint
- FontGlyph get_glyph(uint32_t codepoint) const;
+ FontGlyph get_glyph(uint32_t codepoint);
+ int get_kerning(uint32_t prev_codepoint, uint32_t codepoint);
Texture get_texture() const;
mgl_font* internal_font();
diff --git a/include/mglpp/graphics/Texture.hpp b/include/mglpp/graphics/Texture.hpp
index 9559829..633d2cd 100644
--- a/include/mglpp/graphics/Texture.hpp
+++ b/include/mglpp/graphics/Texture.hpp
@@ -11,13 +11,18 @@ namespace mgl {
class Image;
class Texture {
public:
+ struct LoadOptions {
+ bool compressed;
+ bool pixel_coordinates;
+ };
+
Texture();
~Texture();
static Texture reference(mgl_texture ref);
- bool load_from_file(const char *filepath);
- bool load_from_image(Image &image);
+ bool load_from_file(const char *filepath, const LoadOptions load_options = {false, false});
+ bool load_from_image(Image &image, const LoadOptions load_options = {false, false});
vec2i get_size() const;
bool is_valid() const;
diff --git a/include/mglpp/system/MemoryMappedFile.hpp b/include/mglpp/system/MemoryMappedFile.hpp
new file mode 100644
index 0000000..508518a
--- /dev/null
+++ b/include/mglpp/system/MemoryMappedFile.hpp
@@ -0,0 +1,30 @@
+#ifndef MGLPP_MEMORY_MAPPED_FILE_HPP
+#define MGLPP_MEMORY_MAPPED_FILE_HPP
+
+extern "C" {
+#include <mgl/system/fileutils.h>
+}
+
+namespace mgl {
+ class MemoryMappedFile {
+ public:
+ struct LoadOptions {
+ bool readable;
+ bool writable;
+ };
+
+ MemoryMappedFile();
+ ~MemoryMappedFile();
+
+ bool load(const char *filepath, LoadOptions load_options = { true, true });
+
+ void* data();
+ size_t size();
+
+ const mgl_memory_mapped_file* internal_mapped_file() const;
+ private:
+ mgl_memory_mapped_file memory_mapped_file;
+ };
+}
+
+#endif /* MGLPP_MEMORY_MAPPED_FILE_HPP */
diff --git a/include/mglpp/system/Utf8.hpp b/include/mglpp/system/Utf8.hpp
new file mode 100644
index 0000000..4f6a39a
--- /dev/null
+++ b/include/mglpp/system/Utf8.hpp
@@ -0,0 +1,11 @@
+#ifndef MGLPP_UTF8_HPP
+#define MGLPP_UTF8_HPP
+
+#include <stddef.h>
+#include <stdint.h>
+
+namespace mgl {
+ bool utf8_decode(const unsigned char *str, size_t size, uint32_t *decoded_codepoint, size_t *codepoint_length);
+}
+
+#endif /* MGLPP_UTF8_HPP */
diff --git a/include/mglpp/window/Clipboard.hpp b/include/mglpp/window/Clipboard.hpp
index 7d5c9d4..caec403 100644
--- a/include/mglpp/window/Clipboard.hpp
+++ b/include/mglpp/window/Clipboard.hpp
@@ -6,7 +6,7 @@
namespace mgl {
class Clipboard {
public:
- static void set_string(std::string str);
+ static void set_string(const std::string &str);
static std::string get_string();
};
}
diff --git a/include/mglpp/window/Event.hpp b/include/mglpp/window/Event.hpp
index 5b9e357..f3e9535 100644
--- a/include/mglpp/window/Event.hpp
+++ b/include/mglpp/window/Event.hpp
@@ -29,26 +29,35 @@ namespace mgl {
bool system;
};
- struct MouseMoveEvent {
- int x; /* relative to left of the window */
- int y; /* relative to the top of the window */
- };
-
struct MouseButtonEvent {
Mouse::Button button;
+ int x; /* mouse position relative to left of the window */
+ int y; /* mouse position relative to top of the window */
+ };
+
+ struct MouseWheelScrollEvent {
+ int delta; /* positive = up, negative = down */
+ int x; /* mouse position relative to left of the window */
+ int y; /* mouse position relative to left of the window */
+ };
+
+ struct MouseMoveEvent {
int x; /* relative to left of the window */
- int y; /* relative to top of the window */
+ int y; /* relative to the top of the window */
};
enum Type : int {
Unknown,
Closed, /* Window closed */
Resized, /* Window resized */
+ LostFocus,
+ GainedFocus,
TextEntered,
KeyPressed,
KeyReleased,
MouseButtonPressed,
MouseButtonReleased,
+ MouseWheelScrolled,
MouseMoved
};
@@ -59,6 +68,7 @@ namespace mgl {
TextEvent text;
KeyEvent key;
MouseButtonEvent mouse_button;
+ MouseWheelScrollEvent mouse_wheel_scroll;
MouseMoveEvent mouse_move;
};
};
diff --git a/include/mglpp/window/Keyboard.hpp b/include/mglpp/window/Keyboard.hpp
index b744143..17c4d7c 100644
--- a/include/mglpp/window/Keyboard.hpp
+++ b/include/mglpp/window/Keyboard.hpp
@@ -107,7 +107,10 @@ namespace mgl {
F13,
F14,
F15,
- Pause
+ Pause,
+
+ /* This should always be the last key */
+ __NumKeys__
};
};
}
diff --git a/include/mglpp/window/Mouse.hpp b/include/mglpp/window/Mouse.hpp
index c53f076..4fed4a9 100644
--- a/include/mglpp/window/Mouse.hpp
+++ b/include/mglpp/window/Mouse.hpp
@@ -11,7 +11,10 @@ namespace mgl {
Right,
Middle,
XButton1,
- XButton2
+ XButton2,
+
+ /* This should always be the last mouse button */
+ __NumMouseButtons__
};
};
}
diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp
index 2ef6526..1ce399c 100644
--- a/include/mglpp/window/Window.hpp
+++ b/include/mglpp/window/Window.hpp
@@ -4,7 +4,10 @@
#include "../graphics/PrimitiveType.hpp"
#include "../graphics/Color.hpp"
#include "../system/vec.hpp"
+#include "Keyboard.hpp"
+#include "Mouse.hpp"
#include <stddef.h>
+#include <string>
extern "C" {
#include <mgl/window/window.h>
@@ -25,16 +28,19 @@ namespace mgl {
class Window {
public:
- class Delegate {
- public:
- virtual ~Delegate() = default;
- virtual void draw() = 0;
+ /* Has to match mgl_window_create_params */
+ struct CreateParams {
+ mgl::vec2i position;
+ mgl::vec2i size;
+ mgl::vec2i min_size; /* (0, 0) = no limit */
+ mgl::vec2i max_size; /* (0, 0) = no limit */
+ WindowHandle parent_window = 0; /* 0 = root window */
};
Window();
~Window();
- bool create(const char *title, int width, int height);
+ bool create(const char *title, CreateParams create_params);
// Initialize this window from an existing window
bool create(WindowHandle existing_window);
@@ -53,7 +59,11 @@ namespace mgl {
void set_key_repeat_enabled(bool enabled);
void set_cursor_visible(bool visible);
vec2i get_size() const;
- vec2i get_cursor_position() const;
+ void set_size(mgl::vec2i size);
+ void set_position(mgl::vec2i position);
+ /* if |minimum| is (0, 0) then there is no minimum limit, if |maximum| is (0, 0) then there is no maximum limit */
+ void set_size_limits(mgl::vec2i minimum, mgl::vec2i maximum);
+ vec2i get_mouse_position() const;
/*
This should be called every frame to retain the view.
@@ -64,6 +74,12 @@ namespace mgl {
void set_view(const View &new_view);
View get_view();
+ bool is_key_pressed(Keyboard::Key key) const;
+ bool is_mouse_button_pressed(Mouse::Button button) const;
+
+ void set_clipboard(const std::string &str);
+ std::string get_clipboard();
+
WindowHandle get_system_handle() const;
private:
mgl_window window;