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_4444argb_resources.h"
9 #include "all_widgets_4444argb_specifications.h"
10 
11 extern VOID memory_free(VOID *mem);
12 
13 extern GX_WINDOW     *pRotateScreen;
14 extern GX_WINDOW     *pRotateWin;
15 INT                   rotate_pixelmap_id = GX_PIXELMAP_ID_ICON_FOOT;
16 INT                   angle = 30;
17 GX_BOOL               direct = 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(pRotateScreen);
46         break;
47 
48     case GX_SIGNAL(ID_RADIO_FOOT, GX_EVENT_RADIO_SELECT):
49         rotate_pixelmap_id = GX_PIXELMAP_ID_ICON_FOOT;
50         gx_system_dirty_mark(pRotateScreen);
51         break;
52 
53     case GX_SIGNAL(ID_RADIO_APPLE, GX_EVENT_RADIO_SELECT):
54         rotate_pixelmap_id= GX_PIXELMAP_ID_RED_APPLE;
55         gx_system_dirty_mark(pRotateScreen);
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(pRotateScreen);
61         break;
62 
63     case GX_SIGNAL(ID_DIRECT_ROTATE, GX_EVENT_TOGGLE_ON):
64         direct = GX_TRUE;
65         gx_system_dirty_mark(pRotateScreen);
66         break;
67 
68     case GX_SIGNAL(ID_DIRECT_ROTATE, GX_EVENT_TOGGLE_OFF):
69         direct = GX_FALSE;
70         gx_system_dirty_mark(pRotateScreen);
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 
102     if (direct)
103     {
104         gx_canvas_pixelmap_rotate(xpos, ypos, pixelmap, angle, -1, -1);
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, 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                 memory_free((VOID *)destination.gx_pixelmap_data);
126             }
127         }
128         else
129         {
130             gx_canvas_pixelmap_draw(xpos, ypos, pixelmap);
131         }
132     }
133 }
134