diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-10-18 01:54:59 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-10-18 01:54:59 +0200 |
commit | 3e081d1669622bbc276b038ddc38ecf0600683c3 (patch) | |
tree | 0a92c34f257c75a2b26e63b0ea9da3d594e89cc8 /include |
Initial commit with an example
Diffstat (limited to 'include')
-rw-r--r-- | include/mglpp/graphics/Color.hpp | 13 | ||||
-rw-r--r-- | include/mglpp/graphics/Drawable.hpp | 20 | ||||
-rw-r--r-- | include/mglpp/graphics/Font.hpp | 22 | ||||
-rw-r--r-- | include/mglpp/graphics/Rectangle.hpp | 24 | ||||
-rw-r--r-- | include/mglpp/graphics/Sprite.hpp | 27 | ||||
-rw-r--r-- | include/mglpp/graphics/Text.hpp | 27 | ||||
-rw-r--r-- | include/mglpp/graphics/Texture.hpp | 25 | ||||
-rw-r--r-- | include/mglpp/mglpp.hpp | 12 | ||||
-rw-r--r-- | include/mglpp/system/vec.hpp | 20 | ||||
-rw-r--r-- | include/mglpp/window/Window.hpp | 36 |
10 files changed, 226 insertions, 0 deletions
diff --git a/include/mglpp/graphics/Color.hpp b/include/mglpp/graphics/Color.hpp new file mode 100644 index 0000000..d1c1745 --- /dev/null +++ b/include/mglpp/graphics/Color.hpp @@ -0,0 +1,13 @@ +#ifndef MGLPP_COLOR_HPP +#define MGLPP_COLOR_HPP + +namespace mgl { + struct Color { + float r = 1.0f; + float g = 1.0f; + float b = 1.0f; + float a = 1.0f; + }; +} + +#endif /* MGLPP_COLOR_HPP */ diff --git a/include/mglpp/graphics/Drawable.hpp b/include/mglpp/graphics/Drawable.hpp new file mode 100644 index 0000000..3aa8d4f --- /dev/null +++ b/include/mglpp/graphics/Drawable.hpp @@ -0,0 +1,20 @@ +#ifndef MGLPP_DRAWABLE_HPP +#define MGLPP_DRAWABLE_HPP + +#include "Color.hpp" +#include "../system/vec.hpp" + +namespace mgl { + class Window; + class Drawable { + friend class Window; + public: + virtual ~Drawable() = default; + virtual void set_position(vec2f position) = 0; + virtual void set_color(Color color) = 0; + protected: + virtual void draw(Window &window) = 0; + }; +} + +#endif /* MGLPP_DRAWABLE_HPP */ diff --git a/include/mglpp/graphics/Font.hpp b/include/mglpp/graphics/Font.hpp new file mode 100644 index 0000000..1faa23a --- /dev/null +++ b/include/mglpp/graphics/Font.hpp @@ -0,0 +1,22 @@ +#ifndef MGLPP_FONT_HPP +#define MGLPP_FONT_HPP + +extern "C" { +#include <mgl/graphics/font.h> +} + +namespace mgl { + class Font { + public: + Font(); + ~Font(); + + bool load_from_file(const char *filepath, unsigned int font_size); + + mgl_font* internal_font(); + private: + mgl_font font; + }; +} + +#endif /* MGLPP_FONT_HPP */ diff --git a/include/mglpp/graphics/Rectangle.hpp b/include/mglpp/graphics/Rectangle.hpp new file mode 100644 index 0000000..7bc9373 --- /dev/null +++ b/include/mglpp/graphics/Rectangle.hpp @@ -0,0 +1,24 @@ +#ifndef MGLPP_RECTANGLE_HPP +#define MGLPP_RECTANGLE_HPP + +#include "Drawable.hpp" + +extern "C" { +#include <mgl/graphics/rectangle.h> +} + +namespace mgl { + class Rectangle : public Drawable { + public: + Rectangle(vec2f position, vec2f size); + + void set_position(vec2f position) override; + void set_color(Color color) override; + protected: + void draw(Window &window) override; + private: + mgl_rectangle rectangle; + }; +} + +#endif /* MGLPP_RECTANGLE_HPP */ diff --git a/include/mglpp/graphics/Sprite.hpp b/include/mglpp/graphics/Sprite.hpp new file mode 100644 index 0000000..8a03de5 --- /dev/null +++ b/include/mglpp/graphics/Sprite.hpp @@ -0,0 +1,27 @@ +#ifndef MGLPP_SPRITE_HPP +#define MGLPP_SPRITE_HPP + +#include "Drawable.hpp" + +extern "C" { +#include <mgl/graphics/sprite.h> +} + +namespace mgl { + class Texture; + class Sprite : public Drawable { + public: + Sprite(Texture &texture, vec2f position); + ~Sprite(); + + void set_position(vec2f position) override; + void set_color(Color color) override; + protected: + void draw(Window &window) override; + private: + mgl_sprite sprite; + Texture &texture; + }; +} + +#endif /* MGLPP_SPRITE_HPP */ diff --git a/include/mglpp/graphics/Text.hpp b/include/mglpp/graphics/Text.hpp new file mode 100644 index 0000000..d126994 --- /dev/null +++ b/include/mglpp/graphics/Text.hpp @@ -0,0 +1,27 @@ +#ifndef MGLPP_TEXT_HPP +#define MGLPP_TEXT_HPP + +#include "Drawable.hpp" + +extern "C" { +#include <mgl/graphics/text.h> +} + +namespace mgl { + class Font; + class Text : public Drawable { + public: + Text(const char *str, vec2f position, Font &font); + ~Text(); + + void set_position(vec2f position) override; + void set_color(Color color) override; + protected: + void draw(Window &window) override; + private: + mgl_text text; + Font &font; + }; +} + +#endif /* MGLPP_TEXT_HPP */ diff --git a/include/mglpp/graphics/Texture.hpp b/include/mglpp/graphics/Texture.hpp new file mode 100644 index 0000000..0bd1740 --- /dev/null +++ b/include/mglpp/graphics/Texture.hpp @@ -0,0 +1,25 @@ +#ifndef MGLPP_TEXTURE_HPP +#define MGLPP_TEXTURE_HPP + +#include "../system/vec.hpp" + +extern "C" { +#include <mgl/graphics/texture.h> +} + +namespace mgl { + class Texture { + public: + Texture(); + ~Texture(); + + bool load_from_file(const char *filepath); + vec2i size() const; + + mgl_texture* internal_texture(); + private: + mgl_texture texture; + }; +} + +#endif /* MGLPP_TEXTURE_HPP */ diff --git a/include/mglpp/mglpp.hpp b/include/mglpp/mglpp.hpp new file mode 100644 index 0000000..6e790af --- /dev/null +++ b/include/mglpp/mglpp.hpp @@ -0,0 +1,12 @@ +#ifndef MGLPP_MGLPP_HPP +#define MGLPP_MGLPP_HPP + +namespace mgl { + class Init { + public: + Init(); + ~Init(); + }; +} + +#endif /* MGLPP_MGLPP_HPP */ diff --git a/include/mglpp/system/vec.hpp b/include/mglpp/system/vec.hpp new file mode 100644 index 0000000..40262f0 --- /dev/null +++ b/include/mglpp/system/vec.hpp @@ -0,0 +1,20 @@ +#ifndef MGLPP_VEC_HPP +#define MGLPP_VEC_HPP + +namespace mgl { + struct vec2f { + float x = 0.0f; + float y = 0.0f; + }; + + struct vec2i { + int x = 0; + int y = 0; + + vec2f to_vec2f() const { + return { (float)x, (float)y }; + } + }; +} + +#endif /* MGLPP_VEC_HPP */ diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp new file mode 100644 index 0000000..79e999d --- /dev/null +++ b/include/mglpp/window/Window.hpp @@ -0,0 +1,36 @@ +#ifndef MGLPP_WINDOW_HPP +#define MGLPP_WINDOW_HPP + +#include "../system/vec.hpp" + +extern "C" { +#include <mgl/window/window.h> +} + +namespace mgl { + class Drawable; + class Window { + public: + class Delegate { + public: + virtual ~Delegate() = default; + virtual void draw() = 0; + }; + + Window(Delegate *delegate); + ~Window(); + + bool create(const char *title, int width, int height); + void poll_events(); + void draw(); + void draw(Drawable &drawable); + + vec2i get_cursor_position() const; + Delegate* get_delegate(); + private: + mgl_window window; + Delegate *delegate; + }; +} + +#endif /* MGLPP_WINDOW_HPP */ |