1
2 #include "studiox_includes.h"
3
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7
radial_slider_service_provider()8 radial_slider_service_provider::radial_slider_service_provider()
9 {
10 }
11
GetVarDeclaration()12 CString radial_slider_service_provider::GetVarDeclaration()
13 {
14 return CString("GX_RADIAL_SLIDER_MEMBERS_DECLARE");
15 }
16
DeclarePropertiesStruct()17 CString radial_slider_service_provider::DeclarePropertiesStruct()
18 {
19 CString out(""
20 "typedef struct\n"
21 "{\n"
22 " GX_VALUE xcenter;\n"
23 " GX_VALUE ycenter;\n"
24 " USHORT radius;\n"
25 " USHORT track_width;\n");
26
27 if (project_lib_version() >= GX_VERSION_RADIAL_SLIDER_NEEDLE_OFFSET_CHANGE)
28 {
29 out += " GX_VALUE needle_offset;\n";
30 }
31
32 out+=
33 " GX_VALUE current_angle;\n"
34 " GX_VALUE min_angle;\n"
35 " GX_VALUE max_angle;\n"
36 " GX_RESOURCE_ID background_pixelmap;\n"
37 " GX_RESOURCE_ID needle_pixelmap;\n"
38 " USHORT animation_total_steps;\n"
39 " USHORT animation_delay;\n"
40 " USHORT animation_style;\n"
41 " VOID (*animation_update_callback)(struct GX_RADIAL_SLIDER_STRUCT *slider);\n"
42 "} GX_RADIAL_SLIDER_PROPERTIES;\n\n";
43 return out;
44 }
45
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)46 CString radial_slider_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
47 {
48 CString out;
49 CString propname = prefix + info->app_name;
50 CString callback;
51 CString animation_style;
52
53 animation_style = easing_function_select_dlg::GetEasingFuncIdName(info->ewi.radial_slider.animation_style);
54
55 if (animation_style.IsEmpty())
56 {
57 animation_style = _T("0");
58 }
59 else
60 {
61 animation_style.MakeUpper();
62 animation_style.Replace(' ', '_');
63 animation_style.Insert(0, _T("GX_ANIMATION_"));
64 }
65
66 if (info->callback_func.IsEmpty())
67 {
68 callback = "GX_NULL";
69 }
70 else
71 {
72 callback = info->callback_func;
73 }
74
75 CString needle_offset("");
76
77 if (project_lib_version() >= GX_VERSION_RADIAL_SLIDER_NEEDLE_OFFSET_CHANGE)
78 {
79 needle_offset.Format(_T(" %d, /* needle offset */\n"), info->ewi.radial_slider.needle_offset);
80 }
81
82 out.Format(_T("GX_RADIAL_SLIDER_PROPERTIES %s_properties =\n")
83 _T("{\n")
84 _T(" %d, /* xcenter */\n")
85 _T(" %d, /* ycenter */\n")
86 _T(" %d, /* radius */\n")
87 _T(" %d, /* track width*/\n")
88 _T("%s")
89 _T(" %d, /* current angle */\n")
90 _T(" %d, /* min angle */\n")
91 _T(" %d, /* max angle */\n")
92 _T(" %s, /* background pixelmap */\n")
93 _T(" %s, /* needle pixelmap */\n")
94 _T(" %d, /* animation total steps */\n")
95 _T(" %d, /* animation delay */\n")
96 _T(" %s, /* animation style */\n")
97 _T(" %s, /* animation update callback func */\n")
98 _T("};\n"),
99 propname,
100 info->ewi.radial_slider.xcenter,
101 info->ewi.radial_slider.ycenter,
102 info->ewi.radial_slider.radius,
103 info->ewi.radial_slider.track_width,
104 needle_offset,
105 info->ewi.radial_slider.current_angle,
106 info->ewi.radial_slider.min_angle,
107 info->ewi.radial_slider.max_angle,
108 gen->GetPixelmapIdName(info->pixelmap_id[NORMAL_PIXELMAP_INDEX]),
109 gen->GetPixelmapIdName(info->pixelmap_id[NEEDLE_PIXELMAP_INDEX]),
110 info->ewi.radial_slider.animation_total_steps,
111 info->ewi.radial_slider.animation_delay,
112 animation_style,
113 callback);
114
115 return out;
116 }
117
GetCreateFromDefFunctionName()118 CString radial_slider_service_provider::GetCreateFromDefFunctionName()
119 {
120 return CString("gx_studio_radial_slider_create");
121 }
122
GetCreateFromDefFunction(int version)123 CString radial_slider_service_provider::GetCreateFromDefFunction(int version)
124 {
125 CString out;
126 MakeCreatePreamble("radial_slider", version, out);
127
128 out += "{\n"
129 " UINT status;\n"
130 " GX_RADIAL_SLIDER *slider = (GX_RADIAL_SLIDER *) control_block;\n"
131 " GX_RADIAL_SLIDER_INFO slider_info;\n"
132 " GX_RADIAL_SLIDER_PROPERTIES *props = (GX_RADIAL_SLIDER_PROPERTIES *)info->properties;\n"
133 " memset(&slider_info, 0, sizeof(GX_RADIAL_SLIDER_INFO));\n"
134 " slider_info.gx_radial_slider_info_xcenter = props->xcenter;\n"
135 " slider_info.gx_radial_slider_info_ycenter = props->ycenter;\n"
136 " slider_info.gx_radial_slider_info_radius = props->radius;\n"
137 " slider_info.gx_radial_slider_info_track_width = props->track_width;\n";
138
139 if (project_lib_version() >= GX_VERSION_RADIAL_SLIDER_NEEDLE_OFFSET_CHANGE)
140 {
141 out += " slider_info.gx_radial_slider_info_needle_offset = props->needle_offset;\n";
142 }
143
144 out +=
145 " slider_info.gx_radial_slider_info_current_angle = props->current_angle;\n"
146 " slider_info.gx_radial_slider_info_min_angle = props->min_angle;\n"
147 " slider_info.gx_radial_slider_info_max_angle = props->max_angle;\n"
148 " slider_info.gx_radial_slider_info_background_pixelmap = props->background_pixelmap;\n"
149 " slider_info.gx_radial_slider_info_needle_pixelmap = props->needle_pixelmap;\n"
150 " status = gx_radial_slider_create(slider,\n"
151 " info->widget_name,\n"
152 " parent,\n"
153 " &slider_info,\n"
154 " info->style,\n"
155 " info->widget_id,\n"
156 " &info->size);\n"
157 " gx_radial_slider_animation_set(slider, props->animation_total_steps, props->animation_delay, props->animation_style, props->animation_update_callback);\n"
158 " return status;\n"
159 "}\n";
160 return out;
161
162 }
163
CreateNewInstance(GX_WIDGET * parent)164 widget_info *radial_slider_service_provider::CreateNewInstance(GX_WIDGET *parent)
165 {
166 GX_RADIAL_SLIDER_INFO props;
167 int xcenter;
168 int ycenter;
169 GX_RECTANGLE size;
170
171 xcenter = (parent->gx_widget_size.gx_rectangle_left + parent->gx_widget_size.gx_rectangle_right) >> 1;
172 ycenter = (parent->gx_widget_size.gx_rectangle_top + parent->gx_widget_size.gx_rectangle_bottom) >> 1;
173
174 GX_RADIAL_SLIDER *slider = new GX_RADIAL_SLIDER;
175 memset(slider, 0, sizeof(GX_RADIAL_SLIDER));
176 props.gx_radial_slider_info_xcenter = 100;
177 props.gx_radial_slider_info_ycenter = 100;
178 props.gx_radial_slider_info_radius = 100;
179 props.gx_radial_slider_info_track_width = 20;
180 props.gx_radial_slider_info_needle_offset = 0;
181 props.gx_radial_slider_info_current_angle = -90;
182 props.gx_radial_slider_info_min_angle = -90;
183 props.gx_radial_slider_info_max_angle = 270;
184 props.gx_radial_slider_info_needle_pixelmap = GX_NULL;
185 props.gx_radial_slider_info_background_pixelmap = GX_NULL;
186 props.gx_radial_slider_info_angle_list = GX_NULL;
187
188 size.gx_rectangle_left = xcenter - 100;
189 size.gx_rectangle_top = ycenter - 100;
190 size.gx_rectangle_right = xcenter + 100;
191 size.gx_rectangle_bottom = ycenter + 100;
192
193 gx_radial_slider_create(slider,
194 "radial_slider",
195 parent, &props,
196 GX_STYLE_ENABLED | GX_STYLE_BORDER_NONE, 0, &size);
197
198 widget_info *info = InitWidgetInfo((GX_WIDGET *)slider);
199
200 info->ewi.radial_slider.xcenter = props.gx_radial_slider_info_xcenter;
201 info->ewi.radial_slider.ycenter = props.gx_radial_slider_info_ycenter;
202 info->ewi.radial_slider.radius = props.gx_radial_slider_info_radius;
203 info->ewi.radial_slider.track_width = props.gx_radial_slider_info_track_width;
204 info->ewi.radial_slider.needle_offset = props.gx_radial_slider_info_needle_offset;
205 info->ewi.radial_slider.current_angle = props.gx_radial_slider_info_current_angle;
206 info->ewi.radial_slider.min_angle = props.gx_radial_slider_info_min_angle;
207 info->ewi.radial_slider.max_angle = props.gx_radial_slider_info_max_angle;
208 info->ewi.radial_slider.needle_pixelmap = props.gx_radial_slider_info_needle_pixelmap;
209 info->ewi.radial_slider.background_pixelmap = props.gx_radial_slider_info_background_pixelmap;
210 info->ewi.radial_slider.animation_total_steps = slider->gx_radial_slider_animation_total_steps;
211 info->ewi.radial_slider.animation_delay = slider->gx_radial_slider_animation_delay;
212 info->ewi.radial_slider.animation_style = GX_ANIMATION_CIRC_EASE_IN_OUT;
213 return info;
214 }
215
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)216 GX_WIDGET *radial_slider_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
217 {
218 GX_RADIAL_SLIDER *slider = new GX_RADIAL_SLIDER;
219 GX_RADIAL_SLIDER_INFO props;
220
221 memset(&props, 0, sizeof(GX_RADIAL_SLIDER_INFO));
222 props.gx_radial_slider_info_xcenter = info->ewi.radial_slider.xcenter;
223 props.gx_radial_slider_info_ycenter = info->ewi.radial_slider.ycenter;
224 props.gx_radial_slider_info_radius = info->ewi.radial_slider.radius;
225 props.gx_radial_slider_info_track_width = info->ewi.radial_slider.track_width;
226 props.gx_radial_slider_info_needle_offset = info->ewi.radial_slider.needle_offset;
227 props.gx_radial_slider_info_current_angle = info->ewi.radial_slider.current_angle;
228 props.gx_radial_slider_info_min_angle = info->ewi.radial_slider.min_angle;
229 props.gx_radial_slider_info_max_angle = info->ewi.radial_slider.max_angle;
230 props.gx_radial_slider_info_needle_pixelmap = info->ewi.radial_slider.needle_pixelmap;
231 props.gx_radial_slider_info_background_pixelmap = info->ewi.radial_slider.background_pixelmap;
232
233 gx_radial_slider_create(slider,
234 (CHAR *)info->app_name.GetString(),
235 parent, &props,
236 info->style,
237 0, &info->size);
238
239 gx_radial_slider_animation_set(slider, info->ewi.radial_slider.animation_total_steps, info->ewi.radial_slider.animation_delay,
240 info->ewi.radial_slider.animation_style, GX_NULL);
241
242 gx_widget_fill_color_set((GX_WIDGET *)slider,
243 info->color_id[NORMAL_FILL_COLOR_INDEX],
244 info->color_id[SELECTED_FILL_COLOR_INDEX],
245 info->color_id[DISABLED_FILL_COLOR_INDEX]);
246
247 return ((GX_WIDGET *)slider);
248 }
249
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)250 void radial_slider_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
251 {
252 widget_service_provider::SaveToProject(writer, project, display, info);
253 writer.WriteInt("xcenter", info->ewi.radial_slider.xcenter);
254 writer.WriteInt("ycenter", info->ewi.radial_slider.ycenter);
255 writer.WriteInt("radius", info->ewi.radial_slider.radius);
256 writer.WriteInt("track_width", info->ewi.radial_slider.track_width);
257 writer.WriteInt("needle_offset", info->ewi.radial_slider.needle_offset);
258 writer.WriteInt("current_angle", info->ewi.radial_slider.current_angle);
259 writer.WriteInt("min_angle", info->ewi.radial_slider.min_angle);
260 writer.WriteInt("max_angle", info->ewi.radial_slider.max_angle);
261 WritePixelmapId(writer, project, display, "background_pixelmap", info->pixelmap_id[NORMAL_PIXELMAP_INDEX]);
262 WritePixelmapId(writer, project, display, "needle_pixelmap", info->pixelmap_id[NEEDLE_PIXELMAP_INDEX]);
263 writer.WriteInt("animation_total_steps", info->ewi.radial_slider.animation_total_steps);
264 writer.WriteInt("animation_delay", info->ewi.radial_slider.animation_delay);
265 writer.WriteString("animation_style", easing_function_select_dlg::GetEasingFuncIdName(info->ewi.radial_slider.animation_style));
266 writer.WriteString("callback", info->callback_func);
267 }
268
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)269 void radial_slider_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
270 {
271 CString easing_func;
272
273 widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
274 reader.ReadValue("xcenter", info->ewi.radial_slider.xcenter);
275 reader.ReadValue("ycenter", info->ewi.radial_slider.ycenter);
276 reader.ReadUShort("radius", info->ewi.radial_slider.radius);
277 reader.ReadUShort("track_width", info->ewi.radial_slider.track_width);
278 reader.ReadValue("needle_offset", info->ewi.radial_slider.needle_offset);
279 reader.ReadValue("current_angle", info->ewi.radial_slider.current_angle);
280 reader.ReadValue("min_angle", info->ewi.radial_slider.min_angle);
281 reader.ReadValue("max_angle", info->ewi.radial_slider.max_angle);
282 info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "background_pixelmap");
283 info->pixelmap_id[NEEDLE_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "needle_pixelmap");
284 info->ewi.radial_slider.background_pixelmap = info->pixelmap_id[NORMAL_PIXELMAP_INDEX];
285 info->ewi.radial_slider.needle_pixelmap = info->pixelmap_id[NEEDLE_PIXELMAP_INDEX];
286 reader.ReadUShort("animation_total_steps", info->ewi.radial_slider.animation_total_steps);
287 reader.ReadUShort("animation_delay", info->ewi.radial_slider.animation_delay);
288 reader.ReadString("animation_style", easing_func);
289 info->ewi.radial_slider.animation_style = easing_function_select_dlg::GetEasingFuncId(easing_func);
290 reader.ReadString("callback", info->callback_func);
291 }
292
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)293 void radial_slider_service_provider::AssignPixelmap(widget_info *info, int index, GX_RESOURCE_ID pixmap_id)
294 {
295 GX_RADIAL_SLIDER *slider = (GX_RADIAL_SLIDER *) (info->widget);
296
297 switch (index)
298 {
299 case NORMAL_PIXELMAP_INDEX:
300 info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = pixmap_id;
301 info->ewi.radial_slider.background_pixelmap = pixmap_id;
302
303 if (slider)
304 {
305 slider->gx_radial_slider_info.gx_radial_slider_info_background_pixelmap = pixmap_id;
306 gx_system_dirty_mark((GX_WIDGET *)slider);
307 }
308 break;
309
310 case NEEDLE_PIXELMAP_INDEX:
311 info->pixelmap_id[NEEDLE_PIXELMAP_INDEX] = pixmap_id;
312 info->ewi.radial_slider.needle_pixelmap = pixmap_id;
313
314 if (slider)
315 {
316 slider->gx_radial_slider_info.gx_radial_slider_info_needle_pixelmap = pixmap_id;
317 gx_system_dirty_mark((GX_WIDGET *)slider);
318 }
319 break;
320
321 break;
322 }
323 }
324
Autosize(widget_info * info)325 void radial_slider_service_provider::Autosize(widget_info *info)
326 {
327 CheckResizeToPixelmap(info, RESIZE_MODE_ALL, TRUE);
328 }
329
SetRadialSliderInfo(widget_info * info,radial_slider_info * new_info)330 void radial_slider_service_provider::SetRadialSliderInfo(widget_info *info, radial_slider_info *new_info)
331 {
332 GX_RADIAL_SLIDER *slider = (GX_RADIAL_SLIDER *)info->widget;
333 GX_RADIAL_SLIDER_INFO *slider_info;
334
335 info->ewi.radial_slider = *new_info;
336
337 gx_radial_slider_info_get(slider, &slider_info);
338 slider_info->gx_radial_slider_info_xcenter = new_info->xcenter;
339 slider_info->gx_radial_slider_info_ycenter = new_info->ycenter;
340 slider_info->gx_radial_slider_info_radius = new_info->radius;
341 slider_info->gx_radial_slider_info_track_width = new_info->track_width;
342 slider_info->gx_radial_slider_info_needle_offset = new_info->needle_offset;
343 slider_info->gx_radial_slider_info_current_angle = new_info->current_angle;
344 slider_info->gx_radial_slider_info_min_angle = new_info->min_angle;
345 slider_info->gx_radial_slider_info_max_angle = new_info->max_angle;
346
347 gx_radial_slider_info_set(slider, slider_info);
348 gx_radial_slider_animation_set(slider, new_info->animation_total_steps, new_info->animation_delay, new_info->animation_style, NULL);
349 }