Пример #1
0
        public void Export(string filename, ExportFormat format)
        {
            this.UnselectAll();

            double leftMost   = double.MaxValue,
                   rightMost  = 0,
                   topMost 	  = double.MaxValue,
                   bottomMost = 0;

            Shape leftLayer   = new Shape(),
                  rightLayer  = new Shape(),
                  topLayer    = new Shape(),
                  bottomLayer = new Shape();

            foreach(Shape l in this)
            {
                if(l.Position.X + l.Boundaries.Width / 2 > rightMost)
                {
                    rightMost =  l.Position.X + l.Boundaries.Width / 2;
                    rightLayer = l;
                }
                if(l.Position.X - l.Boundaries.Width / 2 < leftMost)
                {
                    leftMost = l.Position.X - l.Boundaries.Width / 2;
                    leftLayer = l;
                }
                if((l.Position.Y - l.Boundaries.Height / 2) < topMost)
                {
                    topMost = l.Position.Y - l.Boundaries.Height / 2;
                    topLayer = l;
                }
                if(l.Position.Y + l.Boundaries.Height > bottomMost)
                {
                    bottomMost = l.Position.Y + l.Boundaries.Height;
                    bottomLayer = l;
                }
            }

            Size size;

            //TODO: to keep or not to keep the 1px border, that is the question.
            size.Width = (rightLayer.Position.X + rightLayer.Boundaries.Width / 2) -
                         (leftLayer.Position.X - leftLayer.Boundaries.Width / 2) + 1;

            size.Height = (bottomLayer.Position.Y + bottomLayer.Boundaries.Height / 2) -
                          (topLayer.Position.Y - topLayer.Boundaries.Height / 2) + 1;

            Surface surface;

            //TODO: each surface is handling the size differently... BUT WHY?
            switch(format)
            {
                case ExportFormat.SVG:
                    surface = new SvgSurface(filename, size.Width, size.Height);
                    break;
                case ExportFormat.PDF:
                    surface = new PdfSurface(filename, size.Width, size.Height);
                    break;
                case ExportFormat.PNG:
                    surface = new ImageSurface(Format.ARGB32,
                                           	   (int)size.Width,
                                               (int)size.Height);
                    break;
                default:
                    surface = new SvgSurface(filename, size.Width, size.Height);
                    break;
            }

            Cairo.Context c = new Context(surface);

            c.Translate(-leftLayer.Position.X + leftLayer.Boundaries.Width / 2,
                        -(topLayer.Position.Y - topLayer.Boundaries.Height / 2));

            this.Draw(c);

            if(format == ExportFormat.PNG)
                surface.WriteToPng(filename);
            surface.Finish();

            c.Target.Dispose();

            ((IDisposable) c).Dispose ();
        }
Пример #2
0
        protected virtual void DragData_Received(object o, Gtk.DragDataReceivedArgs args)
        {
            Shape l = new Shape(args.SelectionData.Text, new Point(args.X, args.Y));

            this.shapeManager.Add(l);
            this.shapeManager.UnselectAll();
            this.shapeManager.Select(l);
            Gtk.Drag.Finish(args.Context, true, false, args.Time);
        }
Пример #3
0
 public void UnselectAll()
 {
     this.selected = new Shape();
     foreach(Shape l in this)
         l.Selected = false;
 }
Пример #4
0
 // adds a new shape
 public void Add(Shape l)
 {
     this.shapes.Add(l);
 }
Пример #5
0
        public void Select(int x, int y)
        {
            //TODO: PERF
            Shape sel = null;

            foreach(Shape l in this)
            {
                if(PointInRectangle(new Point(x,y),
                                    new Rectangle(new Point((int)(l.Position.X-l.Boundaries.Width/2),
                                                            (int)(l.Position.Y-l.Boundaries.Height/2)),
                                                 		    l.Boundaries.Width,
                                                  			l.Boundaries.Height)))
                {
                    sel = l;
                }
            }
            if(sel != null)
            {
                this.selected.Selected = false;
                sel.Select(new Point(x, y));
                this.selected = sel;
            }
        }
Пример #6
0
 public void Unselect(int index)
 {
     this.selected = new Shape();
     this[index].Selected = false;
 }
Пример #7
0
 public void Select(int index)
 {
     if(index < this.Count && index >= 0)
     {
         this.selected.Selected = false;
         this[index].Selected = true;
         this.selected = this[index];
     }
 }
Пример #8
0
 public void Select(Shape l)
 {
     this.Select(this.shapes.IndexOf(l));
 }
Пример #9
0
 public void Remove(Shape l)
 {
     this.shapes.Remove(l);
 }
Пример #10
0
 public ShapeManager()
 {
     shapes = new List<Shape>();
     this.selected = new Shape();
 }
Пример #11
0
 public void MoveUp(Shape l)
 {
     int index = shapes.IndexOf(l);
     if(index >= 0 && index < this.Count-1)
     {
         this.Remove(l);
         this.Insert(++index, l);
     }
 }
Пример #12
0
        public void MoveDown(Shape l)
        {
            int index = shapes.IndexOf(l);

            if(index > 0)
            {
                this.Remove(l);
                this.Insert(--index, l);
            }
        }
Пример #13
0
 public void Insert(int index, Shape l)
 {
     this.shapes.Insert(index, l);
 }