%%HP: T(3)A(D)F(.);
@
@ HP49G Version S.Lui 9/30/01
@ HP49G TYPE of integer = 28 (was = 0 in HP48 for real number)
@ dspgrbin : Key Stroke Input routine with Grob Display functions
@ By Stanley H.H.Lui 4/2/99
@
@ This routine will input and return a key stroke as pressed by the user.
@ It also display grobs while waiting for a user key press.
@
@ Calling sequence:
@   x y tw rflag xs ys glst  DSPGRBIN - normal operation, displays grobs, and returns user's key press
@   where 
@    xp,yp :  x and y positions of grobs to display, it can be a real number , or lists of real numbers
@            if xp and yp are real numbers, then all grobs are display at (xp,yp).
@    tw:  time in second to wait in between display grobs.  If = 0, no waiting
@    rflag: restore flag - if = 1, save and restore the graphic underneath as each grob is displayed.
@            if = 0, the underneath grob is not saved and restored in between displaying grobs, use this option only
@              if xp and yp are real numbers, AND all grobs have the same size.
@    xs, ys : size of grob for the case when rflag=0, xp,yp are real numbers, and all grobs have the same size.
@    glst: a list of grobs to display.  If a grob value is 0, that grob is skipped.
@
@    [6/11/2000] 
@    Alternative inputs for Disappearing Act [tm] :
@    when tw is negative, then Disappearing Act mode is on
@    When Disappearing Act mode is on, the inputs are
@             td xp yp tw rflag xs ys glst
@             where td : number of MINUTES of inactivity.  When the number of minutes has passed with no
@                            user input, DSPGRBIN will exist with the key pressed = 0.  The caller of this routine
@                            is responsible to interprete the returned key code of 0 appropiately.
@             Note: when this mode is on, DSPRGRBIN will add an additional 14x8 pixel grob to the
@             grob list, the dimensions of the grobs in the grob list should be at least 14x8.
@
@
@    6/01/03 :  If an element in glst is of type program, then that program is executed which must produced a GROB
@    7/26/03 :  If the input for td is negative, the additional 14x8 grob will NOT be displayed.
@    8/17/03:   The input for td is revised to mm.ss   where the integer part specifies the minute(s), and the fractional
@                     part specifies the second(s) to wait.  td can be a negative value (see 7/26/03).
@                     Examples: the following are valid values for td:
@                     3     -    Wait 3 minutes, display extra GROB
@                    -3     -    Wait 3 minutes, do not display extra GROB
@                     3.05 -   Wait 3 minutes and 5 seconds, display extra GROB
@                    -.15  -    Wait 15 seconds, do not display extra GROB
@
@    output:   k - the key press by the user

\<< 



0 0 0 0 0 0 0 {} {} RCLF GROB 10 8 F30012001A005A101F301A101A00F300

         \-> xp yp tw rflag xs ys glst    tc td n k g x y dx dy fs   eg  \<<

         3 CF
         IF tw 0 < THEN
            tw ABS 'tw' STO 3 SF
            'td' STO 
            IF td 0 > THEN
              #14d #8d BLANK {#0d #1d} td \->STR 1 \->GROB GOR {#4d #0d} eg GOR 'eg' STO
              glst
              IF xp TYPE 28 == rflag NOT AND THEN
                 IF xs 14 <  ys 8 < OR THEN 0 ELSE 
                   xs R\->B ys R\->B BLANK  xs 14 - 2 /  R\->B  ys 8 - 2 / R\->B 2 \->LIST eg GOR
                 END
              ELSE
                 xp DUP 1 GET + 'xp' STO   yp DUP 1 GET + 'yp' STO
                 eg
              END + 'glst' STO
            END
            td ABS  DUP IP 60 *  SWAP FP 100 * IP +  'td' STO         
         END

@      if xp, yp are real number, and rflag = 0, then all grobs must be the same size!!!
         IF xp TYPE 28 == rflag NOT AND THEN
           PICT xp R\->B yp R\->B 2 \->LIST
           xp xs  + 1 - R\->B   yp ys + 1 - R\->B 2 \->LIST SUB 'g' STO
         END

         IF xp TYPE 28 == THEN
            xp R\->B 'x' STO yp R\->B 'y' STO
         END
         2 CF
         glst SIZE 'n' STO
         1 CF WHILE 1 FC? REPEAT
            'k' INCR IF n > THEN 1 'k' STO 2 SF END
            IF xp TYPE 5 == THEN
                xp k GET R\->B 'x' STO  yp k GET R\->B 'y' STO
            END
            IF 2 FC? rflag AND THEN
                IF glst k GET 0 == THEN
                   dy 0 + 'dy' STO dx 0 + 'dx' STO
                ELSE
                   IF glst k GET DUP TYPE 8 == THEN EVAL END
                   SIZE dy SWAP + 'dy' STO dx SWAP + 'dx' STO
                END
            END
            IF glst k GET 0 SAME NOT THEN
             IF rflag THEN
                PICT x  y  2 \->LIST
                x dx k GET + #1d -  y  dy k GET + #1d - 2 \->LIST SUB 'g' STO
             END  
             PICT x  y  2 \->LIST IF glst k GET DUP TYPE 8 == THEN EVAL END REPL
             IF KEY THEN
               1 SF
             ELSE
               IF tw THEN
                  tw WAIT
                  IF 3 FS? THEN tw 'tc' STO+ IF tc td > THEN 1 SF 0 END END  
               END
             END
             IF rflag THEN
               PICT x  y  2 \->LIST g REPL
             END
            END
         END

         IF xp TYPE 28 == rflag NOT AND THEN PICT xp R\->B yp R\->B 2 \->LIST g REPL END
         fs STOF                
         \>>
\>>













