Author Topic: Resizing a stretchable window in code?  (Read 2066 times)

0 Members and 1 Guest are viewing this topic.

Offline ZapJackson

  • Newbie
  • Posts: 10
Resizing a stretchable window in code?
« on: January 12, 2020, 12:20:27 pm »
Hey there!

I'm making another text mode game for another game jam (https://itch.io/jam/mini-jam-45-dungeons) and I had another question about window/screen sizing.

I know from this forum's help last time how to make the window stretchable, but I was wondering if there was a way to get it to start running at a larger size than the default, but still maintain the same number of text rows and columns.

  [ You are not allowed to view this attachment ]  

Is there a QB64 command that would simulate the user resizing the window?

Thanks!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Resizing a stretchable window in code?
« Reply #1 on: January 12, 2020, 12:41:38 pm »
With _PUTIMAGE you can build an image in one _DEST and then display it in any window or frame of a window you like (fitting/sretching can be automatic but read Wiki on the subject of _PUTIMAGE).
« Last Edit: January 12, 2020, 12:42:51 pm by bplus »

FellippeHeitor

  • Guest
Re: Resizing a stretchable window in code?
« Reply #2 on: January 12, 2020, 10:15:47 pm »
You can do it like this:

Code: QB64: [Select]
  1.  
  2. canvas& = _NEWIMAGE(136, 208, 32) '       how big your original game screen is
  3. displayArea& = _NEWIMAGE(408, 624, 32) '  how big you want it to be at start
  4.  
  5. SCREEN displayArea& '                     create a window with the initial size
  6. _DEST canvas& '                           tell QB64 we'll be drawing on the canvas&
  7.  
  8.  
  9.     CLS , _RGB32(161, 122, 67)
  10.     PRINT "This is going"
  11.     PRINT "to be:"
  12.     PRINT
  13.     PRINT "Dungeons of the"
  14.     PRINT "Spider Queen"
  15.     PRINT
  16.     PRINT RND
  17.  
  18.     _PUTIMAGE , canvas&, displayArea& '   stretch canvas to fill the screen;
  19.     '                                     if you don't need alpha blending,
  20.     '                                     turn it off with _DONTBLEND and things
  21.     '                                     will render faster.
  22.  
  23.     _DISPLAY
  24.     _LIMIT 30
« Last Edit: January 12, 2020, 10:21:08 pm by FellippeHeitor »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Resizing a stretchable window in code?
« Reply #3 on: January 12, 2020, 11:56:05 pm »
Since you’re talking about a simple text game, wouldn’t the easiest solution be to just use a larger font?

Step 1: Choose a monospace font and size you like.
Step 2: Determine the font size to screen size ratio.
Step 3: Scale font up to a suitable size to fit the screen size you desire.

_FONT _LOADFONT(“consolas.ttf”,16,”monospace”) might be 640x400 pixels...  (I dunno what it’s actual size is, as I’m not at a PC currently to  print the values.)
_FONT _LOADFONT(“consolas.ttf”,24,”monospace”) would be 960x600 pixels.
_FONT _LOADFONT(“consolas.ttf”,32,”monospace”) would be 1280x800 pixels.

Scale the font on a text screen, scale the screen size.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline ZapJackson

  • Newbie
  • Posts: 10
Re: Resizing a stretchable window in code?
« Reply #4 on: January 20, 2020, 03:47:52 pm »
Since you’re talking about a simple text game, wouldn’t the easiest solution be to just use a larger font?


Yeah, this is an option I considered, I just like the look of the built-in 40-column font.  I guess somebody has probably made pixel fonts that are just that font but at different multiples...

Offline EricE

  • Forum Regular
  • Posts: 114
Re: Resizing a stretchable window in code?
« Reply #5 on: February 10, 2020, 09:02:40 am »
I have discovered something about QB64 that might be useful here.

If one includes either $RESIZE STRETCH, or $RESIZE SMOOTH at the beginning of one's program, and then loads an image in a screen created by this line of code:
SCREEN _NEWIMAGE(800, 600, 256)
Then later when the Screen 0 window is created, its screen size in pixels will be determined by the pixel size of the image loaded earlier!
To get a larger Screen 0 text window, load a larger image, to get a smaller Screen 0 text window, load a smaller image file.

Perhaps someone could explain why, if the $RESIZE meta command is used, then the SCREEN 0 window size depends upon the image size loaded in a previous graphics screen?

FellippeHeitor

  • Guest
Re: Resizing a stretchable window in code?
« Reply #6 on: February 10, 2020, 09:33:11 am »
I have discovered something about QB64 that might be useful here.

If one includes either $RESIZE STRETCH, or $RESIZE SMOOTH at the beginning of one's program, and then loads an image in a screen created by this line of code:
SCREEN _NEWIMAGE(800, 600, 256)
Then later when the Screen 0 window is created, its screen size in pixels will be determined by the pixel size of the image loaded earlier!
To get a larger Screen 0 text window, load a larger image, to get a smaller Screen 0 text window, load a smaller image file.

Perhaps someone could explain why, if the $RESIZE meta command is used, then the SCREEN 0 window size depends upon the image size loaded in a previous graphics screen?

That's a very interesting discovery, EricE! It's hacky, sure, but surely enough does the job! Thanks for sharing.

Code: QB64: [Select]

PS: As expected, if you go to SCREEN 13 or any other legacy screen mode, it'll also retain the initial screen size set by SCREEN _NEWIMAGE.
« Last Edit: February 10, 2020, 09:35:18 am by FellippeHeitor »

FellippeHeitor

  • Guest
Re: Resizing a stretchable window in code?
« Reply #7 on: February 10, 2020, 09:42:56 am »
Interestingly it will revert back to original size if the _NEWIMAGE dimensions are in the same ratio as original SCREEN 0.

Offline EricE

  • Forum Regular
  • Posts: 114
Re: Resizing a stretchable window in code?
« Reply #8 on: February 10, 2020, 10:35:54 am »
Hi Fellippe,
Here is the small test program I wrote to demonstrate the screen size depending upon image size.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 256)
  2.  
  3. ' Try loading images of different sizes
  4. i& = _LOADIMAGE("IMAGE.JPG", 32)
  5.  
  6. _DELAY (1)
  7.  
  8. ' Print to Screen 0 window
  9. ' Size of Screen 0 window depends upon size of IMAGE.JPG loaded earlier
  10. PRINT "Hello World"

« Last Edit: February 10, 2020, 12:07:29 pm by EricE »