QB64.org Forum

QB64 Team Software => InForm Discussion => Topic started by: Qwerkey on January 06, 2019, 06:12:58 am

Title: Can a Screen Be Resized by Code?
Post by: Qwerkey on January 06, 2019, 06:12:58 am
After posting my updated Pelmanism Game in the regular Programs section, I realised that I could have made that an InForm game - would give it a more professional look.  But I would need to have three different screen sizes, and in InForm we are resricted to the Screen created by the UiEditor and we can, of course, only have the one screen.  If we could write some code which changed the Screen X- and Y- widths, that would do I think.  A User can do this with $RESIZE and _RESIZEWIDTH etc, but could the screen width/height be set by code commands?  From the Wiki, I think not.  A pity.
Title: Re: Can a Screen Be Resized by Code?
Post by: FellippeHeitor on January 06, 2019, 08:28:25 am
Control(__UI_FormID).Width = (whatever width suits you)
Control(__UI_FormID).Height = (whatever height suits you)

Alternatively you can set a form's CanResize property to true so the user can freely resize the form. That will trigger the __UI_FormResize event from which you can adapt your interface according to the resulting Control(__UI_FormID).Width and Control(__UI_FormID).Height.
Title: Re: Can a Screen Be Resized by Code?
Post by: Qwerkey on January 06, 2019, 10:07:34 am
Oh great!  That's mapped out my next project.
Title: Re: Can a Screen Be Resized by Code?
Post by: Pete on January 06, 2019, 12:45:54 pm
So when is the Inform WIKI going to go live? Don't you have a Clippy equivalent in Brazil? Maybe Senior Quippy?

You're living my dream of customization ability in programs. I've only written a handful of libraries that allow for easy changes like that.

Pete
Title: Re: Can a Screen Be Resized by Code?
Post by: FellippeHeitor on January 06, 2019, 01:02:08 pm
Bam: https://github.com/FellippeHeitor/InForm/wiki

As old as the project itself ;-)
Title: Re: Can a Screen Be Resized by Code?
Post by: FellippeHeitor on January 06, 2019, 01:14:52 pm
You're living my dream of customization ability in programs. I've only written a handful of libraries that allow for easy changes like that.

Pete

It's a project I'm really proud of :-)
Title: Re: Can a Screen Be Resized by Code?
Post by: Qwerkey on January 06, 2019, 01:39:07 pm
As one who has coded some InForm projects, I can attest that the InForm wiki was a great resource.  Fellippe, please do feel proud.

(And I only needed the tiniest amount of Fellippe's additional help to get going - probably not the most correct usage of the superlative of tiny!).
Title: Re: Can a Screen Be Resized by Code?
Post by: Pete on January 06, 2019, 03:10:28 pm
Nice job on the WIKI, too!

We don't need o stinkin' Quippy!

Pete :D
Title: Re: Can a Screen Be Resized by Code?
Post by: Qwerkey on January 07, 2019, 06:40:14 am
Fellippe, I've started on Pelmanism InForm.  I've created a starting Form of a certain size, which will get resized (larger and smaller) during the program execution.  Will there be a problem if the Form size shrinks so that some of the controls are temporarily outside the new Form limits, or shall I have to temporarliy move everything inside the smaller Form?
Title: Re: Can a Screen Be Resized by Code?
Post by: FellippeHeitor on January 07, 2019, 07:06:01 am
If they won't be needed when the form is smaller they can remain hidden, no problem. You may want to set their .Disabled property to True temporarily to prevent them from gaining focus if your user navigates the interface using Tab.
Title: Re: Can a Screen Be Resized by Code?
Post by: Qwerkey on January 09, 2019, 05:36:32 am
Fellippe, I'm most of the way to preparing the InForm version of my Pelmanism program.  However, it is prone to crashing, either at compilation or some way through when running (unpredictable).  When you have some spare time, could you take a look?  I'm now using the 64-bit version of QB64 - could that be a problem?  Thanks, Richard

https://www.dropbox.com/s/p3oeqa30ytdq0qp/Pelmanism%20InForm.zip?dl=1 (https://www.dropbox.com/s/p3oeqa30ytdq0qp/Pelmanism%20InForm.zip?dl=1)
Title: Re: Can a Screen Be Resized by Code?
Post by: FellippeHeitor on January 09, 2019, 11:12:26 am
I'll have a look at your code.

Edit: Just ran it with no issues, compiled with QB64 32bit (btw: flip card times are slooooooooooow). Could you confirm you also get these crashes using the 32bit version of QB64? There are quite a few API calls when InForm is running under Windows, and eventual crashing could be related to that.
Title: Re: Can a Screen Be Resized by Code?
Post by: Qwerkey on January 09, 2019, 12:51:53 pm
Fellippe, thanks for feedback.  Copied my project folder back to QB64 (32-bit) - how long ago that seems! - and initially got Crash Divide by Zero fails every time I clicked on "New Game".  Found out that this was due to _SCREENMOVE statements (I has wanted to reposition the screen for different window sizes).  With the _SCREENMOVE lines commented out, it looks like the 32-bit version runs OK, and I've doubled the speed of the turnovers (I'd made the game deliberately lazy).  The 64-bit version still crashes unreliably at any time.

