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 /**************************************************************************/
_gx_text_scroll_wheel_round_text_draw(GX_TEXT_SCROLL_WHEEL * wheel,GX_RESOURCE_ID tColor,GX_RESOURCE_ID font_id,GX_CONST GX_STRING * string,GX_VALUE x_pos,GX_VALUE y_pos,GX_VALUE width,GX_VALUE height)98 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 UINT status = GX_SUCCESS;
102 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 _gx_context_line_color_set(tColor);
110 _gx_context_font_set(font_id);
111 _gx_context_brush_get(&brush);
112
113 if (!brush -> gx_brush_font)
114 {
115 return(GX_SUCCESS);
116 }
117
118 text_height = brush -> gx_brush_font -> gx_font_line_height;
119
120 if (wheel -> gx_scroll_wheel_row_height <= 0)
121 {
122 return GX_FAILURE;
123 }
124
125 text_height = (GX_VALUE)(text_height * height / wheel -> gx_scroll_wheel_row_height);
126
127 _gx_system_string_width_get_ext(brush -> gx_brush_font, string, &text_width);
128
129 if (!text_height || !text_width)
130 {
131 return(GX_SUCCESS);
132 }
133
134 y_pos = (GX_VALUE)(y_pos + (height - text_height) / 2);
135
136 switch (wheel -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
137 {
138 case GX_STYLE_TEXT_RIGHT:
139 x_pos = (GX_VALUE)(x_pos + width - 1);
140 x_pos = (GX_VALUE)(x_pos - text_width);
141 break;
142
143 case GX_STYLE_TEXT_LEFT:
144 break;
145
146 case GX_STYLE_TEXT_CENTER:
147 default:
148 x_pos = (GX_VALUE)(x_pos + ((width - text_width) / 2));
149 break;
150 }
151
152 status = _gx_utility_string_to_alphamap_ext(string, brush -> gx_brush_font, &textmap);
153
154 if (status == GX_SUCCESS)
155 {
156 status = _gx_utility_pixelmap_resize(&textmap, &resized_map, text_width, text_height);
157
158 if (status == GX_SUCCESS)
159 {
160 old_fill_color = brush -> gx_brush_fill_color;
161 _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 _gx_canvas_pixelmap_draw(x_pos, y_pos, &resized_map);
166 brush -> gx_brush_fill_color = old_fill_color;
167
168 /* free the resized alphamap memory */
169 _gx_system_memory_free((void *)resized_map.gx_pixelmap_data);
170 }
171
172 /* free the temporary canvas memory */
173 _gx_system_memory_free((void *)(textmap.gx_pixelmap_data));
174 }
175
176 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 /**************************************************************************/
_gx_text_scroll_wheel_flat_text_draw(GX_TEXT_SCROLL_WHEEL * wheel,GX_RESOURCE_ID tColor,GX_RESOURCE_ID font_id,GX_CONST GX_STRING * string,GX_VALUE x_pos,GX_VALUE y_pos,GX_VALUE width,GX_VALUE height)233 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 GX_VALUE text_width = 0;
237 GX_VALUE text_height;
238 GX_BRUSH *brush;
239
240 _gx_context_line_color_set(tColor);
241 _gx_context_font_set(font_id);
242 _gx_context_brush_get(&brush);
243
244 if (!brush -> gx_brush_font)
245 {
246 return(GX_SUCCESS);
247 }
248
249 text_height = brush -> gx_brush_font -> gx_font_line_height;
250
251 y_pos = (GX_VALUE)(y_pos + (height - text_height) / 2);
252
253 switch (wheel -> gx_widget_style & GX_STYLE_TEXT_ALIGNMENT_MASK)
254 {
255 case GX_STYLE_TEXT_RIGHT:
256 _gx_system_string_width_get_ext(brush -> gx_brush_font, string, &text_width);
257 x_pos = (GX_VALUE)(x_pos + width - 1);
258 x_pos = (GX_VALUE)(x_pos - text_width);
259 break;
260
261 case GX_STYLE_TEXT_LEFT:
262 break;
263 case GX_STYLE_TEXT_CENTER:
264 default:
265 _gx_system_string_width_get_ext(brush -> gx_brush_font, string, &text_width);
266 x_pos = (GX_VALUE)(x_pos + ((width - text_width) / 2));
267 break;
268 }
269
270 /* Draw the text. */
271 _gx_canvas_text_draw_ext(x_pos, y_pos, string);
272
273 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 /**************************************************************************/
_gx_text_scroll_wheel_row_draw(GX_TEXT_SCROLL_WHEEL * wheel,GX_RECTANGLE * selected_area,GX_RECTANGLE * draw_area,GX_CONST GX_STRING * string)327 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 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 if (string -> gx_string_length == 0)
339 {
340 return status;
341 }
342
343 width = draw_area -> gx_rectangle_right - draw_area -> gx_rectangle_left + 1;
344 height = draw_area -> gx_rectangle_bottom - draw_area -> gx_rectangle_top + 1;
345
346 if (wheel -> gx_widget_style & GX_STYLE_TEXT_SCROLL_WHEEL_ROUND)
347 {
348 text_draw = _gx_text_scroll_wheel_round_text_draw;
349 }
350 else
351 {
352 text_draw = _gx_text_scroll_wheel_flat_text_draw;
353 }
354
355 if ((wheel -> gx_widget_status & GX_STATUS_TRACKING_PEN) ||
356 (wheel -> gx_scroll_wheel_animation_steps != 0) ||
357 (!_gx_utility_rectangle_compare(selected_area, draw_area)))
358 {
359 if (wheel -> gx_widget_style & GX_STYLE_ENABLED)
360 {
361 text_color = wheel -> gx_text_scroll_wheel_normal_text_color;
362 }
363 else
364 {
365 text_color = wheel -> gx_text_scroll_wheel_disabled_text_color;
366 }
367
368 font = wheel -> gx_text_scroll_wheel_normal_font;
369 }
370 else
371 {
372 if (wheel -> gx_widget_style & GX_STYLE_ENABLED)
373 {
374 text_color = wheel -> gx_text_scroll_wheel_selected_text_color;
375 }
376 else
377 {
378 text_color = wheel -> gx_text_scroll_wheel_disabled_text_color;
379 }
380 font = wheel -> gx_text_scroll_wheel_selected_font;
381 }
382
383 /* Draw text. */
384 status = text_draw(wheel, text_color, font, string, draw_area -> gx_rectangle_left,
385 draw_area -> gx_rectangle_top, (GX_VALUE)width, (GX_VALUE)height);
386
387 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 /**************************************************************************/
_gx_text_scroll_wheel_text_get(GX_TEXT_SCROLL_WHEEL * wheel,INT row,GX_STRING * string)436 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 if (wheel -> gx_text_scroll_wheel_text_get_deprecated)
449 {
450 string -> gx_string_ptr = wheel -> gx_text_scroll_wheel_text_get_deprecated(wheel, row);
451
452 if (string -> gx_string_ptr)
453 {
454 status = _gx_utility_string_length_check(string -> gx_string_ptr, &string -> gx_string_length, GX_MAX_STRING_LENGTH);
455
456 if (status != GX_SUCCESS)
457 {
458 return status;
459 }
460 }
461 }
462 else
463 {
464 #endif
465 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 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 /**************************************************************************/
_gx_text_scroll_wheel_round_draw(GX_TEXT_SCROLL_WHEEL * wheel)560 static UINT _gx_text_scroll_wheel_round_draw(GX_TEXT_SCROLL_WHEEL *wheel)
561 {
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 _gx_context_pixelmap_get(wheel -> gx_scroll_wheel_selected_background, &map);
579
580 /* Pickup client height. */
581 _gx_window_client_height_get((GX_WINDOW *)wheel, &height);
582 _gx_window_client_width_get((GX_WINDOW *)wheel, &width);
583 _gx_widget_border_width_get((GX_WIDGET *)wheel, &border_width);
584
585 if (width <= 0 || height <= 0)
586 {
587 return GX_FALSE;
588 }
589
590 row_height = wheel -> gx_scroll_wheel_row_height;
591 xpos = (GX_VALUE)(wheel -> gx_widget_size.gx_rectangle_left + border_width);
592
593 ypos = (GX_VALUE)(wheel -> gx_widget_size.gx_rectangle_top + border_width);
594 ypos = (GX_VALUE)(ypos + (height >> 1));
595 ypos = (GX_VALUE)(ypos - (row_height >> 1));
596
597 /* Draw selected background. */
598 _gx_utility_rectangle_define(&selected_area, xpos, ypos, (GX_VALUE)(xpos + width - 1), (GX_VALUE)(ypos + row_height - 1));
599
600 if (map)
601 {
602 _gx_canvas_pixelmap_tile(&selected_area, map);
603 }
604
605 /* Draw scroll wheel rows. */
606
607 ycenter = (GX_VALUE)(ypos + row_height / 2);
608 ypos = (GX_VALUE)(ypos + wheel -> gx_scroll_wheel_selected_yshift);
609 row = wheel -> gx_scroll_wheel_selected_row;
610
611 while (status == GX_SUCCESS &&
612 ypos < wheel -> gx_widget_size.gx_rectangle_bottom - border_width)
613 {
614 if (row > (INT)(wheel -> gx_scroll_wheel_total_rows - 1))
615 {
616 if (wheel -> gx_widget_style & GX_STYLE_WRAP)
617 {
618 row -= wheel -> gx_scroll_wheel_total_rows;
619 }
620 else
621 {
622 break;
623 }
624 }
625
626 status = _gx_text_scroll_wheel_text_get(wheel, row, &string);
627
628 if (status != GX_SUCCESS)
629 {
630 return status;
631 }
632
633 trans_height = GX_ABS(ypos + row_height / 2 - ycenter);
634
635 if (trans_height == 0)
636 {
637 trans_height = row_height;
638 }
639 else
640 {
641 trans_height = GX_FIXED_VAL_MAKE(GX_ABS(height * 3 / 4 - trans_height));
642 trans_height = 120 * trans_height / height;
643
644 trans_height = GX_FIXED_VAL_TO_INT(_gx_utility_math_sin(trans_height) * row_height);
645
646 if (trans_height < row_height / 5)
647 {
648 break;
649 }
650 }
651
652 _gx_utility_rectangle_define(&draw_area, xpos, ypos, (GX_VALUE)(xpos + width - 1), (GX_VALUE)(ypos + trans_height - 1));
653 status = _gx_text_scroll_wheel_row_draw((GX_TEXT_SCROLL_WHEEL *)wheel, &selected_area, &draw_area, &string);
654 ypos = (GX_VALUE)(ypos + trans_height);
655 row++;
656 }
657
658 ypos = (GX_VALUE)(ycenter - row_height / 2 + wheel -> gx_scroll_wheel_selected_yshift);
659 row = wheel -> gx_scroll_wheel_selected_row - 1;
660
661 while (status == GX_SUCCESS &&
662 ypos > wheel -> gx_widget_size.gx_rectangle_top + border_width)
663 {
664 if (row < 0)
665 {
666 if (wheel -> gx_widget_style & GX_STYLE_WRAP)
667 {
668 row += wheel -> gx_scroll_wheel_total_rows;
669 }
670 else
671 {
672 break;
673 }
674 }
675
676 status = _gx_text_scroll_wheel_text_get(wheel, row, &string);
677
678 if (status != GX_SUCCESS)
679 {
680 return status;
681 }
682
683 trans_height = ycenter + (row_height / 2) - ypos;
684
685 trans_height = GX_FIXED_VAL_MAKE(GX_ABS(height * 3 / 4 - trans_height));
686 trans_height = 120 * trans_height / height;
687
688 trans_height = GX_FIXED_VAL_TO_INT(_gx_utility_math_sin(trans_height) * row_height);
689
690 if (trans_height < row_height / 5)
691 {
692 break;
693 }
694
695 _gx_utility_rectangle_define(&draw_area, xpos, (GX_VALUE)(ypos - trans_height), (GX_VALUE)(xpos + width - 1), (GX_VALUE)(ypos - 1));
696 status = _gx_text_scroll_wheel_row_draw((GX_TEXT_SCROLL_WHEEL *)wheel, &selected_area, &draw_area, &string);
697 ypos = (GX_VALUE)(ypos - trans_height);
698 row--;
699 }
700
701 /* Draw the overlay pixelmap, if there is one: */
702
703 if (wheel -> gx_scroll_wheel_gradient.gx_gradient_pixelmap.gx_pixelmap_data)
704 {
705 _gx_canvas_pixelmap_tile(&wheel -> gx_widget_size, &wheel -> gx_scroll_wheel_gradient.gx_gradient_pixelmap);
706 }
707
708 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 /**************************************************************************/
_gx_text_scroll_wheel_flat_draw(GX_TEXT_SCROLL_WHEEL * wheel)757 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 _gx_context_pixelmap_get(wheel -> gx_scroll_wheel_selected_background, &map);
775
776 /* Pickup client height. */
777 _gx_window_client_height_get((GX_WINDOW *)wheel, &height);
778 _gx_window_client_width_get((GX_WINDOW *)wheel, &width);
779 _gx_widget_border_width_get((GX_WIDGET *)wheel, &border_width);
780
781 row_height = wheel -> gx_scroll_wheel_row_height;
782
783 if (row_height <= 0)
784 {
785 return GX_FALSE;
786 }
787 xpos = (GX_VALUE)(wheel -> gx_widget_size.gx_rectangle_left + border_width);
788
789 ypos = (GX_VALUE)(wheel -> gx_widget_size.gx_rectangle_top + border_width);
790 ypos = (GX_VALUE)(ypos + (height >> 1));
791 ypos = (GX_VALUE)(ypos - (row_height >> 1));
792
793 /* Draw selected background. */
794 _gx_utility_rectangle_define(&selected_area, xpos, ypos, (GX_VALUE)(xpos + width - 1), (GX_VALUE)(ypos + row_height - 1));
795
796 if (map)
797 {
798 _gx_canvas_pixelmap_tile(&selected_area, map);
799 }
800
801 ypos = (GX_VALUE)(ypos + wheel -> gx_scroll_wheel_selected_yshift);
802
803 top_rows = (ypos - wheel -> gx_widget_size.gx_rectangle_top + row_height) / row_height;
804 ypos = (GX_VALUE)(ypos - (top_rows * row_height));
805
806 row = wheel -> gx_scroll_wheel_selected_row - top_rows;
807
808 while (row < 0)
809 {
810 if (wheel -> gx_widget_style & GX_STYLE_WRAP)
811 {
812 row += wheel -> gx_scroll_wheel_total_rows;
813 }
814 else
815 {
816 ypos = (GX_VALUE)(ypos - row * row_height);
817 row = 0;
818 }
819 }
820
821 while (ypos < wheel -> gx_widget_size.gx_rectangle_bottom - border_width)
822 {
823 if (row > (INT)(wheel -> gx_scroll_wheel_total_rows - 1))
824 {
825 if (wheel -> gx_widget_style & GX_STYLE_WRAP)
826 {
827 row -= wheel -> gx_scroll_wheel_total_rows;
828 }
829 else
830 {
831 break;
832 }
833 }
834
835 status = _gx_text_scroll_wheel_text_get(wheel, row, &string);
836 if (status != GX_SUCCESS)
837 {
838 return status;
839 }
840
841 _gx_utility_rectangle_define(&draw_area, xpos, ypos, (GX_VALUE)(xpos + width - 1), (GX_VALUE)(ypos + row_height - 1));
842 _gx_text_scroll_wheel_row_draw((GX_TEXT_SCROLL_WHEEL *)wheel, &selected_area, &draw_area, &string);
843 ypos = (GX_VALUE)(ypos + row_height);
844 row++;
845 }
846
847 /* Draw the overlay pixelmap, if there is one: */
848
849 if (wheel -> gx_scroll_wheel_gradient.gx_gradient_pixelmap.gx_pixelmap_data)
850 {
851 _gx_canvas_pixelmap_tile(&wheel -> gx_widget_size, &wheel -> gx_scroll_wheel_gradient.gx_gradient_pixelmap);
852 }
853
854 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 /**************************************************************************/
_gx_text_scroll_wheel_draw(GX_TEXT_SCROLL_WHEEL * wheel)900 VOID _gx_text_scroll_wheel_draw(GX_TEXT_SCROLL_WHEEL *wheel)
901 {
902 _gx_window_draw((GX_WINDOW *)wheel);
903
904 if (!wheel -> gx_scroll_wheel_total_rows)
905 {
906 return;
907 }
908
909 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
910 if ((wheel -> gx_text_scroll_wheel_text_get_deprecated == GX_NULL) &&
911 (wheel -> gx_text_scroll_wheel_text_get == GX_NULL))
912 {
913 return;
914 }
915 #else
916 if (wheel -> gx_text_scroll_wheel_text_get == GX_NULL)
917 {
918 return;
919 }
920 #endif
921
922 if (wheel -> gx_widget_style & GX_STYLE_TEXT_SCROLL_WHEEL_ROUND)
923 {
924 _gx_text_scroll_wheel_round_draw((GX_TEXT_SCROLL_WHEEL *)wheel);
925 }
926 else
927 {
928 _gx_text_scroll_wheel_flat_draw((GX_TEXT_SCROLL_WHEEL *)wheel);
929 }
930 }
931
932