示例#1
0
        private void DrawBackground(Context ctx, RectangleF area)
        {
            var colorWhite = Color.White;
            var colorBlack = new Color(230, 230, 230, 255);
            int size       = 6;
            int count      = 0;

            for (int x = 0; x < area.Width / size; x++)
            {
                for (int y = 0; y < area.Height / size; y++)
                {
                    bool even = (x % 2 == 0) ^ (y % 2 == 0);

                    WidgetTools.SetColor(ctx, even ? colorWhite : colorBlack);
                    ctx.Rectangle(area.X + x * size, area.Y + y * size, size, size);
                    ctx.Fill();
                }
            }
        }
示例#2
0
        public void Draw(Gdk.Drawable window, Cairo.Context ctx, Gdk.Rectangle bounds, StateType state)
        {
            if (noise == null)
            {
                return;
            }

            var drawBounds  = GraphAreaFromBounds(new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height));
            var outerBounds = drawBounds.Inflated(3);

            // Outer clip area
            ctx.Save();
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Clip();

            var colorSelectedBackground = WidgetTools.ColorSelectedBackground;
            var colorBorder             = WidgetTools.ColorBorder;
            var colorLine = WidgetTools.ColorLine;

            // Background
            if (state == StateType.Selected)
            {
                WidgetTools.SetColor(ctx, colorSelectedBackground);
                ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
                ctx.Fill();
            }

            // Border
            WidgetTools.SetColor(ctx, colorBorder);
            ctx.LineWidth = 1.0;
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Stroke();

            // Zero line
            if (HasZeroLine)
            {
                var height = ToScreen(Vector2.Zero, drawBounds);
                WidgetTools.SetColor(ctx, colorBorder);
                ctx.MoveTo(outerBounds.X, height.Y);
                ctx.LineTo(outerBounds.X + outerBounds.Width, height.Y);
                ctx.LineWidth = 1.0;
                WidgetTools.SetDash(ctx, true);
                ctx.Stroke();
            }

            ////// Inner clip area
            ////ctx.Rectangle(drawBounds.X, drawBounds.Y, drawBounds.Width, drawBounds.Height);
            ////ctx.Clip();

            //if (noise.Count > 0)
            {
                WidgetTools.SetColor(ctx, colorLine);

                int numSteps = (int)drawBounds.Width;

                var p = Evaluate(0, drawBounds);
                ctx.MoveTo(p.X, p.Y);
                ctx.LineWidth = 1.2;
                WidgetTools.SetDash(ctx, false);

                int part = 0;

                for (int i = 0; numSteps > 0 && i <= numSteps; i++)
                {
                    var fraction = (float)i / numSteps;

                    //if (fraction >= startFraction && part == 0)
                    //{
                    //    p = ToScreen(noise.Front.Value, drawBounds);
                    //    ctx.LineTo(p.X, p.Y);
                    //    ctx.Stroke();
                    //    SetDash(ctx, false);
                    //    ctx.MoveTo(p.X, p.Y);

                    //    part++;
                    //}

                    //if (fraction >= endFraction && part == 1)
                    //{
                    //    p = ToScreen(noise.End.Value, drawBounds);
                    //    ctx.LineTo(p.X, p.Y);
                    //    ctx.Stroke();
                    //    SetDash(ctx, true);
                    //    ctx.MoveTo(p.X, p.Y);

                    //    part++;
                    //}

                    p = Evaluate(fraction, drawBounds);
                    ctx.LineTo(p.X, p.Y);
                }

                ctx.Stroke();
                //SetDash(ctx, false);

                //foreach (var entry in noise)
                //{
                //    var b = ToScreen(entry.Value, drawBounds);
                //    float size = 4;
                //    float outerSize = size + 1;

                //    var color = colorLine;
                //    var outerColor = MG.Framework.Numerics.Color.Transparent;


                //    if (outerColor.A != 0)
                //    {
                //        SetColor(ctx, outerColor);
                //        ctx.Rectangle(b.X - outerSize / 2, b.Y - outerSize / 2, outerSize, outerSize);
                //        ctx.LineWidth = 1.0;
                //        ctx.Stroke();
                //    }

                //    SetColor(ctx, color);
                //    ctx.Rectangle(b.X - size / 2, b.Y - size / 2, size, size);
                //    ctx.Fill();
                //}
            }

            ctx.Restore();
        }
