1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** GUIX Component */
16 /** */
17 /** Slider Management (Slider) */
18 /** */
19 /**************************************************************************/
20
21 #define GX_SOURCE_CODE
22
23 /* Include necessary system files. */
24
25 #include "gx_api.h"
26 #include "gx_system.h"
27 #include "gx_canvas.h"
28 #include "gx_context.h"
29 #include "gx_widget.h"
30 #include "gx_utility.h"
31 #include "gx_slider.h"
32
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _gx_slider_tickmarks_draw PORTABLE C */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* Kenneth Maxwell, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This service draws the slider tickmarks. */
48 /* */
49 /* INPUT */
50 /* */
51 /* slider Slider widget control block */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* None */
56 /* */
57 /* CALLS */
58 /* */
59 /* _gx_slider_travel_get Get the slider travel */
60 /* _gx_context_line_color_set Set the line color for the */
61 /* drawing context */
62 /* _gx_context_brush_width_set Set the brush width for the */
63 /* drawing context */
64 /* _gx_canvas_line_draw Draw a line */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Application Code */
69 /* GUIX Internal Code */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
76 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
77 /* resulting in version 6.1 */
78 /* */
79 /**************************************************************************/
_gx_slider_tickmarks_draw(GX_SLIDER * slider)80 VOID _gx_slider_tickmarks_draw(GX_SLIDER *slider)
81 {
82 INT mintravel;
83 INT maxtravel;
84 INT tickstart;
85 INT tickend;
86 INT space;
87 GX_FIXED_VAL tickpos;
88 INT tickcount;
89 GX_SLIDER_INFO *info;
90
91 if (slider -> gx_slider_tick_count <= 1)
92 {
93 return;
94 }
95
96 /* make a border 1/8 of widget size around ticksmarks */
97 if (slider -> gx_widget_style & GX_STYLE_SLIDER_VERTICAL)
98 {
99 mintravel = slider -> gx_widget_size.gx_rectangle_left;
100 maxtravel = slider -> gx_widget_size.gx_rectangle_right;
101 space = (maxtravel - mintravel) / 8;
102
103 /* draw left in */
104 tickend = (maxtravel + mintravel) / 2;
105 tickend -= space;
106 tickstart = mintravel + space;
107 }
108 else
109 {
110 mintravel = slider -> gx_widget_size.gx_rectangle_top;
111 maxtravel = slider -> gx_widget_size.gx_rectangle_bottom;
112 space = (maxtravel - mintravel) / 8;
113
114 /* draw ticks from center down */
115 tickend = maxtravel - space;
116 tickstart = (maxtravel + mintravel) / 2;
117 tickstart += space;
118 }
119
120 /* pick up pointer to slider info struct */
121 info = &slider -> gx_slider_info;
122
123 /* get the limits of the slider travel */
124 _gx_slider_travel_get(slider, info, &mintravel, &maxtravel);
125
126 tickcount = slider -> gx_slider_tick_count;
127 space = GX_FIXED_VAL_MAKE(maxtravel - mintravel) / (tickcount - 1);
128
129 /* set line color */
130 _gx_context_line_color_set(slider -> gx_slider_tick_color);
131 _gx_context_brush_width_set(1);
132 tickpos = GX_FIXED_VAL_MAKE(mintravel);
133
134 while (tickcount > 0)
135 {
136 mintravel = GX_FIXED_VAL_RND(tickpos);
137 if (slider -> gx_widget_style & GX_STYLE_SLIDER_VERTICAL)
138 {
139 _gx_canvas_line_draw((GX_VALUE)tickstart, (GX_VALUE)mintravel, (GX_VALUE)tickend, (GX_VALUE)mintravel);
140 }
141 else
142 {
143 _gx_canvas_line_draw((GX_VALUE)mintravel, (GX_VALUE)tickstart, (GX_VALUE)mintravel, (GX_VALUE)tickend);
144 }
145 tickpos += space;
146 tickcount--;
147 }
148 }
149
150