示例#1
0
        public void ReDraw(Area area = null)
        {
            Rectangle invalidationRect;

            if (widget.GdkWindow == null)
            {
                return;
            }
            if (area == null)
            {
                invalidationRect = WidgetArea;
            }
            else
            {
                invalidationRect = new Gdk.Rectangle((int)area.Start.X - 1, (int)area.Start.Y - 1,
                                                     (int)Math.Ceiling(area.Width) + 2,
                                                     (int)Math.Ceiling(area.Height) + 2);
            }
            widget.GdkWindow.InvalidateRect(invalidationRect, true);
        }
示例#2
0
        protected override void OnSizeAllocated(Gdk.Rectangle allocation)
        {
            int lw, lh;

            layout.Width = (int)(allocation.Width * Pango.Scale.PangoScale);
            layout.GetPixelSize(out lw, out lh);

            Alignment alg = Parent as Alignment;

            if (alg != null && limitHeight)
            {
                HeightRequest = Math.Min((int)(alg.Allocation.Height - alg.TopPadding - alg.BottomPadding), lh);
            }
            else
            {
                HeightRequest = lh;
            }

            base.OnSizeAllocated(allocation);
        }
示例#3
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();
        }
示例#4
0
        unsafe public void Render(ImageSurface surface, Gdk.Rectangle[] rois)
        {
            byte startAlpha;
            byte endAlpha;

            if (this.alphaOnly)
            {
                ComputeAlphaOnlyValuesFromColors(this.startColor, this.endColor, out startAlpha, out endAlpha);
            }
            else
            {
                startAlpha = this.startColor.A;
                endAlpha   = this.endColor.A;
            }

            surface.Flush();

            ColorBgra *src_data_ptr = (ColorBgra *)surface.DataPtr;
            int        src_width    = surface.Width;

            for (int ri = 0; ri < rois.Length; ++ri)
            {
                Gdk.Rectangle rect = rois[ri];

                if (this.startPoint.X == this.endPoint.X && this.startPoint.Y == this.endPoint.Y)
                {
                    // Start and End point are the same ... fill with solid color.
                    for (int y = rect.Top; y <= rect.GetBottom(); ++y)
                    {
                        ColorBgra *pixelPtr = surface.GetPointAddress(rect.Left, y);

                        for (int x = rect.Left; x <= rect.GetRight(); ++x)
                        {
                            ColorBgra result;

                            if (this.alphaOnly && this.alphaBlending)
                            {
                                byte resultAlpha = (byte)Utility.FastDivideShortByByte((ushort)(pixelPtr->A * endAlpha), 255);
                                result   = *pixelPtr;
                                result.A = resultAlpha;
                            }
                            else if (this.alphaOnly && !this.alphaBlending)
                            {
                                result   = *pixelPtr;
                                result.A = endAlpha;
                            }
                            else if (!this.alphaOnly && this.alphaBlending)
                            {
                                result = this.normalBlendOp.Apply(*pixelPtr, this.endColor);
                                //if (!this.alphaOnly && !this.alphaBlending)
                            }
                            else
                            {
                                result = this.endColor;
                            }

                            *pixelPtr = result;
                            ++pixelPtr;
                        }
                    }
                }
                else
                {
                    var mainrect = rect;
                    Parallel.ForEach(Enumerable.Range(rect.Top, rect.Height),
                                     (y) => ProcessGradientLine(startAlpha, endAlpha, y, mainrect, surface, src_data_ptr, src_width));
                }
            }

            surface.MarkDirty();
            AfterRender();
        }
示例#5
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();
        }