internal static void DrawGrid(Graphics graphics, Rectangle viewableRectangle)
 {
     AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
     if (ambientTheme.GridStyle == DashStyle.Dot)
     {
         Point empty = Point.Empty;
         empty.X = viewableRectangle.X - (viewableRectangle.X % ambientTheme.GridSize.Width);
         empty.Y = viewableRectangle.Y - (viewableRectangle.Y % ambientTheme.GridSize.Height);
         for (int i = empty.X; i <= viewableRectangle.Right; i += Math.Max(ambientTheme.GridSize.Width, 1))
         {
             for (int j = empty.Y; j <= viewableRectangle.Bottom; j += Math.Max(ambientTheme.GridSize.Height, 1))
             {
                 graphics.FillRectangle(ambientTheme.MajorGridBrush, new Rectangle(new Point(i, j), new Size(1, 1)));
                 if ((((i + (ambientTheme.GridSize.Width / 2)) >= viewableRectangle.Left) && ((i + (ambientTheme.GridSize.Width / 2)) <= viewableRectangle.Right)) && (((j + (ambientTheme.GridSize.Height / 2)) >= viewableRectangle.Top) && ((j + (ambientTheme.GridSize.Height / 2)) <= viewableRectangle.Bottom)))
                 {
                     graphics.FillRectangle(ambientTheme.MinorGridBrush, new Rectangle(new Point(i + (ambientTheme.GridSize.Width / 2), j + (ambientTheme.GridSize.Height / 2)), new Size(1, 1)));
                 }
             }
         }
     }
     else
     {
         using (Hdc hdc = new Hdc(graphics))
         {
             using (HPen pen = new HPen(ambientTheme.MajorGridPen))
             {
                 using (HPen pen2 = new HPen(ambientTheme.MinorGridPen))
                 {
                     hdc.DrawGrid(pen, pen2, viewableRectangle, ambientTheme.GridSize, true);
                 }
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        ///     This allows collections to treat DeviceContext objects wrapping the same HDC as the same objects.
        /// </summary>


        public override int GetHashCode()
        {
            return(Hdc.GetHashCode());
        }
Beispiel #3
0
 /// <summary>
 ///  This allows collections to treat DeviceContext objects wrapping the same HDC as the same objects.
 /// </summary>
 public override int GetHashCode() => Hdc.GetHashCode();
        internal static void DrawGrid(Graphics graphics, Rectangle viewableRectangle)
        {
            AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
            if (ambientTheme.GridStyle == DashStyle.Dot)
            {
                Point gridStart = Point.Empty;
                gridStart.X = viewableRectangle.X - (viewableRectangle.X % ambientTheme.GridSize.Width);
                gridStart.Y = viewableRectangle.Y - (viewableRectangle.Y % ambientTheme.GridSize.Height);

                for (int gridCoOrdX = gridStart.X; gridCoOrdX <= viewableRectangle.Right; gridCoOrdX += Math.Max(ambientTheme.GridSize.Width, 1))
                {
                    for (int gridCoOrdY = gridStart.Y; gridCoOrdY <= viewableRectangle.Bottom; gridCoOrdY += Math.Max(ambientTheme.GridSize.Height, 1))
                    {
                        graphics.FillRectangle(ambientTheme.MajorGridBrush, new Rectangle(new Point(gridCoOrdX, gridCoOrdY), new Size(1, 1)));

                        if (((gridCoOrdX + ambientTheme.GridSize.Width / 2) >= viewableRectangle.Left && (gridCoOrdX + ambientTheme.GridSize.Width / 2) <= viewableRectangle.Right) &&
                            ((gridCoOrdY + ambientTheme.GridSize.Height / 2) >= viewableRectangle.Top && (gridCoOrdY + ambientTheme.GridSize.Height / 2) <= viewableRectangle.Bottom))
                            graphics.FillRectangle(ambientTheme.MinorGridBrush, new Rectangle(new Point(gridCoOrdX + ambientTheme.GridSize.Width / 2, gridCoOrdY + ambientTheme.GridSize.Height / 2), new Size(1, 1)));
                    }
                }
            }
            else
            {
                //We use native pens to draw the grid for efficiency reason
                using (Hdc hdc = new Hdc(graphics))
                using (HPen majorGridPen = new HPen(ambientTheme.MajorGridPen))
                using (HPen minorGridPen = new HPen(ambientTheme.MinorGridPen))
                {
                    hdc.DrawGrid(majorGridPen, minorGridPen, viewableRectangle, ambientTheme.GridSize, true);
                }
            }
        }