-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathLabelDrawingHelper.cpp
More file actions
116 lines (110 loc) · 3.07 KB
/
LabelDrawingHelper.cpp
File metadata and controls
116 lines (110 loc) · 3.07 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "stdafx.h"
#include "LabelDrawingHelper.h"
// ********************************************************************
// CalcRotation
// ********************************************************************
void LabelDrawingHelper::CalcRotation(CLabelInfo* lbl, double mapRotation, double& angle)
{
if (!lbl) return;
if (lbl->rotation == 0.0 && mapRotation != 0.0)
{
angle = long(mapRotation) % 360;
}
else if (lbl->rotation != 0.0 && mapRotation != 0.0)
{
if (lbl->rotation > 0)
{
angle = long(lbl->rotation - mapRotation) % 360;
if (angle > 90 && angle < 180 || angle < -90 && angle >= -180)
angle = long(lbl->rotation) % 360 + 180;
else if (angle >= 180.0 && angle < 270.0 || angle < -180.0 && angle >= -270.0)
angle = long(lbl->rotation) % 360 - 180;
else
angle = long(lbl->rotation) % 360;
}
else
{
angle = long(mapRotation - lbl->rotation) % 360;
if (angle > 0.0 && angle < 90.0)
angle = long(lbl->rotation) % 360;
else if (angle > 90.0 && angle < 180.0)
angle = long(lbl->rotation) % 360 + 180.0;
else if (angle >= 180.0 && angle < 270.0)
angle = long(lbl->rotation) % 360 - 180.0;
else
angle = long(lbl->rotation) % 360;
}
}
else
{
// we don't want our labels to be upside-down
angle = long(lbl->rotation) % 360;
if (angle > 90.0 && angle < 180) angle += 180.0;
else if (angle >= 180.0 && angle < 270.0) angle -= 180.0;
}
}
// ********************************************************************
// AlignRectangle
// ********************************************************************
// rectangle for text printing is aligned around (0,0) with proper rotation
void LabelDrawingHelper::AlignRectangle(CRect& rect, tkLabelAlignment alignment)
{
// width and height, projected on the X and Y axes
switch (alignment)
{
case laTopLeft:
rect.MoveToXY(-rect.Width(), -rect.Height());
break;
case laTopCenter:
rect.MoveToXY(-rect.Width() / 2, -rect.Height());
break;
case laTopRight:
rect.MoveToXY(0, -rect.Height());
break;
case laCenterLeft:
rect.MoveToXY(-rect.Width(), -rect.Height() / 2);
break;
case laCenter:
rect.MoveToXY(-rect.Width() / 2, -rect.Height() / 2);
break;
case laCenterRight:
rect.MoveToXY(0, -rect.Height() / 2);
break;
case laBottomLeft:
rect.MoveToXY(-rect.Width(), 0);
break;
case laBottomCenter:
rect.MoveToXY(-rect.Width() / 2, 0);
break;
case laBottomRight:
rect.MoveToXY(0, 0);
break;
}
return;
}
// ********************************************************************
// UpdateAutoOffset
// ********************************************************************
void LabelDrawingHelper::UpdateAutoOffset(CRect& rect, tkLabelAlignment align, int offset)
{
if (align == laTopRight ||
align == laBottomRight ||
align == laCenterRight)
{
rect.OffsetRect(offset, 0);
}
else if (align == laTopLeft ||
align == laBottomLeft ||
align == laCenterLeft)
{
rect.OffsetRect(-offset, 0);
}
else if (align == laTopCenter)
{
rect.OffsetRect(0, -offset);
}
else if (align == laBottomCenter)
{
rect.OffsetRect(0, offset);
}
}