2011-07-01 00:17:55 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-01 00:17:55 +04:00
|
|
|
* GDI Region Functions
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2016-04-05 18:07:45 +03:00
|
|
|
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyright 2016 Thincast Technologies GmbH
|
2011-07-01 00:17:55 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2011-08-31 12:35:50 +04:00
|
|
|
#include <freerdp/api.h>
|
2011-07-01 00:17:55 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2011-08-15 22:33:04 +04:00
|
|
|
#include <freerdp/gdi/gdi.h>
|
2011-07-01 00:17:55 +04:00
|
|
|
|
2011-08-22 21:08:01 +04:00
|
|
|
#include <freerdp/gdi/region.h>
|
2011-07-01 00:17:55 +04:00
|
|
|
|
2016-07-19 14:18:30 +03:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
|
|
|
|
#define TAG FREERDP_TAG("gdi.region")
|
|
|
|
|
2020-03-30 18:32:04 +03:00
|
|
|
static char* gdi_rect_str(char* buffer, size_t size, const HGDI_RECT rect)
|
|
|
|
{
|
2020-03-31 15:19:49 +03:00
|
|
|
if (!buffer || (size < 1) || !rect)
|
|
|
|
return NULL;
|
|
|
|
|
2024-08-26 16:39:33 +03:00
|
|
|
(void)_snprintf(buffer, size - 1,
|
|
|
|
"[top/left=%" PRId32 "x%" PRId32 "-bottom/right%" PRId32 "x%" PRId32 "]",
|
|
|
|
rect->top, rect->left, rect->bottom, rect->right);
|
2020-03-31 18:17:35 +03:00
|
|
|
buffer[size - 1] = '\0';
|
2020-03-30 18:32:04 +03:00
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
return buffer;
|
2020-03-30 18:57:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static char* gdi_regn_str(char* buffer, size_t size, const HGDI_RGN rgn)
|
|
|
|
{
|
2020-03-31 15:19:49 +03:00
|
|
|
if (!buffer || (size < 1) || !rgn)
|
|
|
|
return NULL;
|
|
|
|
|
2024-08-26 16:39:33 +03:00
|
|
|
(void)_snprintf(buffer, size - 1, "[%" PRId32 "x%" PRId32 "-%" PRId32 "x%" PRId32 "]", rgn->x,
|
|
|
|
rgn->y, rgn->w, rgn->h);
|
2020-03-31 18:17:35 +03:00
|
|
|
buffer[size - 1] = '\0';
|
2020-03-30 18:57:11 +03:00
|
|
|
|
|
|
|
return buffer;
|
2020-03-30 18:32:04 +03:00
|
|
|
}
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Create a region from rectangular coordinates.
|
|
|
|
* msdn{dd183514}
|
|
|
|
*
|
2011-07-01 00:17:55 +04:00
|
|
|
* @param nLeftRect x1
|
|
|
|
* @param nTopRect y1
|
|
|
|
* @param nRightRect x2
|
|
|
|
* @param nBottomRect y2
|
2022-12-09 16:35:03 +03:00
|
|
|
*
|
2011-07-01 00:17:55 +04:00
|
|
|
* @return new region
|
|
|
|
*/
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
HGDI_RGN gdi_CreateRectRgn(INT32 nLeftRect, INT32 nTopRect, INT32 nRightRect, INT32 nBottomRect)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT64 w = 0;
|
|
|
|
INT64 h = 0;
|
|
|
|
HGDI_RGN hRgn = NULL;
|
2020-03-30 18:57:11 +03:00
|
|
|
|
|
|
|
w = nRightRect - nLeftRect + 1ll;
|
|
|
|
h = nBottomRect - nTopRect + 1ll;
|
|
|
|
if ((w < 0) || (h < 0) || (w > INT32_MAX) || (h > INT32_MAX))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Can not create region top/left=%" PRId32 "x%" PRId32 "-bottom/right=%" PRId32
|
|
|
|
"x%" PRId32,
|
|
|
|
nTopRect, nLeftRect, nBottomRect, nRightRect);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
hRgn = (HGDI_RGN)calloc(1, sizeof(GDI_RGN));
|
2016-07-18 13:36:22 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!hRgn)
|
|
|
|
return NULL;
|
2015-06-16 16:42:07 +03:00
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
hRgn->objectType = GDIOBJECT_REGION;
|
|
|
|
hRgn->x = nLeftRect;
|
|
|
|
hRgn->y = nTopRect;
|
2020-03-30 18:57:11 +03:00
|
|
|
hRgn->w = w;
|
|
|
|
hRgn->h = h;
|
2016-10-06 14:41:52 +03:00
|
|
|
hRgn->null = FALSE;
|
2011-07-01 00:17:55 +04:00
|
|
|
return hRgn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new rectangle.
|
|
|
|
* @param xLeft x1
|
|
|
|
* @param yTop y1
|
|
|
|
* @param xRight x2
|
|
|
|
* @param yBottom y2
|
|
|
|
* @return new rectangle
|
|
|
|
*/
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
HGDI_RECT gdi_CreateRect(INT32 xLeft, INT32 yTop, INT32 xRight, INT32 yBottom)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
HGDI_RECT hRect = NULL;
|
2020-03-31 18:17:35 +03:00
|
|
|
|
|
|
|
if (xLeft > xRight)
|
|
|
|
return NULL;
|
|
|
|
if (yTop > yBottom)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hRect = (HGDI_RECT)calloc(1, sizeof(GDI_RECT));
|
2016-07-18 13:36:22 +03:00
|
|
|
|
2015-04-17 17:21:55 +03:00
|
|
|
if (!hRect)
|
|
|
|
return NULL;
|
2015-06-16 16:42:07 +03:00
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
hRect->objectType = GDIOBJECT_RECT;
|
|
|
|
hRect->left = xLeft;
|
|
|
|
hRect->top = yTop;
|
|
|
|
hRect->right = xRight;
|
|
|
|
hRect->bottom = yBottom;
|
|
|
|
return hRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a rectangle to a region.
|
|
|
|
* @param rect source rectangle
|
|
|
|
* @param rgn destination region
|
|
|
|
*/
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL gdi_RectToRgn(const HGDI_RECT rect, HGDI_RGN rgn)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL rc = TRUE;
|
2024-01-23 18:49:54 +03:00
|
|
|
INT64 w = 0;
|
|
|
|
INT64 h = 0;
|
2020-03-30 18:57:11 +03:00
|
|
|
w = rect->right - rect->left + 1ll;
|
|
|
|
h = rect->bottom - rect->top + 1ll;
|
|
|
|
|
|
|
|
if ((w < 0) || (h < 0) || (w > INT32_MAX) || (h > INT32_MAX))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Can not create region top/left=%" PRId32 "x%" PRId32 "-bottom/right=%" PRId32
|
|
|
|
"x%" PRId32,
|
|
|
|
rect->top, rect->left, rect->bottom, rect->right);
|
|
|
|
w = 0;
|
|
|
|
h = 0;
|
2020-03-31 18:17:35 +03:00
|
|
|
rc = FALSE;
|
2020-03-30 18:57:11 +03:00
|
|
|
}
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
rgn->x = rect->left;
|
|
|
|
rgn->y = rect->top;
|
2020-03-30 18:57:11 +03:00
|
|
|
rgn->w = w;
|
|
|
|
rgn->h = h;
|
2020-03-31 18:17:35 +03:00
|
|
|
|
|
|
|
return rc;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert rectangular coordinates to a region.
|
|
|
|
* @param left x1
|
|
|
|
* @param top y1
|
|
|
|
* @param right x2
|
|
|
|
* @param bottom y2
|
|
|
|
* @param rgn destination region
|
|
|
|
*/
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL gdi_CRectToRgn(INT32 left, INT32 top, INT32 right, INT32 bottom, HGDI_RGN rgn)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL rc = TRUE;
|
2024-01-23 18:49:54 +03:00
|
|
|
INT64 w = 0;
|
|
|
|
INT64 h = 0;
|
2020-03-30 18:57:11 +03:00
|
|
|
w = right - left + 1ll;
|
|
|
|
h = bottom - top + 1ll;
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
if (!rgn)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-03-30 18:57:11 +03:00
|
|
|
if ((w < 0) || (h < 0) || (w > INT32_MAX) || (h > INT32_MAX))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Can not create region top/left=%" PRId32 "x%" PRId32 "-bottom/right=%" PRId32
|
|
|
|
"x%" PRId32,
|
|
|
|
top, left, bottom, right);
|
|
|
|
w = 0;
|
|
|
|
h = 0;
|
2020-03-31 18:17:35 +03:00
|
|
|
rc = FALSE;
|
2020-03-30 18:57:11 +03:00
|
|
|
}
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
rgn->x = left;
|
|
|
|
rgn->y = top;
|
2020-03-30 18:57:11 +03:00
|
|
|
rgn->w = w;
|
|
|
|
rgn->h = h;
|
2020-03-31 18:17:35 +03:00
|
|
|
return rc;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a rectangle to region coordinates.
|
|
|
|
* @param rect source rectangle
|
|
|
|
* @param x x1
|
|
|
|
* @param y y1
|
|
|
|
* @param w width
|
|
|
|
* @param h height
|
|
|
|
*/
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL gdi_RectToCRgn(const HGDI_RECT rect, INT32* x, INT32* y, INT32* w, INT32* h)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL rc = TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
*x = rect->left;
|
|
|
|
*y = rect->top;
|
2023-06-05 13:16:57 +03:00
|
|
|
INT64 tmp = rect->right - rect->left + 1;
|
2020-03-30 18:32:04 +03:00
|
|
|
if ((tmp < 0) || (tmp > INT32_MAX))
|
|
|
|
{
|
|
|
|
char buffer[256];
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "rectangle invalid %s", gdi_rect_str(buffer, sizeof(buffer), rect));
|
2020-03-30 18:32:04 +03:00
|
|
|
*w = 0;
|
2020-03-31 18:17:35 +03:00
|
|
|
rc = FALSE;
|
2020-03-30 18:32:04 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*w = tmp;
|
|
|
|
tmp = rect->bottom - rect->top + 1;
|
|
|
|
if ((tmp < 0) || (tmp > INT32_MAX))
|
|
|
|
{
|
|
|
|
char buffer[256];
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "rectangle invalid %s", gdi_rect_str(buffer, sizeof(buffer), rect));
|
2020-03-30 18:32:04 +03:00
|
|
|
*h = 0;
|
2020-03-31 18:17:35 +03:00
|
|
|
rc = FALSE;
|
2020-03-30 18:32:04 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*h = tmp;
|
2020-03-31 18:17:35 +03:00
|
|
|
return rc;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert rectangular coordinates to region coordinates.
|
|
|
|
* @param left x1
|
|
|
|
* @param top y1
|
|
|
|
* @param right x2
|
|
|
|
* @param bottom y2
|
|
|
|
* @param x x1
|
|
|
|
* @param y y1
|
|
|
|
* @param w width
|
|
|
|
* @param h height
|
|
|
|
*/
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL gdi_CRectToCRgn(INT32 left, INT32 top, INT32 right, INT32 bottom, INT32* x, INT32* y, INT32* w,
|
|
|
|
INT32* h)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT64 wl = 0;
|
|
|
|
INT64 hl = 0;
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL rc = TRUE;
|
2020-03-30 18:57:11 +03:00
|
|
|
wl = right - left + 1ll;
|
|
|
|
hl = bottom - top + 1ll;
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
if ((left > right) || (top > bottom) || (wl <= 0) || (hl <= 0) || (wl > INT32_MAX) ||
|
|
|
|
(hl > INT32_MAX))
|
2020-03-30 18:57:11 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Can not create region top/left=%" PRId32 "x%" PRId32 "-bottom/right=%" PRId32
|
|
|
|
"x%" PRId32,
|
|
|
|
top, left, bottom, right);
|
2020-03-31 18:17:35 +03:00
|
|
|
wl = 0;
|
|
|
|
hl = 0;
|
|
|
|
rc = FALSE;
|
2020-03-30 18:57:11 +03:00
|
|
|
}
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
*x = left;
|
|
|
|
*y = top;
|
2020-03-30 18:57:11 +03:00
|
|
|
*w = wl;
|
|
|
|
*h = hl;
|
2020-03-31 18:17:35 +03:00
|
|
|
return rc;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a region to a rectangle.
|
|
|
|
* @param rgn source region
|
|
|
|
* @param rect destination rectangle
|
|
|
|
*/
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL gdi_RgnToRect(const HGDI_RGN rgn, HGDI_RECT rect)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT64 r = 0;
|
|
|
|
INT64 b = 0;
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL rc = TRUE;
|
2020-03-30 18:57:11 +03:00
|
|
|
r = rgn->x + rgn->w - 1ll;
|
|
|
|
b = rgn->y + rgn->h - 1ll;
|
|
|
|
|
|
|
|
if ((r < INT32_MIN) || (r > INT32_MAX) || (b < INT32_MIN) || (b > INT32_MAX))
|
|
|
|
{
|
|
|
|
char buffer[256];
|
|
|
|
WLog_ERR(TAG, "Can not create region %s", gdi_regn_str(buffer, sizeof(buffer), rgn));
|
|
|
|
r = rgn->x;
|
|
|
|
b = rgn->y;
|
2020-03-31 18:17:35 +03:00
|
|
|
rc = FALSE;
|
2020-03-30 18:57:11 +03:00
|
|
|
}
|
2011-07-01 00:17:55 +04:00
|
|
|
rect->left = rgn->x;
|
|
|
|
rect->top = rgn->y;
|
2020-03-30 18:57:11 +03:00
|
|
|
rect->right = r;
|
|
|
|
rect->bottom = b;
|
2020-03-31 18:17:35 +03:00
|
|
|
|
|
|
|
return rc;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert region coordinates to a rectangle.
|
|
|
|
* @param x x1
|
|
|
|
* @param y y1
|
|
|
|
* @param w width
|
|
|
|
* @param h height
|
|
|
|
* @param rect destination rectangle
|
|
|
|
*/
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
INLINE BOOL gdi_CRgnToRect(INT64 x, INT64 y, INT32 w, INT32 h, HGDI_RECT rect)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2018-01-08 10:57:45 +03:00
|
|
|
BOOL invalid = FALSE;
|
2017-12-22 15:43:37 +03:00
|
|
|
const INT64 r = x + w - 1;
|
|
|
|
const INT64 b = y + h - 1;
|
|
|
|
rect->left = (x > 0) ? x : 0;
|
|
|
|
rect->top = (y > 0) ? y : 0;
|
2018-01-08 10:57:45 +03:00
|
|
|
rect->right = rect->left;
|
|
|
|
rect->bottom = rect->top;
|
2016-07-18 13:36:22 +03:00
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
if ((w <= 0) || (h <= 0))
|
|
|
|
invalid = TRUE;
|
|
|
|
|
2017-12-22 15:43:37 +03:00
|
|
|
if (r > 0)
|
|
|
|
rect->right = r;
|
2016-07-19 14:02:08 +03:00
|
|
|
else
|
2018-01-08 10:57:45 +03:00
|
|
|
invalid = TRUE;
|
2016-07-18 13:36:22 +03:00
|
|
|
|
2017-12-22 15:43:37 +03:00
|
|
|
if (b > 0)
|
|
|
|
rect->bottom = b;
|
2016-07-19 14:02:08 +03:00
|
|
|
else
|
2018-01-08 10:57:45 +03:00
|
|
|
invalid = TRUE;
|
|
|
|
|
|
|
|
if (invalid)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_DBG(TAG, "Invisible rectangle %" PRId64 "x%" PRId64 "-%" PRId64 "x%" PRId64, x, y, r,
|
|
|
|
b);
|
2020-03-31 18:17:35 +03:00
|
|
|
return FALSE;
|
2018-01-08 10:57:45 +03:00
|
|
|
}
|
2020-03-31 18:17:35 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a region to rectangular coordinates.
|
|
|
|
* @param rgn source region
|
|
|
|
* @param left x1
|
|
|
|
* @param top y1
|
|
|
|
* @param right x2
|
|
|
|
* @param bottom y2
|
|
|
|
*/
|
|
|
|
|
2021-10-04 15:43:32 +03:00
|
|
|
BOOL gdi_RgnToCRect(const HGDI_RGN rgn, INT32* left, INT32* top, INT32* right, INT32* bottom)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL rc = TRUE;
|
2020-03-30 18:57:11 +03:00
|
|
|
if ((rgn->w < 0) || (rgn->h < 0))
|
|
|
|
{
|
|
|
|
char buffer[256];
|
|
|
|
WLog_ERR(TAG, "Can not create region %s", gdi_regn_str(buffer, sizeof(buffer), rgn));
|
2020-03-31 18:17:35 +03:00
|
|
|
rc = FALSE;
|
2020-03-30 18:57:11 +03:00
|
|
|
}
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
*left = rgn->x;
|
|
|
|
*top = rgn->y;
|
|
|
|
*right = rgn->x + rgn->w - 1;
|
|
|
|
*bottom = rgn->y + rgn->h - 1;
|
2020-03-31 18:17:35 +03:00
|
|
|
|
|
|
|
return rc;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert region coordinates to rectangular coordinates.
|
|
|
|
* @param x x1
|
|
|
|
* @param y y1
|
|
|
|
* @param w width
|
|
|
|
* @param h height
|
|
|
|
* @param left x1
|
|
|
|
* @param top y1
|
|
|
|
* @param right x2
|
|
|
|
* @param bottom y2
|
|
|
|
*/
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
INLINE BOOL gdi_CRgnToCRect(INT32 x, INT32 y, INT32 w, INT32 h, INT32* left, INT32* top,
|
2019-11-06 17:24:51 +03:00
|
|
|
INT32* right, INT32* bottom)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2020-03-31 18:17:35 +03:00
|
|
|
BOOL rc = TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
*left = x;
|
|
|
|
*top = y;
|
2016-07-19 14:18:30 +03:00
|
|
|
*right = 0;
|
|
|
|
|
|
|
|
if (w > 0)
|
|
|
|
*right = x + w - 1;
|
|
|
|
else
|
2020-03-31 18:17:35 +03:00
|
|
|
{
|
2016-07-19 14:18:30 +03:00
|
|
|
WLog_ERR(TAG, "Invalid width");
|
2020-03-31 18:17:35 +03:00
|
|
|
rc = FALSE;
|
|
|
|
}
|
2016-07-19 14:18:30 +03:00
|
|
|
|
|
|
|
*bottom = 0;
|
|
|
|
|
|
|
|
if (h > 0)
|
|
|
|
*bottom = y + h - 1;
|
|
|
|
else
|
2020-03-31 18:17:35 +03:00
|
|
|
{
|
2016-07-19 14:18:30 +03:00
|
|
|
WLog_ERR(TAG, "Invalid height");
|
2020-03-31 18:17:35 +03:00
|
|
|
rc = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if copying would involve overlapping regions
|
|
|
|
* @param x x1
|
|
|
|
* @param y y1
|
|
|
|
* @param width width
|
|
|
|
* @param height height
|
|
|
|
* @param srcx source x1
|
|
|
|
* @param srcy source y1
|
2015-06-26 15:32:38 +03:00
|
|
|
* @return nonzero if there is an overlap, 0 otherwise
|
2011-07-01 00:17:55 +04:00
|
|
|
*/
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
INLINE BOOL gdi_CopyOverlap(INT32 x, INT32 y, INT32 width, INT32 height, INT32 srcx, INT32 srcy)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
|
|
|
GDI_RECT dst;
|
|
|
|
GDI_RECT src;
|
|
|
|
gdi_CRgnToRect(x, y, width, height, &dst);
|
|
|
|
gdi_CRgnToRect(srcx, srcy, width, height, &src);
|
2020-03-31 18:17:35 +03:00
|
|
|
|
|
|
|
if (dst.right < src.left)
|
|
|
|
return FALSE;
|
|
|
|
if (dst.left > src.right)
|
|
|
|
return FALSE;
|
|
|
|
if (dst.bottom < src.top)
|
|
|
|
return FALSE;
|
|
|
|
if (dst.top > src.bottom)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Set the coordinates of a given rectangle.
|
|
|
|
* msdn{dd145085}
|
|
|
|
*
|
2011-07-01 00:17:55 +04:00
|
|
|
* @param rc rectangle
|
|
|
|
* @param xLeft x1
|
|
|
|
* @param yTop y1
|
|
|
|
* @param xRight x2
|
|
|
|
* @param yBottom y2
|
2022-12-09 16:35:03 +03:00
|
|
|
*
|
2015-06-26 15:32:38 +03:00
|
|
|
* @return nonzero if successful, 0 otherwise
|
2011-07-01 00:17:55 +04:00
|
|
|
*/
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
INLINE BOOL gdi_SetRect(HGDI_RECT rc, INT32 xLeft, INT32 yTop, INT32 xRight, INT32 yBottom)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2020-03-31 18:17:35 +03:00
|
|
|
if (!rc)
|
|
|
|
return FALSE;
|
|
|
|
if (xLeft > xRight)
|
|
|
|
return FALSE;
|
|
|
|
if (yTop > yBottom)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
rc->left = xLeft;
|
|
|
|
rc->top = yTop;
|
|
|
|
rc->right = xRight;
|
|
|
|
rc->bottom = yBottom;
|
2015-06-26 15:32:38 +03:00
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the coordinates of a given region.
|
|
|
|
* @param hRgn region
|
|
|
|
* @param nXLeft x1
|
|
|
|
* @param nYLeft y1
|
|
|
|
* @param nWidth width
|
|
|
|
* @param nHeight height
|
2015-06-26 15:32:38 +03:00
|
|
|
* @return nonzero if successful, 0 otherwise
|
2011-07-01 00:17:55 +04:00
|
|
|
*/
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
INLINE BOOL gdi_SetRgn(HGDI_RGN hRgn, INT32 nXLeft, INT32 nYLeft, INT32 nWidth, INT32 nHeight)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2020-03-31 18:17:35 +03:00
|
|
|
if (!hRgn)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ((nWidth < 0) || (nHeight < 0))
|
|
|
|
return FALSE;
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
hRgn->x = nXLeft;
|
|
|
|
hRgn->y = nYLeft;
|
|
|
|
hRgn->w = nWidth;
|
|
|
|
hRgn->h = nHeight;
|
2016-10-06 14:41:52 +03:00
|
|
|
hRgn->null = FALSE;
|
2015-06-26 15:32:38 +03:00
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert rectangular coordinates to a region
|
|
|
|
* @param hRgn destination region
|
|
|
|
* @param nLeftRect x1
|
|
|
|
* @param nTopRect y1
|
|
|
|
* @param nRightRect x2
|
|
|
|
* @param nBottomRect y2
|
2015-06-26 15:32:38 +03:00
|
|
|
* @return nonzero if successful, 0 otherwise
|
2011-07-01 00:17:55 +04:00
|
|
|
*/
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
INLINE BOOL gdi_SetRectRgn(HGDI_RGN hRgn, INT32 nLeftRect, INT32 nTopRect, INT32 nRightRect,
|
|
|
|
INT32 nBottomRect)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2020-03-31 18:17:35 +03:00
|
|
|
if (!gdi_CRectToRgn(nLeftRect, nTopRect, nRightRect, nBottomRect, hRgn))
|
|
|
|
return FALSE;
|
2016-10-06 14:41:52 +03:00
|
|
|
hRgn->null = FALSE;
|
2015-06-26 15:32:38 +03:00
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* @brief Compare two regions for equality.
|
|
|
|
* msdn{dd162700}
|
|
|
|
*
|
2011-07-01 00:17:55 +04:00
|
|
|
* @param hSrcRgn1 first region
|
|
|
|
* @param hSrcRgn2 second region
|
2015-06-26 15:32:38 +03:00
|
|
|
* @return nonzero if both regions are equal, 0 otherwise
|
2011-07-01 00:17:55 +04:00
|
|
|
*/
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
INLINE BOOL gdi_EqualRgn(const HGDI_RGN hSrcRgn1, const HGDI_RGN hSrcRgn2)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((hSrcRgn1->x == hSrcRgn2->x) && (hSrcRgn1->y == hSrcRgn2->y) &&
|
|
|
|
(hSrcRgn1->w == hSrcRgn2->w) && (hSrcRgn1->h == hSrcRgn2->h))
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2015-06-26 15:32:38 +03:00
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
2015-06-26 15:32:38 +03:00
|
|
|
return FALSE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* @brief Copy coordinates from a rectangle to another rectangle
|
|
|
|
* msdn{dd183481}
|
|
|
|
*
|
2011-07-01 00:17:55 +04:00
|
|
|
* @param dst destination rectangle
|
|
|
|
* @param src source rectangle
|
2015-06-26 15:32:38 +03:00
|
|
|
* @return nonzero if successful, 0 otherwise
|
2011-07-01 00:17:55 +04:00
|
|
|
*/
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
INLINE BOOL gdi_CopyRect(HGDI_RECT dst, const HGDI_RECT src)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2020-03-31 18:17:35 +03:00
|
|
|
if (!dst || !src)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
dst->left = src->left;
|
|
|
|
dst->top = src->top;
|
|
|
|
dst->right = src->right;
|
|
|
|
dst->bottom = src->bottom;
|
2015-06-26 15:32:38 +03:00
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Check if a point is inside a rectangle.
|
|
|
|
* msdn{dd162882}
|
2011-07-01 00:17:55 +04:00
|
|
|
* @param rc rectangle
|
|
|
|
* @param x point x position
|
|
|
|
* @param y point y position
|
2015-06-26 15:32:38 +03:00
|
|
|
* @return nonzero if the point is inside, 0 otherwise
|
2011-07-01 00:17:55 +04:00
|
|
|
*/
|
|
|
|
|
2020-03-31 18:17:35 +03:00
|
|
|
INLINE BOOL gdi_PtInRect(const HGDI_RECT rc, INT32 x, INT32 y)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* points on the left and top sides are considered in,
|
|
|
|
* while points on the right and bottom sides are considered out
|
|
|
|
*/
|
2020-03-31 18:17:35 +03:00
|
|
|
if ((x >= rc->left) && (x <= rc->right))
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2020-03-31 18:17:35 +03:00
|
|
|
if ((y >= rc->top) && (y <= rc->bottom))
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2015-06-26 15:32:38 +03:00
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 15:32:38 +03:00
|
|
|
return FALSE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Invalidate a given region, such that it is redrawn on the next region update.
|
|
|
|
* msdn{dd145003}
|
2011-07-01 00:17:55 +04:00
|
|
|
* @param hdc device context
|
|
|
|
* @param x x1
|
|
|
|
* @param y y1
|
|
|
|
* @param w width
|
|
|
|
* @param h height
|
2015-06-26 15:32:38 +03:00
|
|
|
* @return nonzero on success, 0 otherwise
|
2011-07-01 00:17:55 +04:00
|
|
|
*/
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
INLINE BOOL gdi_InvalidateRegion(HGDI_DC hdc, INT32 x, INT32 y, INT32 w, INT32 h)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
|
|
|
GDI_RECT inv;
|
|
|
|
GDI_RECT rgn;
|
2024-01-23 18:49:54 +03:00
|
|
|
HGDI_RGN invalid = NULL;
|
|
|
|
HGDI_RGN cinvalid = NULL;
|
2011-07-01 00:17:55 +04:00
|
|
|
|
2014-09-12 04:12:32 +04:00
|
|
|
if (!hdc->hwnd)
|
2015-04-17 17:21:55 +03:00
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
|
2014-09-12 04:12:32 +04:00
|
|
|
if (!hdc->hwnd->invalid)
|
2015-04-17 17:21:55 +03:00
|
|
|
return TRUE;
|
2011-08-24 09:47:43 +04:00
|
|
|
|
2014-12-05 21:40:40 +03:00
|
|
|
if (w == 0 || h == 0)
|
2015-04-17 17:21:55 +03:00
|
|
|
return TRUE;
|
2014-12-05 21:40:40 +03:00
|
|
|
|
2011-08-26 21:37:23 +04:00
|
|
|
cinvalid = hdc->hwnd->cinvalid;
|
2011-08-24 09:47:43 +04:00
|
|
|
|
2019-02-07 16:18:53 +03:00
|
|
|
if ((hdc->hwnd->ninvalid + 1) > (INT64)hdc->hwnd->count)
|
2011-08-26 21:37:23 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
HGDI_RGN new_rgn = NULL;
|
2024-08-26 17:33:59 +03:00
|
|
|
size_t new_cnt = 2ULL * hdc->hwnd->count;
|
2020-04-07 09:28:11 +03:00
|
|
|
if (new_cnt > UINT32_MAX)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
new_rgn = (HGDI_RGN)realloc(cinvalid, sizeof(GDI_RGN) * new_cnt);
|
2016-07-18 13:36:22 +03:00
|
|
|
|
2015-03-11 08:55:41 +03:00
|
|
|
if (!new_rgn)
|
2015-04-17 17:21:55 +03:00
|
|
|
return FALSE;
|
2016-07-18 13:36:22 +03:00
|
|
|
|
2015-03-11 08:55:41 +03:00
|
|
|
hdc->hwnd->count = new_cnt;
|
|
|
|
cinvalid = new_rgn;
|
2011-08-24 09:47:43 +04:00
|
|
|
}
|
|
|
|
|
2011-08-26 21:37:23 +04:00
|
|
|
gdi_SetRgn(&cinvalid[hdc->hwnd->ninvalid++], x, y, w, h);
|
|
|
|
hdc->hwnd->cinvalid = cinvalid;
|
2011-07-01 00:17:55 +04:00
|
|
|
invalid = hdc->hwnd->invalid;
|
|
|
|
|
|
|
|
if (invalid->null)
|
|
|
|
{
|
|
|
|
invalid->x = x;
|
|
|
|
invalid->y = y;
|
|
|
|
invalid->w = w;
|
|
|
|
invalid->h = h;
|
2016-10-06 14:41:52 +03:00
|
|
|
invalid->null = FALSE;
|
2015-04-17 17:21:55 +03:00
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gdi_CRgnToRect(x, y, w, h, &rgn);
|
|
|
|
gdi_RgnToRect(invalid, &inv);
|
|
|
|
|
|
|
|
if (rgn.left < inv.left)
|
|
|
|
inv.left = rgn.left;
|
|
|
|
|
|
|
|
if (rgn.top < inv.top)
|
|
|
|
inv.top = rgn.top;
|
|
|
|
|
|
|
|
if (rgn.right > inv.right)
|
|
|
|
inv.right = rgn.right;
|
|
|
|
|
|
|
|
if (rgn.bottom > inv.bottom)
|
|
|
|
inv.bottom = rgn.bottom;
|
|
|
|
|
|
|
|
gdi_RectToRgn(&inv, invalid);
|
2015-04-17 17:21:55 +03:00
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|