Author Topic: Basic question about window size  (Read 489 times)

Basic question about window size
« on: July 07, 2018, 10:51:32 AM »
Hi there!  I just learned about QB64 yesterday because I'm doing this goofy roguelike project:  https://twitter.com/zapjackson/status/1015367087508746240

I have an embarrassingly basic question -- I've been working in QuickBASIC in DOSBox at 2x scaling, and while the screen size of QB64 is really great for coding, I really need the finished product to run in a larger window.

Is there some trick I'm missing to scale the window up when it's in the default 80x24 text screen, or to make it gracefully user-resizable?  I'd love to release this thing when it's done, but it's too small to be comfortable to play on modern monitors.

Zack

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Basic question about window size
« Reply #1 on: July 07, 2018, 11:59:19 AM »
Hi there and welcome to the forum!

Just add this to the beginning of your program:
Code: [Select]
$RESIZE:STRETCH
You can also replace stretch with SMOOTH for some antialiasing.

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Basic question about window size
« Reply #2 on: July 07, 2018, 12:05:58 PM »
If you want an alternative resolution (any size really), you can:

Code: [Select]
myScreen& = _NEWIMAGE(width, height, mode)
SCREEN myScreen&

With mode being any legacy graphic mode (7, 13...) or even 256 (for 8bit color mode) or 32 for 32bit color mode.

We also have easy _RGB32 mixing available:

Code: [Select]
SCREEN _NEWIMAGE(600, 600, 32)
COLOR _RGB33(255, 0, 0)
PRINT "This is bright red"

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Basic question about window size
« Reply #3 on: July 07, 2018, 12:10:40 PM »
_NEWIMAGE can also create any-sized screen 0, except you don't give width and height in pixels, but in characters.

Re: Basic question about window size
« Reply #4 on: July 07, 2018, 07:00:43 PM »
Thanks so much, this is great!

Re: Basic question about window size
« Reply #5 on: November 15, 2018, 04:34:45 AM »
Hey everyone, hopefully it's okay for me to bump this thread, but my problem pertains to the exact subject being discussed and I can't find an answer anywhere.

I'm making a text mode game and I'm having the same issue ZapJackson is - I'm actually using his source code to help with my project (thank you for sharing it, by the way) and he ended up just using the $RESIZE metacommand, which is fine, but I'd really like to be able to manipulate the size of the window in the program and I'm stuck. I know how to do this in graphical screen modes, and I know how to change the number of text columns with WIDTH, but I'd really like to be able to actually resize the window and I'm at a loss. I'd like the game to start in a larger window so the player doesn't have to resize it every time they start playing, and my eventual goal is to have a menu with different windowed/fullscreen options they can set. Basically I want to have the program perform the action of the player resizing the window, but with a specific resolution and without needing to use the mouse.

In the wiki it says "To automatically run in Qbasic fullscreen, use another Screen mode before using SCREEN 0." I don't want it to start fullscreen, but I thought it might work the same way with a window, so I tried this at the beginning of the program:

Code: [Select]
SCREEN _NEWIMAGE(1280, 800, 32)
SLEEP
SCREEN 0

It launches in a 1280x800 window, but after I press a key and it changes to screen 0 it goes right back to the default size. If anyone has any ideas I'd be very appreciative.

Edit: also, in the wiki entry for _FONT it says: "NOTE: SCREEN 0 can only use one font type and style per viewed SCREEN page. Font size may also affect the window size."