示例#3
0
        public void Draw(Drawable window, Context ctx, Rectangle bounds, StateType state)
        {
            if (gradient == null)
            {
                return;
            }

            int outerBoundsThickness = 4;

            var area                    = AreaFromBounds(new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height));
            var outerBounds             = area.Inflated(outerBoundsThickness);
            var colorBorder             = new Color(204, 204, 204, 255);
            var colorSelectedBackground = new Color(154, 154, 154, 255);
            var colorEntry              = Color.Black;

            ctx.Save();

            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Clip();

            // Border
            WidgetTools.SetColor(ctx, state == StateType.Selected ? colorSelectedBackground : colorBorder);
            //SetColor(ctx, colorBorder);
            ctx.LineWidth = 1.0;
            ctx.Antialias = Antialias.Default;
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Stroke();

            // Clip inner area
            ctx.Rectangle(outerBounds.X + 1, outerBounds.Y + 1, outerBounds.Width - 2, outerBounds.Height - 2);
            ctx.Clip();

            // Background
            DrawBackground(ctx, outerBounds);

            // Gradient
            if (gradient.Count > 0 && area.Width > 0)
            {
                int numSteps = (int)outerBounds.Width;

                // Could be done much cheaper with cairo gradients, but this way we'll show the actual values
                for (int i = 0; numSteps > 0 && i < numSteps; i++)
                {
                    var fraction = (i - outerBoundsThickness) / area.Width;
                    fraction = MathTools.ClampNormal(fraction);

                    WidgetTools.SetColor(ctx, gradient.Evaluate(fraction));

                    float x = outerBounds.Position.X + i;
                    float y = outerBounds.Position.Y;
                    ctx.MoveTo(x, y);
                    ctx.LineTo(x, y + outerBounds.Height);
                    ctx.Antialias = Antialias.None;
                    ctx.Stroke();
                }
            }

            // Entries
            foreach (var entry in gradient)
            {
                var slice = GetEntryArea(entry.Position, area);

                ctx.Antialias = Antialias.None;

                ctx.Rectangle(slice.X, slice.Y, slice.Width, slice.Height);
                WidgetTools.SetColor(ctx, entry.Color);
                ctx.Fill();

                Color edgeColor = entry == hoveredEntry?GetComplementary1(entry.Color) : GetComplementary2(entry.Color);

                ctx.Rectangle(slice.X, slice.Y, slice.Width, slice.Height);
                ctx.LineWidth = 1;
                WidgetTools.SetColor(ctx, edgeColor);
                ctx.Stroke();

                if (entry == selectedEntry)
                {
                    ctx.Rectangle(slice.X + 1, slice.Y + 1, slice.Width - 2, slice.Height - 2);
                    ctx.LineWidth = 1;
                    WidgetTools.SetColor(ctx, edgeColor);
                    ctx.Stroke();
                }
            }

            ctx.Restore();
        }
