public override void MouseDrag (MouseEvent ev) {
			DrawSelectionRect ((Gtk.Widget) ev.View, ev.GdkEvent.Window);
			PointD anchor = new PointD (AnchorX, AnchorY);
			PointD corner = new PointD (ev.X, ev.Y);
			_selectionRect = new RectangleD (anchor, corner);
			DrawSelectionRect ((Gtk.Widget) ev.View, ev.GdkEvent.Window);
		}
Esempio n. 2
0
 public NodeGroup(string name, PointD position)
 {
     nodes = ArrayList.Synchronized(new ArrayList());
     this.name = name;
     this.position = position;
     this.dimension = new SizeD(0, 0);
 }
        public virtual RectangleD InvalidateRect(PointD b)
        {
            var r = new RectangleD (b.X, b.Y, 0.0, 0.0);
            r.Inflate (15.0, 15.0);

            return r;
        }
Esempio n. 4
0
        public Tuple<PointD, PointD, PointD, PointD> getSharpestPointAndAssociatedMidpointAndDullestPoints()
        {
            if (-1 == sharpestPointIdx) {
                sharpestPointIdx = TriangleUtils.GetSharpestPoint (tri);
            }
            int sharp = sharpestPointIdx;
            PointD p;
            PointD d1;
            PointD d2;
            // meh
            if (0 == sharp) {
                p = tri.a;
                d1 = tri.b;
                d2 = tri.c;
            } else if (1 == sharp) {
                p = tri.b;
                d1 = tri.a;
                d2 = tri.c;
            } else {
                p = tri.c;
                d1 = tri.a;
                d2 = tri.b;
            }

            PointD midPoint = new PointD ((d1.X+d2.X)/2,(d1.Y+d2.Y)/2);

            return new Tuple<PointD,PointD,PointD,PointD> (p,midPoint,d1,d2);
        }
Esempio n. 5
0
 private void Image_Loaded(object sender, RoutedEventArgs e)
 {
     Image image = (Image)sender;
     using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)image.Width, (int)image.Height))
     {
         using (Context context = new Context(surface))
         {
             PointD p = new PointD(10.0, 10.0);
             PointD p2 = new PointD(100.0, 10.0);
             PointD p3 = new PointD(100.0, 100.0);
             PointD p4 = new PointD(10.0, 100.0);
             context.MoveTo(p);
             context.LineTo(p2);
             context.LineTo(p3);
             context.LineTo(p4);
             context.LineTo(p);
             context.ClosePath();
             context.Fill();
             context.MoveTo(140.0, 110.0);
             context.SetFontSize(32.0);
             context.SetSourceColor(new Color(0.0, 0.0, 0.8, 1.0));
             context.ShowText("Hello Cairo!");
             surface.Flush();
             RgbaBitmapSource source = new RgbaBitmapSource(surface.Data, surface.Width);
             image.Source = source;
         }
     }
 }
Esempio n. 6
0
        public void update()
        {
            LineSegment segmentToPlayer = new LineSegment (position,player.getPosition());

            bool couldSeePlayerBefore = canSeePlayer;
            canSeePlayer = true;

                foreach (LineSegment wall in walls) {
                    if (LineSegment.TestIntersection (segmentToPlayer, wall)) {
                        canSeePlayer = false;
                        break;
                    }
                }

            if (canSeePlayer) {
                target = player.getPosition ();
                setStalkSpeed ();
            }

            if (!canSeePlayer && couldSeePlayerBefore) {
                setRandomTarget ();
                setWanderSpeed ();
            }

                PointD vectorDistance = new PointD (target.X - position.X, target.Y - position.Y);
            double scalarDistance = Math.Sqrt (Math.Pow(vectorDistance.X,2) + Math.Pow(vectorDistance.Y,2));

            if (scalarDistance < tolerance) {
                ;
            } else {
                double total = Math.Abs (vectorDistance.X) + Math.Abs (vectorDistance.Y);
                position.X += (vectorDistance.X / total) * speed;
                position.Y += vectorDistance.Y / total * speed;
            }
        }
Esempio n. 7
0
		protected void UpdateRectangle (PointD point)
		{
			if (!is_drawing)
				return;

			Document doc = PintaCore.Workspace.ActiveDocument;

			Rectangle r = PointsToRectangle (shape_origin, point);
			Rectangle dirty;

			doc.ToolLayer.Clear ();
			doc.ToolLayer.Hidden = false;

			using (Context g = new Context (doc.ToolLayer.Surface)) {
				g.Antialias = Antialias.Subpixel;

				dirty = g.FillStrokedRectangle (r, new Color (0, 0.4, 0.8, 0.1), new Color (0, 0, 0.9), 1);
				dirty = dirty.Clamp ();

				doc.Workspace.Invalidate (last_dirty.ToGdkRectangle ());
				doc.Workspace.Invalidate (dirty.ToGdkRectangle ());
				
				last_dirty = dirty;
			}
		}
        //FIXME: Fix so point stays on edge of circle
        public static PointD EdgePointOfCircle(PointD midpoint, double radius, PointD endpoint)
        {
            var x_vector = endpoint.X - midpoint.X;
            var y_vector = endpoint.Y - midpoint.Y;

            var sin = y_vector / radius;
            var cos = x_vector / radius;
            var x = 0.0;
            var y = 0.0;
            var e = 0.0001;

            if (Math.Abs (sin) > e) {
                y = radius * (-sin);
                y = Range (-radius, radius, y);
            } else
                x = radius;

            if (Math.Abs (cos) > e) {
                x = radius * (-cos);
                x = Range (-radius, radius, x);
            } else
                y = radius;

            return new PointD (midpoint.X + x, midpoint.Y + y);
        }
