Exemplo n.º 1
0
void CDrawingView::OnDraw( CDC *pDC )
{
    CDrawingDoc *pDoc = GetDocument();
    ASSERT_VALID( pDoc );

    // Enumerate through the shapes and draw each one.
    POSITION position = pDoc->GetFirstShapePosition();
    while( position != NULL ) {
        CShape *pShape = pDoc->GetNextShape( position );
        pShape->Draw( pDC );
    }
}
Exemplo n.º 2
0
int _tmain(int argc, _TCHAR* argv[])
{
	cout << "도형 변호를 입력하세요. [1:사각형, 2:원]: " << endl;
	int nInput = 0;
	cin >> nInput;

	CShape *pShape = nullptr;
	if (nInput == 1)
		pShape = new CRectangle;

	else if (nInput == 2)
		pShape = new CCircle;

	else
		pShape = new CShape;

	// 좋은 예
	pShape->Draw();

	// '매우' 나쁜 예
	// 가상 함수를 활용한다면 이런 코드를 작성할 이유가 없다!
	CRectangle *pRect = dynamic_cast<CRectangle*>(pShape);
	if (pRect != NULL)
		cout << "CRectangle::Draw()" << endl;

	else
	{
		CCircle *pCricle = dynamic_cast<CCircle*>(pShape);
		if (pCricle != NULL)
			cout << "CCircle::Draw()" << endl;

		else
			cout << "CShape::Draw()" << endl;
	}

	return 0;
}
Exemplo n.º 3
0
void CTreeWnd::Render(CDC* pDC,CRect& area)
{
	//Timer t1;
    //t1.start();

	// Create offscreen dc & bitmap for double buffering. All
	// tree m_rendering is done to this.
    CRect ca;
	GetClientRect(ca);
	int width = mymax(m_scrollExtents.cx,ca.Width());

    CRect ur;
    GetUpdateRect(ur);

	//CDC memdc;
	//memdc.CreateCompatibleDC(pDC);
	//CBitmap membm;
	//membm.CreateCompatibleBitmap(pDC,width,ca.Height());
	//CBitmap* pOldBM = memdc.SelectObject(&membm);
    //memdc.FillSolidRect(0,0,width,ca.Height(),m_bgColour);

    CDC* pDrawDC = pDC;
    //pDrawDC->FillSolidRect(area,m_bgColour);

	// After all the nodes have been drawn, we'll fill in the rest of the space in the
	// background colour. We use this point to track where we've drawn.
	CPoint bottomRight = CPoint(-1,-1);

	CFont* pOldFont = (CFont*)pDrawDC->SelectStockObject(DEFAULT_GUI_FONT);
    
	int nodesrendered=0;

	bool currNodeSelected = false;
	int xidx = 0;

	vector<CShape*>::iterator pos;
	CShape* pPrevShape = NULL;
	for (pos = m_shapes.begin(); pos != m_shapes.end(); ++pos)
	{
		CShape *pShape = *pos;
        CRect inter;
		
        if (inter.IntersectRect(area,*pShape))
        {
		    CTreeNode* pNode = NodeFromShape(pShape);

			if (pNode && pNode->isSelected() && ( (xidx % m_pTree->numColumns()) >= m_treeColumn) )
			{
				// TODO: get from prefs sytem.
                if (GetFocus() == this)
                    pShape->SetBgColour(GetSysColor(COLOR_HIGHLIGHT));
                else
                    pShape->SetBgColour(RGB(192,192,192));
				pShape->SetFgColour(RGB(255,255,255));
			}
			else
			{
				pShape->SetBgColour(m_bgColour);
			}

			if ( (xidx % m_pTree->numColumns()) == m_treeColumn)
		    {
				// Fill the connecting lines area in, to make sure
				// we're drawing every single pixel.
				// TODO: prevent flickering here.
				CRect a = *pShape;
				//if (pPrevShape)
				//	a.left = pPrevShape->right;
				//else
					a.left = area.left;
				pDrawDC->FillSolidRect(a,m_bgColour);

				OnSetNodeDisplayProperties(pDrawDC,pNode);
				SetNodeShapeIcon(pNode,pShape);
				
				if (!pNode->isSelected())
					pShape->SetFgColour(pNode->GetFgColour());

			    pNode->Draw(pDrawDC,*pShape);
                if (pNode == m_selection.GetFocusItem())
                {
	    		    pShape->Draw(pDrawDC);
//                    pShape->RemoveProperty(CShape::SP_FOCUS_BORDER);
                }
                else
    			    pShape->Draw(pDrawDC);
		    }
		    else // non-tree columns
			{
			    pShape->Draw(pDrawDC);
			}

			if (pShape->right > bottomRight.x)
				bottomRight.x = pShape->right;
			if (pShape->bottom > bottomRight.y)
				bottomRight.y = pShape->bottom;

			nodesrendered++;
        }
		xidx++;
		pPrevShape = pShape;
	}

	// Now fill in the blank area
	CRect emptySpace;
	emptySpace.left = bottomRight.x;
	emptySpace.top  = area.top;
	emptySpace.right = area.right;
	emptySpace.bottom = area.bottom;
	pDrawDC->FillSolidRect(emptySpace,m_bgColour); // right

	emptySpace.left = area.left;
	emptySpace.top  = bottomRight.y;
	emptySpace.right = bottomRight.x;
	emptySpace.bottom = area.bottom;
	pDrawDC->FillSolidRect(emptySpace,m_bgColour); // right


    //t1.stop();
    //TRACE("TREE %x: Rendered %d nodes in %s\n",this,nodesrendered,t1.format().c_str());

    pDrawDC->SelectObject(pOldFont);

    //int desty = area.top;
    //if (m_style & MTS_HEADER)
      //  desty += DEF_HDR_HEIGHT;
	
	// blt to screen
    //int sp = GetScrollPos(SB_HORZ);   	
	//pDC->BitBlt(area.left,area.top,area.Width(),area.Height(),&memdc,area.left+sp,area.top,SRCCOPY);

    // clean up
    //memdc.SelectObject(&pOldBM);
    //memdc.DeleteDC();
    //membm.DeleteObject();

}
Exemplo n.º 4
0
void PrintGreetingFromShape(const CShape & shape)
{
	shape.Hello();
	shape.Draw(42);
}