1
2 #include "demo_guix_washing_machine.h"
3
4 #define ARC_RANGE 33
5 #define ARC_INTERVAL 36
6 #define ARC_COUNT 6
7
8 typedef struct ARC_INFO_STRUCT {
9 INT start_angle;
10 INT end_angle;
11 }ARC_INFO;
12
13 ARC_INFO arc_info_list[ARC_COUNT + 1];
14
15 /******************************************************************************************/
16 /* Initialize some information used by wash cycle window. */
17 /******************************************************************************************/
wash_cycle_window_init(INT remain_seconds)18 VOID wash_cycle_window_init(INT remain_seconds)
19 {
20 INT index;
21 GX_RADIAL_SLIDER_INFO* info = &wash_cycle_window.wash_cycle_window_wash_cycle_slider.gx_radial_slider_info;
22
23 arc_info_list[0].end_angle = info->gx_radial_slider_info_max_angle;
24 arc_info_list[0].start_angle = arc_info_list[0].end_angle - ARC_RANGE;
25
26 for (index = 1; index < ARC_COUNT; index++)
27 {
28 arc_info_list[index].start_angle = arc_info_list[index - 1].start_angle - ARC_INTERVAL;
29 arc_info_list[index].end_angle = arc_info_list[index - 1].end_angle - ARC_INTERVAL;
30 }
31
32 arc_info_list[ARC_COUNT].start_angle = 0;
33 arc_info_list[ARC_COUNT].end_angle = 0;
34
35 /* Update remain time. */
36 wash_cycle_window_remain_time_update(remain_seconds);
37 }
38
39 /******************************************************************************************/
40 /* Update remain time. */
41 /******************************************************************************************/
wash_cycle_window_remain_time_update(INT remain_seconds)42 VOID wash_cycle_window_remain_time_update(INT remain_seconds)
43 {
44 gx_numeric_prompt_value_set(&wash_cycle_window.wash_cycle_window_minute, remain_seconds / 60);
45 gx_numeric_prompt_value_set(&wash_cycle_window.wash_cycle_window_second, remain_seconds % 60);
46 }
47
48 /******************************************************************************************/
49 /* Update wash cycle progress bar value. */
50 /******************************************************************************************/
update_progress_bar_value(INT angle)51 static VOID update_progress_bar_value(INT angle)
52 {
53 GX_RADIAL_SLIDER_INFO* info = &wash_cycle_window.wash_cycle_window_wash_cycle_slider.gx_radial_slider_info;
54
55 INT percent = (info->gx_radial_slider_info_max_angle - angle) * 100 /
56 (info->gx_radial_slider_info_max_angle - info->gx_radial_slider_info_min_angle);
57
58
59 gx_progress_bar_value_set(&main_screen.main_screen_wash_cycle_progress_bar, percent);
60 }
61
62 /******************************************************************************************/
63 /* Override the default event processing of "wash_cycle_window" to handle signals from */
64 /* my child widgets. */
65 /******************************************************************************************/
wash_cycle_window_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)66 UINT wash_cycle_window_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
67 {
68 switch (event_ptr->gx_event_type)
69 {
70 case GX_SIGNAL(ID_WASH_CYCLE_SLIDER, GX_EVENT_SLIDER_VALUE):
71 update_progress_bar_value(event_ptr->gx_event_payload.gx_event_longdata);
72 break;
73
74 default:
75 return gx_window_event_process(window, event_ptr);
76 }
77
78 return 0;
79 }
80
81 /******************************************************************************************/
82 /* Custom defined draw function for wash cycle window. */
83 /******************************************************************************************/
wash_cycle_window_draw(GX_WINDOW * window)84 VOID wash_cycle_window_draw(GX_WINDOW* window)
85 {
86 gx_window_background_draw(window);
87
88 if (main_screen.main_screen_btn_play.gx_widget_style & GX_STYLE_BUTTON_PUSHED)
89 {
90 /* Draw animation wave in the center. */
91 animation_wave_draw(window);
92 }
93
94 gx_widget_children_draw(window);
95 }
96
97 /******************************************************************************************/
98 /* Custom defined draw function for wash cycle slider widget. */
99 /******************************************************************************************/
wash_cycle_slider_draw(GX_RADIAL_SLIDER * slider)100 VOID wash_cycle_slider_draw(GX_RADIAL_SLIDER* slider)
101 {
102 GX_RADIAL_SLIDER_INFO *info = &slider->gx_radial_slider_info;
103 GX_PIXELMAP *map;
104 INT xpos;
105 INT ypos;
106 ARC_INFO *arc = arc_info_list;
107 INT start_angle;
108
109 /* Call default widget background draw. */
110 gx_widget_background_draw((GX_WIDGET*)slider);
111
112 gx_context_pixelmap_get(info->gx_radial_slider_info_background_pixelmap, &map);
113
114 xpos = slider->gx_widget_size.gx_rectangle_left;
115 ypos = slider->gx_widget_size.gx_rectangle_top;
116
117 if (map)
118 {
119 /* Draw background pixelmap. */
120 gx_canvas_pixelmap_draw(xpos, ypos, map);
121 }
122
123 gx_context_brush_width_set(4);
124 gx_context_brush_define(GX_COLOR_ID_GREEN, GX_COLOR_ID_GREEN, GX_BRUSH_ALIAS|GX_BRUSH_ROUND);
125
126 xpos += info->gx_radial_slider_info_xcenter;
127 ypos += info->gx_radial_slider_info_ycenter;
128
129 /* Fill selected area with disconnected arcs. */
130 while (arc->start_angle < arc->end_angle)
131 {
132 if (info->gx_radial_slider_info_current_angle < arc->start_angle)
133 {
134 start_angle = arc->start_angle;
135 }
136 else
137 {
138 start_angle = info->gx_radial_slider_info_current_angle;
139 }
140
141 if (start_angle < arc->end_angle)
142 {
143 gx_canvas_arc_draw(xpos, ypos, info->gx_radial_slider_info_radius, start_angle, arc->end_angle);
144 }
145
146 if (start_angle == info->gx_radial_slider_info_current_angle)
147 {
148 break;
149 }
150
151 arc++;
152 }
153
154 /* Draw children widgets. */
155 gx_widget_children_draw((GX_WIDGET*)slider);
156 }