changeset 26:65398df5fb5c

core: add texture_get_size function
author David Demelier <markand@malikania.fr>
date Sun, 12 Jan 2020 21:01:10 +0100
parents 0d5ecefcccd3
children 607bd90aba63
files src/texture.c src/texture.h
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/texture.c	Fri Jan 10 20:08:26 2020 +0100
+++ b/src/texture.c	Sun Jan 12 21:01:10 2020 +0100
@@ -22,6 +22,25 @@
 #include "texture_p.h"
 #include "window_p.h"
 
+bool
+texture_get_size(struct texture *tex, uint16_t *w, uint16_t *h)
+{
+	assert(tex);
+
+	int rw, rh;
+
+	if (SDL_QueryTexture(tex->handle, NULL, NULL, &rw, &rh) < 0) {
+		*w = 0;
+		*h = 0;
+		return false;
+	}
+
+	*w = rw;
+	*h = rh;
+
+	return true;
+}
+
 void
 texture_draw(struct texture *tex, int x, int y)
 {
--- a/src/texture.h	Fri Jan 10 20:08:26 2020 +0100
+++ b/src/texture.h	Sun Jan 12 21:01:10 2020 +0100
@@ -26,6 +26,9 @@
  * See also \a image.h for usage of textures.
  */
 
+#include <stdbool.h>
+#include <stdint.h>
+
 /**
  * \brief Texture object.
  *
@@ -35,6 +38,17 @@
 struct texture;
 
 /**
+ * Get texture size.
+ *
+ * \pre tex != NULL
+ * \param tex the texture
+ * \param w the width
+ * \param h the height
+ */
+bool
+texture_get_size(struct texture *tex, uint16_t *w, uint16_t *h);
+
+/**
  * Simple texture drawing.
  *
  * \pre tex != NULL