Inheritance: IDisposable
Exemplo n.º 1
0
        protected override void OnMouseDown(Document document, ToolMouseEventArgs e)
        {
            var pos = e.Point;

            // Don't do anything if we're outside the canvas
            if (pos.X < 0 || pos.X >= document.ImageSize.Width)
            {
                return;
            }
            if (pos.Y < 0 || pos.Y >= document.ImageSize.Height)
            {
                return;
            }

            base.OnMouseDown(document, e);

            using (var currentRegion = new Cairo.Region(document.GetSelectedBounds(true).ToCairoRectangleInt())) {
                // See if the mouse click is valid
                if (!currentRegion.ContainsPoint(pos.X, pos.Y) && LimitToSelection)
                {
                    return;
                }

                var surface       = document.Layers.CurrentUserLayer.Surface;
                var stencilBuffer = new BitMask(surface.Width, surface.Height);
                var tol           = (int)(Tolerance * Tolerance * 256);

                Rectangle boundingBox;

                if (IsContinguousMode)
                {
                    CairoExtensions.FillStencilFromPoint(surface, stencilBuffer, pos, tol, out boundingBox, currentRegion, LimitToSelection);
                }
                else
                {
                    CairoExtensions.FillStencilByColor(surface, stencilBuffer, surface.GetColorBgraUnchecked(pos.X, pos.Y), tol, out boundingBox, currentRegion, LimitToSelection);
                }

                OnFillRegionComputed(document, stencilBuffer);

                // If a derived tool is only going to use the stencil,
                // don't waste time building the polygon set
                if (CalculatePolygonSet)
                {
                    var polygonSet = stencilBuffer.CreatePolygonSet(boundingBox, 0, 0);
                    OnFillRegionComputed(document, polygonSet);
                }
            }
        }
Exemplo n.º 2
0
        protected void GenerateMask()
        {
            if (MaskMap != null)
            {
                MaskMap.Dispose();
            }

            using (var maskImage = new ImageSurface(Format.Argb32, Image.Width, Image.Height))
            {
                using (var cr = new Context(maskImage))
                {
                    cr.SetSourceRGB(0, 0, 0);
                    cr.Operator = Operator.Clear;
                    cr.Paint();
                    cr.Operator = Operator.Source;

                    cr.SetSource(Image, 0, 0);
                    cr.Rectangle(new Cairo.Rectangle(0, 0, Image.Width, Image.Height));
                    cr.Paint();
                }
                MaskMap = Gdk.CairoHelper.RegionCreateFromSurface(maskImage);
            }
        }
Exemplo n.º 3
0
		public Status Xor (Region other)
		{
			CheckDisposed ();
			return NativeMethods.cairo_region_xor (Handle, other.Handle);
		}
Exemplo n.º 4
0
		public Status Intersect (Region other)
		{
			CheckDisposed ();
			return NativeMethods.cairo_region_intersect (Handle, other.Handle);
		}
Exemplo n.º 5
0
		public Status Subtract (Region other)
		{
			CheckDisposed ();
			return NativeMethods.cairo_region_subtract (Handle, other.Handle);
		}
Exemplo n.º 6
0
		public override void OnButtonRelease(MouseButtonEvent evt)
		{
			base.OnButtonRelease(evt);

			if (IsSelected && !IsTogglable)
			{
				Deselect();
			}

			// if we were just clicked, we get to handle the next button release event
			if (hitRegion != Region.None)
			{
				hitRegion = Region.None;
				evt.Handle(this);
				MakeDirty();
			}

		}
Exemplo n.º 7
0
		public override void OnButtonPress(MouseButtonEvent evt)
		{
			base.OnButtonPress(evt);

			if (evt.IsHandled)
				return;

			hitRegion = HitRegion(evt.Pos);

			if (hitRegion != Region.None)
			{
				if (IsTogglable)
				{
					if (IsSelected)
						Deselect();
				}

				Select(hitRegion);

				evt.Handle(this);
				if (hitRegion == Region.Button1)
					RaiseAction1();
				else
					RaiseAction2();

				MakeDirty();
			}
		}
Exemplo n.º 8
0
		public override bool HitTest(Coord pos)
		{
			hitRegion = HitRegion(pos);
			Hover(hitRegion);
			return hitRegion != Region.None;
		}
Exemplo n.º 9
0
		/// <summary>
		/// Sets the hovering state on a region (and unsets it on the other one).
		/// </summary>
		protected void Hover(Region region)
		{
			if (region == Region.Button1)
			{
				if ((HitState1 &= HitState.Hovering) == 0) // wasn't hovering before
					MakeDirty();
				HitState1 |= HitState.Hovering;
				HitState2 &= ~HitState.Hovering;
			}
			else if (region == Region.Button2)
			{
				if ((HitState2 &= HitState.Hovering) == 0) // wasn't hovering before
					MakeDirty();
				HitState2 |= HitState.Hovering;
				HitState1 &= ~HitState.Hovering;
			}
			else // nothing is hovering
			{
				HitState1 &= ~HitState.Hovering;
				HitState2 &= ~HitState.Hovering;
			}
		}
Exemplo n.º 10
0
		/// <summary>
		/// Selects the given region (and deselects the other one).
		/// </summary>
		public void Select(Region region)
		{
			Select();
			if (region == Region.Button1)
			{
				HitState1 |= HitState.Selected;
				HitState2 &= ~HitState.Selected;
			}
			else if (region == Region.Button2)
			{
				HitState2 |= HitState.Selected;
				HitState1 &= ~HitState.Selected;
			}
			else // nothing is selected
			{
				HitState1 &= ~HitState.Selected;
				HitState2 &= ~HitState.Selected;
			}
		}
Exemplo n.º 11
0
		public Status Xor (Region other)
		{
			return NativeMethods.cairo_region_xor (Handle, other.Handle);
		}
Exemplo n.º 12
0
		public Status Union (Region other)
		{
			return NativeMethods.cairo_region_union (Handle, other.Handle);
		}
Exemplo n.º 13
0
		public Status Intersect (Region other)
		{
			return NativeMethods.cairo_region_intersect (Handle, other.Handle);
		}
Exemplo n.º 14
0
		public Status Subtract (Region other)
		{
			return NativeMethods.cairo_region_subtract (Handle, other.Handle);
		}