예제 #1
0
        public FastBitmap CreateBitmap(CalculatedFractalPart calculatedFractalPart, IFractalSettings settings, IShader shader)
        {
            var fastBitmap = new FastBitmap(
                calculatedFractalPart.ScreenPosition.Right - calculatedFractalPart.ScreenPosition.Left + 1,
                calculatedFractalPart.ScreenPosition.Bottom - calculatedFractalPart.ScreenPosition.Top + 1);

            using (var lazyGraphics = new LazyGraphics(fastBitmap.Bitmap))
            {
                using (var pens = new PenCache())
                {
                    foreach (var path in calculatedFractalPart.Paths)
                    {
                        var color = shader.GetColor(path.Value, settings.MaxIterations);
                        DrawPath(path, color, fastBitmap, pens, lazyGraphics);
                    }
                }
            }

            return(fastBitmap);
        }
예제 #2
0
        private int drawCursor(int cursor, CharacterRange part, float offset, Graphics g, string atomRaw, Style thisStyle)
        {
            if (cursor < 0 || cursor >= part.Length)
            {
                return(part.Length);
            }

            renderStuff.caretRect = MeasureStringPart(new CharacterRange(cursor, 1), g, atomRaw, thisStyle);

            var caretRect = renderStuff.caretRect;

            caretRect.Offset(offset, 0);

            var pen = PenCache.GetSolid(Color.Black);

            pen.Width = 2;

            g.DrawLine(pen, caretRect.Left, caretRect.Top, caretRect.Left, caretRect.Bottom);

            return(part.Length);
        }
예제 #3
0
        protected void CalculateAndDrawRectangles(Graphics oGraphics, RectangleF oTreemapRectangle, Nodes oNodes, Node oParentNode)
        {
            Debug.Assert(oGraphics != null);
            Debug.Assert(oNodes != null);
            this.AssertValid();
            Brush brush = new SolidBrush(this.m_oBackColor);

            oGraphics.FillRectangle(brush, oTreemapRectangle);
            brush.Dispose();
            ILayoutEngine oLayoutEngine = this.CreateLayoutEngine();

            this.CalculateRectangles(oNodes, oTreemapRectangle, oParentNode, this.GetTopLevelTopPaddingPx(oGraphics), this.m_iPaddingPx, this.m_iPenWidthPx, oLayoutEngine);
            ColorGradientMapper colorGradientMapper  = null;
            ColorGradientMapper colorGradientMapper2 = null;

            if (this.m_eNodeColorAlgorithm == NodeColorAlgorithm.UseColorMetric)
            {
                colorGradientMapper = new ColorGradientMapper();
                Debug.Assert(this.m_fMaxColorMetric > 0f);
                colorGradientMapper.Initialize(oGraphics, 0f, this.m_fMaxColorMetric, Color.White, this.m_oMaxColor, this.m_iDiscretePositiveColors, true);
                colorGradientMapper2 = new ColorGradientMapper();
                Debug.Assert(this.m_fMinColorMetric < 0f);
                colorGradientMapper2.Initialize(oGraphics, 0f, -this.m_fMinColorMetric, Color.White, this.m_oMinColor, this.m_iDiscreteNegativeColors, true);
            }
            PenCache penCache = new PenCache();

            penCache.Initialize(this.m_oBorderColor);
            this.DrawRectangles(oNodes, 0, oGraphics, colorGradientMapper2, colorGradientMapper, penCache);
            if (colorGradientMapper2 != null)
            {
                colorGradientMapper2.Dispose();
            }
            if (colorGradientMapper != null)
            {
                colorGradientMapper.Dispose();
            }
            penCache.Dispose();
        }
예제 #4
0
        protected void DrawRectangles(Nodes oNodes, int iNodeLevel, Graphics oGraphics, ColorGradientMapper oNegativeColorGradientMapper, ColorGradientMapper oPositiveColorGradientMapper, PenCache oPenCache)
        {
            Debug.Assert(oNodes != null);
            Debug.Assert(iNodeLevel >= 0);
            Debug.Assert(oGraphics != null);
            Debug.Assert(this.m_eNodeColorAlgorithm != NodeColorAlgorithm.UseColorMetric || oNegativeColorGradientMapper != null);
            Debug.Assert(this.m_eNodeColorAlgorithm != NodeColorAlgorithm.UseColorMetric || oPositiveColorGradientMapper != null);
            Debug.Assert(oPenCache != null);
            foreach (Node current in oNodes)
            {
                if (!current.Rectangle.IsEmpty)
                {
                    Pen   pen   = oPenCache.GetPen(current.PenWidthPx);
                    Brush brush = null;
                    bool  flag  = false;
                    switch (this.m_eNodeColorAlgorithm)
                    {
                    case NodeColorAlgorithm.UseColorMetric:
                    {
                        Debug.Assert(oNegativeColorGradientMapper != null);
                        Debug.Assert(oPositiveColorGradientMapper != null);
                        float colorMetric = current.ColorMetric;
                        if (colorMetric <= 0f)
                        {
                            brush = oNegativeColorGradientMapper.ColorMetricToBrush(-colorMetric);
                        }
                        else
                        {
                            brush = oPositiveColorGradientMapper.ColorMetricToBrush(colorMetric);
                        }
                        break;
                    }

                    case NodeColorAlgorithm.UseAbsoluteColor:
                    {
                        brush = new SolidBrush(current.AbsoluteColor);
                        flag  = true;
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        break;
                    }
                    }
                    Debug.Assert(brush != null);
                    Rectangle rectangleToDraw = current.RectangleToDraw;
                    oGraphics.FillRectangle(brush, rectangleToDraw);
                    oGraphics.DrawRectangle(pen, rectangleToDraw);
                    if (flag)
                    {
                        brush.Dispose();
                        brush = null;
                    }
                    this.DrawRectangles(current.Nodes, iNodeLevel + 1, oGraphics, oNegativeColorGradientMapper, oPositiveColorGradientMapper, oPenCache);
                }
            }
        }
예제 #5
0
        private static void DrawPath(FractalPath path, Color color, FastBitmap fastBitmap, PenCache pens, LazyGraphics lazyGraphics)
        {
            if (path.IsPixel)
            {
                var point = path.GetFirstPoint();
                fastBitmap.SetPixel((int)point.X, (int)point.Y, color);
                return;
            }

            var pen = pens.GetOrCreatePen(color);

            if (path.IsLine)
            {
                lazyGraphics.Value.DrawLine(pen, path.GetFirstPoint().ToDrawingPoint(), path.GetSecondPoint().ToDrawingPoint());
                return;
            }

            for (var i = 0; i < path.Points.Length - 1; i++)
            {
                lazyGraphics.Value.DrawLine(pen, path.Points[i].ToDrawingPoint(), path.Points[i + 1].ToDrawingPoint());
            }
        }