1 /* This is a small demo of the high-performance GUIX graphics framework. */
2 
3 #include <stdio.h>
4 #include "gx_api.h"
5 
6 #include "sprite_16bpp_resources.h"
7 #include "sprite_16bpp_specifications.h"
8 
9 /* Define the ThreadX demo thread control block and stack.  */
10 MAIN_WINDOW_CONTROL_BLOCK *pMainWin;
11 GX_WINDOW *pAppleWin;
12 
13 TX_THREAD          demo_thread;
14 UCHAR              demo_thread_stack[4096];
15 
16 GX_WINDOW_ROOT    *root;
17 GX_UBYTE          alpha_value = 255;
18 
19 TX_THREAD         demo_thread;
20 UCHAR             demo_thread_stack[4096];
21 TX_BYTE_POOL      resize_pool;
22 
23 #define           SCRATCHPAD_PIXELS (DISPLAY_1_X_RESOLUTION * DISPLAY_1_Y_RESOLUTION)
24 GX_COLOR          scratchpad[SCRATCHPAD_PIXELS];
25 
26 /* Define prototypes.   */
27 VOID  start_guix();
28 
29 #define USE_16BPP
30 
31 #ifdef USE_16BPP
32 extern UINT win32_graphics_driver_setup_565rgb(GX_DISPLAY *display);
33 #else
34 extern UINT win32_graphics_driver_setup_24xrgb(GX_DISPLAY *display);
35 #endif
36 
resize_memory_allocate(ULONG size)37 VOID *resize_memory_allocate(ULONG size)
38 {
39     VOID *memptr;
40 
41     if (tx_byte_allocate(&resize_pool, &memptr, size, TX_NO_WAIT) == TX_SUCCESS)
42     {
43         return memptr;
44     }
45     return NULL;
46 }
47 
resize_memory_free(VOID * mem)48 void resize_memory_free(VOID *mem)
49 {
50     tx_byte_release(mem);
51 }
52 
main(int argc,char ** argv)53 int main(int argc, char ** argv)
54 {
55     tx_kernel_enter();
56     return(0);
57 }
58 
tx_application_define(void * first_unused_memory)59 VOID tx_application_define(void *first_unused_memory)
60 {
61 
62     /* create byte pool for resize to use */
63     tx_byte_pool_create(&resize_pool, "scratchpad", scratchpad,
64         SCRATCHPAD_PIXELS * sizeof(GX_COLOR));
65 
66     start_guix();
67 
68     /* install our memory allocator and de-allocator */
69     gx_system_memory_allocator_set(resize_memory_allocate, resize_memory_free);
70 }
71 
72 
start_guix()73 VOID  start_guix()
74 {
75     /* Initialize GUIX.  */
76     gx_system_initialize();
77 
78     #ifdef USE_16BPP
79     gx_studio_display_configure(DISPLAY_1, win32_graphics_driver_setup_565rgb,
80                                 LANGUAGE_ENGLISH, DISPLAY_1_DEFAULT_THEME, &root);
81     #else
82     gx_studio_display_configure(DISPLAY_1, win32_graphics_driver_setup_24xrgb,
83                                 LANGUAGE_ENGLISH, DISPLAY_1_DEFAULT_THEME, &root);
84     #endif
85 
86     /* create the main screen */
87     gx_studio_named_widget_create("main_window", (GX_WIDGET *) root, (GX_WIDGET **) &pMainWin);
88 
89     pAppleWin = &pMainWin -> main_window_AppleWindow;
90 
91     gx_widget_show(root);
92 
93     /* let GUIX run */
94     gx_system_start();
95 }
96 
DisplayNewAlphaValue(GX_WINDOW * parent)97 void DisplayNewAlphaValue(GX_WINDOW *parent)
98 {
99     GX_PROMPT *prompt;
100     static GX_CHAR number_val[10];
101     GX_STRING string;
102 
103     gx_widget_find(parent, ID_ALPHA_DISPLAY, 1, &prompt);
104     gx_utility_ltoa(alpha_value, number_val, 10);
105     string.gx_string_ptr = number_val;
106     string.gx_string_length = strnlen(number_val, sizeof(number_val));
107     gx_prompt_text_set_ext(prompt, &string);
108 }
109 
MainWindowEventProcess(GX_WINDOW * window,GX_EVENT * myevent)110 UINT MainWindowEventProcess(GX_WINDOW *window, GX_EVENT *myevent)
111 {
112     UINT status = 0;
113 
114     switch(myevent->gx_event_type)
115     {
116     case GX_SIGNAL(ID_ALPHA_SLIDER, GX_EVENT_SLIDER_VALUE):
117         alpha_value = (GX_UBYTE)  myevent->gx_event_payload.gx_event_longdata;
118         DisplayNewAlphaValue(window);
119         gx_system_dirty_mark(&main_window.main_window_AppleWindow);
120         break;
121 
122     default:
123         status = gx_window_event_process(window, myevent);
124         break;
125     }
126     return status;
127 }
128 
AppleWindowDraw(GX_WINDOW * window)129 VOID AppleWindowDraw(GX_WINDOW *window)
130 {
131     GX_PIXELMAP *map;
132     GX_PIXELMAP scaled_map;
133     int width;
134     int height;
135     int xpos;
136     int ypos;
137 
138     gx_context_pixelmap_get(GX_PIXELMAP_ID_RED_APPLE, &map);
139 
140     width = (alpha_value * map->gx_pixelmap_width) >> 8;
141     height = (alpha_value * map->gx_pixelmap_height) >> 8;
142 
143 	if((width == 0) || (height == 0))
144 	{
145 	    return;
146 	}
147 
148     if (gx_utility_pixelmap_resize(map, &scaled_map, width, height) == GX_SUCCESS)
149     {
150         xpos = window->gx_widget_size.gx_rectangle_left;
151         ypos = window->gx_widget_size.gx_rectangle_top;
152 
153         xpos += (map->gx_pixelmap_width - width) >> 1;
154         ypos += (map->gx_pixelmap_height - height) >> 1;
155 
156         gx_canvas_pixelmap_blend(xpos, ypos, &scaled_map, alpha_value);
157 
158         if (scaled_map.gx_pixelmap_data)
159         {
160             resize_memory_free((VOID *)scaled_map.gx_pixelmap_data);
161         }
162 
163         if (scaled_map.gx_pixelmap_aux_data)
164         {
165             resize_memory_free((VOID *)scaled_map.gx_pixelmap_aux_data);
166         }
167     }
168 
169 }
170 
171 
172