aboutsummaryrefslogtreecommitdiff
path: root/layer_image.h
blob: e374053f2cc80e5ed81294e34023eb0ae2bdfd63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef __LAYER_IMAGE_H
#define __LAYER_IMAGE_H

#include <stdlib.h>
#include <stdio.h>

#include <SDL.h>

#include "osc_graphics.h"
#include "layer.h"

#define LayerImage_Info_Name	"image"
#define LayerImage_Info_Types	"s"	/* file */

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:
	static void register_layer() {}

	LayerImage(const char *name,
		   SDL_Rect geo = (SDL_Rect){0, 0, 0, 0},
		   float opacity = 1.,
		   const char *file = NULL);
	static Layer *
	ctor_osc(const char *name, SDL_Rect geo, float opacity, lo_arg **argv)
	{
		return new LayerImage(name, geo, opacity, &argv[0]->s);
	}
	~LayerImage();

	void frame(SDL_Surface *target);

private:
	void geo(SDL_Rect geo);
	void alpha(float opacity);

	void file(const char *file = NULL);
	OSCServer::MethodHandlerId *file_osc_id;
	static void
	file_osc(LayerImage *obj, lo_arg **argv)
	{
		obj->file(&argv[0]->s);
	}
};

/*
 * Macros
 */
#define SDL_IMAGE_ERROR(FMT, ...) do {					\
	fprintf(stderr, "%s(%d): " FMT ": %s\n",			\
		__FILE__, __LINE__, ##__VA_ARGS__, IMG_GetError());	\
} while (0)

#endif