⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.cpp

📁 MFC简易绘图
💻 CPP
字号:
// List.cpp: implementation of the CList class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DrawSemple.h"
#include "List.h"

#include "Tuyuan.h"
#include "Line.h"
#include "Ellipse.h"
#include "Rectangle.h"
#include "Circle.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CList::CList()
{
	ListHead=ListTial=NULL;
}

CList::~CList()
{
	node *temp=ListHead;
	while(temp)
	{
		ListHead=ListHead->next;
		delete temp;
		temp=ListHead;
	}
}

void CList::AddTuyuan(CLine * ptuyuan)   //添加图元到队列
{
	node *temp;
	temp=new node;
	temp->m_ptuyuan=new CLine(*ptuyuan);
	if(ListHead==NULL)
	{
		ListHead=ListTial=temp;
		temp->next=NULL;
		temp->before=NULL;
	}
	else
	{
		temp->next=ListHead;
		ListHead->before=temp;
		temp->before=NULL;
		ListHead=temp;
	}
}

void CList::DrawAll(CDC *pDC)                      //打印队列
{
	CTuyuan::Tcount=0;
	CLine::Lcount=0;
	CEllipse::Ecount=0;
	CRectangle::Rcount=0;
	CCircle::Ccount=0;
	node *temp=ListHead;
	while(temp)
	{
		temp->m_ptuyuan->DrawTuyuan(pDC);
		temp->m_ptuyuan->BrushTuyuan(pDC);
		temp=temp->next;
	}
}

void CList::AddTuyuan(CEllipse *ptuyuan)
{
	node *temp;
	temp=new node;
	temp->m_ptuyuan=new CEllipse(*ptuyuan);
	if(ListHead==NULL)
	{
		ListHead=ListTial=temp;
		temp->next=NULL;
		temp->before=NULL;
	}
	else
	{
		temp->next=ListHead;
		ListHead->before=temp;
		temp->before=NULL;
		ListHead=temp;
	}	
}

void CList::AddTuyuan(CCircle * ptuyuan)
{
	node *temp;
	temp=new node;
	temp->m_ptuyuan=new CCircle(*ptuyuan);
	if(ListHead==NULL)
	{
		ListHead=ListTial=temp;
		temp->next=NULL;
		temp->before=NULL;
	}
	else
	{
		temp->next=ListHead;
		ListHead->before=temp;
		temp->before=NULL;
		ListHead=temp;
	}	
}

void CList::AddTuyuan(CRectangle * ptuyuan)
{
	node *temp;
	temp=new node;
	temp->m_ptuyuan=new CRectangle(*ptuyuan);
	if(ListHead==NULL)
	{
		ListHead=ListTial=temp;
		temp->next=NULL;
		temp->before=NULL;
	}
	else
	{
		temp->next=ListHead;
		ListHead->before=temp;
		temp->before=NULL;
		ListHead=temp;
	}
}

void CList::DelTuyuan(CTuyuan * ptuyuan)		//从队列中删除直线
{
	node *temp1,*temp2;
	temp1=temp2=ListHead;
	while(temp1)
	{
		if(temp1->m_ptuyuan==ptuyuan)
		{
			if(temp1==ListHead && temp1==ListTial)
			{
				ListHead=NULL;
				ListTial=NULL;
			}
			else if(temp1==ListHead)
			{
				ListHead=ListHead->next;
				ListHead->before=NULL;
			}
			else if(temp1==ListTial)
			{
				ListTial=ListTial->before;
				ListTial->next=NULL;
			}
			else
			{
				temp2->next=temp1->next;
				temp1->next->before=temp2;
			}		
			delete temp1;
			break;
		}
		else
		{
			temp2=temp1;
			temp1=temp1->next;
		}
	}
}

CTuyuan * CList::XuanDing(CPoint &pt1, CPoint &pt2)
{
	node *temp;
	temp=ListHead;
	while(temp)
	{
		CPoint cpt1,cpt2;
		cpt1=temp->m_ptuyuan->Getpt1();
		cpt2=temp->m_ptuyuan->Getpt2();
		if((cpt1.x>=pt1.x && cpt1.y>=pt1.y &&cpt2.x<=pt2.x && cpt2.y<=pt2.y)
			||(cpt2.x>=pt1.x && cpt2.y>=pt1.y &&cpt1.x<=pt2.x && cpt1.y<=pt2.y)
			||(cpt1.x>=pt2.x && cpt1.y>=pt2.y &&cpt2.x<=pt2.x && cpt1.y<=pt1.y)
			||(cpt2.x>=pt2.x && cpt2.y>=pt2.y &&cpt1.x<=pt1.x && cpt1.y<=pt1.y))
			return temp->m_ptuyuan;
		else	temp=temp->next;
	}
	return NULL;
}

void CList::BrushAll(CDC *pDC)
{
	CTuyuan::Tcount=0;
	CLine::Lcount=0;
	CEllipse::Ecount=0;
	CRectangle::Rcount=0;
	CCircle::Ccount=0;
	node *temp=ListHead;
	while(temp)
	{
		temp->m_ptuyuan->BrushTuyuan(pDC);
		temp=temp->next;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -