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