remstart
   ==============================================================
   =  Title  : Text Entry Excercise 2
   =  Author : Latch
   =  Date   : 04/16/2007
   =  Update :
   =  Version:
   ==============================================================
   Comments    Text entry excercise without input command or
               enhancements. This is one idea for text entry
               Not very efficient - inkey$() is too slow.
 
               Have to create result from pressing delete or
               backspace key.
 
               To manage editing of text, need array to hold
               characters entered, or temp file - maybe both.
   ==============================================================
remend
 
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
   autocam off
   `set display mode 800,600,32
   sync on
   sync rate 0
 
rem =============================================================
rem = MAIN
rem =============================================================
   _main:
   gosub _init
 
   do
      gosub _keyboard_entry
      gosub _cursor
 
      sync
   loop
 
   end
 
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
   _init:
      rem cursor
      create bitmap 1,100,100
      cls rgb(255,255,255)
      get image 1,0,0,1,text height("Q")
      sprite 1,col,row,1
      set sprite 1,1,0
      delete bitmap 1
 
      set current bitmap 0
 
   return
`----------------------------------------------------------------
   _cursor:
      if timer()-cblink >=250
         toggle=1-toggle
         cblink=timer()
         if toggle=1 then show sprite 1 else hide sprite 1
      endif
   return
 
`----------------------------------------------------------------
   _keyboard_entry:
 
      col=col+lw
      if col >= screen width()-40
         col=0-lw
         row=row+lh
      endif
 
      letter$=inkey$()
      lw=text width(letter$)
      lh=text height(letter$)
 
      rem return key
      if asc(letter$)=13
         row=row+lh
         col=0-lw
         sprite 1,col+lw,row,1
         repeat
            sync
         until inkey$()=""
      endif
 
      rem backspace key
      if asc(letter$)=8
         repeat
            sync
         until inkey$()=""
      endif
 
      rem display text
      if asc(letter$) > 31 and asc(letter$) < 128
         sprite 1,col+lw,row,1
         text col,row,letter$
         repeat
            sync
         until inkey$()=""
      endif
   return
rem =============================================================
rem = FUNCTIONS
rem =============================================================
 
rem =============================================================
rem = DATA STATEMENTS
rem =============================================================