1 #include "demo_guix_smart_watch.h"
2
3 #define LINE_LENGTH 388
4 #define LINE_CORNER_ANGLE_0 50
5 #define LINE_CORNER_ANGLE_1 130
6 #define LINE_CORNER_ANGLE_2 230
7 #define LINE_CORNER_ANGLE_3 310
8
9 /********************************************/
10 /* Line rotation angle illustration. */
11 /* */
12 /* 50 -> 130 */
13 /* *************** */
14 /* ** ** */
15 /* * * * * */
16 /* * * * * */
17 /* * * * */
18 /* * * * * */
19 /* * * * * */
20 /* ** ** */
21 /* *************** */
22 /* 310 <- 230 */
23 /********************************************/
24
25 /* Define rotate angle for background animation. */
26 static INT rotate_angle = 50;
27
28 /******************************************************************************************/
29 /* Update rotate angle. */
30 /******************************************************************************************/
background_rotate_update()31 static VOID background_rotate_update()
32 {
33 rotate_angle++;
34
35 if (rotate_angle >= 360)
36 {
37 rotate_angle -= 360;
38 }
39 gx_system_dirty_mark(&clock_3_screen);
40 }
41
42 /******************************************************************************************/
43 /* Override the default event processing of "clock_screen_template" to handle signals */
44 /* from my child widgets. */
45 /******************************************************************************************/
clock_3_screen_event_process(GX_WINDOW * window,GX_EVENT * event_ptr)46 UINT clock_3_screen_event_process(GX_WINDOW* window, GX_EVENT* event_ptr)
47 {
48 switch (event_ptr->gx_event_type)
49 {
50 case GX_EVENT_SHOW:
51 screen_clock_update(&clock_3_screen.clock_3_screen_hour, &clock_3_screen.clock_3_screen_minute, GX_NULL);
52 gx_system_timer_start(window, SCREEN_CLOCK_TIMER_ID, GX_TICKS_SECOND, GX_TICKS_SECOND);
53 return gx_window_event_process(window, event_ptr);
54
55 case USER_EVENT_ANIMATION_START:
56 gx_system_timer_start(window, SCREEN_ANIMATION_TIMER_ID, 100 / GX_SYSTEM_TIMER_MS, 100 / GX_SYSTEM_TIMER_MS);
57 break;
58
59 case USER_EVENT_ANIMATION_STOP:
60 gx_system_timer_stop(window, SCREEN_ANIMATION_TIMER_ID);
61 break;
62
63 case GX_EVENT_TIMER:
64 switch (event_ptr->gx_event_payload.gx_event_timer_id)
65 {
66 case SCREEN_CLOCK_TIMER_ID:
67 screen_clock_update(&clock_3_screen.clock_3_screen_hour, &clock_3_screen.clock_3_screen_minute, GX_NULL);
68 break;
69
70 case SCREEN_ANIMATION_TIMER_ID:
71 background_rotate_update();
72 break;
73 }
74 break;
75
76 default:
77 return gx_window_event_process(window, event_ptr);
78 }
79
80 return 0;
81 }
82
83 /******************************************************************************************/
84 /* Override the default drawing of "clock_3_screen" to add some animation effects. */
85 /******************************************************************************************/
clock_3_screen_draw(GX_WINDOW * window)86 VOID clock_3_screen_draw(GX_WINDOW *window)
87 {
88 INT scaled_angle;
89 INT x_dist;
90 INT y_dist;
91 GX_RECTANGLE* size;
92 INT x_center;
93 INT y_center;
94 GX_POINT polygon[4];
95
96 /* Calculate the polygon for filling. */
97 scaled_angle = GX_FIXED_VAL_MAKE(rotate_angle);
98 x_dist = GX_FIXED_VAL_TO_INT(gx_utility_math_cos(scaled_angle) * LINE_LENGTH);
99 y_dist = GX_FIXED_VAL_TO_INT(gx_utility_math_sin(scaled_angle) * LINE_LENGTH);
100
101 size = &window->gx_widget_size;
102 x_center = ((size->gx_rectangle_left + size->gx_rectangle_right) >> 1);
103 y_center = ((size->gx_rectangle_top + size->gx_rectangle_bottom) >> 1);
104
105 polygon[0].gx_point_x = x_center - x_dist;
106 polygon[0].gx_point_y = y_center - y_dist;
107 polygon[1].gx_point_x = x_center + x_dist;
108 polygon[1].gx_point_y = y_center + y_dist;
109
110 if (rotate_angle >= LINE_CORNER_ANGLE_0 && rotate_angle < LINE_CORNER_ANGLE_1)
111 {
112 polygon[2].gx_point_x = size->gx_rectangle_right;
113 polygon[2].gx_point_y = polygon[1].gx_point_y;
114 polygon[3].gx_point_x = size->gx_rectangle_right;
115 polygon[3].gx_point_y = polygon[0].gx_point_y;
116 }
117 else if (rotate_angle >= LINE_CORNER_ANGLE_1 && rotate_angle < LINE_CORNER_ANGLE_2)
118 {
119 polygon[2].gx_point_x = polygon[1].gx_point_x;
120 polygon[2].gx_point_y = size->gx_rectangle_bottom;
121 polygon[3].gx_point_x = polygon[0].gx_point_x;
122 polygon[3].gx_point_y = size->gx_rectangle_bottom;
123 }
124 else if (rotate_angle >= LINE_CORNER_ANGLE_2 && rotate_angle < LINE_CORNER_ANGLE_3)
125 {
126 polygon[2].gx_point_x = size->gx_rectangle_left;
127 polygon[2].gx_point_y = polygon[1].gx_point_y;
128 polygon[3].gx_point_x = size->gx_rectangle_left;
129 polygon[3].gx_point_y = polygon[0].gx_point_y;
130 }
131 else
132 {
133 polygon[2].gx_point_x = polygon[1].gx_point_x;
134 polygon[2].gx_point_y = size->gx_rectangle_top;
135 polygon[3].gx_point_x = polygon[0].gx_point_x;
136 polygon[3].gx_point_y = size->gx_rectangle_top;
137 }
138
139 /* Draw and fill the polygon with blue color. */
140 gx_context_brush_define(GX_COLOR_ID_BLUE, GX_COLOR_ID_BLUE, GX_BRUSH_ALIAS | GX_BRUSH_SOLID_FILL);
141 gx_context_brush_width_set(1);
142 gx_canvas_polygon_draw(polygon, 4);
143
144 /* Draw the screen children. */
145 gx_widget_children_draw(window);
146 }