diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-28 15:26:29 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-28 15:26:29 +0200 |
commit | e7da86053b3df2882816b0df8089e1a51b61939f (patch) | |
tree | 8f7430f7d1e82ddb8449548886f57a3a7c646c05 /src/layer.h | |
parent | 9b134ea457f91ba8ea6ae558c9192f58c09f62bc (diff) | |
download | osc-graphics-e7da86053b3df2882816b0df8089e1a51b61939f.tar.gz |
autotools based build system
Diffstat (limited to 'src/layer.h')
-rw-r--r-- | src/layer.h | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/src/layer.h b/src/layer.h new file mode 100644 index 0000000..21fab50 --- /dev/null +++ b/src/layer.h @@ -0,0 +1,125 @@ +#ifndef __HAVE_LAYER_H +#define __HAVE_LAYER_H + +#include <string.h> +#include <bsd/sys/queue.h> + +#include <SDL.h> +#include <SDL_thread.h> + +#include <lo/lo.h> + +#include "osc_graphics.h" +#include "osc_server.h" + +extern OSCServer osc_server; + +class Layer { + SDL_mutex *mutex; + +public: + /* + * Every derived class must have a static CtorInfo struct "ctor_info" + * and a static "ctor_osc" method + */ + struct CtorInfo { + const char *name; + const char *types; + }; + + LIST_ENTRY(Layer) layers; + + char *name; + + Layer(const char *name); + virtual ~Layer(); + + inline void + lock() + { + SDL_LockMutex(mutex); + } + inline void + unlock() + { + SDL_UnlockMutex(mutex); + } + + /* + * Frame render method + */ + virtual void frame(SDL_Surface *target) = 0; + +protected: + inline OSCServer::MethodHandlerId * + register_method(const char *method, const char *types, + OSCServer::MethodHandlerCb method_cb) + { + return osc_server.register_method(this, method, types, method_cb); + } + inline void + unregister_method(OSCServer::MethodHandlerId *hnd) + { + osc_server.unregister_method(hnd); + } + + /* + * Default methods + */ + virtual void geo(SDL_Rect geo) = 0; + virtual void alpha(float opacity) = 0; + +private: + /* + * OSC handler methods + */ + OSCServer::MethodHandlerId *geo_osc_id; + static void + geo_osc(Layer *obj, lo_arg **argv) + { + SDL_Rect geo = { + (Sint16)argv[0]->i, (Sint16)argv[1]->i, + (Uint16)argv[2]->i, (Uint16)argv[3]->i + }; + obj->geo(geo); + } + OSCServer::MethodHandlerId *alpha_osc_id; + static void + alpha_osc(Layer *obj, lo_arg **argv) + { + obj->alpha(argv[0]->f); + } +}; + +class LayerList { + LIST_HEAD(layers_head, Layer) head; + + SDL_mutex *mutex; + + inline void + lock() + { + SDL_LockMutex(mutex); + } + inline void + unlock() + { + SDL_UnlockMutex(mutex); + } + +public: + LayerList() : mutex(SDL_CreateMutex()) + { + LIST_INIT(&head); + } + ~LayerList() + { + SDL_DestroyMutex(mutex); + } + + void insert(int pos, Layer *layer); + void delete_layer(Layer *layer); + void render(SDL_Surface *target); +}; + +#endif
\ No newline at end of file |