Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <string.h>
- typedef enum
- {
- SML_ETYPE_NONE = (0x000000),
- SML_ETYPE_WINDOW = (0x000001),
- SML_ETYPE_WIDGET_FOCUSABLE = (0x000002),
- SML_ETYPE_WIDGET_NONFOCUSABLE = (0x000003),
- SML_ETYPE_TIME = (0x000004),
- SML_ETYPE_GRAPHICS = (0x000005),
- SML_ETYPE_TEXTOBJ = (0x000006),
- SML_ETYPE_GRAPHRULES = (0x000007),
- SML_ETYPE_SHARED = (0x000008)
- } SmlElemType;
- #define SML_GENERICDATASIZE (1024) /* bytes */
- typedef uint32_t SmlErrors; // simplified.
- typedef uint32_t SmlIndex;
- typedef struct
- {
- char data[SML_GENERICDATASIZE];
- } SmlGenericData;
- #define SML_THEMEBLOCK_SIZE (0x20)
- typedef struct
- {
- SmlIndex sprite[SML_THEMEBLOCK_SIZE];
- SmlIndex theme [SML_THEMEBLOCK_SIZE];
- } SmlWidgetData;
- typedef union
- {
- SmlGenericData gen;
- SmlWidgetData wdg;
- } SmlElemData;
- typedef struct
- {
- SmlElemType type;
- SmlElemData data;
- } SmlElement;
- typedef struct
- {
- SmlElement * elem;
- uint32_t elemcount;
- } Warehouse;
- Warehouse warehouse;
- SmlErrors SmlWhsAdd(SmlElement element, SmlIndex * index)
- {
- //SML_CHECKPTR(index); Just checks if null.
- SmlElement * ptrold = warehouse.elem;
- warehouse.elem = realloc(warehouse.elem,
- (++warehouse.elemcount) * sizeof(SmlElement));
- if (!(warehouse.elem))
- {
- warehouse.elem = ptrold;
- *index = 0;
- warehouse.elemcount--;
- return 1;//SML_ERR_BADALLOC;
- }
- warehouse.elem[warehouse.elemcount - 1] = element;
- *index = (warehouse.elemcount - 1);
- return 0;//SML_ERR_SUCCESS;
- }
- int main(void)
- {
- // Inits in another module
- warehouse.elemcount = 0;
- warehouse.elem = NULL;
- SmlElement dummy;
- dummy.type = SML_ETYPE_WINDOW;
- SmlIndex window;
- SmlWhsAdd(dummy, &window);
- SmlElement sprite;
- sprite.type = SML_ETYPE_GRAPHICS;
- SmlWhsAdd(sprite, &(warehouse.elem[window].data.wdg.sprite[0]));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement