summaryrefslogtreecommitdiffstats
path: root/engine/include
diff options
context:
space:
mode:
Diffstat (limited to 'engine/include')
-rw-r--r--engine/include/core/signal.hpp108
-rw-r--r--engine/include/flatcomponent.h16
-rw-r--r--engine/include/flatsurface.h17
3 files changed, 77 insertions, 64 deletions
diff --git a/engine/include/core/signal.hpp b/engine/include/core/signal.hpp
index be1644a..8a3d639 100644
--- a/engine/include/core/signal.hpp
+++ b/engine/include/core/signal.hpp
@@ -21,10 +21,22 @@ namespace flat
{
public:
+
+ struct package
+ {
+ package(void *data) : data(data) {}
+
+ template<class T>
+ T * get() {
+
+ return dynamic_cast<T>(data);
+ }
+
+ void * data;
+ };
object * sender;
package m_package;
- priority_t prior;
signal( object * sender,
const std::string& id = "",
@@ -33,24 +45,47 @@ namespace flat
/* Alias to flat::core::channel::emit() */
bool emit(const std::string& channel) const;
+ };
+
+ /* Listener class */
+ class listener
+ {
+ public:
- struct package
+ using callback = std::function<void(const object*, signal::package)>;
+ using ptr = std::shared_ptr<listener>;
+
+ listener(callback m_callback, const std::initializer_list<std::string>& filters = {});
+ ~listener();
+
+ void add_filter(const std::string&);
+ void remove_filter(const std::string&);
+
+ bool connect(const std::string&);
+ bool disconnect(const std::string&);
+
+ void invoke(const signal&);
+
+ /* Allow to safely bind a functor */
+ template<typename R, typename T>
+ static ptr create( R T::*mf,
+ T& obj,
+ const std::initializer_list<std::string>& filters = {})
{
- package(void *data) : data(data) {}
+ return std::make_shared<listener>(std::bind(mf, obj), filters);
+ }
- template<class T>
- T * get() {
+ private:
- return dynamic_cast<T>(data);
- }
+ callback m_callback;
- void * data;
- };
+ std::list<std::string> filters;
+
+ bool check_in_filters(const std::string&) const;
};
-
/* Channel class */
- class channel : virtual public labelled
+ class channel : virtual public labelled, public std::enable_shared_from_this<channel>
{
/* Post processing signal stacking */
queue<signal> stack;
@@ -63,65 +98,34 @@ namespace flat
/* Channel mapping */
static std::map<std::string, std::weak_ptr<channel>> channels;
+
+ bool mapped;
public:
+
+ using ptr = std::shared_ptr<channel>;
- channel(const std::string& id = "", priority_t task_priority = priority_t::none);
+ channel(const std::string& id = "");
~channel();
- void start();
+ void start(priority_t task_priority = priority_t::none);
bool map();
void emit(const signal&);
bool connect(listener::ptr l);
void disconnect(listener::ptr l);
+
+ bool connect(listener* l);
+ void disconnect(listener* l);
static ptr find(const std::string&);
- static ptr create(const string& id, priority_t prior);
+ static ptr create(const std::string& id, priority_t prior);
void check_and_call();
-
- typedef shared_ptr<channel> ptr;
};
-
- /* Listener class */
- class listener
- {
- std::list<std::string> filters;
-
- bool check_in_filters(const std::string&) const;
-
- callback_t m_callback;
-
- public:
-
- listener( callback_t m_callback,
- const std::initializer_list<std::string>& filters = {});
-
- ~listener();
- void add_filter(const std::string&);
- void remove_filter(const std::string&);
-
- bool connect(const std::string&);
- bool disconnect(const std::string&);
-
- void invoke(const signal&);
-
- /* Allow to safely bind a functor */
- template<class T>
- static ptr create( const (T::*method(const object*, void*))& fct,
- T* obj,
- const std::initializer_list<std::string>& filters = {})
- {
- return new listener(std::bind(fct, ptr), filters);
- }
-
- typedef std::function<void(const object*, signal::package)> callback_t;
- typedef shared_ptr<listener> ptr;
- };
}
}
diff --git a/engine/include/flatcomponent.h b/engine/include/flatcomponent.h
index 881e34f..4ad99c8 100644
--- a/engine/include/flatcomponent.h
+++ b/engine/include/flatcomponent.h
@@ -5,24 +5,28 @@
#include "core/labelled.hpp"
#include <string>
-class Component : virtual public flat::core::object, virtual public flat::core::labelled
+namespace flat {
+
+class component : virtual public core::object, virtual public core::labelled
{
- Component * parent;
+ component * m_parent;
public:
/* Zero means attach to main window layer */
/* Send a 'created' signal in component reserved channel */
- Component(Component *parent = 0, const std::string& id = "");
+ component(component *parent = 0, const std::string& id = "");
/* Send a 'deleted' signal in component reserved channel */
- virtual ~Component();
+ virtual ~component();
- void setParent(Component*);
- Component * getParent();
+ void set_parent(component*);
+ component * parent();
virtual void render() = 0;
};
+}
+
#endif
diff --git a/engine/include/flatsurface.h b/engine/include/flatsurface.h
index fff07dd..5364e8e 100644
--- a/engine/include/flatsurface.h
+++ b/engine/include/flatsurface.h
@@ -2,11 +2,14 @@
#define __FLATSURFACE_H__
#include "core/object.hpp"
+#include "core/labelled.hpp"
#include <SDL2/SDL.h>
-class FlatSurface : public flat::core::object
+namespace flat {
+
+class surface : virtual public core::object, virtual public core::labelled
{
- SDL_Surface * surface;
+ SDL_Surface * sdl_surface;
SDL_Surface * parent;
SDL_Rect * offset;
@@ -16,12 +19,12 @@ class FlatSurface : public flat::core::object
public:
- FlatSurface(const char *filename, uint32_t format = SDL_PIXELFORMAT_RGBA32, SDL_Surface *parent = 0);
- FlatSurface(SDL_Surface *surface, SDL_Surface *parent = 0);
+ surface(const char *filename, uint32_t format = SDL_PIXELFORMAT_RGBA32, SDL_Surface *parent = 0);
+ surface(SDL_Surface *surf, SDL_Surface *parent = 0);
- FlatSurface(const FlatSurface&);
+ surface(const surface&);
- ~FlatSurface();
+ ~surface();
void setOffset(int, int, int w = -1, int h = -1);
@@ -52,4 +55,6 @@ public:
static SDL_Surface * copySurface(SDL_Surface*);
};
+}
+
#endif