|
|
@@ -2,6 +2,8 @@
|
|
|
#include <gl2d/gl2d.h>
|
|
|
#include <sushi/sushiPrimitives.h>
|
|
|
#include <sushi/sushiInput.h>
|
|
|
+#include <unordered_map>
|
|
|
+#include <map>
|
|
|
|
|
|
namespace sushi
|
|
|
{
|
|
|
@@ -13,7 +15,7 @@ namespace sushi
|
|
|
SushiUiElement(const char *name, int id)
|
|
|
{
|
|
|
this->id = id;
|
|
|
- std::strncpy(this->name, name, sizeof(name) - 1);
|
|
|
+ std::strncpy(this->name, name, sizeof(this->name) - 1);
|
|
|
};
|
|
|
|
|
|
char name[16] = {};
|
|
|
@@ -28,57 +30,18 @@ namespace sushi
|
|
|
|
|
|
};
|
|
|
|
|
|
- struct SushiParent;
|
|
|
-
|
|
|
- //parent or ui
|
|
|
- struct SushiElement
|
|
|
- {
|
|
|
- SushiElement() {};
|
|
|
- SushiElement(void *ptr, int type):ptr(ptr), type(type) {};
|
|
|
- SushiElement(SushiUiElement *ptr):ptr(ptr), type(TypeUiElement) {};
|
|
|
- SushiElement(SushiParent *ptr):ptr(ptr), type(TypeParent) {};
|
|
|
-
|
|
|
- void *ptr = 0;
|
|
|
- int type = 0;
|
|
|
-
|
|
|
- enum Type
|
|
|
- {
|
|
|
- TypeUiElement = 1,
|
|
|
- TypeParent = 2,
|
|
|
- };
|
|
|
-
|
|
|
- SushiUiElement *getUiElement()
|
|
|
- {
|
|
|
- if (type == TypeUiElement)
|
|
|
- {
|
|
|
- return (SushiUiElement *)ptr;
|
|
|
- }
|
|
|
- else { return 0; }
|
|
|
- }
|
|
|
-
|
|
|
- SushiParent *getParent()
|
|
|
- {
|
|
|
- if (type == TypeParent)
|
|
|
- {
|
|
|
- return (SushiParent *)ptr;
|
|
|
- }
|
|
|
- else { return 0; }
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
struct SushiParent
|
|
|
{
|
|
|
SushiParent() {};
|
|
|
SushiParent(const char *name, int id)
|
|
|
{
|
|
|
this->id = id;
|
|
|
- std::strncpy(this->name, name, sizeof(name) - 1);
|
|
|
+ std::strncpy(this->name, name, sizeof(this->name) - 1);
|
|
|
};
|
|
|
SushiParent(const char *name, int id, Background b)
|
|
|
{
|
|
|
this->id = id;
|
|
|
- std::strncpy(this->name, name, sizeof(name) - 1);
|
|
|
+ std::strncpy(this->name, name, sizeof(this->name) - 1);
|
|
|
background = b;
|
|
|
};
|
|
|
|
|
|
@@ -104,24 +67,82 @@ namespace sushi
|
|
|
|
|
|
void update(gl2d::Renderer2D &renderer,
|
|
|
sushi::SushiInput &input, glm::vec4 parentTransform);
|
|
|
-
|
|
|
+
|
|
|
OutData outData;
|
|
|
|
|
|
- bool deleteById(unsigned int id);
|
|
|
+ bool deleteByIdInternal(unsigned int id);
|
|
|
|
|
|
- void addElement(
|
|
|
+ void addElementInternal(
|
|
|
const char *name,
|
|
|
Transform &transform,
|
|
|
Background &background,
|
|
|
unsigned int id);
|
|
|
|
|
|
- void addParent(
|
|
|
+ void addParentInternal(
|
|
|
const char *name,
|
|
|
Transform &transform,
|
|
|
Background &background,
|
|
|
unsigned int id);
|
|
|
};
|
|
|
|
|
|
+ //parent or ui
|
|
|
+ struct SushiElement
|
|
|
+ {
|
|
|
+ SushiElement() {};
|
|
|
+ SushiElement(void *ptr, int type):ptr(ptr), type(type) {};
|
|
|
+ SushiElement(SushiUiElement *ptr):ptr(ptr), type(TypeUiElement) {};
|
|
|
+ SushiElement(SushiParent *ptr):ptr(ptr), type(TypeParent) {};
|
|
|
+
|
|
|
+ void *ptr = 0;
|
|
|
+ int type = 0;
|
|
|
+
|
|
|
+ enum Type
|
|
|
+ {
|
|
|
+ TypeUiElement = 1,
|
|
|
+ TypeParent = 2,
|
|
|
+ };
|
|
|
+
|
|
|
+ SushiUiElement *getUiElement()
|
|
|
+ {
|
|
|
+ if (type == TypeUiElement)
|
|
|
+ {
|
|
|
+ return (SushiUiElement *)ptr;
|
|
|
+ }
|
|
|
+ else { return 0; }
|
|
|
+ }
|
|
|
+
|
|
|
+ SushiParent *getParent()
|
|
|
+ {
|
|
|
+ if (type == TypeParent)
|
|
|
+ {
|
|
|
+ return (SushiParent *)ptr;
|
|
|
+ }
|
|
|
+ else { return 0; }
|
|
|
+ }
|
|
|
+
|
|
|
+ bool isUiElement() { return type == TypeUiElement; }
|
|
|
+ bool isParent() { return type == TypeParent; }
|
|
|
+ bool hasValue() { return (type != 0) && (ptr != nullptr); }
|
|
|
+ std::string getName()
|
|
|
+ {
|
|
|
+ if (hasValue())
|
|
|
+ {
|
|
|
+ if (isParent())
|
|
|
+ {
|
|
|
+ return getParent()->name;
|
|
|
+ }else if (isUiElement())
|
|
|
+ {
|
|
|
+ return getUiElement()->name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
//this is a sushi context. Holds all the windows and manages stuff
|
|
|
struct SushyContext
|
|
|
{
|
|
|
@@ -147,10 +168,23 @@ namespace sushi
|
|
|
Transform &transform,
|
|
|
Background &background);
|
|
|
|
|
|
+ bool deleteById(unsigned int id);
|
|
|
+
|
|
|
+ std::unordered_multimap<std::string, SushiElement> cachedData;
|
|
|
+
|
|
|
+ void signalElementToCacheInternl(SushiElement el);
|
|
|
+
|
|
|
+ void signalElementToCacheToRemoveInternal(SushiElement el);
|
|
|
+
|
|
|
+ SushiElement genUniqueElement(std::string name);
|
|
|
+
|
|
|
+ std::pair<std::unordered_multimap<std::string, SushiElement>::iterator,
|
|
|
+ std::unordered_multimap<std::string, SushiElement>::iterator> getElements(std::string name);
|
|
|
+
|
|
|
+ void rename(SushiElement el, char *newName);
|
|
|
};
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|