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