📄 text.cpp
字号:
// text.cpp: implementation of the CText class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "geditor.h"
#include "text.h"
#include "geditorView.h"
#include <cmath>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CText::CText()
{/*
LOGFONT log;
log.lfCharSet=ANSI_CHARSET; //字体字符集
log.lfClipPrecision=CLIP_DEFAULT_PRECIS; //剪贴板字符
log.lfEscapement=0; //角度
strcpy(log.lfFaceName,"Cyz Font"); //
log.lfHeight=8;
log.lfItalic=0; //斜体度
log.lfOrientation=0;
log.lfOutPrecision=OUT_DEFAULT_PRECIS;
log.lfPitchAndFamily=VARIABLE_PITCH|FF_ROMAN; //字体间距和字体族
log.lfQuality=PROOF_QUALITY;
log.lfStrikeOut=0; //镂空字体
log.lfUnderline=0;
log.lfWeight=FW_NORMAL; //字体精细
log.lfWidth=0;
tfont.CreateFontIndirect(&log);
tpt.x=tpt.y=100;*/
Rotnumber=0;
RotateNoInit=0;
rect.left=pts[0].x-1;
rect.top=pts[0].y-1;
rect.right=pts[2].x+2;
rect.bottom=pts[2].y+2;
edgeclr=0x00C0C0C0;
}
CText::CText(LOGFONT &log,CPoint &pt,COLORREF &clr,CString &str)
{
tlog=log;
pts[0]=pt;
m_color=clr;
textstr=str;
//calculate for change
width=abs(log.lfHeight)*textstr.GetLength()*4/7;
pts[1].x=pt.x+width;//width?
pts[1].y=pt.y;
pts[2].x=pt.x+width;
pts[2].y=pt.y-log.lfHeight;
pts[3].x=pt.x;
pts[3].y=pts[2].y;
Rotnumber=0;
RotateNoInit=0;
rect.left=pts[0].x-1;
rect.top=pts[0].y-1;
rect.right=pts[2].x+2;
rect.bottom=pts[2].y+2;
edgeclr=0x00C0C0C0;
}
CText::~CText()
{
}
void CText::Draw(CDC *pDC)
{
CFont font;
font.CreateFontIndirect(&tlog);
CPen pen(PS_DOT,1,RGB(0,0,0));
CFont *oldf=pDC->SelectObject(&font);
CPen *oldpen=pDC->SelectObject(&pen);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(m_color);
pDC->TextOut(pts[0].x,pts[0].y,textstr);
pDC->SelectObject(oldf);
if(dragmode!=0)
{
UpdateProp();
pDC->MoveTo(pts[0]);
pDC->LineTo(pts[1]);
pDC->LineTo(pts[2]);
pDC->LineTo(pts[3]);
pDC->LineTo(pts[0]);
};
font.DeleteObject();
DeleteObject(pen);
pDC->SelectObject(oldpen);
pDC->SelectObject(oldf);
}
int CText::InTest(CPoint pt)
{
CRgn rgn;
rgn.CreatePolygonRgn(pts,4,ALTERNATE);
if(rgn.PtInRegion(pt))
{
::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSEL));
return 1;
};
return 0;
}
void CText::dragobj(int leash, CDC *pDC, CPoint pt, CGeditorView *pView)
{
if (leash==1)
pt.y=movept.y;
else if (leash==2)
pt.x=movept.x;
invalid(pView);
if (dragmode==1)
{
for(int i=0;i<4;i++)
{
pts[i].x+=pt.x-movept.x;
pts[i].y+=pt.y-movept.y;
};
changepts(1);
movept.x=pt.x;
movept.y=pt.y;
} ;
Draw(pDC);
}
void CText::invalid(CGeditorView *pView)
{
pView->InvalidateRect(rect);
DeleteObject(rect);
}
void CText::Serialize(CArchive &ar)
{
CObject::Serialize(ar);
serialfont(ar);
int i=0;
if(ar.IsStoring())
{
ar<<textstr<<movept<<m_color<<dragmode<<Rotnumber<<linesty;
for (i=0;i<4;i++)
ar<<pts[i];
}
else
{
ar>>textstr>>movept>>m_color>>dragmode<<Rotnumber>>linesty;
for (i=0;i<4;i++)
ar>>pts[i];
};
}
void CText::serialfont(CArchive &ar)
{
if(ar.IsStoring())
{
ar<<tlog.lfCharSet<<tlog.lfClipPrecision<<tlog.lfEscapement<<tlog.lfHeight<<tlog.lfItalic<<tlog.lfOrientation<<tlog.lfOutPrecision<<tlog.lfPitchAndFamily<<tlog.lfQuality<<tlog.lfStrikeOut<<tlog.lfUnderline<<tlog.lfWeight<<tlog.lfWidth<<name;
}else
{
ar>>tlog.lfCharSet>>tlog.lfClipPrecision>>tlog.lfEscapement>>tlog.lfHeight>>tlog.lfItalic>>tlog.lfOrientation>>tlog.lfOutPrecision>>tlog.lfPitchAndFamily>>tlog.lfQuality>>tlog.lfStrikeOut>>tlog.lfUnderline>>tlog.lfWeight>>tlog.lfWidth>>name;
};
}
void CText::InitProp()
{
/* int count=p->m_list.GetItemCount();
if (count!=0)
{
for(int i=0;i<count;i++)
p->m_list.DeleteItem(0);
};
item.mask=LVIF_TEXT|LVIF_STATE;
item.state=0;
item.stateMask=0;
item.iItem=0;
item.iSubItem=0;
item.pszText="BasePt.X";
p->m_list.InsertItem(&item);
sprintf(svalue,"%3d",pts[0].x);
p->m_list.SetItemText(0,1,svalue);
item.iItem=1;
item.iSubItem=0;
item.pszText="BasePt.Y";
p->m_list.InsertItem(&item);
sprintf(svalue,"%3d",pts[0].y);
p->m_list.SetItemText(1,1,svalue);
p->m_Fill.EnableWindow(FALSE);
p->bkclr=0;
p->m_fill=FALSE;
p->OtherShow(m_color,-1,1);*/
}
CShape * CText::copys(TCHAR &ch)
{
CText *t;
t=new CText;
t->textstr=textstr;
t->tlog=tlog;
for (int i=0;i<4;i++)
{
t->pts[i].x=pts[i].x+10;
t->pts[i].y=pts[i].y+10;
};
ch='T';
return t;
}
void CText::rotate(int rsel, CDC *pDC, CPoint pt, CGeditorView *pView)
{
if(RotateNoInit==1)
{
invalid(pView);
Rotnumber++;
Rotnumber%=4;
int sita=Rotnumber*900;
tlog.lfEscapement=tlog.lfOrientation=sita;
changepts(0);
Draw(pDC);
RotateNoInit=0;
};
}
void CText::CalForRot(CPoint &pt)
{
RotateNoInit=1;
}
void CText::changepts(int sel)
{
switch(Rotnumber)
{
case 0:
if (sel==0)
{
pts[1].x=pts[0].x+width;
pts[1].y=pts[0].y;
pts[2].x=pts[1].x;
pts[2].y=pts[0].y-tlog.lfHeight;
pts[3].x=pts[0].x;
pts[3].y=pts[2].y;
};
rect.left=pts[0].x-1;
rect.top=pts[0].y-1;
rect.right=pts[2].x+2;
rect.bottom=pts[2].y+2;
break;
case 1:
if(sel==0)
{
pts[1].x=pts[0].x;
pts[1].y=pts[0].y-width;
pts[2].x=pts[1].x-tlog.lfHeight;
pts[2].y=pts[1].y;
pts[3].x=pts[2].x;
pts[3].y=pts[0].y;
};
rect.left=pts[1].x-1;
rect.top=pts[1].y-1;
rect.right=pts[3].x+2;
rect.bottom=pts[3].y+2;
break;
case 2:
if(sel==0)
{
pts[1].x=pts[0].x-width;
pts[1].y=pts[0].y;
pts[2].x=pts[1].x;
pts[2].y=pts[1].y+tlog.lfHeight;
pts[3].x=pts[0].x;
pts[3].y=pts[2].y;
};
rect.left=pts[2].x-1;
rect.top=pts[2].y-1;
rect.right=pts[0].x+2;
rect.bottom=pts[0].y+2;
break;
case 3:
if(sel==0)
{
pts[1].x=pts[0].x;
pts[1].y=pts[0].y+width;
pts[2].x=pts[1].x+tlog.lfHeight;
pts[2].y=pts[1].y;
pts[3].x=pts[2].x;
pts[3].y=pts[0].y;
};
rect.left=pts[3].x-1;
rect.top=pts[3].y-1;
rect.right=pts[1].x+2;
rect.bottom=pts[1].y+2;
break;
default:
break;
};
}
void CText::UpdateProp()
{
/*
sprintf(svalue,"%3d",pts[0].x);
p->m_list.SetItemText(0,1,svalue);
sprintf(svalue,"%3d",pts[0].y);
p->m_list.SetItemText(1,1,svalue);
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -