aboutsummaryrefslogtreecommitdiff
path: root/src/layer_box.cpp
blob: b720d5c7b860effb442eda552cfe5aff1d98d24a (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
#include <math.h>

#include <SDL.h>
#include <SDL_gfxPrimitives.h>

#include "osc_graphics.h"
#include "layer_box.h"

Layer::CtorInfo LayerBox::ctor_info = {"box", COLOR_TYPES};

LayerBox::LayerBox(const char *name, SDL_Rect geo, float opacity,
		   SDL_Color color) : Layer(name)
{
	color_osc_id = register_method("color", COLOR_TYPES,
				       (OSCServer::MethodHandlerCb)color_osc);

	LayerBox::geo(geo);
	LayerBox::color(color);
	LayerBox::alpha(opacity);
}

void
LayerBox::geo(SDL_Rect geo)
{
	x1 = geo.x;
	y1 = geo.y;
	x2 = geo.x + geo.w;
	y2 = geo.y + geo.h;
}

void
LayerBox::alpha(float opacity)
{
	a = (Uint8)ceilf(opacity*SDL_ALPHA_OPAQUE);
}

void
LayerBox::frame(SDL_Surface *target)
{
	boxRGBA(target, x1, y1, x2 ? : target->w, y2 ? : target->h,
		r, g, b, a);
}

LayerBox::~LayerBox()
{
	unregister_method(color_osc_id);
}