diff options
Diffstat (limited to 'src/layer_box.cpp')
-rw-r--r-- | src/layer_box.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/layer_box.cpp b/src/layer_box.cpp new file mode 100644 index 0000000..b720d5c --- /dev/null +++ b/src/layer_box.cpp @@ -0,0 +1,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); +} |