2 * Copyright (C) 2008 Google (Lei Zhang)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "gdiplus_private.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
33 /**********************************************************
35 * Data returned by GdipGetRegionData looks something like this:
37 * struct region_data_header
39 * DWORD size; size in bytes of the data - 8.
40 * DWORD magic1; probably a checksum.
41 * DWORD magic2; always seems to be 0xdbc01001 - version?
42 * DWORD num_ops; number of combining ops * 2
45 * Then follows a sequence of combining ops and region elements.
47 * A region element is either a RECTF or some path data.
49 * Combining ops are just stored as their CombineMode value.
51 * Each RECTF is preceded by the DWORD 0x10000000. An empty rect is
52 * stored as 0x10000002 (with no following RECTF) and an infinite rect
53 * is stored as 0x10000003 (again with no following RECTF).
55 * Path data is preceded by the DWORD 0x10000001. Then follows a
56 * DWORD size and then size bytes of data.
58 * The combining ops are stored in the reverse order to the region
59 * elements and in the reverse order to which the region was
62 * When two or more complex regions (ie those with more than one
63 * element) are combined, the combining op for the two regions comes
64 * first, then the combining ops for the region elements in region 1,
65 * followed by the region elements for region 1, then follows the
66 * combining ops for region 2 and finally region 2's region elements.
67 * Presumably you're supposed to use the 0x1000000x header to find the
68 * end of the op list (the count of the elements in each region is not
71 * When a simple region (1 element) is combined, it's treated as if a
72 * single rect/path is being combined.
76 #define FLAGS_NOFLAGS 0x0
77 #define FLAGS_INTPATH 0x4000
79 /* Header size as far as header->size is concerned. This doesn't include
80 * header->size or header->checksum
82 static const INT sizeheader_size = sizeof(DWORD) * 2;
84 typedef struct packed_point
90 /* Everything is measured in DWORDS; round up if there's a remainder */
91 static inline INT get_pathtypes_size(const GpPath* path)
93 INT needed = path->pathdata.Count / sizeof(DWORD);
95 if (path->pathdata.Count % sizeof(DWORD) > 0)
98 return needed * sizeof(DWORD);
101 static inline INT get_element_size(const region_element* element)
103 INT needed = sizeof(DWORD); /* DWORD for the type */
104 switch(element->type)
107 return needed + sizeof(GpRect);
109 needed += element->elementdata.pathdata.pathheader.size;
110 needed += sizeof(DWORD); /* Extra DWORD for pathheader.size */
112 case RegionDataEmptyRect:
113 case RegionDataInfiniteRect:
116 needed += get_element_size(element->elementdata.combine.left);
117 needed += get_element_size(element->elementdata.combine.right);
124 /* Does not check parameters, caller must do that */
125 static inline GpStatus init_region(GpRegion* region, const RegionType type)
127 region->node.type = type;
128 region->header.checksum = 0xdeadbeef;
129 region->header.magic = VERSION_MAGIC;
130 region->header.num_children = 0;
131 region->header.size = sizeheader_size + get_element_size(®ion->node);
136 static inline GpStatus clone_element(const region_element* element,
137 region_element** element2)
141 /* root node is allocated with GpRegion */
143 *element2 = GdipAlloc(sizeof(region_element));
148 (*element2)->type = element->type;
150 switch (element->type)
153 (*element2)->elementdata.rect = element->elementdata.rect;
155 case RegionDataEmptyRect:
156 case RegionDataInfiniteRect:
159 (*element2)->elementdata.pathdata.pathheader = element->elementdata.pathdata.pathheader;
160 stat = GdipClonePath(element->elementdata.pathdata.path,
161 &(*element2)->elementdata.pathdata.path);
162 if (stat != Ok) goto clone_out;
165 (*element2)->elementdata.combine.left = NULL;
166 (*element2)->elementdata.combine.right = NULL;
168 stat = clone_element(element->elementdata.combine.left,
169 &(*element2)->elementdata.combine.left);
170 if (stat != Ok) goto clone_out;
171 stat = clone_element(element->elementdata.combine.right,
172 &(*element2)->elementdata.combine.right);
173 if (stat != Ok) goto clone_out;
180 delete_element(*element2);
185 /* Common code for CombineRegion*
186 * All the caller has to do is get its format into an element
188 static inline void fuse_region(GpRegion* region, region_element* left,
189 region_element* right, const CombineMode mode)
191 region->node.type = mode;
192 region->node.elementdata.combine.left = left;
193 region->node.elementdata.combine.right = right;
195 region->header.size = sizeheader_size + get_element_size(®ion->node);
196 region->header.num_children += 2;
199 /*****************************************************************************
200 * GdipCloneRegion [GDIPLUS.@]
202 * Creates a deep copy of the region
205 * region [I] source region
206 * clone [O] resulting clone
210 * FAILURE: InvalidParameter or OutOfMemory
212 GpStatus WINGDIPAPI GdipCloneRegion(GpRegion *region, GpRegion **clone)
214 region_element *element;
216 TRACE("%p %p\n", region, clone);
218 if (!(region && clone))
219 return InvalidParameter;
221 *clone = GdipAlloc(sizeof(GpRegion));
224 element = &(*clone)->node;
226 (*clone)->header = region->header;
227 return clone_element(®ion->node, &element);
230 /*****************************************************************************
231 * GdipCombineRegionPath [GDIPLUS.@]
233 GpStatus WINGDIPAPI GdipCombineRegionPath(GpRegion *region, GpPath *path, CombineMode mode)
235 GpRegion *path_region;
236 region_element *left, *right = NULL;
239 TRACE("%p %p %d\n", region, path, mode);
241 if (!(region && path))
242 return InvalidParameter;
244 stat = GdipCreateRegionPath(path, &path_region);
248 /* simply replace region data */
249 if(mode == CombineModeReplace){
250 delete_element(®ion->node);
251 memcpy(region, path_region, sizeof(GpRegion));
255 left = GdipAlloc(sizeof(region_element));
258 *left = region->node;
260 stat = clone_element(&path_region->node, &right);
264 fuse_region(region, left, right, mode);
266 GdipDeleteRegion(path_region);
271 GdipDeleteRegion(path_region);
275 /*****************************************************************************
276 * GdipCombineRegionRect [GDIPLUS.@]
278 GpStatus WINGDIPAPI GdipCombineRegionRect(GpRegion *region,
279 GDIPCONST GpRectF *rect, CombineMode mode)
281 GpRegion *rect_region;
282 region_element *left, *right = NULL;
285 TRACE("%p %p %d\n", region, rect, mode);
287 if (!(region && rect))
288 return InvalidParameter;
290 stat = GdipCreateRegionRect(rect, &rect_region);
294 /* simply replace region data */
295 if(mode == CombineModeReplace){
296 delete_element(®ion->node);
297 memcpy(region, rect_region, sizeof(GpRegion));
301 left = GdipAlloc(sizeof(region_element));
304 memcpy(left, ®ion->node, sizeof(region_element));
306 stat = clone_element(&rect_region->node, &right);
310 fuse_region(region, left, right, mode);
312 GdipDeleteRegion(rect_region);
317 GdipDeleteRegion(rect_region);
321 /*****************************************************************************
322 * GdipCombineRegionRectI [GDIPLUS.@]
324 GpStatus WINGDIPAPI GdipCombineRegionRectI(GpRegion *region,
325 GDIPCONST GpRect *rect, CombineMode mode)
329 TRACE("%p %p %d\n", region, rect, mode);
332 return InvalidParameter;
334 rectf.X = (REAL)rect->X;
335 rectf.Y = (REAL)rect->Y;
336 rectf.Height = (REAL)rect->Height;
337 rectf.Width = (REAL)rect->Width;
339 return GdipCombineRegionRect(region, &rectf, mode);
342 /*****************************************************************************
343 * GdipCombineRegionRegion [GDIPLUS.@]
345 GpStatus WINGDIPAPI GdipCombineRegionRegion(GpRegion *region1,
346 GpRegion *region2, CombineMode mode)
348 region_element *left, *right = NULL;
352 TRACE("%p %p %d\n", region1, region2, mode);
354 if(!(region1 && region2))
355 return InvalidParameter;
357 /* simply replace region data */
358 if(mode == CombineModeReplace){
359 stat = GdipCloneRegion(region2, ®2copy);
360 if(stat != Ok) return stat;
362 delete_element(®ion1->node);
363 memcpy(region1, reg2copy, sizeof(GpRegion));
368 left = GdipAlloc(sizeof(region_element));
372 *left = region1->node;
373 stat = clone_element(®ion2->node, &right);
380 fuse_region(region1, left, right, mode);
381 region1->header.num_children += region2->header.num_children;
386 /*****************************************************************************
387 * GdipCreateRegion [GDIPLUS.@]
389 GpStatus WINGDIPAPI GdipCreateRegion(GpRegion **region)
391 TRACE("%p\n", region);
394 return InvalidParameter;
396 *region = GdipAlloc(sizeof(GpRegion));
400 return init_region(*region, RegionDataInfiniteRect);
403 /*****************************************************************************
404 * GdipCreateRegionPath [GDIPLUS.@]
406 * Creates a GpRegion from a GpPath
409 * path [I] path to base the region on
410 * region [O] pointer to the newly allocated region
414 * FAILURE: InvalidParameter
417 * If a path has no floating point points, its points will be stored as shorts
420 * If a path is empty, it is considered to be an INTPATH
422 GpStatus WINGDIPAPI GdipCreateRegionPath(GpPath *path, GpRegion **region)
424 region_element* element;
429 DWORD flags = FLAGS_INTPATH;
432 TRACE("%p, %p\n", path, region);
434 if (!(path && region))
435 return InvalidParameter;
437 *region = GdipAlloc(sizeof(GpRegion));
440 stat = init_region(*region, RegionDataPath);
443 GdipDeleteRegion(*region);
446 element = &(*region)->node;
447 count = path->pathdata.Count;
449 /* Test to see if the path is an Integer path */
452 pointsi = GdipAlloc(sizeof(GpPoint) * count);
453 pointsf = GdipAlloc(sizeof(GpPointF) * count);
454 if (!(pointsi && pointsf))
458 GdipDeleteRegion(*region);
462 stat = GdipGetPathPointsI(path, pointsi, count);
465 GdipDeleteRegion(*region);
468 stat = GdipGetPathPoints(path, pointsf, count);
471 GdipDeleteRegion(*region);
475 for (i = 0; i < count; i++)
477 if (!(pointsi[i].X == pointsf[i].X &&
478 pointsi[i].Y == pointsf[i].Y ))
480 flags = FLAGS_NOFLAGS;
488 stat = GdipClonePath(path, &element->elementdata.pathdata.path);
491 GdipDeleteRegion(*region);
495 /* 3 for headers, once again size doesn't count itself */
496 element->elementdata.pathdata.pathheader.size = ((sizeof(DWORD) * 3));
499 /* Floats, sent out as floats */
501 element->elementdata.pathdata.pathheader.size +=
502 (sizeof(DWORD) * count * 2);
504 /* INTs, sent out as packed shorts */
506 element->elementdata.pathdata.pathheader.size +=
507 (sizeof(DWORD) * count);
510 FIXME("Unhandled flags (%08x). Expect wrong results.\n", flags);
512 element->elementdata.pathdata.pathheader.size += get_pathtypes_size(path);
513 element->elementdata.pathdata.pathheader.magic = VERSION_MAGIC;
514 element->elementdata.pathdata.pathheader.count = count;
515 element->elementdata.pathdata.pathheader.flags = flags;
516 (*region)->header.size = sizeheader_size + get_element_size(element);
521 /*****************************************************************************
522 * GdipCreateRegionRect [GDIPLUS.@]
524 GpStatus WINGDIPAPI GdipCreateRegionRect(GDIPCONST GpRectF *rect,
529 TRACE("%p, %p\n", rect, region);
531 if (!(rect && region))
532 return InvalidParameter;
534 *region = GdipAlloc(sizeof(GpRegion));
535 stat = init_region(*region, RegionDataRect);
538 GdipDeleteRegion(*region);
542 (*region)->node.elementdata.rect.X = rect->X;
543 (*region)->node.elementdata.rect.Y = rect->Y;
544 (*region)->node.elementdata.rect.Width = rect->Width;
545 (*region)->node.elementdata.rect.Height = rect->Height;
550 /*****************************************************************************
551 * GdipCreateRegionRectI [GDIPLUS.@]
553 GpStatus WINGDIPAPI GdipCreateRegionRectI(GDIPCONST GpRect *rect,
558 TRACE("%p, %p\n", rect, region);
560 rectf.X = (REAL)rect->X;
561 rectf.Y = (REAL)rect->Y;
562 rectf.Width = (REAL)rect->Width;
563 rectf.Height = (REAL)rect->Height;
565 return GdipCreateRegionRect(&rectf, region);
568 GpStatus WINGDIPAPI GdipCreateRegionRgnData(GDIPCONST BYTE *data, INT size, GpRegion **region)
570 FIXME("(%p, %d, %p): stub\n", data, size, region);
573 return NotImplemented;
577 /******************************************************************************
578 * GdipCreateRegionHrgn [GDIPLUS.@]
580 GpStatus WINGDIPAPI GdipCreateRegionHrgn(HRGN hrgn, GpRegion **region)
590 TRACE("(%p, %p)\n", hrgn, region);
592 if(!region || !(size = GetRegionData(hrgn, 0, NULL)))
593 return InvalidParameter;
595 buf = GdipAlloc(size);
599 if(!GetRegionData(hrgn, size, buf)){
604 if(buf->rdh.nCount == 0){
605 if((stat = GdipCreateRegion(&local)) != Ok){
609 if((stat = GdipSetEmpty(local)) != Ok){
611 GdipDeleteRegion(local);
619 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok){
624 rect = (LPRECT)buf->Buffer;
625 for(i = 0; i < buf->rdh.nCount; i++){
626 if((stat = GdipAddPathRectangle(path, (REAL)rect->left, (REAL)rect->top,
627 (REAL)(rect->right - rect->left), (REAL)(rect->bottom - rect->top))) != Ok){
629 GdipDeletePath(path);
635 stat = GdipCreateRegionPath(path, region);
638 GdipDeletePath(path);
642 /*****************************************************************************
643 * GdipDeleteRegion [GDIPLUS.@]
645 GpStatus WINGDIPAPI GdipDeleteRegion(GpRegion *region)
647 TRACE("%p\n", region);
650 return InvalidParameter;
652 delete_element(®ion->node);
658 /*****************************************************************************
659 * GdipGetRegionBounds [GDIPLUS.@]
661 GpStatus WINGDIPAPI GdipGetRegionBounds(GpRegion *region, GpGraphics *graphics, GpRectF *rect)
667 TRACE("(%p, %p, %p)\n", region, graphics, rect);
669 if(!region || !graphics || !rect)
670 return InvalidParameter;
672 /* Contrary to MSDN, native ignores the graphics transform. */
673 status = GdipGetRegionHRgn(region, NULL, &hrgn);
679 rect->X = rect->Y = -(REAL)(1 << 22);
680 rect->Width = rect->Height = (REAL)(1 << 23);
684 if(!GetRgnBox(hrgn, &r)){
691 rect->Width = r.right - r.left;
692 rect->Height = r.bottom - r.top;
697 /*****************************************************************************
698 * GdipGetRegionBoundsI [GDIPLUS.@]
700 GpStatus WINGDIPAPI GdipGetRegionBoundsI(GpRegion *region, GpGraphics *graphics, GpRect *rect)
705 TRACE("(%p, %p, %p)\n", region, graphics, rect);
708 return InvalidParameter;
710 status = GdipGetRegionBounds(region, graphics, &rectf);
712 rect->X = roundr(rectf.X);
713 rect->Y = roundr(rectf.X);
714 rect->Width = roundr(rectf.Width);
715 rect->Height = roundr(rectf.Height);
721 static inline void write_dword(DWORD* location, INT* offset, const DWORD write)
723 location[*offset] = write;
727 static inline void write_float(DWORD* location, INT* offset, const FLOAT write)
729 ((FLOAT*)location)[*offset] = write;
733 static inline void write_packed_point(DWORD* location, INT* offset,
734 const GpPointF* write)
740 memcpy(location + *offset, &point, sizeof(packed_point));
744 static inline void write_path_types(DWORD* location, INT* offset,
747 memcpy(location + *offset, path->pathdata.Types, path->pathdata.Count);
749 /* The unwritten parts of the DWORD (if any) must be cleared */
750 if (path->pathdata.Count % sizeof(DWORD))
751 ZeroMemory(((BYTE*)location) + (*offset * sizeof(DWORD)) +
752 path->pathdata.Count,
753 sizeof(DWORD) - path->pathdata.Count % sizeof(DWORD));
754 *offset += (get_pathtypes_size(path) / sizeof(DWORD));
757 static void write_element(const region_element* element, DWORD *buffer,
760 write_dword(buffer, filled, element->type);
761 switch (element->type)
763 case CombineModeReplace:
764 case CombineModeIntersect:
765 case CombineModeUnion:
767 case CombineModeExclude:
768 case CombineModeComplement:
769 write_element(element->elementdata.combine.left, buffer, filled);
770 write_element(element->elementdata.combine.right, buffer, filled);
773 write_float(buffer, filled, element->elementdata.rect.X);
774 write_float(buffer, filled, element->elementdata.rect.Y);
775 write_float(buffer, filled, element->elementdata.rect.Width);
776 write_float(buffer, filled, element->elementdata.rect.Height);
781 const GpPath* path = element->elementdata.pathdata.path;
783 memcpy(buffer + *filled, &element->elementdata.pathdata.pathheader,
784 sizeof(element->elementdata.pathdata.pathheader));
785 *filled += sizeof(element->elementdata.pathdata.pathheader) / sizeof(DWORD);
786 switch (element->elementdata.pathdata.pathheader.flags)
789 for (i = 0; i < path->pathdata.Count; i++)
791 write_float(buffer, filled, path->pathdata.Points[i].X);
792 write_float(buffer, filled, path->pathdata.Points[i].Y);
796 for (i = 0; i < path->pathdata.Count; i++)
798 write_packed_point(buffer, filled,
799 &path->pathdata.Points[i]);
802 write_path_types(buffer, filled, path);
805 case RegionDataEmptyRect:
806 case RegionDataInfiniteRect:
811 /*****************************************************************************
812 * GdipGetRegionData [GDIPLUS.@]
814 * Returns the header, followed by combining ops and region elements.
817 * region [I] region to retrieve from
818 * buffer [O] buffer to hold the resulting data
819 * size [I] size of the buffer
820 * needed [O] (optional) how much data was written
824 * FAILURE: InvalidParameter
827 * The header contains the size, a checksum, a version string, and the number
828 * of children. The size does not count itself or the checksum.
829 * Version is always something like 0xdbc01001 or 0xdbc01002
831 * An element is a RECT, or PATH; Combining ops are stored as their
832 * CombineMode value. Special regions (infinite, empty) emit just their
833 * op-code; GpRectFs emit their code followed by their points; GpPaths emit
834 * their code followed by a second header for the path followed by the actual
835 * path data. Followed by the flags for each point. The pathheader contains
836 * the size of the data to follow, a version number again, followed by a count
837 * of how many points, and any special flags which may apply. 0x4000 means its
838 * a path of shorts instead of FLOAT.
840 * Combining Ops are stored in reverse order from when they were constructed;
841 * the output is a tree where the left side combining area is always taken
844 GpStatus WINGDIPAPI GdipGetRegionData(GpRegion *region, BYTE *buffer, UINT size,
849 TRACE("%p, %p, %d, %p\n", region, buffer, size, needed);
851 if (!(region && buffer && size))
852 return InvalidParameter;
854 memcpy(buffer, ®ion->header, sizeof(region->header));
855 filled += sizeof(region->header) / sizeof(DWORD);
856 /* With few exceptions, everything written is DWORD aligned,
857 * so use that as our base */
858 write_element(®ion->node, (DWORD*)buffer, &filled);
861 *needed = filled * sizeof(DWORD);
866 /*****************************************************************************
867 * GdipGetRegionDataSize [GDIPLUS.@]
869 GpStatus WINGDIPAPI GdipGetRegionDataSize(GpRegion *region, UINT *needed)
871 TRACE("%p, %p\n", region, needed);
873 if (!(region && needed))
874 return InvalidParameter;
876 /* header.size doesn't count header.size and header.checksum */
877 *needed = region->header.size + sizeof(DWORD) * 2;
882 static GpStatus get_path_hrgn(GpPath *path, GpGraphics *graphics, HRGN *hrgn)
894 stat = GdipCreateFromHDC(new_hdc, &graphics);
897 ReleaseDC(0, new_hdc);
902 save_state = SaveDC(graphics->hdc);
903 EndPath(graphics->hdc);
905 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
908 stat = trace_path(graphics, path);
911 *hrgn = PathToRegion(graphics->hdc);
912 stat = *hrgn ? Ok : OutOfMemory;
915 RestoreDC(graphics->hdc, save_state);
918 ReleaseDC(0, new_hdc);
919 GdipDeleteGraphics(graphics);
925 static GpStatus get_region_hrgn(struct region_element *element, GpGraphics *graphics, HRGN *hrgn)
927 switch (element->type)
929 case RegionDataInfiniteRect:
932 case RegionDataEmptyRect:
933 *hrgn = CreateRectRgn(0, 0, 0, 0);
934 return *hrgn ? Ok : OutOfMemory;
936 return get_path_hrgn(element->elementdata.pathdata.path, graphics, hrgn);
941 GpRectF* rc = &element->elementdata.rect;
943 stat = GdipCreatePath(FillModeAlternate, &path);
946 stat = GdipAddPathRectangle(path, rc->X, rc->Y, rc->Width, rc->Height);
949 stat = get_path_hrgn(path, graphics, hrgn);
951 GdipDeletePath(path);
955 case CombineModeIntersect:
956 case CombineModeUnion:
958 case CombineModeExclude:
959 case CombineModeComplement:
965 stat = get_region_hrgn(element->elementdata.combine.left, graphics, &left);
974 /* existing region is infinite */
975 switch (element->type)
977 case CombineModeIntersect:
978 return get_region_hrgn(element->elementdata.combine.right, graphics, hrgn);
979 case CombineModeXor: case CombineModeExclude:
980 FIXME("cannot exclude from an infinite region\n");
982 case CombineModeUnion: case CombineModeComplement:
988 stat = get_region_hrgn(element->elementdata.combine.right, graphics, &right);
998 /* new region is infinite */
999 switch (element->type)
1001 case CombineModeIntersect:
1004 case CombineModeXor: case CombineModeComplement:
1005 FIXME("cannot exclude from an infinite region\n");
1007 case CombineModeUnion: case CombineModeExclude:
1014 switch (element->type)
1016 case CombineModeIntersect:
1017 ret = CombineRgn(left, left, right, RGN_AND);
1019 case CombineModeUnion:
1020 ret = CombineRgn(left, left, right, RGN_OR);
1022 case CombineModeXor:
1023 ret = CombineRgn(left, left, right, RGN_XOR);
1025 case CombineModeExclude:
1026 ret = CombineRgn(left, left, right, RGN_DIFF);
1028 case CombineModeComplement:
1029 ret = CombineRgn(left, right, left, RGN_DIFF);
1035 DeleteObject(right);
1041 return GenericError;
1048 FIXME("GdipGetRegionHRgn unimplemented for region type=%x\n", element->type);
1050 return NotImplemented;
1054 /*****************************************************************************
1055 * GdipGetRegionHRgn [GDIPLUS.@]
1057 GpStatus WINGDIPAPI GdipGetRegionHRgn(GpRegion *region, GpGraphics *graphics, HRGN *hrgn)
1059 TRACE("(%p, %p, %p)\n", region, graphics, hrgn);
1061 if (!region || !hrgn)
1062 return InvalidParameter;
1064 return get_region_hrgn(®ion->node, graphics, hrgn);
1067 GpStatus WINGDIPAPI GdipIsEmptyRegion(GpRegion *region, GpGraphics *graphics, BOOL *res)
1069 TRACE("(%p, %p, %p)\n", region, graphics, res);
1071 if(!region || !graphics || !res)
1072 return InvalidParameter;
1074 *res = (region->node.type == RegionDataEmptyRect);
1079 /*****************************************************************************
1080 * GdipIsEqualRegion [GDIPLUS.@]
1082 GpStatus WINGDIPAPI GdipIsEqualRegion(GpRegion *region, GpRegion *region2, GpGraphics *graphics,
1088 TRACE("(%p, %p, %p, %p)\n", region, region2, graphics, res);
1090 if(!region || !region2 || !graphics || !res)
1091 return InvalidParameter;
1093 stat = GdipGetRegionHRgn(region, graphics, &hrgn1);
1096 stat = GdipGetRegionHRgn(region2, graphics, &hrgn2);
1098 DeleteObject(hrgn1);
1102 *res = EqualRgn(hrgn1, hrgn2);
1104 /* one of GpRegions is infinite */
1106 *res = (!hrgn1 && !hrgn2);
1108 DeleteObject(hrgn1);
1109 DeleteObject(hrgn2);
1114 /*****************************************************************************
1115 * GdipIsInfiniteRegion [GDIPLUS.@]
1117 GpStatus WINGDIPAPI GdipIsInfiniteRegion(GpRegion *region, GpGraphics *graphics, BOOL *res)
1119 /* I think graphics is ignored here */
1120 TRACE("(%p, %p, %p)\n", region, graphics, res);
1122 if(!region || !graphics || !res)
1123 return InvalidParameter;
1125 *res = (region->node.type == RegionDataInfiniteRect);
1130 /*****************************************************************************
1131 * GdipIsVisibleRegionRect [GDIPLUS.@]
1133 GpStatus WINGDIPAPI GdipIsVisibleRegionRect(GpRegion* region, REAL x, REAL y, REAL w, REAL h, GpGraphics *graphics, BOOL *res)
1139 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %p, %p)\n", region, x, y, w, h, graphics, res);
1142 return InvalidParameter;
1144 if((stat = GdipGetRegionHRgn(region, NULL, &hrgn)) != Ok)
1153 rect.left = ceilr(x);
1154 rect.top = ceilr(y);
1155 rect.right = ceilr(x + w);
1156 rect.bottom = ceilr(y + h);
1158 *res = RectInRegion(hrgn, &rect);
1165 /*****************************************************************************
1166 * GdipIsVisibleRegionRectI [GDIPLUS.@]
1168 GpStatus WINGDIPAPI GdipIsVisibleRegionRectI(GpRegion* region, INT x, INT y, INT w, INT h, GpGraphics *graphics, BOOL *res)
1170 TRACE("(%p, %d, %d, %d, %d, %p, %p)\n", region, x, y, w, h, graphics, res);
1172 return InvalidParameter;
1174 return GdipIsVisibleRegionRect(region, (REAL)x, (REAL)y, (REAL)w, (REAL)h, graphics, res);
1177 /*****************************************************************************
1178 * GdipIsVisibleRegionPoint [GDIPLUS.@]
1180 GpStatus WINGDIPAPI GdipIsVisibleRegionPoint(GpRegion* region, REAL x, REAL y, GpGraphics *graphics, BOOL *res)
1185 TRACE("(%p, %.2f, %.2f, %p, %p)\n", region, x, y, graphics, res);
1188 return InvalidParameter;
1190 if((stat = GdipGetRegionHRgn(region, NULL, &hrgn)) != Ok)
1199 *res = PtInRegion(hrgn, roundr(x), roundr(y));
1206 /*****************************************************************************
1207 * GdipIsVisibleRegionPointI [GDIPLUS.@]
1209 GpStatus WINGDIPAPI GdipIsVisibleRegionPointI(GpRegion* region, INT x, INT y, GpGraphics *graphics, BOOL *res)
1211 TRACE("(%p, %d, %d, %p, %p)\n", region, x, y, graphics, res);
1213 return GdipIsVisibleRegionPoint(region, (REAL)x, (REAL)y, graphics, res);
1216 /*****************************************************************************
1217 * GdipSetEmpty [GDIPLUS.@]
1219 GpStatus WINGDIPAPI GdipSetEmpty(GpRegion *region)
1223 TRACE("%p\n", region);
1226 return InvalidParameter;
1228 delete_element(®ion->node);
1229 stat = init_region(region, RegionDataEmptyRect);
1234 GpStatus WINGDIPAPI GdipSetInfinite(GpRegion *region)
1238 TRACE("%p\n", region);
1241 return InvalidParameter;
1243 delete_element(®ion->node);
1244 stat = init_region(region, RegionDataInfiniteRect);
1249 GpStatus WINGDIPAPI GdipTransformRegion(GpRegion *region, GpMatrix *matrix)
1251 FIXME("(%p, %p): stub\n", region, matrix);
1253 return NotImplemented;
1256 /* Translates GpRegion elements with specified offsets */
1257 static void translate_region_element(region_element* element, REAL dx, REAL dy)
1261 switch(element->type)
1263 case RegionDataEmptyRect:
1264 case RegionDataInfiniteRect:
1266 case RegionDataRect:
1267 element->elementdata.rect.X += dx;
1268 element->elementdata.rect.Y += dy;
1270 case RegionDataPath:
1271 for(i = 0; i < element->elementdata.pathdata.path->pathdata.Count; i++){
1272 element->elementdata.pathdata.path->pathdata.Points[i].X += dx;
1273 element->elementdata.pathdata.path->pathdata.Points[i].Y += dy;
1277 translate_region_element(element->elementdata.combine.left, dx, dy);
1278 translate_region_element(element->elementdata.combine.right, dx, dy);
1283 /*****************************************************************************
1284 * GdipTranslateRegion [GDIPLUS.@]
1286 GpStatus WINGDIPAPI GdipTranslateRegion(GpRegion *region, REAL dx, REAL dy)
1288 TRACE("(%p, %f, %f)\n", region, dx, dy);
1291 return InvalidParameter;
1293 translate_region_element(®ion->node, dx, dy);
1298 /*****************************************************************************
1299 * GdipTranslateRegionI [GDIPLUS.@]
1301 GpStatus WINGDIPAPI GdipTranslateRegionI(GpRegion *region, INT dx, INT dy)
1303 TRACE("(%p, %d, %d)\n", region, dx, dy);
1305 return GdipTranslateRegion(region, (REAL)dx, (REAL)dy);