Author Topic: Resizing Questions  (Read 3844 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Resizing Questions
« on: January 10, 2019, 11:21:26 am »
$RESIZE:ON and its associated code allows a user to resize the program window.  I am in the habit a writing graphics programs which use large screens, sometimes larger than members' monitors.  Fellippe has advised me to use the $RESIZE:ON method.

But when a user changes the program's window size, does everything inside the window scale?  I don't see why things such as _MOUSEX and graphics would scale inside the new window size.  Such parameters are defined as pixel distances from the window Top-Left and not as fractions of the window size.  Have the QB64 magicians been clever enough that all program "distances" scale with the $Resized window?  If not, of course, a mouse click will not necessarily work properly at appropriate places.

Offline Gets

  • Newbie
  • Posts: 28
    • View Profile
Re: Resizing Questions
« Reply #1 on: January 10, 2019, 11:51:25 am »
Quote
Have the QB64 magicians been clever enough that all program "distances" scale with the $Resized window?

Yes.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Resizing Questions
« Reply #2 on: January 14, 2019, 06:34:14 am »
I think that I have managed (at last) to answer my own question, with a little help from Fellippe.

The $RESIZE:ON and its associated code does NOT automatically scale everything inside the window.  The user must adjust all x- and y- distances with written code for scaling to the new _WIDTH and HEIGHT of the window (screen).

The first block of code demonstrates the usage of $RESIZE:ON and its associated _RESIZE code.  This allows the user to change the widow size, but the image and _PRINTSTRING text do no scale with the window size.  They stay at their fixed (x,y) positions and fixed sizes, and this is as we expect: those positions are defined as pixel distances from the top left.  The text figures given are: screen width, screen height, mousex and mousey.  Resize the window and see what happens.  Esc to quit.

Code: QB64: [Select]
  1. '$Resize:ON only - image position & size does not change
  2.  
  3.  
  4. TempImg& = _NEWIMAGE(100, 100, 32)
  5. _DEST TempImg&
  6. COLOR _RGB32(0, 0, 255), _RGB(80, 80, 80)
  7. LINE (0, 0)-(19, 19), , BF
  8. LINE (80, 80)-(99, 99), , BF
  9. Block& = _COPYIMAGE(TempImg&, 33)
  10. _FREEIMAGE TempImg&
  11.  
  12. s& = _NEWIMAGE(300, 300, 32)
  13.  
  14.     _LIMIT 30
  15.         oldimage& = s&
  16.         s& = _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 32)
  17.         SCREEN s&
  18.         _FREEIMAGE oldimage&
  19.     END IF
  20.     _PUTIMAGE (100, 100), Block&
  21.     _PRINTSTRING (200, 100), STR$(_WIDTH)
  22.     _PRINTSTRING (200, 120), STR$(_HEIGHT)
  23.     _PRINTSTRING (200, 140), STR$(_MOUSEX)
  24.     _PRINTSTRING (200, 160), STR$(_MOUSEY)
  25.  
  26.     K$ = INKEY$
  27.     IF K$ <> "" THEN
  28.         IF ASC(K$) = 27 THEN SYSTEM
  29.     END IF
  30.     K$ = ""
  31.  
  32.     _DISPLAY
  33.  

If you want the image to scale with the window, then write code for the x- and y- positions scaled to the window size, as in the next code block (lines 31-38).  Now the image scales with screen size.  The size of the _PRINTSTRING text does not scale, of course.

Code: QB64: [Select]
  1. '$Resize:ON with scaled dimensions - sizes do change
  2.  
  3.  
  4. TempImg& = _NEWIMAGE(100, 100, 32)
  5. _DEST TempImg&
  6. COLOR _RGB32(0, 0, 255), _RGB(80, 80, 80)
  7. LINE (0, 0)-(19, 19), , BF
  8. LINE (80, 80)-(99, 99), , BF
  9. Block& = _COPYIMAGE(TempImg&, 33)
  10. _FREEIMAGE TempImg&
  11.  
  12. s& = _NEWIMAGE(300, 300, 32)
  13.  
  14.     _LIMIT 30
  15.         oldimage& = s&
  16.         s& = _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 32)
  17.         SCREEN s&
  18.         _FREEIMAGE oldimage&
  19.     END IF
  20.  
  21.     'Code to change size of image scaled with window sizes
  22.     X1% = CINT(100 * _WIDTH / 300)
  23.     X2% = CINT(199 * _WIDTH / 300)
  24.     X3% = CINT(200 * _WIDTH / 300)
  25.     Y1% = CINT(100 * _HEIGHT / 300)
  26.     Y2% = CINT(199 * _HEIGHT / 300)
  27.     Y3% = CINT(120 * _HEIGHT / 300)
  28.     Y4% = CINT(140 * _HEIGHT / 300)
  29.     Y5% = CINT(160 * _HEIGHT / 300)
  30.     _PUTIMAGE (X1%, Y1%)-(X2%, Y2%), Block&
  31.     _PRINTSTRING (X3%, Y1%), STR$(_WIDTH)
  32.     _PRINTSTRING (X3%, Y3%), STR$(_HEIGHT)
  33.     _PRINTSTRING (X3%, Y4%), STR$(_MOUSEX)
  34.     _PRINTSTRING (X3%, Y5%), STR$(_MOUSEY)
  35.  
  36.     K$ = INKEY$
  37.     IF K$ <> "" THEN
  38.         IF ASC(K$) = 27 THEN SYSTEM
  39.     END IF
  40.     K$ = ""
  41.  
  42.     _DISPLAY
  43.  