Esempio n. 9
0
		// In perspective mode, the warping functions are:
		//	x' = (a0 + a1 x + a2 y) / (c0 x + c1 y + 1)
		//	y' = (b0 + b1 x + b2 y) / (c0 x + c1 y + 1)
		//
		// The following calculates the factors a#, b# and c#.
		// We do this by creating a set of eight equations with a#, b# and c# as unknowns.
		// The equations are derived by:
		// 1. substituting the srcPoints for (x, y);
		// 2. substituting the corresponding destPoints for (x', y');
		// 3. solving the resulting set of equations, with the factors as unknowns.
		//
		// The equations are like these:
		//	a0	x a1	y a2	0		0		0		-xx'c0	-yx'c1	= x'
		//	0	0		0		b0		x b1	y b2	-xy'c0	-yy'c1  = y'
		// The known factors of left hand side ar put in the 8x8 matrix mxLeft for
		// all four point pairs, and the right hand side in the one column matrix mxRight.
		// After solving, m_mxWarpFactors contains a0, a1, a2, b0, b1, b2, c0, c1.
		private void PreCalc(PointD[] destPoints, PointD[] srcPoints)
		{
			var mxLeft = new GeneralMatrix(8, 8); //mxLeft.Null();
			var 	mxRight = new GeneralMatrix(8, 1);

			var row = 0;

			for (int i = 0; i < 4; i++)
			{
				mxLeft.Array[row][0] = 1.0;
				mxLeft.Array[row][1] = srcPoints[i].X;
				mxLeft.Array[row][2] = srcPoints[i].Y;

				mxLeft.Array[row][6] = - srcPoints[i].X * destPoints[i].X;
				mxLeft.Array[row][7] = - srcPoints[i].Y * destPoints[i].X;

				mxRight.Array[row][0] = destPoints[i].X;

				row++;

				mxLeft.Array[row][3] = 1.0f;
				mxLeft.Array[row][4] = srcPoints[i].X;
				mxLeft.Array[row][5] = srcPoints[i].Y;

				mxLeft.Array[row][6] = - srcPoints[i].X * destPoints[i].Y;
				mxLeft.Array[row][7] = - srcPoints[i].Y * destPoints[i].Y;

				mxRight.Array[row][0] = destPoints[i].Y;

				row++;
			}

			_mxWarpFactors = mxLeft.Solve(mxRight);
		}
Esempio n. 10
0
 public NodeGroup()
 {
     nodes = ArrayList.Synchronized(new ArrayList());
     name = string.Empty;
     position = new PointD(0, 0);
     dimension = new SizeD(0, 0);
 }
Esempio n. 11
0
		protected override void OnMouseDown (DrawingArea canvas, ButtonPressEventArgs args, Cairo.PointD point)
		{
			// Ignore extra button clicks while drawing
			if (is_drawing)
				return;

			Document doc = PintaCore.Workspace.ActiveDocument;
			hist = new SelectionHistoryItem(Icon, Name);
			hist.TakeSnapshot();

			reset_origin = args.Event.GetPoint();

            active_control = HandleResize (point);
			if (!active_control.HasValue)
			{
				combine_mode = PintaCore.Workspace.SelectionHandler.DetermineCombineMode(args);

				double x = Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1);
				double y = Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1);
				shape_origin = new PointD(x, y);

                doc.PreviousSelection.Dispose ();
				doc.PreviousSelection = doc.Selection.Clone();
				doc.Selection.SelectionPolygons.Clear();

                // The bottom right corner should be selected.
                active_control = 3;
			}

            is_drawing = true;
		}
Esempio n. 12
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            origin_offset = point;
            is_dragging = true;

            hist = new MovePixelsHistoryItem (Icon, Name);
            hist.TakeSnapshot ();

            if (!PintaCore.Layers.ShowSelectionLayer) {
                // Copy the selection to the temp layer
                PintaCore.Layers.CreateSelectionLayer ();
                PintaCore.Layers.ShowSelectionLayer = true;

                using (Cairo.Context g = new Cairo.Context (PintaCore.Layers.SelectionLayer.Surface)) {
                    g.AppendPath (PintaCore.Layers.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource (PintaCore.Layers.CurrentLayer.Surface);
                    g.Clip ();
                    g.Paint ();
                }

                Cairo.ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

                using (Cairo.Context g = new Cairo.Context (surf)) {
                    g.AppendPath (PintaCore.Layers.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Operator = Cairo.Operator.Clear;
                    g.Fill ();
                }
            }

            canvas.GdkWindow.Invalidate ();
        }
Esempio n. 13
0
 public void Translate(double dx, double dy)
 {
     Point dP = new Point (dx, dy);
     PointUtils.TranslatePointIP (ref a, dP);
     PointUtils.TranslatePointIP (ref b, dP);
     PointUtils.TranslatePointIP (ref c, dP);
 }
Esempio n. 14
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Debug.WriteLine("OnPaint");

            //draw something on the back surface

            var p1 = new PointD(10, 10);
            var p2 = new PointD(100, 10);
            var p3 = new PointD(100, 100);
            var p4 = new PointD(10, 100);

            BackContext.SetSourceColor(new Cairo.Color(1,0,0));
            BackContext.MoveTo(p1);
            BackContext.LineTo(p2);
            BackContext.LineTo(p3);
            BackContext.LineTo(p4);
            BackContext.LineTo(p1);
            BackContext.ClosePath();
            BackContext.Stroke();

            BackContext.SetSourceColor(new Cairo.Color(0, 1, 0));
            BackContext.MoveTo(new PointD(p3.X + 10, p3.Y + 10));
            Cairo.Path path = DWriteCairo.RenderLayoutToCairoPath(BackContext, textLayout);
            BackContext.AppendPath(path);
            path.Dispose();
            BackContext.Fill();

            //copy back surface to font surface
            SwapBuffer();
        }
