aboutsummaryrefslogtreecommitdiff
path: root/layer_image.h
diff options
context:
space:
mode:
Diffstat (limited to 'layer_image.h')
-rw-r--r--layer_image.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/layer_image.h b/layer_image.h
new file mode 100644
index 0000000..7f51885
--- /dev/null
+++ b/layer_image.h
@@ -0,0 +1,54 @@
+#ifndef __HAVE_LAYER_IMAGE_H
+#define __HAVE_LAYER_IMAGE_H
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <SDL.h>
+
+#include "osc_graphics.h"
+#include "layer.h"
+
+class LayerImage : public Layer {
+ SDL_Surface *surf_alpha; /* with per-surface alpha */
+ SDL_Surface *surf_scaled; /* scaled image */
+ SDL_Surface *surf; /* original image */
+
+ SDL_Rect geov;
+ float alphav;
+
+public:
+ LayerImage(const char *name,
+ SDL_Rect geo = (SDL_Rect){0, 0, 0, 0},
+ float opacity = 1.,
+ const char *file = NULL) : Layer(name), surf_alpha(NULL), surf_scaled(NULL), surf(NULL)
+ {
+ LayerImage::alpha(opacity);
+ LayerImage::geo(geo);
+ LayerImage::file(file);
+ }
+
+ ~LayerImage()
+ {
+ SDL_FREESURFACE_SAFE(surf_alpha);
+ SDL_FREESURFACE_SAFE(surf_scaled);
+ SDL_FREESURFACE_SAFE(surf);
+ }
+
+ void geo(SDL_Rect geo);
+ void alpha(float opacity);
+
+ void file(const char *file = NULL);
+
+ void frame(SDL_Surface *target);
+};
+
+/*
+ * Macros
+ */
+#define SDL_IMAGE_ERROR(FMT, ...) do { \
+ fprintf(stderr, "%s(%d): " FMT ": %s\n", \
+ __FILE__, __LINE__, ##__VA_ARGS__, IMG_GetError()); \
+} while (0)
+
+#endif