Ejemplo n.º 1
0
        Control Preview()
        {
            var size     = new Size(128, 128);
            var drawable = new Drawable {
                Size = size
            };

            drawable.Paint += (sender, pe) =>
            {
                if (canvas != null)
                {
                    canvas.DrawRegion(pe.Graphics, new Rectangle(size));
                }
            };
            drawable.LoadComplete += delegate {
                canvas = new BGICanvas(drawable, size);
                DrawCanvas();
            };

            var layout = new DynamicLayout();

            layout.AddCentered(drawable, verticalCenter: false);
            return(new GroupBox {
                Text = "Preview", Content = layout
            });
        }
Ejemplo n.º 2
0
        Control FontType()
        {
            var drawable = new Drawable
            {
                Size = new Size(40, 40)
            };

            drawable.MouseUp += delegate
            {
                SelectFont();
            };

            drawable.Paint += delegate(object sender, PaintEventArgs pe)
            {
                if (canvas != null)
                {
                    canvas.DrawRegion(pe.Graphics, new Rectangle(Point.Empty, canvas.WindowSize));
                }
            };

            drawable.LoadComplete += delegate             // Shown?
            {
                if (drawable.Size.IsEmpty)
                {
                    return;
                }
                canvas = new BGICanvas(drawable, drawable.Size);
                DrawCanvas();
            };
            return(drawable);
        }
Ejemplo n.º 3
0
 public override bool InternalShouldApply(BGICanvas bgi)
 {
     return(this.Style != BGICanvas.FillStyle.User &&
            (
                bgi.GetFillColor() != this.Color ||
                bgi.GetFillStyle() != this.Style
            ));
 }
Ejemplo n.º 4
0
 public override bool InternalShouldApply(BGICanvas bgi)
 {
     return
         (isUserStyle &&
          (
              bgi.GetFillStyle() != BGICanvas.FillStyle.User ||
              bgi.GetFillColor() != Color ||
              !bgi.GetFillPattern(BGICanvas.FillStyle.User).SequenceEqual(Pattern)
          ));
 }