There are quite a few API calls when InForm is running under Windows

No idea what an API call is: another gaping hole in my knowledge - if Steve stumbles across this post, he'll probably give me another large dose of tuition!  I'll just keep taking those tablets of wisdom.
Title: Re: Can a Screen Be Resized by Code?
Post by: FellippeHeitor on January 09, 2019, 12:57:41 pm
No idea what an API call is: another gaping hole in my knowledge - if Steve stumbles across this post, he'll probably give me another large dose of tuition!  I'll just keep taking those tablets of wisdom.

https://en.wikipedia.org/wiki/Application_programming_interface

When you use a system function Windows makes available via DLLs. The reason why we have http://www.qb64.org/wiki/DECLARE_DYNAMIC_LIBRARY
Title: Re: Can a Screen Be Resized by Code?
Post by: Qwerkey on January 10, 2019, 06:07:15 am
With the _SCREENMOVE lines commented out, it looks like the 32-bit version runs OK

Oh, by the way, is there an InForm equivalent of _SCREENMOVE which I can use in the running code?  Clearly InForm doesn't like _SCREENMOVE after UI_OnLoad.
Title: Re: Can a Screen Be Resized by Code?
Post by: Qwerkey on January 11, 2019, 05:38:18 am
I've just tried adding code to this InForm project to allow the user to change window size for the larger screens.  Code that works in standard QB64 has no effect in InForm

Code: QB64: [Select]
  1.  
  2.     oldimage& = s&
  3.     SCREEN s&
  4.     _FREEIMAGE oldimage&

If the $RESIZE:ON is placed somewhere in the code, either at __UI_OnLoad or in the main loop, and the _RESIZE lines are placed in the main loop there is no resizing allowed: the cursor does not even change to a sizing arrow when at the window boundaries - this indicates that $RESIZE doesn't work in InForm.  Would there be an InForm equivalent to resizing code, or have I just misunderstood again?
Title: Re: Can a Screen Be Resized by Code?
Post by: FellippeHeitor on January 11, 2019, 05:55:52 am
As with most libraries, the idea is that no "low level" manipulation will be done by the user.

What you were trying to do with $resize is automatically handled by InForm internally when you do this:

Alternatively you can set a form's CanResize property to true so the user can freely resize the form. That will trigger the __UI_FormResize event from which you can adapt your interface according to the resulting Control(__UI_FormID).Width and Control(__UI_FormID).Height.

Try creating a dummy empty form in the editor and just set the CanResize property to True as indicated above.

You will see InForm will automatically add $RESIZE to the .frm file and that the _RESIZE event will be automatically caught and generate a call to the __UI_FormResize event which will have filled the width and height properties of the Control(__UI_FormID) with the values of _RESIZEWIDTH and _RESIZEHEIGHT that you will use to reposition your controls accordingly.
Title: Re: Can a Screen Be Resized by Code?
Post by: FellippeHeitor on January 11, 2019, 06:04:08 am
Just for curiosity's sake, here's how InForm deals with resizes in InForm.ui:

