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_synergy_16bpp_rotated_ccw_resources.h"
9 #include "all_widgets_synergy_16bpp_rotated_ccw_specifications.h"
10
11 extern VOID dynamic_memory_free(VOID *mem);
12
13 INT angle = 90;
14 GX_BOOL rotate_to_canvas = GX_FALSE;
15 INT rotate_pixelmap_id = GX_PIXELMAP_ID__ALPHAMAP;
16
update_angle_prompt()17 VOID update_angle_prompt()
18 {
19 GX_PROMPT *pp;
20 static GX_CHAR rotate_angle[10];
21
22 gx_widget_find(&rotate_screen, ID_ANGLE_DISPLAY, 0, &pp);
23
24 if (pp)
25 {
26 gx_utility_ltoa(angle, rotate_angle, 10);
27 gx_prompt_text_set(pp, rotate_angle);
28 }
29 }
30
rotate_event_handler(GX_WINDOW * window,GX_EVENT * myevent)31 UINT rotate_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
32 {
33 switch (myevent->gx_event_type)
34 {
35 case GX_SIGNAL(ID_SLIDER_ANGLE, GX_EVENT_SLIDER_VALUE):
36 angle = myevent->gx_event_payload.gx_event_longdata;
37 update_angle_prompt();
38 break;
39
40 case GX_SIGNAL(ID_ALPHAMAP, GX_EVENT_RADIO_SELECT):
41 rotate_pixelmap_id = GX_PIXELMAP_ID__ALPHAMAP;
42 break;
43
44 case GX_SIGNAL(ID_32ARGB, GX_EVENT_RADIO_SELECT):
45 rotate_pixelmap_id = GX_PIXELMAP_ID__32ARGB;
46 break;
47
48 case GX_SIGNAL(ID_4444ARGB, GX_EVENT_RADIO_SELECT):
49 rotate_pixelmap_id = GX_PIXELMAP_ID__4444ARGB;
50 break;
51
52 case GX_SIGNAL(ID_565RGB, GX_EVENT_RADIO_SELECT):
53 rotate_pixelmap_id = GX_PIXELMAP_ID__565RGB;
54 break;
55
56 case GX_SIGNAL(ID_ROTATE_TO_CANVAS, GX_EVENT_TOGGLE_ON):
57 rotate_to_canvas = GX_TRUE;
58 break;
59
60 case GX_SIGNAL(ID_ROTATE_TO_CANVAS, GX_EVENT_TOGGLE_OFF):
61 rotate_to_canvas = GX_FALSE;
62 break;
63
64 default:
65 return next_button_handler(window, myevent);
66 }
67
68 gx_system_dirty_mark(&rotate_screen.rotate_screen_pixelmap_window);
69
70 return 0;
71 }
72
pixelmap_draw(GX_WINDOW * window)73 VOID pixelmap_draw(GX_WINDOW *window)
74 {
75 INT xpos;
76 INT ypos;
77 GX_PIXELMAP *pixelmap;
78 GX_RECTANGLE win_size;
79 GX_PIXELMAP destination;
80 INT x_axis_old;
81 INT y_axis_old;
82 INT x_axis;
83 INT y_axis;
84
85 gx_window_draw((GX_WINDOW*)window);
86
87 gx_context_pixelmap_get(rotate_pixelmap_id, &pixelmap);
88 win_size = window->gx_widget_size;
89
90 xpos = (win_size.gx_rectangle_right + win_size.gx_rectangle_left - pixelmap->gx_pixelmap_width) >> 1;
91 ypos = (win_size.gx_rectangle_top + win_size.gx_rectangle_bottom - pixelmap->gx_pixelmap_height) >> 1;
92
93 gx_context_brush_define(GX_COLOR_ID_ORANGE, GX_COLOR_ID_ORANGE, 0);
94
95 if (rotate_to_canvas)
96 {
97 gx_canvas_pixelmap_rotate(xpos, ypos, pixelmap, angle, -1, -1);
98 }
99 else
100 {
101 x_axis_old = (pixelmap->gx_pixelmap_width >> 1);
102 y_axis_old = (pixelmap->gx_pixelmap_height >> 1);
103
104 x_axis = x_axis_old;
105 y_axis = y_axis_old;
106
107 if (gx_utility_pixelmap_rotate(pixelmap, angle, &destination, &x_axis, &y_axis) == GX_SUCCESS)
108 {
109 xpos += x_axis_old - x_axis;
110 ypos += y_axis_old - y_axis;
111
112 /* Draw rotated pixelmap. */
113 gx_canvas_pixelmap_draw(xpos, ypos, &destination);
114
115 /* free memory of the rotated pixelmap */
116 if (destination.gx_pixelmap_data)
117 {
118 dynamic_memory_free((VOID *)destination.gx_pixelmap_data);
119 }
120 if (destination.gx_pixelmap_aux_data)
121 {
122 dynamic_memory_free((VOID *)destination.gx_pixelmap_aux_data);
123 }
124 }
125 else
126 {
127 gx_canvas_pixelmap_draw(xpos, ypos, pixelmap);
128 }
129 }
130 }
131