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