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