1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Numeric Scroll Wheel Management (Scroll Wheel)                      */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_scroll_wheel.h"
29 #include "gx_utility.h"
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _gx_numeric_scroll_wheel_text_get                   PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Kenneth Maxwell, Microsoft Corporation                              */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function returns pointer to numeric text.                      */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    wheel                                 Scroll wheel control block    */
48 /*    row                                   Desired text row              */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    status                                Completion status             */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _gx_utility_ltoa                      Convert integer to string     */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    _gx_text_scroll_wheel_draw                                          */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
67 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*                                                                        */
70 /**************************************************************************/
_gx_numeric_scroll_wheel_text_get(GX_NUMERIC_SCROLL_WHEEL * wheel,INT row,GX_STRING * string)71 UINT _gx_numeric_scroll_wheel_text_get(GX_NUMERIC_SCROLL_WHEEL *wheel, INT row, GX_STRING *string)
72 {
73 INT  step;
74 INT  val;
75 
76     if (row < wheel -> gx_scroll_wheel_total_rows)
77     {
78         step = wheel -> gx_numeric_scroll_wheel_end_val - wheel -> gx_numeric_scroll_wheel_start_val;
79 
80         if (step == (wheel -> gx_scroll_wheel_total_rows - 1))
81         {
82             step = 1;
83         }
84         else if (step == (1 - wheel -> gx_scroll_wheel_total_rows))
85         {
86             step = -1;
87         }
88         else if (wheel -> gx_scroll_wheel_total_rows > 1)
89         {
90             step /= (wheel -> gx_scroll_wheel_total_rows - 1);
91         }
92 
93         val = wheel -> gx_numeric_scroll_wheel_start_val + (step * row);
94         _gx_utility_ltoa(val, wheel -> gx_numeric_scroll_wheel_string_buffer, GX_NUMERIC_SCROLL_WHEEL_STRING_BUFFER_SIZE);
95 
96         string -> gx_string_ptr = wheel -> gx_numeric_scroll_wheel_string_buffer;
97         _gx_utility_string_length_check(string -> gx_string_ptr, &string -> gx_string_length, GX_NUMERIC_SCROLL_WHEEL_STRING_BUFFER_SIZE - 1);
98     }
99     else
100     {
101         string -> gx_string_ptr = GX_NULL;
102         string -> gx_string_length = 0;
103     }
104 
105     return(GX_SUCCESS);
106 }
107 
108