FreeRDP
Loading...
Searching...
No Matches
clipping.c
1
22#include <freerdp/config.h>
23
24#include <stdio.h>
25#include <string.h>
26#include <stdlib.h>
27
28#include <freerdp/freerdp.h>
29#include <freerdp/gdi/gdi.h>
30
31#include <freerdp/gdi/region.h>
32
33#include "clipping.h"
34
35BOOL gdi_SetClipRgn(HGDI_DC hdc, INT32 nXLeft, INT32 nYLeft, INT32 nWidth, INT32 nHeight)
36{
37 return gdi_SetRgn(hdc->clip, nXLeft, nYLeft, nWidth, nHeight);
38}
39
48GDI_RGN* gdi_GetClipRgn(HGDI_DC hdc)
49{
50 return hdc->clip;
51}
52
59BOOL gdi_SetNullClipRgn(HGDI_DC hdc)
60{
61 if (!gdi_SetClipRgn(hdc, 0, 0, 0, 0))
62 return FALSE;
63 hdc->clip->null = TRUE;
64 return TRUE;
65}
66
79BOOL gdi_ClipCoords(HGDI_DC hdc, INT32* x, INT32* y, INT32* w, INT32* h, INT32* srcx, INT32* srcy)
80{
81 GDI_RECT bmp = WINPR_C_ARRAY_INIT;
82 GDI_RECT clip = WINPR_C_ARRAY_INIT;
83 GDI_RECT coords = WINPR_C_ARRAY_INIT;
84 int dx = 0;
85 int dy = 0;
86 BOOL draw = TRUE;
87
88 if (hdc == nullptr)
89 return FALSE;
90
91 HGDI_BITMAP hBmp = (HGDI_BITMAP)hdc->selectedObject;
92
93 if (hBmp != nullptr)
94 {
95 if (hdc->clip->null)
96 {
97 if (!gdi_CRgnToRect(0, 0, hBmp->width, hBmp->height, &clip))
98 return TRUE;
99 }
100 else
101 {
102 if (!gdi_RgnToRect(hdc->clip, &clip))
103 return TRUE;
104 if (!gdi_CRgnToRect(0, 0, hBmp->width, hBmp->height, &bmp))
105 return TRUE;
106
107 if (clip.left < bmp.left)
108 clip.left = bmp.left;
109
110 if (clip.right > bmp.right)
111 clip.right = bmp.right;
112
113 if (clip.top < bmp.top)
114 clip.top = bmp.top;
115
116 if (clip.bottom > bmp.bottom)
117 clip.bottom = bmp.bottom;
118 }
119 }
120 else
121 {
122 if (!gdi_RgnToRect(hdc->clip, &clip))
123 return TRUE;
124 }
125
126 if (!gdi_CRgnToRect(*x, *y, *w, *h, &coords))
127 return TRUE;
128
129 if (coords.right >= clip.left && coords.left <= clip.right && coords.bottom >= clip.top &&
130 coords.top <= clip.bottom)
131 {
132 /* coordinates overlap with clipping region */
133 if (coords.left < clip.left)
134 {
135 dx = (clip.left - coords.left);
136 coords.left = clip.left;
137 }
138
139 if (coords.right > clip.right)
140 coords.right = clip.right;
141
142 if (coords.top < clip.top)
143 {
144 dy = (clip.top - coords.top);
145 coords.top = clip.top;
146 }
147
148 if (coords.bottom > clip.bottom)
149 coords.bottom = clip.bottom;
150 }
151 else
152 {
153 /* coordinates do not overlap with clipping region */
154 coords.left = 0;
155 coords.right = 0;
156 coords.top = 0;
157 coords.bottom = 0;
158 draw = FALSE;
159 }
160
161 if (srcx != nullptr)
162 *srcx += dx;
163
164 if (srcy != nullptr)
165 *srcy += dy;
166
167 if (!gdi_RectToCRgn(&coords, x, y, w, h))
168 return FALSE;
169 return draw;
170}