1 /* This is a small demo of the high-performance GUIX graphics framework. */
2 
3 #include "demo_guix_car_infotainment.h"
4 
5 /* Define macros.  */
6 #define PROGRESS_BAR_ANIMATION_TOTAL_STEPS 20
7 #define MAX_VOLUME 100
8 #define MIN_VOLUME 0
9 
10 /* Define local variables.  */
11 static GX_BOOL is_mute = GX_FALSE;
12 static int volume_progress_val = 23;
13 static int progress_bar_animation_step = 0;
14 static int progress_bar_animation_target_val = 0;
15 static int progress_bar_animation_start_val = 0;
16 
17 extern GX_WINDOW *current_screen;
18 
19 /******************************************************************************************/
20 /* Update volume value.                                                                   */
21 /******************************************************************************************/
update_volume_prompt(VOLUME_SCREEN_BASE_CONTROL_BLOCK * base)22 static void update_volume_prompt(VOLUME_SCREEN_BASE_CONTROL_BLOCK *base)
23 {
24     INT volume;
25     GX_PROGRESS_BAR_INFO* info = &base->volume_screen_base_volume_progress_bar.gx_progress_bar_info;
26 
27     volume = info->gx_progress_bar_info_current_val - info->gx_progress_bar_info_min_val;
28     volume *= (MAX_VOLUME - MIN_VOLUME);
29     volume /= info->gx_progress_bar_info_max_val - info->gx_progress_bar_info_min_val;
30     volume += MIN_VOLUME;
31 
32     if (!is_mute)
33     {
34         volume_progress_val = info->gx_progress_bar_info_current_val;
35     }
36 
37     gx_numeric_prompt_value_set(&base->volume_screen_base_volume_value, volume);
38 }
39 
40 /******************************************************************************************/
41 /* Start progress bar animation.                                                          */
42 /******************************************************************************************/
progress_bar_animation_start(VOLUME_SCREEN_BASE_CONTROL_BLOCK * base,int target_val)43 static void progress_bar_animation_start(VOLUME_SCREEN_BASE_CONTROL_BLOCK *base, int target_val)
44 {
45     GX_PROGRESS_BAR_INFO* info = &base->volume_screen_base_volume_progress_bar.gx_progress_bar_info;
46 
47     progress_bar_animation_target_val = target_val;
48     progress_bar_animation_start_val = info->gx_progress_bar_info_current_val;
49     progress_bar_animation_step = 0;
50     gx_system_timer_start(base, TIMER_ID_PROGRESS_BAR_ANIMATION, 20 / GX_SYSTEM_TIMER_MS, 20 / GX_SYSTEM_TIMER_MS);
51 }
52 
53 /******************************************************************************************/
54 /* Update progress bar animation.                                                         */
55 /******************************************************************************************/
progress_bar_animation_update(VOLUME_SCREEN_BASE_CONTROL_BLOCK * base)56 static void progress_bar_animation_update(VOLUME_SCREEN_BASE_CONTROL_BLOCK *base)
57 {
58     GX_PROGRESS_BAR* progress_bar = &base->volume_screen_base_volume_progress_bar;
59     INT val;
60 
61     progress_bar_animation_step++;
62 
63     val = (progress_bar_animation_target_val - progress_bar_animation_start_val) * progress_bar_animation_step;
64     val /= PROGRESS_BAR_ANIMATION_TOTAL_STEPS;
65     val += progress_bar_animation_start_val;
66 
67     gx_progress_bar_value_set(progress_bar, val);
68 
69     if (progress_bar_animation_step == PROGRESS_BAR_ANIMATION_TOTAL_STEPS)
70     {
71         gx_system_timer_stop(base, TIMER_ID_PROGRESS_BAR_ANIMATION);
72     }
73 }
74 
75 /******************************************************************************************/
76 /* Start volume progress bar animation.                                                   */
77 /******************************************************************************************/
volume_progress_bar_animation_start(VOLUME_SCREEN_BASE_CONTROL_BLOCK * base)78 static void volume_progress_bar_animation_start(VOLUME_SCREEN_BASE_CONTROL_BLOCK *base)
79 {
80     GX_PROGRESS_BAR *progress_bar;
81     INT progress_val;
82     GX_ANIMATION *animation;
83     GX_ANIMATION_INFO info;
84 
85     gx_system_animation_get(&animation);
86 
87     if (animation)
88     {
89         memset(&info, 0, sizeof(GX_ANIMATION_INFO));
90         info.gx_animation_target = (GX_WIDGET*)&base->volume_screen_base_volume_progress_bar_win;
91         info.gx_animation_parent = (GX_WIDGET *)base;
92         info.gx_animation_start_position.gx_point_x = 640;
93         info.gx_animation_start_position.gx_point_y = info.gx_animation_target->gx_widget_size.gx_rectangle_top;
94         info.gx_animation_end_position.gx_point_y = info.gx_animation_start_position.gx_point_y;
95         info.gx_animation_end_position.gx_point_x = info.gx_animation_target->gx_widget_size.gx_rectangle_left;
96         info.gx_animation_frame_interval = 20 / GX_SYSTEM_TIMER_MS;
97         info.gx_animation_steps = 20;
98         info.gx_animation_start_alpha = 255;
99         info.gx_animation_end_alpha = 255;
100         gx_animation_start(animation, &info);
101     }
102 
103     if (!is_mute)
104     {
105         progress_bar = &base->volume_screen_base_volume_progress_bar;
106         progress_val = progress_bar->gx_progress_bar_info.gx_progress_bar_info_current_val;
107         gx_progress_bar_value_set(progress_bar, 0);
108         progress_bar_animation_start(base, progress_val);
109     }
110 
111 
112 }
113 
114 /******************************************************************************************/
115 /* Override the default event processing of "phone_screen" to handle signals from my      */
116 /* child widgets.                                                                         */
117 /******************************************************************************************/
volume_screen_base_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)118 UINT volume_screen_base_event_process(GX_WINDOW *window, GX_EVENT* event_ptr)
119 {
120     switch (event_ptr->gx_event_type)
121     {
122     case GX_EVENT_SHOW:
123         volume_progress_bar_animation_start((VOLUME_SCREEN_BASE_CONTROL_BLOCK *)window);
124         screen_base_event_process(window, event_ptr);
125         break;
126 
127     case GX_SIGNAL(ID_VOLUME_PROGRESS_BAR, GX_EVENT_PROGRESS_VALUE):
128         update_volume_prompt((VOLUME_SCREEN_BASE_CONTROL_BLOCK *)window);
129         break;
130 
131     case GX_SIGNAL(ID_BTN_MUTE, GX_EVENT_TOGGLE_ON):
132         is_mute = GX_TRUE;
133         progress_bar_animation_start((VOLUME_SCREEN_BASE_CONTROL_BLOCK *)window, 0);
134         break;
135 
136     case GX_SIGNAL(ID_BTN_MUTE, GX_EVENT_TOGGLE_OFF):
137         is_mute = GX_FALSE;
138         progress_bar_animation_start((VOLUME_SCREEN_BASE_CONTROL_BLOCK *)window, volume_progress_val);
139         break;
140 
141     case GX_EVENT_TIMER:
142         if (event_ptr->gx_event_payload.gx_event_timer_id == TIMER_ID_PROGRESS_BAR_ANIMATION)
143         {
144             progress_bar_animation_update((VOLUME_SCREEN_BASE_CONTROL_BLOCK *)window);
145         }
146         break;
147 
148     default:
149         return screen_base_event_process(window, event_ptr);
150     }
151 
152     return 0;
153 }
154 
155 /******************************************************************************************/
156 /* Override the default event processing of "volume_progress_bar" to handle pen down      */
157 /* event.                                                                                 */
158 /******************************************************************************************/
volume_progress_bar_event_process(GX_PROGRESS_BAR * bar,GX_EVENT * event_ptr)159 UINT volume_progress_bar_event_process(GX_PROGRESS_BAR *bar, GX_EVENT* event_ptr)
160 {
161     INT val;
162     GX_RECTANGLE* size = &bar->gx_widget_size;
163     GX_PROGRESS_BAR_INFO* info = &bar->gx_progress_bar_info;
164     VOLUME_SCREEN_BASE_CONTROL_BLOCK *base;
165 
166     if (event_ptr->gx_event_type == GX_EVENT_PEN_DOWN)
167     {
168         if (is_mute)
169         {
170             /* Unmute.  */
171             is_mute = GX_FALSE;
172 
173             if (current_screen)
174             {
175                 base = (VOLUME_SCREEN_BASE_CONTROL_BLOCK*)current_screen;
176                 gx_widget_style_remove(&base->volume_screen_base_mute_btn, GX_STYLE_BUTTON_PUSHED);
177             }
178         }
179 
180         val = (size->gx_rectangle_bottom - event_ptr->gx_event_payload.gx_event_pointdata.gx_point_y + 2);
181         val *= (info->gx_progress_bar_info_max_val - info->gx_progress_bar_info_min_val);
182         val /= (size->gx_rectangle_bottom - size->gx_rectangle_top + 1);
183         val += info->gx_progress_bar_info_min_val;
184 
185         gx_progress_bar_value_set(bar, val);
186         return GX_SUCCESS;
187     }
188     else
189     {
190         return gx_progress_bar_event_process(bar, event_ptr);
191     }
192 }
193