Exemplo n.º 1
0
        /// <summary>
        /// Draws the grid center middle of the region.
        /// </summary>
        public static void Draw(ColorGridStyle style, Graphics graphics, Size drawRegion, bool enabled)
        {
            float cellDim  = GetCellDimension(style, drawRegion);
            float xOffset  = (drawRegion.Width / 2f) - style.Colors.GetLength(0) * cellDim / 2;
            float yOffset  = (drawRegion.Height / 2f) - style.Colors.GetLength(1) * cellDim / 2;
            float spacing  = style.CellSpacingScale * cellDim;
            var   master   = GetMasterRectangle(style, drawRegion);
            var   backPath = RoundedRectangleF.Create(master, style.RoundedRadius);

            graphics.FillPath(enabled ? Brushes.Black : Brushes.DimGray, backPath);

            for (int row = 0; row < style.Colors.GetLength(0); row++)
            {
                for (int clm = 0; clm < style.Colors.GetLength(1); clm++)
                {
                    float dim   = cellDim - spacing * 2;
                    var   brush = new SolidBrush(style.Colors[clm, row]);
                    if (!enabled)
                    {
                        brush.Color = brush.Color.Desaturate();
                    }
                    float x    = (xOffset + cellDim * row) + spacing;
                    float y    = (yOffset + cellDim * clm) + spacing;
                    var   path = RoundedRectangleF.Create(x, y, dim, dim, style.RoundedRadius);
                    graphics.FillPath(brush, path);
                    brush.Dispose();
                }
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode   = SmoothingMode.AntiAlias;
            e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
            e.Graphics.Clear(GetBackColor());
            ColorGridRendering.Draw(Style, e.Graphics, ClientSize, Enabled);

            if (ClickMode == ClickMode.ColorSet && hoveredRect != Rectangle.Empty)
            {
                var path = RoundedRectangleF.Create(hoveredRect, RoundedRadius);
                Pen pen  = new Pen(Color.White, 3f);
                pen.Alignment = PenAlignment.Center;
                e.Graphics.DrawPath(pen, path);
                pen.Dispose();
            }
            else if (ClickMode == ClickMode.Rotation)
            {
                var rect = ColorGridRendering.GetMasterRectangle(Style, Size);

                if (rect.Contains(PointToClient(Cursor.Position)))
                {
                    ControlPaint.DrawBorder3D(e.Graphics, Rectangle.Truncate(rect),
                                              Border3DStyle.Flat);
                }
            }
        }