1 
2 /***************************************************************************
3  * Copyright (c) 2024 Microsoft Corporation
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the MIT License which is available at
7  * https://opensource.org/licenses/MIT.
8  *
9  * SPDX-License-Identifier: MIT
10  **************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Dispaly Management (Dispaly)                                        */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_display.h"
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_display_driver_8bpp_mouse_capture               PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This service captures canvas memory under mouse position.           */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    display                               Display control block         */
47 /*                                                                        */
48 /*  OUTPUT                                                                */
49 /*                                                                        */
50 /*  CALLS                                                                 */
51 /*                                                                        */
52 /*                                                                        */
53 /*  CALLED BY                                                             */
54 /*                                                                        */
55 /*    GUIX Internal Code                                                  */
56 /*                                                                        */
57 /*  RELEASE HISTORY                                                       */
58 /*                                                                        */
59 /*    DATE              NAME                      DESCRIPTION             */
60 /*                                                                        */
61 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
62 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
63 /*                                            resulting in version 6.1    */
64 /*                                                                        */
65 /**************************************************************************/
66 #if defined(GX_MOUSE_SUPPORT)
67 #if !defined(GX_HARDWARE_MOUSE_SUPPORT)
_gx_display_driver_8bpp_mouse_capture(GX_DISPLAY * display)68 VOID _gx_display_driver_8bpp_mouse_capture(GX_DISPLAY  *display)
69 {
70 INT            width;
71 INT            height;
72 INT            row;
73 INT            column;
74 GX_UBYTE      *put;
75 GX_UBYTE      *getrow;
76 GX_UBYTE      *get;
77 GX_PIXELMAP   *map;
78 GX_RESOURCE_ID image_id;
79 GX_RECTANGLE   mouse_rect;
80 GX_CANVAS     *canvas;
81 
82     if (display -> gx_display_mouse.gx_mouse_cursor_info)
83     {
84         if (display -> gx_display_mouse.gx_mouse_capture_memory)
85         {
86             canvas = display -> gx_display_mouse.gx_mouse_canvas;
87             image_id = display -> gx_display_mouse.gx_mouse_cursor_info -> gx_mouse_cursor_image_id;
88 
89             if (image_id && image_id < display -> gx_display_pixelmap_table_size)
90             {
91                 map = display -> gx_display_pixelmap_table[image_id];
92 
93                 mouse_rect.gx_rectangle_left = display -> gx_display_mouse.gx_mouse_position.gx_point_x;
94                 mouse_rect.gx_rectangle_top = display -> gx_display_mouse.gx_mouse_position.gx_point_y;
95                 mouse_rect.gx_rectangle_left = (GX_VALUE)(mouse_rect.gx_rectangle_left - display -> gx_display_mouse.gx_mouse_cursor_info -> gx_mouse_cursor_hotspot_x);
96                 mouse_rect.gx_rectangle_top = (GX_VALUE)(mouse_rect.gx_rectangle_top - display -> gx_display_mouse.gx_mouse_cursor_info -> gx_mouse_cursor_hotspot_y);
97 
98                 mouse_rect.gx_rectangle_right = (GX_VALUE)(mouse_rect.gx_rectangle_left + map -> gx_pixelmap_width - 1);
99                 mouse_rect.gx_rectangle_bottom = (GX_VALUE)(mouse_rect.gx_rectangle_top + map -> gx_pixelmap_height - 1);
100 
101                 if (mouse_rect.gx_rectangle_left < 0)
102                 {
103                     mouse_rect.gx_rectangle_left = 0;
104                 }
105                 if (mouse_rect.gx_rectangle_top < 0)
106                 {
107                     mouse_rect.gx_rectangle_top = 0;
108                 }
109                 if (mouse_rect.gx_rectangle_right >= canvas -> gx_canvas_x_resolution)
110                 {
111                     mouse_rect.gx_rectangle_right = (GX_VALUE)(canvas -> gx_canvas_x_resolution - 1);
112                 }
113                 if (mouse_rect.gx_rectangle_bottom >= canvas -> gx_canvas_y_resolution)
114                 {
115                     mouse_rect.gx_rectangle_bottom = (GX_VALUE)(canvas -> gx_canvas_y_resolution - 1);
116                 }
117                 width = mouse_rect.gx_rectangle_right - mouse_rect.gx_rectangle_left + 1;
118                 height = mouse_rect.gx_rectangle_bottom - mouse_rect.gx_rectangle_top + 1;
119             }
120             else
121             {
122                 width = height = 0;
123             }
124 
125             if (width > 0 && height > 0)
126             {
127                 display -> gx_display_mouse.gx_mouse_rect = mouse_rect;
128 
129                 getrow = (GX_UBYTE *)canvas -> gx_canvas_memory;
130                 getrow += canvas -> gx_canvas_x_resolution * mouse_rect.gx_rectangle_top;
131                 getrow += mouse_rect.gx_rectangle_left;
132                 put = (GX_UBYTE *)display -> gx_display_mouse.gx_mouse_capture_memory;
133 
134                 for (row = 0; row < height; row++)
135                 {
136                     get = getrow;
137                     for (column = 0; column < width; column++)
138                     {
139                         *put++ = *get++;
140                     }
141                     getrow += canvas -> gx_canvas_x_resolution;
142                 }
143             }
144             else
145             {
146                 display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_top = 0;
147                 display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_bottom = -1;
148                 display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_left = 0;
149                 display -> gx_display_mouse.gx_mouse_rect.gx_rectangle_right = -1;
150             }
151         }
152     }
153 }
154 #endif
155 #endif
156 
157