Esempio n. 15
0
        protected override void DrawGraduations(Context gr, PointD pStart, PointD pEnd)
        {
            Rectangle r = ClientRectangle;
            Foreground.SetAsSource (gr);

            gr.LineWidth = 2;
            gr.MoveTo(pStart);
            gr.LineTo(pEnd);

            gr.Stroke();
            gr.LineWidth = 1;

            double sst = unity * SmallIncrement;
            double bst = unity * LargeIncrement;

            PointD vBar = new PointD(0, sst);
            for (double x = Minimum; x <= Maximum - Minimum; x += SmallIncrement)
            {
                double lineLength = r.Height / 3;
                if (x % LargeIncrement != 0)
                    lineLength /= 3;
                PointD p = new PointD(pStart.X + x * unity, pStart.Y);
                gr.MoveTo(p);
                gr.LineTo(new PointD(p.X, p.Y + lineLength));
            }
            gr.Stroke();
        }
Esempio n. 16
0
 protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, PointD point)
 {
     if (active) {
         PintaCore.Workspace.ScrollCanvas ((int)(last_point.X - args.Event.XRoot), (int)(last_point.Y - args.Event.YRoot));
         last_point = new PointD (args.Event.XRoot, args.Event.YRoot);
     }
 }
Esempio n. 17
0
        void OnDrawingAreaExposed(object o, ExposeEventArgs args)
        {
            if (prevSize != Allocation.Size)
            {
                if (model != null)
                    treeMapModel = new TreeMapModel(model, Allocation.Width, Allocation.Height);
            }

            DrawingArea area = (DrawingArea)o;
            Cairo.Context g = Gdk.CairoHelper.Create(area.GdkWindow);

            if (treeMapModel != null)
            {
                foreach (var item in treeMapModel.Items)
                {
                    double width = item.Rectangle.Width;
                    double height = item.Rectangle.Height;

                    double x1 = item.Rectangle.X;
                    double x2 = item.Rectangle.X + item.Rectangle.Width;
                    double y1 = item.Rectangle.Y;
                    double y2 = item.Rectangle.Y + item.Rectangle.Height;

                    PointD p1, p2, p3, p4;
                    p1 = new PointD(x1, y1);
                    p2 = new PointD(x2, y1);
                    p3 = new PointD(x2, y2);
                    p4 = new PointD(x1, y2);

                    g.MoveTo(p1);
                    g.LineTo(p2);
                    g.LineTo(p3);
                    g.LineTo(p4);
                    g.LineTo(p1);
                    g.ClosePath();

                    g.Save();
                    //using (Gradient pat = new LinearGradient(x1, y1, x2, y2))
                    using (Gradient pat = new RadialGradient(x1 + (x2 - x1) / 4.0, y1 + (y2 - y1) / 4.0, 3, x1 + (x2 - x1) / 4.0, y1 + (y2 - y1) / 4.0, Math.Sqrt(width*width + height*height)))
                    {
                        pat.AddColorStop(0, new Cairo.Color(1, 1, 1, 1));
                        pat.AddColorStop(1, new Cairo.Color(0, 0, 1, 1));
                        g.Pattern = pat;

                        // Fill the path with pattern
                        g.FillPreserve();
                    }

                    // We "undo" the pattern setting here
                    g.Restore();

                    g.Color = new Color(0, 0, 0, 0);
                    g.Stroke();
                }
            }

            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
Esempio n. 18
0
 public Layer(ImageSurface surface, bool hidden, double opacity, string name)
 {
     Surface = surface;
     Hidden = hidden;
     Opacity = opacity;
     Name = name;
     Offset = new PointD (0, 0);
 }
Esempio n. 19
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            origin_offset = point;
            is_dragging = true;

            hist = new SelectionHistoryItem (Icon, Name);
            hist.TakeSnapshot ();
        }
Esempio n. 20
0
 // Initializes ioHandler, mode set to line at start and a
 // line drawn between upper left corner and lower right corner.
 // ,Last setting' for flush was false since we last issued that
 // a line should be drawn.
 public IoHandler()
 {
     startPoint = new PointD(0,0);
     // Set according to Gui.cs design at 26.2.12.
     endPoint = new PointD(500,500);
     mode = 'l';
     flush = false;
 }
Esempio n. 21
0
 public Head(IScene scene,Point pos)
 {
     controller = new HeadController (this);
     view = new HeadView (this);
     this.scene = scene;
     bounds = scene.getBounds ();
     position = pos;
 }
		public override void InvokeStep (double x, double y, IDrawingView view)	{
			RectangleD r = Owner.DisplayBox;

			PointD new_location = new PointD (r.X, Math.Min (r.Y + r.Height, y));
			PointD new_corner   = new PointD (Math.Max (r.X, x), r.Y + r.Height);

			Owner.DisplayBox = new RectangleD (new_location, new_corner);
		}
Esempio n. 23
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, PointD point)
        {
            // Don't scroll if the whole canvas fits (no scrollbars)
            if (!PintaCore.Workspace.CanvasFitsInWindow)
                active = true;

            last_point = new PointD (args.Event.XRoot, args.Event.YRoot);
        }
		public override void InvokeStep(MouseEvent ev) {
			RectangleD r = Owner.DisplayBox;

			PointD new_location = new PointD (Math.Min (r.X + r.Width, ev.X), r.Y);
			PointD new_corner   = new PointD (r.X + r.Width, Math.Max (r.Y, ev.Y));

			Owner.DisplayBox = new RectangleD (new_location, new_corner);
		}
