blob: 640d55893a4d553584cc00cbc236cb8efc725135 [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18#ifndef __REGIONHELPER_H__
19#define __REGIONHELPER_H__
20
21// RegionHelper is a class which helps in using X server regions by
22// automatically freeing them in the destructor. It also fixes a problem with
23// REGION_INIT when given an empty rectangle.
24
25class RegionHelper {
26public:
27
28 // constructor from a single rect
29 RegionHelper(ScreenPtr pScreen_, BoxPtr rect, int size)
30 : pScreen(pScreen_), reg(0)
31 {
32 init(rect, size);
33 }
34
35 // constructor from an existing X server region
36 RegionHelper(ScreenPtr pScreen_, RegionPtr pRegion)
37 : pScreen(pScreen_), reg(&regRec)
38 {
39 REGION_INIT(pScreen, reg, NullBox, 0);
40 REGION_COPY(pScreen, reg, pRegion);
41 }
42
43 // constructor from an array of rectangles
44 RegionHelper(ScreenPtr pScreen_, int nrects, xRectanglePtr rects,
45 int ctype=CT_NONE)
46 : pScreen(pScreen_)
47 {
48 reg = RECTS_TO_REGION(pScreen, nrects, rects, ctype);
49 }
50
51 // constructor for calling init() later
52 RegionHelper(ScreenPtr pScreen_) : pScreen(pScreen_), reg(0) {
53 }
54
55 void init(BoxPtr rect, int size) {
56 reg = &regRec;
57 if (rect && (rect->x2 == rect->x1 || rect->y2 == rect->y1)) {
58 REGION_INIT(pScreen, reg, NullBox, 0);
59 } else {
60 REGION_INIT(pScreen, reg, rect, size);
61 }
62 }
63
64 // destructor frees as appropriate
65 ~RegionHelper() {
66 if (reg == &regRec) {
67 REGION_UNINIT(pScreen, reg);
68 } else if (reg) {
69 REGION_DESTROY(pScreen, reg);
70 }
71 }
72 ScreenPtr pScreen;
73 RegionRec regRec;
74 RegionPtr reg;
75};
76
77#endif