Line | |
---|
1 | using System.Drawing;
|
---|
2 |
|
---|
3 | namespace Netron.Diagramming.Core {
|
---|
4 | // ----------------------------------------------------------------------
|
---|
5 | /// <summary>
|
---|
6 | /// Aligns the center of the selected entities horizontally.
|
---|
7 | /// </summary>
|
---|
8 | // ----------------------------------------------------------------------
|
---|
9 | public class AlignCentersHorizontallyTool : AlignmentToolBase {
|
---|
10 | // ------------------------------------------------------------------
|
---|
11 | /// <summary>
|
---|
12 | /// Constructor.
|
---|
13 | /// </summary>
|
---|
14 | /// <param name="toolName">string: The name of this tool</param>
|
---|
15 | // ------------------------------------------------------------------
|
---|
16 | public AlignCentersHorizontallyTool(string toolName)
|
---|
17 | : base(toolName) {
|
---|
18 | }
|
---|
19 |
|
---|
20 | // ------------------------------------------------------------------
|
---|
21 | /// <summary>
|
---|
22 | /// Aligns the center of all selected entities horizontally. The
|
---|
23 | /// 'X' component of the center location of the first entity in the
|
---|
24 | /// selection is used for all other entities.
|
---|
25 | /// </summary>
|
---|
26 | // ------------------------------------------------------------------
|
---|
27 | public override void Align(IDiagramEntity[] entities) {
|
---|
28 | // The amount to offset the entities by.
|
---|
29 | Point offset;
|
---|
30 |
|
---|
31 | for (int i = 1; i < entities.Length; i++) {
|
---|
32 | IDiagramEntity entity = entities[i];
|
---|
33 |
|
---|
34 | // Keep the entities same y location but offset it's
|
---|
35 | // x location.
|
---|
36 | offset = new Point(
|
---|
37 | this.centerOfFirstEntity.X - entity.Center.X,
|
---|
38 | 0);
|
---|
39 |
|
---|
40 | // Move the entity by this amount.
|
---|
41 | entity.MoveBy(offset);
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.