GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_text_scroll_wheel_draw.c Lines: 205 205 100.0 %
Date: 2024-12-05 08:52:37 Branches: 104 104 100.0 %

Line Branch Exec Source
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
/**   String Scroll Wheel Management (Scroll Wheel)                       */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
24
/* Include necessary system files.  */
25
26
#include "gx_api.h"
27
#include "gx_system.h"
28
#include "gx_window.h"
29
#include "gx_widget.h"
30
#include "gx_scroll_wheel.h"
31
#include "gx_context.h"
32
#include "gx_canvas.h"
33
#include "gx_utility.h"
34
35
/**************************************************************************/
36
/*                                                                        */
37
/*  FUNCTION                                               RELEASE        */
38
/*                                                                        */
39
/*    _gx_text_scroll_wheel_round_text_draw               PORTABLE C      */
40
/*                                                           6.1.10       */
41
/*  AUTHOR                                                                */
42
/*                                                                        */
43
/*    Kenneth Maxwell, Microsoft Corporation                              */
44
/*                                                                        */
45
/*  DESCRIPTION                                                           */
46
/*                                                                        */
47
/*    Internal helper function to draw text to specified area in rounded  */
48
/*    style.                                                              */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    wheel                                 Scroll wheel control block    */
53
/*    tColor                                Text color id                 */
54
/*    font_id                               Font id                       */
55
/*    string                                Text to be draw               */
56
/*    x_pos                                 Draw start xpos               */
57
/*    y_pos                                 Draw start ypos               */
58
/*    width                                 Draw width                    */
59
/*    height                                Draw height                   */
60
/*                                                                        */
61
/*  OUTPUT                                                                */
62
/*                                                                        */
63
/*    status                                Completion status             */
64
/*                                                                        */
65
/*  CALLS                                                                 */
66
/*                                                                        */
67
/*    _gx_context_line_color_set            Set line color                */
68
/*    _gx_context_fill_color_set            Set fill color                */
69
/*    _gx_context_font_set                  Set font                      */
70
/*    _gx_context_brush_get                 Get brush                     */
71
/*    _gx_system_string_width_get           Get string width              */
72
/*    _gx_utility_string_to_alphamap        Convert string to alphamap    */
73
/*    _gx_utility_pixelmap_resize           Resize a pixelmap             */
74
/*    _gx_canvas_pixelmap_draw              Draw pixelmap to canvas       */
75
/*    _gx_system_memory_free                Application defined memory    */
76
/*                                            free function               */
77
/*                                                                        */
78
/*  CALLED BY                                                             */
79
/*                                                                        */
80
/*    _gx_text_scroll_wheel_row_draw                                      */
81
/*                                                                        */
82
/*  RELEASE HISTORY                                                       */
83
/*                                                                        */
84
/*    DATE              NAME                      DESCRIPTION             */
85
/*                                                                        */
86
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
87
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
88
/*                                            resulting in version 6.1    */
89
/*  06-02-2021     Kenneth Maxwell          Modified comment(s),          */
90
/*                                            rename RENESAS_DAVE2D       */
91
/*                                            support conditional,        */
92
/*                                            resulting in version 6.1.7  */
93
/*  01-31-2022     Ting Zhu                 Modified comment(s),          */
94
/*                                            removed alpha set,          */
95
/*                                            resulting in version 6.1.10 */
96
/*                                                                        */
97
/**************************************************************************/
98
4015
static UINT  _gx_text_scroll_wheel_round_text_draw(GX_TEXT_SCROLL_WHEEL *wheel, GX_RESOURCE_ID tColor, GX_RESOURCE_ID font_id,
99
                                                   GX_CONST GX_STRING *string, GX_VALUE x_pos, GX_VALUE y_pos, GX_VALUE width, GX_VALUE height)
