StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Rob  
#1 Posted : Tuesday, June 11, 2019 12:52:35 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
This script will use the location where the gesture started (action.Start) and determine which region of the application's window it was in, based on the number of rows and columns you set to divide the window into:

Code:
var columns = 6;
var rows = 6;
var region = sp.GetRegionFromPoint(action.Window.Rectangle, action.Start, columns, rows);
if(region.Column == 1 || region.Column == 2) {
    sp.MessageBox(`Match!\r\nColumn 1 or 2, any Row\r\n\Region: Column: ${region.Column} - Row: ${region.Row}`, "Match");
} else if (region.Column == 4 && region.Row == 3) {
    sp.MessageBox(`Match!\r\nColumn 4, Row 3\r\n\Region: Column: ${region.Column} - Row: ${region.Row}`, "Match");
} else if (region.Column == 6 && (region.Row == 5 || region.Row == 6)) {
    sp.MessageBox(`Match!\r\nColumn 6, Row 5 or Row 6\r\n\Region: Column: ${region.Column} - Row: ${region.Row}`, "Match");
} else {
    sp.MessageBox(`No match, default condition\r\nRegion: Column: ${region.Column} - Row: ${region.Row}`, "No Match");
}
T908  
#2 Posted : Thursday, August 15, 2019 8:04:49 AM(UTC)
james200410

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/11/2019(UTC)
Posts: 3
Australia

Thanks: 3 times
Thanks for this script Rob, it has helped me greatly.
I can now split up the monitor and have 2,4,6 many actions to the same gesture and it works great.

I am just wondering if we could add an END variable so if a gesture starts in one region and ends in a different, pre-determined region, I could then also expand my use count by way of the physical size of the gesture as well.

Do you know if there are allowances for such a thing ?

Thanks in advance,


Rob  
#3 Posted : Thursday, August 15, 2019 12:56:49 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Sure, you can use the gesture start and end:

Code:
var columns = 6;
var rows = 6;
var startRegion = sp.GetRegionFromPoint(action.Window.Rectangle, action.Start, columns, rows);
var endRegion = sp.GetRegionFromPoint(action.Window.Rectangle, action.End, columns, rows);
if((startRegion.Column == 1 && endRegion.Column != 6 && endRegion.Row != 6) || startRegion.Column == 2) {
    sp.MessageBox(`Match!\r\nColumn 1 or 2, any Row\r\n\Start Region: Column: ${startRegion.Column} - Row: ${startRegion.Row}`, "Match");
} else if (startRegion.Column == 4 && startRegion.Row == 3) {
    sp.MessageBox(`Match!\r\nColumn 4, Row 3\r\n\Start Region: Column: ${startRegion.Column} - Row: ${startRegion.Row}`, "Match");
} else if (startRegion.Column == 6 && (startRegion.Row == 5 || startRegion.Row == 6)) {
    sp.MessageBox(`Match!\r\nColumn 6, Row 5 or Row 6\r\n\Start Region: Column: ${startRegion.Column} - Row: ${startRegion.Row}`, "Match");
} else if (startRegion.Column == 1 && startRegion.Row == 1 && endRegion.Column == 6 && endRegion.Row == 6) {
    sp.MessageBox(`Multiple Region Match!\r\n1,1 to 6,6\r\n\Start Region: Column: ${startRegion.Column} - Row: ${startRegion.Row}\r\n\End Region: Column: ${endRegion.Column} - Row: ${endRegion.Row}`, "Match");
} else {
    sp.MessageBox(`No match, default condition\r\nStart Region: Column: ${startRegion.Column} - Row: ${startRegion.Row}`, "No Match");
}


You can also use some math to find the distance between the gesture start and end points. This would be direct distance between the points, not the length of the line itself:

Code:
var distance = parseInt(Math.sqrt(Math.pow((action.End.X - action.Start.X), 2.0) + Math.pow((action.End.Y - action.Start.Y), 2.0)));
sp.MessageBox(distance, "Distance");


And you can get the number of gesture points captured for simple/rough comparisons:
Code:
var pointCount = action.GesturePoints.Count();
sp.MessageBox(pointCount, "Gesture Points");


Or use the gesture point count with your specified line options (pixel distances) to get the overall length of the line as it was drawn:
Code:
//Subtract 1 since it's already counted in the startDistance
var gesturePoints = action.GesturePoints.Count() - 1;
//Add 1 because the logic is if start segment being greater than the setting
var startDistance = sp_config.MinGestureStartDistance + 1;
//Add 1 because the logic is if current segment being greater than the setting
var segmentLength = sp_config.MinSegmentLength + 1;
var totalDistance = (gesturePoints * segmentLength) + startDistance;
sp.MessageBox(totalDistance, "Total Distance");


Note that these may not always be 100% accurate, but will be very close. Mouse messages travel very fast and there can be timing issues during the capture of points, etc.

Edited by user Thursday, August 15, 2019 1:08:04 PM(UTC)  | Reason: Not specified

Rob  
#4 Posted : Thursday, August 15, 2019 1:22:21 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
If you use the math calculation against the points, it's pretty much exact except for cumulative rounding effects:

Code:
var distance = 0;
//Intentionally starting index at 1 since it compares against previous point
for(var i = 1; i <= action.GesturePoints.Count() - 1; i++) {
    distance += parseInt(Math.sqrt(Math.pow((action.GesturePoints[i].X - action.GesturePoints[i-1].X), 2.0) + Math.pow((action.GesturePoints[i].Y - action.GesturePoints[i-1].Y), 2.0)));
}
sp.MessageBox(distance, "Total Distance");
T908  
#5 Posted : Thursday, August 15, 2019 9:28:48 PM(UTC)
james200410

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/11/2019(UTC)
Posts: 3
Australia

Thanks: 3 times
Hello Rob,

Thanks very much, I will try them out later today.

And sorry to had to ask, but I couldn't see any reference to the region.End in the help file, only the region.Start.

Am gonna have fun even further expanding my 1 gesture to do just about everything ... lol ;)

Rob  
#6 Posted : Thursday, August 15, 2019 10:51:10 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
There is no region.End property, RectRegion (returned by sp.GetRegionFromPoint) only has .Column and .Row properties.

In the example script for sp.GetRegionFromPoint, it's passing action.Start for the point parameter, but in the Script Help under Script Objects > ActionVars you can see .End is an available property for action as well.

action.Start is a Point type which contains the coordinates of where the gesture began.
action.End is a Point for the end (last) coordinates of the gesture.

thanks 1 user thanked Rob for this useful post.
james200410 on 8/18/2019(UTC)
T908  
#7 Posted : Sunday, August 18, 2019 8:09:04 PM(UTC)
james200410

Rank: Newbie

Reputation:

Groups: Approved
Joined: 8/11/2019(UTC)
Posts: 3
Australia

Thanks: 3 times
Thanks, Rob,
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.