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_332rgb_resources.h"
6 #include "all_widgets_332rgb_specifications.h"
7 
8 GX_UBYTE          alpha_value = 255;
9 GX_BOOL           sprite_move_down = GX_TRUE;
10 extern GX_WINDOW *pSpriteScreen;
11 extern VOID        memory_free(VOID *mem);
12 GX_RESOURCE_ID     map_id = GX_PIXELMAP_ID_ROTATE_APPLE;
13 
14 void move_sprite(void);
15 
16 
17 
sprite_event_handler(GX_WINDOW * window,GX_EVENT * event_ptr)18 UINT sprite_event_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
19 {
20     switch (event_ptr->gx_event_type)
21     {
22     case GX_SIGNAL(ID_ALPHA_SLIDER, GX_EVENT_SLIDER_VALUE):
23         alpha_value = (GX_UBYTE)event_ptr->gx_event_payload.gx_event_longdata;
24         gx_system_dirty_mark(&((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_apple_window);
25         break;
26 
27     case GX_SIGNAL(ID_BIRD_SPRITE, GX_EVENT_SPRITE_COMPLETE):
28         gx_widget_hide(&((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_sprite);
29         move_sprite();
30         gx_widget_show(&((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_sprite);
31         break;
32     default:
33         return next_button_handler(window, event_ptr);
34     }
35 
36     return 0;
37 }
38 
move_sprite(void)39 void move_sprite(void)
40 {
41     GX_RECTANGLE size;
42     GX_SPRITE *sprite = &((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_sprite;
43 
44     size = sprite->gx_widget_size;
45 
46     if (sprite_move_down)
47     {
48         gx_utility_rectangle_shift(&size, 100, 117);
49         sprite_move_down = GX_FALSE;
50     }
51     else
52     {
53         gx_utility_rectangle_shift(&size, 100, -57);
54         sprite_move_down = GX_TRUE;
55     }
56     if (size.gx_rectangle_bottom > pSpriteScreen->gx_widget_size.gx_rectangle_bottom)
57     {
58         size.gx_rectangle_top -= pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
59         size.gx_rectangle_bottom -= pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
60     }
61     if (size.gx_rectangle_top < pSpriteScreen->gx_widget_size.gx_rectangle_top)
62     {
63         size.gx_rectangle_top += pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
64         size.gx_rectangle_bottom += pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
65     }
66 
67 
68     if (size.gx_rectangle_right > pSpriteScreen->gx_widget_size.gx_rectangle_right)
69     {
70         size.gx_rectangle_left -= pSpriteScreen->gx_widget_size.gx_rectangle_right;
71         size.gx_rectangle_right -= pSpriteScreen->gx_widget_size.gx_rectangle_right;
72     }
73     gx_widget_resize(sprite, &size);
74 }
75 
apple_window_draw(GX_WINDOW * window)76 VOID apple_window_draw(GX_WINDOW *window)
77 {
78     GX_PIXELMAP *map;
79     GX_PIXELMAP scaled_map;
80     int         width;
81     int         height;
82     int         xpos;
83     int         ypos;
84 
85     gx_context_pixelmap_get(map_id, &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             memory_free((VOID *)scaled_map.gx_pixelmap_data);
108         }
109 
110         if (scaled_map.gx_pixelmap_aux_data)
111         {
112             memory_free((VOID *)scaled_map.gx_pixelmap_aux_data);
113         }
114     }
115 
116 }