Author Topic: Can a Screen Be Resized by Code?  (Read 470 times)

Re: Can a Screen Be Resized by Code?
« Reply #15 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: [Select]
$RESIZE:ON

IF _RESIZE THEN
    oldimage& = s&
    s& = _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 32)
    SCREEN s&
    _FREEIMAGE oldimage&
END IF

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?

Offline FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Can a Screen Be Resized by Code?
« Reply #16 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.

Offline FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Can a Screen Be Resized by Code?
« Reply #17 on: January 11, 2019, 06:04:08 AM »
Just for curiosity's sake, here's how InForm deals with resizes in InForm.ui:

Code: [Select]
    'Adjust the Resize Status of this form based on its CanResize property:
    IF __UI_DesignMode = False THEN
        IF Control(__UI_FormID).CanResize <> __UI_CurrentResizeStatus THEN
            __UI_CurrentResizeStatus = Control(__UI_FormID).CanResize
            IF __UI_CurrentResizeStatus THEN
                _RESIZE ON
            ELSE
                _RESIZE OFF
            END IF
        END IF
    END IF

    'Resize event:
    '(Triggered either programatically or by directly resizing the form):
    DIM CheckResize AS _BYTE
    CheckResize = _RESIZE
    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
        _DELAY .1
        IF CheckResize THEN
            Control(__UI_FormID).Width = _RESIZEWIDTH
            Control(__UI_FormID).Height = _RESIZEHEIGHT
        END IF
        IF Control(__UI_FormID).Width > 0 AND Control(__UI_FormID).Height > 0 THEN
            __UI_CurrentBackColor = Control(__UI_FormID).BackColor

            __UI_HasResized = 2 'Indicate this process is in the middle

            OldScreen& = _DISPLAY
            SCREEN _NEWIMAGE(Control(__UI_FormID).Width, Control(__UI_FormID).Height, 32)
            _FREEIMAGE OldScreen&
            'Recreate the main form's canvas
            IF Control(__UI_FormID).Canvas <> 0 THEN _FREEIMAGE Control(__UI_FormID).Canvas
            Control(__UI_FormID).Canvas = _NEWIMAGE(Control(__UI_FormID).Width, Control(__UI_FormID).Height, 32)
            _DEST Control(__UI_FormID).Canvas
            COLOR Control(__UI_FormID).ForeColor, Control(__UI_FormID).BackColor
            CLS
            IF __UI_HasMenuBar = True THEN
                'Add menubar div to main form's canvas
                _FONT Control(__UI_FormID).Font
                __UI_MenuBarOffsetV = falcon_uspacing& + (((_FONT = 8) * -1) * __UI_Font8Offset + ((_FONT = 16) * -1) * __UI_Font16Offset) + 5 + 2
                LINE (0, __UI_MenuBarOffsetV - 1)-STEP(Control(__UI_FormID).Width - 1, 0), Darken(Control(__UI_FormID).BackColor, 80)
                LINE (0, __UI_MenuBarOffsetV)-STEP(Control(__UI_FormID).Width - 1, 0), Darken(Control(__UI_FormID).BackColor, 120)
                __UI_RefreshMenuBar
            ELSE
                __UI_MenuBarOffsetV = 0
            END IF
            _DEST 0

            IF LEN(__UI_CurrentTitle) THEN _TITLE __UI_CurrentTitle

            __UI_HasResized = True
            __UI_HasInput = True
        END IF
    END IF

Re: Can a Screen Be Resized by Code?
« Reply #18 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.

Offline FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Can a Screen Be Resized by Code?
« Reply #19 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.

Re: Can a Screen Be Resized by Code?
« Reply #20 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.