OSDN Git Service

Change Dir Structure to be same as TortoiseSVN'
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RevisionGraph / StandardLayoutConnectionList.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "StdAfx.h"\r
20 #include "StandardLayoutConnectionList.h"\r
21 \r
22 // construction\r
23 \r
24 CStandardLayoutConnectionList::CStandardLayoutConnectionList \r
25     ( const std::vector<CStandardLayoutNodeInfo>& nodes\r
26     , const std::vector<std::pair<index_t, index_t> >& connections)\r
27     : nodes (nodes)\r
28     , connections (connections)\r
29 {\r
30 }\r
31 \r
32 // implement ILayoutItemList\r
33 \r
34 index_t CStandardLayoutConnectionList::GetCount() const\r
35 {\r
36     return static_cast<index_t>(connections.size());\r
37 }\r
38 \r
39 CString CStandardLayoutConnectionList::GetToolTip (index_t /* index */) const\r
40 {\r
41     return CString();\r
42 }\r
43 \r
44 index_t CStandardLayoutConnectionList::GetFirstVisible \r
45     (const CRect& viewRect) const\r
46 {\r
47     return GetNextVisible (static_cast<index_t>(-1), viewRect);\r
48 }\r
49 \r
50 index_t CStandardLayoutConnectionList::GetNextVisible \r
51     ( index_t prev\r
52     , const CRect& viewRect) const\r
53 {\r
54     for (size_t i = prev+1, count = connections.size(); i < count; ++i)\r
55     {\r
56         const std::pair<index_t, index_t>& connection = connections[i];\r
57 \r
58         CRect commonRect;\r
59         commonRect.UnionRect ( nodes[connection.first].rect\r
60                              , nodes[connection.second].rect);\r
61         if (FALSE != CRect().IntersectRect (commonRect, viewRect))\r
62             return static_cast<index_t>(i);\r
63     }\r
64 \r
65     return static_cast<index_t>(NO_INDEX);\r
66 }\r
67 \r
68 index_t CStandardLayoutConnectionList::GetAt \r
69     ( const CPoint& /* point */\r
70     , long /* delta */) const\r
71 {\r
72     return static_cast<index_t>(NO_INDEX);\r
73 }\r
74 \r
75 // implement ILayoutConnectionList\r
76 \r
77 CStandardLayoutConnectionList::SConnection \r
78 CStandardLayoutConnectionList::GetConnection (index_t index) const\r
79 {\r
80     // determine the end points of the connection\r
81 \r
82     const std::pair<index_t, index_t>& connection = connections[index];\r
83     const CRect* source = &nodes[connection.first].rect;\r
84     const CRect* dest = &nodes[connection.second].rect;\r
85 \r
86     if (source->left > dest->right)\r
87         std::swap (source, dest);\r
88 \r
89         CPoint startPoint;\r
90         CPoint endPoint;\r
91 \r
92     if (source->right < dest->left)\r
93     {\r
94         // there is a vertical gap between source and dest\r
95 \r
96         startPoint.x = source->right;\r
97         startPoint.y = (source->top + source->bottom) / 2;\r
98     }\r
99     else\r
100     {\r
101         // there must be a horizontal gap\r
102 \r
103         if (source->top > dest->top)\r
104             std::swap (source, dest);\r
105 \r
106         startPoint.x = (source->left + source->right) / 2;\r
107         startPoint.y = source->bottom;\r
108     }\r
109 \r
110     endPoint.x = (dest->left + dest->right) / 2;\r
111     endPoint.y = dest->top > startPoint.y ? dest->top : dest->bottom;\r
112     \r
113     // Bezier points\r
114 \r
115     static CPoint points[4];\r
116 \r
117         points[0] = startPoint;\r
118         points[1].x = (startPoint.x + endPoint.x) / 2;          // first control point\r
119         points[1].y = startPoint.y;\r
120         points[2].x = endPoint.x;                                                       // second control point\r
121         points[2].y = startPoint.y;\r
122         points[3] = endPoint;\r
123 \r
124     // construct result\r
125 \r
126     SConnection result;\r
127 \r
128     result.style = 0;\r
129     result.numberOfPoints = 4;\r
130     result.points = points;\r
131 \r
132     return result;\r
133 }\r