Esempio n. 25
0
 double CalculateDistance(PointD A, PointD B)
 {
     return (
         Math.Sqrt(
             Math.Pow(B.X - A.X, 2) + Math.Pow(B.Y - A.Y, 2)
         )
     );
 }
Esempio n. 26
0
 public Protagonist(IScene scene)
 {
     controller = new ProtagonistController (this);
     view = new ProtagonistView (this);
     this.scene = scene;
     PointD bounds = scene.getBounds ();
     position = new PointD (bounds.X / 2, bounds.Y - 70);
 }
 public ConnectorToolboxItemNode(string name, ConnectionType connectorType, Gdk.Pixbuf icon)
     : base()
 {
     Icon = icon;
     Name = name;
     _connectorType = connectorType;
     point = new PointD (0.0, 0.0);
 }
Esempio n. 28
0
        public unsafe override void Render(ImageSurface src, ImageSurface dst, Gdk.Rectangle[] rois)
        {
            PointD start = new PointD (0, 0);
            double theta = ((double)(Data.Angle + 180) * 2 * Math.PI) / 360.0;
            double alpha = (double)Data.Distance;
            PointD end = new PointD ((float)alpha * Math.Cos (theta), (float)(-alpha * Math.Sin (theta)));

            if (Data.Centered) {
                start.X = -end.X / 2.0f;
                start.Y = -end.Y / 2.0f;

                end.X /= 2.0f;
                end.Y /= 2.0f;
            }

            PointD[] points = new PointD[((1 + Data.Distance) * 3) / 2];

            if (points.Length == 1) {
                points[0] = new PointD (0, 0);
            } else {
                for (int i = 0; i < points.Length; ++i) {
                    float frac = (float)i / (float)(points.Length - 1);
                    points[i] = Utility.Lerp (start, end, frac);
                }
            }

            ColorBgra* samples = stackalloc ColorBgra[points.Length];

            ColorBgra* src_dataptr = (ColorBgra*)src.DataPtr;
            int src_width = src.Width;
            int src_height = src.Height;

            foreach (Gdk.Rectangle rect in rois) {

                for (int y = rect.Top; y <= rect.GetBottom (); ++y) {
                    ColorBgra* dstPtr = dst.GetPointAddressUnchecked (rect.Left, y);

                    for (int x = rect.Left; x <= rect.GetRight (); ++x) {
                        int sampleCount = 0;

                        PointD a = new PointD ((float)x + points[0].X, (float)y + points[0].Y);
                        PointD b = new PointD ((float)x + points[points.Length - 1].X, (float)y + points[points.Length - 1].Y);

                        for (int j = 0; j < points.Length; ++j) {
                            PointD pt = new PointD (points[j].X + (float)x, points[j].Y + (float)y);

                            if (pt.X >= 0 && pt.Y >= 0 && pt.X <= (src_width - 1) && pt.Y <= (src_height - 1)) {
                                samples[sampleCount] = src.GetBilinearSample (src_dataptr, src_width, src_height, (float)pt.X, (float)pt.Y);
                                ++sampleCount;
                            }
                        }

                        *dstPtr = ColorBgra.Blend (samples, sampleCount);
                        ++dstPtr;
                    }
                }
            }
        }
Esempio n. 29
0
 public override void MouseDrag (MouseEvent ev) 
 {
     if(active) 
     {
         Gdk.EventMotion motion = ev.GdkEvent as Gdk.EventMotion;
         View.ScrollCanvas((int)(last_point.X - motion.XRoot), (int)(last_point.Y - motion.YRoot));
         last_point = new PointD (motion.XRoot, motion.YRoot);
     }
 }
Esempio n. 30
0
 public Triangle(Point a, Point b, Point c)
 {
     this.a.X = a.X;
     this.a.Y = a.Y;
     this.b.X = b.X;
     this.b.Y = b.Y;
     this.c.X = c.X;
     this.c.Y = c.Y;
 }
Esempio n. 31
0
 protected virtual void OnMouseUp(DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
 {
 }
Esempio n. 32
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            surface_modified = false;
            undo_surface     = doc.CurrentUserLayer.Surface.Clone();
            path             = null;

            doc.ToolLayer.Clear();
            doc.ToolLayer.Hidden = false;
        }
Esempio n. 33
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            doc.ToolLayer.Hidden = true;

            if (surface_modified)
            {
                PintaCore.History.PushNewItem(new SimpleHistoryItem(Icon, Name, undo_surface, doc.CurrentUserLayerIndex));
            }
            else if (undo_surface != null)
            {
                (undo_surface as IDisposable).Dispose();
            }

            surface_modified = false;
            ImageSurface surf = doc.CurrentUserLayer.Surface;

            using (Context g = new Context(surf)) {
                g.AppendPath(doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                if (path != null)
                {
                    g.AppendPath(path);
                    (path as IDisposable).Dispose();
                    path = null;
                }

                g.ClosePath();
                g.LineWidth = BrushWidth;
                g.LineJoin  = LineJoin.Round;
                g.LineCap   = LineCap.Round;
                g.FillRule  = FillRule.EvenOdd;

                if (FillShape && StrokeShape)
                {
                    g.Color = fill_color;
                    g.FillPreserve();
                    g.Color = outline_color;
                    g.Stroke();
                }
                else if (FillShape)
                {
                    g.Color = outline_color;
                    g.Fill();
                }
                else
                {
                    g.Color = outline_color;
                    g.Stroke();
                }
            }

            doc.Workspace.Invalidate();
        }
