Post Reply 
Controlling program exit
11-14-2020, 04:31 PM
Post: #8
RE: Controlling program exit
I use these types of UI loops quite a bit and have come up with a couple of support routines I use in many different programs. The TESTUI example program is a demo of how these can be used.

Code:
#pragma mode( separator(.,;) integer(h32) )
// support routines
ResetTExit();
GetMK_in();
FlushKeysMouse();
ClearMouse();

// global variables
TExit:=2; // number of minutes before auto exit
TExit_count; // timeout tracker
MK_in,MK_mx,MK_my; // input variable and touch input x and y coordinates

EXPORT TESTUI()
BEGIN
  LOCAL my_str:="",exit_cond:=0;
  TExit_count:=0; // initialize auto exit counter
  REPEAT
    RECT_P(); // clear the screen
    TEXTOUT_P("TESTUI",G0,0,0); // some static text
    TEXTOUT_P(my_str,G0,0,50);
    DRAWMENU("","","","","Cancel","OK"); // basic menu
    GetMK_in(); // get input
    IF TYPE(MK_in)==0 THEN // keyboard input
      IF MK_in==-1 THEN // timeout after 60 seconds
        TExit_count:=TExit_count+1; // increment the exit counter
        my_str:="Exit counter is at " + STRING(TExit_count);
      ELSE
        ResetTExit(); // input was provided so clear the exit counter
        CASE
          IF MK_in==19 THEN // backspace
            MSGBOX("Exit condition met");
            exit_cond:=1;
          END;
          IF MK_in==30 THEN // ENTER
            my_str:="ENTER was pressed";
          END;
          IF MK_in==400 THEN // timed out
            MSGBOX("Timed out");
            exit_cond:=1;
          END;
          DEFAULT
          my_str:="Key " + STRING(MK_in) + " was pressed";
        END;
      END;
    ELSE // touch input
      CASE
        IF MK_my>219 THEN // menu
          CASE
            IF 265>MK_mx>212 THEN // Cancel
              MSGBOX("Exit condition met");
              exit_cond:=1;
            END;
            IF MK_mx>264 THEN // OK
              my_str:="OK menu button was touched";
            END;
            DEFAULT
            my_str:="Menu area left of cancel was touched";
          END;
        END;
        DEFAULT // above menu area
        my_str:="X: " + STRING(B→R(MK_mx)) + "  Y: " + STRING(B→R(MK_my));
      END;
    END;
  UNTIL exit_cond;        
END;

ResetTExit()
BEGIN
  IF TYPE(MK_in)==0 THEN
    IF MK_in<>400 THEN
      TExit_count:=0;
    END;
  END;
END;

GetMK_in()
BEGIN
  IF TExit_count==TExit THEN
    MK_in:=400;
  ELSE
    REPEAT
      IFERR MK_in:=WAIT(-1); THEN
        MK_in:=4;
        FlushKeysMouse();
      END;
    UNTIL TYPE(MK_in)==0 OR IFTE(SIZE(MK_in)>1,MK_in(1)==3,0);
    ClearMouse();
    IF TYPE(MK_in)==6 THEN // list
      MK_mx:=MK_in(2);
      MK_my:=MK_in(3);
      TExit_count:=0;
    END;
  END;
END;

// get all keys and mouse events out of the system
FlushKeysMouse()
BEGIN
  LOCAL j,ksum;
  REPEAT
    ksum:=0;
    FOR j FROM 0 TO 50 DO
      ksum:=ksum+ISKEYDOWN(j);
    END;
  UNTIL ksum==0;
  ClearMouse();
END;

ClearMouse()
BEGIN
  LOCAL m;
  REPEAT
    m:=MOUSE();
  UNTIL SIZE(m(1))==0;
END;
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Controlling program exit - cahlucas - 11-13-2020, 05:03 PM
RE: Controlling program exit - cahlucas - 11-13-2020, 10:16 PM
RE: Controlling program exit - Han - 11-13-2020, 10:44 PM
RE: Controlling program exit - cahlucas - 11-13-2020, 11:08 PM
RE: Controlling program exit - Jacob Wall - 11-14-2020 04:31 PM
RE: Controlling program exit - cahlucas - 11-15-2020, 07:55 PM
RE: Controlling program exit - Jacob Wall - 11-15-2020, 10:58 PM
RE: Controlling program exit - cahlucas - 11-17-2020, 05:31 PM
RE: Controlling program exit - Jacob Wall - 11-17-2020, 09:08 PM
RE: Controlling program exit - cahlucas - 11-18-2020, 05:55 PM
RE: Controlling program exit - Han - 11-17-2020, 10:15 PM
RE: Controlling program exit - Han - 11-18-2020, 09:41 PM
RE: Controlling program exit - cahlucas - 11-20-2020, 01:59 AM
RE: Controlling program exit - Han - 11-21-2020, 04:53 PM
RE: Controlling program exit - cahlucas - 11-21-2020, 11:54 PM
RE: Controlling program exit - Han - 11-30-2020, 01:57 AM
RE: Controlling program exit - cahlucas - 11-30-2020, 10:01 PM



User(s) browsing this thread: 1 Guest(s)