示例#4
0
        public void Draw(Gdk.Drawable window, Cairo.Context ctx, Gdk.Rectangle bounds, StateType state)
        {
            if (curve == null)
            {
                return;
            }

            var drawBounds  = GraphAreaFromBounds(new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height));
            var outerBounds = drawBounds.Inflated(3);

            // Outer clip area
            ctx.Save();
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Clip();

            var colorSelectedBackground = WidgetTools.ColorSelectedBackground;
            var colorBorder             = WidgetTools.ColorBorder;
            var colorLine          = WidgetTools.ColorLine;
            var colorHoveredEntry  = WidgetTools.ColorHoveredEntry;
            var colorSelectedEntry = WidgetTools.ColorSelectedEntry;

            // Background
            if (state == StateType.Selected)
            {
                WidgetTools.SetColor(ctx, colorSelectedBackground);
                ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
                ctx.Fill();
            }

            // Border
            WidgetTools.SetColor(ctx, colorBorder);
            ctx.LineWidth = 1.0;
            ctx.Rectangle(outerBounds.X, outerBounds.Y, outerBounds.Width, outerBounds.Height);
            ctx.Stroke();

            // Zero line
            if (HasZeroLine)
            {
                var height = ToScreen(Vector2.Zero, drawBounds);
                WidgetTools.SetColor(ctx, colorBorder);
                ctx.MoveTo(outerBounds.X, height.Y);
                ctx.LineTo(outerBounds.X + outerBounds.Width, height.Y);
                ctx.LineWidth = 1.0;
                WidgetTools.SetDash(ctx, true);
                ctx.Stroke();
            }

            //// Inner clip area
            //ctx.Rectangle(drawBounds.X, drawBounds.Y, drawBounds.Width, drawBounds.Height);
            //ctx.Clip();

            if (curve.Count > 0)
            {
                WidgetTools.SetColor(ctx, colorLine);

                int numSteps = (int)drawBounds.Width;

                var p = Evaluate(0, drawBounds);
                ctx.MoveTo(p.X, p.Y);
                ctx.LineWidth = 1.2;
                WidgetTools.SetDash(ctx, true);

                var startFraction = curve.Front.Value.X;
                var endFraction   = curve.End.Value.X;
                int part          = 0;

                for (int i = 0; numSteps > 0 && i <= numSteps; i++)
                {
                    var fraction = (float)i / numSteps;

                    if (fraction >= startFraction && part == 0)
                    {
                        p = ToScreen(curve.Front.Value, drawBounds);
                        ctx.LineTo(p.X, p.Y);
                        ctx.Stroke();
                        WidgetTools.SetDash(ctx, false);
                        ctx.MoveTo(p.X, p.Y);

                        part++;
                    }

                    if (fraction >= endFraction && part == 1)
                    {
                        p = ToScreen(curve.End.Value, drawBounds);
                        ctx.LineTo(p.X, p.Y);
                        ctx.Stroke();
                        WidgetTools.SetDash(ctx, true);
                        ctx.MoveTo(p.X, p.Y);

                        part++;
                    }

                    p = Evaluate(fraction, drawBounds);
                    ctx.LineTo(p.X, p.Y);
                }

                ctx.Stroke();
                WidgetTools.SetDash(ctx, false);

                foreach (var entry in curve)
                {
                    var   b         = ToScreen(entry.Value, drawBounds);
                    float size      = 4;
                    float outerSize = size + 1;

                    var color      = colorLine;
                    var outerColor = MG.Framework.Numerics.Color.Transparent;
                    if (entry == hoveredEntry)
                    {
                        color = colorHoveredEntry;
                    }

                    if (entry == selectedEntry)
                    {
                        color      = colorHoveredEntry;
                        outerColor = colorSelectedEntry;

                        ctx.LineWidth = 1.0;
                        WidgetTools.SetColor(ctx, outerColor);

                        if (entry.Type == CurveEntry.EntryType.Bezier)
                        {
                            ctx.MoveTo(b.X, b.Y);
                            p = ToScreen(entry.LeftHandle, drawBounds);
                            ctx.LineTo(p.X, p.Y);
                            ctx.Stroke();

                            WidgetTools.SetColor(ctx, hoveredHandle == Handle.Left ? colorHoveredEntry : outerColor);
                            ctx.Arc(p.X, p.Y, 2, 0, 2 * Math.PI);
                            ctx.Fill();

                            WidgetTools.SetColor(ctx, outerColor);
                            ctx.MoveTo(b.X, b.Y);
                            p = ToScreen(entry.RightHandle, drawBounds);
                            ctx.LineTo(p.X, p.Y);
                            ctx.Stroke();

                            WidgetTools.SetColor(ctx, hoveredHandle == Handle.Right ? colorHoveredEntry : outerColor);
                            ctx.Arc(p.X, p.Y, 2, 0, 2 * Math.PI);
                            ctx.Fill();
                        }
                    }

                    if (outerColor.A != 0)
                    {
                        WidgetTools.SetColor(ctx, outerColor);
                        ctx.Rectangle(b.X - outerSize / 2, b.Y - outerSize / 2, outerSize, outerSize);
                        ctx.LineWidth = 1.0;
                        ctx.Stroke();
                    }

                    WidgetTools.SetColor(ctx, color);
                    ctx.Rectangle(b.X - size / 2, b.Y - size / 2, size, size);
                    ctx.Fill();
                }
            }

            ctx.Restore();
        }