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

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Mastering InForm: Click Timings
« on: September 24, 2018, 05: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

FellippeHeitor

  • Guest
Re: Mastering InForm: Click Timings
« Reply #1 on: September 27, 2018, 11:33:46 am »
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.

FellippeHeitor

  • Guest
Re: Mastering InForm: Click Timings
« Reply #2 on: September 27, 2018, 12: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: QB64: [Select]
  1. ON TIMER(t1, .5) halfSecond
  2. TIMER(t1) ON
  3.  
  4.     _LIMIT 1 'do nothing; only timed sub will run
  5.  
  6. SUB halfSecond
  7.     DIM counter AS _UNSIGNED LONG
  8.     STATIC i, lastRun#
  9.     IF lastRun# > 0 THEN
  10.         PRINT "time since last run: "; INT((TIMER - lastRun#) * 1000); "ms",
  11.     END IF
  12.     lastRun# = TIMER
  13.  
  14.     IF _KEYDOWN(100304) OR _KEYDOWN(100303) THEN
  15.         i = i + 1
  16.         PRINT
  17.         PRINT "Instance of timer: "; i; " - shift pressed..."
  18.         row = CSRLIN
  19.         col = POS(1)
  20.         DO WHILE _KEYDOWN(100304) OR _KEYDOWN(100303)
  21.             counter = counter + 1
  22.             LOCATE row, col
  23.             PRINT counter;
  24.             _LIMIT 30
  25.         LOOP
  26.         i = i - 1
  27.     END IF
  28.  
« Last Edit: September 27, 2018, 12:09:21 pm by FellippeHeitor »