StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
Resize windows based on region, holding ALT
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
Ridiculously large and complicated script for Discord request, but hey it does work! Code://Resize window based on 3x3 grid of application's window where gesture/action started
//Set action's Modifier as ALT, Capture Before (though Either works too)
//You MUST be holding the ALT key down BEFORE pressing the stroke button!
/*
1. ALT down (hold)
2. Stroke button down
3. (optional draw gesture)
4. Stroke button release
5. Move mouse to resize
6. Release ALT
*/
//Only do this if the window is not maximized
if(!action.Window.Maximized)
{
sp.StoreObject("ResizeStartRegion", sp.GetRegionFromPoint(action.Window.Rectangle, action.Start, 3, 3));
sp.StorePoint("ResizeLastCursorPos", action.End);
sp.StoreObject("ResizeWindow", action.Window);
//Create timer, ticks every 50ms until ALT is not being held down
//NOTE the end of this line is a backtick, encompassing nearly everything below
sp.CreateTimer("ResizeWindowTimer", 50, 50, `
//If ALT is not down, clean up and kill timer
if(!(sp.GetKeyState(vk.MENU) & 0x8000))
{
sp.DeleteStoredPoint("ResizeLastCursorPos");
sp.DeleteStoredObject("ResizeStartRegion");
sp.DeleteStoredObject("ResizeWindow");
sp.DeleteTimer("ResizeWindowTimer");
sp.DeleteStoredBool("ResizeActive");
//Send Alt down/up to clear the Alt menu effect
sp.SendAltDown();
sp.SendAltUp();
}
else
{
//Only do this if there isn't an active timer tick handling a resize
if(!sp.GetStoredBool("ResizeActive"))
{
//Signal so timer doesn't start concurrent resizing
sp.StoreBool("ResizeActive", true);
var startRegion = sp.GetStoredObject("ResizeStartRegion");
var lastPoint = sp.GetStoredPoint("ResizeLastCursorPos");
var currentPoint = sp.GetCurrentMousePoint();
var resizeTarget = sp.GetStoredObject("ResizeWindow");
var currentRect = resizeTarget.Rectangle;
var newRect = new Rectangle(currentRect.Location, currentRect.Size)
var xDiff = lastPoint.X - currentPoint.X;
var yDiff = lastPoint.Y - currentPoint.Y;
//Only do this next set of logic if the mouse has moved
if(xDiff !== 0 || yDiff !== 0)
{
if(startRegion.Row === 1)
{
//Top row --------------------------------
if(startRegion.Column === 1)
{
//Top left
newRect.Location = new Point(currentRect.X - xDiff, currentRect.Y - yDiff);
newRect.Width = currentRect.Width + xDiff;
newRect.Height = currentRect.Height + yDiff;
}
else if(startRegion.Column === 2)
{
//Top center
newRect.Location = new Point(currentRect.X, currentRect.Y - yDiff);
newRect.Height = currentRect.Height + yDiff;
}
else if(startRegion.Column === 3)
{
//Top right
newRect.Location = new Point(currentRect.X, currentRect.Y - yDiff);
newRect.Width = currentRect.Width - xDiff;
newRect.Height = currentRect.Height + yDiff;
}
}
else if(startRegion.Row === 2)
{
//Center row --------------------------------
if(startRegion.Column === 1)
{
//Center left
newRect.Location = new Point(currentRect.X - xDiff, currentRect.Y);
newRect.Width = currentRect.Width + xDiff;
}
else if(startRegion.Column === 2)
{
//Center - Scale? Up/Down & Left/Right
newRect.Location = new Point(currentRect.X - parseInt(xDiff / 2), currentRect.Y - parseInt(yDiff / 2));
newRect.Width = currentRect.Width + xDiff;
newRect.Height = currentRect.Height + yDiff;
}
else if(startRegion.Column === 3)
{
//Center right
newRect.Width = currentRect.Width - xDiff;
}
}
else if(startRegion.Row === 3)
{
//Bottom row --------------------------------
if(startRegion.Column === 1)
{
//Bottom left
newRect.Location = new Point(currentRect.X - xDiff, currentRect.Y);
newRect.Width = currentRect.Width + xDiff;
newRect.Height = currentRect.Height - yDiff;
}
else if(startRegion.Column === 2)
{
//Bottom center
newRect.Height = currentRect.Height - yDiff;
}
else if(startRegion.Column === 3)
{
//Bottom right
newRect.Width = currentRect.Width - xDiff;
newRect.Height = currentRect.Height - yDiff;
}
}
//Assign window size to new rectangle
resizeTarget.Rectangle = newRect;
//Store current mouse point as last location
sp.StorePoint("ResizeLastCursorPos", currentPoint);
}
//Allow next timer tick to process resizing
sp.StoreBool("ResizeActive", false);
}
}
`); //End of Timer script parameter
}
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Newbie
Groups: Approved
Joined: 10/28/2020(UTC) Posts: 3 Thanks: 2 times Was thanked: 1 time(s) in 1 post(s)
|
Wow man, thanks!! 👌👌👌 I didn't expect you to make it! Haha, I was just wondering if it was possible and I was going to sort it out... The timer thing is interesting... 🤔 I will test it out when I get a chance! Edited by user Wednesday, October 28, 2020 4:37:27 PM(UTC)
| Reason: Not specified
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
Resize windows based on region, holding ALT
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.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close