Esempio n. 34
0
        protected override void OnMouseDown(DrawingArea canvas, ButtonPressEventArgs args, Cairo.PointD point)
        {
            // Ignore extra button clicks while drawing
            if (is_drawing)
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            doc.Selection.selOrigin = shape_origin;
            doc.Selection.selEnd    = shape_end;

            hist = new SelectionHistoryItem(Icon, Name);
            hist.TakeSnapshot();

            reset_origin = args.Event.GetPoint();

            if (!handler_active || !HandleResize(point.X, point.Y))
            {
                doc.selHandler.DetermineCombineMode(args);

                doc.PreviousSelection = doc.Selection.Clone();
                doc.Selection.SelectionPolygons.Clear();

                double x = Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1);
                double y = Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1);

                shape_origin = new PointD(x, y);

                is_drawing = true;
            }
            else
            {
                isResizing = true;
            }
        }
Esempio n. 35
0
        private void Draw(DrawingArea drawingarea1, Color tool_color, Cairo.PointD point, bool first_pixel)
        {
            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals(point_empty))
            {
                last_point = new Point(x, y);

                if (!first_pixel)
                {
                    return;
                }
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            if (doc.Workspace.PointInCanvas(point))
            {
                surface_modified = true;
            }

            ImageSurface surf = doc.CurrentUserLayer.Surface;

            if (first_pixel)
            {
                // Does Cairo really not support a single-pixel-long single-pixel-wide line?
                surf.Flush();
                int       shiftedX = (int)point.X;
                int       shiftedY = (int)point.Y;
                ColorBgra source   = surf.GetColorBgra(shiftedX, shiftedY);
                source = UserBlendOps.NormalBlendOp.ApplyStatic(source, tool_color.ToColorBgra());
                surf.SetColorBgra(source, shiftedX, shiftedY);
                surf.MarkDirty();
            }
            else
            {
                using (Context g = new Context(surf)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Clip();

                    g.Antialias = Antialias.None;

                    // Adding 0.5 forces cairo into the correct square:
                    // See https://bugs.launchpad.net/bugs/672232
                    g.MoveTo(last_point.X + 0.5, last_point.Y + 0.5);
                    g.LineTo(x + 0.5, y + 0.5);

                    g.Color     = tool_color;
                    g.LineWidth = 1;
                    g.LineCap   = LineCap.Square;

                    g.Stroke();
                }
            }

            Gdk.Rectangle r = GetRectangleFromPoints(last_point, new Point(x, y));

            if (doc.Workspace.IsPartiallyOffscreen(r))
            {
                doc.Workspace.Invalidate();
            }
            else
            {
                doc.Workspace.Invalidate(doc.ClampToImageSize(r));
            }

            last_point = new Point(x, y);
        }
Esempio n. 36
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            if (surface_modified)
            {
                return;
            }

            surface_modified = false;
            undo_surface     = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface.Clone();
            Color tool_color;

            if (args.Event.Button == 1)             // left
            {
                tool_color = PintaCore.Palette.PrimaryColor;
            }
            else if (args.Event.Button == 3)             // right
            {
                tool_color = PintaCore.Palette.SecondaryColor;
            }
            else
            {
                last_point = point_empty;
                return;
            }

            Draw(canvas, tool_color, point, true);
        }
Esempio n. 37
0
        protected unsafe override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            ColorBgra old_color;
            ColorBgra new_color;

            if (mouse_button == 1)
            {
                old_color = PintaCore.Palette.PrimaryColor.ToColorBgra();
                new_color = PintaCore.Palette.SecondaryColor.ToColorBgra();
            }
            else if (mouse_button == 3)
            {
                old_color = PintaCore.Palette.SecondaryColor.ToColorBgra();
                new_color = PintaCore.Palette.PrimaryColor.ToColorBgra();
            }
            else
            {
                last_point = point_empty;
                return;
            }

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals(point_empty))
            {
                last_point = new Point(x, y);
            }

            if (doc.Workspace.PointInCanvas(point))
            {
                surface_modified = true;
            }

            ImageSurface surf      = doc.CurrentUserLayer.Surface;
            ImageSurface tmp_layer = doc.ToolLayer.Surface;

            Gdk.Rectangle roi = GetRectangleFromPoints(last_point, new Point(x, y));

            roi         = PintaCore.Workspace.ClampToImageSize(roi);
            myTolerance = (int)(Tolerance * 256);

            tmp_layer.Flush();

            ColorBgra *tmp_data_ptr  = (ColorBgra *)tmp_layer.DataPtr;
            int        tmp_width     = tmp_layer.Width;
            ColorBgra *surf_data_ptr = (ColorBgra *)surf.DataPtr;
            int        surf_width    = surf.Width;

            // The stencil lets us know if we've already checked this
            // pixel, providing a nice perf boost
            // Maybe this should be changed to a BitVector2DSurfaceAdapter?
            for (int i = roi.X; i <= roi.GetRight(); i++)
            {
                for (int j = roi.Y; j <= roi.GetBottom(); j++)
                {
                    if (stencil[i, j])
                    {
                        continue;
                    }

                    if (IsColorInTolerance(new_color, surf.GetColorBgra(surf_data_ptr, surf_width, i, j)))
                    {
                        *tmp_layer.GetPointAddressUnchecked(tmp_data_ptr, tmp_width, i, j) = AdjustColorDifference(new_color, old_color, surf.GetColorBgra(surf_data_ptr, surf_width, i, j));
                    }

                    stencil[i, j] = true;
                }
            }

            tmp_layer.MarkDirty();

            using (Context g = new Context(surf)) {
                g.AppendPath(doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                g.MoveTo(last_point.X, last_point.Y);
                g.LineTo(x, y);

                g.LineWidth = BrushWidth;
                g.LineJoin  = LineJoin.Round;
                g.LineCap   = LineCap.Round;

                g.SetSource(tmp_layer);

                g.Stroke();
            }

            doc.Workspace.Invalidate(roi);

            last_point = new Point(x, y);
        }
