From 43b1a466695a9aeec5f77eafb3c56b29cd40a0fd Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 3 Jun 2018 17:28:54 -0400 Subject: [PATCH] Wrote the common table data functions. --- common/CMakeLists.txt | 1 + common/tabledata.c | 105 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 common/tabledata.c diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 4ef742d6..23cf663b 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -12,6 +12,7 @@ list(APPEND _LIBUI_SOURCES common/opentype.c common/shouldquit.c common/table.c + common/tabledata.c common/userbugs.c common/utf.c ) diff --git a/common/tabledata.c b/common/tabledata.c new file mode 100644 index 00000000..25710bcf --- /dev/null +++ b/common/tabledata.c @@ -0,0 +1,105 @@ +// 3 june 2018 +#include "../ui.h" +#include "uipriv.h" + +struct uiTableData { + uiTableDataType type; + union { + char *str; + uiImage *img; + int i; + struct { + double r; + double g; + double b; + double a; + } color; + } u; +}; + +static uiTableData *newTableData(uiTableData type) +{ + uiTableData *d; + + d = uiprivNew(uiTableData); + d->type = type; + return d; +} + +void uiFreeAttribute(uiTableData *a) +{ + switch (d->type) { + case uiTableDataTypeString: + uiprivFree(d->u.str); + break; + } + uiprivFree(d); +} + +uiTableDataType uiTableDataGetType(const uiTableData *d) +{ + return d->type; +} + +uiTableData *uiNewTableDataString(const char *str) +{ + uiTableData *d; + + d = newTableData(uiTableDataTypeString); + d->u.str = (char *) uiprivAlloc((strlen(str) + 1) * sizeof (char), "char[] (uiTableData)"); + strcpy(d->u.str, str); + return d; +} + +const char *uiTableDataString(const uiTableData *d) +{ + return d->u.str; +} + +uiTableData *uiNewTableDataImage(uiImage *img) +{ + uiTableData *d; + + d = newTableData(uiTableDataTypeImage); + d->u.img = img; + return d; +} + +uiImage *uiTableDataImage(const uiTableData *d) +{ + return d->u.img; +} + +uiTableData *uiNewTableDataInt(int i) +{ + uiTableData *d; + + d = newTableData(uiTableDataTypeInt); + d->u.i = i; + return d; +} + +int uiTableDataInt(const uiTableData *d) +{ + return d->u.i; +} + +uiTableData *uiNewTableDataColor(double r, double g, double b, double a) +{ + uiTableData *d; + + d = newTableData(uiTableDataTypeColor); + d->u.color.r = r; + d->u.color.g = g; + d->u.color.b = b; + d->u.color.a = a; + return d; +} + +void uiTableDataColor(const uiTableData *d, double *r, double *g, double *b, double *a) +{ + *r = d->u.color.r; + *g = d->u.color.g; + *b = d->u.color.b; + *a = d->u.color.a; +}