aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graphics/Font.cpp8
-rw-r--r--src/graphics/Image.cpp34
-rw-r--r--src/graphics/Rectangle.cpp8
-rw-r--r--src/graphics/Sprite.cpp20
-rw-r--r--src/graphics/Text.cpp4
-rw-r--r--src/window/Window.cpp41
6 files changed, 93 insertions, 22 deletions
diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp
index 7d157ed..7b5dd68 100644
--- a/src/graphics/Font.cpp
+++ b/src/graphics/Font.cpp
@@ -9,10 +9,14 @@ namespace mgl {
mgl_font_unload(&font);
}
- bool Font::load_from_file(const char *filepath, unsigned int font_size) {
+ bool Font::load_from_file(const char *filepath, unsigned int character_size) {
if(font.texture.id)
return false;
- return mgl_font_load_from_file(&font, filepath, font_size) == 0;
+ return mgl_font_load_from_file(&font, filepath, character_size) == 0;
+ }
+
+ unsigned int Font::get_character_size() const {
+ return font.character_size;
}
mgl_font* Font::internal_font() {
diff --git a/src/graphics/Image.cpp b/src/graphics/Image.cpp
new file mode 100644
index 0000000..4c9a222
--- /dev/null
+++ b/src/graphics/Image.cpp
@@ -0,0 +1,34 @@
+#include "../../include/mglpp/graphics/Image.hpp"
+#include <string.h>
+
+namespace mgl {
+ Image::Image() {
+ memset(&image, 0, sizeof(image));
+ }
+
+ Image::~Image() {
+ mgl_image_unload(&image);
+ }
+
+ bool Image::load_from_file(const char *filepath) {
+ if(image.data)
+ return false;
+ return mgl_image_load_from_file(&image, filepath) == 0;
+ }
+
+ unsigned char* Image::data() {
+ return image.data;
+ }
+
+ size_t Image::byte_size() {
+ return mgl_image_get_size(&image);
+ }
+
+ vec2i Image::size() const {
+ return { image.width, image.height };
+ }
+
+ mgl_image* Image::internal_image() {
+ return &image;
+ }
+} \ No newline at end of file
diff --git a/src/graphics/Rectangle.cpp b/src/graphics/Rectangle.cpp
index 17060c7..f6961f7 100644
--- a/src/graphics/Rectangle.cpp
+++ b/src/graphics/Rectangle.cpp
@@ -19,6 +19,14 @@ namespace mgl {
rectangle.color = { color.r, color.g, color.b, color.a };
}
+ vec2f Rectangle::get_position() const {
+ return { rectangle.position.x, rectangle.position.y };
+ }
+
+ void Rectangle::set_size(vec2f size) {
+ rectangle.size = { size.x, size.y };
+ }
+
void Rectangle::draw(Window&) {
mgl_rectangle_draw(mgl_get_context(), &rectangle);
}
diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp
index ce32aa3..63caa79 100644
--- a/src/graphics/Sprite.cpp
+++ b/src/graphics/Sprite.cpp
@@ -22,6 +22,26 @@ namespace mgl {
mgl_sprite_set_color(&sprite, {color.r, color.g, color.b, color.a});
}
+ vec2f Sprite::get_position() const {
+ return { sprite.position.x, sprite.position.y };
+ }
+
+ void Sprite::set_scale(vec2f scale) {
+ sprite.scale = { scale.x, scale.y };
+ }
+
+ void Sprite::set_scale(float scale) {
+ sprite.scale = { scale, scale };
+ }
+
+ vec2f Sprite::get_scale() const {
+ return { sprite.scale.x, sprite.scale.y };
+ }
+
+ const Texture& Sprite::get_texture() const {
+ return texture;
+ }
+
void Sprite::draw(Window&) {
mgl_sprite_draw(mgl_get_context(), &sprite);
}
diff --git a/src/graphics/Text.cpp b/src/graphics/Text.cpp
index e598b2f..094b198 100644
--- a/src/graphics/Text.cpp
+++ b/src/graphics/Text.cpp
@@ -22,6 +22,10 @@ namespace mgl {
mgl_text_set_color(&text, {color.r, color.g, color.b, color.a});
}
+ vec2f Text::get_position() const {
+ return { text.position.x, text.position.y };
+ }
+
void Text::draw(Window&) {
mgl_text_draw(mgl_get_context(), &text);
}
diff --git a/src/window/Window.cpp b/src/window/Window.cpp
index d4518eb..bc1f5ac 100644
--- a/src/window/Window.cpp
+++ b/src/window/Window.cpp
@@ -1,13 +1,13 @@
#include "../../include/mglpp/window/Window.hpp"
+#include "../../include/mglpp/window/Event.hpp"
#include "../../include/mglpp/graphics/Drawable.hpp"
-namespace mgl {
- static void draw_callback(mgl_window *window, void *userdata) {
- Window *windowpp = (Window*)userdata;
- windowpp->get_delegate()->draw();
- }
+extern "C" {
+#include <mgl/window/event.h>
+}
- Window::Window(Delegate *delegate) : delegate(delegate) {
+namespace mgl {
+ Window::Window() {
window.window = 0;
}
@@ -18,23 +18,22 @@ namespace mgl {
bool Window::create(const char *title, int width, int height) {
if(window.window)
return false;
-
- mgl_window_callback callback;
- callback.userdata = this;
- callback.draw = draw_callback;
- return mgl_window_create_with_params(&window, title, width, height, 0, &callback) == 0;
+ return mgl_window_create_with_params(&window, title, width, height, 0) == 0;
}
- void Window::poll_events() {
+ bool Window::poll_event(Event &event) {
if(!window.window)
- return;
- mgl_window_events_poll(&window);
+ return false;
+
+ /* TODO: Convert c_event to |event| */
+ mgl_event c_event;
+ return mgl_window_poll_event(&window, &c_event);
}
- void Window::draw() {
+ void Window::clear(mgl::Color color) {
if(!window.window)
return;
- mgl_window_draw(&window);
+ mgl_window_clear(&window, mgl_color{color.r, color.g, color.b, color.a});
}
void Window::draw(Drawable &drawable) {
@@ -42,11 +41,13 @@ namespace mgl {
drawable.draw(*this);
}
- vec2i Window::get_cursor_position() const {
- return { window.cursor_position.x, window.cursor_position.y };
+ void Window::display() {
+ if(!window.window)
+ return;
+ mgl_window_display(&window);
}
- Window::Delegate* Window::get_delegate() {
- return delegate;
+ vec2i Window::get_cursor_position() const {
+ return { window.cursor_position.x, window.cursor_position.y };
}
} \ No newline at end of file