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 "synergy_glyph_draw_16bpp_screen_resources.h"
7 #include "synergy_glyph_draw_16bpp_screen_specifications.h"
8
9 WINDOW_CONTROL_BLOCK *pMainWin;
10 GX_WINDOW *pHorizontalClip;
11 GX_WINDOW *pVerticalClip;
12 GX_SLIDER *pHorizontalSlider;
13 GX_SLIDER *pVerticalSlider;
14 GX_SINGLE_LINE_TEXT_INPUT *pVSliderInput;
15 GX_SINGLE_LINE_TEXT_INPUT *pHSliderInput;
16 GX_SINGLE_LINE_TEXT_INPUT *pVClipInput;
17 GX_SINGLE_LINE_TEXT_INPUT *pHClipInput;
18
19 /* Define the ThreadX demo thread control block and stack. */
20
21 TX_THREAD demo_thread;
22 UCHAR demo_thread_stack[4096];
23
24 GX_WINDOW_ROOT *root;
25 INT xshift;
26 INT yshift;
27 INT pre_vslider_value = 345;
28 INT pre_hslider_value = 20;
29
30 /* Define prototypes. */
31 VOID demo_thread_entry(ULONG thread_input);
32 extern UINT win32_dave2d_graphics_driver_setup_565rgb(GX_DISPLAY *display);
33
34 void string_to_int(char *str, int len, int *value);
35
main(int argc,char ** argv)36 int main(int argc, char ** argv)
37 {
38 tx_kernel_enter();
39 return(0);
40 }
41
42
tx_application_define(void * first_unused_memory)43 VOID tx_application_define(void *first_unused_memory)
44 {
45
46 /* Create the main demo thread. */
47 tx_thread_create(&demo_thread, "GUIX Demo Thread", demo_thread_entry,
48 0, demo_thread_stack, sizeof(demo_thread_stack),
49 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
50 }
51
demo_thread_entry(ULONG thread_input)52 VOID demo_thread_entry(ULONG thread_input)
53 {
54 GX_STRING string;
55
56 /* Initialize GUIX. */
57 gx_system_initialize();
58
59 gx_studio_display_configure(DISPLAY_1, win32_dave2d_graphics_driver_setup_565rgb,
60 0, 0, &root);
61
62 /* create the main screen */
63 gx_studio_named_widget_create("window", (GX_WIDGET *) root, (GX_WIDGET **) &pMainWin);
64
65 pHorizontalClip = &pMainWin -> window_horizontal_clip;
66 pVerticalClip = &pMainWin -> window_vertical_clip;
67 pHorizontalSlider = &pMainWin -> window_horizontal_slider;
68 pVerticalSlider = &pMainWin -> window_vertical_slider;
69
70 pVSliderInput = &pMainWin -> window_text_input_vslider_val;
71 pHSliderInput = &pMainWin -> window_text_input_hslider_val;
72 pVClipInput = &pMainWin -> window_vclip_width;
73 pHClipInput = &pMainWin -> window_hclip_width;
74
75 /* Initialize single line text input. */
76 string.gx_string_ptr = "20";
77 string.gx_string_length = 2;
78
79 gx_single_line_text_input_text_set_ext(pVSliderInput, &string);
80 gx_single_line_text_input_text_set_ext(pHSliderInput, &string);
81 gx_single_line_text_input_text_set_ext(pVClipInput, &string);
82 gx_single_line_text_input_text_set_ext(pHClipInput, &string);
83
84
85 /* Show the root window to make it and patients screen visible. */
86 gx_widget_show(root);
87
88 /* let GUIX run */
89 gx_system_start();
90 }
91
main_event_handler(GX_WINDOW * window,GX_EVENT * myevent)92 UINT main_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
93 {
94 UINT status = 0;
95 INT value;
96 GX_RECTANGLE size;
97
98 switch(myevent -> gx_event_type)
99 {
100 case GX_SIGNAL(ID_VERTICAL_SLIDER, GX_EVENT_SLIDER_VALUE):
101 yshift = myevent -> gx_event_payload.gx_event_longdata;
102 yshift = pre_vslider_value - yshift;
103 pre_vslider_value = myevent -> gx_event_payload.gx_event_longdata;
104
105 gx_widget_shift(pHorizontalClip, 0, yshift, GX_TRUE);
106 break;
107
108 case GX_SIGNAL(ID_HORIZONTAL_SLIDER, GX_EVENT_SLIDER_VALUE):
109 xshift = myevent -> gx_event_payload.gx_event_longdata;
110 xshift -= pre_hslider_value;
111 pre_hslider_value = myevent -> gx_event_payload.gx_event_longdata;
112
113 gx_widget_shift(pVerticalClip, xshift, 0, GX_TRUE);
114 break;
115
116 case GX_SIGNAL(ID_VSLIDER_INPUT, GX_EVENT_TEXT_EDITED):
117 string_to_int(pVSliderInput -> gx_single_line_text_input_buffer, pVSliderInput -> gx_single_line_text_input_string_size, &value);
118 if((value >= 20) && (value <= 345))
119 {
120 value = 345 - (value - 20);
121 gx_slider_value_set(pVerticalSlider, &pVerticalSlider->gx_slider_info, value);
122 }
123 break;
124
125 case GX_SIGNAL(ID_HSLIDER_INPUT, GX_EVENT_TEXT_EDITED):
126 string_to_int(pHSliderInput -> gx_single_line_text_input_buffer, pHSliderInput -> gx_single_line_text_input_string_size, &value);
127 if((value >= 20) && (value <= 570))
128 {
129 gx_slider_value_set(pHorizontalSlider, &pHorizontalSlider->gx_slider_info, value);
130 }
131 break;
132
133 case GX_SIGNAL(ID_VCLIP_INPUT, GX_EVENT_TEXT_EDITED):
134 string_to_int(pVClipInput -> gx_single_line_text_input_buffer, pVClipInput -> gx_single_line_text_input_string_size, &value);
135 if((value >= 5) && (value <= 30))
136 {
137 size = pVerticalClip -> gx_widget_size;
138 size.gx_rectangle_right = size.gx_rectangle_left + value;
139 gx_widget_resize(pVerticalClip, &size);
140
141 size.gx_rectangle_right = size.gx_rectangle_left + value/2;
142 gx_widget_resize(pVerticalClip->gx_widget_first_child, &size);
143 }
144 break;
145
146 case GX_SIGNAL(ID_HCLIP_INPUT, GX_EVENT_TEXT_EDITED):
147 string_to_int(pHClipInput -> gx_single_line_text_input_buffer, pHClipInput -> gx_single_line_text_input_string_size, &value);
148 if((value >= 5) && (value <= 30))
149 {
150 size = pHorizontalClip -> gx_widget_size;
151 size.gx_rectangle_bottom = size.gx_rectangle_top + value;
152 gx_widget_resize(pHorizontalClip, &size);
153
154 size.gx_rectangle_bottom = size.gx_rectangle_top + value/2;
155 gx_widget_resize(pHorizontalClip->gx_widget_first_child, &size);
156 }
157 break;
158
159 default:
160 status = gx_window_event_process(window, myevent);
161 break;
162 }
163 return status;
164 }
165
string_to_int(char * str,int len,int * value)166 void string_to_int(char *str, int len, int *value)
167 {
168 int i;
169
170 *value = 0;
171
172 for(i = 0; i < len; i++)
173 {
174 *value = *value * 10;
175 *value += str[i] - '0';
176 }
177 }