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 /** Radial Slider Management (Slider) */ 18 /** */ 19 /**************************************************************************/ 20 21 #define GX_SOURCE_CODE 22 23 24 /* Include necessary system files. */ 25 26 #include "gx_api.h" 27 #include "gx_utility.h" 28 #include "gx_radial_slider.h" 29 30 /**************************************************************************/ 31 /* */ 32 /* FUNCTION RELEASE */ 33 /* */ 34 /* _gx_radial_slider_angle_calculate PORTABLE C */ 35 /* 6.1 */ 36 /* AUTHOR */ 37 /* */ 38 /* Kenneth Maxwell, Microsoft Corporation */ 39 /* */ 40 /* DESCRIPTION */ 41 /* */ 42 /* This service calculates the slider angle according to a point value.*/ 43 /* */ 44 /* INPUT */ 45 /* */ 46 /* slider Radial slider control block */ 47 /* point Point value on radial track */ 48 /* return_value Retrieved angle value */ 49 /* */ 50 /* OUTPUT */ 51 /* */ 52 /* status Completion status */ 53 /* */ 54 /* CALLS */ 55 /* */ 56 /* _gx_utility_math_acos Compute acos value */ 57 /* _gx_utility_math_asin Compute asin value */ 58 /* _gx_utility_math_sqrt Compute sqrt value */ 59 /* */ 60 /* CALLED BY */ 61 /* */ 62 /* GUIX Internal Code */ 63 /* */ 64 /* RELEASE HISTORY */ 65 /* */ 66 /* DATE NAME DESCRIPTION */ 67 /* */ 68 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ 69 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */ 70 /* resulting in version 6.1 */ 71 /* */ 72 /**************************************************************************/ _gx_radial_slider_angle_calculate(GX_RADIAL_SLIDER * slider,GX_POINT point,GX_VALUE * return_value)73UINT _gx_radial_slider_angle_calculate(GX_RADIAL_SLIDER *slider, GX_POINT point, GX_VALUE *return_value) 74 { 75 GX_RADIAL_SLIDER_INFO *info; 76 INT new_value; 77 INT dist; 78 INT x_dist; 79 INT y_dist; 80 INT x_center; 81 INT y_center; 82 83 info = &slider -> gx_radial_slider_info; 84 85 x_center = slider -> gx_widget_size.gx_rectangle_left + info -> gx_radial_slider_info_xcenter; 86 y_center = slider -> gx_widget_size.gx_rectangle_top + info -> gx_radial_slider_info_ycenter; 87 88 x_dist = (INT)(point.gx_point_x - x_center); 89 y_dist = (INT)(point.gx_point_y - y_center); 90 91 dist = (x_dist * x_dist) + (y_dist * y_dist); 92 dist = (INT)_gx_utility_math_sqrt((UINT)dist); 93 94 if (!dist) 95 { 96 *return_value = 0; 97 return GX_FAILURE; 98 } 99 100 if (point.gx_point_y <= y_center) 101 { 102 x_dist = GX_FIXED_VAL_MAKE(x_dist) / dist; 103 104 /* The needle is between [0, 180]. */ 105 new_value = _gx_utility_math_acos(x_dist); 106 } 107 else 108 { 109 y_dist = (GX_FIXED_VAL_MAKE(y_dist)) / dist; 110 111 /* The needle is between [180, 360] */ 112 new_value = _gx_utility_math_asin(y_dist); 113 114 if (point.gx_point_x < x_center) 115 { 116 new_value = 180 + new_value; 117 } 118 else 119 { 120 new_value = 360 - new_value; 121 } 122 } 123 124 /* Range value inside specified [-90, 270]*/ 125 if (new_value > 270) 126 { 127 new_value = new_value - 360; 128 } 129 130 *return_value = (GX_VALUE)new_value; 131 132 return(GX_SUCCESS); 133 } 134 135