Author Topic: Mastering InForm: Click Timings  (Read 170 times)

Mastering InForm: Click Timings
« on: September 24, 2018, 06:04:52 AM »
I have a project where I have the __UI_BeforeUpdateDisplay loop, the __UI_Click loop and a Calculations loop (in its own subroutine).

Inside the __UI_BeforeUpdateDisplay loop, there is a Condition A which may become True, and if so it sets a Flag to inform the  Calculations loop.

There is a Button which when clicked will reset the Flag and will alter things in the __UI_BeforeUpdateDisplay loop so that  Condition A will be False.

If I were not doing this in InForm, my Mouse Polling would be at the start of the equivalent of the __UI_BeforeUpdateDisplay loop so that timings always ensure the Flag is reset at the correct moment and that the Condition A is False.

However, suppose in the Inform situation, the Mouse is clicked part way through the __UI_BeforeUpdateDisplay loop.  The Flag would be reset, but at the end of that __UI_BeforeUpdateDisplay loop cycle the Condition A has still been True and therefore sets the Flag again.

I hope that you've get all that!  How does InForm Mouse Polling ensure that Click events do not occur 'part way through' the __UI_BeforeUpdateDisplay loop?  I suspect that this is another of my dumb questions.  In the actual program, the Reset Click always works properly.

Richard

Offline FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Mastering InForm: Click Timings
« Reply #1 on: September 27, 2018, 12:33:46 PM »
Quote
How does InForm Mouse Polling ensure that Click events do not occur 'part way through' the __UI_BeforeUpdateDisplay loop?

Input processing is done by a TIMER while drawing (which triggers __UI_BeforeUpdateDisplay) is done by another TIMER. A TIMER procedure won't execute over itself.

Offline FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Mastering InForm: Click Timings
« Reply #2 on: September 27, 2018, 01:07:34 PM »
Just as proof of concept, try the code below. It'll run SUB halfSecond every 500ms (times between runs shown vary slighlty). Whenever you feel like it, hold down shift. That'll enter a LOOP in the halfSecond sub that'll be run for as long as the key is held down. No other instance of the SUB will be run while the counter is going up and next time the SUB is run you'll see the time elapsed since you let go of shift:

Code: [Select]
t1 = _FREETIMER
ON TIMER(t1, .5) halfSecond
TIMER(t1) ON

DO
    _LIMIT 1 'do nothing; only timed sub will run
LOOP

SUB halfSecond
    DIM counter AS _UNSIGNED LONG
    STATIC i, lastRun#
    IF lastRun# > 0 THEN
        PRINT "time since last run: "; INT((TIMER - lastRun#) * 1000); "ms",
    END IF
    lastRun# = TIMER

    IF _KEYDOWN(100304) OR _KEYDOWN(100303) THEN
        i = i + 1
        PRINT
        PRINT "Instance of timer: "; i; " - shift pressed..."
        row = CSRLIN
        col = POS(1)
        DO WHILE _KEYDOWN(100304) OR _KEYDOWN(100303)
            counter = counter + 1
            LOCATE row, col
            PRINT counter;
            _LIMIT 30
        LOOP
        i = i - 1
    END IF
END SUB
« Last Edit: September 27, 2018, 01:09:21 PM by FellippeHeitor »