1 /* This is a small demo of the high-performance GUIX graphics framework. */
2 
3 #include <stdio.h>
4 #include <time.h>
5 #include "gx_api.h"
6 
7 #include "guix_medical_resources.h"
8 #include "guix_medical_specifications.h"
9 
10 #include "demo_guix_medical.h"
11 
12 /* Define timer ids.  */
13 #define TIME_TIMER                    100
14 #define ACTIVE_CIRCLE_ANIMATION_TIMER 101
15 
16 /* Define constants.  */
17 #define SCHEDULE_COL_COUNT 7
18 #define SCHEDULE_ROW_COUNT 11
19 
20 UINT month_name_ids[] = {
21     GX_STRING_ID_JANUARY,
22     GX_STRING_ID_FEBRUARY,
23     GX_STRING_ID_MARCH,
24     GX_STRING_ID_APRIL,
25     GX_STRING_ID_MAY,
26     GX_STRING_ID_JUNE,
27     GX_STRING_ID_JULY,
28     GX_STRING_ID_AUGUST,
29     GX_STRING_ID_SEPTEMBER,
30     GX_STRING_ID_OCTOBER,
31     GX_STRING_ID_NOVEMBER,
32     GX_STRING_ID_DECEMBER
33 };
34 
35 UINT week_name_ids[] = {
36     GX_STRING_ID_SUNDAY,
37     GX_STRING_ID_MONDAY,
38     GX_STRING_ID_TUESDAY,
39     GX_STRING_ID_WEDNESDAY,
40     GX_STRING_ID_THURSDAY,
41     GX_STRING_ID_FRIDAY,
42     GX_STRING_ID_SATURDAY
43 };
44 
45 GX_PROMPT* week_widget_list[SCHEDULE_COL_COUNT] = {
46     &schedule_screen.schedule_screen_c1_week,
47     &schedule_screen.schedule_screen_c2_week,
48     &schedule_screen.schedule_screen_c3_week,
49     &schedule_screen.schedule_screen_c4_week,
50     &schedule_screen.schedule_screen_c5_week,
51     &schedule_screen.schedule_screen_c6_week,
52     &schedule_screen.schedule_screen_c7_week
53 };
54 
55 GX_NUMERIC_PROMPT* day_widget_list[SCHEDULE_COL_COUNT] = {
56     &schedule_screen.schedule_screen_c1_day,
57     &schedule_screen.schedule_screen_c2_day,
58     &schedule_screen.schedule_screen_c3_day,
59     &schedule_screen.schedule_screen_c4_day,
60     &schedule_screen.schedule_screen_c5_day,
61     &schedule_screen.schedule_screen_c6_day,
62     &schedule_screen.schedule_screen_c7_day,
63 };
64 
65 VOID hide_active_bar();
66 
67 /******************************************************************************************/
68 /* Update date of the schedule table.                                                     */
69 /******************************************************************************************/
update_date()70 static VOID update_date()
71 {
72 INT        index;
73 time_t     now;
74 struct tm *ts;
75 
76     now = time(NULL);
77     ts = localtime(&now);
78 
79     gx_prompt_text_id_set(&schedule_screen.schedule_screen_month, month_name_ids[ts->tm_mon]);
80     gx_numeric_prompt_value_set(&schedule_screen.schedule_screen_year, ts->tm_year + 1900);
81 
82     ts->tm_mday--;
83 
84     for (index = 0; index < SCHEDULE_COL_COUNT; index++)
85     {
86         /* Normalize ts.  */
87         mktime(ts);
88 
89         gx_prompt_text_id_set(week_widget_list[index], week_name_ids[ts->tm_wday]);
90         gx_numeric_prompt_value_set(day_widget_list[index], ts->tm_mday);
91 
92         ts->tm_mday++;
93     }
94 }
95 
96 /******************************************************************************************/
97 /* Show the active bar to display the patient's information.                              */
98 /******************************************************************************************/
show_active_bar()99 static VOID show_active_bar()
100 {
101     gx_widget_attach(&schedule_screen.schedule_screen_r5_win, &schedule_screen.schedule_screen_active_bar);
102     gx_widget_attach(&schedule_screen.schedule_screen_active_bar, &schedule_screen.schedule_screen_active_ball);
103 
104     gx_widget_hide(&schedule_screen.schedule_screen_active_circle);
105 }
106 
107 /******************************************************************************************/
108 /* Hide the active bar.                                                                   */
109 /******************************************************************************************/
hide_active_bar()110 VOID hide_active_bar()
111 {
112     gx_widget_detach(&schedule_screen.schedule_screen_active_bar);
113     gx_widget_attach(&schedule_screen.schedule_screen_r5_win, &schedule_screen.schedule_screen_active_ball);
114 
115     gx_widget_show(&schedule_screen.schedule_screen_active_circle);
116 }
117 
118 /******************************************************************************************/
119 /* Show/Hide active circle.                                                               */
120 /******************************************************************************************/
show_hide_active_circle()121 static VOID show_hide_active_circle()
122 {
123     if (schedule_screen.schedule_screen_active_bar.gx_widget_parent == GX_NULL)
124     {
125         if (schedule_screen.schedule_screen_active_circle.gx_widget_parent)
126         {
127             gx_widget_detach(&schedule_screen.schedule_screen_active_circle);
128         }
129         else
130         {
131             gx_widget_back_attach(&schedule_screen.schedule_screen_r5_win, &schedule_screen.schedule_screen_active_circle);
132         }
133     }
134 }
135 
136 /******************************************************************************************/
137 /* Update time colon animation.                                                           */
138 /******************************************************************************************/
update_time_colon_animation()139 static VOID update_time_colon_animation()
140 {
141     GX_RESOURCE_ID text_color;
142 
143     if (schedule_screen.schedule_screen_colon.gx_prompt_disabled_text_color == GX_COLOR_ID_GRAY)
144     {
145         text_color = GX_COLOR_ID_DARK_GRAY;
146     }
147     else
148     {
149         text_color = GX_COLOR_ID_GRAY;
150     }
151 
152     gx_prompt_text_color_set(&schedule_screen.schedule_screen_colon, text_color, text_color, text_color);
153 }
154 
155 /******************************************************************************************/
156 /* Override the default event processing of "schedule_screen" to handle signals from my   */
157 /* child widgets.                                                                         */
158 /******************************************************************************************/
schedule_screen_event_handler(GX_WINDOW * window,GX_EVENT * myevent)159 UINT schedule_screen_event_handler(GX_WINDOW* window, GX_EVENT* myevent)
160 {
161     UINT status = GX_SUCCESS;
162 
163     switch (myevent->gx_event_type)
164     {
165     case GX_EVENT_SHOW:
166         update_date();
167 
168         gx_system_timer_start(window, TIME_TIMER, GX_TICKS_SECOND, GX_TICKS_SECOND);
169 
170         template_event_handler(window, myevent);
171         break;
172 
173     case GX_EVENT_HIDE:
174 
175         /* Call the event process of the template on which the vitals screen is based.  */
176         template_event_handler(window, myevent);
177 
178         /* Stop all timers that belongs to the window. */
179         gx_system_timer_stop((GX_WIDGET*)window, 0);
180         break;
181 
182     case GX_SIGNAL(ID_ACTIVE_BALL, GX_EVENT_CLICKED):
183         if (schedule_screen.schedule_screen_active_bar.gx_widget_parent == GX_NULL)
184         {
185             show_active_bar();
186         }
187         else
188         {
189             hide_active_bar();
190         }
191         break;
192 
193     case GX_EVENT_ANIMATION_COMPLETE:
194         if (myevent->gx_event_sender == ID_R5_WIN_FADE_IN)
195         {
196             gx_system_timer_start(window, ACTIVE_CIRCLE_ANIMATION_TIMER, GX_TICKS_SECOND / 2, GX_TICKS_SECOND / 2);
197         }
198         break;
199 
200     case GX_EVENT_TIMER:
201         switch (myevent->gx_event_payload.gx_event_timer_id)
202         {
203         case ACTIVE_CIRCLE_ANIMATION_TIMER:
204             show_hide_active_circle();
205             break;
206 
207         case TIME_TIMER:
208             update_time_colon_animation();
209             break;
210         }
211         break;
212 
213     default:
214         status = template_event_handler(window, myevent);
215         break;
216     }
217 
218     return status;
219 }
220 
221 /******************************************************************************************/
222 /* Custom schedule window draw function that draws the grid lines.                        */
223 /******************************************************************************************/
schedule_win_draw(GX_WINDOW * window)224 VOID schedule_win_draw(GX_WINDOW *window)
225 {
226 GX_RECTANGLE *client;
227 GX_RECTANGLE *size;
228 INT           xpos;
229 INT           ypos;
230 INT           xoffset;
231 INT           yoffset;
232 INT           index;
233 
234     /* Draw window background.  */
235     gx_window_background_draw(window);
236 
237     client = &window->gx_window_client;
238 
239     xoffset = (schedule_screen.schedule_screen_c2_day.gx_widget_size.gx_rectangle_left -
240                schedule_screen.schedule_screen_c1_day.gx_widget_size.gx_rectangle_left);
241 
242     yoffset = (schedule_screen.schedule_screen_r2_hour.gx_widget_size.gx_rectangle_top -
243                schedule_screen.schedule_screen_r1_hour.gx_widget_size.gx_rectangle_top);
244 
245     xpos = schedule_screen.schedule_screen_r1_am_pm.gx_widget_size.gx_rectangle_right + 5;
246     ypos = schedule_screen.schedule_screen_r1_am_pm.gx_widget_size.gx_rectangle_bottom - 5;
247 
248     /* Draw horizontal lines.  */
249     gx_context_brush_width_set(1);
250     gx_context_line_color_set(GX_COLOR_ID_DARK_GRAY);
251 
252     for (index = 0; index < SCHEDULE_ROW_COUNT; index++)
253     {
254         gx_canvas_line_draw(xpos, ypos, client->gx_rectangle_right, ypos);
255 
256         ypos += yoffset;
257     }
258 
259     xpos = schedule_screen.schedule_screen_c1_week.gx_widget_size.gx_rectangle_left - 10;
260     ypos -= yoffset;
261 
262     /* Draw vertical lines.  */
263     for (index = 0; index < SCHEDULE_COL_COUNT; index++)
264     {
265 
266         gx_canvas_line_draw(xpos, client->gx_rectangle_top, xpos, ypos);
267 
268         xpos += xoffset;
269     }
270 
271     /* Draw current time line.  */
272     gx_context_line_color_set(GX_COLOR_ID_RED);
273     size = &schedule_screen.schedule_screen_current_time.gx_widget_size;
274 
275     xpos = schedule_screen.schedule_screen_r1_am_pm.gx_widget_size.gx_rectangle_right + 5;
276     ypos = (size->gx_rectangle_top + size->gx_rectangle_bottom) >> 1;
277     gx_canvas_line_draw(xpos, ypos, size->gx_rectangle_left - 1, ypos);
278 
279     xpos = size->gx_rectangle_right + 1;
280     gx_canvas_line_draw(xpos, ypos, client->gx_rectangle_right, ypos);
281 
282     /* Draw child widgets.  */
283     gx_widget_children_draw(window);
284 }
285