Click on specific/smaller region (maxX-10)

I want to mouse click on a region but remove like 10 pixels from +X, I found this on the forum but can’t get it to work.
Visual sample:

|:black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square:|
|:black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square::black_small_square:| ← remove 10 from maxX

I’m using:

MouseClickWithRegionSubstituted(dest, new RectInt(dest.Region.Min0,dest.Region.Min1,dest.Region.Max0-10,dest.Region.Max1), MouseButtonIdEnum.Left);

with:

MotionParam MouseClickWithRegionSubstituted( IUIElement destination, RectInt region, MouseButtonIdEnum mouseButton, int repetitionCount = 0) => new MotionParam { MouseListWaypoint = new{ new MotionParamMouseRegion { UIElement = destination, RegionReplacement = region, }}, MouseButton = new{mouseButton}, MouseButtonRepetitionCount = repetitionCount, };

Thank you in advance for any help

I found some functions on /src/Sanderling.Interface/Sanderling.Interface/MemoryStruct/Extension.cs like:

WithRegion
WithRegionSizePivotAtCenter
WithRegionSizeBoundedMaxPivotAtCenter

but I also found one that I can’t find anywhere:

FromCenterAndSize

How do I actually do what I want to do without having the center of the region as reference?

I answered my own question with this code, might be overdoing it but it works:

MotionResult MouseClickOffset(IUIElement destination, RectInt changeA, RectInt changeB, MouseButtonIdEnum mouseButton) {
long xC = 0; long yC = 0; long xS = destination.Region.Size().A; long yS = destination.Region.Size().B;

if (changeA.Area() != 0) {
if (changeA.Min0 != 0) { xC = changeA.Min0/2; xS-= changeA.Min0; }
if (changeA.Max0 != 0) { xC = changeA.Max0/2; xS-= changeA.Max0; }
if (changeA.Min1 != 0) { yC = changeA.Min1/2; yS-= changeA.Min0; }
if (changeA.Max1 != 0) { yC = changeA.Max1/2; yS-= changeA.Max0; }
}
if (changeB.Area() != 0) {
if (changeB.Min0 != 0) { xC = -(xS/2)+(changeB.Min0/2); xS = changeB.Min0; }
if (changeB.Max0 != 0) { xC = (xS/2)-(changeB.Max0/2); xS = changeB.Max0; }
if (changeB.Min1 != 0) { yC = -(yS/2)+(changeB.Min1/2); yS = changeB.Min1; }
if (changeB.Max1 != 0) { yC = (yS/2)-(changeB.Max1/2); yS = changeB.Max1; }
}

return MouseClickWithRegionSubstituted(destination,
RectInt.FromCenterAndSize(new Vektor2DInt(xC, yC), new Vektor2DInt(xS, yS)),
mouseButton);
}

My usage is:

MouseClickOffset(IUIElement destination,
RectInt ( // Make the box shorter
10, // Remove 10 from the region X at the left
5, // Remove 5 from the region X at the right
10, // Remove 10 from the region X at the top
10 // Remove 10 from the region X at the top
),
RectInt ( // Make box size at position
10, // Change box X limit to 10 (from the left)
5, // Change box X limit to 5 (from the right)
10, // Change box Y limit to 5 (from the top)
10 // // Change box Y limit to 5 (from the bottom)
),
MouseButtonIdEnum.Left);

Visual aid: http://i.imgur.com/EBIBuom.png

This should work with several values in, but I haven’t even tested it.

1 Like

I think reusing the sample from Ajout de certaines fonctionnalité - #11 by Arcitectus would be a good start:

using Bib3.Geometrik;

static MotionParam MouseClickWithRegionSubstituted(
	IUIElement destination,
	RectInt region,
	MouseButtonIdEnum mouseButton,
	int repetitionCount = 0) =>
	new MotionParam
	{
		MouseListWaypoint = new[] { new MotionParamMouseRegion { UIElement = destination, RegionReplacement = region, } },
		MouseButton = new[] { mouseButton },
		MouseButtonRepetitionCount = repetitionCount,
	};

Then, to implement the reduction by 10 pixels from the right side, I would try the following code:

static MotionParam MouseClickWithRegionReducedByTenOnTheRight(
	IUIElement destination,
	MouseButtonIdEnum mouseButton,
	int repetitionCount = 0) =>
	MouseClickWithRegionSubstituted(
		destination,
		RectInt.FromMinPointAndMaxPoint(
			destination.Region.MinPoint(),
			new Vektor2DInt(destination.Region.Max0 - 10, destination.Region.Max1)),
		mouseButton,
		repetitionCount);
1 Like

Thank you, anywhere I can find a reference for all those functions like FromMinPointAndMaxPoint and FromCenterAndSize and any others that are available?

For example, you can view a reference in Visual Studio Object Browser, as shown in this Screenshot:

http://i.imgur.com/Kw4WhyS.png