1 /****************************************************************/
2 /* This file tests gx_utility_4444argb_roate and                */
3 /*                 _gx_display_driver_16bpp_pixelmap_rotate     */
4 /*                                                              */
5 /****************************************************************/
6 #include <stdio.h>
7 #include "gx_api.h"
8 #include "all_widgets_16bpp_rotated_cw_binary_resources.h"
9 #include "all_widgets_16bpp_rotated_cw_binary_specifications.h"
10 
11 extern VOID dynamic_memory_free(VOID *mem);
12 
13 INT     angle = 90;
14 GX_BOOL direct = GX_FALSE;
15 INT     rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FOOT;
16 
rotate_event_handler(GX_WINDOW * window,GX_EVENT * myevent)17 UINT rotate_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
18 {
19     switch (myevent->gx_event_type)
20     {
21     case GX_SIGNAL(ID_SLIDER_ANGLE, GX_EVENT_SLIDER_VALUE):
22         angle = myevent->gx_event_payload.gx_event_longdata;
23         gx_numeric_prompt_value_set(&rotate_screen.rotate_screen_angle_value, angle);
24         gx_system_dirty_mark(window);
25         break;
26 
27     case GX_SIGNAL(ID_RADIO_FOOT, GX_EVENT_RADIO_SELECT):
28         rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FOOT;
29         gx_system_dirty_mark(window);
30         break;
31 
32     case GX_SIGNAL(ID_RADIO_APPLE, GX_EVENT_RADIO_SELECT):
33         rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_APPLE;
34         gx_system_dirty_mark(window);
35         break;
36 
37     case GX_SIGNAL(ID_RADIO_FISH, GX_EVENT_RADIO_SELECT):
38         rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FISH;
39         gx_system_dirty_mark(window);
40         break;
41 
42     case GX_SIGNAL(ID_DIRECT_ROTATE, GX_EVENT_TOGGLE_ON):
43         direct = GX_TRUE;
44         gx_system_dirty_mark(window);
45         break;
46 
47     case GX_SIGNAL(ID_DIRECT_ROTATE, GX_EVENT_TOGGLE_OFF):
48         direct = GX_FALSE;
49         gx_system_dirty_mark(window);
50         break;
51 
52     default:
53         return next_button_handler(window, myevent);
54         break;
55     }
56 
57     return 0;
58 }
59 
pixelmap_draw(GX_WINDOW * window)60 VOID pixelmap_draw(GX_WINDOW *window)
61 {
62 INT  xpos;
63 INT  ypos;
64 GX_PIXELMAP *pixelmap;
65 GX_RECTANGLE win_size;
66 GX_PIXELMAP destination;
67 INT x_axis_old;
68 INT y_axis_old;
69 INT x_axis;
70 INT y_axis;
71 
72     gx_window_draw((GX_WINDOW*)window);
73 
74     gx_context_pixelmap_get(rotate_pixelmap_id, &pixelmap);
75     win_size = window->gx_widget_size;
76 
77     xpos = (win_size.gx_rectangle_right + win_size.gx_rectangle_left - pixelmap->gx_pixelmap_width) >> 1;
78     ypos = (win_size.gx_rectangle_top + win_size.gx_rectangle_bottom - pixelmap->gx_pixelmap_height) >> 1;
79 
80     gx_context_brush_define(GX_COLOR_ID_GRAY, GX_COLOR_ID_GRAY, 0);
81 
82     if (direct)
83     {
84         gx_canvas_pixelmap_rotate(xpos, ypos, pixelmap, angle, -1, -1);
85     }
86     else
87     {
88         x_axis_old = (pixelmap->gx_pixelmap_width >> 1);
89         y_axis_old = (pixelmap->gx_pixelmap_height >> 1);
90 
91         x_axis = x_axis_old;
92         y_axis = y_axis_old;
93 
94         if (gx_utility_pixelmap_rotate(pixelmap, angle, &destination, &x_axis, &y_axis) == GX_SUCCESS)
95         {
96             xpos += x_axis_old - x_axis;
97             ypos += y_axis_old - y_axis;
98 
99             /* Draw rotated pixelmap.  */
100             gx_canvas_pixelmap_draw(xpos, ypos, &destination);
101 
102             /* free memory of the rotated pixelmap */
103             if (destination.gx_pixelmap_data)
104             {
105                 dynamic_memory_free((VOID *)destination.gx_pixelmap_data);
106             }
107             if (destination.gx_pixelmap_aux_data)
108             {
109                 dynamic_memory_free((VOID *)destination.gx_pixelmap_aux_data);
110             }
111         }
112         else
113         {
114             gx_canvas_pixelmap_draw(xpos, ypos, pixelmap);
115         }
116     }
117 }
118