Compass - Measure angles and scale distances with your mouse

Post your working scripts, libraries and tools
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

Re: Compass - Measure angles and scale distances with your mouse

05 Aug 2020, 19:04

use win+p or another method to toggle to single monitor mode and then launch it, that should tell you if its a multi monitor issue or something else pretty quickly

also set your dpi scaling to 100%, another possible culprit
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
iilabs
Posts: 177
Joined: 07 Jun 2020, 16:57

Re: Compass - Measure angles and scale distances with your mouse

05 Aug 2020, 19:53

Thank you. Went through all those steps and it started to work until I loaded the program meant for. So it seems to work fine on some applications. Maybe some form of block if a program uses graphics Dll as this script ? At least the data is available for me to work around the cosmetics. The lines do help with accuracy and for making clip images. Maybe it has to do with the dll being used? I’ve used other scripts with line or circles that’s used gdip?
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

Re: Compass - Measure angles and scale distances with your mouse

05 Aug 2020, 20:44

try running the script as administrator
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
iilabs
Posts: 177
Joined: 07 Jun 2020, 16:57

Re: Compass - Measure angles and scale distances with your mouse

05 Aug 2020, 21:31

Thanks for that idea. I gave it a try. Although it didn’t work, I did discover something. It seems like the lines show up after making the monitor your main monitor in windows setting. When you switch another monitor to be main it then works. Also keeps the previous monitor made previously into main. After going through 4 monitors they all work! Wonder if this means the script can be adjusted since likely not the native application?
awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

Re: Compass - Measure angles and scale distances with your mouse

06 Aug 2020, 14:16

gwarble wrote:
05 Aug 2020, 17:16
nice update, small bug:
when snap is on, the second line created moves the endpoint of the previous line to its unsnapped position
Thanks for pointing that out. Actually, I saw that behavior once during my brief testing but I didn't see it again so I forgot about it.
It should be fixed now (I edited my previous post). I added a check for snap before the lines are stored.
I also made some other small tweaks and fixes.
for me some trivial changes, i removed the msgbox and let it add up to 10 lines to the screen before deleting, or deleting on Esc::,
I think the limit will be 20 because that's the max number of tooltips allowed.
iilabs wrote:
05 Aug 2020, 21:31
It seems like the lines show up after making the monitor your main monitor in windows setting. When you switch another monitor to be main it then works. Also keeps the previous monitor made previously into main. After going through 4 monitors they all work! Wonder if this means the script can be adjusted since likely not the native application?
I'm not sure what would be causing that. Maybe the program in question is causing it through some sort or unique behavior? If there are no other programs with this problem then we could guess that the program is doing something to cause it. For example, forcing its window to be always on top.
User avatar
iilabs
Posts: 177
Joined: 07 Jun 2020, 16:57

Re: Compass - Measure angles and scale distances with your mouse

06 Aug 2020, 15:45

Bizzare. At least I’m getting the data which is key. Thank you all for you input and contributions!
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

Re: Compass - Measure angles and scale distances with your mouse

06 Aug 2020, 15:51

Thanks.

Oh yeah true, well the screen seemed too cluttered after 10 anyway... I might mess around with drawing the dimension inline with the actual line via gdip and ditch the tooltip altogether. Also I added crosshairs and separate X and Y dimensions, just because its useful for machined part drawings.

There might be a memory or GDI object leak, it crashes for me after running for a little while.

Overall very cool and I'm looking forward to finding ways to use it.


iilabs: Does it work perfectly in that program when the computer is set to single monitor mode? If not and its not running as admin, it could be the AlwaysOnTop conflict awel mentioned, try adding F1::Gui, Compass: +AlwaysOnTop to the end of the script and see if pressing F1 makes the lines appear or flash.
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
iilabs
Posts: 177
Joined: 07 Jun 2020, 16:57

Re: Compass - Measure angles and scale distances with your mouse

06 Aug 2020, 17:51

Yes works no problem with single monitor. Will try your suggestions. Do you have the updated code with cross hairs? That would be a nice addition.
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

Re: Compass - Measure angles and scale distances with your mouse

06 Aug 2020, 18:19

