QB64.org Forum

Active Forums => Programs => Topic started by: Dav on February 26, 2021, 06:14:15 pm

Title: Almost real desktop Magnifying glass effect (Windows only)
Post by: Dav on February 26, 2021, 06:14:15 pm
Playing around with Windows Regions API today, made a little fake magnifying glass over desktop effect.  Use mouse to move circle over a captured desktop screenimage, it appears to magnify desktop area (see attached image).  It's not really magnifying the active desktop, but maybe someone could use this effect technique to do something more useful down the road.

Press ESC to end effect and close program.

- Dav

Code: QB64: [Select]
  1. '=================
  2. 'MagnifyCircle.bas
  3. '=================
  4. 'Fake magnifying glass effect using Windows API
  5. 'Coded by Dav, FEB/2021
  6.  
  7. 'This mostly just shows how to make a region and use it
  8. 'for a special effect.  Grabs desktop, stretches it a little,
  9. 'darkens it for an overlay feel.
  10.  
  11. 'Press ESC to end the effect and close program.
  12.  
  13. TYPE POINTAPI
  14.     x AS LONG
  15.     y AS LONG
  16.  
  17. DIM apixy AS POINTAPI
  18.  
  19.     FUNCTION SetWindowRgn& (BYVAL hwnd&, BYVAL hrgn~&, BYVAL bredraw%)
  20.     FUNCTION GetCursorPos% (lpPoint AS POINTAPI)
  21.     FUNCTION SetWindowPos& (BYVAL hWnd&, BYVAL hWndInsertAfter&, BYVAL X&, BYVAL Y&, BYVAL cx&, BYVAL cy&, BYVAL wFlags&)
  22.  
  23.     FUNCTION CreateRoundRectRgn& (BYVAL x1&, BYVAL y1&, BYVAL x2&, BYVAL y2&, BYVAL x3&, BYVAL y3&)
  24.  
  25. SCREEN _NEWIMAGE(200, 200, 32)
  26. back& = _SCREENIMAGE
  27.  
  28. rgn& = CreateRoundRectRgn(30, 30, 180, 180, 150, 150)
  29. IF SetWindowRgn(hwnd&, rgn&, 0) = 0 THEN PRINT "Failed...": END
  30.  
  31.  
  32.     mi = GetCursorPos(apixy): mx = apixy.x: my = apixy.y
  33.     x& = SetWindowPos(hwnd&, -1, mx - 100, my - 100, 0, 0, &H1)
  34.     x1 = -mx + 50: y1 = -my + 50
  35.     x2 = _DESKTOPWIDTH + x1: y2 = _DESKTOPHEIGHT + y1
  36.     _PUTIMAGE (x1, y1)-(x2 + 75, y2 + 75), back&,
  37.     LINE (x1, y1)-(x2 + 75, y2 + 75), _RGBA(0, 0, 0, 50), BF
  38.     _DISPLAY
  39.     _LIMIT 60
  40.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: SpriggsySpriggs on February 26, 2021, 06:30:07 pm
Now THAT IS IMPRESSIVE
Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: bplus on February 26, 2021, 10:16:44 pm
Yeah I am getting that desperate. Can you get it to focus where my eyes are pointed ;-)
Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: Pete on February 26, 2021, 11:21:57 pm
Useful. I'm trying to figure out a way to incorporate that into a dating app I'm creating. :O

Pete 
Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: Richard Frost on February 27, 2021, 12:17:09 am
It's nice to see short, easily understood demos of unusual library functions.

Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: Dav on February 27, 2021, 03:16:00 pm
Thanks everyone.  I have another one that updates & magnifies the active desktop, but have a bug or two to squash before posting.

- Dav

Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: Petr on February 27, 2021, 05:56:51 pm
ZOOM without libraries:

modify variables SizeOriginal or SizeZOOM for zooming ratio settings.

Code: QB64: [Select]
  1. TYPE xy
  2.     X AS SINGLE
  3.     Y AS SINGLE
  4. DIM C(628) AS xy
  5.  
  6. SizeOriginal = 50
  7. SizeZOOM = 70
  8.  
  9. FOR ci = 0 TO _PI(2) STEP .01
  10.     C(i).X = COS(ci)
  11.     C(i).Y = SIN(ci)
  12.     i = i + 1
  13.  
  14.  
  15.     _PUTIMAGE , img
  16.     MX = _MOUSEX
  17.     MY = _MOUSEY
  18.  
  19.     FOR D = 1 TO i - 1
  20.         _MAPTRIANGLE (MX, MY)-(MX + C(D).X * SizeOriginal, MY + C(D).Y * SizeOriginal)-(MX + C(D - 1).X * SizeOriginal, MY + C(D - 1).Y * SizeOriginal), img TO(MX, MY)-(MX + C(D).X * SizeZOOM, MY + C(D).Y * SizeZOOM)-(MX + C(D - 1).X * SizeZOOM, MY + C(D - 1).Y * SizeZOOM), 0
  21.     NEXT
  22.     _DISPLAY
  23.  

Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: Dav on February 27, 2021, 06:08:15 pm
Cool, @Petr !  I gotta start looking into maptriangle.

I'm gonna use that.

- Dav
Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: Petr on February 27, 2021, 06:17:56 pm
Thank you Dav. IF you rewrite XY types to INTEGERS, result is square. (Then the same effect can do _PUTIMAGE and it is faster)
Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: Dav on February 27, 2021, 07:41:37 pm
Thats good to know, Petr. Thanks.

@Pete, use Petrs zoom version for your dating app. You won't miss seeing anything using that one.

- Dav
Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: Pete on February 28, 2021, 05:28:44 am
Now if we could just get a SCREEN 0 version, so I could see what I'm typing in my WP. I thought I wrote on my dating app: College Graduate, but it turned out my spell checker changed that to: Constantly flatulates. If I had a SCREEN 0 magnifier, maybe I'd have something else to do on Friday nights, besides coding.

Pete
Title: Re: Almost real desktop Magnifying glass effect (Windows only)
Post by: Petr on February 28, 2021, 07:35:57 am
Quote
Now if we could just get a SCREEN 0 version, so I could see what I'm typing in my WP

Try use SaveImage to save screen 0 as 32 bit  image and then continue in the same way :)