2 * FreeRDP: A Remote Desktop Protocol Client
3 * GDI Clipping Functions
5 * Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 #include <freerdp/freerdp.h>
24 #include <freerdp/gdi/gdi.h>
26 #include <freerdp/gdi/region.h>
28 #include <freerdp/gdi/clipping.h>
30 int gdi_SetClipRgn(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight)
32 return gdi_SetRgn(hdc->clip, nXLeft, nYLeft, nWidth, nHeight);
36 * Get the current clipping region.\n
38 * @param hdc device context
39 * @return clipping region
42 HGDI_RGN gdi_GetClipRgn(HGDI_DC hdc)
48 * Set the current clipping region to null.
49 * @param hdc device context
53 int gdi_SetNullClipRgn(HGDI_DC hdc)
55 gdi_SetClipRgn(hdc, 0, 0, 0, 0);
61 * Clip coordinates according to clipping region
62 * @param hdc device context
67 * @param srcx source x1
68 * @param srcy source y1
69 * @return 1 if there is something to draw, 0 otherwise
72 int gdi_ClipCoords(HGDI_DC hdc, int *x, int *y, int *w, int *h, int *srcx, int *srcy)
86 hBmp = (HGDI_BITMAP) hdc->selectedObject;
92 gdi_CRgnToRect(0, 0, hBmp->width, hBmp->height, &clip);
96 gdi_RgnToRect(hdc->clip, &clip);
97 gdi_CRgnToRect(0, 0, hBmp->width, hBmp->height, &bmp);
99 if (clip.left < bmp.left)
100 clip.left = bmp.left;
102 if (clip.right > bmp.right)
103 clip.right = bmp.right;
105 if (clip.top < bmp.top)
108 if (clip.bottom > bmp.bottom)
109 clip.bottom = bmp.bottom;
114 gdi_RgnToRect(hdc->clip, &clip);
117 gdi_CRgnToRect(*x, *y, *w, *h, &coords);
119 if (coords.right >= clip.left && coords.left <= clip.right &&
120 coords.bottom >= clip.top && coords.top <= clip.bottom)
122 /* coordinates overlap with clipping region */
124 if (coords.left < clip.left)
126 dx = (clip.left - coords.left) + 1;
127 coords.left = clip.left;
130 if (coords.right > clip.right)
131 coords.right = clip.right;
133 if (coords.top < clip.top)
135 dy = (clip.top - coords.top) + 1;
136 coords.top = clip.top;
139 if (coords.bottom > clip.bottom)
140 coords.bottom = clip.bottom;
144 /* coordinates do not overlap with clipping region */
169 gdi_RectToCRgn(&coords, x, y, w, h);