os/graphics/graphicsdeviceinterface/bitgdi/sbit/ROUNDREC.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1997-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 <fntstore.h>
sl@0
    17
#include <bitmap.h>
sl@0
    18
#include <bitstd.h>
sl@0
    19
#include <bitdev.h>
sl@0
    20
#include "BITPANIC.H"
sl@0
    21
#include <bitdraw.h>
sl@0
    22
#include <graphics/fbsrasterizer.h>
sl@0
    23
sl@0
    24
/**
sl@0
    25
Draws and fills a rectangle with rounded corners.
sl@0
    26
sl@0
    27
The function provides a concrete implementation of the pure virtual
sl@0
    28
function <code>CGraphicsContext::DrawRoundRect()</code>. The function
sl@0
    29
behaviour is the same as documented in that class.
sl@0
    30
*/
sl@0
    31
EXPORT_C void CFbsBitGc::DrawRoundRect(const TRect& aRect,const TSize& aSize)
sl@0
    32
	{
sl@0
    33
	if (CheckDevice(aRect))
sl@0
    34
		return;
sl@0
    35
sl@0
    36
	TSize ellsize(aSize);
sl@0
    37
	ellsize.iWidth <<= 1;
sl@0
    38
	ellsize.iHeight <<= 1;
sl@0
    39
sl@0
    40
	if (ellsize.iWidth < 3 || ellsize.iHeight < 3)
sl@0
    41
		{
sl@0
    42
		DrawRect(aRect);
sl@0
    43
		return;
sl@0
    44
		}
sl@0
    45
sl@0
    46
	if (aRect.Width() < ellsize.iWidth && aRect.Height() < ellsize.iHeight)
sl@0
    47
		{
sl@0
    48
		DrawEllipse(aRect);
sl@0
    49
		return;
sl@0
    50
		}
sl@0
    51
sl@0
    52
	TRect rcpy(aRect);
sl@0
    53
	rcpy.Move(iOrigin);
sl@0
    54
	iDevice->TruncateRect(rcpy);
sl@0
    55
	ellsize.iWidth = Min(rcpy.Width(),ellsize.iWidth);
sl@0
    56
	ellsize.iHeight = Min(rcpy.Height(),ellsize.iHeight);
sl@0
    57
sl@0
    58
	TRect clippedBoundingRect(rcpy);
sl@0
    59
	clippedBoundingRect.Grow((iPenSize.iWidth >> 1) + 1,(iPenSize.iHeight >> 1) + 1);
sl@0
    60
	if (!clippedBoundingRect.Intersects(iUserClipRect))
sl@0
    61
		return;
sl@0
    62
sl@0
    63
	SetupDevice();
sl@0
    64
	iDevice->DrawingBegin(&iBrushBitmap);
sl@0
    65
	CFbsRasterizer* brushRasterizer = PrepareRasterizerForExtendedBitmap(iBrushBitmap);
sl@0
    66
sl@0
    67
	if (iBrushStyle != ENullBrush)
sl@0
    68
		RoundRectFill(rcpy,ellsize);
sl@0
    69
sl@0
    70
	if (iPenStyle != ENullPen && iPenSize.iWidth > 0 && iPenSize.iHeight > 0)
sl@0
    71
		RoundRectOutline(rcpy,ellsize);
sl@0
    72
sl@0
    73
	if (brushRasterizer)
sl@0
    74
		{
sl@0
    75
		brushRasterizer->EndBitmap(iBrushBitmap.SerialNumber());
sl@0
    76
		}
sl@0
    77
	iDevice->DrawingEnd(&iBrushBitmap);
sl@0
    78
	}
sl@0
    79
sl@0
    80
// if iBrushBitmap is an extended bitmap, PrepareRasterizerForExtendedBitmap() must have been called before this method
sl@0
    81
