aboutsummaryrefslogtreecommitdiff
path: root/src/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics')
-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
5 files changed, 72 insertions, 2 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);
}