FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
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 gdi_SetClipRgn(hdc, 0, 0, 0, 0);
62 hdc->clip->null = TRUE;
63 return TRUE;
64}
65
78BOOL gdi_ClipCoords(HGDI_DC hdc, INT32* x, INT32* y, INT32* w, INT32* h, INT32* srcx, INT32* srcy)
79{
80 GDI_RECT bmp;
81 GDI_RECT clip;
82 GDI_RECT coords;
83 HGDI_BITMAP hBmp = NULL;
84 int dx = 0;
85 int dy = 0;
86 BOOL draw = TRUE;
87
88 if (hdc == NULL)
89 return FALSE;
90
91 hBmp = (HGDI_BITMAP)hdc->selectedObject;
92
93 if (hBmp != NULL)
94 {
95 if (hdc->clip->null)
96 {
97 gdi_CRgnToRect(0, 0, hBmp->width, hBmp->height, &clip);
98 }
99 else
100 {
101 gdi_RgnToRect(hdc->clip, &clip);
102 gdi_CRgnToRect(0, 0, hBmp->width, hBmp->height, &bmp);
103
104 if (clip.left < bmp.left)
105 clip.left = bmp.left;
106
107 if (clip.right > bmp.right)
108 clip.right = bmp.right;
109
110 if (clip.top < bmp.top)
111 clip.top = bmp.top;
112
113 if (clip.bottom > bmp.bottom)
114 clip.bottom = bmp.bottom;
115 }
116 }
117 else
118 {
119 gdi_RgnToRect(hdc->clip, &clip);
120 }
121
122 gdi_CRgnToRect(*x, *y, *w, *h, &coords);
123
124 if (coords.right >= clip.left && coords.left <= clip.right && coords.bottom >= clip.top &&
125 coords.top <= clip.bottom)
126 {
127 /* coordinates overlap with clipping region */
128 if (coords.left < clip.left)
129 {
130 dx = (clip.left - coords.left);
131 coords.left = clip.left;
132 }
133
134 if (coords.right > clip.right)
135 coords.right = clip.right;
136
137 if (coords.top < clip.top)
138 {
139 dy = (clip.top - coords.top);
140 coords.top = clip.top;
141 }
142
143 if (coords.bottom > clip.bottom)
144 coords.bottom = clip.bottom;
145 }
146 else
147 {
148 /* coordinates do not overlap with clipping region */
149 coords.left = 0;
150 coords.right = 0;
151 coords.top = 0;
152 coords.bottom = 0;
153 draw = FALSE;
154 }
155
156 if (srcx != NULL)
157 *srcx += dx;
158
159 if (srcy != NULL)
160 *srcy += dy;
161
162 gdi_RectToCRgn(&coords, x, y, w, h);
163 return draw;
164}