void CFbsBitGc::RoundRectFill(const TRect& aRect,TSize aSize)
sl@0
    82
	{
sl@0
    83
	TRect rcpy(aRect);
sl@0
    84
	if (iPenSize.iWidth < 1 || iPenSize.iHeight < 1)
sl@0
    85
		rcpy.Grow(1,1);
sl@0
    86
	AddRect(rcpy);
sl@0
    87
sl@0
    88
	if (rcpy.iBr.iX - rcpy.iTl.iX < aSize.iWidth)
sl@0
    89
		aSize.iWidth = rcpy.Width();
sl@0
    90
	if (rcpy.iBr.iY - rcpy.iTl.iY < aSize.iHeight)
sl@0
    91
		aSize.iHeight = rcpy.Height();
sl@0
    92
sl@0
    93
	TInt xoff = rcpy.Width() - aSize.iWidth;
sl@0
    94
	TInt yoff = rcpy.Height() - aSize.iHeight;
sl@0
    95
	TPoint tl,tr,bl,br;
sl@0
    96
	TInt prevlev = 0;
sl@0
    97
	TBool draw = EFalse;
sl@0
    98
sl@0
    99
	const TInt limit = iDefaultRegionPtr->Count();
sl@0
   100
	for (TInt count = 0; count < limit; count++)
sl@0
   101
		{
sl@0
   102
		iClipRect = (*iDefaultRegionPtr)[count];
sl@0
   103
		if (UserClipRect(iClipRect))
sl@0
   104
			continue;
sl@0
   105
		if (!iClipRect.Intersects(aRect))
sl@0
   106
			continue;
sl@0
   107
sl@0
   108
		draw = ETrue;
sl@0
   109
		iClipRect.Intersection(aRect);
sl@0
   110
sl@0
   111
		TEllipse ellipse;
sl@0
   112
		ellipse.Construct(TRect(rcpy.iTl,rcpy.iTl + aSize));
sl@0
   113
		ellipse.SingleStep(tl,tr,bl,br);
sl@0
   114
		prevlev = tl.iY;
sl@0
   115
sl@0
   116
		while (!ellipse.SingleStep(tl,tr,bl,br))
sl@0
   117
			{
sl@0
   118
			if (tl.iY == prevlev)
sl@0
   119
				continue;
sl@0
   120
sl@0
   121
			tl.iX++;
sl@0
   122
			tr.iX += xoff - 1;
sl@0
   123
			bl.iX++;
sl@0
   124
			bl.iY += yoff;
sl@0
   125
			br.iX += xoff - 1;
sl@0
   126
			br.iY += yoff;
sl@0
   127
sl@0
   128
			ClipFillLine(tl,tr);
sl@0
   129
			ClipFillLine(bl,br);
sl@0
   130
sl@0
   131
			prevlev = tl.iY;
sl@0
   132
			}
sl@0
   133
sl@0
   134
		iDevice->iDrawDevice->UpdateRegion(iClipRect);
sl@0
   135
		}
sl@0
   136
sl@0
   137
	if (!draw)
sl@0
   138
		return;
sl@0
   139
sl@0
   140
	if (tl.iY >= bl.iY)
sl@0
   141
		{
sl@0
   142
		tl.iY--;
sl@0
   143
		br.iY++;
sl@0
   144
		}
sl@0
   145
sl@0
   146
	tl.iX++;
sl@0
   147
	tl.iY++;
sl@0
   148
	br.iX += xoff;
sl@0
   149
	br.iY += yoff;
sl@0
   150
sl@0
   151
	RectFill(TRect(tl,br));
sl@0
   152
	}
sl@0
   153
sl@0
   154
