//Background drawing function
void CTestRectGc::Draw(CWindowGc& aGc, const CCoeControl& aControl, const TRect& aRect) const
	{		
		if (iBmpBackground) 
		{
						
			TPoint a = PositionRelativeToScreen();
			TPoint b = aControl.PositionRelativeToScreen();

			//The source rect of the background is the relationship between this control and the control being drawn (child)
			//plus the subrect (aRect) to be drawn.
			TRect SourceRect(b-a+aRect.iTl, aRect.Size());

			aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
			aGc.BitBlt(aRect.iTl, iBmpBackground, SourceRect);			
			aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
		}
		else
		{
			TRect rc;
			aGc.SetClippingRect(aRect);
			aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    		aGc.SetBrushColor(iBrushColor);
    		aGc.SetBrushStyle(iBrushStyle);
			aGc.DrawRect(rc);
			aGc.CancelClippingRect();

		}		
	}
Example #2
0
void RectPacker::pack(const Rect& targetArea,
          const vector<Rect>& rects,
          bool rotate,
          bool sort)
{
  // clear stats
  sumIter = 0;
  sumNodes = 0;
  
  // clear previous result and init to target area
  nodes.clear();
  Node rootNode;
  rootNode.rect = targetArea;
  nodes.push_back(rootNode);
  
  // create the source vector and preserve incming ids in the progress
  // by wrapping the incoming rects in the SourceRect struct
  sourceRects.clear();
  int32_t numRects = (int32_t)rects.size();
  for(int32_t i=0; i<numRects; ++i)
  {
    sourceRects.push_back(SourceRect(rects[i], i));
  }
  
  // sort the source rects by size for better fitting
  if(sort)
    std::sort(sourceRects.begin(), sourceRects.end(), compareRects);
    
  // pack all source rects into the target area
  for(int32_t i=0; i<numRects; ++i)
  {
    if(!pack(i))
    {
      DOUT("couldn't pack "<<i);
    }
  }
  
  // clean up temporary data
  sourceRects.clear();
  recursionStack.clear();
//  DOUT("searched "<<(u32)((sumIter/sumNodes)*100)<<"% of all nodes");
//  DOUT(" iterations: "<<sumIter<<" nodes:"<<sumNodes);
}