Esempio n. 38
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (!tracking || args.Event.Button != button)
            {
                return;
            }

            tracking = false;
            doc.History.PushNewItem(new SimpleHistoryItem(Icon, Name, undo_surface, doc.CurrentUserLayerIndex));
        }
Esempio n. 39
0
 public void MoveTo(PointD p)
 {
     ThrowIfDisposed();
     MoveTo(p.X, p.Y);
 }
Esempio n. 40
0
 public void Rectangle(PointD p, double width, double height)
 {
     Rectangle(p.X, p.Y, width, height);
 }
Esempio n. 41
0
 public void CurveTo(PointD p1, PointD p2, PointD p3)
 {
     CurveTo(p1.X, p1.Y, p2.X, p2.Y, p3.X, p3.Y);
 }
Esempio n. 42
0
 public void LineTo(PointD p)
 {
     LineTo(p.X, p.Y);
 }
Esempio n. 43
0
 public void MoveTo(PointD p)
 {
     MoveTo(p.X, p.Y);
 }
Esempio n. 44
0
 public void LineTo(PointD p)
 {
     ThrowIfDisposed();
     LineTo(p.X, p.Y);
 }
Esempio n. 45
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            // If we are already drawing, ignore any additional mouse down events
            if (is_drawing)
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            shape_origin  = point;
            current_point = point;

            is_drawing = true;

            if (args.Event.Button == 1)
            {
                outline_color = PintaCore.Palette.PrimaryColor;
                fill_color    = PintaCore.Palette.SecondaryColor;
            }
            else
            {
                outline_color = PintaCore.Palette.SecondaryColor;
                fill_color    = PintaCore.Palette.PrimaryColor;
            }

            doc.ToolLayer.Clear();
            doc.ToolLayer.Hidden = false;

            surface_modified = false;
            undo_surface     = doc.CurrentUserLayer.Surface.Clone();
        }
Esempio n. 46
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            // Protect against history corruption
            if (tracking)
            {
                return;
            }

            startpoint   = point;
            tracking     = true;
            button       = args.Event.Button;
            undo_surface = doc.CurrentUserLayer.Surface.Clone();
        }
Esempio n. 47
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Color tool_color;

            if ((args.Event.State & Gdk.ModifierType.Button1Mask) != 0)
            {
                tool_color = PintaCore.Palette.PrimaryColor;
            }
            else if ((args.Event.State & Gdk.ModifierType.Button3Mask) != 0)
            {
                tool_color = PintaCore.Palette.SecondaryColor;
            }
            else
            {
                last_point = point_empty;
                return;
            }

            Draw((DrawingArea)o, tool_color, point, false);
        }
Esempio n. 48
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (tracking)
            {
                GradientRenderer gr = CreateGradientRenderer();

                if (button == 3)                        // Right-click
                {
                    gr.StartColor = PintaCore.Palette.SecondaryColor.ToColorBgra();
                    gr.EndColor   = PintaCore.Palette.PrimaryColor.ToColorBgra();
                }
                else                                    //1 Left-click
                {
                    gr.StartColor = PintaCore.Palette.PrimaryColor.ToColorBgra();
                    gr.EndColor   = PintaCore.Palette.SecondaryColor.ToColorBgra();
                }

                gr.StartPoint    = startpoint;
                gr.EndPoint      = point;
                gr.AlphaBlending = UseAlphaBlending;

                gr.BeforeRender();

                Gdk.Rectangle selection_bounds = doc.GetSelectedBounds(true);
                ImageSurface  scratch_layer    = doc.ToolLayer.Surface;

                gr.Render(scratch_layer, new Gdk.Rectangle[] { selection_bounds });

                using (var g = doc.CreateClippedContext()) {
                    g.SetSource(scratch_layer);
                    g.Paint();
                }

                doc.ToolLayer.Clear();

                selection_bounds.Inflate(5, 5);
                doc.Workspace.Invalidate(selection_bounds);
            }
        }
Esempio n. 49
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (surface_modified)
            {
                doc.History.PushNewItem(new SimpleHistoryItem(Icon, Name, undo_surface, doc.CurrentUserLayerIndex));
            }
            else if (undo_surface != null)
            {
                (undo_surface as IDisposable).Dispose();
            }

            surface_modified = false;
        }
