使用soui4实现一个打印排版软件(四)椭圆、圆、三角形、菱形元素控件

椭圆、圆、三角形、菱形元素的移动以及拉伸处理跟rect元素一样。
不一样的地方就在绘制元素的地方,实现如下:
椭圆:

void CEleEllipse::OnPaint(IRenderTarget* pRT)
{
	SetMsgHandled(FALSE);
	pRT->SetAntiAlias(TRUE);
	CRect rcWindow = GetWindowRect();
	CPoint ptCenter = rcWindow.CenterPoint();
	{
		COLORREF clrBorder = GETCOLOR(L"RGB(0,0,255)");
		int nBorderLine = PS_SOLID;
		CAutoRefPtr<IPen> pen, oldpen;
		pRT->CreatePen(nBorderLine | PS_ENDCAP_SQUARE, clrBorder, 2, &pen);
		pRT->SelectObject(pen, (IRenderObj**)&oldpen);
		pRT->DrawEllipse(&rcWindow);
		pRT->SelectObject(oldpen, NULL);
	}
	//...
}

圆:

void CEleCircular::OnPaint(IRenderTarget* pRT)
{
	SetMsgHandled(FALSE);
	pRT->SetAntiAlias(TRUE);
	CRect rcWindow = GetWindowRect();
	CPoint ptCenter = rcWindow.CenterPoint();
	{
		COLORREF clrBorder = GETCOLOR(L"RGB(0,0,255)");
		int nBorderLine = PS_SOLID;
		CAutoRefPtr<IPen> pen, oldpen;
		pRT->CreatePen(nBorderLine | PS_ENDCAP_SQUARE, clrBorder, 2, &pen);
		pRT->SelectObject(pen, (IRenderObj**)&oldpen);
		pRT->DrawEllipse(&rcWindow);
		pRT->SelectObject(oldpen, NULL);
	}
	//...
}

三角形:

void CEleTriangle::OnPaint(IRenderTarget* pRT)
{
	SetMsgHandled(FALSE);
	pRT->SetAntiAlias(TRUE);
	CRect rcWindow = GetWindowRect();
	CPoint ptCenter = rcWindow.CenterPoint();
	{
		CAutoRefPtr<IPathS> path;
		GETRENDERFACTORY->CreatePath(&path);
		COLORREF clrBorder = GETCOLOR(L"RGB(0,0,255)");
		int nBorderLine = PS_SOLID;
		CAutoRefPtr<IPen> pen, oldpen;

		//根据矩形计算三角形的三个顶点
		CPoint pt1, pt2, pt3;
		pt1.x = rcWindow.left;
		pt1.y = rcWindow.bottom;
		pt2.x = ptCenter.x;
		pt2.y = rcWindow.top;
		pt3 = rcWindow.BottomRight();

		path->moveTo(pt1.x, pt1.y);
		path->lineTo(pt2.x, pt2.y);
		path->lineTo(pt3.x, pt3.y);
		path->lineTo(pt1.x, pt1.y);

		pRT->CreatePen(nBorderLine | PS_ENDCAP_SQUARE, clrBorder, 2, &pen);
		pRT->SelectObject(pen, (IRenderObj**)&oldpen);
		pRT->DrawPath(path);
		pRT->SelectObject(oldpen, NULL);
	}
	//...
}

菱形:

void CEleDiamond::OnPaint(IRenderTarget* pRT)
{
	SetMsgHandled(FALSE);
	pRT->SetAntiAlias(TRUE);
	CRect rcWindow = GetWindowRect();
	CPoint ptCenter = rcWindow.CenterPoint();
	{
		CAutoRefPtr<IPathS> path;
		GETRENDERFACTORY->CreatePath(&path);
		COLORREF clrBorder = GETCOLOR(L"RGB(0,0,255)");
		int nBorderLine = PS_SOLID;
		CAutoRefPtr<IPen> pen, oldpen;
		//根据矩形计算菱形的四个顶点
		CPoint pt1, pt2, pt3, pt4;
		pt1.x = ptCenter.x;
		pt1.y = rcWindow.bottom;
		pt2.x = rcWindow.left;
		pt2.y = ptCenter.y;
		pt3.x = ptCenter.x;
		pt3.y = rcWindow.top;
		pt4.x = rcWindow.right;
		pt4.y = ptCenter.y;

		path->moveTo(pt1.x, pt1.y);
		path->lineTo(pt2.x, pt2.y);
		path->lineTo(pt3.x, pt3.y);
		path->lineTo(pt4.x, pt4.y);
		path->lineTo(pt1.x, pt1.y);

		pRT->CreatePen(nBorderLine | PS_ENDCAP_SQUARE, clrBorder, 2, &pen);
		pRT->SelectObject(pen, (IRenderObj**)&oldpen);
		pRT->DrawPath(path);
		pRT->SelectObject(oldpen, NULL);
	}
	//...
}

