1 #include <stdio.h>
2 #include "gx_api.h"
3 #include "folder_output_test_MAIN_DISPLAY_resources.h"
4 #include "folder_output_test_SECONDARY_resources.h"
5 #include "folder_output_test_specifications.h"
6 
7 extern VOID           rotate_memory_free(VOID *mem);
8 
9 INT                   rotate_angle = 30;
10 INT                   rotate_pixelmap_id = GX_PIXELMAP_ID_MAIN_DISPLAY_ROTATE_FOOT;
11 GX_BOOL               canvas_rotate = GX_FALSE;
12 
update_angle_prompt()13 VOID update_angle_prompt()
14 {
15     GX_PROMPT *pp;
16     static GX_CHAR text[10];
17 
18     gx_widget_find((GX_WIDGET *)&MAIN_DISPLAY_rotate_screen, ID_ANGLE_DISPLAY, 0, &pp);
19 
20     if (pp)
21     {
22         gx_utility_ltoa(rotate_angle, text, 10);
23         gx_prompt_text_set(pp, text);
24     }
25 }
26 
rotate_event_handler(GX_WINDOW * window,GX_EVENT * myevent)27 UINT rotate_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
28 {
29 UINT status = 0;
30 
31     switch (myevent->gx_event_type)
32     {
33     case GX_SIGNAL(ID_SLIDER_ANGLE, GX_EVENT_SLIDER_VALUE):
34         rotate_angle = myevent->gx_event_payload.gx_event_longdata;
35         update_angle_prompt();
36         gx_system_dirty_mark((GX_WIDGET *)&MAIN_DISPLAY_rotate_screen.MAIN_DISPLAY_rotate_screen_pixelmap_window);
37         break;
38 
39     case GX_SIGNAL(ID_RADIO_FOOT, GX_EVENT_RADIO_SELECT):
40         rotate_pixelmap_id = GX_PIXELMAP_ID_MAIN_DISPLAY_ROTATE_FOOT;
41         gx_system_dirty_mark((GX_WIDGET *)&MAIN_DISPLAY_rotate_screen.MAIN_DISPLAY_rotate_screen_pixelmap_window);
42         break;
43 
44     case GX_SIGNAL(ID_RADIO_APPLE, GX_EVENT_RADIO_SELECT):
45         rotate_pixelmap_id = GX_PIXELMAP_ID_MAIN_DISPLAY_ROTATE_APPLE;
46         gx_system_dirty_mark((GX_WIDGET *)&MAIN_DISPLAY_rotate_screen.MAIN_DISPLAY_rotate_screen_pixelmap_window);
47         break;
48 
49     case GX_SIGNAL(ID_RADIO_FISH, GX_EVENT_RADIO_SELECT):
50         rotate_pixelmap_id = GX_PIXELMAP_ID_MAIN_DISPLAY_ROTATE_FISH;
51         gx_system_dirty_mark((GX_WIDGET *)&MAIN_DISPLAY_rotate_screen.MAIN_DISPLAY_rotate_screen_pixelmap_window);
52         break;
53 
54     case GX_SIGNAL(ID_DIRECT_ROTATE, GX_EVENT_TOGGLE_ON):
55         canvas_rotate = GX_TRUE;
56         gx_system_dirty_mark((GX_WIDGET *)&MAIN_DISPLAY_rotate_screen.MAIN_DISPLAY_rotate_screen_pixelmap_window);
57         break;
58 
59     case GX_SIGNAL(ID_DIRECT_ROTATE, GX_EVENT_TOGGLE_OFF):
60         canvas_rotate = GX_FALSE;
61         gx_system_dirty_mark((GX_WIDGET *)&MAIN_DISPLAY_rotate_screen.MAIN_DISPLAY_rotate_screen_pixelmap_window);
62         break;
63 
64     default:
65         return gx_window_event_process(window, myevent);
66         break;
67     }
68     return status;
69 }
70 
pixelmap_draw(GX_WINDOW * window)71 VOID pixelmap_draw(GX_WINDOW *window)
72 {
73 INT  xpos;
74 INT  ypos;
75 GX_PIXELMAP *pixelmap;
76 GX_RECTANGLE win_size;
77 GX_PIXELMAP destination;
78 INT x_axis_old;
79 INT y_axis_old;
80 INT x_axis;
81 INT y_axis;
82 
83     gx_window_draw((GX_WINDOW*)window);
84 
85     gx_context_pixelmap_get(rotate_pixelmap_id, &pixelmap);
86 
87     win_size = MAIN_DISPLAY_rotate_screen.MAIN_DISPLAY_rotate_screen_pixelmap_window.gx_widget_size;
88 
89     xpos = (win_size.gx_rectangle_right + win_size.gx_rectangle_left - pixelmap->gx_pixelmap_width) >> 1;
90     ypos = (win_size.gx_rectangle_top + win_size.gx_rectangle_bottom - pixelmap->gx_pixelmap_height) >> 1;
91 
92     if (canvas_rotate)
93     {
94         if ((rotate_angle % 360) > 180)
95         {
96             x_axis = (pixelmap->gx_pixelmap_width >> 1);
97             y_axis = (pixelmap->gx_pixelmap_height >> 1);
98         }
99         else
100         {
101             x_axis = -1;
102             y_axis = -1;
103         }
104         gx_canvas_pixelmap_rotate(xpos, ypos, pixelmap, rotate_angle, x_axis, y_axis);
105     }
106     else
107     {
108         x_axis_old = (pixelmap->gx_pixelmap_width >> 1);
109         y_axis_old = (pixelmap->gx_pixelmap_height >> 1);
110 
111         x_axis = x_axis_old;
112         y_axis = y_axis_old;
113 
114         if (gx_utility_pixelmap_rotate(pixelmap, rotate_angle, &destination, &x_axis, &y_axis) == GX_SUCCESS)
115         {
116             xpos += x_axis_old - x_axis;
117             ypos += y_axis_old - y_axis;
118 
119             /* Draw rotated pixelmap.  */
120             gx_canvas_pixelmap_draw(xpos, ypos, &destination);
121 
122             /* free memory of the rotated pixelmap */
123             if (destination.gx_pixelmap_data)
124             {
125                 rotate_memory_free((VOID *)destination.gx_pixelmap_data);
126             }
127             if (destination.gx_pixelmap_aux_data)
128             {
129                 rotate_memory_free((VOID *)destination.gx_pixelmap_aux_data);
130             }
131         }
132         else
133         {
134             gx_canvas_pixelmap_draw(xpos, ypos, pixelmap);
135         }
136     }
137 }
138