1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 
13 /* Include necessary system files. */
14 #include "gx_api.h"
15 
16 /* Define constants for the GUIX Win32 demo.  */
17 
18 /* Define the display dimentions specific to this implemenation.  */
19 #define DEMO_DISPLAY_WIDTH                         320
20 #define DEMO_DISPLAY_HEIGHT                        240
21 
22 /* Define the number of pixels on the canvas */
23 #define DEFAULT_CANVAS_PIXELS     (DEMO_DISPLAY_WIDTH * DEMO_DISPLAY_HEIGHT)
24 
25 /* Define the ThreadX demo thread control block. */
26 TX_THREAD          demo_thread;
27 
28 /* Define the stack for the demo thread. */
29 ULONG              demo_thread_stack[4096 / sizeof(ULONG)];
30 
31 /* Define the GUIX resources for this demo.  */
32 
33 /* GUIX display represents the physical display device */
34 GX_DISPLAY        demo_display;
35 
36 /* GUIX canvas is the frame buffer on top of GUIX displayl. */
37 GX_CANVAS         default_canvas;
38 
39 /* The root window is a special GUIX background window, right on top of the canvas. */
40 GX_WINDOW_ROOT    demo_root_window;
41 
42 /* GUIX Prompt displays a string. */
43 GX_PROMPT         demo_prompt;
44 
45 /* Memory for the frame buffer. */
46 GX_COLOR default_canvas_memory[DEFAULT_CANVAS_PIXELS];
47 
48 
49 /* Define GUIX strings ID for the demo. */
50 enum demo_string_ids
51 {
52     SID_HELLO_WORLD = 1,
53     SID_MAX
54 };
55 
56 static GX_CONST GX_CHAR string_hello_world[] = "Hello World";
57 
58 /* Define GUIX string for the demo. */
59 GX_CONST GX_STRING demo_strings[] = {
60     {NULL, 0},
61     {string_hello_world, sizeof(string_hello_world) - 1}
62 };
63 
64 /* Define Language table. */
65 GX_CONST GX_STRING *language_table[1] =
66 {
67     demo_strings,
68 };
69 
70 /* User-defined color ID */
71 #define GX_COLOR_ID_BLACK     GX_FIRST_USER_COLOR
72 #define GX_COLOR_ID_WHITE     (GX_FIRST_USER_COLOR + 1)
73 
74 /* Define the default theme colors.   */
75 
76 #define GX_COLOR_CANVAS                     GX_COLOR_BLACK
77 #define GX_COLOR_WIDGET_FILL                0x00787c78
78 #define GX_COLOR_WINDOW_FILL                0x00e2e2e2
79 #define GX_COLOR_STANDARD_BORDER            0x009b9b73
80 #define GX_COLOR_WINDOW_BORDER              0x007599aa
81 #define GX_COLOR_NORMAL_TEXT                GX_COLOR_BLACK
82 #define GX_COLOR_SELECTED_TEXT              GX_COLOR_WHITE
83 #define GX_COLOR_SELECTED_FILL              GX_COLOR_BLUE
84 
85 #define GX_COLOR_SHADOW                     GX_COLOR_DARKGRAY
86 #define GX_COLOR_SHINE                      0x00dadada
87 
88 #define GX_COLOR_BUTTON_BORDER              0x00e0c060
89 #define GX_COLOR_BUTTON_UPPER               0x00f8f8e0
90 #define GX_COLOR_BUTTON_LOWER               0x00f8ecb0
91 #define GX_COLOR_BUTTON_TEXT                GX_COLOR_BLACK
92 
93 #define GX_COLOR_SCROLL_FILL                0x00e8d8f8
94 #define GX_COLOR_SCROLL_BUTTON              0x00e8ccb0
95 #define GX_COLOR_TEXT_INPUT_TEXT            GX_COLOR_BLACK
96 #define GX_COLOR_TEXT_INPUT_FILL            GX_COLOR_WHITE
97 
98 #define GX_COLOR_SLIDER_TICK                GX_COLOR_BLACK
99 #define GX_COLOR_SLIDER_GROOVE_TOP          GX_COLOR_LIGHTGRAY
100 #define GX_COLOR_SLIDER_GROOVE_BOTTOM       GX_COLOR_WHITE
101 #define GX_COLOR_SLIDER_NEEDLE_OUTLINE      GX_COLOR_BLACK
102 #define GX_COLOR_SLIDER_NEEDLE_FILL         GX_COLOR_DARKGRAY
103 #define GX_COLOR_SLIDER_NEEDLE_LINE1        GX_COLOR_LIGHTGRAY
104 #define GX_COLOR_SLIDER_NEEDLE_LINE2        GX_COLOR_BUTTON_BORDER
105 
106 #define GX_SYSTEM_DEFAULT_COLORS_DECLARE \
107     GX_COLOR_CANVAS,                     \
108     GX_COLOR_WIDGET_FILL,                \
109     GX_COLOR_WINDOW_FILL,                \
110     GX_COLOR_STANDARD_BORDER,            \
111     GX_COLOR_WINDOW_BORDER,              \
112     GX_COLOR_NORMAL_TEXT,                \
113     GX_COLOR_SELECTED_TEXT,              \
114     GX_COLOR_SELECTED_FILL,              \
115     GX_COLOR_SHADOW,                     \
116     GX_COLOR_SHINE,                      \
117     GX_COLOR_BUTTON_BORDER,              \
118     GX_COLOR_BUTTON_UPPER,               \
119     GX_COLOR_BUTTON_LOWER,               \
120     GX_COLOR_BUTTON_TEXT,                \
121     GX_COLOR_SCROLL_FILL,                \
122     GX_COLOR_SCROLL_BUTTON,              \
123     GX_COLOR_TEXT_INPUT_TEXT,            \
124     GX_COLOR_TEXT_INPUT_FILL,            \
125     GX_COLOR_SLIDER_TICK,                \
126     GX_COLOR_SLIDER_GROOVE_TOP,          \
127     GX_COLOR_SLIDER_GROOVE_BOTTOM,       \
128     GX_COLOR_SLIDER_NEEDLE_OUTLINE,      \
129     GX_COLOR_SLIDER_NEEDLE_FILL,         \
130     GX_COLOR_SLIDER_NEEDLE_LINE1,        \
131     GX_COLOR_SLIDER_NEEDLE_LINE2
132 
133 /* User-defined color table. */
134 static GX_COLOR demo_color_table[] =
135 {
136     /* First, bring in GUIX default color table.  These colors are used
137        by GUIX internals. */
138     GX_SYSTEM_DEFAULT_COLORS_DECLARE,
139 
140     /* In this demo, two color entries are added to the color table. */
141     GX_COLOR_BLACK,
142     GX_COLOR_WHITE
143 };
144 
145 /* Font Table                                                                  */
146 
147 
148 extern GX_FONT _gx_system_font_8bpp;
149 GX_FONT *demo_font_table[] =
150 {
151     &_gx_system_font_8bpp,
152     &_gx_system_font_8bpp,
153     &_gx_system_font_8bpp,
154     &_gx_system_font_8bpp
155 };
156 
157 
158 /* Define prototypes.   */
159 
160 VOID  demo_thread_entry(ULONG thread_input);
161 
162 
163 /* Prototype for the win32 screen driver setup routine. */
164 extern UINT  win32_graphics_driver_setup_24xrgb(GX_DISPLAY *graphic);
165 
main(int argc,char ** argv)166 int main(int argc, char ** argv)
167 {
168 
169     tx_kernel_enter();
170 
171     return (0);
172 }
173 
174 
175 
tx_application_define(void * first_unused_memory)176 VOID tx_application_define(void *first_unused_memory)
177 {
178 
179     /* Create the main demo thread.  */
180     tx_thread_create(&demo_thread, "GUIX Demo Thread", demo_thread_entry, 0,
181                      demo_thread_stack, sizeof(demo_thread_stack),
182                      1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
183 }
184 
demo_thread_entry(ULONG thread_input)185 VOID  demo_thread_entry(ULONG thread_input)
186 {
187 
188 GX_RECTANGLE    root_window_size;
189 GX_RECTANGLE    prompt_position;
190 
191     /* Initialize GUIX.  */
192     gx_system_initialize();
193 
194     /* Create the demo display and associated driver.  */
195     gx_display_create(&demo_display, "demo display", win32_graphics_driver_setup_24xrgb,
196                       DEMO_DISPLAY_WIDTH, DEMO_DISPLAY_HEIGHT);
197 
198     /* Install the demo color table. */
199     gx_display_color_table_set(&demo_display, demo_color_table, sizeof(demo_color_table) / sizeof(GX_COLOR));
200 
201     /* Install the demo font table. */
202     gx_display_font_table_set(&demo_display, demo_font_table, sizeof(demo_font_table) / sizeof(GX_FONT *));
203 
204     /* Create the default canvas. */
205     gx_canvas_create(&default_canvas, "demo canvas", &demo_display,
206                      GX_CANVAS_MANAGED | GX_CANVAS_VISIBLE,
207                      DEMO_DISPLAY_WIDTH, DEMO_DISPLAY_HEIGHT,
208                      default_canvas_memory, sizeof(default_canvas_memory));
209 
210 
211     /*Define the size of the root window. */
212     gx_utility_rectangle_define(&root_window_size, 0, 0, DEMO_DISPLAY_WIDTH - 1, DEMO_DISPLAY_HEIGHT - 1);
213 
214     /* Create a background root window and attach to the canvas. */
215     gx_window_root_create(&demo_root_window, "demo root window", &default_canvas,
216                           GX_STYLE_BORDER_NONE, GX_ID_NONE, &root_window_size);
217 
218     /* Set language table.  */
219     gx_display_language_table_set_ext(demo_root_window.gx_window_root_canvas->gx_canvas_display, language_table, 1, SID_MAX);
220     gx_system_active_language_set(0);
221 
222     /* Set the root window to be black */
223     gx_widget_fill_color_set(&demo_root_window, GX_COLOR_ID_BLACK, GX_COLOR_ID_BLACK, GX_COLOR_ID_BLACK);
224 
225     /* Create a text prompt on the root window.  Set the text color to white, and the background to black. */
226 
227     /* Define the size and the position of the prompt. */
228     gx_utility_rectangle_define(&prompt_position, 100, 90, 220, 130);
229 
230     /* Create the prompt on top of the root window using the string defined by string ID SID_HELLO_WORLD */
231     gx_prompt_create(&demo_prompt, NULL, &demo_root_window, SID_HELLO_WORLD, GX_STYLE_NONE, GX_ID_NONE, &prompt_position);
232 
233     /* Set the text color to be white, and the background color to be black. */
234     gx_prompt_text_color_set(&demo_prompt, GX_COLOR_ID_WHITE, GX_COLOR_ID_WHITE, GX_COLOR_ID_WHITE);
235 
236     gx_widget_fill_color_set(&demo_prompt, GX_COLOR_ID_BLACK, GX_COLOR_ID_BLACK, GX_COLOR_ID_BLACK);
237 
238     /* Show the root window.  */
239     gx_widget_show(&demo_root_window);
240 
241     /* let GUIX run */
242     gx_system_start();
243 }
244