1 /* This is a small demo of the high-performance GUIX graphics framework. */
2 
3 #include <stdio.h>
4 #include "all_widgets_4bpp_resources.h"
5 #include "all_widgets_4bpp_specifications.h"
6 
7 GX_UBYTE          alpha_value = 255;
8 GX_BOOL           sprite_move_down = GX_TRUE;
9 extern GX_WINDOW *pSpriteScreen;
10 extern VOID        memory_free(VOID *mem);
11 
12 void move_sprite(void);
13 
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         move_sprite();
26         gx_sprite_start(&sprite_screen.sprite_screen_sprite, 0);
27         break;
28     default:
29         return next_button_handler(window, event_ptr);
30     }
31 
32     return 0;
33 }
34 
move_sprite(void)35 void move_sprite(void)
36 {
37     GX_RECTANGLE size;
38     GX_SPRITE *sprite = &((SPRITE_SCREEN_CONTROL_BLOCK *)pSpriteScreen)->sprite_screen_sprite;
39 
40     size = sprite->gx_widget_size;
41 
42     if (sprite_move_down)
43     {
44         gx_utility_rectangle_shift(&size, 100, 117);
45         sprite_move_down = GX_FALSE;
46     }
47     else
48     {
49         gx_utility_rectangle_shift(&size, 100, -57);
50         sprite_move_down = GX_TRUE;
51     }
52     if (size.gx_rectangle_bottom > pSpriteScreen->gx_widget_size.gx_rectangle_bottom)
53     {
54         size.gx_rectangle_top -= pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
55         size.gx_rectangle_bottom -= pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
56     }
57     if (size.gx_rectangle_top < pSpriteScreen->gx_widget_size.gx_rectangle_top)
58     {
59         size.gx_rectangle_top += pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
60         size.gx_rectangle_bottom += pSpriteScreen->gx_widget_size.gx_rectangle_bottom;
61     }
62 
63 
64     if (size.gx_rectangle_right > pSpriteScreen->gx_widget_size.gx_rectangle_right)
65     {
66         size.gx_rectangle_left -= pSpriteScreen->gx_widget_size.gx_rectangle_right;
67         size.gx_rectangle_right -= pSpriteScreen->gx_widget_size.gx_rectangle_right;
68     }
69     gx_widget_resize(sprite, &size);
70 }
71 
apple_window_draw(GX_WINDOW * window)72 VOID apple_window_draw(GX_WINDOW *window)
73 {
74     GX_PIXELMAP *map;
75     GX_PIXELMAP scaled_map;
76     int         width;
77     int         height;
78     int         xpos;
79     int         ypos;
80 
81     gx_context_pixelmap_get(GX_PIXELMAP_ID_RED_APPLE, &map);
82 
83     width = (alpha_value * map->gx_pixelmap_width) >> 8;
84     height = (alpha_value * map->gx_pixelmap_height) >> 8;
85 
86     if ((width == 0) || (height == 0))
87     {
88         return;
89     }
90 
91     if (gx_utility_pixelmap_resize(map, &scaled_map, width, height) == GX_SUCCESS)
92     {
93         xpos = window->gx_widget_size.gx_rectangle_left;
94         ypos = window->gx_widget_size.gx_rectangle_top;
95 
96         xpos += (map->gx_pixelmap_width - width) >> 1;
97         ypos += (map->gx_pixelmap_height - height) >> 1;
98 
99         gx_canvas_pixelmap_draw(xpos, ypos, &scaled_map);
100 
101         if (scaled_map.gx_pixelmap_data)
102         {
103             memory_free((VOID *)scaled_map.gx_pixelmap_data);
104         }
105 
106         if (scaled_map.gx_pixelmap_aux_data)
107         {
108             memory_free((VOID *)scaled_map.gx_pixelmap_aux_data);
109         }
110     }
111 }
112