Esempio n. 50
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (mouse_button == 1)
            {
                StrokeColor = PintaCore.Palette.PrimaryColor;
                FillColor   = PintaCore.Palette.SecondaryColor;
            }
            else if (mouse_button == 3)
            {
                StrokeColor = PintaCore.Palette.SecondaryColor;
                FillColor   = PintaCore.Palette.PrimaryColor;
            }
            else
            {
                LastPoint = point_empty;
                return;
            }

            // TODO: also multiply by pressure
            StrokeColor = new Color(StrokeColor.R, StrokeColor.G, StrokeColor.B,
                                    StrokeColor.A * active_brush.StrokeAlphaMultiplier);

            int x = (int)point.X;
            int y = (int)point.Y;

            if (LastPoint.Equals(point_empty))
            {
                LastPoint = new Point(x, y);
            }

            if (doc.Workspace.PointInCanvas(point))
            {
                surface_modified = true;
            }

            var surf            = doc.CurrentLayer.Surface;
            var invalidate_rect = Gdk.Rectangle.Zero;
            var brush_width     = BrushWidth;

            Surface = surf;

            using (Drawable = new Context(surf)) {
                Drawable.AppendPath(doc.Selection.SelectionPath);
                Drawable.FillRule = FillRule.EvenOdd;
                Drawable.Clip();

                Drawable.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;
                Drawable.LineWidth = brush_width;
                Drawable.LineJoin  = LineJoin.Round;
                Drawable.LineCap   = BrushWidth == 1 ? LineCap.Butt : LineCap.Round;
                Drawable.Color     = StrokeColor;

                active_brush.Tool = this;
                invalidate_rect   = active_brush.DoMouseMove(x, y, LastPoint.X, LastPoint.Y);
                active_brush.Tool = null;
            }

            Surface  = null;
            Drawable = null;

            // If we draw partially offscreen, Cairo gives us a bogus
            // dirty rectangle, so redraw everything.
            if (doc.Workspace.IsPartiallyOffscreen(invalidate_rect))
            {
                doc.Workspace.Invalidate();
            }
            else
            {
                doc.Workspace.Invalidate(invalidate_rect);
            }

            LastPoint = new Point(x, y);
        }
Esempio n. 51
0
        void drawDesignOverlay(Context gr, GraphicObject g, Rectangle cb, Rectangle hr, double coteStroke, double space = 6.5)
        {
            double z = zoom / 100.0;
            double coteW = 3, coteL = 5;
            bool   fill = true;

            Cairo.PointD p1 = new Cairo.PointD(hr.X + 0.5, hr.Y - space);
            Cairo.PointD p2 = new Cairo.PointD(hr.Right - 0.5, hr.Y - space);

            if (p1.Y < cb.Top)
            {
                if (hr.Bottom > cb.Bottom - space)
                {
                    p1.Y = p2.Y = hr.Bottom - space;
                }
                else
                {
                    p1.Y = p2.Y = hr.Bottom + space;
                }
            }

            if (g.Width.IsFit)
            {
                gr.DrawCoteInverse(p1, p2, coteStroke, fill, coteW, coteL);
            }
            else if (g.Width.IsRelativeToParent)
            {
                gr.DrawCote(p1, p2, coteStroke, fill, coteW, coteL);
                if (g.Width.Value < 100)
                {
                    drawCenteredTextLine(gr, p1.Add(p2.Substract(p1).Divide(2)), g.Width.ToString());
                }
            }
            else if (g.Width.IsFixed)
            {
                gr.DrawCoteFixed(p1, p2, coteStroke * 2.0, coteW);
                drawCenteredTextLine(gr, p1.Add(p2.Substract(p1).Divide(2)), g.Width.Value.ToString());
            }

            p1 = new Cairo.PointD(hr.X - space, hr.Top + 0.5);
            p2 = new Cairo.PointD(hr.X - space, hr.Bottom - 0.5);

            if (p1.X < cb.Left)
            {
                if (hr.Right > cb.Right - space)
                {
                    p1.X = p2.X = hr.Right - space;
                }
                else
                {
                    p1.X = p2.X = hr.Right + space;
                }
            }
            if (g.Height.IsFit)
            {
                gr.DrawCoteInverse(p1, p2, coteStroke, fill, coteW, coteL);
            }
            else if (g.Height.IsRelativeToParent)
            {
                gr.DrawCote(p1, p2, coteStroke, fill, coteW, coteL);
                if (g.Height.Value < 100)
                {
                    drawCenteredTextLine(gr, p1.Add(p2.Substract(p1).Divide(2)), g.Height.ToString());
                }
            }
            else if (g.Width.IsFixed)
            {
                gr.DrawCoteFixed(p1, p2, coteStroke * 2.0, coteW);
                drawCenteredTextLine(gr, p1.Add(p2.Substract(p1).Divide(2)), g.Height.Value.ToString());
            }

            //				hr.Inflate (2);
            //gr.SetDash (new double[]{ 1.0, 4.0 }, 0.0);
            //gr.SetSourceColor (Color.Gray);
//			gr.Rectangle (hr,coteStroke);
//			gr.Stroke ();
            gr.Operator = Operator.Over;
        }
Esempio n. 52
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (!is_drawing)
            {
                return;
            }

            double x = Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1);
            double y = Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1);

            doc.Selection.Visible = true;

            ImageSurface surf = doc.SelectionLayer.Surface;

            using (Context g = new Context(surf)) {
                g.Antialias = Antialias.Subpixel;

                if (path != null)
                {
                    g.AppendPath(path);
                    (path as IDisposable).Dispose();
                }
                else
                {
                    g.MoveTo(x, y);
                }

                g.LineTo(x, y);
                lasso_polygon.Add(new IntPoint((long)x, (long)y));

                path = g.CopyPath();

                g.FillRule = FillRule.EvenOdd;
                g.ClosePath();
            }

            doc.Selection.SelectionPolygons.Clear();
            doc.Selection.SelectionPolygons.Add(lasso_polygon.ToList());
            SelectionModeHandler.PerformSelectionMode(combine_mode, doc.Selection.SelectionPolygons);
            doc.Workspace.Invalidate();
        }