void CFbsBitGc::RoundRectOutline(const TRect& aRect,TSize aSize)
sl@0
   155
	{
sl@0
   156
	TRect rcpy(aRect);
sl@0
   157
	const TInt halfpenwidth = (iPenSize.iWidth + 1) >> 1;
sl@0
   158
	const TInt halfpenheight = (iPenSize.iWidth + 1) >> 1;
sl@0
   159
	rcpy.Grow(halfpenwidth,halfpenheight);
sl@0
   160
	AddRect(rcpy);
sl@0
   161
sl@0
   162
	if (aRect.Width() < aSize.iWidth)
sl@0
   163
		aSize.iWidth = aRect.Width();
sl@0
   164
	if (aRect.Height() < aSize.iHeight)
sl@0
   165
		aSize.iHeight = aRect.Height();
sl@0
   166
sl@0
   167
	TPoint tl,tr,bl,br;
sl@0
   168
	const TInt xoff = aRect.Width() - aSize.iWidth;
sl@0
   169
	const TInt yoff = aRect.Height() - aSize.iHeight;
sl@0
   170
	const TInt dotparam = iDotParam;
sl@0
   171
sl@0
   172
	const TInt limit = iDefaultRegionPtr->Count();
sl@0
   173
	for (TInt count = 0; count < limit; count++)
sl@0
   174
		{
sl@0
   175
		iClipRect = (*iDefaultRegionPtr)[count];
sl@0
   176
		if (!iClipRect.Intersects(rcpy))
sl@0
   177
			continue;
sl@0
   178
		iClipRect.Intersection(rcpy);
sl@0
   179
		if (UserClipRect(iClipRect))
sl@0
   180
			continue;
sl@0
   181
sl@0
   182
		iDotParam = Max(iPenSize.iWidth >> 1,iPenSize.iHeight >> 1);
sl@0
   183
		TInt column = aRect.iTl.iX + (aSize.iWidth >> 1);
sl@0
   184
		TInt lastcolumn = aRect.iTl.iX + xoff + (aSize.iWidth >> 1);
sl@0
   185
sl@0
   186
		for (; column < lastcolumn; column++)
sl@0
   187
			{
sl@0
   188
			PenDrawClipped(TPoint(column,aRect.iTl.iY));
sl@0
   189
			PenDrawClipped(TPoint(column,aRect.iBr.iY - 1));
sl@0
   190
			iDotParam += iDotDirection;
sl@0
   191
			}
sl@0
   192
sl@0
   193
		TEllipse ellipse;
sl@0
   194
		ellipse.Construct(TRect(aRect.iTl,aRect.iTl + aSize));
sl@0
   195
		while (!ellipse.SingleStep(tl,tr,bl,br))
sl@0
   196
			{
sl@0
   197
			tr.iX += xoff;
sl@0
   198
			bl.iY += yoff;
sl@0
   199
			br.iX += xoff;
sl@0
   200
			br.iY += yoff;
sl@0
   201
sl@0
   202
			PenDrawClipped(tl);
sl@0
   203
			PenDrawClipped(tr);
sl@0
   204
			PenDrawClipped(bl);
sl@0
   205
			PenDrawClipped(br);
sl@0
   206
sl@0
   207
			iDotParam += iDotDirection;
sl@0
   208
			}
sl@0
   209
sl@0
   210
		if (tl.iY >= bl.iY)
sl@0
   211
			{
sl@0
   212
			tl.iY--;
sl@0
   213
			bl.iY++;
sl@0
   214
			}
sl@0
   215
sl@0
   216
		bl.iY += yoff;
sl@0
   217
sl@0
   218
		for (column = tl.iY + 1; column < bl.iY; column++)
sl@0
   219
			{
sl@0
   220
			PenDrawClipped(TPoint(aRect.iTl.iX,column));
sl@0
   221
			PenDrawClipped(TPoint(aRect.iBr.iX - 1,column));
sl@0
   222
			iDotParam += iDotDirection;
sl@0
   223
			}
sl@0
   224
sl@0
   225
		iDevice->iDrawDevice->UpdateRegion(iClipRect);
sl@0
   226
		}
sl@0
   227
sl@0
   228
	iDotParam = dotparam;
sl@0
   229
	}
sl@0
   230