1 /* This is a small demo of the high-performance GUIX graphics framework. */
2
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "gx_api.h"
6 #include "all_widgets_5_4_1_resources.h"
7 #include "all_widgets_5_4_1_specifications.h"
8
9 GX_UBYTE alpha_value = 255;
10 GX_BOOL sprite_move_down = GX_TRUE;
11 extern GX_WINDOW *pSpriteScreen;
12
13 VOID rotate_memory_free(VOID *mem);
14 void move_sprite(void);
15
sprite_event_handler(GX_WINDOW * window,GX_EVENT * event_ptr)16 UINT sprite_event_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
17 {
18 switch (event_ptr->gx_event_type)
19 {
20 case GX_SIGNAL(ID_ALPHA_SLIDER, GX_EVENT_SLIDER_VALUE):
21 alpha_value = (GX_UBYTE)event_ptr->gx_event_payload.gx_event_longdata;
22 gx_system_dirty_mark(&((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_apple_window);
23 break;
24
25 case GX_SIGNAL(ID_BIRD_SPRITE, GX_EVENT_SPRITE_COMPLETE):
26 gx_widget_hide(&((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_sprite_1);
27 move_sprite();
28 gx_widget_show(&((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_sprite_1);
29 break;
30
31 default:
32 return gx_window_event_process(window, event_ptr);
33 }
34
35 return 0;
36 }
37
move_sprite(void)38 void move_sprite(void)
39 {
40 GX_RECTANGLE size;
41 GX_SPRITE *sprite = &((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_sprite_1;
42
43 size = sprite->gx_widget_size;
44
45 if (sprite_move_down)
46 {
47 gx_utility_rectangle_shift(&size, 100, 117);
48 sprite_move_down = GX_FALSE;
49 }
50 else
51 {
52 gx_utility_rectangle_shift(&size, 100, -57);
53 sprite_move_down = GX_TRUE;
54 }
55 if (size.gx_rectangle_bottom > pSpriteScreen->gx_widget_size.gx_rectangle_bottom)
56 {
57 size.gx_rectangle_top -= pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
58 size.gx_rectangle_bottom -= pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
59 }
60 if (size.gx_rectangle_top < pSpriteScreen->gx_widget_size.gx_rectangle_top)
61 {
62 size.gx_rectangle_top += pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
63 size.gx_rectangle_bottom += pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
64 }
65
66
67 if (size.gx_rectangle_right > pSpriteScreen->gx_widget_size.gx_rectangle_right)
68 {
69 size.gx_rectangle_left -= pSpriteScreen->gx_widget_size.gx_rectangle_right;
70 size.gx_rectangle_right -= pSpriteScreen->gx_widget_size.gx_rectangle_right;
71 }
72 gx_widget_resize(sprite, &size);
73 }
74
apple_window_draw(GX_WINDOW * window)75 VOID apple_window_draw(GX_WINDOW *window)
76 {
77 GX_PIXELMAP *map;
78 GX_PIXELMAP scaled_map;
79 int width;
80 int height;
81 int xpos;
82 int ypos;
83
84 gx_context_pixelmap_get(GX_PIXELMAP_ID_RED_APPLE, &map);
85
86 width = (alpha_value * map->gx_pixelmap_width) >> 8;
87 height = (alpha_value * map->gx_pixelmap_height) >> 8;
88
89 if ((width == 0) || (height == 0))
90 {
91 return;
92 }
93
94 if (gx_utility_pixelmap_resize(map, &scaled_map, width, height) == GX_SUCCESS)
95 {
96 xpos = window->gx_widget_size.gx_rectangle_left;
97 ypos = window->gx_widget_size.gx_rectangle_top;
98
99 xpos += (map->gx_pixelmap_width - width) >> 1;
100 ypos += (map->gx_pixelmap_height - height) >> 1;
101
102 gx_canvas_pixelmap_blend(xpos, ypos, &scaled_map, alpha_value);
103
104 if (scaled_map.gx_pixelmap_data)
105 {
106 rotate_memory_free((VOID *)scaled_map.gx_pixelmap_data);
107 }
108 }
109 }