summaryrefslogtreecommitdiff
path: root/src/idlist.c
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2018-07-03 15:11:54 +0300
committerOxore <oxore@protonmail.com>2018-07-03 15:11:54 +0300
commited8127a72e1a2d2703372d5b5dfa8d96703ec3bb (patch)
tree80f340c64861913f2dc648c2c7280c144b988881 /src/idlist.c
parent21a0a44853451f3d791bafc80c01deab0ff4c79e (diff)
Refactor field, refactor next shape drawing
Refactor field functions names. Transfer next shape drawing to painter. Introduce idlist struct with foreach function. Refactor config. Introduce color map array instead of "switch case" statement bloating while coloring rectangles. Decouple field and shape structs from SFML sfVector2 structs by introducing own vector2i and vector2ui structs. Also remove sfRectangleShape members form field an shape structs.
Diffstat (limited to 'src/idlist.c')
-rw-r--r--src/idlist.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/idlist.c b/src/idlist.c
new file mode 100644
index 0000000..5b4d99b
--- /dev/null
+++ b/src/idlist.c
@@ -0,0 +1,55 @@
+#include <stdlib.h>
+#include "idlist.h"
+
+struct idlist *list_new()
+{
+ struct idlist *list = calloc(1, sizeof(struct idlist));
+ list->id = 1;
+ return list;
+}
+
+struct idlist *list_append(struct idlist *list)
+{
+ if (!list)
+ return list;
+ struct idlist *last = list;
+ while (last->next)
+ last = last->next;
+ last->next = calloc(1, sizeof(struct idlist));
+ last->next->id = last->id + 1;
+ last->next->prev = last;
+ return last->next;
+}
+
+struct idlist *list_get(const struct idlist *list, unsigned long id)
+{
+ const struct idlist *sought = list;
+ if (sought) {
+ if (sought->id == id)
+ return (struct idlist *)sought;
+ while ((sought = sought->next))
+ if (sought->id == id)
+ return (struct idlist *)sought;
+ }
+ return NULL;
+}
+
+void list_rm_node(struct idlist *node)
+{
+ if (node) {
+ if (node->prev)
+ node->prev->next = node->next;
+ if (node->next)
+ node->next->prev = node->prev;
+ free(node);
+ }
+}
+
+void list_foreach(struct idlist *list, void (*job)(void *))
+{
+ if (list) {
+ job(list->obj);
+ while ((list = list->next))
+ job(list->obj);
+ }
+}