1 /* This is a small demo of the high-performance GUIX graphics framework. */
2
3 #include <stdio.h>
4 #include "gx_api.h"
5 #include "all_widgets_565bgr_resources.h"
6 #include "all_widgets_565bgr_specifications.h"
7
8
9 GX_WINDOW *pLineWin = &lines_screen.lines_screen_line_window;
10 int lines_screen_line_angle = 0;
11 int lines_screen_line_width = 1;
12 GX_BOOL lines_screen_anti_aliased = GX_FALSE;
13 GX_BOOL lines_screen_rounded = GX_FALSE;
14 GX_RESOURCE_ID lines_screen_line_color = GX_COLOR_ID_BLACK;
15 GX_UBYTE lines_screen_brush_alpha = 255;
16 int line_x1;
17 int line_x2;
18 int line_y1;
19 int line_y2;
20 int lines_screen_line_length = 100;
21
22 /* Define prototypes. */
23 VOID PopulateDropList(void);
24
calculate_line_ends(VOID)25 VOID calculate_line_ends(VOID)
26 {
27 INT scaled_angle;
28 INT x_dist;
29 INT y_dist;
30
31 INT x_center = (pLineWin->gx_widget_size.gx_rectangle_left + pLineWin->gx_widget_size.gx_rectangle_right) / 2;
32 INT y_center = (pLineWin->gx_widget_size.gx_rectangle_top + pLineWin->gx_widget_size.gx_rectangle_bottom) / 2;
33
34 scaled_angle = GX_FIXED_VAL_MAKE(lines_screen_line_angle);
35 x_dist = GX_FIXED_VAL_TO_INT(gx_utility_math_cos(scaled_angle) * lines_screen_line_length);
36 y_dist = GX_FIXED_VAL_TO_INT(gx_utility_math_sin(scaled_angle) * lines_screen_line_length);
37
38 line_x1 = x_center - x_dist;
39 line_x2 = x_center + x_dist;
40 line_y1 = y_center - y_dist;
41 line_y2 = y_center + y_dist;
42 }
43
update_prompt(GX_RESOURCE_ID id,INT value)44 VOID update_prompt(GX_RESOURCE_ID id, INT value)
45 {
46 GX_PROMPT *pp;
47 static GX_CHAR val[10];
48 GX_STRING string;
49
50 gx_widget_find((GX_WIDGET *)&lines_screen, (USHORT)id, 0, &pp);
51
52 if (pp)
53 {
54 gx_utility_ltoa(value, val, 10);
55 string.gx_string_ptr = val;
56 string.gx_string_length = strnlen(val, sizeof(val));
57 gx_prompt_text_set_ext(pp, &string);
58 }
59 }
60
main_event_handler(GX_WINDOW * window,GX_EVENT * myevent)61 UINT main_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
62 {
63 UINT status = 0;
64
65 switch(myevent -> gx_event_type)
66 {
67 case GX_SIGNAL(ID_BRUSH_ALPHA_SLIDER, GX_EVENT_SLIDER_VALUE):
68 lines_screen_brush_alpha = (GX_UBYTE)myevent->gx_event_payload.gx_event_longdata;
69 update_prompt(ID_BRUSH_ALPHA_PROMPT, lines_screen_brush_alpha);
70 gx_system_dirty_mark(pLineWin);
71 break;
72
73 case GX_SIGNAL(ID_LINE_WIDTH, GX_EVENT_SLIDER_VALUE):
74 lines_screen_line_width = myevent ->gx_event_payload.gx_event_longdata;
75 update_prompt(ID_WIDTH_DISPLAY, lines_screen_line_width);
76 gx_system_dirty_mark(pLineWin);
77 break;
78
79 case GX_SIGNAL(ID_LINE_ANGLE, GX_EVENT_SLIDER_VALUE):
80 lines_screen_line_angle = myevent ->gx_event_payload.gx_event_longdata;
81 update_prompt(ID_ANGLE_DISPLAY, lines_screen_line_angle);
82 calculate_line_ends();
83 gx_system_dirty_mark(pLineWin);
84 break;
85
86 case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_ON):
87 lines_screen_anti_aliased = GX_TRUE;
88 gx_system_dirty_mark(pLineWin);
89 break;
90
91 case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_OFF):
92 lines_screen_anti_aliased = GX_FALSE;
93 gx_system_dirty_mark(pLineWin);
94 break;
95
96 case GX_SIGNAL(ID_ROUNDED, GX_EVENT_TOGGLE_ON):
97 lines_screen_rounded = GX_TRUE;
98 gx_system_dirty_mark(pLineWin);
99 break;
100
101 case GX_SIGNAL(ID_ROUNDED, GX_EVENT_TOGGLE_OFF):
102 lines_screen_rounded = GX_FALSE;
103 gx_system_dirty_mark(pLineWin);
104 break;
105
106 case GX_SIGNAL(ID_COLOR_BLACK, GX_EVENT_RADIO_SELECT):
107 lines_screen_line_color = GX_COLOR_ID_BLACK;
108 gx_system_dirty_mark(pLineWin);
109 break;
110
111 case GX_SIGNAL(ID_COLOR_WHITE, GX_EVENT_RADIO_SELECT):
112 lines_screen_line_color = GX_COLOR_ID_WHITE;
113 gx_system_dirty_mark(pLineWin);
114 break;
115
116 case GX_SIGNAL(ID_COLOR_ORANGE, GX_EVENT_RADIO_SELECT):
117 lines_screen_line_color = GX_COLOR_ID_ORANGE;
118 gx_system_dirty_mark(pLineWin);
119 break;
120
121 default:
122 status = next_button_handler(window, myevent);
123 break;
124 }
125 return status;
126 }
127
line_win_draw(GX_WINDOW * window)128 VOID line_win_draw(GX_WINDOW *window)
129 {
130 ULONG brush_style = 0;
131 GX_BRUSH *brush;
132 GX_RECTANGLE *size;
133
134 gx_window_draw((GX_WINDOW*) window);
135
136 gx_context_brush_get(&brush);
137 brush -> gx_brush_alpha = lines_screen_brush_alpha;
138
139 if (lines_screen_anti_aliased)
140 {
141 brush_style |= GX_BRUSH_ALIAS;
142 }
143 if (lines_screen_rounded)
144 {
145 brush_style |= GX_BRUSH_ROUND;
146 }
147 gx_context_brush_define(lines_screen_line_color, window ->gx_widget_normal_fill_color, brush_style);
148 gx_context_brush_width_set(lines_screen_line_width);
149
150 /* Draw pattern lines. */
151 size = &window->gx_widget_size;
152
153 gx_context_brush_pattern_set(0xf8fcfeff);
154 gx_canvas_line_draw(size->gx_rectangle_left + 5, size->gx_rectangle_top + 5, size->gx_rectangle_left + 5, size->gx_rectangle_bottom - 5);
155 gx_context_brush_pattern_set(0xf0f0f0f0);
156 gx_canvas_line_draw(size->gx_rectangle_left + 5, size->gx_rectangle_top + 5, size->gx_rectangle_right - 5, size->gx_rectangle_top + 5);
157 gx_context_brush_pattern_set(0xaaaaaaaa);
158 gx_canvas_line_draw(size->gx_rectangle_left + 5, size->gx_rectangle_bottom - 5, size->gx_rectangle_right - 5, size->gx_rectangle_bottom - 5);
159 gx_context_brush_pattern_set(0x33333333);
160 gx_canvas_line_draw(size->gx_rectangle_right - 5, size->gx_rectangle_top + 5, size->gx_rectangle_right - 5, size->gx_rectangle_bottom - 5);
161
162 gx_context_brush_pattern_set(0);
163 calculate_line_ends();
164 gx_canvas_line_draw(line_x1, line_y1, line_x2, line_y2);
165 }
166