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_16bpp_rotated_resources.h"
6 #include "all_widgets_16bpp_rotated_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
49 gx_widget_find((GX_WIDGET *)&lines_screen, (USHORT)id, 0, &pp);
50
51 if (pp)
52 {
53 gx_utility_ltoa(value, val, 10);
54 gx_prompt_text_set(pp, val);
55 }
56 }
57
main_event_handler(GX_WINDOW * window,GX_EVENT * myevent)58 UINT main_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
59 {
60 UINT status = 0;
61
62 switch(myevent -> gx_event_type)
63 {
64 case GX_SIGNAL(ID_BRUSH_ALPHA_SLIDER, GX_EVENT_SLIDER_VALUE):
65 lines_screen_brush_alpha = (GX_UBYTE)myevent->gx_event_payload.gx_event_longdata;
66 update_prompt(ID_BRUSH_ALPHA_PROMPT, lines_screen_brush_alpha);
67 gx_system_dirty_mark(pLineWin);
68 break;
69
70 case GX_SIGNAL(ID_LINE_WIDTH, GX_EVENT_SLIDER_VALUE):
71 lines_screen_line_width = myevent ->gx_event_payload.gx_event_longdata;
72 update_prompt(ID_WIDTH_DISPLAY, lines_screen_line_width);
73 gx_system_dirty_mark(pLineWin);
74 break;
75
76 case GX_SIGNAL(ID_LINE_ANGLE, GX_EVENT_SLIDER_VALUE):
77 lines_screen_line_angle = myevent ->gx_event_payload.gx_event_longdata;
78 update_prompt(ID_ANGLE_DISPLAY, lines_screen_line_angle);
79 calculate_line_ends();
80 gx_system_dirty_mark(pLineWin);
81 break;
82
83 case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_ON):
84 lines_screen_anti_aliased = GX_TRUE;
85 gx_system_dirty_mark(pLineWin);
86 break;
87
88 case GX_SIGNAL(ID_ANTI_ALIASED, GX_EVENT_TOGGLE_OFF):
89 lines_screen_anti_aliased = GX_FALSE;
90 gx_system_dirty_mark(pLineWin);
91 break;
92
93 case GX_SIGNAL(ID_ROUNDED, GX_EVENT_TOGGLE_ON):
94 lines_screen_rounded = GX_TRUE;
95 gx_system_dirty_mark(pLineWin);
96 break;
97
98 case GX_SIGNAL(ID_ROUNDED, GX_EVENT_TOGGLE_OFF):
99 lines_screen_rounded = GX_FALSE;
100 gx_system_dirty_mark(pLineWin);
101 break;
102
103 case GX_SIGNAL(ID_COLOR_BLACK, GX_EVENT_RADIO_SELECT):
104 lines_screen_line_color = GX_COLOR_ID_BLACK;
105 gx_system_dirty_mark(pLineWin);
106 break;
107
108 case GX_SIGNAL(ID_COLOR_WHITE, GX_EVENT_RADIO_SELECT):
109 lines_screen_line_color = GX_COLOR_ID_WHITE;
110 gx_system_dirty_mark(pLineWin);
111 break;
112
113 case GX_SIGNAL(ID_COLOR_ORANGE, GX_EVENT_RADIO_SELECT):
114 lines_screen_line_color = GX_COLOR_ID_ORANGE;
115 gx_system_dirty_mark(pLineWin);
116 break;
117
118 default:
119 status = next_button_handler(window, myevent);
120 break;
121 }
122 return status;
123 }
124
line_win_draw(GX_WINDOW * window)125 VOID line_win_draw(GX_WINDOW *window)
126 {
127 ULONG brush_style = 0;
128 GX_BRUSH *brush;
129 GX_RECTANGLE *size;
130
131 gx_window_draw((GX_WINDOW*) window);
132
133 gx_context_brush_get(&brush);
134 brush -> gx_brush_alpha = lines_screen_brush_alpha;
135
136 if (lines_screen_anti_aliased)
137 {
138 brush_style |= GX_BRUSH_ALIAS;
139 }
140 if (lines_screen_rounded)
141 {
142 brush_style |= GX_BRUSH_ROUND;
143 }
144 gx_context_brush_define(lines_screen_line_color, window ->gx_widget_normal_fill_color, brush_style);
145 gx_context_brush_width_set(lines_screen_line_width);
146
147 /* Draw pattern lines. */
148 size = &window->gx_widget_size;
149
150 gx_context_brush_pattern_set(0xf8fcfeff);
151 gx_canvas_line_draw(size->gx_rectangle_left + 5, size->gx_rectangle_top + 5, size->gx_rectangle_left + 5, size->gx_rectangle_bottom - 5);
152 gx_context_brush_pattern_set(0xf0f0f0f0);
153 gx_canvas_line_draw(size->gx_rectangle_left + 5, size->gx_rectangle_top + 5, size->gx_rectangle_right - 5, size->gx_rectangle_top + 5);
154 gx_context_brush_pattern_set(0xaaaaaaaa);
155 gx_canvas_line_draw(size->gx_rectangle_left + 5, size->gx_rectangle_bottom - 5, size->gx_rectangle_right - 5, size->gx_rectangle_bottom - 5);
156 gx_context_brush_pattern_set(0x33333333);
157 gx_canvas_line_draw(size->gx_rectangle_right - 5, size->gx_rectangle_top + 5, size->gx_rectangle_right - 5, size->gx_rectangle_bottom - 5);
158
159 gx_context_brush_pattern_set(0);
160 calculate_line_ends();
161 gx_canvas_line_draw(line_x1, line_y1, line_x2, line_y2);
162 }
163