os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiroundrec.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "swdirectgdiengine.h"
    17 #include "swdirectgdiellipse.h"
    18    
    19 /**
    20 @see MDirectGdiEngine::DrawRoundRect()
    21 */
    22 void CSwDirectGdiEngine::DrawRoundRect(const TRect& aRect, const TSize& aCornerSize)
    23 	{
    24 	TSize cornerSize(aCornerSize);
    25 	cornerSize.iWidth <<= 1;
    26 	cornerSize.iHeight <<= 1;
    27 
    28 	
    29 	TRect rcpy(aRect);
    30 	rcpy.Move(iOrigin);
    31 	TruncateRect(rcpy);
    32 	cornerSize.iWidth = Min(rcpy.Width(),cornerSize.iWidth);
    33 	cornerSize.iHeight = Min(rcpy.Height(),cornerSize.iHeight);
    34 
    35 	TRect targetRect(rcpy);
    36 	targetRect.Grow((iPenSize.iWidth >> 1) + 1,(iPenSize.iHeight >> 1) + 1);
    37 
    38 	if (iBrushStyle != DirectGdi::ENullBrush)
    39 		{
    40 		RoundRectFill(rcpy,cornerSize);
    41 		}
    42 
    43 	if ((iPenStyle != DirectGdi::ENullPen) && ((iPenSize.iWidth > 0) && (iPenSize.iHeight > 0)))
    44 		{
    45 		RoundRectOutline(rcpy, cornerSize);
    46 		}
    47 	}
    48 
    49 /**
    50 @see DrawRoundRect()
    51 */
    52 void CSwDirectGdiEngine::RoundRectFill(const TRect& aRect, const TSize& aCornerSize)
    53 	{
    54 	TRect rcpy(aRect);
    55 	if (iPenSize.iWidth < 1 || iPenSize.iHeight < 1)
    56 		{
    57 		rcpy.Grow(1,1);
    58 		}
    59 
    60 	TInt xoff = rcpy.Width() - aCornerSize.iWidth;
    61 	TInt yoff = rcpy.Height() - aCornerSize.iHeight;
    62 	TPoint tl, tr, bl, br;
    63 	TInt prevlev = 0;
    64 	TBool draw = EFalse;
    65 
    66 	TRect clipRect(0,0,0,0);
    67 	const TInt limit = iDefaultRegionPtr->Count();
    68 	for (TInt count = 0; count < limit; count++)
    69 		{
    70 		clipRect = (*iDefaultRegionPtr)[count];	
    71 		if (!clipRect.Intersects(aRect))
    72 			{
    73 			continue;
    74 			}
    75 
    76 		draw = ETrue;
    77 		clipRect.Intersection(aRect);
    78 
    79 		TSwDirectGdiEllipse ellipse;
    80 		ellipse.Construct(TRect(rcpy.iTl,rcpy.iTl + aCornerSize));
    81 		ellipse.SingleStep(tl, tr, bl, br);
    82 		prevlev = tl.iY;
    83 
    84 		while (!ellipse.SingleStep(tl, tr, bl, br))
    85 			{
    86 			if (tl.iY == prevlev)
    87 				{
    88 				continue;
    89 				}
    90 
    91 			tl.iX++;
    92 			tr.iX += xoff - 1;
    93 			bl.iX++;
    94 			bl.iY += yoff;
    95 			br.iX += xoff - 1;
    96 			br.iY += yoff;
    97 
    98 			ClipFillLine(tl, tr,clipRect);
    99 			ClipFillLine(bl, br,clipRect);
   100 
   101 			prevlev = tl.iY;
   102 			}
   103 
   104 		iDrawDevice->UpdateRegion(clipRect);
   105 		}
   106 
   107 	if (!draw)
   108 		{
   109 		return;
   110 		}
   111 
   112 	if (tl.iY >= bl.iY)
   113 		{
   114 		tl.iY--;
   115 		br.iY++;
   116 		}
   117 
   118 	tl.iX++;
   119 	tl.iY++;
   120 	br.iX += xoff;
   121 	br.iY += yoff;
   122 
   123 	RectFill(TRect(tl,br));
   124 	}
   125 
   126 /**
   127 @see DrawRoundRect()
   128 */
   129 void CSwDirectGdiEngine::RoundRectOutline(const TRect& aRect, const TSize& aCornerSize)
   130 	{
   131 	TRect rcpy(aRect);
   132 	const TInt halfpenwidth = (iPenSize.iWidth + 1) >> 1;
   133 	const TInt halfpenheight = (iPenSize.iHeight + 1) >> 1;
   134 	rcpy.Grow(halfpenwidth,halfpenheight);
   135 
   136 	TPoint tl, tr, bl, br;
   137 	const TInt xoff = aRect.Width() - aCornerSize.iWidth;
   138 	const TInt yoff = aRect.Height() - aCornerSize.iHeight;
   139 	const TInt dotparam = iDotParam;
   140 
   141 	TRect clipRect(0,0,0,0);
   142 	const TInt limit = iDefaultRegionPtr->Count();
   143 	for (TInt count = 0; count < limit; count++)
   144 		{
   145 		clipRect = (*iDefaultRegionPtr)[count];
   146 		if (!clipRect.Intersects(rcpy))
   147 			{
   148 			continue;
   149 			}
   150 		clipRect.Intersection(rcpy);
   151 
   152 		iDotParam = Max(iPenSize.iWidth >> 1,iPenSize.iHeight >> 1);
   153 		TInt column = aRect.iTl.iX + (aCornerSize.iWidth >> 1);
   154 		TInt lastcolumn = aRect.iTl.iX + xoff + (aCornerSize.iWidth >> 1);
   155 
   156 		for (; column < lastcolumn; column++)
   157 			{
   158 			PenDrawClipped(TPoint(column,aRect.iTl.iY), clipRect);
   159 			PenDrawClipped(TPoint(column,aRect.iBr.iY - 1), clipRect);
   160 			iDotParam += iDotDirection;
   161 			}
   162 
   163 		TSwDirectGdiEllipse ellipse;
   164 		ellipse.Construct(TRect(aRect.iTl,aRect.iTl + aCornerSize));
   165 		while (!ellipse.SingleStep(tl,tr,bl,br))
   166 			{
   167 			tr.iX += xoff;
   168 			bl.iY += yoff;
   169 			br.iX += xoff;
   170 			br.iY += yoff;
   171 
   172 			PenDrawClipped(tl, clipRect);
   173 			PenDrawClipped(tr, clipRect);
   174 			PenDrawClipped(bl, clipRect);
   175 			PenDrawClipped(br, clipRect);
   176 
   177 			iDotParam += iDotDirection;
   178 			}
   179 
   180 		if (tl.iY >= bl.iY)
   181 			{
   182 			tl.iY--;
   183 			bl.iY++;
   184 			}
   185 
   186 		bl.iY += yoff;
   187 
   188 		for (column = tl.iY + 1; column < bl.iY; column++)
   189 			{
   190 			PenDrawClipped(TPoint(aRect.iTl.iX,column), clipRect);
   191 			PenDrawClipped(TPoint(aRect.iBr.iX - 1,column), clipRect);
   192 			iDotParam += iDotDirection;
   193 			}
   194 
   195 		iDrawDevice->UpdateRegion(clipRect);
   196 		}
   197 
   198 	iDotParam = dotparam;
   199 	}