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