您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

45 行
2.4 KiB

  1. //This is the central structure that is supposed to make this library be useful.
  2. //It is essentially a rose-tree structure that is traversed in a depth-first-esque manner.
  3. //When rendering, the tree is traversed in "left to right" fashion, rendering everything things as it goes.
  4. //When clicking, the tree is traversed in "right to left" fashion and stops at the first eligible object.
  5. //Possible todo: add usage of nifty means to figure out at runtime when updates are made to structure,
  6. // which objects don't need to be rendered at all and keep track of that by managing the tree structure more closely.
  7. //That might require some trickery, depending on how the management of this structure pans out.
  8. #ifndef SDL_CLICKY_CLICKABLE_HIERARCHY_H_
  9. #define SDL_CLICKY_CLICKABLE_HIERARCHY_H_
  10. #include "clickable.h"
  11. struct Clickable_Hierarchy_Element;
  12. //Simply a list of subtress that may be leaves.
  13. typedef struct {
  14. int num_children;
  15. int num_children_slots;
  16. struct Clickable_Hierarchy_Element* children;
  17. } Clickable_Hierarchy;
  18. //This one requires explanation.
  19. //The clickable should be self-explanatory, this is the clickable that this element represents.
  20. //The subtree, though, determines if this is a leaf (NULL) or not (!NULL). If !NULL, then the clickable is a container object.
  21. //How to use this, from a clickable and container perspective?
  22. // Clickable: Just add it and the subtree will be NULL.
  23. // Container: If your container only renders itself then it should add all of its subelements to the tree.
  24. // If it recursively renders all of its own subelements, then it should not add those to the tree because the tree would render them too.
  25. // That means, if you handle the rendering of subelements, just pretend to only be a clickable.
  26. // If you have a mix for some reason, register as a container but only add the subelements you don't handle yourself.
  27. typedef struct Clickable_Hierarchy_Element {
  28. Clickable* clickable;
  29. Clickable_Hierarchy* subtree;
  30. } Clickable_Hierarchy_Element;
  31. void Clicky_Clickable_Hierarchy_Render(Clickable_Hierarchy* ch, SDL_Renderer* r);
  32. bool Clicky_Clickable_Hierarchy_Click(Clickable_Hierarchy* ch, int x, int y);
  33. int Clicky_Clickable_Hierarchy_Add_Clickable(Clickable_Hierarchy* ch, Clickable* cl);
  34. Clickable_Hierarchy* Clicky_Clickable_Hierarchy_Add_Subtree(Clickable_Hierarchy* ch, Clickable* cl, int numchildren);
  35. #endif // SDL_CLICKY_CLICKABLE_HIERARCHY_H_