So I assume this means I can change the font size and the window will automatically scale to adapt to it, but I have no idea how to do this. :( I know it would be possible if I load a custom TTF, but is there a way to change the size of the default font 16?
« Last Edit: November 15, 2018, 04:56:35 AM by dukeofthebump »

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Basic question about window size
« Reply #6 on: November 15, 2018, 04:57:46 AM »
SCREEN _NEWIMAGE(80, 25, 0)

The command above will create a screen identical to SCREEN 0: 80 columns by 25 rows in text mode (0). Just change the number of columns/rows you desire.

Welcome to the forum, dukeofthebump.
« Last Edit: November 15, 2018, 04:59:10 AM by FellippeHeitor »

Online luke

  • QB64 Developer
Re: Basic question about window size
« Reply #7 on: November 15, 2018, 05:04:00 AM »
Text and graphics screens are treated very similarly:
Code: [Select]
SCREEN _NEWIMAGE(20, 30, 0)That'll give you a text mode screen that is 20 characters wide and 30 characters high. Things to note:
 - Measurements are in characters, not in pixels.
 - Like graphics commands (but unlike LOCATE) the order of arguments is the X coordinate (columns) first then the Y coordinate (rows).
 - Because character cells aren't squares, _NEWIMAGE(50, 50, 0) doesn't produce a square window. You can use the _FONTHEIGHT and _FONTWIDTH commands to convert pixel measurements to character cell measurements, so
Code: [Select]
SCREEN _NEWIMAGE(800 / _FONTWIDTH, 800 / _FONTHEIGHT, 0)will give you a window that is square (though beware the optical illusion where width & height are perceived differently - check with a ruler if in doubt).

That passage from the wiki sounds misleading and probably needs to be edited.

Re: Basic question about window size
« Reply #8 on: November 15, 2018, 05:22:29 AM »
Thanks so much for the quick response!

The problem is, I want to increase the size of the window but also scale the contents of the window, as if the user had resized it themselves. That is, I don't want a window with more characters, I want the characters to be larger.

It'll probably be easier to get with visual examples:

This is the basic screen mode 0 with no changes

This is that same window, stretched to approximately double-sized by the player

This is what I get when I try to double the screen size with SCREEN _NEWIMAGE(80, 50, 0). The window's bigger, but it's not actually scaling anything.

I'd like the look of example #2 without the player needing to physically resize the window with the mouse.

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Basic question about window size
« Reply #9 on: November 15, 2018, 06:39:05 AM »
This is a rather convoluted solution, but it works. I hope the comments in the code are clear enough (feel free to ask anything if they happen to not be). This approach will also slow down execution quite a bit:

Code: [Select]
'setup screen sizes
originalW = 640
originalH = 400
desiredW = 1280
'desired height is automatically calculated below

'create canvases
smallerScreen = _NEWIMAGE(originalW, originalH, 256)
bigScreen = _NEWIMAGE(desiredW, (originalH * desiredW) / originalW, 32)
SCREEN bigScreen
_DEST smallerScreen

'setup an update timer
updateTimer = _FREETIMER
ON TIMER(updateTimer, .03) updateScreen
TIMER(updateTimer) ON

'-----------------------------------------------------------------
'your actual program starts here
PRINT "hello world"
PRINT "active screen:"; _WIDTH(smallerScreen); "x"; _HEIGHT(smallerScreen)
PRINT "visible screen:"; _WIDTH(bigScreen); "x"; _HEIGHT(bigScreen)

DO
    _LIMIT 30
LOOP UNTIL _KEYHIT

'-----------------------------------------------------------------
'update the screen by stretching the working canvas to fit the visible window area:
SUB updateScreen
    SHARED smallerScreen, bigScreen
    _PUTIMAGE , smallerScreen, bigScreen
    _DISPLAY
END SUB
« Last Edit: November 15, 2018, 06:41:12 AM by FellippeHeitor »

Re: Basic question about window size
« Reply #10 on: November 15, 2018, 07:08:21 AM »
I didn't realize this would be such an involved process, and I really appreciate you taking the time to work this out. I thought I was just missing something obvious, but I guess I was over-estimating the flexibility of text mode. I tried your solution and it works perfectly, and at least so far I'm not noticing much of a speed hit, but that might change as the game gets more complex. It might be better in the long run to just build it from the ground up with graphical mode in mind, and fake text mode with a bitmapped font and limited palette.

Thanks again!

Offline SMcNeill

  • QB64 Developer
Re: Basic question about window size
« Reply #11 on: November 15, 2018, 09:00:57 AM »
I sn't this just a simple case of adding $RESIZE to the top of the code?

Re: Basic question about window size
« Reply #12 on: November 15, 2018, 09:24:10 AM »
I sn't this just a simple case of adding $RESIZE to the top of the code?

That lets the player resize the window with the mouse, but I need to be able to do it within the program itself.

Offline SMcNeill

  • QB64 Developer
Re: Basic question about window size
« Reply #13 on: November 15, 2018, 09:56:12 AM »
I sn't this just a simple case of adding $RESIZE to the top of the code?

That lets the player resize the window with the mouse, but I need to be able to do it within the program itself.

Would a simple routine like the one below work for you?

Code: [Select]
_FONT _LOADFONT("cour.ttf", 16, "monospace")
ScaleScreen 0 'initialize the font settings

PRINT "Hello World"
SLEEP

ScaleScreen 50
SLEEP
ScaleScreen 200
SLEEP
ScaleScreen 150
SLEEP





SUB ScaleScreen (percent AS INTEGER)
    STATIC FontSize(4 TO 100), RanOnce
    IF NOT RanOnce THEN
        RanOnce = -1
        FOR i = 4 TO 100
            _LIMIT 25
            F = _LOADFONT("cour.ttf", i, "monospace")
            FontSize(i) = _FONTWIDTH(F) 'make and keep an array of font sizes so we don't have to keep loading them over and over
            _FREEFONT F
        NEXT
    END IF
    IF percent = 0 THEN EXIT SUB
    h = _FONTWIDTH
    desiredscale = (percent / 100) * h
    FOR i = 5 TO 100
        IF FontSize(i) > desiredscale THEN EXIT FOR
    NEXT
    Ftemp = _FONT
    F = _LOADFONT("cour.ttf", i - 1, "monospace")
    _FONT F
    IF Ftemp <> 16 THEN _FREEFONT Ftemp
END SUB