NEW FEATURE: DisplayDevice.FlippingEnabled [18483]

Follow

Comments

2 comments

  • Avatar
    David McFarlane

    I have found that FlippingEnabled interferes with the use of MsgBox under E-Prime 2 -- after running any visual display object that uses flipping, MsgBox will not appear on the Display, and holds up further program execution until the MsgBox gets a response, which you must enter blindly.  Apparently MsgBox writes to the video backbuffer, but then E-Prime never gets or produces a signal to flip the backbuffer into the front in order to show the MsgBox.

    Using inline code to temporarily set Display.FlippingEnabled to False and then True again later does not reliably fix this.  Simply setting FlippingEnabled to False for the whole experiment does fix this, but then you lose the advantage of page flipping; furthermore, Windows 10 does not allow running EP2 with FlippingEnabled disabled at all.  Presumably the same problem applies to AskBox, InputBox, and the like, but I have not systematically checked this.

    I did, however, stumble upon a workaround while investigating this.  It turns out that if you precede MsgBox with a Draw of some fresh TextDisplay, the MsgBox will work.  E.g.,

        Dim  DummyText As TextDisplay
        Set DummyText = New TextDisplay
        DummyText.BackStyle = "transparent"  ' important!
        DummyText.Width = 1:  DummyText.Height = 1  ' optional
        DummyText.Draw
        MsgBox "Your message here!"
        Set DummyText = Nothing

    In order to generalize this, you might package it into a Sub or Function in the global User script area, thus:

        Sub MssgBox( mssg As String )
        ' Workaround to present MsgBox when Display.FlippingEnabled is True.
        ' Simply Draw some fresh dummy TextDisplay before runnng the MsgBox.
            Dim  DummyText As TextDisplay
            Set DummyText = New TextDisplay
            DummyText.BackStyle = "transparent"  ' important!
            DummyText.Width = 1:  DummyText.Height = 1  ' optional
            DummyText.Draw
            MsgBox mssg
            Set DummyText = Nothing
        End Sub

    or finally, if you wish to be a little more selective in when E-Prime applies this workaround,

        Sub MssgBox( mssg As String )
        ' Workaround to present MsgBox when Display.FlippingEnabled is True.
        ' Simply Draw some fresh dummy TextDisplay before runnng the MsgBox.
            Dim  DummyText As TextDisplay
            If Display.FlippingEnabled Then
                Set DummyText = New TextDisplay
                DummyText.BackStyle = "transparent"  ' important!
                DummyText.Width = 1:  DummyText.Height = 1  ' optional
                DummyText.Draw
            End If
            MsgBox mssg
            Set DummyText = Nothing
        End Sub

    Then in inline code you could use MssgBox in place of MsgBox.  You might also do something like this for AskBox, InputBox, etc.

    Note that E-Prime 3 offers DisplayDevice.MsgBox and similar methods as replacements to MsgBox, etc., which should fix this problem for users of EP3.  Note, however, that DisplayDevice.MsgBox and its cousins have their own peculiarities.

  • Avatar
    David McFarlane

    Turns out my first workaround falls short in some cases.  So I made a new workaround using a TextDisplay for the message, using Keyboard Device directly for response, and using an offscreen Canvas to preserve & restore the existing Display.  With slight modification you could use this to also return a response.  Here it is:

    Sub MsgDisplay( mssg As String )
    ' MsgBox does not work well with Display.FlippingEnabled.  This workaround
    ' presents a message using a TextDisplay object.  It uses an offscreen Canvas to
    ' preserve and restore the existing Display, uses TextDisplay.Draw so as not to
    ' disturb object timing, and uses direct access to the Keyboard Device to wait
    ' for a response without disturbing any running input mask.
        Const  ExitKey As String = "{ENTER}"
        Dim  kbdCount As Integer
        Dim  tempCnvs As Canvas
        Dim  MsgText As TextDisplay
        ' preserve current Display ...
        Set tempCnvs = Display.CreateCanvas
        tempCnvs.Copy Display.Canvas
        ' set up message ...
        Set MsgText = New TextDisplay
        MsgText.ForeColor = CColor("black"):  MsgText.BackColor = CColor("white")
        MsgText.Width = "40%":  MsgText.Height = "25%"
        MsgText.BorderWidth = 3
        MsgText.FontSize = 14
        MsgText.Text = mssg & "\n\n(press Enter)"
        MsgText.Draw  ' display message
        ' wait for exit key ...
        kbdCount = Keyboard.History.Count
        Do
            Do Until (kbdCount < Keyboard.History.Count)
            Loop
            kbdCount = kbdCount + 1
        Loop Until Keyboard.History(kbdCount).RESP = ExitKey
        ''? Loop Until Keyboard.History(kbdCount).RESP <> ""  ' allow any key
        Display.Canvas.Copy tempCnvs  ' restore Display
        ' cleanup ...
        Set tempCnvs = Nothing
        Set MsgText = Nothing
    End Sub

Please sign in to leave a comment.

Powered by Zendesk