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