Screenmove absolute coordinates
#1
I think the demo here speaks for itself:

Code: (Select All)
$COLOR:32
_DEFINE A-Z AS LONG
SCREEN _NEWIMAGE(1020, 780, 32)
ScreenMove_Middle
PRINT "Your desktop dimensions: "; _DESKTOPWIDTH, _DESKTOPHEIGHT
PRINT "Your program dimensions: "; _WIDTH, _HEIGHT
PRINT "Your program borders   : "; glutGet(506)
PRINT "Your program titlebar  : "; glutGet(507)
PRINT
PRINT "To properly center your program, it should be at:"
PRINT (_DESKTOPWIDTH - _WIDTH) / 2,
PRINT (_DESKTOPHEIGHT - _HEIGHT) / 2
PRINT
PRINT "Using Screenmove_Middle, it is currently at:"
PRINT glutGet(100), glutGet(101)
PRINT
SLEEP
PRINT "Using _SCREENMOVE _MIDDLE, the screen is placed at:"
_SCREENMOVE _MIDDLE
PRINT glutGet(100), glutGet(101)
PRINT
PRINT "Which, as you can see, doesn't account for our borders or titlebar width and height."
SLEEP

CLS
PRINT "Maybe a better example would be to move the screen to 0,0."
_SCREENMOVE 0, 0
PRINT "Notice how the titlebar and borders are still here?"
PRINT "Our program is actually at: "; glutGet(100), glutGet(101)
SLEEP

ScreenMove 0, 0
PRINT "And notice how our program window now starts at 0,0, like we told it to?"
PRINT "And, as you can see, we're now actually at :"; glutGet(100), glutGet(101)
SLEEP

CLS

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."

SUB ScreenMove_Middle
    $IF BORDERDEC = UNDEFINED THEN
        $LET BORDERDEC = TRUE
        DECLARE LIBRARY
            FUNCTION glutGet& (BYVAL what&)
        END DECLARE
    $END IF
    BorderWidth = glutGet(506)
    TitleBarHeight = glutGet(507)
    _SCREENMOVE (_DESKTOPWIDTH - _WIDTH - BorderWidth) / 2 + 1, (_DESKTOPHEIGHT - _HEIGHT - BorderWidth) / 2 - TitleBarHeight + 1
END SUB

SUB ScreenMove (x, y)
    $IF BORDERDEC = UNDEFINED THEN
        $LET BORDERDEC = TRUE
        DECLARE LIBRARY
        FUNCTION glutGet& (BYVAL what&)
        END DECLARE
    $END IF
    BorderWidth = glutGet(506)
    TitleBarHeight = glutGet(507)
    _SCREENMOVE x - BorderWidth, y - BorderWidth - TitleBarHeight
END SUB


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.  Wink
Reply




Users browsing this thread: 2 Guest(s)