-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSketchElement_Line.cpp
64 lines (48 loc) · 1.27 KB
/
SketchElement_Line.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "StdAfx.h"
#include "SketchElement_Line.h"
#include "SketcherEngine.h"
SketchElement_Line::SketchElement_Line(void)
{
}
SketchElement_Line::~SketchElement_Line(void)
{
}
void SketchElement_Line::Draw(SketcherEngine *pSketcher, CDC *pDC)
{
static const float PI=3.14159265f;
CPen pen;
COLORREF color=m_color;
pen.CreatePen(PS_SOLID, m_iMarkThickness, color);
CPen* pOldPen=pDC->SelectObject(&pen);
CBrush* pOldBrush=(CBrush*)pDC->SelectStockObject(NULL_BRUSH);
float rad=m_fMarkAngle * PI / 180.0f;
int dx=0;
int dy=0;
if(m_bDirectedDraw)
{
dx=static_cast<int>(m_orientation.GetX() * m_iMarkLength / 2);
dy=static_cast<int>(m_orientation.GetY() * m_iMarkLength / 2);
}
else
{
dx=static_cast<int>(m_iMarkLength * cos(rad) / 2);
dy=static_cast<int>(m_iMarkLength * sin(rad) / 2 );
}
int sx=m_pos.x + dx;
int sy=m_pos.y + dy;
int ex=m_pos.x - dx;
int ey=m_pos.y - dy;
if(sx < 0) sx=0;
if(sx >= m_iCanvasWidth) sx=m_iCanvasWidth;
if(sy < 0) sy=0;
if(sy >= m_iCanvasHeight) sy=m_iCanvasHeight;
if(ex < 0) ex=0;
if(ex >= m_iCanvasWidth) ex=m_iCanvasWidth;
if(ey < 0) ey=0;
if(ey >= m_iCanvasHeight) ey=m_iCanvasHeight;
pDC->MoveTo(ex, ey);
pDC->LineTo(sx, sy);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
pen.DeleteObject();
}