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 "lines_resources.h"
7 #include "lines_specifications.h"
8
9
10 #define DROP_LIST_VISIBLE_ROWS 5
11 #define LINE_WINDOW_LINE_LENGTH 80
12 #define LINE_CENTER_X_OFFSET 159
13 #define LINE_CENTER_Y_OFFSET 159
14
15 #define MAX_COLOR_TEXT_LENGTH 10
16
17 MAIN_WINDOW_CONTROL_BLOCK *pMainWin;
18 GX_WINDOW *pLineWin;
19 int line_angle = 0;
20 int line_width = 1;
21 GX_BOOL anti_aliased = GX_FALSE;
22 GX_BOOL rounded = GX_FALSE;
23 GX_RESOURCE_ID line_color = GX_COLOR_ID_CANVAS;
24 int line_x1;
25 int line_x2;
26 int line_y1;
27 int line_y2;
28
29 typedef struct COLOR_LIST_STRUCT{
30 GX_CHAR color[MAX_COLOR_TEXT_LENGTH + 1] ;
31 GX_RESOURCE_ID color_id ;
32 }COLOR_LIST;
33
34 COLOR_LIST color_list[] = {
35 { "BLACK", GX_COLOR_ID_CANVAS },
36 { "WHITE", GX_COLOR_ID_SELECTED_TEXT },
37 { "ORANGE", GX_COLOR_ID_SCROLL_BUTTON },
38 { "YELLOW", GX_COLOR_ID_BTN_LOWER },
39 { "LIGHTGRAY", GX_COLOR_ID_TEXT_INPUT_FILL }
40 };
41
42 GX_PROMPT drop_list_widgets[DROP_LIST_VISIBLE_ROWS + 1];
43 GX_SCROLLBAR list_scroll;
44 GX_UBYTE brush_alpha = 255;
45
46 #define LINE_LENGTH 100
47
48 /* Define the ThreadX demo thread control block and stack. */
49
50 GX_WINDOW_ROOT *root;
51
52 /* Define prototypes. */
53 VOID PopulateDropList(void);
54 VOID start_guix(VOID);
55 extern UINT win32_graphics_driver_setup_24xrgb(GX_DISPLAY *display);
56 UINT string_length_get(GX_CONST GX_CHAR* input_string, UINT max_string_length);
57
main(int argc,char ** argv)58 int main(int argc, char ** argv)
59 {
60 tx_kernel_enter();
61 return(0);
62 }
63
64
tx_application_define(void * first_unused_memory)65 VOID tx_application_define(void *first_unused_memory)
66 {
67 start_guix();
68 }
69
70
start_guix(VOID)71 VOID start_guix(VOID)
72 {
73 /* Initialize GUIX. */
74 gx_system_initialize();
75
76
77 gx_studio_display_configure(DISPLAY_1, win32_graphics_driver_setup_24xrgb,
78 LANGUAGE_ENGLISH, DISPLAY_1_DEFAULT_THEME, &root);
79
80 /* create the main screen */
81 gx_studio_named_widget_create("main_window", (GX_WIDGET *) root, (GX_WIDGET **) &pMainWin);
82 PopulateDropList();
83
84 /* get a pointer to line window */
85 pLineWin = &pMainWin->main_window_line_window;
86
87 /* Show the root window to make it and patients screen visible. */
88 gx_widget_show(root);
89
90 /* start GUIX thread */
91 gx_system_start();
92 }
93
calculate_line_ends(VOID)94 VOID calculate_line_ends(VOID)
95 {
96 GX_FIXED_VAL scaled_angle;
97 INT x_dist;
98 INT y_dist;
99
100 INT x_center = pLineWin->gx_widget_size.gx_rectangle_left + LINE_CENTER_X_OFFSET;
101 INT y_center = pLineWin->gx_widget_size.gx_rectangle_top + LINE_CENTER_Y_OFFSET;
102
103 scaled_angle = GX_FIXED_VAL_MAKE(line_angle);
104 x_dist = gx_utility_math_cos(scaled_angle) * LINE_LENGTH;
105 y_dist = gx_utility_math_sin(scaled_angle) * LINE_LENGTH;
106 x_dist = GX_FIXED_VAL_TO_INT(x_dist);
107 y_dist = GX_FIXED_VAL_TO_INT(y_dist);
108
109 line_x1 = x_center - x_dist;
110 line_x2 = x_center + x_dist;
111 line_y1 = y_center - y_dist;
112 line_y2 = y_center + y_dist;
113 }
114
update_prompt(GX_RESOURCE_ID id,INT value)115 VOID update_prompt(GX_RESOURCE_ID id, INT value)
116 {
117 GX_PROMPT *pp;
118 static GX_CHAR val[10];
119 GX_STRING string;
120
121 gx_widget_find(pMainWin, (USHORT)id, 0, &pp);
122
123 if (pp)
124 {
125 gx_utility_ltoa(value, val, 10);
126 string.gx_string_ptr = val;
127 string.gx_string_length = string_length_get(val, sizeof(val) - 1);
128 gx_prompt_text_set_ext(pp, &string);
129 }
130 }
131
main_event_handler(GX_WINDOW * window,GX_EVENT * myevent)132 UINT main_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
133 {
134 UINT status = 0;
135 GX_VERTICAL_LIST *list;
136 GX_DROP_LIST *drop;
137 GX_PROMPT *prompt;
138
139 switch(myevent -> gx_event_type)
140 {
141 case GX_SIGNAL(ID_BRUSH_ALPHA_SLIDER, GX_EVENT_SLIDER_VALUE):
142 brush_alpha = (GX_UBYTE)myevent->gx_event_payload.gx_event_longdata;
143 update_prompt(ID_BRUSH_ALPHA_PROMPT, brush_alpha);
144 gx_system_dirty_mark(pLineWin);
145 break;
146
147 case GX_SIGNAL(ID_LINE_WIDTH, GX_EVENT_SLIDER_VALUE):
148 line_width = myevent ->gx_event_payload.gx_event_longdata;
149 update_prompt(ID_WIDTH_DISPLAY, line_width);
150 gx_system_dirty_mark(pLineWin);
151 break;
152
153 case GX_SIGNAL(ID_LINE_ANGLE, GX_EVENT_SLIDER_VALUE):
154 line_angle = myevent ->gx_event_payload.gx_event_longdata;
155 update_prompt(ID_ANGLE_DISPLAY, line_angle);
156 calculate_line_ends();
157 gx_system_dirty_mark(pLineWin);
158 break;
159
160 case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_ON):
161 anti_aliased = GX_TRUE;
162 gx_system_dirty_mark(pLineWin);
163 break;
164
165 case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_OFF):
166 anti_aliased = GX_FALSE;
167 gx_system_dirty_mark(pLineWin);
168 break;
169
170 case GX_SIGNAL(ID_ROUNDED, GX_EVENT_TOGGLE_ON):
171 rounded = GX_TRUE;
172 gx_system_dirty_mark(pLineWin);
173 break;
174
175 case GX_SIGNAL(ID_ROUNDED, GX_EVENT_TOGGLE_OFF):
176 rounded = GX_FALSE;
177 gx_system_dirty_mark(pLineWin);
178 break;
179
180 case GX_SIGNAL(ID_COLOR_LIST, GX_EVENT_LIST_SELECT):
181 drop = &pMainWin->main_window_color_list;
182 gx_drop_list_popup_get(drop, &list);
183
184 gx_vertical_list_selected_widget_get(list, (GX_WIDGET **)&prompt);
185
186 if (prompt)
187 {
188 line_color = prompt->gx_prompt_normal_text_color;
189 gx_system_dirty_mark(pLineWin);
190 }
191 break;
192
193 default:
194 status = gx_window_event_process(window, myevent);
195 break;
196 }
197 return status;
198 }
199
200
201
line_win_draw(GX_WINDOW * window)202 VOID line_win_draw(GX_WINDOW *window)
203 {
204 ULONG brush_style = 0;
205 GX_BRUSH *brush;
206
207 gx_window_draw((GX_WINDOW*) window);
208 gx_context_brush_get(&brush);
209 brush -> gx_brush_alpha = brush_alpha;
210
211 if (anti_aliased)
212 {
213 brush_style |= GX_BRUSH_ALIAS;
214 }
215 if (rounded)
216 {
217 brush_style |= GX_BRUSH_ROUND;
218 }
219 gx_context_brush_define(line_color, window ->gx_widget_normal_fill_color, brush_style);
220 gx_context_brush_width_set(line_width);
221
222 calculate_line_ends();
223 gx_canvas_line_draw(line_x1, line_y1, line_x2, line_y2);
224 }
225
drop_list_color_create(GX_VERTICAL_LIST * list,GX_WIDGET * widget,INT index)226 VOID drop_list_color_create(GX_VERTICAL_LIST *list, GX_WIDGET *widget, INT index)
227 {
228 GX_BOOL created;
229 GX_RECTANGLE size;
230 GX_STRING string;
231
232 GX_PROMPT *prompt = (GX_PROMPT *)widget;
233
234 gx_widget_created_test(widget, &created);
235
236 if (!created)
237 {
238 gx_utility_rectangle_define(&size, 0, 0, 100, 30);
239 gx_prompt_create(prompt, GX_NULL, list, 0, GX_STYLE_ENABLED | GX_STYLE_TEXT_LEFT | GX_STYLE_BORDER_NONE, 0, &size);
240 gx_prompt_text_color_set(prompt, color_list[index].color_id, color_list[index].color_id, color_list[index].color_id);
241 }
242
243 string.gx_string_ptr = color_list[index].color;
244 string.gx_string_length = string_length_get(string.gx_string_ptr, MAX_COLOR_TEXT_LENGTH);
245 gx_prompt_text_set_ext(prompt, &string);
246 }
247
PopulateDropList(void)248 VOID PopulateDropList(void)
249 {
250 int index;
251 GX_VERTICAL_LIST *list;
252
253 GX_DROP_LIST *drop = &pMainWin->main_window_color_list;
254 gx_drop_list_popup_get(drop, &list);
255
256 for (index = 0; index < DROP_LIST_VISIBLE_ROWS; index++)
257 {
258 drop_list_color_create(list, (GX_WIDGET *)&drop_list_widgets[index], index);
259 }
260
261 gx_vertical_scrollbar_create(&list_scroll, "list_scroll", list, GX_NULL,
262 GX_SCROLLBAR_VERTICAL | GX_SCROLLBAR_RELATIVE_THUMB | GX_SCROLLBAR_END_BUTTONS);
263 }
264
string_length_get(GX_CONST GX_CHAR * input_string,UINT max_string_length)265 UINT string_length_get(GX_CONST GX_CHAR* input_string, UINT max_string_length)
266 {
267 UINT length = 0;
268
269 if (input_string)
270 {
271 /* Traverse the string. */
272 for (length = 0; input_string[length]; length++)
273 {
274 /* Check if the string length is bigger than the max string length. */
275 if (length >= max_string_length)
276 {
277 break;
278 }
279 }
280 }
281
282 return length;
283 }