Esempio n. 53
0
        protected override void OnMouseUp(DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            // If the user didn't move the mouse, they want to deselect
            int tolerance = 0;

            if (Math.Abs(reset_origin.X - args.Event.X) <= tolerance && Math.Abs(reset_origin.Y - args.Event.Y) <= tolerance)
            {
                PintaCore.Actions.Edit.Deselect.Activate();
                if (hist != null)
                {
                    hist.Dispose();
                    hist = null;
                }
                handler_active = false;
                doc.ToolLayer.Clear();
            }
            else
            {
                ReDraw(args.Event.State);
                if (doc.Selection != null)
                {
                    doc.selHandler.PerformSelectionMode(DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons));
                    PintaCore.Workspace.Invalidate();
                }
                if (hist != null)
                {
                    doc.History.PushNewItem(hist);
                    hist.Dispose();
                    hist = null;
                }
                handler_active = true;
            }

            is_drawing = false;
            isResizing = false;
        }
Esempio n. 54
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            if (is_drawing)
            {
                return;
            }

            hist = new SelectionHistoryItem(Icon, Name);
            hist.TakeSnapshot();

            combine_mode = PintaCore.Workspace.SelectionHandler.DetermineCombineMode(args);
            path         = null;
            is_drawing   = true;

            var doc = PintaCore.Workspace.ActiveDocument;

            doc.PreviousSelection.Dispose();
            doc.PreviousSelection = doc.Selection.Clone();
        }
Esempio n. 55
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if ((args.Event.State & Gdk.ModifierType.Button1Mask) == Gdk.ModifierType.Button1Mask)
            {
                outline_color = PintaCore.Palette.PrimaryColor;
                fill_color    = PintaCore.Palette.SecondaryColor;
            }
            else if ((args.Event.State & Gdk.ModifierType.Button3Mask) == Gdk.ModifierType.Button3Mask)
            {
                outline_color = PintaCore.Palette.SecondaryColor;
                fill_color    = PintaCore.Palette.PrimaryColor;
            }
            else
            {
                last_point = point_empty;
                return;
            }

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals(point_empty))
            {
                last_point = new Point(x, y);
                return;
            }

            if (doc.Workspace.PointInCanvas(point))
            {
                surface_modified = true;
            }

            doc.ToolLayer.Clear();
            ImageSurface surf = doc.ToolLayer.Surface;

            using (Context g = new Context(surf)) {
                doc.Selection.Clip(g);

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                if (path != null)
                {
                    g.AppendPath(path);
                    (path as IDisposable).Dispose();
                }

                g.LineTo(x, y);

                path = g.CopyPath();

                g.ClosePath();
                g.LineWidth = BrushWidth;
                g.LineJoin  = LineJoin.Round;
                g.LineCap   = LineCap.Round;
                g.FillRule  = FillRule.EvenOdd;

                if (FillShape && StrokeShape)
                {
                    g.Color = fill_color;
                    g.FillPreserve();
                    g.Color = outline_color;
                    g.Stroke();
                }
                else if (FillShape)
                {
                    g.Color = outline_color;
                    g.Fill();
                }
                else
                {
                    g.Color = outline_color;
                    g.Stroke();
                }
            }

            doc.Workspace.Invalidate();

            last_point = new Point(x, y);
        }
Esempio n. 56
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            ImageSurface surf = doc.SelectionLayer.Surface;

            using (Context g = new Context(surf)) {
                if (path != null)
                {
                    g.AppendPath(path);
                    (path as IDisposable).Dispose();
                    path = null;
                }

                g.FillRule = FillRule.EvenOdd;
                g.ClosePath();
            }

            doc.Selection.SelectionPolygons.Clear();
            doc.Selection.SelectionPolygons.Add(lasso_polygon.ToList());
            SelectionModeHandler.PerformSelectionMode(combine_mode, doc.Selection.SelectionPolygons);
            doc.Workspace.Invalidate();

            if (hist != null)
            {
                doc.History.PushNewItem(hist);
                hist = null;
            }

            lasso_polygon.Clear();
            is_drawing = false;
        }
Esempio n. 57
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (!is_drawing)
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            current_point = point;
            double x = point.X;
            double y = point.Y;

            doc.ToolLayer.Clear();

            bool      shiftkey_pressed = (args.Event.State & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask;
            Rectangle dirty            = DrawShape(Utility.PointsToRectangle(shape_origin, new PointD(x, y), shiftkey_pressed), doc.ToolLayer, shiftkey_pressed);

            dirty = dirty.Clamp();

            doc.Workspace.Invalidate(last_dirty.ToGdkRectangle());
            doc.Workspace.Invalidate(dirty.ToGdkRectangle());

            last_dirty = dirty;

            if (doc.Workspace.PointInCanvas(point))
            {
                surface_modified = true;
            }
        }
Esempio n. 58
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            double x = point.X;
            double y = point.Y;

            current_point        = point;
            doc.ToolLayer.Hidden = true;

            DrawShape(Utility.PointsToRectangle(shape_origin, new PointD(x, y), args.Event.IsShiftPressed()), doc.CurrentUserLayer, args.Event.IsShiftPressed());

            doc.Workspace.Invalidate(last_dirty.ToGdkRectangle());

            is_drawing = false;

            if (surface_modified)
            {
                doc.History.PushNewItem(CreateHistoryItem());
            }
            else if (undo_surface != null)
            {
                (undo_surface as IDisposable).Dispose();
            }

            surface_modified = false;
        }
Esempio n. 59
0
 public void Rectangle(PointD p, double width, double height)
 {
     ThrowIfDisposed();
     Rectangle(p.X, p.Y, width, height);
 }
Esempio n. 60
0
 public void CurveTo(PointD p1, PointD p2, PointD p3)
 {
     ThrowIfDisposed();
     CurveTo(p1.X, p1.Y, p2.X, p2.Y, p3.X, p3.Y);
 }