/// <summary> /// Draws a tree-control style expander, which looks like a square with /// a dash (expanded) or a cross (unexpanded).</summary> /// <param name="x">X coordinate of expander top right corner</param> /// <param name="y">Y coordinate of expander top right corner</param> /// <param name="pen">Pen, should be 1 pixel wide</param> /// <param name="size">Size of pin, in pixels</param> /// <param name="pinned">Whether or not expander should appear "expanded"</param> /// <param name="g">Graphics object</param> public static void DrawRightPin(int x, int y, int size, D2dBrush pen, bool pinned, D2dGraphics g) { //g.DrawRectangle(pen, x - size, y, size, size); int rectWidth = size / 4; int rectHeight = 2 * size / 3; int center = size / 2; if (pinned) { g.DrawLine(x + center - size, y + rectHeight, x + center - size, y + size, pen); //lower center-vertical line g.DrawLine(x - size, y + rectHeight, x, y + rectHeight, pen); // middle-horizontal line g.DrawRectangle(new RectangleF(x + rectWidth - size, y, 2 * rectWidth, rectHeight), pen); //g.DrawLine(pen, x + 3 * rectWidth - 1, y, x + 3 * rectWidth - 1, y + rectHeight); // a vertial line next to the right side of the rect g.DrawLine(x + 3 * rectWidth - 1 - size, y, x + 3 * rectWidth - 1 - size, y + rectHeight, pen); // a vertial line next to the right side of the rect } else { g.DrawLine(x, y + center, x - size + rectHeight, y + center, pen); //left center-horizontal line g.DrawLine(x - size + rectHeight, y, x - size + rectHeight, y + size, pen); // middle-vertical line g.DrawRectangle(new RectangleF(x - size, y + (size - rectWidth) / 2 - 1, rectHeight, 2 * rectWidth), pen); g.DrawLine(x - size + rectHeight, y + (size - rectWidth) / 2 + 2 * rectWidth - 2, x - size, y + (size - rectWidth) / 2 + 2 * rectWidth - 2, pen); // a horizontal line next to the bottom side of the rect } }
private void control_DrawingD2d(object sender, EventArgs e) { if (Selector.IsSelecting) { var d2dControl = (D2dAdaptableControl)sender; D2dGraphics g = d2dControl.D2dGraphics; // Replace transform and anti-aliasing setting. Matrix3x2F xform = d2dControl.D2dGraphics.Transform; d2dControl.D2dGraphics.Transform = Matrix3x2F.Identity; D2dAntialiasMode oldAA = d2dControl.D2dGraphics.AntialiasMode; d2dControl.D2dGraphics.AntialiasMode = D2dAntialiasMode.Aliased; // Draw the selection rectangle. Rectangle rect = MakeSelectionRect( ClientToCanvas(Selector.CurrentPoint), ClientToCanvas(Selector.FirstPoint)); rect.Intersect(AdaptedControl.ClientRectangle); var rectF = new RectangleF(rect.X, rect.Y, rect.Width, rect.Height); g.DrawRectangle(rectF, SelectionBorderColor, 1.0f, null); g.FillRectangle(rectF, SelectionFillColor); // Restore D2dGraphics settings. d2dControl.D2dGraphics.Transform = xform; d2dControl.D2dGraphics.AntialiasMode = oldAA; } }
private void PaintD2d(object sender, EventArgs e) { if (!IsContextValid()) { return; } var control = (D2dAdaptableControl)AdaptedControl; var sourceControl = m_birdEyeView.m_sourceControl; var srcXformAdapter = sourceControl.Cast <ITransformAdapter>(); D2dGraphics g = control.D2dGraphics; Matrix3x2F invXform = g.Transform; float scaleX = invXform.M11; invXform.Invert(); Point cpt = control.PointToClient(Control.MousePosition); var gpt = Matrix3x2F.TransformPoint(invXform, cpt); // transform client rect of source control to graph space. var srcInvXform = Matrix3x2F.Invert(srcXformAdapter.Transform); var grect = Matrix3x2F.Transform(srcInvXform, sourceControl.ClientRectangle); float strokeWidth = m_dragging || (grect.Contains(gpt) && control.Focused) ? 3.0f / scaleX : 1.5f / scaleX; g.DrawRectangle(grect, Color.Yellow, strokeWidth); Point srcCpt = sourceControl.PointToClient(Control.MousePosition); var srcGpt = Matrix3x2F.TransformPoint(srcInvXform, srcCpt); if (sourceControl.Focused && grect.Contains(srcGpt) && !control.ClientRectangle.Contains(cpt)) { float cursorSize = 7.0f / scaleX; RectangleF cursorRect = new RectangleF(srcGpt.X - cursorSize / 2, srcGpt.Y - cursorSize / 2, cursorSize, cursorSize); g.FillEllipse(cursorRect, Color.Yellow); } }
private void DrawOutline(TNode state, D2dBrush brush, D2dGraphics g) { RectangleF bounds = state.Bounds; if (state.Type != StateType.Normal) { g.DrawEllipse((D2dEllipse)bounds, brush, m_theme.StrokeWidth); } else { float scaleX = g.Transform.M11; // assume no rotation. float radInPixel = scaleX * CornerRadius; if (radInPixel > MinRadiusInPixel) { m_stateRect.Rect = bounds; g.DrawRoundedRectangle(m_stateRect, brush, m_theme.StrokeWidth); } else { g.DrawRectangle(bounds, brush, m_theme.StrokeWidth); } } }
/// <summary> /// Draws floating group pin</summary> /// <param name="grpPin">Group pin</param> /// <param name="inputSide">True for input pin, false for output pin</param> /// <param name="style">DiagramDrawingStyle</param> /// <param name="g">Graphics object</param> public void DrawFloatingGroupPin(ICircuitGroupPin <TElement> grpPin, bool inputSide, DiagramDrawingStyle style, D2dGraphics g) { SizeF pinNameSize = g.MeasureText(grpPin.Name, Theme.TextFormat); PointF p; if (inputSide) { p = GetGroupPinLocation(grpPin, true); RectangleF pinRect = new RectangleF(p.X + CircuitGroupPinInfo.FloatingPinBoxWidth - Theme.PinSize, grpPin.Bounds.Location.Y + Theme.PinMargin + Theme.PinOffset, Theme.PinSize, Theme.PinSize); // draw output pin for input floating pins g.DrawRectangle(pinRect, m_subGraphPinPen); if (grpPin.Info.Pinned) { D2dUtil.DrawPin((int)(p.X + CircuitGroupPinInfo.FloatingPinBoxWidth), (int)p.Y, true, true, m_pinBrush, g); } else { D2dUtil.DrawPin((int)(p.X + CircuitGroupPinInfo.FloatingPinBoxWidth), (int)p.Y + Theme.PinSize / 2, false, true, m_pinBrush, g); } RectangleF bounds = new RectangleF(p.X, p.Y, CircuitGroupPinInfo.FloatingPinBoxWidth, CircuitGroupPinInfo.FloatingPinBoxHeight); RectangleF alignRect = new RectangleF( bounds.Left, bounds.Bottom + Theme.PinMargin, pinNameSize.Width, Theme.RowSpacing); var textAlignment = Theme.TextFormat.TextAlignment; Theme.TextFormat.TextAlignment = D2dTextAlignment.Leading; g.DrawText(grpPin.Name, Theme.TextFormat, alignRect.Location, Theme.TextBrush); Theme.TextFormat.TextAlignment = textAlignment; } else { // assume vertical scroll bar width = 16 p = GetGroupPinLocation(grpPin, false); RectangleF pinRect = new RectangleF(p.X + 1, grpPin.Bounds.Location.Y + Theme.PinMargin + Theme.PinOffset, Theme.PinSize, Theme.PinSize); // draw input pin for output floating pins g.DrawRectangle(pinRect, m_subGraphPinPen); // draw pin icon if (grpPin.Info.Pinned) { D2dUtil.DrawPin((int)p.X, (int)p.Y, true, false, m_pinBrush, g); } else { D2dUtil.DrawPin((int)p.X, (int)p.Y + Theme.PinSize / 2, false, false, m_pinBrush, g); } // draw label RectangleF bounds = new RectangleF(p.X, p.Y, CircuitGroupPinInfo.FloatingPinBoxWidth, CircuitGroupPinInfo.FloatingPinBoxHeight); RectangleF alignRectF = new RectangleF(bounds.Right - pinNameSize.Width, bounds.Bottom + Theme.PinMargin, pinNameSize.Width, Theme.RowSpacing); var textAlignment = Theme.TextFormat.TextAlignment; Theme.TextFormat.TextAlignment = D2dTextAlignment.Trailing; g.DrawText(grpPin.Name, Theme.TextFormat, alignRectF, Theme.TextBrush); Theme.TextFormat.TextAlignment = textAlignment; } // draw the fake pin node itself float savedStrokeWidth = Theme.StrokeWidth; Theme.StrokeWidth = 2.0f; if (style == DiagramDrawingStyle.Normal) { g.DrawRectangle(new RectangleF(p.X, p.Y, CircuitGroupPinInfo.FloatingPinBoxWidth, CircuitGroupPinInfo.FloatingPinBoxHeight), m_subGraphPinNodePen); } else { g.DrawRectangle(new RectangleF(p.X, p.Y, CircuitGroupPinInfo.FloatingPinBoxWidth, CircuitGroupPinInfo.FloatingPinBoxHeight), Theme.HotBrush); } Theme.StrokeWidth = savedStrokeWidth; if (!grpPin.Info.ExternalConnected) { RectangleF eyeRect = GetVisibilityCheckRect(grpPin, inputSide); g.DrawEyeIcon(eyeRect, grpPin.Info.Visible ? m_visiblePinBrush : m_hiddrenPinBrush, 1.0f); } // draw fake edge that connects group pin fake node DrawGroupPinNodeFakeEdge(grpPin, p, inputSide, style, g); }
private void Draw(TNode state, D2dGraphics g, bool outline) { RectangleF bounds = state.Bounds; if (state.Type != StateType.Normal) { DrawPseudostate(state, g, outline); } else { float scaleX = g.Transform.M11; // assume no rotation. float radInPixel = scaleX * CornerRadius; IComplexState <TNode, TEdge> complexState = state as IComplexState <TNode, TEdge>; StateIndicators indicators = state.Indicators; if ((indicators & StateIndicators.Active) != 0) { if (radInPixel > MinRadiusInPixel) { D2dEllipse ellipse = new D2dEllipse(); ellipse.RadiusX = CornerRadius; ellipse.RadiusY = CornerRadius; ellipse.Center = bounds.Location; g.FillEllipse(ellipse, Color.SpringGreen); } } if (radInPixel > MinRadiusInPixel) { m_stateRect.Rect = bounds; D2dLinearGradientBrush gradbrush = m_theme.FillGradientBrush; gradbrush.StartPoint = bounds.Location; gradbrush.EndPoint = new PointF(bounds.Right, bounds.Bottom); g.FillRoundedRectangle(m_stateRect, gradbrush); if (outline) { g.DrawRoundedRectangle(m_stateRect, m_theme.OutlineBrush); } } else { g.FillRectangle(bounds, m_theme.FillBrush); if (outline) { g.DrawRectangle(bounds, m_theme.OutlineBrush); } } g.DrawLine(bounds.Left, bounds.Top + m_fontHeight + Margin, bounds.Right, bounds.Top + m_fontHeight + Margin, m_theme.OutlineBrush); if ((scaleX * m_fontHeight) > MinFontHeightInPixel) { g.DrawText(complexState.TitleText, m_theme.TextFormat, new PointF(bounds.X + CornerRadius, bounds.Y + Margin), m_theme.TextBrush); } //RectangleF textBounds = new RectangleF( // (float)(bounds.Left + 4), // (float)(bounds.Top + m_fontHeight + 2), // (float)(bounds.Width - 5), // (float)(bounds.Height - m_fontHeight - 4)); //g.DrawString(complexState.Text, m_theme.Font, m_theme.TextBrush, textBounds, s_stateTextFormat); //IList<int> partitionWidths = complexState.PartitionSizes; //if (partitionWidths.Count > 0) //{ // // draw AND-state dividers // int lastDivider = bounds.Left; // foreach (int width in partitionWidths) // { // g.DrawLine( // m_dividerPen, // lastDivider, bounds.Y + m_fontHeight + Margin, // lastDivider, bounds.Y + bounds.Height); // lastDivider += width; // } //} } }