forked from eclipse-threadx/guix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircular_gauge_service_provider.cpp
268 lines (228 loc) · 11.1 KB
/
circular_gauge_service_provider.cpp
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include "studiox_includes.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
circular_gauge_service_provider::circular_gauge_service_provider()
{
}
CString circular_gauge_service_provider::GetVarDeclaration()
{
return CString("GX_CIRCULAR_GAUGE_MEMBERS_DECLARE");
}
CString circular_gauge_service_provider::DeclarePropertiesStruct()
{
CString out(""
"typedef struct\n"
"{\n"
" GX_VALUE start_angle;\n"
" GX_VALUE animation_steps;\n"
" GX_VALUE animation_delay;\n"
" GX_VALUE needle_xpos;\n"
" GX_VALUE needle_ypos;\n"
" GX_VALUE needle_xcor;\n"
" GX_VALUE needle_ycor;\n"
" GX_RESOURCE_ID normal_pixelmap_id;\n"
" GX_RESOURCE_ID selected_pixelmap_id;\n"
" GX_RESOURCE_ID needle_pixelmap_id;\n"
"} GX_CIRCULAR_GAUGE_PROPERTIES;\n\n");
return out;
}
CString circular_gauge_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
{
CString out;
CString propname = prefix + info->app_name;
out.Format(_T("GX_CIRCULAR_GAUGE_PROPERTIES %s_properties =\n")
_T("{\n")
_T(" %d, /* start angle */\n")
_T(" %d, /* animation steps */\n")
_T(" %d, /* animation delay */\n")
_T(" %d, /* needle xpos */\n")
_T(" %d, /* needle yos */\n")
_T(" %d, /* needle xcor */\n")
_T(" %d, /* needle ycor */\n")
_T(" %s, /* normal pixelmap id */\n")
_T(" %s, /* selected pixelmap id */\n")
_T(" %s /* needle pixelmap id */\n};\n"),
propname,
info->ewi.gauge.start_angle,
info->ewi.gauge.info.gx_circular_gauge_info_animation_steps,
info->ewi.gauge.info.gx_circular_gauge_info_animation_delay,
info->ewi.gauge.info.gx_circular_gauge_info_needle_xpos,
info->ewi.gauge.info.gx_circular_gauge_info_needle_ypos,
info->ewi.gauge.info.gx_circular_gauge_info_needle_xcor,
info->ewi.gauge.info.gx_circular_gauge_info_needle_ycor,
gen->GetPixelmapIdName(info->pixelmap_id[NORMAL_PIXELMAP_INDEX]),
gen->GetPixelmapIdName(info->pixelmap_id[SELECTED_PIXELMAP_INDEX]),
gen->GetPixelmapIdName(info->pixelmap_id[NEEDLE_PIXELMAP_INDEX]));
return out;
}
CString circular_gauge_service_provider::GetCreateFromDefFunctionName()
{
return CString("gx_studio_circular_gauge_create");
}
CString circular_gauge_service_provider::GetCreateFromDefFunction(int version)
{
CString out;
MakeCreatePreamble("circular_gauge", version, out);
out += "{\n"
" UINT status;\n"
" GX_CIRCULAR_GAUGE *gauge = (GX_CIRCULAR_GAUGE *) control_block;\n"
" GX_CIRCULAR_GAUGE_PROPERTIES *props = (GX_CIRCULAR_GAUGE_PROPERTIES *) info->properties;\n"
" GX_CIRCULAR_GAUGE_INFO gauge_info;\n"
" gauge_info.gx_circular_gauge_info_needle_pixelmap = props->needle_pixelmap_id;\n"
" gauge_info.gx_circular_gauge_info_needle_xpos = props->needle_xpos;\n"
" gauge_info.gx_circular_gauge_info_needle_ypos = props->needle_ypos;\n"
" gauge_info.gx_circular_gauge_info_needle_xcor = props->needle_xcor;\n"
" gauge_info.gx_circular_gauge_info_needle_ycor = props->needle_ycor;\n"
" gauge_info.gx_circular_gauge_info_animation_steps = props->animation_steps;\n"
" gauge_info.gx_circular_gauge_info_animation_delay = props->animation_delay;\n"
" gauge->gx_icon_normal_pixelmap = props->normal_pixelmap_id;\n"
" gauge->gx_icon_selected_pixelmap = props->selected_pixelmap_id;\n"
" status = gx_circular_gauge_create(gauge,\n"
" info->widget_name,\n"
" parent,\n"
" &gauge_info,\n"
" props->normal_pixelmap_id,\n"
" info->style,\n"
" info->widget_id,\n"
" info->size.gx_rectangle_left,\n"
" info->size.gx_rectangle_top);\n"
" return status;\n"
"}\n";
return out;
}
widget_info *circular_gauge_service_provider::CreateNewInstance(GX_WIDGET *parent)
{
GX_RECTANGLE size;
gx_utility_rectangle_define(&size, 0, 0, 100, 79);
gx_utility_rectangle_center(&size, &parent->gx_widget_size);
GX_CIRCULAR_GAUGE *gauge = new GX_CIRCULAR_GAUGE;
GX_CIRCULAR_GAUGE_INFO gauge_info;
gauge->gx_circular_gauge_start_angle = 0;
gauge_info.gx_circular_gauge_info_needle_pixelmap = 0;
gauge_info.gx_circular_gauge_info_needle_xpos = 20;
gauge_info.gx_circular_gauge_info_needle_ypos = 20;
gauge_info.gx_circular_gauge_info_needle_xcor = 10;
gauge_info.gx_circular_gauge_info_needle_ycor = 10;
gauge_info.gx_circular_gauge_info_animation_delay = 1;
gauge_info.gx_circular_gauge_info_animation_steps = 30;
gx_circular_gauge_create(gauge,
"gauge",
parent, &gauge_info, 0,
GX_STYLE_ENABLED, 0,
size.gx_rectangle_left, size.gx_rectangle_top);
// the gauge will be 1x1 pixels since it has no pixelmap, so make it larger
// so that you can actually see it.
gx_widget_resize((GX_WIDGET *)gauge, &size);
widget_info *info = InitWidgetInfo((GX_WIDGET *)gauge);
info->ewi.gauge.info = gauge_info;
return info;
}
GX_WIDGET *circular_gauge_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
{
GX_CIRCULAR_GAUGE *gauge = new GX_CIRCULAR_GAUGE;
gx_circular_gauge_create(gauge,
(CHAR *)info->app_name.GetString(),
parent, &info->ewi.gauge.info, info->pixelmap_id[NORMAL_PIXELMAP_INDEX],
info->style,
0,
info->size.gx_rectangle_left, info->size.gx_rectangle_top);
gx_widget_resize((GX_WIDGET*) gauge, &info->size);
gx_widget_fill_color_set((GX_WIDGET *)gauge,
info->color_id[NORMAL_FILL_COLOR_INDEX],
info->color_id[SELECTED_FILL_COLOR_INDEX],
info->color_id[DISABLED_FILL_COLOR_INDEX]);
return ((GX_WIDGET *) gauge);
}
void circular_gauge_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
{
widget_service_provider::SaveToProject(writer, project, display, info);
writer.WriteInt("start_angle", info->ewi.gauge.start_angle);
writer.WriteInt("animation_steps", info->ewi.gauge.info.gx_circular_gauge_info_animation_steps);
writer.WriteInt("animation_delay", info->ewi.gauge.info.gx_circular_gauge_info_animation_delay);
writer.WriteInt("xpos", info->ewi.gauge.info.gx_circular_gauge_info_needle_xpos);
writer.WriteInt("ypos", info->ewi.gauge.info.gx_circular_gauge_info_needle_ypos);
writer.WriteInt("xcor", info->ewi.gauge.info.gx_circular_gauge_info_needle_xcor);
writer.WriteInt("ycor", info->ewi.gauge.info.gx_circular_gauge_info_needle_ycor);
WritePixelmapId(writer, project, display, "normal_pixlmap", info->pixelmap_id[NORMAL_PIXELMAP_INDEX]);
WritePixelmapId(writer, project, display, "selected_pixlmap", info->pixelmap_id[SELECTED_PIXELMAP_INDEX]);
WritePixelmapId(writer, project, display, "needle_pixlmap", info->pixelmap_id[NEEDLE_PIXELMAP_INDEX]);
}
void circular_gauge_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
{
valid_styles |= GX_STYLE_CIRCULAR_GAUGE_CCW;
widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
reader.ReadInt("start_angle", info->ewi.gauge.start_angle);
reader.ReadInt("animation_steps", info->ewi.gauge.info.gx_circular_gauge_info_animation_steps);
reader.ReadInt("animation_delay", info->ewi.gauge.info.gx_circular_gauge_info_animation_delay);
reader.ReadValue("xpos", info->ewi.gauge.info.gx_circular_gauge_info_needle_xpos);
reader.ReadValue("ypos", info->ewi.gauge.info.gx_circular_gauge_info_needle_ypos);
reader.ReadValue("xcor", info->ewi.gauge.info.gx_circular_gauge_info_needle_xcor);
reader.ReadValue("ycor", info->ewi.gauge.info.gx_circular_gauge_info_needle_ycor);
info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "normal_pixlmap");
info->pixelmap_id[SELECTED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "selected_pixlmap");
info->pixelmap_id[NEEDLE_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "needle_pixlmap");
info->ewi.gauge.info.gx_circular_gauge_info_needle_pixelmap = info->pixelmap_id[NEEDLE_PIXELMAP_INDEX];
}
void circular_gauge_service_provider::AssignPixelmap(widget_info *info, int index, GX_RESOURCE_ID pixmap_id)
{
GX_CIRCULAR_GAUGE_INFO gauge_info = info->ewi.gauge.info;
GX_CIRCULAR_GAUGE *gauge = (GX_CIRCULAR_GAUGE *) (info->widget);
GX_RECTANGLE newsize;
switch (index)
{
case NORMAL_PIXELMAP_INDEX:
info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = pixmap_id;
if (gauge)
{
gauge->gx_icon_normal_pixelmap = pixmap_id;
gauge->gx_icon_selected_pixelmap = info->pixelmap_id[SELECTED_PIXELMAP_INDEX];
gauge_info.gx_circular_gauge_info_needle_pixelmap = info->pixelmap_id[NEEDLE_PIXELMAP_INDEX];
gauge->gx_circular_gauge_info = gauge_info;
gx_icon_pixelmap_set((GX_ICON *)gauge, pixmap_id, info->pixelmap_id[SELECTED_PIXELMAP_INDEX]);
}
break;
case SELECTED_PIXELMAP_INDEX:
info->pixelmap_id[SELECTED_PIXELMAP_INDEX] = pixmap_id;
if (gauge)
{
gauge->gx_icon_normal_pixelmap = info->pixelmap_id[NORMAL_PIXELMAP_INDEX];
gauge->gx_icon_selected_pixelmap = pixmap_id;
gauge_info.gx_circular_gauge_info_needle_pixelmap = info->pixelmap_id[NEEDLE_PIXELMAP_INDEX];
gauge->gx_circular_gauge_info = gauge_info;
gx_icon_pixelmap_set((GX_ICON *)gauge, info->pixelmap_id[NORMAL_PIXELMAP_INDEX], pixmap_id);
}
break;
case NEEDLE_PIXELMAP_INDEX:
info->pixelmap_id[NEEDLE_PIXELMAP_INDEX] = pixmap_id;
info->ewi.gauge.info.gx_circular_gauge_info_needle_pixelmap = pixmap_id;
if (gauge)
{
gauge->gx_icon_normal_pixelmap = info->pixelmap_id[NORMAL_PIXELMAP_INDEX];
gauge->gx_icon_selected_pixelmap = info->pixelmap_id[SELECTED_PIXELMAP_INDEX];
gauge_info.gx_circular_gauge_info_needle_pixelmap = pixmap_id;
gauge->gx_circular_gauge_info = gauge_info;
gx_widget_pixelmap_get((GX_WIDGET *)gauge,
gauge->gx_circular_gauge_info.gx_circular_gauge_info_needle_pixelmap,
&gauge->gx_circular_gauge_needle_source);
gx_system_dirty_mark((GX_WIDGET *)gauge);
}
break;
}
// check to see if the gauge auto-sized to new pixelmap, if so
// notify the properties window:
if (gauge)
{
newsize = gauge->gx_widget_size;
if (!gx_utility_rectangle_compare(&newsize, &info->size))
{
info->size = newsize;
GetPropsWin()->WidgetWasMoved();
GetTargetScreen()->WidgetWasMoved(info);
}
}
}
void circular_gauge_service_provider::Autosize(widget_info *info)
{
CheckResizeToPixelmap(info, RESIZE_MODE_HEIGHT, TRUE);
}