100
{
101
4015
UINT        status = GX_SUCCESS;
102
4015
GX_VALUE    text_width = 0;
103
GX_VALUE    text_height;
104
GX_BRUSH   *brush;
105
GX_PIXELMAP textmap;
106
GX_PIXELMAP resized_map;
107
GX_COLOR    old_fill_color;
108
109
4015
    _gx_context_line_color_set(tColor);
110
4015
    _gx_context_font_set(font_id);
111
4015
    _gx_context_brush_get(&brush);
112
113
4015
    if (!brush -> gx_brush_font)
114
    {
115
98
        return(GX_SUCCESS);
116
    }
117
118
3917
    text_height = brush -> gx_brush_font -> gx_font_line_height;
119
120
3917
    if (wheel -> gx_scroll_wheel_row_height <= 0)
121
    {
122
1
        return GX_FAILURE;
123
    }
124
125
3916
    text_height = (GX_VALUE)(text_height * height / wheel -> gx_scroll_wheel_row_height);
126
127
3916
    _gx_system_string_width_get_ext(brush -> gx_brush_font, string, &text_width);
128
129

3916
    if (!text_height || !text_width)
130
    {
131
12
        return(GX_SUCCESS);
132
    }
133
134
3904
    y_pos = (GX_VALUE)(y_pos + (height - text_height) / 2);
135
136
3904
    switch (wheel -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
137
    {
138
16
    case GX_STYLE_TEXT_RIGHT:
139
16
        x_pos = (GX_VALUE)(x_pos + width - 1);
140
16
        x_pos = (GX_VALUE)(x_pos - text_width);
141
16
        break;
142
143
16
    case GX_STYLE_TEXT_LEFT:
144
16
        break;
145
146
3872
    case GX_STYLE_TEXT_CENTER:
147
    default:
148
3872
        x_pos = (GX_VALUE)(x_pos + ((width - text_width) / 2));
149
3872
        break;
150
    }
151
152
3904
    status = _gx_utility_string_to_alphamap_ext(string, brush -> gx_brush_font, &textmap);
153
154
3904
    if (status == GX_SUCCESS)
155
    {
156
3885
        status = _gx_utility_pixelmap_resize(&textmap, &resized_map, text_width, text_height);
157
158
3885
        if (status == GX_SUCCESS)
159
        {
160
3883
            old_fill_color = brush -> gx_brush_fill_color;
161
3883
            _gx_context_fill_color_set(tColor);
162
#if defined(GX_RENESAS_DAVE2D_DRAW)
163
            resized_map.gx_pixelmap_flags |= GX_PIXELMAP_DYNAMICALLY_ALLOCATED;
164
#endif
165
3883
            _gx_canvas_pixelmap_draw(x_pos, y_pos, &resized_map);
166
3883
            brush -> gx_brush_fill_color = old_fill_color;
167
168
            /* free the resized alphamap memory */
169
3883
            _gx_system_memory_free((void *)resized_map.gx_pixelmap_data);
170
        }
171
172
        /* free the temporary canvas memory */
173
3885
        _gx_system_memory_free((void *)(textmap.gx_pixelmap_data));
174
    }
175
176
3904
    return status;
177
}
178
179
/**************************************************************************/
180
/*                                                                        */
181
/*  FUNCTION                                               RELEASE        */
182
/*                                                                        */
183
/*    _gx_text_scroll_wheel_flat_text_draw                PORTABLE C      */
184
/*                                                           6.1.10       */
185
/*  AUTHOR                                                                */
186
/*                                                                        */
187
/*    Kenneth Maxwell, Microsoft Corporation                              */
188
/*                                                                        */
189
/*  DESCRIPTION                                                           */
190
/*                                                                        */
191
/*    Internal helper function to draw text to specified area in normal   */
192
/*    style.                                                              */
193
/*                                                                        */
194
/*  INPUT                                                                 */
195
/*                                                                        */
196
/*    wheel                                 Scroll wheel control block    */
197
/*    tColor                                Text color id                 */
198
/*    font_id                               Font id                       */
199
/*    string                                Text to be draw               */
200
/*    x_pos                                 Draw start xpos               */
201
/*    y_pos                                 Draw start ypos               */
202
/*    width                                 Draw width                    */
203
/*    height                                Draw height                   */
204
/*                                                                        */
205
/*  OUTPUT                                                                */
206
/*                                                                        */
207
/*    status                                Completion status             */
208
/*                                                                        */
209
/*  CALLS                                                                 */
210
/*                                                                        */
211
/*    _gx_context_line_color_set            Set line color                */
212
/*    _gx_context_font_set                  Set font                      */
213
/*    _gx_context_brush_get                 Get brush                     */
214
/*    _gx_system_string_width_get           Get string width              */
215
/*    _gx_canvas_text_draw                  Draw text to canvas           */
216
/*                                                                        */
217
/*  CALLED BY                                                             */
218
/*                                                                        */
219
/*    _gx_text_scroll_wheel_row_draw                                      */
220
/*                                                                        */
221
/*  RELEASE HISTORY                                                       */
222
/*                                                                        */
223
/*    DATE              NAME                      DESCRIPTION             */
224
/*                                                                        */
225
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
226
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
227
/*                                            resulting in version 6.1    */
228
/*  01-31-2022     Ting Zhu                 Modified comment(s),          */
229
/*                                            removed alpha set,          */
230
/*                                            resulting in version 6.1.10 */
231
/*                                                                        */
232
/**************************************************************************/
233
1535
static UINT  _gx_text_scroll_wheel_flat_text_draw(GX_TEXT_SCROLL_WHEEL *wheel, GX_RESOURCE_ID tColor, GX_RESOURCE_ID font_id,
234
                                                  GX_CONST GX_STRING *string, GX_VALUE x_pos, GX_VALUE y_pos, GX_VALUE width, GX_VALUE height)
235
{
236
1535
GX_VALUE  text_width = 0;
237
GX_VALUE  text_height;
238
GX_BRUSH *brush;
239
240
1535
    _gx_context_line_color_set(tColor);
241
1535
    _gx_context_font_set(font_id);
242
1535
    _gx_context_brush_get(&brush);
243
244
1535
    if (!brush -> gx_brush_font)
245
    {
246
2
        return(GX_SUCCESS);
247
    }
248
249
1533
    text_height = brush -> gx_brush_font -> gx_font_line_height;
250
251
1533
    y_pos = (GX_VALUE)(y_pos + (height - text_height) / 2);
252
253
1533
    switch (wheel -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
254
    {
255
14
    case GX_STYLE_TEXT_RIGHT:
256
14
        _gx_system_string_width_get_ext(brush -> gx_brush_font, string, &text_width);
257
14
        x_pos = (GX_VALUE)(x_pos + width - 1);
258
14
        x_pos = (GX_VALUE)(x_pos - text_width);
259
14
        break;
260
261
231
    case GX_STYLE_TEXT_LEFT:
262
231
        break;
263
1288
    case GX_STYLE_TEXT_CENTER:
264
    default:
265
1288
        _gx_system_string_width_get_ext(brush -> gx_brush_font, string, &text_width);
266
1288
        x_pos = (GX_VALUE)(x_pos + ((width - text_width) / 2));
267
1288
        break;
268
    }
269
270
    /* Draw the text.  */
271
1533
    _gx_canvas_text_draw_ext(x_pos, y_pos, string);
272
273
1533
    return GX_SUCCESS;
274
}
275
276
/**************************************************************************/
277
/*                                                                        */
278
/*  FUNCTION                                               RELEASE        */
279
/*                                                                        */
280
/*    _gx_text_scroll_wheel_row_draw                      PORTABLE C      */
281
/*                                                           6.1.4        */
282
/*  AUTHOR                                                                */
283
/*                                                                        */
284
/*    Kenneth Maxwell, Microsoft Corporation                              */
285
/*                                                                        */
286
/*  DESCRIPTION                                                           */
287
/*                                                                        */
288
/*    Internal helper function to draw text to specified area with        */
289
/*    relevant fonts.                                                     */
290
/*                                                                        */
291
/*  INPUT                                                                 */
292
/*                                                                        */
293
/*    wheel                                 Scroll wheel control block    */
294
/*    selected_area                         The area of selected item     */
295
/*    draw_draw                             The area for drawing          */
296
/*                                                                        */
297
/*  OUTPUT                                                                */
298
/*                                                                        */
299
/*    status                                Completion status             */
300
/*                                                                        */
301
/*  CALLS                                                                 */
302
/*                                                                        */
303
/*    _gx_utility_rectangle_compare         Test if rectangles are equal  */
304
/*    _gx_utility_string_length_check       Test string length            */
305
/*    _gx_text_scroll_wheel_round_text_draw Draw text in rounded style    */
306
/*    _gx_text_scroll_wheel_flat_text_draw  Draw text in normal style     */
307
/*                                                                        */
308
/*  CALLED BY                                                             */
309
/*                                                                        */
310
/*    _gx_text_scroll_wheel_round_draw                                    */
311
/*    _gx_text_scroll_wheel_flat_draw                                     */
312
/*                                                                        */
313
/*  RELEASE HISTORY                                                       */
314
/*                                                                        */
315
/*    DATE              NAME                      DESCRIPTION             */
316
/*                                                                        */
317
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
318
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
319
/*                                            resulting in version 6.1    */
320
/*  02-02-2021     Kenneth Maxwell          Modified comment(s),          */
321
/*                                            renamed                     */
322
/*                                            GX_STYLE_SCROLL_WHEEL_DRAG  */
323
/*                                            to GX_STATUS_TRACKING_PEN,  */
324
/*                                            resulting in version 6.1.4  */
325
/*                                                                        */
326
/**************************************************************************/
327
5582
static UINT _gx_text_scroll_wheel_row_draw(GX_TEXT_SCROLL_WHEEL *wheel, GX_RECTANGLE *selected_area, GX_RECTANGLE *draw_area, GX_CONST GX_STRING *string)
328
{
329
5582
UINT           status = GX_SUCCESS;
330
GX_RESOURCE_ID text_color;
331
GX_RESOURCE_ID font;
332
INT            width;
333
INT            height;
334
UINT           (*text_draw)(GX_TEXT_SCROLL_WHEEL *wheel, GX_RESOURCE_ID tColor, GX_RESOURCE_ID font_id,
335
                            GX_CONST GX_STRING *string, GX_VALUE x_pos, GX_VALUE y_pos, GX_VALUE width, GX_VALUE height);
336
337
338
5582
    if (string -> gx_string_length == 0)
339
    {
340
32
        return status;
341
    }
342
343
5550
    width = draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1;
344
5550
    height = draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1;
345
346
5550
    if (wheel -> gx_widget_style & GX_STYLE_TEXT_SCROLL_WHEEL_ROUND)
347
    {
348
4015
        text_draw = _gx_text_scroll_wheel_round_text_draw;
349
    }
350
    else
351
    {
352
1535
        text_draw = _gx_text_scroll_wheel_flat_text_draw;
353
    }
354
355
5550
    if ((wheel -> gx_widget_status & GX_STATUS_TRACKING_PEN) ||
356

8819
        (wheel -> gx_scroll_wheel_animation_steps != 0) ||
357
3954
        (!_gx_utility_rectangle_compare(selected_area, draw_area)))
358
    {
359
5001
        if (wheel -> gx_widget_style & GX_STYLE_ENABLED)
360
        {
361
4974
            text_color = wheel -> gx_text_scroll_wheel_normal_text_color;
362
        }
363
        else
364
        {
365
27
            text_color = wheel -> gx_text_scroll_wheel_disabled_text_color;
366
        }
367
368
5001
        font = wheel -> gx_text_scroll_wheel_normal_font;
369
    }
370
    else
371
    {
372
549
        if (wheel -> gx_widget_style & GX_STYLE_ENABLED)
373
        {
374
543
            text_color = wheel -> gx_text_scroll_wheel_selected_text_color;
375
        }
376
        else
377
        {
378
6
            text_color = wheel -> gx_text_scroll_wheel_disabled_text_color;
379
        }
380
549
        font = wheel -> gx_text_scroll_wheel_selected_font;
381
    }
382
383
    /* Draw text. */
384
5550
    status = text_draw(wheel, text_color, font, string, draw_area -> gx_rectangle_left,
385
5550
                       draw_area -> gx_rectangle_top, (GX_VALUE)width, (GX_VALUE)height);
386
387
5550
    return status;
388
}
389
390
/**************************************************************************/
391
/*                                                                        */
392
/*  FUNCTION                                               RELEASE        */
393
/*                                                                        */
394
/*    _gx_text_scroll_wheel_text_get                      PORTABLE C      */
395
/*                                                           6.1.10       */
396
/*  AUTHOR                                                                */
397
/*                                                                        */
398
/*    Kenneth Maxwell, Microsoft Corporation                              */
399
/*                                                                        */
400
/*  DESCRIPTION                                                           */
401
/*                                                                        */
402
/*    Internal helper function to retrieve text of sepecified row.        */
403
/*                                                                        */
404
/*  INPUT                                                                 */
405
/*                                                                        */
406
/*    wheel                                 Scroll wheel control block    */
407
/*    row                                   Row index                     */
408
/*    string                                String pointer to be return   */
409
/*                                                                        */
410
/*  OUTPUT                                                                */
411
/*                                                                        */
412
/*    status                                Completion status             */
413
/*                                                                        */
414
/*  CALLS                                                                 */
415
/*                                                                        */
416
/*    [gx_text_scroll_wheel_text_get]      Retrieve row text              */
417
/*    [_gx_system_memory_allocator]        Memory allocator               */
418
/*    _gx_utility_bidi_paragraph_reorder   Reorder bidi text              */
419
/*                                                                        */
420
/*  CALLED BY                                                             */
421
/*                                                                        */
422
/*    _gx_text_scroll_wheel_flat_draw                                     */
423
/*    _gx_text_scroll_wheel_round_draw                                    */
424
/*                                                                        */
425
/*  RELEASE HISTORY                                                       */
426
/*                                                                        */
427
/*    DATE              NAME                      DESCRIPTION             */
428
/*                                                                        */
429
/*  09-30-2020     Kenneth Maxwell          Initial Version 6.1           */
430
/*  01-31-2022     Ting Zhu                 Modified comment(s),          */
431
/*                                            updated with new bidi text  */
432
/*                                            reorder function call,      */
433
/*                                            resulting in version 6.1.10 */
434
/*                                                                        */
435
/**************************************************************************/
436
5595
static UINT _gx_text_scroll_wheel_text_get(GX_TEXT_SCROLL_WHEEL *wheel, INT row, GX_STRING *string)
437
{
438
#ifdef GX_DYNAMIC_BIDI_TEXT_SUPPORT
439
GX_BIDI_TEXT_INFO           text_info;
440
GX_BIDI_RESOLVED_TEXT_INFO *resolved_info;
441
GX_CANVAS                  *canvas;
442
GX_DISPLAY                 *display;
443
#endif
444
445
#if defined(GX_ENABLE_DEPRECATED_STRING_API)
446
UINT status;
447
448
5595
    if (wheel -> gx_text_scroll_wheel_text_get_deprecated)
449
    {
450
47
        string -> gx_string_ptr = wheel -> gx_text_scroll_wheel_text_get_deprecated(wheel, row);
451
452
47
        if (string -> gx_string_ptr)
453
        {
454
32
            status = _gx_utility_string_length_check(string -> gx_string_ptr, &string -> gx_string_length, GX_MAX_STRING_LENGTH);
455
456
32
            if (status != GX_SUCCESS)
457
            {
458
5
                return status;
459
            }
460
        }
461
    }
462
    else
463
    {
464
#endif
465
5548
        wheel -> gx_text_scroll_wheel_text_get(wheel, row, string);
466
#if defined(GX_ENABLE_DEPRECATED_STRING_API)
467
    }
468
#endif
469
470
#ifdef GX_DYNAMIC_BIDI_TEXT_SUPPORT
471
    if (_gx_system_bidi_text_enabled)
472
    {
473
        if (!_gx_system_memory_allocator)
474
        {
475
            return GX_SYSTEM_MEMORY_ERROR;
476
        }
477
478
        if (!wheel -> gx_text_scroll_wheel_bidi_resolved_text_info)
479
        {
480
            wheel -> gx_text_scroll_wheel_bidi_resolved_text_info = (GX_BIDI_RESOLVED_TEXT_INFO **)_gx_system_memory_allocator(sizeof(GX_BIDI_RESOLVED_TEXT_INFO *) * (UINT)wheel -> gx_scroll_wheel_total_rows);
481
482
            if (!wheel -> gx_text_scroll_wheel_bidi_resolved_text_info)
483
            {
484
                return GX_SYSTEM_MEMORY_ERROR;
485
            }
486
487
            memset(wheel -> gx_text_scroll_wheel_bidi_resolved_text_info, 0, sizeof(GX_BIDI_RESOLVED_TEXT_INFO *) * (UINT)wheel -> gx_scroll_wheel_total_rows);
488
        }
489
490
        if (!wheel -> gx_text_scroll_wheel_bidi_resolved_text_info[row])
491
        {
492
            text_info.gx_bidi_text_info_text = *string;
493
            text_info.gx_bidi_text_info_font = GX_NULL;
494
            text_info.gx_bidi_text_info_display_width = 0;
495
            GX_UTILITY_TEXT_DIRECTION_GET(text_info.gx_bidi_text_info_direction, wheel, canvas, display);
496
497
            if (_gx_utility_bidi_paragraph_reorder_ext(&text_info, &resolved_info) == GX_SUCCESS)
498
            {
499
                wheel -> gx_text_scroll_wheel_bidi_resolved_text_info[row] = resolved_info;
500
            }
501
        }
502
503
        if (wheel -> gx_text_scroll_wheel_bidi_resolved_text_info[row])
504
        {
505
            *string = *wheel -> gx_text_scroll_wheel_bidi_resolved_text_info[row] -> gx_bidi_resolved_text_info_text;
506
        }
507
    }
508
#endif
509
510
5590
    return GX_SUCCESS;
511
}
512
513
/**************************************************************************/
514
/*                                                                        */
515
/*  FUNCTION                                               RELEASE        */
516
/*                                                                        */
517
/*    _gx_text_scroll_wheel_round_draw                    PORTABLE C      */
518
/*                                                           6.1          */
519
/*  AUTHOR                                                                */
520
/*                                                                        */
521
/*    Kenneth Maxwell, Microsoft Corporation                              */
522
/*                                                                        */
523
/*  DESCRIPTION                                                           */
524
/*                                                                        */
525
/*    Internal helper function to draw a scroll wheel, which contain some */
526
/*    text transformating process.                                        */
527
/*                                                                        */
528
/*  INPUT                                                                 */
529
/*                                                                        */
530
/*    wheel                                 Scroll wheel control block    */
531
/*                                                                        */
532
/*  OUTPUT                                                                */
533
/*                                                                        */
534
/*    status                                Completion status             */
535
/*                                                                        */
536
/*  CALLS                                                                 */
537
/*                                                                        */
538
/*    _gx_context_pixelmap_get             Get pixelmap by resource ID    */
539
/*    _gx_window_client_height_get         Get window client height       */
540
/*    _gx_window_client_width_get          Get window clietn width        */
541
/*    _gx_widget_border_width_get          Get widget border width        */
542
/*    _gx_utility_rectangle_define         Define a rectangle             */
543
/*    _gx_canvas_pixelmap_tile             Title a pixelmap               */
544
/*    _gx_text_scroll_wheel_row_draw       Draw text to specified area    */
545
/*                                                                        */
546
/*  CALLED BY                                                             */
547
/*                                                                        */
548
/*    _gx_text_scroll_wheel_draw                                          */
549
/*                                                                        */
550
/*  RELEASE HISTORY                                                       */
551
/*                                                                        */
552
/*    DATE              NAME                      DESCRIPTION             */
553
/*                                                                        */
554
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
555
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
556
/*                                            improved logic,             */
557
/*                                            resulting in version 6.1    */
558
/*                                                                        */
559
/**************************************************************************/
560
562
static UINT _gx_text_scroll_wheel_round_draw(GX_TEXT_SCROLL_WHEEL *wheel)
561
{
562
562
UINT         status = GX_SUCCESS;
563
GX_PIXELMAP *map;
564
GX_VALUE     width;
565
GX_VALUE     height;
566
GX_VALUE     row_height;
567
INT          trans_height;
568
GX_VALUE     xpos;
569
GX_VALUE     ypos;
570
GX_VALUE     ycenter;
571
GX_VALUE     border_width;
572
GX_RECTANGLE selected_area;
573
GX_RECTANGLE draw_area;
574
GX_STRING    string;
575
INT          row;
576
577
    /* Pickup selected background. */
578
562
    _gx_context_pixelmap_get(wheel -> gx_scroll_wheel_selected_background, &map);
579
580
    /* Pickup client height. */
581
562
    _gx_window_client_height_get((GX_WINDOW *)wheel, &height);
582
562
    _gx_window_client_width_get((GX_WINDOW *)wheel, &width);
583
562
    _gx_widget_border_width_get((GX_WIDGET *)wheel, &border_width);
584
585

562
    if (width <= 0 || height <= 0)
586
    {
587
2
        return GX_FALSE;
588
    }
589
590
560
    row_height = wheel -> gx_scroll_wheel_row_height;
591
560
    xpos = (GX_VALUE)(wheel -> gx_widget_size.gx_rectangle_left + border_width);
592
593
560
    ypos = (GX_VALUE)(wheel -> gx_widget_size.gx_rectangle_top + border_width);
594
560
    ypos = (GX_VALUE)(ypos + (height >> 1));
595
560
    ypos = (GX_VALUE)(ypos - (row_height >> 1));
596
597
    /* Draw selected background. */
598
560
    _gx_utility_rectangle_define(&selected_area, xpos, ypos, (GX_VALUE)(xpos + width - 1), (GX_VALUE)(ypos + row_height - 1));
599
600
560
    if (map)
601
    {
602
554
        _gx_canvas_pixelmap_tile(&selected_area, map);
603
    }
604
605
    /* Draw scroll wheel rows. */
606
607
560
    ycenter = (GX_VALUE)(ypos + row_height / 2);
608
560
    ypos = (GX_VALUE)(ypos + wheel -> gx_scroll_wheel_selected_yshift);
609
560
    row = wheel -> gx_scroll_wheel_selected_row;
610
611
2711
    while (status == GX_SUCCESS &&
612
2689
           ypos < wheel -> gx_widget_size.gx_rectangle_bottom - border_width)
613
    {
614
2187
        if (row > (INT)(wheel -> gx_scroll_wheel_total_rows - 1))
615
        {
616
167
            if (wheel -> gx_widget_style & GX_STYLE_WRAP)
617
            {
618
136
                row -= wheel -> gx_scroll_wheel_total_rows;
619
            }
620
            else
621
            {
622
31
                break;
623
            }
624
        }
625
626
2156
        status = _gx_text_scroll_wheel_text_get(wheel, row, &string);
627
628
2156
        if (status != GX_SUCCESS)
629
        {
630
1
            return status;
631
        }
632
633
2155
        trans_height = GX_ABS(ypos + row_height / 2 - ycenter);
634
635
2155
        if (trans_height == 0)
636
        {
637
364
            trans_height = row_height;
638
        }
639
        else
640
        {
641
1791
            trans_height = GX_FIXED_VAL_MAKE(GX_ABS(height * 3 / 4 - trans_height));
642
1791
            trans_height = 120 * trans_height / height;
643
644
1791
            trans_height = GX_FIXED_VAL_TO_INT(_gx_utility_math_sin(trans_height) * row_height);
645
646
1791
            if (trans_height < row_height / 5)
647
            {
648
4
                break;
649
            }
650
        }
651
652
2151
        _gx_utility_rectangle_define(&draw_area, xpos, ypos, (GX_VALUE)(xpos + width - 1), (GX_VALUE)(ypos + trans_height - 1));
653
2151
        status = _gx_text_scroll_wheel_row_draw((GX_TEXT_SCROLL_WHEEL *)wheel, &selected_area, &draw_area, &string);
654
2151
        ypos = (GX_VALUE)(ypos + trans_height);
655
2151
        row++;
656
    }
657
658
559
    ypos = (GX_VALUE)(ycenter - row_height / 2 + wheel -> gx_scroll_wheel_selected_yshift);
659
559
    row = wheel -> gx_scroll_wheel_selected_row - 1;
660
661
2442
    while (status == GX_SUCCESS &&
662
2420
           ypos > wheel -> gx_widget_size.gx_rectangle_top + border_width)
663
    {
664
1953
        if (row < 0)
665
        {
666
157
            if (wheel -> gx_widget_style & GX_STYLE_WRAP)
667
            {
668
92
                row += wheel -> gx_scroll_wheel_total_rows;
669
            }
670
            else
671
            {
672
65
                break;
673
            }
674
        }
675
676
1888
        status = _gx_text_scroll_wheel_text_get(wheel, row, &string);
677
678
1888
        if (status != GX_SUCCESS)
679
        {
680
1
            return status;
681
        }
682
683
1887
        trans_height = ycenter + (row_height / 2) - ypos;
684
685
1887
        trans_height = GX_FIXED_VAL_MAKE(GX_ABS(height * 3 / 4 - trans_height));
686
1887
        trans_height = 120 * trans_height / height;
687
688
1887
        trans_height = GX_FIXED_VAL_TO_INT(_gx_utility_math_sin(trans_height) * row_height);
689
690
1887
        if (trans_height < row_height / 5)
691
        {
692
4
            break;
693
        }
694
695
1883
        _gx_utility_rectangle_define(&draw_area, xpos, (GX_VALUE)(ypos - trans_height), (GX_VALUE)(xpos + width - 1), (GX_VALUE)(ypos - 1));
696
1883
        status = _gx_text_scroll_wheel_row_draw((GX_TEXT_SCROLL_WHEEL *)wheel, &selected_area, &draw_area, &string);
697
1883
        ypos = (GX_VALUE)(ypos - trans_height);
698
1883
        row--;
699
    }
700
701
    /* Draw the overlay pixelmap, if there is one: */
702
703
558
    if (wheel -> gx_scroll_wheel_gradient.gx_gradient_pixelmap.gx_pixelmap_data)
704
    {
705
552
        _gx_canvas_pixelmap_tile(&wheel -> gx_widget_size, &wheel -> gx_scroll_wheel_gradient.gx_gradient_pixelmap);
706
    }
707
708
558
    return status;
709
}
710
711
/**************************************************************************/
712
/*                                                                        */
713
/*  FUNCTION                                               RELEASE        */
714
/*                                                                        */
715
/*    _gx_text_scroll_wheel_flat_draw                     PORTABLE C      */
716
/*                                                           6.1          */
717
/*  AUTHOR                                                                */
718
/*                                                                        */
719
/*    Kenneth Maxwell, Microsoft Corporation                              */
720
/*                                                                        */
721
/*  DESCRIPTION                                                           */
722
/*                                                                        */
723
/*    Internal helper function to draw a scroll wheel in normal case.     */
724
/*                                                                        */
725
/*  INPUT                                                                 */
726
/*                                                                        */
727
/*    wheel                                 Scroll wheel control block    */
728
/*                                                                        */
729
/*  OUTPUT                                                                */
730
/*                                                                        */
731
/*    status                                Completion status             */
732
/*                                                                        */
733
/*  CALLS                                                                 */
734
/*                                                                        */
735
/*    _gx_context_pixelmap_get              Get pixelmap by resource ID   */
736
/*    _gx_window_client_height_get          Get window client height      */
737
/*    _gx_window_client_width_get           Get window client width       */
738
/*    _gx_widget_border_width_get           Get widget border width       */
739
/*    _gx_utility_rectangle_define          Define a rectangle            */
740
/*    _gx_canvas_pixelmap_tile              Tile a pixelmap               */
741
/*    _gx_text_scroll_wheel_row_draw        Draw text to specified area   */
742
/*                                                                        */
743
/*  CALLED BY                                                             */
744
/*                                                                        */
745
/*    _gx_text_scroll_wheel_draw                                          */
746
/*                                                                        */
747
/*  RELEASE HISTORY                                                       */
748
/*                                                                        */
749
/*    DATE              NAME                      DESCRIPTION             */
750
/*                                                                        */
751
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
752
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
753
/*                                            improved logic,             */
754
/*                                            resulting in version 6.1    */
755
/*                                                                        */
756
/**************************************************************************/
757
267
static UINT _gx_text_scroll_wheel_flat_draw(GX_TEXT_SCROLL_WHEEL *wheel)
758
{
759
GX_PIXELMAP *map;
760
GX_VALUE     width;
761
GX_VALUE     height;
762
GX_VALUE     row_height;
763
GX_VALUE     xpos;
764
GX_VALUE     ypos;
765
GX_VALUE     border_width;
766
GX_RECTANGLE selected_area;
767
GX_RECTANGLE draw_area;
768
GX_STRING    string;
769
INT          row;
770
INT          top_rows;
771
UINT         status;
772
773
    /* Pickup selected background. */
774
267
    _gx_context_pixelmap_get(wheel -> gx_scroll_wheel_selected_background, &map);
775
776
    /* Pickup client height. */
777
267
    _gx_window_client_height_get((GX_WINDOW *)wheel, &height);
778
267
    _gx_window_client_width_get((GX_WINDOW *)wheel, &width);
779
267
    _gx_widget_border_width_get((GX_WIDGET *)wheel, &border_width);
780
781
267
    row_height = wheel -> gx_scroll_wheel_row_height;
782
783
267
    if (row_height <= 0)
784
    {
785
2
        return GX_FALSE;
786
    }
787
265
    xpos = (GX_VALUE)(wheel -> gx_widget_size.gx_rectangle_left + border_width);
788
789
265
    ypos = (GX_VALUE)(wheel -> gx_widget_size.gx_rectangle_top + border_width);
790
265
    ypos = (GX_VALUE)(ypos + (height >> 1));
791
265
    ypos = (GX_VALUE)(ypos - (row_height >> 1));
792
793
    /* Draw selected background. */
794
265
    _gx_utility_rectangle_define(&selected_area, xpos, ypos, (GX_VALUE)(xpos + width - 1), (GX_VALUE)(ypos + row_height - 1));
795
796
265
    if (map)
797
    {
798
194
        _gx_canvas_pixelmap_tile(&selected_area, map);
799
    }
800
801
265
    ypos = (GX_VALUE)(ypos + wheel -> gx_scroll_wheel_selected_yshift);
802
803
265
    top_rows = (ypos - wheel -> gx_widget_size.gx_rectangle_top + row_height) / row_height;
804
265
    ypos = (GX_VALUE)(ypos - (top_rows * row_height));
805
806
265
    row = wheel -> gx_scroll_wheel_selected_row - top_rows;
807
808
419
    while (row < 0)
809
    {
810
154
        if (wheel -> gx_widget_style & GX_STYLE_WRAP)
811
        {
812
67
            row += wheel -> gx_scroll_wheel_total_rows;
813
        }
814
        else
815
        {
816
87
            ypos = (GX_VALUE)(ypos - row * row_height);
817
87
            row = 0;
818
        }
819
    }
820
821
1813
    while (ypos < wheel -> gx_widget_size.gx_rectangle_bottom - border_width)
822
    {
823
1556
        if (row > (INT)(wheel -> gx_scroll_wheel_total_rows - 1))
824
        {
825
158
            if (wheel -> gx_widget_style & GX_STYLE_WRAP)
826
            {
827
153
                row -= wheel -> gx_scroll_wheel_total_rows;
828
            }
829
            else
830
            {
831
5
                break;
832
            }
833
        }
834
835
1551
        status = _gx_text_scroll_wheel_text_get(wheel, row, &string);
836
1551
        if (status != GX_SUCCESS)
837
        {
838
3
            return status;
839
        }
840
841
1548
        _gx_utility_rectangle_define(&draw_area, xpos, ypos, (GX_VALUE)(xpos + width - 1), (GX_VALUE)(ypos + row_height - 1));
842
1548
        _gx_text_scroll_wheel_row_draw((GX_TEXT_SCROLL_WHEEL *)wheel, &selected_area, &draw_area, &string);
843
1548
        ypos = (GX_VALUE)(ypos + row_height);
844
1548
        row++;
845
    }
846
847
    /* Draw the overlay pixelmap, if there is one: */
848
849
262
    if (wheel -> gx_scroll_wheel_gradient.gx_gradient_pixelmap.gx_pixelmap_data)
850
    {
851
235
        _gx_canvas_pixelmap_tile(&wheel -> gx_widget_size, &wheel -> gx_scroll_wheel_gradient.gx_gradient_pixelmap);
852
    }
853
854
262
    return GX_SUCCESS;
855
}
856
857
/**************************************************************************/
858
/*                                                                        */
859
/*  FUNCTION                                               RELEASE        */
860
/*                                                                        */
861
/*    _gx_text_scroll_wheel_draw                          PORTABLE C      */
862
/*                                                           6.1          */
863
/*  AUTHOR                                                                */
864
/*                                                                        */
865
/*    Kenneth Maxwell, Microsoft Corporation                              */
866
/*                                                                        */
867
/*  DESCRIPTION                                                           */
868
/*                                                                        */
869
/*    This function draws a text scroll wheel widget.                     */
870
/*                                                                        */
871
/*  INPUT                                                                 */
872
/*                                                                        */
873
/*    wheel                                 Text scroll wheel control     */
874
/*                                            block                       */
875
/*                                                                        */
876
/*  OUTPUT                                                                */
877
/*                                                                        */
878
/*    None                                                                */
879
/*                                                                        */
880
/*  CALLS                                                                 */
881
/*                                                                        */
882
/*    _gx_window_draw                       Draw a window                 */
883
/*    _gx_text_scroll_wheel_round_draw      Draw round style scroll wheel */
884
/*    _gx_text_scroll_wheel_flat_draw       Draw flat style scroll wheel  */
885
/*                                                                        */
886
/*  CALLED BY                                                             */
887
/*                                                                        */
888
/*    Application Code                                                    */
889
/*    GUIX Internal Code                                                  */
890
/*                                                                        */
891
/*  RELEASE HISTORY                                                       */
892
/*                                                                        */
893
/*    DATE              NAME                      DESCRIPTION             */
894
/*                                                                        */
895
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
896
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
897
/*                                            resulting in version 6.1    */
898
/*                                                                        */
899
/**************************************************************************/
900
854
VOID _gx_text_scroll_wheel_draw(GX_TEXT_SCROLL_WHEEL *wheel)
901
{
902
854
    _gx_window_draw((GX_WINDOW *)wheel);
903
904
854
    if (!wheel -> gx_scroll_wheel_total_rows)
905
    {
906
24
        return;
907
    }
908
909
#if defined(GX_ENABLE_DEPRECATED_STRING_API)
910
830
    if ((wheel -> gx_text_scroll_wheel_text_get_deprecated == GX_NULL) &&
911
820
        (wheel -> gx_text_scroll_wheel_text_get == GX_NULL))
912
    {
913
1
        return;
914
    }
915
#else
916
    if (wheel -> gx_text_scroll_wheel_text_get == GX_NULL)
917
    {
918
        return;
919
    }
920
#endif
921
922
829
    if (wheel -> gx_widget_style & GX_STYLE_TEXT_SCROLL_WHEEL_ROUND)
923
    {
924
562
        _gx_text_scroll_wheel_round_draw((GX_TEXT_SCROLL_WHEEL *)wheel);
925
    }
926
    else
927
    {
928
267
        _gx_text_scroll_wheel_flat_draw((GX_TEXT_SCROLL_WHEEL *)wheel);
929
    }
930
}
931