1 #include <stdio.h>
2 #include "gx_api.h"
3 #include "all_widgets_32argb_resources.h"
4 #include "all_widgets_32argb_specifications.h"
5
6 extern VOID rotate_memory_free(VOID *mem);
7
8 INT rotate_angle = 30;
9 INT rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FOOT;
10 GX_BOOL canvas_rotate = GX_FALSE;
11
update_angle_prompt()12 VOID update_angle_prompt()
13 {
14 GX_PROMPT *pp;
15 static GX_CHAR text_buffer[10];
16 GX_STRING string;
17
18 gx_widget_find((GX_WIDGET *)&rotate_screen, ID_ANGLE_DISPLAY, 0, &pp);
19
20 if (pp)
21 {
22 gx_utility_ltoa(rotate_angle, text_buffer, sizeof(text_buffer));
23 string.gx_string_ptr = text_buffer;
24 string.gx_string_length = strnlen(text_buffer, sizeof(text_buffer));
25 gx_prompt_text_set_ext(pp, &string);
26 }
27 }
28
rotate_event_handler(GX_WINDOW * window,GX_EVENT * myevent)29 UINT rotate_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
30 {
31 UINT status = 0;
32
33 switch (myevent->gx_event_type)
34 {
35 case GX_SIGNAL(ID_SLIDER_ANGLE, GX_EVENT_SLIDER_VALUE):
36 rotate_angle = myevent->gx_event_payload.gx_event_longdata;
37 update_angle_prompt();
38 gx_system_dirty_mark((GX_WIDGET *)&rotate_screen.rotate_screen_pixelmap_window);
39 break;
40
41 case GX_SIGNAL(ID_RADIO_FOOT, GX_EVENT_RADIO_SELECT):
42 rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FOOT;
43 gx_system_dirty_mark((GX_WIDGET *)&rotate_screen.rotate_screen_pixelmap_window);
44 break;
45
46 case GX_SIGNAL(ID_RADIO_APPLE, GX_EVENT_RADIO_SELECT):
47 rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_APPLE;
48 gx_system_dirty_mark((GX_WIDGET *)&rotate_screen.rotate_screen_pixelmap_window);
49 break;
50
51 case GX_SIGNAL(ID_RADIO_FISH, GX_EVENT_RADIO_SELECT):
52 rotate_pixelmap_id = GX_PIXELMAP_ID_ROTATE_FISH;
53 gx_system_dirty_mark((GX_WIDGET *)&rotate_screen.rotate_screen_pixelmap_window);
54 break;
55
56 case GX_SIGNAL(ID_DIRECT_ROTATE, GX_EVENT_TOGGLE_ON):
57 canvas_rotate = GX_TRUE;
58 gx_system_dirty_mark((GX_WIDGET *)&rotate_screen.rotate_screen_pixelmap_window);
59 break;
60
61 case GX_SIGNAL(ID_DIRECT_ROTATE, GX_EVENT_TOGGLE_OFF):
62 canvas_rotate = GX_FALSE;
63 gx_system_dirty_mark((GX_WIDGET *)&rotate_screen.rotate_screen_pixelmap_window);
64 break;
65
66 default:
67 return gx_window_event_process(window, myevent);
68 break;
69 }
70 return status;
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
89 win_size = rotate_screen.rotate_screen_pixelmap_window.gx_widget_size;
90
91 xpos = (win_size.gx_rectangle_right + win_size.gx_rectangle_left - pixelmap->gx_pixelmap_width) >> 1;
92 ypos = (win_size.gx_rectangle_top + win_size.gx_rectangle_bottom - pixelmap->gx_pixelmap_height) >> 1;
93
94 if (canvas_rotate)
95 {
96 if ((rotate_angle % 360) > 180)
97 {
98 x_axis = (pixelmap->gx_pixelmap_width >> 1);
99 y_axis = (pixelmap->gx_pixelmap_height >> 1);
100 }
101 else
102 {
103 x_axis = -1;
104 y_axis = -1;
105 }
106 gx_canvas_pixelmap_rotate(xpos, ypos, pixelmap, rotate_angle, x_axis, y_axis);
107 }
108 else
109 {
110 x_axis_old = (pixelmap->gx_pixelmap_width >> 1);
111 y_axis_old = (pixelmap->gx_pixelmap_height >> 1);
112
113 x_axis = x_axis_old;
114 y_axis = y_axis_old;
115
116 if (gx_utility_pixelmap_rotate(pixelmap, rotate_angle, &destination, &x_axis, &y_axis) == GX_SUCCESS)
117 {
118 xpos += x_axis_old - x_axis;
119 ypos += y_axis_old - y_axis;
120
121 /* Draw rotated pixelmap. */
122 gx_canvas_pixelmap_draw(xpos, ypos, &destination);
123
124 /* free memory of the rotated pixelmap */
125 if (destination.gx_pixelmap_data)
126 {
127 rotate_memory_free((VOID *)destination.gx_pixelmap_data);
128 }
129 if (destination.gx_pixelmap_aux_data)
130 {
131 rotate_memory_free((VOID *)destination.gx_pixelmap_aux_data);
132 }
133 }
134 else
135 {
136 gx_canvas_pixelmap_draw(xpos, ypos, pixelmap);
137 }
138 }
139 }
140