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 : Sunday, March 1, 2020 9:23:19 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 602
United States

Thanks: 5 times
Was thanked: 134 time(s) in 120 post(s)
This set of scripts will allow you to drag a window to fit within grid cells on the screen.

For example, using 2 columns and 2 rows would split the screen into 4 cells, dragging the mouse around the screen would move the window to fit in the cell below the mouse.

This script is setup to use an action where Left click is a modifier! So you begin to draw the gesture, then press and hold the left mouse button, then release the stroke button while continuing to hold the left button. Then you simply move the window around the screen while holding the left button and when the mouse enters the area of a new cell, it will move and fit the window inside that cell. When you release the left button, the window will remain in that location.

Action Script (remember to make Left Button a modifier):
Code:
if(!sp.GetStoredBool("GridSnapActive")) {
    sp.StoreBool("GridSnapActive", true);
    sp.StoreHandle("GridSnapWindow", action.Window.HWnd);
    if(action.Window.Maximized) {
        action.Window.Restore();
    }
    //Create timer that executes every 100 milliseconds to watch the mouse location and move the window
    sp.CreateTimer("GridSnap", 
                   0, 
                   100, 
                    `var columns = 2; //Change this as needed
                      var rows = 2; //Change this as needed
                      var mousePt = sp.GetCurrentMousePoint();
                      //Convert the point to a PointF since the regions' Rect property is a RectangleF
                      var mousePointF = new drawing.System.Drawing.PointF(mousePt.X, mousePt.Y);
                      //Get a SystemWindow object representing the application's window
                      var gridSnapWindow = sp.WindowFromHandle(sp.GetStoredHandle("GridSnapWindow"));
                      //Get an array of regions, splitting the screen where the mouse is located into the defined columns and rows
                      var regions = sp.GetRegions(Screen.FromPoint(mousePt).WorkingArea, columns, rows);                             
                      //Go through each region (cell) and if the mouse is located in that region, move and size the window to fit    
                      for(var r  = 0; r < regions.Length; r++) {
                          if(regions[r].Rect.Contains(mousePointF)) {
                              gridSnapWindow.Location = new Point(parseInt(regions[r].Rect.X), parseInt(regions[r].Rect.Y));
                              gridSnapWindow.Size = new Size(parseInt(regions[r].Rect.Width), parseInt(regions[r].Rect.Height));
                              break;
                          }
                      }
                 `); 
}



For this to work, we do need to enable Global Actions > Mouse Events > Left Click:
(no need to check the consume box)
Code:
//If the click event is not the Down event (so on left button up) and the grid snap is active
if(!click.Down && sp.GetStoredBool("GridSnapActive")) {
    //Stop/delete the timer script and the other variables used for these scripts
    sp.DeleteTimer("GridSnap");
    sp.DeleteStoredHandle("GridSnapWindow");
    sp.DeleteStoredBool("GridSnapActive");
}

Edited by user Sunday, March 1, 2020 9:49:55 AM(UTC)  | Reason: Not specified

thanks 1 user thanked Rob for this useful post.
breakcore on 3/1/2020(UTC)
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.