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_4444argb_resources.h"
6 #include "all_widgets_4444argb_specifications.h"
7 
8 GX_UBYTE          alpha_value = 255;
9 GX_BOOL           sprite_move_down = GX_TRUE;
10 GX_RESOURCE_ID    apple_window_pixelmap_id = GX_PIXELMAP_ID_RED_APPLE;
11 extern GX_WINDOW *pSpriteScreen;
12 extern VOID       memory_free(VOID *mem);
13 
14 void move_sprite(void);
15 
16 
sprite_event_handler(GX_WINDOW * window,GX_EVENT * event_ptr)17 UINT sprite_event_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
18 {
19     switch (event_ptr->gx_event_type)
20     {
21     case GX_SIGNAL(ID_ALPHA_SLIDER, GX_EVENT_SLIDER_VALUE):
22         alpha_value = (GX_UBYTE)event_ptr->gx_event_payload.gx_event_longdata;
23         gx_system_dirty_mark(&((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_apple_window);
24         break;
25 
26     case GX_SIGNAL(ID_BIRD_SPRITE, GX_EVENT_SPRITE_COMPLETE):
27         gx_widget_hide(&((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_sprite);
28         move_sprite();
29         gx_widget_show(&((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_sprite);
30         break;
31     default:
32         return next_button_handler(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;
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(apple_window_pixelmap_id, &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             memory_free((VOID *)scaled_map.gx_pixelmap_data);
107         }
108     }
109 }