Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

overlay image from file and follow cursor, scale up or down with scroll wheel, and rotate



  • Please log in to reply
10 replies to this topic
cooljunk
  • Members
  • 19 posts
  • Last active: Oct 31 2015 08:03 PM
  • Joined: 22 Oct 2015

Hi guys, so I'm really stumped with making this script. I have a template I want to be able to activate with certain hotkeys and have it follow my mouse cursor, scale up when scrolling up, scale down when scrolling down, and then rotate with arrow keys, and then close with escape. 

 

 

I found this from a gdip tutorial 

 

; Get a bitmap from the image
pBitmap := Gdip_CreateBitmapFromFile("background.png")

 

But I can figure out how to add to it.

 

 

Any help appreciated!



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Make sure you have the library in your folder and use #Include or put the explicit functions in your script. In this case, make sure you have a function called Gdip_CreateBitmapFromFile() somewhere.

 

I haven't worked with the Gdip library so I don't know exactly how to best help you.



cooljunk
  • Members
  • 19 posts
  • Last active: Oct 31 2015 08:03 PM
  • Joined: 22 Oct 2015

Make sure you have the library in your folder and use #Include or put the explicit functions in your script. In this case, make sure you have a function called Gdip_CreateBitmapFromFile() somewhere.

 

I haven't worked with the Gdip library so I don't know exactly how to best help you.

Could we perhaps do without it? I was playing with the normal functions last night and it seems I can at least get some transparency in my image to show up using WinSet, TransColor, FFFFFF  but it does not seem to recognize semi-transparency. only full transparency or completely solid, which isn't a bad deal because I noticed you can apply variable transparency to a window. I'm thinknig I could connect transparency control to my up and down arrow keys. So, left and right arrow keys rotate, up and down for transparency, and scroll wheel for size.



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Like I said I haven't played with the Gdip library, but if we try to work without it, we'd basically have to recreate the library anyway to get something as good. But yes, only a part of the library. I'm not sure how best to end up up doing the rotating, but this link is something I bookmarked a couple years ago:

 

http://www.autohotke...keys-need-help/

 

And that is great - this uses Gdip, so, it looks kind of unavoidable.

 

Sizing should be capable by redrawing the GUI after resetting the image size values, but the other stuff seems tricky. WinSet Transparent could be enough for the iamge, but, not entirely sure.



cooljunk
  • Members
  • 19 posts
  • Last active: Oct 31 2015 08:03 PM
  • Joined: 22 Oct 2015

Like I said I haven't played with the Gdip library, but if we try to work without it, we'd basically have to recreate the library anyway to get something as good. But yes, only a part of the library. I'm not sure how best to end up up doing the rotating, but this link is something I bookmarked a couple years ago:

 

http://www.autohotke...keys-need-help/

 

And that is great - this uses Gdip, so, it looks kind of unavoidable.

 

Sizing should be capable by redrawing the GUI after resetting the image size values, but the other stuff seems tricky. WinSet Transparent could be enough for the iamge, but, not entirely sure.

Cool I'm going to see what I can come up with now as that thread seems very useful. Thanks!



cooljunk
  • Members
  • 19 posts
  • Last active: Oct 31 2015 08:03 PM
  • Joined: 22 Oct 2015

I can't seem to get anywhere. I can't even get a PNG to display properly.  Could someone please help me get started?



noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011
✓  Best Answer

It was less complex than i thought .This is a complete working example with a "kompas" picture and the whole library included that explains the size!

 

You can download or copy and paste :  https://dl.dropboxus...7708/Rotate.ahk

 

Spoiler

winXP  and ahk unicode


cooljunk
  • Members
  • 19 posts
  • Last active: Oct 31 2015 08:03 PM
  • Joined: 22 Oct 2015

It was less complex than i thought .This is a complete working example with a "kompas" picture and the whole library included that explains the size!

 

You can download or copy and paste :  https://dl.dropboxus...7708/Rotate.ahk

 

Spoiler

Holy moley thank you Noname! This works perfectly with your image, however there seems to be a problem in that you must first click on the image before you can scale, but this seems to only work on a non-transparent part of the image. Would it be easy to fix it so the scaleability is always active?

 

If you're not sure how to fix the problem, I may just simply make the center of the image have a nontransparent part. Also, rotating is very laggy. Is this something that can be fixed with the code or is it due to having a high resolution image?

 

 

Thanks again!



noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011

 

Would it be easy to fix it so the scaleability is always active?

 

It is always active,i do not see what can cause your problem.When you set the "settimer,move,200" (line 50) to 200000 the image will not follow the cursor and you should be able to scale it even if the mouse is not on it.

 

The rotating is very cpu intensive and be aware that if you scale the image to make it smaller ,the bitmap that rotates is still the same ( to make calculating position much simpler) so take the smallest image to begin with.I guess 200 pixels width is the max for smooth rotation on my system.


winXP  and ahk unicode


cooljunk
  • Members
  • 19 posts
  • Last active: Oct 31 2015 08:03 PM
  • Joined: 22 Oct 2015

It is always active,i do not see what can cause your problem.When you set the "settimer,move,200" (line 50) to 200000 the image will not follow the cursor and you should be able to scale it even if the mouse is not on it.

 

The rotating is very cpu intensive and be aware that if you scale the image to make it smaller ,the bitmap that rotates is still the same ( to make calculating position much simpler) so take the smallest image to begin with.I guess 200 pixels width is the max for smooth rotation on my system.

I've been playing around with this a bit. First I reduced the resolution of my image. It was 3 times larger than my display anyway so it made sense to do so. Lagging is now greatly reduced. I also tweaked the code some.  You can see the revised code below. First thing I did was remove the image extraction as I found it to be unnecessary.

 

 I added a couple of keys for fine-tuning the scale (+ and -) and they worked without the image needing to be clicked on first so I guess the scroll wheel is just special in that you must click the image first. I did need to add some transparency to the image as well in order to click it and not through it. The entire center region is normally 100% transparent which made me click through it (in addition to scrolling) so I made it 99%.

Also, for clicking the image first, I believe I found a work-around for that. Under the move functions, I added this: 

Send % "{Click " . ( GetKeyState("LButton") ? "Up}" : "Down}" )

 

So, whenever I move the cursor, it holds down left click. This also seems to have improved the framerate on the image when it is moved. It is completely lag-free. You might be interested in trying my modified script. I also added a toggle to the cursor follow, when you right click you will get a message saying to click OK to return the overlay back to following the cursor.

Spoiler
 
Thanks again for your help!


noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011

 

It is completely lag-free.

 

Very good .I still cannot see why scaling needs a click on the image ( i tried your code without it and it works without click on my PC).You loose and gain something.You lose the ability to use the leftmouse button ( if the center is transparent ) but you gain the smooth movement!


winXP  and ahk unicode