Replace the static variables with this (mainly add a Cross variable, I set some defaults how I'd want):

Code: Select all

    static Color1 := 0x55000000, Color2 := 0x990066ff, Lineweight1 := 1
    , ScaleFactor := 1., Units := "pixels", Snap := true, Cross := 20
and replace this function:

Code: Select all

    GDIP_DrawLine(StartX, CurrentX, StartY, CurrentY) {
        DllCall("gdiplus.dll\GdipDrawLine", "Ptr", this.Graphics, "Ptr", this.pPen, "Float", StartX, "Float", StartY, "Float", CurrentX, "Float", CurrentY)
        , DllCall("gdiplus.dll\GdipDrawLine", "Ptr", this.Graphics, "Ptr", this.pPen, "Float", StartX+this.Cross, "Float", StartY, "Float", StartX-this.Cross, "Float", StartY)
        , DllCall("gdiplus.dll\GdipDrawLine", "Ptr", this.Graphics, "Ptr", this.pPen, "Float", CurrentX, "Float", CurrentY+this.Cross, "Float", CurrentX, "Float", CurrentY-this.Cross)
        , DllCall("gdiplus.dll\GdipDrawLine", "Ptr", this.Graphics, "Ptr", this.pPen, "Float", StartX, "Float", StartY+this.Cross, "Float", StartX, "Float", StartY-this.Cross)
        , DllCall("gdiplus.dll\GdipDrawLine", "Ptr", this.Graphics, "Ptr", this.pPen, "Float", CurrentX+this.Cross, "Float", CurrentY, "Float", CurrentX-this.Cross, "Float", CurrentY)
        , DllCall("gdiplus.dll\GdipFillEllipse", "Ptr", this.Graphics, "Ptr", this.pBrush, "Float", StartX - 4, "Float", StartY - 4, "Float", 8, "Float", 8) ;fixed uncentered circles...
        , DllCall("gdiplus.dll\GdipFillEllipse", "Ptr", this.Graphics, "Ptr", this.pBrush, "Float", CurrentX - 4, "Float", CurrentY - 4, "Float", 8, "Float", 8)
    }
Last edited by gwarble on 06 Aug 2020, 18:32, edited 1 time in total.
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

Re: Compass - Measure angles and scale distances with your mouse

06 Aug 2020, 18:24

I was also playing around with the crosshair before you click once ctrl+alt is held:

add to script:

Code: Select all

^Alt::
 Compass.Crosshair()
Return
add to class:

Code: Select all

    Crosshair() {
        if (this.Lines.MaxIndex() < 1) { ; If there are no existing lines, start GDIP
            this.GetWinArea()
            this.GDIP_Start()
            this.GDIP_Setup()
        }
        CoordMode, Mouse, Screen
        MouseGetPos, StartX, StartY
        while (GetKeyState("Ctrl", "P")) {    ; *Loop until Ctrl or L/RButton is released.
            MouseGetPos, CurrentX, CurrentY
                this.GDIP_DrawCrosshair(CurrentX, CurrentY)
              this.UpdateLines()
            }
              this.UpdateLines()
        return ;this.pxDist(CurrentX, StartX, CurrentY, StartY)
    }

Code: Select all

    GDIP_DrawCrosshair(X, Y) {
        DllCall("gdiplus.dll\GdipDrawLine", "Ptr", this.Graphics, "Ptr", this.pPen, "Float", X+this.Cross, "Float", Y, "Float", X-this.Cross, "Float", Y)
        , DllCall("gdiplus.dll\GdipDrawLine", "Ptr", this.Graphics, "Ptr", this.pPen, "Float", X, "Float", Y+this.Cross, "Float", X, "Float", Y-this.Cross)
        , DllCall("gdiplus.dll\GdipFillEllipse", "Ptr", this.Graphics, "Ptr", this.pBrush, "Float", X - 4, "Float", Y - 4, "Float", 8, "Float", 8)
    }
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

Re: Compass - Measure angles and scale distances with your mouse

07 Aug 2020, 10:12

gwarble wrote:
06 Aug 2020, 15:51
There might be a memory or GDI object leak, it crashes for me after running for a little while.
I think you are right but I don't see the cause.
gwarble wrote:
06 Aug 2020, 15:51
I might mess around with drawing the dimension inline with the actual line via gdip and ditch the tooltip altogether. Also I added crosshairs and separate X and Y dimensions, just because its useful for machined part drawings.
That sounds cool. Definitely keep posting the tweaks you do, or even a full version; I'd be interested to see more.
The crosshairs are great; a massive improvement IMO.

I'm not sure, but I think the following code might cause problems. If this.Lines.MaxIndex() is 0, then the script will start GDIP. But, if you then don't add any lines to this.lines then the next time you press the hotkey GDIP will be started again. (Now that I think about it, a similar problem may be the cause of the memory leak you mentioned.)

Code: Select all

    Crosshair() {
        if (this.Lines.MaxIndex() < 1) { ; If there are no existing lines, start GDIP
            this.GetWinArea()
            this.GDIP_Start()
            this.GDIP_Setup()
        }
        ;...
Maybe, instead of checking this.Lines.MaxIndex(), the script could set a flag when GDIP is started. That way it would be easier to check if it's running already.

Something like this could work:

Code: Select all

    GDIP_Close() {
        DllCall("gdiplus.dll\GdiplusShutdown", "UPtr", this.pToken)
        , DllCall("kernel32.dll\FreeLibrary", "Ptr", this.hGDIPLUS)
        this.pToken := "", this.hGDIPLUS := "" ; Clear these values to indicate that GDIP is not started
    }

... and then:

Code: Select all

    if (this.pToken = "") {
        this.GetWinArea()
        this.GDIP_Start()
        this.GDIP_Setup()
    }

Regarding @iilabs problem, it seems like it could be related to the multi-monitor setup. Is it possible to have negative monitor coordinates? GetWinArea() and GDIP_Setup() assume the 'Left' and 'Top' coordinates are zero. https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createdibsection
I wonder what the bounding coordinates of @iilabs' monitors are. Maybe the script is not getting them somehow. Could try hard coding them.
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

Re: Compass - Measure angles and scale distances with your mouse

07 Aug 2020, 17:03

yeah I agree its probably managing startup and shutdown of GDI+ a little more carefully, I havent had a chance to dig into it yet.

I will keep adding to this functionality and share what I like, its already proved useful on two machined parts today!
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
MonuKashyap
Posts: 74
Joined: 06 Jun 2016, 21:32

Re: Compass - Measure angles and scale distances with your mouse

09 Aug 2020, 01:23

Superb concept!!, its intresting..!!
User avatar
iilabs
Posts: 177
Joined: 07 Jun 2020, 16:57

Re: Compass - Measure angles and scale distances with your mouse

09 Aug 2020, 13:14

Yes!! Double high fives to all the contributors!

Thank you all for the updates as well. Please keep this going. An interesting ruler indeed. You all are saving me years of life.

Where would one go if we want to make this a more a more customizable ruler with a hotkey triggered GUI interface? GUI Creator come to mind?

For example, take this ruler to another level by allowing a menu GUI to:

toggle on/off cross hairs change to circle ends, triangles, etc
A 3,4,5 triangle pointer based on the scale taken for quick eyeball size measurements*
A 2mm, 3mm, etcs for snapping,
change the line color (invert to whats on background?) this would help with contrast
A number of measurements to sustain or send a sentence to the clipboard like "This measures 3mm" versus "This measures 2 x 3 mm, etc"*.

* will give me a multitasking headache pain relief as well. Happy to donate to any cause!
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

Re: Compass - Measure angles and scale distances with your mouse

09 Aug 2020, 13:48

my advice would be to learn to use AutoHotkey, all of that should be possible but its very niche/unique end user base so you’re never going to get the customizability you would if you understand a few basic things the code is doing it and tweak away from there

as for your ideas, all seem useful for measuring off a visual medical picture (i’m envisioning the ultrasound software where they snap a freeze frame and take some rough measurements by clicking points)

for reading pdfs of mechanical drawings, drawn to scale but missing important dimensions, is my end use case, so a fine line, crosshairs for pixel precision, and drawing bounding shapes (like what size round bar can i make this part out of) are useful


specifically, i was also thinking an inverted color would be nice but don’t know how to do that with gdi+ yet
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
iilabs
Posts: 177
Joined: 07 Jun 2020, 16:57

Re: Compass - Measure angles and scale distances with your mouse

10 Aug 2020, 10:07

Yes very good points. I've bought some udemy lectures and Jack Dunning's books. So the gradual and steep learning process for me. However, this forum, your contributions and others, and the challenges as well as time saving rewards that lay ahead will get me there! By any chance are you or anyone that you know for hire for tutoring or programming?
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

Re: Compass - Measure angles and scale distances with your mouse

15 Aug 2020, 07:07

Everyone is different, but I learn by trying to accomplish tasks and then improving piece by piece. This isn't a very basic task, so start with something basic that you waste time doing (like maybe writing the same email every week or filling out a form every visit). The Ask for Help forum will be useful for specifics, but the general usage, flow, and overall capabilities will come with use.

Its hard to make the time to be able to sign up for that kind of assistance, but I can answer questions as they come up. You might want to start a thread in the Ask for Help section to divert discussion away from kon's thread and draw in more helpers (and better ones)
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

Return to “Scripts and Functions”

Who is online

Users browsing this forum: daywalker, pgeugene and 17 guests