Author Topic: Screenmove actual program screen  (Read 3360 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Screenmove actual program screen
« on: February 15, 2021, 06:20:48 pm »
I think the demo here speaks for itself:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1020, 780, 32)
  2. ScreenMove_Middle
  3. PRINT "Your desktop dimensions: "; _DESKTOPWIDTH, _DESKTOPHEIGHT
  4. PRINT "Your program dimensions: "; _WIDTH, _HEIGHT
  5. PRINT "Your program borders   : "; glutGet(506)
  6. PRINT "Your program titlebar  : "; glutGet(507)
  7. PRINT "To properly center your program, it should be at:"
  8. PRINT "Using Screenmove_Middle, it is currently at:"
  9. PRINT glutGet(100), glutGet(101)
  10. PRINT "Using _SCREENMOVE _MIDDLE, the screen is placed at:"
  11. PRINT glutGet(100), glutGet(101)
  12. PRINT "Which, as you can see, doesn't account for our borders or titlebar width and height."
  13.  
  14. PRINT "Maybe a better example would be to move the screen to 0,0."
  15. PRINT "Notice how the titlebar and borders are still here?"
  16. PRINT "Our program is actually at: "; glutGet(100), glutGet(101)
  17.  
  18. ScreenMove 0, 0
  19. PRINT "And notice how our program window now starts at 0,0, like we told it to?"
  20. PRINT "And, as you can see, we're now actually at :"; glutGet(100), glutGet(101)
  21.  
  22.  
  23. PRINT "And, best of all, since all these values are calculated manually, you don't need to worry about using a _DELAY with them, at   the beginning of your code, as we're manually setting our X/Y position and not trying to do it automatically."
  24.  
  25. SUB ScreenMove_Middle
  26.     $IF BORDERDEC = UNDEFINED THEN
  27.         $LET BORDERDEC = TRUE
  28.         DECLARE LIBRARY
  29.             FUNCTION glutGet& (BYVAL what&)
  30.         END DECLARE
  31.     $END IF
  32.     BorderWidth = glutGet(506)
  33.     TitleBarHeight = glutGet(507)
  34.     _SCREENMOVE (_DESKTOPWIDTH - _WIDTH - BorderWidth) / 2 + 1, (_DESKTOPHEIGHT - _HEIGHT - BorderWidth) / 2 - TitleBarHeight + 1
  35.  
  36. SUB ScreenMove (x, y)
  37.     $IF BORDERDEC = UNDEFINED THEN
  38.         $LET BORDERDEC = TRUE
  39.         DECLARE LIBRARY
  40.         FUNCTION glutGet& (BYVAL what&)
  41.         END DECLARE
  42.     $END IF
  43.     BorderWidth = glutGet(506)
  44.     TitleBarHeight = glutGet(507)
  45.     _SCREENMOVE x - BorderWidth, y - BorderWidth - TitleBarHeight
  46.  

Note: I found these subtle positioning differences to be vital for me, in another little batch program which tries to interact with my screen in various ways.  Clicks were often not registering as my screen simply wasn't where I expected it to be.  A box from (0,0)-(100,100), wasn't really at those coordinates, as it was instead at (borderwidth, borderwidth + titlebarheight)-STEP(100,100)...

Which was more than enough to throw all my work off and cause all sorts of unintentional glitches.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!