diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-17 03:39:01 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-17 03:39:01 +0200 |
commit | abfc56b8c4fc768593c7afdd1961aab35c0468c4 (patch) | |
tree | 1d39b8312b4ae0abdf63c3a1708be67f3c873811 | |
parent | d7eb9b29c8bcfd9ca97e0604b5b1868b3967164e (diff) | |
download | osc-graphics-abfc56b8c4fc768593c7afdd1961aab35c0468c4.tar.gz |
all layer constructor methods support an alpha argument
-rw-r--r-- | chuck/OSCGraphics.ck | 37 | ||||
-rw-r--r-- | chuck/OSCGraphicsLayer.ck | 5 | ||||
-rw-r--r-- | main.c | 32 |
3 files changed, 44 insertions, 30 deletions
diff --git a/chuck/OSCGraphics.ck b/chuck/OSCGraphics.ck index 6c8dd9f..2c3c25e 100644 --- a/chuck/OSCGraphics.ck +++ b/chuck/OSCGraphics.ck @@ -17,30 +17,36 @@ public class OSCGraphics { return img; } fun static OSCGraphicsImage @ - newImage(int pos, int geo[], string file) + newImage(int pos, int geo[], float opacity, string file) { OSCGraphicsImage img; - img.init(osc_send, "image", "s", pos, "__image_"+free_id, geo); + img.init(osc_send, "image", "s", + pos, "__image_"+free_id, geo, opacity); file => osc_send.addString; free_id++; return img; } fun static OSCGraphicsImage @ + newImage(int pos, int geo[], float opacity) + { + return newImage(pos, geo, opacity, ""); + } + fun static OSCGraphicsImage @ newImage(int pos, int geo[]) { - return newImage(pos, geo, ""); + return newImage(pos, geo, 1., ""); } fun static OSCGraphicsImage @ newImage(int pos) { - return newImage(pos, null, ""); + return newImage(pos, null, 1., ""); } fun static OSCGraphicsImage @ newImage() { - return newImage(-1, null, ""); + return newImage(-1, null, 1., ""); } fun static OSCGraphicsVideo @ @@ -52,30 +58,36 @@ public class OSCGraphics { return video; } fun static OSCGraphicsVideo @ - newVideo(int pos, int geo[], string file) + newVideo(int pos, int geo[], float opacity, string file) { OSCGraphicsVideo video; - video.init(osc_send, "video", "s", pos, "__video_"+free_id, geo); + video.init(osc_send, "video", "s", + pos, "__video_"+free_id, geo, opacity); file => osc_send.addString; free_id++; return video; } fun static OSCGraphicsVideo @ + newVideo(int pos, int geo[], float opacity) + { + return newVideo(pos, geo, 1., ""); + } + fun static OSCGraphicsVideo @ newVideo(int pos, int geo[]) { - return newVideo(pos, geo, ""); + return newVideo(pos, geo, 1., ""); } fun static OSCGraphicsVideo @ newVideo(int pos) { - return newVideo(pos, null, ""); + return newVideo(pos, null, 1., ""); } fun static OSCGraphicsVideo @ newVideo() { - return newVideo(-1, null, ""); + return newVideo(-1, null, 1., ""); } fun static OSCGraphicsBox @ @@ -91,8 +103,8 @@ public class OSCGraphics { { OSCGraphicsBox box; - box.init(osc_send, "box", "fiii", pos, "__box_"+free_id, geo); - opacity => osc_send.addFloat; + box.init(osc_send, "box", "iii", + pos, "__box_"+free_id, geo, opacity); for (0 => int i; i < 3; i++) color[i] => osc_send.addInt; @@ -114,7 +126,6 @@ public class OSCGraphics { { return newBox(-1, null, 1., color); } - } /* static initialization */ new OscSend @=> OSCGraphics.osc_send; diff --git a/chuck/OSCGraphicsLayer.ck b/chuck/OSCGraphicsLayer.ck index 9aed84e..77afd98 100644 --- a/chuck/OSCGraphicsLayer.ck +++ b/chuck/OSCGraphicsLayer.ck @@ -4,7 +4,7 @@ public class OSCGraphicsLayer { fun void init(OscSend @osc_send, string type, string osc_types, - int pos, string name, int geo[]) /* pseudo-constructor */ + int pos, string name, int geo[], float opacity) /* pseudo-constructor */ { if (geo == null) [0, 0, 0, 0] @=> geo; @@ -12,11 +12,12 @@ public class OSCGraphicsLayer { osc_send @=> this.osc_send; name => this.name; - osc_send.startMsg("/layer/new/"+type, "isiiii"+osc_types); + osc_send.startMsg("/layer/new/"+type, "isiiiif"+osc_types); pos => osc_send.addInt; name => osc_send.addString; for (0 => int i; i < 4; i++) geo[i] => osc_send.addInt; + opacity => osc_send.addFloat; } class GeoPort extends OSCGraphicsPort { @@ -50,9 +50,9 @@ __FILE__, __LINE__, ##__VA_ARGS__, IMG_GetError()); \ } while (0) -#define GEO_TYPES "iiii" /* x, y, width, height */ -#define NEW_LAYER_TYPES "is" GEO_TYPES /* position, name */ -#define COLOR_TYPES "iii" /* r, g, b */ +#define GEO_TYPES "iiii" /* x, y, width, height */ +#define NEW_LAYER_TYPES "is" GEO_TYPES "f" /* position, name, GEO, alpha */ +#define COLOR_TYPES "iii" /* r, g, b */ /* * Default values @@ -71,15 +71,16 @@ static int layer_insert(int pos, const char *name, void *data, layer_frame_cb_t frame_cb, layer_free_cb_t free_cb); static int layer_delete_by_name(const char *name); -static struct layer_image *layer_image_new(SDL_Rect geo, const char *file); +static struct layer_image *layer_image_new(SDL_Rect geo, float opacity, + const char *file); static void layer_image_geo(struct layer_image *ctx, SDL_Rect geo); static void layer_image_change(struct layer_image *ctx, const char *file); static void layer_image_alpha(struct layer_image *ctx, float opacity); static void layer_image_frame_cb(void *data, SDL_Surface *target); static void layer_image_free_cb(void *data); -static struct layer_video *layer_video_new(SDL_Rect geo, const char *file, - SDL_Color *key); +static struct layer_video *layer_video_new(SDL_Rect geo, float opacity, + const char *file, SDL_Color *key); static void layer_video_geo(struct layer_video *ctx, SDL_Rect geo); static void layer_video_change(struct layer_video *ctx, const char *file, SDL_Color *key); @@ -239,7 +240,7 @@ osc_image_new(const char *path, const char *types, lo_arg **argv, (Uint16)argv[4]->i, (Uint16)argv[5]->i }; - struct layer_image *ctx = layer_image_new(geo, &argv[6]->s); + struct layer_image *ctx = layer_image_new(geo, argv[6]->f, &argv[7]->s); if (layer_insert(argv[0]->i, &argv[1]->s, ctx, layer_image_frame_cb, layer_image_free_cb)) @@ -306,7 +307,8 @@ osc_video_new(const char *path, const char *types, lo_arg **argv, (Uint16)argv[4]->i, (Uint16)argv[5]->i }; - struct layer_video *ctx = layer_video_new(geo, &argv[6]->s, NULL); + struct layer_video *ctx = layer_video_new(geo, argv[6]->f, + &argv[7]->s, NULL); if (layer_insert(argv[0]->i, &argv[1]->s, ctx, layer_video_frame_cb, layer_video_free_cb)) @@ -383,10 +385,10 @@ osc_box_new(const char *path, const char *types, lo_arg **argv, (Uint16)argv[4]->i, (Uint16)argv[5]->i }; SDL_Color color = { - (Uint8)argv[6]->i, (Uint8)argv[7]->i, (Uint8)argv[8]->i + (Uint8)argv[7]->i, (Uint8)argv[8]->i, (Uint8)argv[9]->i }; - struct layer_box *ctx = layer_box_new(geo, argv[9]->f, color); + struct layer_box *ctx = layer_box_new(geo, argv[6]->f, color); if (layer_insert(argv[0]->i, &argv[1]->s, ctx, layer_box_frame_cb, layer_box_free_cb)) @@ -415,7 +417,7 @@ osc_init(const char *port) osc_image_new, server); lo_server_add_method(server, "/layer/new/video", NEW_LAYER_TYPES "s", osc_video_new, server); - lo_server_add_method(server, "/layer/new/box", NEW_LAYER_TYPES COLOR_TYPES "f", + lo_server_add_method(server, "/layer/new/box", NEW_LAYER_TYPES COLOR_TYPES, osc_box_new, server); return server; @@ -440,7 +442,7 @@ struct layer_image { }; static struct layer_image * -layer_image_new(SDL_Rect geo, const char *file) +layer_image_new(SDL_Rect geo, float opacity, const char *file) { struct layer_image *ctx = malloc(sizeof(struct layer_image)); @@ -449,7 +451,7 @@ layer_image_new(SDL_Rect geo, const char *file) memset(ctx, 0, sizeof(*ctx)); - layer_image_alpha(ctx, 1.); + layer_image_alpha(ctx, opacity); layer_image_geo(ctx, geo); layer_image_change(ctx, file); @@ -666,7 +668,7 @@ layer_video_display_cb(void *data __attribute__((unused)), void *id) } static struct layer_video * -layer_video_new(SDL_Rect geo, const char *file, SDL_Color *key) +layer_video_new(SDL_Rect geo, float opacity, const char *file, SDL_Color *key) { char const *vlc_argv[] = { "--no-audio", /* skip any audio track */ @@ -679,7 +681,7 @@ layer_video_new(SDL_Rect geo, const char *file, SDL_Color *key) memset(ctx, 0, sizeof(*ctx)); - ctx->alpha = 1.; + ctx->alpha = opacity; ctx->mutex = SDL_CreateMutex(); layer_video_geo(ctx, geo); |