控件使用:
1、注册控件

m_theApp->RegisterWindowClass<CEleEllipse>();
m_theApp->RegisterWindowClass<CEleCircular>();
m_theApp->RegisterWindowClass<CEleTriangle>();
m_theApp->RegisterWindowClass<CEleDiamond>();

2、往画板容器中放置元素
椭圆:

CEleEllipse* pEle = (CEleEllipse*)SApplication::getSingleton().CreateWindowByName(L"ele_ellipse");
SASSERT(pEle);
SApplication::getSingleton().SetSwndDefAttr(pEle);
this->InsertChild(pEle);
pEle->SSendMessage(WM_CREATE);
CPoint ptReal(point);
ptReal.x -= rcContainer.left;
ptReal.y -= rcContainer.top;

SStringT sstrRectPos;
sstrRectPos.Format(_T("%d,%d,@%d,@%d"), ptReal.x, ptReal.y, 100, 50);
pEle->SetAttribute(L"pos", sstrRectPos);

//将位置、长宽等信息转为毫米
CPoint ptRB(ptReal.x + 100, ptReal.y + 50);
pEle->m_ptLT = ptReal;
pEle->m_ptRB = ptRB;

圆:

CEleCircular* pEle = (CEleCircular*)SApplication::getSingleton().CreateWindowByName(L"ele_circular");
SASSERT(pEle);
SApplication::getSingleton().SetSwndDefAttr(pEle);
this->InsertChild(pEle);
pEle->SSendMessage(WM_CREATE);
CPoint ptReal(point);
ptReal.x -= rcContainer.left;
ptReal.y -= rcContainer.top;

SStringT sstrRectPos;
sstrRectPos.Format(_T("%d,%d,@%d,@%d"), ptReal.x, ptReal.y, 100, 100);
pEle->SetAttribute(L"pos", sstrRectPos);

//将位置、长宽等信息转为毫米
CPoint ptRB(ptReal.x + 100, ptReal.y + 100);
pEle->m_ptLT = ptReal;
pEle->m_ptRB = ptRB;

三角形:

CEleTriangle* pEle = (CEleTriangle*)SApplication::getSingleton().CreateWindowByName(L"ele_triangle");
SASSERT(pEle);
SApplication::getSingleton().SetSwndDefAttr(pEle);
this->InsertChild(pEle);
pEle->SSendMessage(WM_CREATE);
CPoint ptReal(point);
ptReal.x -= rcContainer.left;
ptReal.y -= rcContainer.top;

SStringT sstrRectPos;
sstrRectPos.Format(_T("%d,%d,@%d,@%d"), ptReal.x, ptReal.y, 100, 80);
pEle->SetAttribute(L"pos", sstrRectPos);

//将位置、长宽等信息转为毫米
CPoint ptRB(ptReal.x + 100, ptReal.y + 80);
pEle->m_ptLT = ptReal;
pEle->m_ptRB = ptRB;

菱形:

CEleDiamond* pEle = (CEleDiamond*)SApplication::getSingleton().CreateWindowByName(L"ele_diamond");
SASSERT(pEle);
SApplication::getSingleton().SetSwndDefAttr(pEle);
this->InsertChild(pEle);
pEle->SSendMessage(WM_CREATE);
CPoint ptReal(point);
ptReal.x -= rcContainer.left;
ptReal.y -= rcContainer.top;

SStringT sstrRectPos;
sstrRectPos.Format(_T("%d,%d,@%d,@%d"), ptReal.x, ptReal.y, 80, 100);
pEle->SetAttribute(L"pos", sstrRectPos);

//将位置、长宽等信息转为毫米
CPoint ptRB(ptReal.x + 80, ptReal.y + 100);
pEle->m_ptLT = ptReal;
pEle->m_ptRB = ptRB;

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值