private void DrawElements(Graphics graphics) { LayoutProperties layoutProperties = new LayoutProperties(); layoutProperties.DesignAreaLocation = DesignAreaLocation; layoutProperties.DesignAreaSize = DesignAreaSize; layoutProperties.ViewportLocation = ViewportLocation; layoutProperties.ViewportSize = ViewportSize; layoutProperties.ZoomRatio = ZoomRatio; foreach (LayoutElement element in Layout.Elements) { LayoutElementRenderer elementRenderer = GetElementRendererForElementType(element.TypeName); if (elementRenderer != null) { elementRenderer.Draw(element, graphics, layoutProperties); if (IsElementInSelection(element)) { TransformHandleType transformHandleType = TransformHandleType.All; VisualLayoutElement visualLayoutElement = element as VisualLayoutElement; if (visualLayoutElement != null && !visualLayoutElement.Rotatable) { if (!KeyboardHelper.IsShiftKeyPressed) { transformHandleType = TransformHandleType.All; } else { transformHandleType = TransformHandleType.OnlyCorners; } } DesignerHelper.DrawTransformHandles(graphics, element, layoutProperties, transformHandleType); } } else { throw new Exception("Element renderer for element type not found!"); } } }
public static void DrawTransformHandles(Graphics graphics, LayoutElement element, LayoutProperties layoutProperties, TransformHandleType handleType) { Point elementLocation = element.Location.Multiply(layoutProperties.ZoomRatio); elementLocation = elementLocation.Add(layoutProperties.DesignAreaLocation); elementLocation = elementLocation.Subtract(layoutProperties.ViewportLocation); Size elementSize = element.Size; elementSize = elementSize.Multiply(layoutProperties.ZoomRatio); Pen penRectangle = new Pen(Color.Silver); graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation, elementSize), 1); Pen penHandle = new Pen(Color.Black); Brush brushHandle = new SolidBrush(Color.White); Size handleSize = new Size(HANDLE_WIDTH, HANDLE_HEIGHT); if (handleType == TransformHandleType.All || handleType == TransformHandleType.OnlyCorners) { graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()), handleSize), 2); graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()), handleSize), 2); } if (handleType == TransformHandleType.All) { graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width / 2), handleSize), 2); graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width / 2), handleSize), 2); } if (handleType == TransformHandleType.All || handleType == TransformHandleType.OnlyCorners) { graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width), handleSize), 2); graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width), handleSize), 2); } if (handleType == TransformHandleType.All) { graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddY(elementSize.Height / 2), handleSize), 2); graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddY(elementSize.Height / 2), handleSize), 2); } if (handleType == TransformHandleType.All) { graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width).AddY(elementSize.Height / 2), handleSize), 2); graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width).AddY(elementSize.Height / 2), handleSize), 2); } if (handleType == TransformHandleType.All || handleType == TransformHandleType.OnlyCorners) { graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddY(elementSize.Height), handleSize), 2); graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddY(elementSize.Height), handleSize), 2); } if (handleType == TransformHandleType.All) { graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width / 2).AddY(elementSize.Height), handleSize), 2); graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width / 2).AddY(elementSize.Height), handleSize), 2); } if (handleType == TransformHandleType.All || handleType == TransformHandleType.OnlyCorners) { graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width).AddY(elementSize.Height), handleSize), 2); graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width).AddY(elementSize.Height), handleSize), 2); } }