Posts: 189
Threads: 22
Joined: Mar 2023
Reputation:
12
11-01-2023, 10:39 PM
(This post was last modified: 11-01-2023, 10:41 PM by NakedApe.)
Howdy. I want a program to run at 1600x900 on desktops and 1280x720 or 1280x800 on laptops. That seems straightforward enough, but this sub - at the big resolution so far - doesn't actually center the program window on the desktop. Why is _SCREENMOVE _MIDDLE opening this window far to the right and off-screen? Also any suggestions for improving this resolution changing sub will be gladly and humbly accepted. Thanks! Ted
' ------------------------------------------------------------------------------
SUB resolution () ' first attempt at resolution changer
' I want 1600x900 on larger screens else 1280x720 or 1280x800 on smaller
DIM ratio AS SINGLE
IF _DESKTOPWIDTH > 1750 THEN SWIDTH = 1600 ELSE SWIDTH = 1280
ratio = _DESKTOPWIDTH / _DESKTOPHEIGHT
IF ratio = 1.6 THEN ' 8:5 aspect ratio - 13" macBook
SHEIGHT = SWIDTH / ratio
ELSE SHEIGHT = SWIDTH / 1.777 ' 16:9 aspect ratio
END IF
CLS
PRINT "Screen Width is"; SWIDTH
PRINT "Screen Height is"; SHEIGHT
PRINT "Aspect Ratio is"; ratio;
_DELAY 3
SCREEN _NEWIMAGE(SWIDTH, SHEIGHT, 32)
IF SWIDTH = 1280 THEN ' laptop mode in fullscreen
_FULLSCREEN , _SMOOTH
IF _FULLSCREEN = 0 THEN ' on fullscreen error
BEEP: CLS
_FULLSCREEN _OFF
PRINT "Fullscreen failed. Going native. Press a key."
SLEEP
_SCREENMOVE _MIDDLE
END IF
END IF
IF SWIDTH = 1600 THEN _SCREENMOVE _MIDDLE ' I put this here after the SCREEN statement, but it still doesn't center the program window
CenterX = SWIDTH / 2 ' define screen center points
CenterY = SHEIGHT / 2 '
END SUB
' ----------------------------------------------------------------------
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
For older versions of QB64, there's a race condition at startup that can cause issues with SCREENMOVE. Add a _DELAY .25 before that _SCREENMOVE statement and see if it changes how things act, or else make certain that you're on the latest version of QB64PE where we've patched the issue a few releases ago.
Posts: 189
Threads: 22
Joined: Mar 2023
Reputation:
12
11-02-2023, 12:58 AM
(This post was last modified: 11-02-2023, 01:01 AM by NakedApe.)
(11-01-2023, 10:46 PM)SMcNeill Wrote: For older versions of QB64, there's a race condition at startup that can cause issues with SCREENMOVE. Add a _DELAY .25 before that _SCREENMOVE statement and see if it changes how things act, or else make certain that you're on the latest version of QB64PE where we've patched the issue a few releases ago. Adding the delay did it. Thanks, Steve! The issue is there with v 3.8.0. Which version corrected the issue?
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
Honestly, I'm not sure. As a developer, I tend to clone and work with the repo directly a lot, so I honestly don't pay that close of attention to the various release numbers. I know it used to be an issue that _DELAY could help overcome. I also know we fixed it a while back. I just don't have a clue which version that patch ended up first appearing in.
My advice? Always try to stay up to date, if possible, and avoid those issues that we've fixed. Sure, we like to add new stuff when we can -- but one of our main goals has always been maintaining and bug fixing the existing code base. Every version you're out of date, you're that many bug fixes behind!
Posts: 734
Threads: 30
Joined: Apr 2022
Reputation:
43
I seem to recall
Code: (Select All)
DO
LOOP UNTIL _SCREENEXISTS
being better than using a delay, so you can verify that the window handle actually is available.
Tread on those who tread on you
Posts: 3,978
Threads: 177
Joined: Apr 2022
Reputation:
220
I don't recall the issue being resolved. I do remember a time they said it was fixed but wasn't. Using 3.8 at moment haven't needed save image yet and Steve's is working OK anyway. They also said they fixed the Titles for Dialogs but no...
To skip delays just use _ScreenMove x, y with hard numbers. That has worked great for me and no fooling around with _Delay or _ScreenExists and _DeskTopWidth and height aren't even needed for a calc.
I usually only need to clear titlebar for access to Windows Close and center a little off left side depending on width of screen I want or need. My toolbar is down right side to save vertical space.
b = b + ...
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
This code:
SCREEN _NEWIMAGE(640, 480, 32)
_SCREENMOVE _MIDDLE
Works correctly in versions 3.9.1, 3.8.0, 3.7.0, 3.6.0, 3.5.0, and 3.4.1 for me. That's as far back as I have installed versions.
Like Bplus, I thought this issue hadn't been resolved fully either, but all of these versions worked correctly so somewhere along the way the issue was corrected.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 660
Threads: 142
Joined: Apr 2022
Reputation:
58
_screenmove _middle fails for me ... sometimes. Not always.
this never seems to fail:
Code: (Select All)
Screen _NewImage(1000, 500, 32)
Print "Hello"
dw = _DesktopWidth
dh = _DesktopHeight
_ScreenMove dw / 2 - _Width / 2, dh / 2 - _Height / 2
Posts: 303
Threads: 10
Joined: Apr 2022
Reputation:
44
I believe the issue is that `Screen` does not resize the window immediately, rather it queues that change to happen on the next window redraw (which happens at 1/60 second intervals). `_ScreenMove _Middle` uses the current width and height of the window when calculating the location, so if call it immediately after `Screen` the window will not have been redrawn yet and will still be the old size, resulting in the issue. I suspect it's not all that hard to fix, we can make `Screen` wait for the window redraw to happen before it finishes.
In the mean time, a very short delay would solve the problem (ensure you call `_Display` if you're not using `_AutoDisplay` though). There are also some commands like `_DesktopWidth` that will wait for a window redraw to happen, you could call one of those a couple times (even if you don't use the result) to ensure the window has been redrawn.
Posts: 4
Threads: 0
Joined: May 2024
Reputation:
0
05-07-2024, 05:06 PM
(This post was last modified: 05-07-2024, 05:20 PM by stoneskipper.)
Does anyone else have this problem re screen resolution/size? QBPE vs QB64 returns only 1/2 resolution.
The following picture shows output for the code: "PRINT _DESKTOPHEIGHT; _DESKTOPWIDTH: INPUT z: END".
QB64 output is correct.
Very frustrating, as I'm trying to move eg. a lot of old screen control macros (heavily reliant upon correct window/mouse etc. locations) over to PE.
It seems to me used to do QB64 do this, too, years ago?? Thoughts ...
|