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_1555xrgb_resources.h"
9 #include "all_widgets_1555xrgb_specifications.h"
10 
11 extern VOID memory_free(VOID *mem);
12 
13 extern GX_WINDOW     *pRotateScreen;
14 extern GX_WINDOW     *pRotateWin;
15 INT                   angle = 30;
16 INT                   rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FOOT;
17 GX_BOOL               canvas_rotate = GX_FALSE;
18 
update_angle_prompt()19 VOID update_angle_prompt()
20 {
21     GX_PROMPT *pp;
22     static GX_CHAR angle_text_buffer[10];
23     GX_STRING angle_text;
24 
25     gx_widget_find(pRotateScreen, ID_ANGLE_DISPLAY, 0, &pp);
26 
27     if (pp)
28     {
29         gx_utility_ltoa(angle, angle_text_buffer, 10);
30         angle_text.gx_string_ptr = angle_text_buffer;
31         angle_text.gx_string_length = strnlen(angle_text_buffer, sizeof(angle_text_buffer));
32         gx_prompt_text_set_ext(pp, &angle_text);
33     }
34 }
35 
rotate_event_handler(GX_WINDOW * window,GX_EVENT * myevent)36 UINT rotate_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
37 {
38 UINT status = 0;
39 
40     switch (myevent->gx_event_type)
41     {
42     case GX_SIGNAL(ID_SLIDER_ANGLE, GX_EVENT_SLIDER_VALUE):
43         angle = myevent->gx_event_payload.gx_event_longdata;
44         update_angle_prompt();
45         gx_system_dirty_mark(pRotateWin);
46         break;
47 
48     case GX_SIGNAL(ID_RADIO_FOOT, GX_EVENT_RADIO_SELECT):
49         rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FOOT;
50         gx_system_dirty_mark(pRotateWin);
51         break;
52 
53     case GX_SIGNAL(ID_RADIO_APPLE, GX_EVENT_RADIO_SELECT):
54         rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_APPLE;
55         gx_system_dirty_mark(pRotateWin);
56         break;
57 
58     case GX_SIGNAL(ID_RADIO_FISH, GX_EVENT_RADIO_SELECT):
59         rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FISH;
60         gx_system_dirty_mark(pRotateWin);
61         break;
62 
63     case GX_SIGNAL(ID_DIRECT_ROTATE, GX_EVENT_TOGGLE_ON):
64         canvas_rotate = GX_TRUE;
65         gx_system_dirty_mark(pRotateWin);
66         break;
67 
68     case GX_SIGNAL(ID_DIRECT_ROTATE, GX_EVENT_TOGGLE_OFF):
69         canvas_rotate = GX_FALSE;
70         gx_system_dirty_mark(pRotateWin);
71         break;
72 
73     default:
74         return next_button_handler(window, myevent);
75         break;
76     }
77     return status;
78 }
79 
pixelmap_draw(GX_WINDOW * window)80 VOID pixelmap_draw(GX_WINDOW *window)
81 {
82 INT  xpos;
83 INT  ypos;
84 GX_PIXELMAP *pixelmap;
85 GX_RECTANGLE win_size;
86 GX_PIXELMAP destination;
87 INT x_axis_old;
88 INT y_axis_old;
89 INT x_axis;
90 INT y_axis;
91 
92     gx_window_draw((GX_WINDOW*)window);
93 
94     gx_context_pixelmap_get(rotate_pixelmap_id, &pixelmap);
95 
96     win_size = pRotateWin->gx_widget_size;
97 
98     xpos = (win_size.gx_rectangle_right + win_size.gx_rectangle_left - pixelmap->gx_pixelmap_width) >> 1;
99     ypos = (win_size.gx_rectangle_top + win_size.gx_rectangle_bottom - pixelmap->gx_pixelmap_height) >> 1;
100 
101     if (canvas_rotate)
102     {
103         gx_canvas_pixelmap_rotate(xpos, ypos, pixelmap, angle, -1, -1);
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, 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                 memory_free((VOID *)destination.gx_pixelmap_data);
125             }
126             if (destination.gx_pixelmap_aux_data)
127             {
128                 memory_free((VOID *)destination.gx_pixelmap_aux_data);
129             }
130         }
131         else
132         {
133             /* Draw rotated pixelmap.  */
134             gx_canvas_pixelmap_draw(xpos, ypos, pixelmap);
135         }
136     }
137 }
138