Exemple #1
0
        protected override void UpdateWithLocation(Rectangle rect, Keys modifiers, Point end)
        {
            shouldApplyCharacter = ApplyCharacter;       //modifiers.HasFlag (Key.Shift | Application.Instance.CommonModifier) ^ ApplyCharacter;
            shouldApplyColour    = ApplyColour;          //modifiers.HasFlag (Key.Alt | Application.Instance.CommonModifier) ^ ApplyColour;

            var oldRect = currentRect;

            rect.Normalize();
            lines.Clear();
            if (!Filled)
            {
                var templines = new ScanLines();
                currentRect = rect = templines.AddEllipse(rect);
                ScanLinesDrawDelegate draw = (drawrect) => {
                    lines.AddRect(drawrect);
                };
                templines.Outline(draw);
            }
            else
            {
                currentRect = rect = lines.AddEllipse(rect);
            }

            if (oldRect != null)
            {
                rect = Rectangle.Union(rect, oldRect.Value);
            }
            UpdatingCursor         = true;
            Handler.CursorPosition = end;
            UpdatingCursor         = false;
            Handler.InvalidateCharacterRegion(rect, false, false);
        }
Exemple #2
0
 public void Fill(ScanLinesDrawDelegate draw)
 {
     foreach (var row in this.Values)
     {
         var minx     = row.Min();
         var width    = row.Max() - minx + 1;
         var linerect = new Rectangle(minx, row.Row, width, 1);
         draw(linerect);
     }
 }
Exemple #3
0
        public void Do(Point?cursorPosition, Rectangle rect, CanvasElement element, bool applyColour, bool applyCharacter, bool filled)
        {
            var canvas = Handler.CurrentPage.Canvas;

            Handler.Undo.Save(cursorPosition, cursorPosition, rect);

            var lines = new ScanLines();

            lines.AddEllipse(rect);

            ScanLinesDrawDelegate draw = (linerect) => {
                if (applyColour && applyCharacter)
                {
                    canvas.Fill(linerect, element);
                }
                else if (applyColour)
                {
                    canvas.Fill(linerect, element.Attribute);
                }
                else if (applyCharacter)
                {
                    canvas.Fill(linerect, element.Character);
                }
            };

            if (filled)
            {
                lines.Fill(draw);
            }
            else
            {
                lines.Outline(draw);
            }

            Handler.InvalidateCharacterRegion(rect, true, false);
            Handler.Document.IsModified = true;
        }
Exemple #4
0
        public void Outline(ScanLinesDrawDelegate draw)
        {
            int     lastx = 0;
            ScanRow row;
            var     rows = new List <ScanRow>(this.Values);

            rows.Sort((x, y) => x.Row.CompareTo(y.Row));
            // remove all innards
            foreach (var childrow in rows)
            {
                childrow.Sort();
                if (childrow.Count > 2)
                {
                    childrow.RemoveRange(1, childrow.Count - 2);
                }
            }

            //int maxy = rows.Select (r => r.Row).Max ();
            //int miny = rows.Select (r => r.Row).Min ();
            // trace min edge
            for (int i = 0; i < rows.Count; i++)
            {
                row = rows [i];
                var  cury  = row.Row;
                int  curx  = row.Min();
                bool last  = i == rows.Count - 1;
                bool first = i == 0;

                if (!first && !last)
                {
                    var nextx = rows[i + 1].Min();
                    if (curx < lastx)
                    {
                        draw(new Rectangle(new Point(curx, cury), new Point(lastx - 1, cury)));
                    }
                    else if (curx > lastx + 1)
                    {
                        draw(new Rectangle(new Point(lastx + 1, cury - 1), new Point(curx - 1, cury - 1)));
                        draw(new Rectangle(new Point(curx, cury), new Point(curx, cury)));
                    }
                    else
                    {
                        draw(new Rectangle(new Point(curx, cury), new Point(curx, cury)));
                    }
                    if (nextx > curx)
                    {
                        draw(new Rectangle(new Point(curx, cury), new Point(nextx - 1, cury)));
                    }
                }
                lastx = curx;
            }
            // trace max edge
            for (int i = 0; i < rows.Count; i++)
            {
                row = rows [i];
                var  cury  = row.Row;
                int  curx  = row.Max();
                bool last  = i == rows.Count - 1;
                bool first = i == 0;

                if (!first && !last)
                {
                    var nextx = rows[i + 1].Max();
                    if (curx > lastx)
                    {
                        draw(new Rectangle(new Point(lastx + 1, cury), new Point(curx, cury)));
                    }
                    else if (curx < lastx - 1)
                    {
                        draw(new Rectangle(new Point(curx + 1, cury - 1), new Point(lastx - 1, cury - 1)));
                        draw(new Rectangle(new Point(curx, cury), new Point(curx, cury)));
                    }
                    else
                    {
                        draw(new Rectangle(new Point(curx, cury), new Point(curx, cury)));
                    }
                    if (nextx < curx)
                    {
                        draw(new Rectangle(new Point(nextx + 1, cury), new Point(curx, cury)));
                    }
                }
                lastx = curx;
            }
            // fill top/bottom
            row = rows[0];
            draw(new Rectangle(new Point(row.Min(), row.Row), new Point(row.Max(), row.Row)));
            row = rows[rows.Count - 1];
            draw(new Rectangle(new Point(row.Min(), row.Row), new Point(row.Max(), row.Row)));
        }