-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodeHorizontal.cpp
176 lines (151 loc) · 5.36 KB
/
NodeHorizontal.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "NodeHorizontal.h"
#include <algorithm>
#include "nodehelperinfo.h"
#include "OutputBase.h"
#include "displayhint.h"
#include "expressiondepth.h"
#include "DefaultGraphicsSeparator.h"
namespace NodeHorizontal_impl
{
const int leftPadding = 5;
const int rightPadding = 5;
const int middlePadding = 5;
const int topPadding = 5;
const int bottomPadding = 5;
const SizeFactor factorDiffer = 8;
SizeFactor computSizeFactorOfChildNode(SizeFactor myFactor)
{
return myFactor-factorDiffer;
}
SizeFactor computeMySizeFactorFromChildFactor(SizeFactor childFactor)
{
return childFactor+factorDiffer;
}
Point computeLeftChildPos(Size const&mySize,Size const&leftSize)
{
return Point(0,(mySize.height()-leftSize.height())/2);//垂直方向上居中
}
Point computeRightChildPoint(Point const&myNotationPos,Size const¬ationSize)
{
return myNotationPos+Point(notationSize.width()+middlePadding,0);
}
// Size computeSize(Size const&left,Size const&middle,Size const& right)
// {
// Size ret;
// ret.width()=leftPadding
// +left.width()
// +middlePadding
// +middle.width()
// +middlePadding
// +right.width()
// +rightPadding;
// ret.height() =topPadding
// +std::max
// (
// std::max
// (
// left.height(),middle.height()
// ),
// right.height()
// )
// +bottomPadding;
// return ret;
// }
}
void NodeHorizontal::display(OutputBase &o,Point topLeft) const
{
using namespace NodeHorizontal_impl;
o.put(notation(),
Rect(positionOfMyNotaion+topLeft,sizeOfMyNotation),
getFactorOfCurrentSize()
);
}
//bool NodeHorizontal::isSizeUpdated() const
//{
// return left->isSizeUpdated()&&right->isSizeUpdated();
//}
void NodeHorizontal::updateLeftPos()
{
using namespace NodeHorizontal_impl;
Size leftSize = left->getCurrentSize();
left->setCurrentTopLeft(Point(leftPadding,(getCurrentSize().height()-topPadding-bottomPadding-leftSize.height())/2+topPadding),getCurrentSize());
}
void NodeHorizontal::updateMyNotationPos()
{
using namespace NodeHorizontal_impl;
Point leftPos = left->getCurrentTopLeft();
Size leftSize = left->getCurrentSize();
positionOfMyNotaion = Point(leftPos.x()+leftSize.width()+middlePadding,
(getCurrentSize().height()-topPadding-bottomPadding-sizeOfMyNotation.height())/2+topPadding);
}
void NodeHorizontal::updateRightPos()
{
using namespace NodeHorizontal_impl;
Size rightSize = right->getCurrentSize();
right->setCurrentTopLeft(Point(positionOfMyNotaion.x()+sizeOfMyNotation.width()+middlePadding,
(getCurrentSize().height()-topPadding-bottomPadding-rightSize.height())/2+topPadding),getCurrentSize());
}
void NodeHorizontal::updateChildAndNotaionPosition()
{
using namespace NodeHorizontal_impl;
updateLeftPos();
updateMyNotationPos();
updateRightPos();
}
void NodeHorizontal::updateMyNotationSize(SizeFactor newSizeFactor)
{
setFactorOfCurrentSize(newSizeFactor);
sizeOfMyNotation = getNodeHelper()
->pDisplayHint
->sizeHint(notation(),getFactorOfCurrentSize());
}
void NodeHorizontal::updateMySize()
{
using namespace NodeHorizontal_impl;
Size l = left->getCurrentSize();
Size r = right->getCurrentSize();
Size newSize;
newSize.width() = leftPadding
+l.width()
+middlePadding
+sizeOfMyNotation.width()
+middlePadding
+r.width()
+rightPadding;
newSize.height() = topPadding
+std::max
(
std::max
(
l.height(),sizeOfMyNotation.height()
)
,r.height()
)
+bottomPadding;
setCurrentSize(newSize);
}
void NodeHorizontal::updateSize(SizeFactor newSizeFactor)
{
using namespace NodeHorizontal_impl;
NodeBase::updateSize(newSizeFactor);
SizeFactor newChildSizeFactor = computSizeFactorOfChildNode(newSizeFactor);
left->updateSize(newChildSizeFactor);
right->updateSize(newChildSizeFactor);
if(getFactorOfCurrentSize() != newSizeFactor)
{
updateMyNotationSize(newSizeFactor);
}
updateMySize();
updateChildAndNotaionPosition();
}
SizeFactor NodeHorizontal::getMinimumSizeFactor(DepthNum n)const
{
using namespace NodeHorizontal_impl;
//使用者调用updateSize时其参数不得小于此,所以是minimum
return computeMySizeFactorFromChildFactor(std::max(left->getMinimumSizeFactor(getChildDepth(n)),
right->getMinimumSizeFactor(getChildDepth(n))));
}
DepthNum NodeHorizontal::getChildDepth(DepthNum myDepth) const
{
return getNodeHelper()->pExpressionDepth->getChildDepth(myDepth);
}