sl@0
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "BMDRAW.H"
|
sl@0
|
17 |
#include "BitDrawInterfaceId.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
//The method prepares RGB value writting, calculating physical aX, aY, aWidth and aHeight.
|
sl@0
|
20 |
//The calculated coordinates are used by methods wich do not use methods in BmDraw8Scaling.cpp
|
sl@0
|
21 |
//file - WriteRgbMultiXOR(), WriteRgbMultiAND(), WriteRgbMultiOR().
|
sl@0
|
22 |
//If the scaling is "off" then it is very simple - draw physical pixels. But if the scaling is
|
sl@0
|
23 |
//"on" then a rectanngle is being drawn instead of a pixel. And rectangle coordinates are
|
sl@0
|
24 |
//calculated depending on the device' orientation.
|
sl@0
|
25 |
//aX, aY - logical coordinates.
|
sl@0
|
26 |
//aWidth, aHeight - output parameters, they will be initialized in the method's body,
|
sl@0
|
27 |
//if aDrawMode is not CGraphicsContext::EPenmode. If aDrawMode is CGraphicsContext::EPenmode,
|
sl@0
|
28 |
//then aWidth will be set with iScalingSettings.iFactorX and aheight - with
|
sl@0
|
29 |
//iScalingSettings.iFactorY.
|
sl@0
|
30 |
void CDrawBitmap::PreWriteRgb(TInt& aWidth,
|
sl@0
|
31 |
TInt& aHeight,
|
sl@0
|
32 |
TInt& aX,
|
sl@0
|
33 |
TInt& aY,
|
sl@0
|
34 |
CGraphicsContext::TDrawMode aDrawMode)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
DeOrientate(aX, aY);//aX and aY - physical coordinates
|
sl@0
|
37 |
|
sl@0
|
38 |
__ASSERT_DEBUG(aX >= 0 && aX < iSize.iWidth,Panic(EScreenDriverPanicOutOfBounds));
|
sl@0
|
39 |
__ASSERT_DEBUG(aY >= 0 && aY < iSize.iHeight,Panic(EScreenDriverPanicOutOfBounds));
|
sl@0
|
40 |
|
sl@0
|
41 |
//If scaling is ON, instead of drawing single point, rectangle with size [FactorX, FactorY]
|
sl@0
|
42 |
//is drawn. Rectangle's width and height might be swapped, depending on the orientation.
|
sl@0
|
43 |
aWidth = iScalingSettings.iFactorX;
|
sl@0
|
44 |
aHeight = iScalingSettings.iFactorY;
|
sl@0
|
45 |
|
sl@0
|
46 |
if(iScalingOff)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
return;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
//Do this additional deorientation only for not EPenmode modes and when scaling is ON!
|
sl@0
|
52 |
//EPenmode uses WriteRgb(aX,aY,aColor), which does not need any changes in
|
sl@0
|
53 |
//coordinates!
|
sl@0
|
54 |
if(!(aDrawMode & CGraphicsContext::EPenmode))
|
sl@0
|
55 |
{
|
sl@0
|
56 |
//aX, aY - physical coordinates
|
sl@0
|
57 |
//aWidth, aWidth - output parameters
|
sl@0
|
58 |
//When scaling is ON, instead of drawing single point, rectangle is drawn
|
sl@0
|
59 |
//and top-left coordinates, width and height has to be calculated.
|
sl@0
|
60 |
register TInt scalingFactorX = aWidth;
|
sl@0
|
61 |
register TInt scalingFactorY = aHeight;
|
sl@0
|
62 |
__ASSERT_DEBUG(scalingFactorX > 0, User::Invariant());
|
sl@0
|
63 |
__ASSERT_DEBUG(scalingFactorY > 0, User::Invariant());
|
sl@0
|
64 |
register CFbsDrawDevice::TOrientation orientation = iOrientation;
|
sl@0
|
65 |
|
sl@0
|
66 |
switch(orientation)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
case EOrientationRotated90:
|
sl@0
|
69 |
case EOrientationRotated270:
|
sl@0
|
70 |
{
|
sl@0
|
71 |
if(orientation == EOrientationRotated90)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
aX -= (scalingFactorX - 1);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
if(orientation == EOrientationRotated270)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
aY -= (scalingFactorY - 1);
|
sl@0
|
78 |
}
|
sl@0
|
79 |
break;
|
sl@0
|
80 |
}
|
sl@0
|
81 |
case EOrientationRotated180 :
|
sl@0
|
82 |
{
|
sl@0
|
83 |
aX -= (scalingFactorX - 1);
|
sl@0
|
84 |
aY -= (scalingFactorY - 1);
|
sl@0
|
85 |
break;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
default:
|
sl@0
|
88 |
break;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
//If the calculated coordinates are negative, set them to 0.
|
sl@0
|
91 |
if(aX < 0)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
aX = 0;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
if(aY < 0)
|
sl@0
|
96 |
{
|
sl@0
|
97 |
aY = 0;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
}
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
//Writes RGB value at the specified physical screen coordinates.
|
sl@0
|
103 |
//When scaling is ON - rectangle [aWidth, aHeight] is drawn instead of single point.
|
sl@0
|
104 |
//Depending on the orientation aWidth and aHeight might be swapped.
|
sl@0
|
105 |
//aX, aY - physical coordinates
|
sl@0
|
106 |
//aWidth, aHeight - physical
|
sl@0
|
107 |
void CDrawBitmap::WriteRgb(TInt& aWidth, TInt& aHeight,
|
sl@0
|
108 |
TInt& aX, TInt& aY, TRgb aColor,
|
sl@0
|
109 |
CGraphicsContext::TDrawMode aDrawMode)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
MapColorToUserDisplayMode(aColor);
|
sl@0
|
112 |
if(iShadowMode)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
Shadow(aColor);
|
sl@0
|
115 |
}
|
sl@0
|
116 |
if(aDrawMode&CGraphicsContext::EInvertPen)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
aColor=~aColor;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
if(aDrawMode&CGraphicsContext::EPenmode)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
WriteRgb(aX,aY,aColor);
|
sl@0
|
123 |
return;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
__ASSERT_DEBUG(aWidth > 0, User::Invariant());
|
sl@0
|
126 |
__ASSERT_DEBUG(aHeight > 0, User::Invariant());
|
sl@0
|
127 |
if(aDrawMode&CGraphicsContext::EWriteAlpha)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
// WriteRgbMulti is the only available api that writes alpha
|
sl@0
|
130 |
WriteRgbMulti(aX,aY,aWidth,aHeight,aColor);
|
sl@0
|
131 |
return;
|
sl@0
|
132 |
}
|
sl@0
|
133 |
if(aDrawMode&CGraphicsContext::EInvertScreen)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
WriteRgbMultiXOR(aX, aY, aWidth, aHeight, KRgbWhite);
|
sl@0
|
136 |
}
|
sl@0
|
137 |
if(aDrawMode&CGraphicsContext::EXor)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
WriteRgbMultiXOR(aX, aY, aWidth, aHeight, aColor);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
else if(aDrawMode&CGraphicsContext::EAnd)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
WriteRgbMultiAND(aX, aY, aWidth, aHeight, aColor);
|
sl@0
|
144 |
}
|
sl@0
|
145 |
else if(aDrawMode&CGraphicsContext::EOr)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
WriteRgbMultiOR(aX, aY, aWidth, aHeight, aColor);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
/**
|
sl@0
|
152 |
Implementation for CFbsDrawDevice::GetDrawRect().
|
sl@0
|
153 |
Gets logical coordinates of the drawing rectangle.
|
sl@0
|
154 |
If the device is not scaled and with zero origin, logocal coordinates of
|
sl@0
|
155 |
the drawing rectangle are the same as its physical coordinates.
|
sl@0
|
156 |
If the device is rotated, drawing rectangle width and height are swapped.
|
sl@0
|
157 |
Always prefer GetDrawRect() to SizeInPixels() call. SizeInPixels() will return
|
sl@0
|
158 |
drawing rectangle width and height. But if the device is scaled or with nonzero origin,
|
sl@0
|
159 |
GetDrawRect() will take into account and the top-left corner of the drawing rectangle too,
|
sl@0
|
160 |
which may not be [0, 0].
|
sl@0
|
161 |
@param aRect Upon return aRect contains drawing rectangle logical coordinates.
|
sl@0
|
162 |
*/
|
sl@0
|
163 |
void CDrawBitmap::GetDrawRect(TRect& aDrawRect) const
|
sl@0
|
164 |
{
|
sl@0
|
165 |
aDrawRect = iDrawRect;
|
sl@0
|
166 |
if (iOrientation & 1)
|
sl@0
|
167 |
{//90 or 270 degrees
|
sl@0
|
168 |
if (iOrigin.iX!=iOrigin.iY || iScalingSettings.iFactorX!=iScalingSettings.iFactorY)
|
sl@0
|
169 |
{ //When the scales are different between the dimensions the origin needs to recalculating
|
sl@0
|
170 |
aDrawRect.iTl.iX=Origin(iOrigin.iX,iScalingSettings.iFactorY);
|
sl@0
|
171 |
aDrawRect.iTl.iY=Origin(iOrigin.iY,iScalingSettings.iFactorX);
|
sl@0
|
172 |
}
|
sl@0
|
173 |
aDrawRect.SetWidth(iDrawRect.Height());
|
sl@0
|
174 |
aDrawRect.SetHeight(iDrawRect.Width());
|
sl@0
|
175 |
}
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
/**
|
sl@0
|
179 |
Implementation for MScalingSettings::Set().
|
sl@0
|
180 |
Sets scaling factor by which the drawing device should scale the drawing images.
|
sl@0
|
181 |
If you want to un-scale the device, call Set() with
|
sl@0
|
182 |
factorX = 1, factorY = 1, divisorX = 1, divisorY = 1.
|
sl@0
|
183 |
@param aFactorX Scaling factor for the X-axis of the screen device.
|
sl@0
|
184 |
@param aFactorY Scaling factor for the y-axis of the screen device.
|
sl@0
|
185 |
@param aDivisorX Not used. Should be set to 1.
|
sl@0
|
186 |
@param aDivisorY Not used. Should be set to 1.
|
sl@0
|
187 |
@return KErrNone success.
|
sl@0
|
188 |
*/
|
sl@0
|
189 |
TInt CDrawBitmap::Set(TInt aFactorX, TInt aFactorY, TInt aDivisorX, TInt aDivisorY)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
__ASSERT_DEBUG(aDivisorX == 1 && aDivisorY == 1, User::Invariant());
|
sl@0
|
192 |
__ASSERT_DEBUG(aFactorX > 0 && aFactorY > 0, User::Invariant());
|
sl@0
|
193 |
|
sl@0
|
194 |
iScalingSettings.iFactorX = aFactorX;
|
sl@0
|
195 |
iScalingSettings.iFactorY = aFactorY;
|
sl@0
|
196 |
iScalingSettings.iDivisorX = aDivisorX;
|
sl@0
|
197 |
iScalingSettings.iDivisorY = aDivisorY;
|
sl@0
|
198 |
|
sl@0
|
199 |
iScalingOff = aFactorX == 1 && aFactorY == 1 && aDivisorX == 1 && aDivisorY == 1;
|
sl@0
|
200 |
|
sl@0
|
201 |
InitLogicalCoordinates();
|
sl@0
|
202 |
|
sl@0
|
203 |
return KErrNone;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
/**
|
sl@0
|
207 |
Implementation for MScalingSettings::Get().
|
sl@0
|
208 |
Retrieves X-axis and Y-axis scaling factors.
|
sl@0
|
209 |
@param aFactorX Upon return contains X-axis scaling factor.
|
sl@0
|
210 |
@param aFactorY Upon return contains Y-axis scaling factor.
|
sl@0
|
211 |
@param aDivisorX Upon return contains the decimal fraction of X-axis scaling factor.
|
sl@0
|
212 |
@param aDivisorY Upon return contains the decimal fraction of Y-axis scaling factor.
|
sl@0
|
213 |
*/
|
sl@0
|
214 |
void CDrawBitmap::Get(TInt& aFactorX, TInt& aFactorY, TInt& aDivisorX, TInt& aDivisorY)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
aFactorX = iScalingSettings.iFactorX;
|
sl@0
|
217 |
aFactorY = iScalingSettings.iFactorY;
|
sl@0
|
218 |
aDivisorX = iScalingSettings.iDivisorX;
|
sl@0
|
219 |
aDivisorY = iScalingSettings.iDivisorY;
|
sl@0
|
220 |
}
|
sl@0
|
221 |
|
sl@0
|
222 |
/**
|
sl@0
|
223 |
Implementation for MScalingSettings::IsScalingOff().
|
sl@0
|
224 |
Notifies the caller whether the drawing device is scaled or not.
|
sl@0
|
225 |
@return ETrue Drawing device is not scaled, EFalse - it is scaled.
|
sl@0
|
226 |
*/
|
sl@0
|
227 |
TBool CDrawBitmap::IsScalingOff()
|
sl@0
|
228 |
{
|
sl@0
|
229 |
return iScalingOff;
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
/**
|
sl@0
|
233 |
Implementation for MDrawDeviceOrigin::Set().
|
sl@0
|
234 |
Sets drawing device origin.
|
sl@0
|
235 |
If you want to the default origin, call Set() with Origin (0,0).
|
sl@0
|
236 |
@param aOrigin Specifies physical coordinates of the new scaling origin
|
sl@0
|
237 |
of the drawing device. The drawing device maps the logical point [0,0] to
|
sl@0
|
238 |
the "aOrigin" physical point .
|
sl@0
|
239 |
@return KErrNone success.
|
sl@0
|
240 |
*/
|
sl@0
|
241 |
TInt CDrawBitmap::Set(const TPoint& aOrigin)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
__ASSERT_DEBUG(aOrigin.iX >= 0 && aOrigin.iY >= 0, User::Invariant());
|
sl@0
|
244 |
__ASSERT_DEBUG(aOrigin.iX < iSize.iWidth && aOrigin.iY < iSize.iHeight, User::Invariant());
|
sl@0
|
245 |
|
sl@0
|
246 |
iOrigin = aOrigin;
|
sl@0
|
247 |
|
sl@0
|
248 |
iOriginIsZero = iOrigin.iX == 0 && iOrigin.iY == 0;
|
sl@0
|
249 |
|
sl@0
|
250 |
InitLogicalCoordinates();
|
sl@0
|
251 |
|
sl@0
|
252 |
return KErrNone;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
|
sl@0
|
255 |
/**
|
sl@0
|
256 |
Implementation for MDrawDeviceOrigin::Get().
|
sl@0
|
257 |
Retrieves origin point.
|
sl@0
|
258 |
@param aOrigin Upon return contains scaling origin point.
|
sl@0
|
259 |
*/
|
sl@0
|
260 |
void CDrawBitmap::Get(TPoint& aOrigin)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
aOrigin = iOrigin;
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
//Initializes iDrawRect data member, which contains logical coordinates of
|
sl@0
|
266 |
//the drawing(screen) rectangle.
|
sl@0
|
267 |
//The method does not use iOrientation data member.
|
sl@0
|
268 |
void CDrawBitmap::InitLogicalCoordinates()
|
sl@0
|
269 |
{
|
sl@0
|
270 |
register TInt orgX = iOrigin.iX;
|
sl@0
|
271 |
register TInt orgY = iOrigin.iY;
|
sl@0
|
272 |
register TInt fX = iScalingSettings.iFactorX;
|
sl@0
|
273 |
register TInt fY = iScalingSettings.iFactorY;
|
sl@0
|
274 |
|
sl@0
|
275 |
iDrawRect.iTl.iX = Origin(orgX, fX);
|
sl@0
|
276 |
iDrawRect.iTl.iY = Origin(orgY, fY);
|
sl@0
|
277 |
iDrawRect.iBr.iX = OtherSide(orgX, iSize.iWidth, fX);
|
sl@0
|
278 |
iDrawRect.iBr.iY = OtherSide(orgY, iSize.iHeight, fY);
|
sl@0
|
279 |
if (orgX!=orgY)
|
sl@0
|
280 |
{ //The number of addressable pixels in the physical dimensions
|
sl@0
|
281 |
//Sometimes needs to be one less when rotationed by 90 or 270
|
sl@0
|
282 |
//If so set it one less all the time as the value is not recalculated
|
sl@0
|
283 |
if (fX>1)
|
sl@0
|
284 |
{ //Calculated the physical left and right of screen when rotation by 90 or 270
|
sl@0
|
285 |
//Use this width if it is smaller
|
sl@0
|
286 |
TInt left = Origin(orgY, fX);
|
sl@0
|
287 |
TInt right = OtherSide(orgY, iSize.iWidth, fX);
|
sl@0
|
288 |
iDrawRect.iBr.iX = Min(iDrawRect.iBr.iX, iDrawRect.iTl.iX+(right-left));
|
sl@0
|
289 |
}
|
sl@0
|
290 |
if (fY>1)
|
sl@0
|
291 |
{ //Calculated the physical top and bottom of screen when rotation by 90 or 270
|
sl@0
|
292 |
//Use this height if it is smaller
|
sl@0
|
293 |
TInt top = Origin(orgX, fY);
|
sl@0
|
294 |
TInt bottom = OtherSide(orgX, iSize.iHeight, fY);
|
sl@0
|
295 |
iDrawRect.iBr.iY = Min(iDrawRect.iBr.iY, iDrawRect.iTl.iY+(bottom-top));
|
sl@0
|
296 |
}
|
sl@0
|
297 |
}
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
/**
|
sl@0
|
301 |
Notifies the caller whether the drawing device can be scaled or not.
|
sl@0
|
302 |
@return ETrue Drawing device can be scaled, EFalse - it can't be scaled.
|
sl@0
|
303 |
*/
|
sl@0
|
304 |
TBool CDrawBitmap::CanBeScaled() const
|
sl@0
|
305 |
{
|
sl@0
|
306 |
//The function will return true for all display modes
|
sl@0
|
307 |
return ETrue;
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|
sl@0
|
310 |
/**
|
sl@0
|
311 |
Notifies the caller whether the drawing device origin can be moved from (0, 0) point or not.
|
sl@0
|
312 |
@return ETrue Drawing device origin can be moved, EFalse - it can't be moved.
|
sl@0
|
313 |
*/
|
sl@0
|
314 |
TBool CDrawBitmap::CanOriginBeMoved() const
|
sl@0
|
315 |
{
|
sl@0
|
316 |
//The function will return true for all display modes
|
sl@0
|
317 |
return ETrue;
|
sl@0
|
318 |
}
|
sl@0
|
319 |
|
sl@0
|
320 |
//This method calculates pixel increment value and row increment value depending
|
sl@0
|
321 |
//on the orientation. The device might be scaled. The result is returned in
|
sl@0
|
322 |
//aPixelInc and aRowInc parameters.
|
sl@0
|
323 |
void CDrawBitmap::SetPixelInc(TInt& aPixelInc, TInt& aRowInc) const
|
sl@0
|
324 |
{
|
sl@0
|
325 |
register TInt scalingFactorX = iScalingSettings.iFactorX;
|
sl@0
|
326 |
register TInt scalingFactorY = iScalingSettings.iFactorY;
|
sl@0
|
327 |
switch(iOrientation)
|
sl@0
|
328 |
{
|
sl@0
|
329 |
case EOrientationNormal:
|
sl@0
|
330 |
{
|
sl@0
|
331 |
aPixelInc = scalingFactorX;
|
sl@0
|
332 |
aRowInc = iLongWidth * scalingFactorY;
|
sl@0
|
333 |
break;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
case EOrientationRotated90:
|
sl@0
|
336 |
{
|
sl@0
|
337 |
aPixelInc = iLongWidth * scalingFactorY;
|
sl@0
|
338 |
aRowInc = -scalingFactorX;
|
sl@0
|
339 |
break;
|
sl@0
|
340 |
}
|
sl@0
|
341 |
case EOrientationRotated180:
|
sl@0
|
342 |
{
|
sl@0
|
343 |
aPixelInc = -scalingFactorX;
|
sl@0
|
344 |
aRowInc = -iLongWidth * scalingFactorY;
|
sl@0
|
345 |
break;
|
sl@0
|
346 |
}
|
sl@0
|
347 |
default: // EOrientationRotated270
|
sl@0
|
348 |
{
|
sl@0
|
349 |
aPixelInc = -iLongWidth * scalingFactorY;
|
sl@0
|
350 |
aRowInc = scalingFactorX;
|
sl@0
|
351 |
break;
|
sl@0
|
352 |
}
|
sl@0
|
353 |
}
|
sl@0
|
354 |
}
|
sl@0
|
355 |
|
sl@0
|
356 |
//Calculates "Y" increment value and assigns it to aY parameter.
|
sl@0
|
357 |
//The device might be scaled and rotated.
|
sl@0
|
358 |
//It is used by WriteBinary(), WriteBinaryOp(), ... methods and only there.
|
sl@0
|
359 |
//The method is very specific for the methods mentioned above -
|
sl@0
|
360 |
//if the device is scaled and rotated 0 or 180 degrees, Y-axis coordinate has to
|
sl@0
|
361 |
//be incremented not by 1, but by iScalingSettings.iFactorY. Because of the integer divison
|
sl@0
|
362 |
//when transforming logical to physical coordinates, incremented Y-axis coordinates may
|
sl@0
|
363 |
//go negative or greater than drawing rectangle height. Then it has to be adjusted to 0
|
sl@0
|
364 |
//or rectangle height.
|
sl@0
|
365 |
void CDrawBitmap::IncScaledY(TInt& aY, TInt aYOrg) const
|
sl@0
|
366 |
{
|
sl@0
|
367 |
const TOrientation orientation = iOrientation;
|
sl@0
|
368 |
const TInt fY = iScalingSettings.iFactorY;
|
sl@0
|
369 |
switch(orientation)
|
sl@0
|
370 |
{
|
sl@0
|
371 |
case EOrientationNormal:
|
sl@0
|
372 |
{
|
sl@0
|
373 |
aY += fY;
|
sl@0
|
374 |
const TInt height = iSize.iHeight - 1;
|
sl@0
|
375 |
if(aY > height)
|
sl@0
|
376 |
{
|
sl@0
|
377 |
aY = height;
|
sl@0
|
378 |
}
|
sl@0
|
379 |
break;
|
sl@0
|
380 |
}
|
sl@0
|
381 |
case EOrientationRotated180:
|
sl@0
|
382 |
{
|
sl@0
|
383 |
aY -= fY;
|
sl@0
|
384 |
if(aY < 0)
|
sl@0
|
385 |
{
|
sl@0
|
386 |
aY = 0;
|
sl@0
|
387 |
}
|
sl@0
|
388 |
break;
|
sl@0
|
389 |
}
|
sl@0
|
390 |
default:
|
sl@0
|
391 |
{
|
sl@0
|
392 |
aY = aYOrg;
|
sl@0
|
393 |
}
|
sl@0
|
394 |
}
|
sl@0
|
395 |
}
|
sl@0
|
396 |
|
sl@0
|
397 |
//Calculates "Y" increment value and assigns it to aY parameter.
|
sl@0
|
398 |
//The device might be scaled and rotated.
|
sl@0
|
399 |
//It is used by WriteBinary(), WriteBinaryOp(), WriteLine...() methods and only there.
|
sl@0
|
400 |
//The method is very specific for the methods mentioned above -
|
sl@0
|
401 |
//if the device is scaled and rotated 90 or 270 degrees, Y-axis coordinate has to
|
sl@0
|
402 |
//be incremented not by 1, but by iScalingSettings.iFactorX. Because of the integer divison
|
sl@0
|
403 |
//when transforming logical to physical coordinates, incremented Y-axis coordinates may
|
sl@0
|
404 |
//go negative or greater than drawing rectangle height. Then it has to be adjusted to 0
|
sl@0
|
405 |
//or rectangle height.
|
sl@0
|
406 |
void CDrawBitmap::IncScaledY(TInt& aY) const
|
sl@0
|
407 |
{
|
sl@0
|
408 |
const TOrientation orientation = iOrientation;
|
sl@0
|
409 |
const TInt fX = iScalingSettings.iFactorY;
|
sl@0
|
410 |
if(orientation == EOrientationRotated90)
|
sl@0
|
411 |
{
|
sl@0
|
412 |
aY += fX;
|
sl@0
|
413 |
const TInt height = iSize.iHeight - 1;
|
sl@0
|
414 |
if(aY > height)
|
sl@0
|
415 |
{
|
sl@0
|
416 |
aY = height;
|
sl@0
|
417 |
}
|
sl@0
|
418 |
}
|
sl@0
|
419 |
else if(orientation == EOrientationRotated270)
|
sl@0
|
420 |
{
|
sl@0
|
421 |
aY -= fX;
|
sl@0
|
422 |
if(aY < 0)
|
sl@0
|
423 |
{
|
sl@0
|
424 |
aY = 0;
|
sl@0
|
425 |
}
|
sl@0
|
426 |
}
|
sl@0
|
427 |
}
|
sl@0
|
428 |
|
sl@0
|
429 |
//Increment without scaling
|
sl@0
|
430 |
TInt CDrawBitmap::PixelAddressIncrement() const
|
sl@0
|
431 |
{
|
sl@0
|
432 |
switch (iOrientation)
|
sl@0
|
433 |
{
|
sl@0
|
434 |
case EOrientationNormal:
|
sl@0
|
435 |
return 1;
|
sl@0
|
436 |
case EOrientationRotated90:
|
sl@0
|
437 |
return iLongWidth;
|
sl@0
|
438 |
case EOrientationRotated180:
|
sl@0
|
439 |
return -1;
|
sl@0
|
440 |
case EOrientationRotated270:
|
sl@0
|
441 |
return -iLongWidth;
|
sl@0
|
442 |
default:
|
sl@0
|
443 |
break;
|
sl@0
|
444 |
}
|
sl@0
|
445 |
return KInvalidValue;
|
sl@0
|
446 |
}
|
sl@0
|
447 |
|
sl@0
|
448 |
//Pixel increment with scaling.
|
sl@0
|
449 |
//It is used by CDrawEightBppBitmapCommon::SetPixels,
|
sl@0
|
450 |
//CDrawEightBppBitmapCommon::XORPixels, CDrawEightBppBitmapCommon::ANDPixels,
|
sl@0
|
451 |
//CDrawEightBppBitmapCommon::ORPixels methods
|
sl@0
|
452 |
TInt CDrawBitmap::LogicalPixelAddressIncrement() const
|
sl@0
|
453 |
{
|
sl@0
|
454 |
register TInt scalingFactorX = iScalingSettings.iFactorX;
|
sl@0
|
455 |
register TInt scalingFactorY = iScalingSettings.iFactorY;
|
sl@0
|
456 |
switch (iOrientation)
|
sl@0
|
457 |
{
|
sl@0
|
458 |
case EOrientationNormal:
|
sl@0
|
459 |
return scalingFactorX;
|
sl@0
|
460 |
case EOrientationRotated90:
|
sl@0
|
461 |
return iLongWidth * scalingFactorY;
|
sl@0
|
462 |
case EOrientationRotated180:
|
sl@0
|
463 |
return -scalingFactorX;
|
sl@0
|
464 |
case EOrientationRotated270:
|
sl@0
|
465 |
return -iLongWidth * scalingFactorY;
|
sl@0
|
466 |
default:
|
sl@0
|
467 |
break;
|
sl@0
|
468 |
}
|
sl@0
|
469 |
return KInvalidValue;
|
sl@0
|
470 |
}
|
sl@0
|
471 |
|
sl@0
|
472 |
inline TInt CDrawBitmap::Origin(TInt aPhysOrg, TInt aScale) const
|
sl@0
|
473 |
{
|
sl@0
|
474 |
return -(aPhysOrg/aScale + (aPhysOrg%aScale ? 1:0));
|
sl@0
|
475 |
}
|
sl@0
|
476 |
|
sl@0
|
477 |
inline TInt CDrawBitmap::OtherSide(TInt aPhysOrg, TInt aPhysSize, TInt aScale) const
|
sl@0
|
478 |
{
|
sl@0
|
479 |
return (aPhysSize-1-aPhysOrg) / aScale + 1;
|
sl@0
|
480 |
}
|