Code: QB64: [Select]
  1.     'Adjust the Resize Status of this form based on its CanResize property:
  2.     IF __UI_DesignMode = False THEN
  3.         IF Control(__UI_FormID).CanResize <> __UI_CurrentResizeStatus THEN
  4.             __UI_CurrentResizeStatus = Control(__UI_FormID).CanResize
  5.             IF __UI_CurrentResizeStatus THEN
  6.                 _RESIZE ON
  7.             ELSE
  8.                 _RESIZE OFF
  9.             END IF
  10.         END IF
  11.     END IF
  12.  
  13.     'Resize event:
  14.     '(Triggered either programatically or by directly resizing the form):
  15.     DIM CheckResize AS _BYTE
  16.     CheckResize = _RESIZE
  17.     IF (CheckResize AND Control(__UI_FormID).CanResize) OR (CheckResize AND __UI_DesignMode) OR __UI_CurrentBackColor <> Control(__UI_FormID).BackColor OR Control(__UI_FormID).Width <> _WIDTH(0) OR Control(__UI_FormID).Height <> _HEIGHT(0) THEN
  18.         _DELAY .1
  19.         IF CheckResize THEN
  20.             Control(__UI_FormID).Width = _RESIZEWIDTH
  21.             Control(__UI_FormID).Height = _RESIZEHEIGHT
  22.         END IF
  23.         IF Control(__UI_FormID).Width > 0 AND Control(__UI_FormID).Height > 0 THEN
  24.             __UI_CurrentBackColor = Control(__UI_FormID).BackColor
  25.  
  26.             __UI_HasResized = 2 'Indicate this process is in the middle
  27.  
  28.             OldScreen& = _DISPLAY
  29.             SCREEN _NEWIMAGE(Control(__UI_FormID).Width, Control(__UI_FormID).Height, 32)
  30.             _FREEIMAGE OldScreen&
  31.             'Recreate the main form's canvas
  32.             IF Control(__UI_FormID).Canvas <> 0 THEN _FREEIMAGE Control(__UI_FormID).Canvas
  33.             Control(__UI_FormID).Canvas = _NEWIMAGE(Control(__UI_FormID).Width, Control(__UI_FormID).Height, 32)
  34.             _DEST Control(__UI_FormID).Canvas
  35.             COLOR Control(__UI_FormID).ForeColor, Control(__UI_FormID).BackColor
  36.             CLS
  37.             IF __UI_HasMenuBar = True THEN
  38.                 'Add menubar div to main form's canvas
  39.                 _FONT Control(__UI_FormID).Font
  40.                 __UI_MenuBarOffsetV = falcon_uspacing& + (((_FONT = 8) * -1) * __UI_Font8Offset + ((_FONT = 16) * -1) * __UI_Font16Offset) + 5 + 2
  41.                 LINE (0, __UI_MenuBarOffsetV - 1)-STEP(Control(__UI_FormID).Width - 1, 0), Darken(Control(__UI_FormID).BackColor, 80)
  42.                 LINE (0, __UI_MenuBarOffsetV)-STEP(Control(__UI_FormID).Width - 1, 0), Darken(Control(__UI_FormID).BackColor, 120)
  43.                 __UI_RefreshMenuBar
  44.             ELSE
  45.                 __UI_MenuBarOffsetV = 0
  46.             END IF
  47.             _DEST 0
  48.  
  49.             IF LEN(__UI_CurrentTitle) THEN _TITLE __UI_CurrentTitle
  50.  
  51.             __UI_HasResized = True
  52.             __UI_HasInput = True
  53.         END IF
  54.     END IF
  55.  
Title: Re: Can a Screen Be Resized by Code?
Post by: Qwerkey on January 11, 2019, 08:15:39 am
Fellippe, I hadn't wanted to use the Global CanResize, but wanted to allow form resizing "on the fly", depending upon whether the screen was large (allow) or small (not allow).  When I changed the CanResize property in the UiEditor, it does allow resizing, but then the start form is diplayed with the wrong size, even though lines Control(__UI_FormID).Width = 310 and Control(__UI_FormID).Height = 360 are set at __UI_OnLoad.

So, I can either have the CanResize on from the start, and then the first screen comes out the wrong size, or I can have the screens my desired size but not resizable.

"On the fly" resizing with lines IF Level%% > 0 THEN Control(__UI_FormID).CanResize = True  and then Control(__UI_FormID).CanResize = False doesn't work, because the necessary code lines haven't been created.

I'll decide which of the two options I'll take.
Title: Re: Can a Screen Be Resized by Code?
Post by: FellippeHeitor on January 11, 2019, 08:32:08 am
but then the start form is diplayed with the wrong size, even though lines Control(__UI_FormID).Width = 310 and Control(__UI_FormID).Height = 360 are set at __UI_OnLoad

Set the initial value at the .frm file instead.
Title: Re: Can a Screen Be Resized by Code?
Post by: Qwerkey on January 11, 2019, 11:15:31 am
Fellippe, you may have noticed that I placed a query about resizing in the general section where I asked if $Resize plus _RESIZE (with suitable code), automatically resized everything inside the screen: I couldn't work out how this was being achieved.  I now see from your remarks here that the parameters  _RESIZEWIDTH and _RESIZEHEIGHT have to be used to adjust all _PUTIMAGE coordinate data (for images), adjusting the Mouse x- & y- accordingly and scaling Top, Left, Width and Height parameters for controls, otherwise only the window borders move during resizing.  I didn't believe that somehow the code knew which coordinates to adjust.  With just the CanResize parameter set to True, all that happens is that the window borders can be adjusted, as I would have expected. When I've properly mastered resizing, I'll revisit this.