昵称:烦夫子
类别:界面/平面设计师
年龄:38
现所在地:北京
主页浏览总数:24259
总积分:89
文章数:88
作品数:70
// Shape.cpp: implementation of the Shape class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SoftDraw.h"
#include "Shape.h"
#include "global.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
/*----- Constructors ------------------------------------*/
//None
Shape::Shape (const Object * p) : Object (p)
{
name = TShape;
shape = SPoint;
a = 1; b = 1;
edangle = 0;
stangle = PI2;
p1 = Vector(0,0);
p2 = Vector(0,0);
p3 = Vector(0,0);
p4 = Vector(0,0);
radius = 1;
color = RGB(0,0,255);
previewmode = 0;
//0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
plottype = 2;
GetMinMax ();
}
//Point
Shape::Shape (const Object * p, Vector& v1) : Object (p)
{
name = TShape;
a = 1; b = 1;
edangle = 0;
stangle = PI2;
p2 = Vector(0,0);
p3 = Vector(0,0);
p4 = Vector(0,0);
radius = 1;
previewmode = 0;
shape = SPoint;
p1 = v1;
color = RGB(0,0,255);
//0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
plottype = 2;
GetMinMax ();
}
Shape::Shape (const Object * p, Vector& v1, Vector& v2) : Object (p)
{
name = TShape;
a = 1; b = 1;
edangle = 0;
stangle = PI2;
p3 = Vector(0,0);
p4 = Vector(0,0);
radius = 1;
previewmode = 0;
shape = SLine;
p1 = v1;
p2 = v2;
color = RGB(0,0,255);
//0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
plottype = 2;
GetMinMax ();
}
Shape::Shape (const Object * p, Vector& v1, Vector& v2, Vector& v3, Vector& v4) : Object (p)
{
name = TShape;
a = 1; b = 1;
edangle = 0;
stangle = PI2;
radius = 1;
previewmode = 0;
shape = SRectangle;
p1 = v1;
p2 = v2;
p3 = v3;
p4 = v4;
color = RGB(0,0,255);
//0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
plottype = 2;
GetMinMax ();
}
Shape::Shape (const Object * p, Vector& v1, float rr) : Object (p)
{
name = TShape;
a = 1; b = 1;
p2 = Vector(0,0);
p3 = Vector(0,0);
p4 = Vector(0,0);
shape = SCircle;
p1 = v1;
radius = rr;
stangle = 0;
edangle = PI2;
color = RGB(0,0,255);
previewmode = 0;
//0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
plottype = 2;
GetMinMax ();
}
Shape::Shape (const Object * p, Vector& v1,BOOL bChange) : Object (p)
{
name = TShape;
a = 1; b = 1;
p2 = Vector(0,0);
p3 = Vector(0,0);
p4 = Vector(0,0);
shape = SHole;
p1 = v1;
radius = 1;
stangle = 0;
edangle = PI2;
color = RGB(0,0,0);
previewmode = 0;
//0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
plottype = 2;
GetMinMax ();
}
Shape::Shape (const Object * p, Vector& v1, float rr, float sta, float eda) : Object (p)
{
name = TShape;
a = 1; b = 1;
p2 = Vector(0,0);
p3 = Vector(0,0);
p4 = Vector(0,0);
previewmode = 0;
shape = SArc;
p1 = v1; //center
radius = rr; //radius
stangle = sta; //start angle
edangle = eda; //end angle
color = RGB(0,0,255);
//0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
plottype = 2;
GetMinMax ();
}
// 功能:在装饰库中画椭圆
Shape::Shape (const Object * p, Vector& v1, float aa, float bb) : Object (p)
{
name = TShape;
p2 = Vector(0,0);
p3 = Vector(0,0);
p4 = Vector(0,0);
radius = 1;
shape = SEllipse;
p1 = v1; //center
a = aa; //long axis
b = bb; //short axis
stangle = 0; //obliquing angle
edangle = 0;
color = RGB(0,0,255);
previewmode = 0;
//0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
plottype = 2;
GetMinMax ();
}
/*----- Operators ---------------------------------------*/
BOOL Shape::IsInRegion(CRgn *region) const
{
switch (shape) {
case SPoint:
return region->PtInRegion(p1.x, p1.y);
case SLine:
return region->PtInRegion(p1.x, p1.y) && region->PtInRegion(p2.x, p2.y);
case SCircle:
{
return region->PtInRegion(p1.x, p1.y) &&
region->PtInRegion(p1.x-radius, p1.y) &&
region->PtInRegion(p1.x+radius, p1.y) &&
region->PtInRegion(p1.x, p1.y-radius) &&
region->PtInRegion(p1.x, p1.y+radius) &&
region->PtInRegion(p1.x-0.707*radius, p1.y-0.707*radius) &&
region->PtInRegion(p1.x-0.707*radius, p1.y+0.707*radius) &&
region->PtInRegion(p1.x+0.707*radius, p1.y-0.707*radius) &&
region->PtInRegion(p1.x+0.707*radius, p1.y+0.707*radius) ;
}
}
return 0;
}
void Shape::Draw (CDC* dc, float scale, DrawMode mode, int dispmode) const
//参数: dc, scale -- 显示比例, mode -- 显示模式
//返回: 无
{
//显示图形
Object::Draw (dc, scale, mode, dispmode);
}
void Shape::DrawOrder(CDC* dc, float scale, DrawMode mode) const
{
CString csInd;
int iInd;
iInd = parent->GetIndex(this);
csInd.Format("%d", iInd);
Vector v;
VectorRun dp;
switch(shape) {
case SPoint:
v = p1 * scale;
break;
case SLine:
v = (p1 + p2) * scale * 0.5;
break;
case SRectangle:
v = (p1 + p2 + p3 + p4) * 0.25;
break;
case SEllipse:
case SCircle:
case SArc:
v = p1 * scale;
break;
default:
break;
}
CFont font, *ofont;
font.CreatePointFont(80, _T("Arial"));
ofont = dc->SelectObject(&font);
v = dp.WorldToDc(v);
dc->TextOut(v.x, v.y, csInd);
dc->SelectObject(ofont);
}