Ejemplo n.º 5
0
        public virtual bool ShouldApply(BGICanvas bgi)
        {
            var contains = this.Document.OptionalApplied.Contains(OpCode);

            if (InternalShouldApply(bgi) || !contains)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
		void SetBGI(RipHandler handler)
		{
			var pane = handler?.ViewerControl as ViewerPane;
			var viewer = pane != null ? pane?.Viewer : null;
			
			if (BGI != null)
				BGI.Control = viewer;
			else
				BGI = new BGICanvas(viewer);
		}
Ejemplo n.º 7
0
        void SetBGI(RipHandler handler)
        {
            var pane   = handler != null && handler.HasViewerControl ? handler.ViewerControl as ViewerPane : null;
            var viewer = pane != null ? pane.Viewer : null;

            if (BGI != null)
            {
                BGI.Control = viewer;
            }
            else
            {
                BGI = new BGICanvas(viewer);
            }
        }
Ejemplo n.º 8
0
        public float DrawCharacter(BGICanvas bgi, float x, float y, BGICanvas.Direction dir, int size, byte character, IList <Rectangle> updates)
        {
            BGICharacter ch = this[character];

            if (ch != null)
            {
                var drawUpdates = updates ?? new List <Rectangle>();
                ch.Draw(bgi, x, y, dir, size, updates);
                if (updates == null)
                {
                    bgi.UpdateRegion(drawUpdates);
                }
                return(ch.GetWidth(size));
            }
            return(0);
        }
Ejemplo n.º 9
0
        public void Draw(BGICanvas bgi, float x, float y, BGICanvas.Direction dir, int size, IList <Rectangle> updates)
        {
            var drawUpdates = updates ?? new List <Rectangle> ();

            var height = font.Height * scaleup [size] / scaledown [size];

            if (dir == BGICanvas.Direction.Horizontal)
            {
                foreach (var stroke in strokes)
                {
                    int curx = (int)x + (stroke.x * scaleup [size] / scaledown [size]);
                    int cury = (int)y + height - (stroke.y * scaleup [size] / scaledown [size]);

                    if (stroke.type == StrokeType.MoveTo)
                    {
                        bgi.MoveTo(curx, cury);
                    }
                    else if (stroke.type == StrokeType.LineTo)
                    {
                        bgi.LineTo(curx, cury, drawUpdates);
                    }
                }
            }
            else
            {
                foreach (var stroke in strokes)
                {
                    int curx = (int)x + height - (stroke.y * scaleup [size] / scaledown [size]);
                    int cury = (int)y - (stroke.x * scaleup [size] / scaledown [size]);

                    if (stroke.type == StrokeType.MoveTo)
                    {
                        bgi.MoveTo(curx, cury);
                    }
                    else if (stroke.type == StrokeType.LineTo)
                    {
                        bgi.LineTo(curx, cury, drawUpdates);
                    }
                }
            }
            if (updates == null)
            {
                bgi.UpdateRegion(drawUpdates);
            }
        }
Ejemplo n.º 10
0
        protected override void ApplyInvertedDrawing(IList <Rectangle> updates)
        {
            var point      = this.Command.Point;
            int startAngle = Command.StartAngle;
            int endAngle   = Command.EndAngle;

            if (startAngle > endAngle)
            {
                var t = startAngle;
                startAngle = endAngle;
                endAngle   = t;
            }

            this.BGI.Ellipse(point.X, point.Y, startAngle, endAngle, Command.Radius.Width, Command.Radius.Height, updates);
            this.BGI.Line(point, point + BGICanvas.GetAngleSize(startAngle, Command.Radius), updates);
            this.BGI.Line(point, point + BGICanvas.GetAngleSize(endAngle, Command.Radius), updates);
            ApplyHandles(updates);
        }
Ejemplo n.º 11
0
        public Size GetMaxCharacterSize(BGICanvas.Direction dir, int size)
        {
            float width = 0;

            foreach (var ch in characters)
            {
                if (ch != null)
                {
                    width = Math.Max(width, ch.GetWidth(size));
                }
            }
            if (dir == BGICanvas.Direction.Horizontal)
            {
                return(new Size(BGICanvas.Round(width), (int)((Height + Math.Abs(OriginToDescender) + 1) * BGICharacter.scaleup[size] / BGICharacter.scaledown[size])));
            }
            else
            {
                return(new Size((int)((Height + Math.Abs(OriginToDescender) + 1) * BGICharacter.scaleup[size] / BGICharacter.scaledown[size]), BGICanvas.Round(width)));
            }
        }
Ejemplo n.º 12
0
        public Size GetTextSize(string str, BGICanvas.Direction dir, int size)
        {
            float width = 0;

            foreach (byte c in BGICanvas.Encoding.GetBytes(str))
            {
                BGICharacter ch = this[c];
                if (ch != null)
                {
                    width += ch.Width;
                }
            }
            if (dir == BGICanvas.Direction.Horizontal)
            {
                return(new Size(BGICanvas.Trunc(width * BGICharacter.scaleup[size] / BGICharacter.scaledown[size]), (int)((Height + Math.Abs(OriginToDescender) + 1) * BGICharacter.scaleup[size] / BGICharacter.scaledown[size])));
            }
            else
            {
                return(new Size((int)((Height + Math.Abs(OriginToDescender) + 1) * BGICharacter.scaleup[size] / BGICharacter.scaledown[size]), BGICanvas.Trunc(width * BGICharacter.scaleup[size] / BGICharacter.scaledown[size])));
            }
        }
Ejemplo n.º 13
0
        Control Preview()
        {
            var control = new Drawable
            {
                Size = new Size(400, 100)
            };

            control.Paint += delegate(object sender, PaintEventArgs pe)
            {
                if (canvas != null)
                {
                    canvas.DrawRegion(pe.Graphics, new Rectangle(canvas.WindowSize));
                }
            };

            control.LoadComplete += delegate
            {
                canvas = new BGICanvas(control, control.Size);
                DrawPreview();
            };

            return(control);
        }
Ejemplo n.º 14
0
        Control Preview()
        {
            var size     = new Size(128, 128);
            var drawable = new Drawable {
                Size = size
            };

            drawable.Paint += (sender, pe) =>
            {
                if (canvas != null)
                {
                    canvas.DrawRegion(pe.Graphics, new Rectangle(size));
                }
            };
            drawable.LoadComplete += delegate {
                canvas = new BGICanvas(drawable, size);
                DrawCanvas();
            };

            return(new GroupBox {
                Text = "Preview", Content = drawable
            });
        }
Ejemplo n.º 15
0
        Control Preview()
        {
            var size     = new Size(256, 128);
            var drawable = new Drawable {
                Size = size
            };

            drawable.Paint += delegate(object sender, PaintEventArgs pe)
            {
                this.canvas.DrawRegion(pe.Graphics, new Rectangle(size));
            };
            drawable.LoadComplete += delegate
            {
                canvas = new BGI.BGICanvas(drawable, size);
                DrawCanvas();
            };

            var layout = new DynamicLayout();

            layout.AddCentered(drawable);
            return(new GroupBox {
                Text = "Preview", Content = layout
            });
        }
Ejemplo n.º 16
0
        int GetAngle(Point start, Point end)
        {
            var offset = new Point(end - start);

            var angle = BGICanvas.Round(Math.Atan((double)offset.Y * radius.Width / radius.Height / offset.X) * (180.0 / Math.PI));

            if (offset.Y < 0 && offset.X < 0)
            {
                angle = 180 - angle;
            }
            else if (offset.Y > 0 && offset.X < 0)
            {
                angle = 180 - angle;
            }
            else if (offset.Y > 0 && offset.X > 0)
            {
                angle = 360 - angle;
            }
            else
            {
                angle = -angle;
            }
            return(angle);
        }
Ejemplo n.º 17
0
 public override bool InternalShouldApply(BGICanvas bgi)
 {
     return(bgi.GetColor() != Value);
 }
Ejemplo n.º 18
0
 public override void Set(BGICanvas bgi)
 {
     this.Font          = bgi.GetFontType();
     this.Direction     = bgi.GetTextDirection();
     this.CharacterSize = bgi.GetFontSize();
 }
Ejemplo n.º 19
0
 public override bool InternalShouldApply(BGICanvas bgi)
 {
     return(bgi.GetFontType() != this.Font ||
            bgi.GetTextDirection() != this.Direction ||
            bgi.GetFontSize() != this.CharacterSize);
 }
Ejemplo n.º 20
0
 public override void Set(BGICanvas bgi)
 {
     this.Style     = bgi.GetLineStyle();
     this.Pattern   = bgi.GetLinePattern(BGICanvas.LineStyle.User);
     this.Thickness = bgi.GetLineThickness();
 }
Ejemplo n.º 21
0
 public override bool InternalShouldApply(BGICanvas bgi)
 {
     return(Style != bgi.GetLineStyle() ||
            (Style == BGICanvas.LineStyle.User && Pattern != bgi.GetLinePattern(BGICanvas.LineStyle.User)) ||
            Thickness != bgi.GetLineThickness());
 }
Ejemplo n.º 22
0
 public override void Set(BGICanvas bgi)
 {
     Mode = bgi.GetWriteMode();
 }
Ejemplo n.º 23
0
 public override void Set(BGICanvas bgi)
 {
     this.Style = bgi.GetFillStyle();
     this.Color = bgi.GetFillColor();
 }
Ejemplo n.º 24
0
 public abstract bool InternalShouldApply(BGICanvas bgi);
Ejemplo n.º 25
0
 public abstract void Set(BGICanvas bgi);
Ejemplo n.º 26
0
 public override bool ShouldApply(BGICanvas bgi)
 {
     return(isUserStyle && base.ShouldApply(bgi));
 }
Ejemplo n.º 27
0
        public float DrawCharacter(BGICanvas bgi, float x, float y, BGICanvas.Direction dir, int size, byte character, IList <Rectangle> updates)
        {
            byte          foreCol = bgi.GetColor();
            FontCharacter fc      = this[character];

            if (dir == BGICanvas.Direction.Horizontal)
            {
                int starty = (int)y;
                for (int cy = 0; cy < Height; cy++)
                {
                    int startx = (int)x;
                    for (int cx = 0; cx < Width; cx++)
                    {
                        if (fc[cx, cy])
                        {
                            if (size == 1)
                            {
                                bgi.PutPixelInternal(startx, starty, foreCol);
                            }
                            else
                            {
                                for (int ccy = 0; ccy < size; ccy++)
                                {
                                    for (int ccx = 0; ccx < size; ccx++)
                                    {
                                        bgi.PutPixelInternal(startx + ccx, starty + ccy, foreCol);
                                    }
                                }
                            }
                        }
                        startx += size;
                    }
                    starty += size;
                }
                var updateRect = new Rectangle((int)x, (int)y, Width * size, Height * size);
                if (updates != null)
                {
                    updates.Add(updateRect);
                }
                else
                {
                    bgi.UpdateRegion(updateRect);
                }
            }
            else
            {
                int startx = (int)x;
                for (int cy = 0; cy < Height; cy++)
                {
                    int starty = (int)y;
                    for (int cx = 0; cx < Width; cx++)
                    {
                        if (fc[cx, cy])
                        {
                            if (size == 1)
                            {
                                bgi.PutPixelInternal(startx, starty, foreCol);
                            }
                            else
                            {
                                for (int ccy = 0; ccy < size; ccy++)
                                {
                                    for (int ccx = 0; ccx < size; ccx++)
                                    {
                                        bgi.PutPixelInternal(startx + ccx, starty - ccy, foreCol);
                                    }
                                }
                            }
                        }
                        starty -= size;
                    }
                    startx += size;
                }
                var updateRect = new Rectangle((int)x, (int)y, Height * size, Width * size);
                if (updates != null)
                {
                    updates.Add(updateRect);
                }
                else
                {
                    bgi.UpdateRegion(updateRect);
                }
            }
            return(Width * size);
        }
Ejemplo n.º 28
0
 public override bool InternalShouldApply(BGICanvas bgi)
 {
     return(bgi.GetWriteMode() != Mode);
 }