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