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

0 Members and 1 Guest are viewing this topic.

Offline ZapJackson

  • Newbie
  • Posts: 10
    • View Profile
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

FellippeHeitor

  • Guest
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: QB64: [Select]

You can also replace stretch with SMOOTH for some antialiasing.

FellippeHeitor

  • Guest
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: QB64: [Select]
  1. myScreen& = _NEWIMAGE(width, height, mode)
  2. 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: QB64: [Select]
  1. SCREEN _NEWIMAGE(600, 600, 32)
  2. COLOR _RGB33(255, 0, 0)
  3. PRINT "This is bright red"
  4.  

FellippeHeitor

  • Guest
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.

Offline ZapJackson

  • Newbie
  • Posts: 10
    • View Profile
Re: Basic question about window size
« Reply #4 on: July 07, 2018, 07:00:43 pm »
Thanks so much, this is great!

Offline dukeofthebump

  • Newbie
  • Posts: 4
    • View Profile
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: QB64: [Select]
  1. SCREEN _NEWIMAGE(1280, 800, 32)
  2.  

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 »

FellippeHeitor

  • Guest
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 »

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
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: QB64: [Select]
  1. 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: QB64: [Select]
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.

Offline dukeofthebump

  • Newbie
  • Posts: 4
    • View Profile
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.

FellippeHeitor

  • Guest
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: QB64: [Select]
  1. 'setup screen sizes
  2. originalW = 640
  3. originalH = 400
  4. desiredW = 1280
  5. 'desired height is automatically calculated below
  6.  
  7. 'create canvases
  8. smallerScreen = _NEWIMAGE(originalW, originalH, 256)
  9. bigScreen = _NEWIMAGE(desiredW, (originalH * desiredW) / originalW, 32)
  10. SCREEN bigScreen
  11. _DEST smallerScreen
  12.  
  13. 'setup an update timer
  14. updateTimer = _FREETIMER
  15. ON TIMER(updateTimer, .03) updateScreen
  16. TIMER(updateTimer) ON
  17.  
  18. '-----------------------------------------------------------------
  19. 'your actual program starts here
  20. PRINT "hello world"
  21. PRINT "active screen:"; _WIDTH(smallerScreen); "x"; _HEIGHT(smallerScreen)
  22. PRINT "visible screen:"; _WIDTH(bigScreen); "x"; _HEIGHT(bigScreen)
  23.  
  24.     _LIMIT 30
  25.  
  26. '-----------------------------------------------------------------
  27. 'update the screen by stretching the working canvas to fit the visible window area:
  28. SUB updateScreen
  29.     SHARED smallerScreen, bigScreen
  30.     _PUTIMAGE , smallerScreen, bigScreen
  31.     _DISPLAY
« Last Edit: November 15, 2018, 06:41:12 am by FellippeHeitor »

Offline dukeofthebump

  • Newbie
  • Posts: 4
    • View Profile
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
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
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?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline dukeofthebump

  • Newbie
  • Posts: 4
    • View Profile
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
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
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: QB64: [Select]
  1. _FONT _LOADFONT("cour.ttf", 16, "monospace")
  2. ScaleScreen 0 'initialize the font settings
  3.  
  4. PRINT "Hello World"
  5.  
  6. ScaleScreen 50
  7. ScaleScreen 200
  8. ScaleScreen 150
  9.  
  10.  
  11.  
  12.  
  13.  
  14. SUB ScaleScreen (percent AS INTEGER)
  15.     STATIC FontSize(4 TO 100), RanOnce
  16.     IF NOT RanOnce THEN
  17.         RanOnce = -1
  18.         FOR i = 4 TO 100
  19.             _LIMIT 25
  20.             F = _LOADFONT("cour.ttf", i, "monospace")
  21.             FontSize(i) = _FONTWIDTH(F) 'make and keep an array of font sizes so we don't have to keep loading them over and over
  22.             _FREEFONT F
  23.         NEXT
  24.     END IF
  25.     IF percent = 0 THEN EXIT SUB
  26.     h = _FONTWIDTH
  27.     desiredscale = (percent / 100) * h
  28.     FOR i = 5 TO 100
  29.         IF FontSize(i) > desiredscale THEN EXIT FOR
  30.     NEXT
  31.     Ftemp = _FONT
  32.     F = _LOADFONT("cour.ttf", i - 1, "monospace")
  33.     _FONT F
  34.     IF Ftemp <> 16 THEN _FREEFONT Ftemp
  35.  
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!