This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
loadproj.c
140 lines (128 loc) · 3.7 KB
/
loadproj.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <mxml.h>
#include <stdio.h>
#include "loadproj.h"
#include "dataset.h"
typedef struct _widget_stack_t_{
lv_obj_t * widget;
struct _widget_stack_t_ * next;
}widget_stack_t;
static widget_stack_t * wstack = NULL;
static mxml_sax_cb_t sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *data);
static void wstack_push(lv_obj_t * new);
static void wstack_pop(void);
static lv_obj_t * wstack_top(void);
void load_project(lv_obj_t * tft_win)
{
FILE * fp = fopen("lgd.xml", "r");
if(!fp)
{
printf("Project file not found!");
return;
}
wstack_push(tft_win);
mxml_node_t * sax_node = mxmlSAXLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK, sax_cb, NULL);
fclose(fp);
}
static mxml_sax_cb_t sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *data)
{
if(event == MXML_SAX_ELEMENT_OPEN)
{
//create a new widget and PUSH to stack
const char * element = mxmlGetElement(node);
if(!strcmp(element, "BTN"))
{
lv_obj_t * obj = lv_btn_create(wstack_top(), NULL);
wstack_push(obj);
}
if(!strcmp(element, "LABEL"))
{
lv_obj_t * obj = lv_label_create(wstack_top(), NULL);
wstack_push(obj);
}
if(!strcmp(element, "LED"))
{
lv_obj_t * obj = lv_led_create(wstack_top(), NULL);
wstack_push(obj);
}
if(!strcmp(element, "CHECKBOX"))
{
lv_obj_t * obj = lv_cb_create(wstack_top(), NULL);
wstack_push(obj);
}
if(!strcmp(element, "BAR"))
{
lv_obj_t * obj = lv_bar_create(wstack_top(), NULL);
wstack_push(obj);
}
if(!strcmp(element, "ROLLER"))
{
lv_obj_t * obj = lv_roller_create(wstack_top(), NULL);
wstack_push(obj);
}
if(!strcmp(element, "DDLIST"))
{
lv_obj_t * obj = lv_ddlist_create(wstack_top(), NULL);
wstack_push(obj);
}
if(!strcmp(element, "ARC"))
{
lv_obj_t * obj = lv_arc_create(wstack_top(), NULL);
wstack_push(obj);
}
if(!strcmp(element, "CONTAINER"))
{
lv_obj_t * obj = lv_cont_create(wstack_top(), NULL);
lv_cont_set_fit(obj, LV_FIT_FLOOD);
lv_cont_set_layout(obj, LV_LAYOUT_PRETTY); //TEST Attribute
wstack_push(obj);
}
//Set Attribute
int i, count;
for (i = 0, count = mxmlElementGetAttrCount(node); i < count; i++)
{
const char * name, * value;
value = mxmlElementGetAttrByIndex(node, i, &name);
if(!strcmp(name, "x"))
{
lv_coord_t x = atoi(value);
lv_obj_set_x(wstack_top(), x);
}
if(!strcmp(name, "y"))
{
lv_coord_t y = atoi(value);
lv_obj_set_y(wstack_top(), y);
}
// if(!strcmp(name, "fit"))
// {
// atoi(value);
// lv_obj_set_y(wstack_top(), y);
// }
}
}else if(event == MXML_SAX_ELEMENT_CLOSE)
{
//POP
wstack_pop();
}
}
static void wstack_push(lv_obj_t * new)
{
widget_stack_t * new_top = (widget_stack_t *)malloc(sizeof(widget_stack_t));
new_top->next = wstack;
new_top->widget = new;
wstack = new_top;
}
static void wstack_pop(void)
{
if(wstack != NULL)
{
widget_stack_t * tmp = wstack;
wstack = wstack->next;
// lv_obj_t * last = tmp->widget;
free(tmp);
}
}
static lv_obj_t * wstack_top(void)
{
if(wstack != NULL) return wstack->widget;
return NULL;
}