Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resize breaking
#1
An example of some code which I'm having issues with, which may be a glitch in QB64, or might be a glitch in poor Steve.  I thought I'd post it here to share so others could test it out and see what's wrong with it.

Code: (Select All)
'Set compiler and global progeam options
'All variables and arrays are dynamic by default
'$Dynamic
'Allow the screen to be resized, but handle operations manually.
$Resize:On
'Allow the use of color names for 32-bit screen mode
$Color:32
_Define A-Z As LONG  'default variable type is long
_Title "Test Glitch"



'Types and global variables
Dim Shared As Long ScreenWidth, ScreenHeight, DisplayScreen, WorkScreen, ReDrawScreen
Dim Shared As Long Font(10), FontSize

'Defaut vaues for global variables
ScreenWidth = 1280
ScreenHeight = 720
DisplayScreen = _NewImage(1024, 720, 32)
WorkScreen = _NewImage(1024, 32000, 32)
ReDrawScreen = 0
Font(0) = _LoadFont("courbd.ttf", 6, "monospace")
Font(1) = _LoadFont("courbd.ttf", 8, "monospace")
Font(2) = _LoadFont("courbd.ttf", 10, "monospace")
Font(3) = _LoadFont("courbd.ttf", 12, "monospace")
Font(4) = _LoadFont("courbd.ttf", 14, "monospace")
Font(5) = _LoadFont("courbd.ttf", 16, "monospace")
Font(6) = _LoadFont("courbd.ttf", 18, "monospace")
Font(7) = _LoadFont("courbd.ttf", 22, "monospace")
Font(8) = _LoadFont("courbd.ttf", 28, "monospace")
Font(9) = _LoadFont("courbd.ttf", 36, "monospace")
Font(10) = _LoadFont("courbd.ttf", 48, "monospace")
FontSize = 8 'starting font size

Screen DisplayScreen
_Delay .2
_Dest WorkScreen
_Font Font(FontSize)
clearFlag = _Resize


Do
    AutoResize
    Cls , 0
    Print _Width(DisplayScreen), _Height(DisplayScreen)

    _PutImage , WorkScreen, DisplayScreen, (0, 0)-Step(_Width(DisplayScreen), _Height(DisplayScreen))
    _Limit 60
    _Display
Loop


Sub AutoResize
    Static OldFontSize

    W = _Width(DisplayScreen): H = _Height(DisplayScreen)
    FW = _FontWidth: FH = _FontHeight


    If _Resize Then
        Do
            _Delay .1
        Loop Until _Resize = 0 'wait for the user to finish their resize event
        RW = _ResizeWidth: RH = _ResizeHeight
        If RW < 640 Then RW = 640
        If RW > _DesktopWidth Then RW = _DesktopWidth
        If RH < 400 Then RH = 400
        If RH > _DesktopHeight Then RH = _DesktopHeight
        GoTo resize_event
    End If

    If OldFontSize <> FontSize Then
        RW = W: RH = H
        GoTo resize_event
    End If
    Exit Sub

    resize_event:
    RW = (RW \ FW) * FW
    RH = (RH \ FH) * FH


    tempscreen = _NewImage(RW, 32000, 32) 'create the newly sized WorkScreen
    _Dest tempscreen 'can't freeimage a screen if it's in use?
    _FreeImage WorkScreen 'free the old WorkScreen
    WorkScreen = tempscreen
    _Dest WorkScreen
    _Font Font(FontSize)


    tempscreen = _NewImage(RW, RH, 32)
    Screen tempscreen
    _FreeImage DisplayScreen
    DisplayScreen = tempscreen


    OldFontSize = FontSize
    ReDrawScreen = -1
    Do
        _Delay .1
    Loop Until _Resize = 0
End Sub


Now, at the moment, this doesn't do much except print the width and height of the screen for us.  Generally, it works as it should, with one exception -- if we drag the size below the minimum bounds set by the program (640x400).

The first time we snap below 640 width, the program does as it should and resizes back up to 640.

If we then grab it and resize it down below 640 width a second time, the screen loses that snap-ability and refuses to resize.  Oddest thing however, is that it still reports itself as being 640 wide, even when it's obviously not.

I've no clue where the glitch is in the matrix on this one!

To add to the oddness, you can then drag the width back to the right a few times, and pass that 640 mark, and after a few attempts, the resize routine will start working just peachy fine again -- as long as you don't go below the 640 limit.

So what's the glitch here guys?  Is QB64 doing something oddish, or is it just me with a broken head?  Tongue
Reply


Messages In This Thread
Resize breaking - by SMcNeill - 08-01-2022, 07:01 PM
RE: Resize breaking - by Pete - 08-01-2022, 07:19 PM
RE: Resize breaking - by SMcNeill - 08-01-2022, 07:21 PM
RE: Resize breaking - by SMcNeill - 08-01-2022, 07:49 PM
RE: Resize breaking - by TempodiBasic - 08-01-2022, 10:07 PM
RE: Resize breaking - by SMcNeill - 08-01-2022, 10:22 PM
RE: Resize breaking - by TempodiBasic - 08-01-2022, 09:00 PM
RE: Resize breaking - by admin - 08-01-2022, 09:13 PM
RE: Resize breaking - by SMcNeill - 08-01-2022, 09:17 PM
RE: Resize breaking - by Kernelpanic - 08-01-2022, 10:14 PM
RE: Resize breaking - by SMcNeill - 08-01-2022, 10:31 PM
RE: Resize breaking - by TempodiBasic - 08-01-2022, 10:59 PM



Users browsing this thread: 14 Guest(s)