1 /* This is a small demo of the high-performance GUIX graphics framework. */
2
3 #include <stdio.h>
4 #include "gx_api.h"
5
6 #include "text_rotation_resources.h"
7 #include "text_rotation_specifications.h"
8
9 #define ROTATION_TIMER 1
10
11 GX_WINDOW_ROOT *root;
12 GX_CANVAS text_canvas;
13 TX_BYTE_POOL memory_pool;
14
15 GX_PIXELMAP Alphamap_8bit_font;
16 GX_PIXELMAP Alphamap_4bit_font;
17 GX_PIXELMAP Alphamap_1bit_font;
18 GX_PIXELMAP Alphamap_8bit_dynamic;
19
20 INT text_angle = 30;
21 GX_BOOL animation_running = GX_FALSE;
22 INT xshift_8bpp = 10;
23 INT yshift_8bpp = 10;
24 INT xshift_4bpp = 5;
25 INT yshift_4bpp = 5;
26 INT xshift_1bpp = 5;
27 INT yshift_1bpp = 5;
28 INT xshift_dynamic = 0;
29 INT yshift_dynamic = 0;
30 INT dynamic_count = 123456789;
31 GX_CHAR dynamic_text[20];
32
33 GX_RESOURCE_ID text_color = GX_COLOR_ID_RED;
34
35 /* define some memory for storage of rotated text pixelmap */
36 #define ROTATION_MEMORY_SIZE (MAIN_DISPLAY_X_RESOLUTION * MAIN_DISPLAY_Y_RESOLUTION)
37 GX_UBYTE rotation_memory[ROTATION_MEMORY_SIZE];
38
39 /* Define prototypes. */
40
41 VOID start_guix(VOID);
42 extern UINT win32_graphics_driver_setup_24xrgb(GX_DISPLAY *display);
43 VOID RenderTextToAlphamaps(GX_WIDGET *window);
44
main(int argc,char ** argv)45 int main(int argc, char ** argv)
46 {
47 tx_kernel_enter();
48 return(0);
49 }
50
51 /******************************************************************************************/
memory_allocate(ULONG size)52 VOID *memory_allocate(ULONG size)
53 {
54 VOID *memptr;
55
56 if (tx_byte_allocate(&memory_pool, &memptr, size, TX_NO_WAIT) == TX_SUCCESS)
57 {
58 return memptr;
59 }
60 return NULL;
61 }
62
63 /******************************************************************************************/
memory_free(VOID * mem)64 void memory_free(VOID *mem)
65 {
66 tx_byte_release(mem);
67 }
68
69 /******************************************************************************************/
tx_application_define(void * first_unused_memory)70 VOID tx_application_define(void *first_unused_memory)
71 {
72 /* create byte pool for needle rotation to use */
73 tx_byte_pool_create(&memory_pool, "scratchpad", rotation_memory,
74 ROTATION_MEMORY_SIZE);
75 start_guix();
76 }
77
78 /******************************************************************************************/
start_guix(VOID)79 VOID start_guix(VOID)
80 {
81 /* Initialize GUIX. */
82 gx_system_initialize();
83
84 gx_studio_display_configure(MAIN_DISPLAY, win32_graphics_driver_setup_24xrgb,
85 LANGUAGE_ENGLISH, MAIN_DISPLAY_DEFAULT_THEME, &root);
86
87 /* install our memory allocator and de-allocator */
88 gx_system_memory_allocator_set(memory_allocate, memory_free);
89
90 /* create the main screen */
91 gx_studio_named_widget_create("screen_base", (GX_WIDGET *)root, GX_NULL);
92
93 /* Show the root window to make it and patients screen visible. */
94 gx_widget_show(root);
95
96 /* start GUIX thread */
97 gx_system_start();
98 }
99
RotateAndShift(GX_WINDOW * window)100 VOID RotateAndShift(GX_WINDOW *window)
101 {
102 INT *xshift;
103 INT *yshift;
104
105 text_angle += 5;
106 if (text_angle >= 360)
107 {
108 text_angle = 0;
109 }
110
111 switch(window->gx_widget_id)
112 {
113 case TEXT_WIN_8BPP:
114 xshift = &xshift_8bpp;
115 yshift = &yshift_8bpp;
116 break;
117
118 case TEXT_WIN_4BPP:
119 xshift = &xshift_4bpp;
120 yshift = &yshift_4bpp;
121 break;
122
123 case TEXT_WIN_1BPP:
124 xshift = &xshift_1bpp;
125 yshift = &yshift_1bpp;
126 break;
127
128 case DYNAMIC_TEXT_WINDOW:
129 xshift = &xshift_dynamic;
130 yshift = &yshift_dynamic;
131 dynamic_count += 17;
132 gx_system_dirty_mark(&screen_base.screen_base_dynamic_text_window);
133 break;
134 }
135
136 if (*xshift || *yshift)
137 {
138 gx_widget_shift(window, *xshift, *yshift, GX_TRUE);
139
140 if (*xshift > 0)
141 {
142 if (window->gx_widget_size.gx_rectangle_right >= MAIN_DISPLAY_X_RESOLUTION)
143 {
144 *xshift = -*xshift;
145 }
146 }
147 else
148 {
149 if (window->gx_widget_size.gx_rectangle_left <= 0)
150 {
151 *xshift = -*xshift;
152 }
153 }
154 if (*yshift > 0)
155 {
156 if (window->gx_widget_size.gx_rectangle_bottom >= MAIN_DISPLAY_Y_RESOLUTION)
157 {
158 *yshift = -*yshift;
159 }
160 }
161 else
162 {
163 if (window->gx_widget_size.gx_rectangle_top <= 0)
164 {
165 *yshift = -*yshift;
166 }
167 }
168 }
169 }
170
RotateAndShiftAll(VOID)171 VOID RotateAndShiftAll(VOID)
172 {
173 RotateAndShift(&screen_base.screen_base_text_window);
174 RotateAndShift(&screen_base.screen_base_text_window_4bpp);
175 RotateAndShift(&screen_base.screen_base_text_window_1bpp);
176 RotateAndShift(&screen_base.screen_base_dynamic_text_window);
177 }
178
179 /******************************************************************************************/
background_win_event_process(GX_WINDOW * window,GX_EVENT * myevent)180 UINT background_win_event_process(GX_WINDOW *window, GX_EVENT *myevent)
181 {
182 switch(myevent->gx_event_type)
183 {
184 case GX_EVENT_SHOW:
185 gx_window_event_process(window, myevent);
186
187 // For the text that doesn't change, render it once to an alpha-map. Then
188 // we can just rotate this alphamap with each drawing update.
189 RenderTextToAlphamaps((GX_WIDGET *) window);
190 break;
191
192 case GX_SIGNAL(ID_BUTTON1, GX_EVENT_CLICKED):
193 text_color = GX_COLOR_ID_RED;
194 if (!animation_running)
195 {
196 RotateAndShiftAll();
197 }
198 break;
199
200 case GX_SIGNAL(ID_BUTTON2, GX_EVENT_CLICKED):
201 text_color = GX_COLOR_ID_GREEN;
202 if (!animation_running)
203 {
204 RotateAndShiftAll();
205 }
206 break;
207
208 case GX_SIGNAL(ID_BUTTON3, GX_EVENT_CLICKED):
209 text_color = GX_COLOR_ID_BLUE;
210 if (!animation_running)
211 {
212 RotateAndShiftAll();
213 }
214 break;
215
216 case GX_SIGNAL(ID_HOME, GX_EVENT_CLICKED):
217 if (animation_running)
218 {
219 gx_system_timer_stop(window, ROTATION_TIMER);
220 animation_running = GX_FALSE;
221 }
222 else
223 {
224 gx_system_timer_start(window, ROTATION_TIMER, 5, 5);
225 animation_running = GX_TRUE;
226 }
227 break;
228
229 case GX_EVENT_TIMER:
230 RotateAndShiftAll();
231 break;
232
233 default:
234 return gx_window_event_process(window, myevent);
235 }
236 return 0;
237 }
238
RenderTextToAlphamaps(GX_WIDGET * widget)239 VOID RenderTextToAlphamaps(GX_WIDGET *widget)
240 {
241 GX_FONT *font;
242 GX_CONST GX_CHAR string_hello_world[] = "Hello World";
243 GX_CONST GX_CHAR string_4bpp_font[] = "4 bpp font";
244 GX_CONST GX_CHAR string_1bpp_font[] = "1 bpp font";
245 GX_STRING string;
246
247
248 gx_widget_font_get(widget, GX_FONT_ID_SCREEN_LABEL, &font);
249 string.gx_string_ptr = string_hello_world;
250 string.gx_string_length = sizeof(string_hello_world) - 1;
251 gx_utility_string_to_alphamap_ext(&string, font, &Alphamap_8bit_font);
252
253 // KGM: Add these once done in gx_utility
254
255 gx_widget_font_get(widget, GX_FONT_ID_SMALL_BOLD, &font);
256 string.gx_string_ptr = string_4bpp_font;
257 string.gx_string_length = sizeof(string_4bpp_font) - 1;
258 gx_utility_string_to_alphamap_ext(&string, font, &Alphamap_4bit_font);
259
260 gx_widget_font_get(widget, GX_FONT_ID_MONO_FONT, &font);
261 string.gx_string_ptr = string_1bpp_font;
262 string.gx_string_length = sizeof(string_1bpp_font) - 1;
263 gx_utility_string_to_alphamap_ext(&string, font, &Alphamap_1bit_font);
264 }
265
text_window_draw(GX_WINDOW * window)266 void text_window_draw(GX_WINDOW *window)
267 {
268 INT xpos = 0;
269 INT ypos = 0;
270 GX_PIXELMAP rotated_text;
271 GX_PIXELMAP *source_map = GX_NULL;
272 GX_STRING string;
273
274 gx_window_draw(window);
275
276 gx_context_line_color_set(text_color);
277 gx_context_fill_color_set(text_color);
278
279 switch (window->gx_widget_id)
280 {
281 case TEXT_WIN_8BPP:
282 source_map = &Alphamap_8bit_font;
283 break;
284
285 case TEXT_WIN_4BPP:
286 source_map = &Alphamap_4bit_font;
287 break;
288
289 case TEXT_WIN_1BPP:
290 source_map = &Alphamap_1bit_font;
291 break;
292 }
293
294 if (source_map)
295 {
296 if(gx_utility_pixelmap_rotate(source_map, text_angle, &rotated_text, &xpos, &ypos) == GX_SUCCESS)
297 {
298 xpos = (window->gx_widget_size.gx_rectangle_left + window->gx_widget_size.gx_rectangle_right) / 2;
299 ypos = (window->gx_widget_size.gx_rectangle_top + window->gx_widget_size.gx_rectangle_bottom) / 2;
300 xpos -= rotated_text.gx_pixelmap_width / 2;
301 ypos -= rotated_text.gx_pixelmap_height / 2;
302
303 gx_canvas_pixelmap_draw(xpos, ypos, &rotated_text);
304 memory_free((VOID *) rotated_text.gx_pixelmap_data);
305 }
306 }
307 else
308 {
309 xpos = (window->gx_widget_size.gx_rectangle_left + window->gx_widget_size.gx_rectangle_right) / 2;
310 ypos = (window->gx_widget_size.gx_rectangle_top + window->gx_widget_size.gx_rectangle_bottom) / 2;
311 gx_context_font_set(GX_FONT_ID_SMALL_BOLD);
312 gx_utility_ltoa(dynamic_count, dynamic_text, 20);
313 string.gx_string_ptr = dynamic_text;
314 string.gx_string_length = strnlen(dynamic_text, sizeof(dynamic_text));
315 gx_canvas_rotated_text_draw_ext(&string, xpos, ypos, text_angle);
316 }
317 }
318
319 /* Define prototypes. */
page_button_draw(GX_PIXELMAP_BUTTON * widget)320 VOID page_button_draw(GX_PIXELMAP_BUTTON *widget)
321 {
322 GX_PIXELMAP *map;
323 INT top;
324 INT left;
325 GX_BOOL draw_selected;
326
327 left = widget->gx_widget_size.gx_rectangle_left;
328 top = widget->gx_widget_size.gx_rectangle_top;
329
330 if (widget->gx_widget_style & GX_STYLE_BUTTON_PUSHED)
331 {
332 top += 3;
333 draw_selected = GX_TRUE;
334 }
335 else
336 {
337 draw_selected = GX_FALSE;
338 }
339
340 if (draw_selected)
341 {
342 gx_widget_pixelmap_get(widget, GX_PIXELMAP_ID_BUTTON_ACTIVE, &map);
343 gx_context_fill_color_set(GX_COLOR_ID_WHITE);
344 gx_context_line_color_set(GX_COLOR_ID_WHITE);
345 }
346 else
347 {
348 gx_widget_pixelmap_get(widget, GX_PIXELMAP_ID_BUTTON, &map);
349 gx_context_fill_color_set(GX_COLOR_ID_LIGHT_GRAY);
350 gx_context_line_color_set(GX_COLOR_ID_LIGHT_GRAY);
351 }
352
353 gx_canvas_pixelmap_draw(left, top, map);
354 }
355