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_1bpp_resources.h"
8 #include "all_widgets_1bpp_specifications.h"
9 
10 extern VOID memory_free(VOID *mem);
11 
12 extern GX_WINDOW  *pRotateScreen;
13 extern GX_WINDOW  *pRotateWin;
14 INT                angle = 270;
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         x_axis_old = (pixelmap->gx_pixelmap_width >> 1);
107         y_axis_old = (pixelmap->gx_pixelmap_height >> 1);
108 
109         x_axis = x_axis_old;
110         y_axis = y_axis_old;
111 
112         if (gx_utility_pixelmap_rotate(pixelmap, angle, &destination, &x_axis, &y_axis) == GX_SUCCESS)
113         {
114             xpos += x_axis_old - x_axis;
115             ypos += y_axis_old - y_axis;
116 
117             /* Draw rotated pixelmap.  */
118             gx_canvas_pixelmap_draw(xpos, ypos, &destination);
119 
120             /* free memory of the rotated pixelmap */
121             if (destination.gx_pixelmap_data)
122             {
123                 memory_free((VOID *)destination.gx_pixelmap_data);
124             }
125 
126         }
127         else
128         {
129             gx_canvas_pixelmap_draw(xpos, ypos, pixelmap);
130         }
131     }
132 }
133