source: trunk/src/gui/painting/qregion_pm.cpp@ 659

Last change on this file since 659 was 659, checked in by Dmitry A. Kuminov, 15 years ago

global: Updated year to 2010 in OS/2-specific headers.

File size: 5.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** Copyright (C) 2010 netlabs.org. OS/2 parts.
8**
9** This file is part of the QtGui module of the Qt Toolkit.
10**
11** $QT_BEGIN_LICENSE:LGPL$
12** Commercial Usage
13** Licensees holding valid Qt Commercial licenses may use this file in
14** accordance with the Qt Commercial License Agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Nokia.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 2.1 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 2.1 requirements
24** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** In addition, as a special exception, Nokia gives you certain additional
27** rights. These rights are described in the Nokia Qt LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** GNU General Public License Usage
31** Alternatively, this file may be used under the terms of the GNU
32** General Public License version 3.0 as published by the Free Software
33** Foundation and appearing in the file LICENSE.GPL included in the
34** packaging of this file. Please review the following information to
35** ensure the GNU General Public License version 3.0 requirements will be
36** met: http://www.gnu.org/copyleft/gpl.html.
37**
38** If you have questions regarding the use of this file, please contact
39** Nokia at [email protected].
40** $QT_END_LICENSE$
41**
42****************************************************************************/
43
44#include "qbitmap.h"
45#include "qbuffer.h"
46#include "qimage.h"
47#include "qpolygon.h"
48#include "qregion.h"
49
50#include "qt_os2.h"
51
52QT_BEGIN_NAMESPACE
53
54// To compensate the difference between Qt (where y axis goes downwards) and
55// GPI (where y axis goes upwards) coordinate spaces when dealing with regions
56// we use the following technique: when a GPI resource is allocated for a Qt
57// region, we simply change the sign of all y coordinates to quickly flip it
58// top to bottom in a manner that doesn't depend on the target device height.
59// All we have to do to apply the created GPI region to a particular GPI device
60// is to align its y axis to the top of the device (i.e. offset the region
61// up by the height of the device), and unalign it afterwards to bring it back
62// to the coordinate space of other device-independent (unaligned) regions.
63// To optimize this, we remember (in data->hgt) the last height value used to
64// align the region, and align it again only if the target device height
65// changes. Zero height indicates a device-independent target (such as other
66// unaligned Qt region).
67//
68// The handle() function, used for external access to the region, takes an
69// argument that must be always set to the height of the target device to
70// guarantee the correct y axis alignment.
71
72QRegion::QRegionData QRegion::shared_empty = { Q_BASIC_ATOMIC_INITIALIZER(1),
73 NULLHANDLE, 0 };
74
75/*!
76 \internal
77
78 Deletes the given region handle.
79 */
80void QRegion::disposeHandle(HRGN hrgn)
81{
82 if (hrgn != 0)
83 GpiDestroyRegion(qt_display_ps(), hrgn);
84}
85
86/*!
87 \internal
88
89 Updates the region handle so that it is suitable for selection to
90 a device with the given \a height.
91 */
92void QRegion::updateHandle(int targetHeight) const
93{
94 QRegion *self = const_cast<QRegion*>(this); // we're const here
95
96 if (d->rgn != 0) {
97 if (self->d->ref == 1) {
98 // align region y axis to the top of the device
99 POINTL ptl = { 0, targetHeight - d->height };
100 GpiOffsetRegion(qt_display_ps(), d->rgn, &ptl);
101 self->d->height = targetHeight;
102 return;
103 }
104 // create a copy since the hande may be in use (this will reset d->rgn)
105 *self = copy();
106 }
107
108 Q_ASSERT(d->rgn == 0);
109
110 // new/updated/copied Qt region data, create a new HRGN for it
111 self->d->height = targetHeight;
112 if (d->qt_rgn) {
113 if (d->qt_rgn->numRects > 0) {
114 if (d->qt_rgn->numRects == 1) {
115 // d->qt_rgn->rects is empty, use d->qt_rgn->extents instead
116 const QRect r = d->qt_rgn->extents;
117 RECTL rcl = { r.left(), d->height - (r.bottom() + 1),
118 r.right() + 1, d->height - r.top() };
119 self->d->rgn = GpiCreateRegion(qt_display_ps(), 1, &rcl);
120 } else {
121 PRECTL rcls = new RECTL[d->qt_rgn->numRects];
122 for (int i = 0; i < d->qt_rgn->numRects; ++i) {
123 QRect r = d->qt_rgn->rects.at(i);
124 // note RECTL is inclusive-exclusive here
125 rcls[i].xLeft = r.left();
126 rcls[i].yBottom = d->height - (r.bottom() + 1);
127 rcls[i].xRight = r.right() + 1;
128 rcls[i].yTop = d->height - r.top();
129 }
130 self->d->rgn = GpiCreateRegion(qt_display_ps(),
131 d->qt_rgn->numRects, rcls);
132 delete[] rcls;
133 }
134 return;
135 }
136 }
137
138 // create an empty region
139 self->d->rgn = GpiCreateRegion(qt_display_ps(), 0, NULL);
140}
141
142QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.