1 #include "studiox_includes.h"
2 
3 #ifdef _DEBUG
4 #define new DEBUG_NEW
5 #endif
6 
7 
circular_gauge_service_provider()8 circular_gauge_service_provider::circular_gauge_service_provider()
9 {
10 }
11 
GetVarDeclaration()12 CString circular_gauge_service_provider::GetVarDeclaration()
13 {
14     return CString("GX_CIRCULAR_GAUGE_MEMBERS_DECLARE");
15 }
16 
DeclarePropertiesStruct()17 CString circular_gauge_service_provider::DeclarePropertiesStruct()
18 {
19     CString out(""
20         "typedef struct\n"
21         "{\n"
22         "    GX_VALUE start_angle;\n"
23         "    GX_VALUE animation_steps;\n"
24         "    GX_VALUE animation_delay;\n"
25         "    GX_VALUE needle_xpos;\n"
26         "    GX_VALUE needle_ypos;\n"
27         "    GX_VALUE needle_xcor;\n"
28         "    GX_VALUE needle_ycor;\n"
29         "    GX_RESOURCE_ID normal_pixelmap_id;\n"
30         "    GX_RESOURCE_ID selected_pixelmap_id;\n"
31         "    GX_RESOURCE_ID needle_pixelmap_id;\n"
32         "} GX_CIRCULAR_GAUGE_PROPERTIES;\n\n");
33     return out;
34 }
35 
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)36 CString circular_gauge_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
37 {
38     CString out;
39     CString propname = prefix + info->app_name;
40 
41     out.Format(_T("GX_CIRCULAR_GAUGE_PROPERTIES %s_properties =\n")
42         _T("{\n")
43         _T("    %d, /* start angle */\n")
44         _T("    %d, /* animation steps */\n")
45         _T("    %d, /* animation delay */\n")
46         _T("    %d, /* needle xpos */\n")
47         _T("    %d, /* needle yos */\n")
48         _T("    %d, /* needle xcor */\n")
49         _T("    %d, /* needle ycor */\n")
50         _T("    %s, /* normal pixelmap id */\n")
51         _T("    %s, /* selected pixelmap id */\n")
52         _T("    %s  /* needle pixelmap id */\n};\n"),
53         propname,
54         info->ewi.gauge.start_angle,
55         info->ewi.gauge.info.gx_circular_gauge_info_animation_steps,
56         info->ewi.gauge.info.gx_circular_gauge_info_animation_delay,
57         info->ewi.gauge.info.gx_circular_gauge_info_needle_xpos,
58         info->ewi.gauge.info.gx_circular_gauge_info_needle_ypos,
59         info->ewi.gauge.info.gx_circular_gauge_info_needle_xcor,
60         info->ewi.gauge.info.gx_circular_gauge_info_needle_ycor,
61         gen->GetPixelmapIdName(info->pixelmap_id[NORMAL_PIXELMAP_INDEX]),
62         gen->GetPixelmapIdName(info->pixelmap_id[SELECTED_PIXELMAP_INDEX]),
63         gen->GetPixelmapIdName(info->pixelmap_id[NEEDLE_PIXELMAP_INDEX]));
64     return out;
65 }
66 
GetCreateFromDefFunctionName()67 CString circular_gauge_service_provider::GetCreateFromDefFunctionName()
68 {
69     return CString("gx_studio_circular_gauge_create");
70 }
71 
GetCreateFromDefFunction(int version)72 CString circular_gauge_service_provider::GetCreateFromDefFunction(int version)
73 {
74     CString out;
75     MakeCreatePreamble("circular_gauge", version, out);
76 
77     out += "{\n"
78         "    UINT status;\n"
79         "    GX_CIRCULAR_GAUGE *gauge = (GX_CIRCULAR_GAUGE *) control_block;\n"
80         "    GX_CIRCULAR_GAUGE_PROPERTIES *props = (GX_CIRCULAR_GAUGE_PROPERTIES *) info->properties;\n"
81         "    GX_CIRCULAR_GAUGE_INFO gauge_info;\n"
82         "    gauge_info.gx_circular_gauge_info_needle_pixelmap = props->needle_pixelmap_id;\n"
83         "    gauge_info.gx_circular_gauge_info_needle_xpos = props->needle_xpos;\n"
84         "    gauge_info.gx_circular_gauge_info_needle_ypos = props->needle_ypos;\n"
85         "    gauge_info.gx_circular_gauge_info_needle_xcor = props->needle_xcor;\n"
86         "    gauge_info.gx_circular_gauge_info_needle_ycor = props->needle_ycor;\n"
87         "    gauge_info.gx_circular_gauge_info_animation_steps = props->animation_steps;\n"
88         "    gauge_info.gx_circular_gauge_info_animation_delay = props->animation_delay;\n"
89         "    gauge->gx_icon_normal_pixelmap = props->normal_pixelmap_id;\n"
90         "    gauge->gx_icon_selected_pixelmap = props->selected_pixelmap_id;\n"
91         "    status = gx_circular_gauge_create(gauge,\n"
92         "                    info->widget_name,\n"
93         "                    parent,\n"
94         "                    &gauge_info,\n"
95         "                    props->normal_pixelmap_id,\n"
96         "                    info->style,\n"
97         "                    info->widget_id,\n"
98         "                    info->size.gx_rectangle_left,\n"
99         "                    info->size.gx_rectangle_top);\n"
100         "    return status;\n"
101         "}\n";
102     return out;
103 }
104 
CreateNewInstance(GX_WIDGET * parent)105 widget_info *circular_gauge_service_provider::CreateNewInstance(GX_WIDGET *parent)
106 {
107     GX_RECTANGLE size;
108     gx_utility_rectangle_define(&size, 0, 0, 100, 79);
109     gx_utility_rectangle_center(&size, &parent->gx_widget_size);
110 
111     GX_CIRCULAR_GAUGE *gauge = new GX_CIRCULAR_GAUGE;
112     GX_CIRCULAR_GAUGE_INFO gauge_info;
113 
114     gauge->gx_circular_gauge_start_angle = 0;
115     gauge_info.gx_circular_gauge_info_needle_pixelmap = 0;
116     gauge_info.gx_circular_gauge_info_needle_xpos = 20;
117     gauge_info.gx_circular_gauge_info_needle_ypos = 20;
118     gauge_info.gx_circular_gauge_info_needle_xcor = 10;
119     gauge_info.gx_circular_gauge_info_needle_ycor = 10;
120     gauge_info.gx_circular_gauge_info_animation_delay = 1;
121     gauge_info.gx_circular_gauge_info_animation_steps = 30;
122 
123     gx_circular_gauge_create(gauge,
124         "gauge",
125         parent, &gauge_info, 0,
126         GX_STYLE_ENABLED, 0,
127         size.gx_rectangle_left, size.gx_rectangle_top);
128 
129     // the gauge will be 1x1 pixels since it has no pixelmap, so make it larger
130     // so that you can actually see it.
131     gx_widget_resize((GX_WIDGET *)gauge, &size);
132 
133     widget_info *info = InitWidgetInfo((GX_WIDGET *)gauge);
134     info->ewi.gauge.info = gauge_info;
135     return info;
136 }
137 
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)138 GX_WIDGET *circular_gauge_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
139 {
140     GX_CIRCULAR_GAUGE *gauge = new GX_CIRCULAR_GAUGE;
141 
142     gx_circular_gauge_create(gauge,
143         (CHAR *)info->app_name.GetString(),
144         parent, &info->ewi.gauge.info, info->pixelmap_id[NORMAL_PIXELMAP_INDEX],
145         info->style,
146         0,
147         info->size.gx_rectangle_left, info->size.gx_rectangle_top);
148 
149     gx_widget_resize((GX_WIDGET*) gauge, &info->size);
150 
151     gx_widget_fill_color_set((GX_WIDGET *)gauge,
152         info->color_id[NORMAL_FILL_COLOR_INDEX],
153         info->color_id[SELECTED_FILL_COLOR_INDEX],
154         info->color_id[DISABLED_FILL_COLOR_INDEX]);
155 
156     return ((GX_WIDGET *) gauge);
157 }
158 
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)159 void circular_gauge_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
160 {
161 
162     widget_service_provider::SaveToProject(writer, project, display, info);
163 
164     writer.WriteInt("start_angle", info->ewi.gauge.start_angle);
165     writer.WriteInt("animation_steps", info->ewi.gauge.info.gx_circular_gauge_info_animation_steps);
166     writer.WriteInt("animation_delay", info->ewi.gauge.info.gx_circular_gauge_info_animation_delay);
167     writer.WriteInt("xpos", info->ewi.gauge.info.gx_circular_gauge_info_needle_xpos);
168     writer.WriteInt("ypos", info->ewi.gauge.info.gx_circular_gauge_info_needle_ypos);
169     writer.WriteInt("xcor", info->ewi.gauge.info.gx_circular_gauge_info_needle_xcor);
170     writer.WriteInt("ycor", info->ewi.gauge.info.gx_circular_gauge_info_needle_ycor);
171 
172     WritePixelmapId(writer, project, display, "normal_pixlmap", info->pixelmap_id[NORMAL_PIXELMAP_INDEX]);
173     WritePixelmapId(writer, project, display, "selected_pixlmap", info->pixelmap_id[SELECTED_PIXELMAP_INDEX]);
174     WritePixelmapId(writer, project, display, "needle_pixlmap", info->pixelmap_id[NEEDLE_PIXELMAP_INDEX]);
175 }
176 
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)177 void circular_gauge_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
178 {
179     valid_styles |= GX_STYLE_CIRCULAR_GAUGE_CCW;
180     widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
181 
182     reader.ReadInt("start_angle", info->ewi.gauge.start_angle);
183     reader.ReadInt("animation_steps", info->ewi.gauge.info.gx_circular_gauge_info_animation_steps);
184     reader.ReadInt("animation_delay", info->ewi.gauge.info.gx_circular_gauge_info_animation_delay);
185     reader.ReadValue("xpos", info->ewi.gauge.info.gx_circular_gauge_info_needle_xpos);
186     reader.ReadValue("ypos", info->ewi.gauge.info.gx_circular_gauge_info_needle_ypos);
187     reader.ReadValue("xcor", info->ewi.gauge.info.gx_circular_gauge_info_needle_xcor);
188     reader.ReadValue("ycor", info->ewi.gauge.info.gx_circular_gauge_info_needle_ycor);
189 
190     info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "normal_pixlmap");
191     info->pixelmap_id[SELECTED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "selected_pixlmap");
192     info->pixelmap_id[NEEDLE_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "needle_pixlmap");
193 
194     info->ewi.gauge.info.gx_circular_gauge_info_needle_pixelmap = info->pixelmap_id[NEEDLE_PIXELMAP_INDEX];
195 }
196 
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)197 void circular_gauge_service_provider::AssignPixelmap(widget_info *info, int index, GX_RESOURCE_ID pixmap_id)
198 {
199     GX_CIRCULAR_GAUGE_INFO gauge_info = info->ewi.gauge.info;
200     GX_CIRCULAR_GAUGE *gauge = (GX_CIRCULAR_GAUGE *) (info->widget);
201     GX_RECTANGLE newsize;
202 
203     switch (index)
204     {
205     case NORMAL_PIXELMAP_INDEX:
206         info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = pixmap_id;
207 
208         if (gauge)
209         {
210             gauge->gx_icon_normal_pixelmap = pixmap_id;
211             gauge->gx_icon_selected_pixelmap = info->pixelmap_id[SELECTED_PIXELMAP_INDEX];
212             gauge_info.gx_circular_gauge_info_needle_pixelmap = info->pixelmap_id[NEEDLE_PIXELMAP_INDEX];
213             gauge->gx_circular_gauge_info = gauge_info;
214             gx_icon_pixelmap_set((GX_ICON *)gauge, pixmap_id, info->pixelmap_id[SELECTED_PIXELMAP_INDEX]);
215         }
216         break;
217 
218     case SELECTED_PIXELMAP_INDEX:
219         info->pixelmap_id[SELECTED_PIXELMAP_INDEX] = pixmap_id;
220 
221         if (gauge)
222         {
223             gauge->gx_icon_normal_pixelmap = info->pixelmap_id[NORMAL_PIXELMAP_INDEX];
224             gauge->gx_icon_selected_pixelmap = pixmap_id;
225             gauge_info.gx_circular_gauge_info_needle_pixelmap = info->pixelmap_id[NEEDLE_PIXELMAP_INDEX];
226             gauge->gx_circular_gauge_info = gauge_info;
227             gx_icon_pixelmap_set((GX_ICON *)gauge, info->pixelmap_id[NORMAL_PIXELMAP_INDEX], pixmap_id);
228         }
229         break;
230 
231     case NEEDLE_PIXELMAP_INDEX:
232         info->pixelmap_id[NEEDLE_PIXELMAP_INDEX] = pixmap_id;
233         info->ewi.gauge.info.gx_circular_gauge_info_needle_pixelmap = pixmap_id;
234 
235         if (gauge)
236         {
237             gauge->gx_icon_normal_pixelmap = info->pixelmap_id[NORMAL_PIXELMAP_INDEX];
238             gauge->gx_icon_selected_pixelmap = info->pixelmap_id[SELECTED_PIXELMAP_INDEX];
239             gauge_info.gx_circular_gauge_info_needle_pixelmap = pixmap_id;
240             gauge->gx_circular_gauge_info = gauge_info;
241             gx_widget_pixelmap_get((GX_WIDGET *)gauge,
242                 gauge->gx_circular_gauge_info.gx_circular_gauge_info_needle_pixelmap,
243                 &gauge->gx_circular_gauge_needle_source);
244             gx_system_dirty_mark((GX_WIDGET *)gauge);
245         }
246         break;
247     }
248 
249     // check to see if the gauge auto-sized to new pixelmap, if so
250     // notify the properties window:
251 
252     if (gauge)
253     {
254         newsize = gauge->gx_widget_size;
255 
256         if (!gx_utility_rectangle_compare(&newsize, &info->size))
257         {
258             info->size = newsize;
259             GetPropsWin()->WidgetWasMoved();
260             GetTargetScreen()->WidgetWasMoved(info);
261         }
262     }
263 }
264 
Autosize(widget_info * info)265 void circular_gauge_service_provider::Autosize(widget_info *info)
266 {
267     CheckResizeToPixelmap(info, RESIZE_MODE_HEIGHT, TRUE);
268 }