FellippeHeitor

  • Guest
Re: Resizing Questions
« Reply #3 on: January 14, 2019, 08:14:28 am »
Don't forget about $RESIZE:SMOOTH and $RESIZE:STRETCH, which don't require polling _RESIZEWIDTH or _RESIZEHEIGHT or creating a new screen, as they just stretch the screen to the new resized dimensions and automatically adjust mouse clicks.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Resizing Questions
« Reply #4 on: January 14, 2019, 08:36:34 am »
Oh, Pardom me.  I had not understood from the wiki that $RESIZE:SMOOTH and $RESIZE:STRETCH don't require polling, _RESIZEWIDTH, _RESIZEHEIGHT or creating a new screen.

When I tried $RESIZE:SMOOTH and $RESIZE:STRETCH with the first code (and with previous efforts of mine), nothing much seemed to happen.

$RESIZE:SMOOTH and $RESIZE:STRETCH do automatically scale everything with the window size with just the one command.

Perhaps the wiki is not as clear as it might be for us dopeyer members.

FellippeHeitor

  • Guest
Re: Resizing Questions
« Reply #5 on: January 14, 2019, 08:57:02 am »
Code: QB64: [Select]
  1.  
  2. CONST true = -1, false = 0
  3.  
  4.  
  5.     CLS
  6.     COLOR 7, 0
  7.     PRINT "_MOUSEX:"; _MOUSEX; ", _MOUSEY:"; _MOUSEY
  8.  
  9.     COLOR 15
  10.     PRINT "Resize me."
  11.     PRINT
  12.     PRINT "Click exactly here: ";
  13.  
  14.     hovering = false
  15.     IF _MOUSEX >= POS(1) AND _MOUSEX <= POS(1) + 9 AND _MOUSEY >= CSRLIN AND _MOUSEY <= CSRLIN + 4 THEN
  16.         hovering = true
  17.         COLOR 2
  18.     END IF
  19.  
  20.     col = POS(1)
  21.     FOR i = CSRLIN TO CSRLIN + 4
  22.         LOCATE i, col
  23.         PRINT STRING$(10, 219);
  24.     NEXT
  25.  
  26.         IF mouseDown = false THEN
  27.             clicked = false
  28.             mouseDown = true
  29.         END IF
  30.     ELSE
  31.         IF mouseDown THEN
  32.             mouseDown = false
  33.             IF hovering THEN
  34.                 clicked = true
  35.             END IF
  36.         END IF
  37.     END IF
  38.  
  39.     IF clicked THEN COLOR 2: PRINT: PRINT "That's it."
  40.  
  41.     _DISPLAY
  42.     _LIMIT 30

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Resizing Questions
« Reply #6 on: January 14, 2019, 10:27:55 am »
Would I be right in thinking that $RESIZE:STRETCH (or $RESIZE:SMOOTH) can only feature once (at the beginning of the code) in a program?

I've tried a conditional $RESIZE:STRETCH mid code, just before a SCREEN statement, so that you can resize a large screen (should it need it), but not a smaller one (which doesn't need it).  It appeared that you can only have Resize either on or off permanently (this was for a non-Inform project).

Having the $RESIZE:OFF function available implies that you can turn on/off resizing at will.  But this does not seem to be the case, although I must say that I am still in wonder that this auto-scaled resizing has been achieved.

FellippeHeitor

  • Guest
Re: Resizing Questions
« Reply #7 on: January 14, 2019, 10:32:24 am »
Set $RESIZE once (it's a precompiler switch), then use
Code: QB64: [Select]
  1. _RESIZE OFF 'or back ON
To toggle during execution.
« Last Edit: January 14, 2019, 02:22:47 pm by FellippeHeitor »