home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / sourcecode / general / line_edit.amos / line_edit.amosSourceCode < prev    next >
Encoding:
AMOS Source Code  |  1993-01-07  |  3.7 KB  |  189 lines

  1. '
  2. ' *** 3D TEXT INPUT
  3. '
  4. ' * ED$ MUST BE GLOBAL OR THIS ROUTINE WILL NOT WORK.
  5. '
  6. Global ED$
  7. '
  8. ' * THESE ARE SOME EXAMPLE EDIT REQUESTERS.
  9. '
  10. ED["Greetings","",10,10]
  11. Print ED$
  12. '
  13. ED["Enter your name","",10,30]
  14. Print ED$
  15. '
  16. ED["Quit (Y/N) ?","N",1,1]
  17. Print ED$
  18. '
  19. ED["Text has already been entered using ED$","This is the text",50,50]
  20. Print ED$
  21. '
  22. ' THE 3D BUTTON ROUTINE IS USED TO DRAW THE TEXT INPUT SCREEN. 
  23. '
  24. Procedure B[X1,Y1,X2,Y2,A$,IN,BC,FC]
  25.    If IN=1
  26.       C1=2
  27.       C2=3
  28.    Else 
  29.       C1=3
  30.       C2=2
  31.    End If 
  32.    Ink BC
  33.    If IN<2
  34.       Bar X1,Y1 To X2,Y2
  35.       Ink C1
  36.       Box X1,Y1 To X2,Y2
  37.       Ink C2
  38.       Polyline X1,Y2 To X2,Y2 To X2,Y1
  39.       If IN=1
  40.          Plot X1+1,Y1+1,1
  41.       End If 
  42.    Else 
  43.       Bar X1+1,Y1+1 To X2-1,Y2-1
  44.    End If 
  45.    If A$<>""
  46.       WID=Text Length(A$)
  47.       X7=(((X2-X1)/2)+X1)-(WID/2)
  48.       Gr Writing 0
  49.       Ink 3,BC
  50.       Text X7+1,((Y2-Y1)/2)+Y1+3,A$
  51.       Text X7-1,((Y2-Y1)/2)+Y1+3,A$
  52.       Text X7,((Y2-Y1)/2)+Y1+4,A$
  53.       Text X7,((Y2-Y1)/2)+Y1+2,A$
  54.       Ink FC,BC
  55.       Text X7,((Y2-Y1)/2)+Y1+3,A$
  56.       Gr Writing 1
  57.    End If 
  58. End Proc
  59. '
  60. Procedure ED[MSG$,ED$,SX,ML]
  61.    '
  62.    ' MSG$  - This is the message that the edit screen tells the user. 
  63.    '
  64.    ' ED$   - This is what the user can put on the edit line before writing. 
  65.    '
  66.    ' SX    - This is the width of the edit line.
  67.    '
  68.    ' ML    - This is the maximum length of the edit line, it can be bigger
  69.    '         than SX, because the edit line scrolls through text as well. 
  70.    '
  71.    '
  72.    ' * WHATEVER HAS BEEN TYPED IN THE EDIT LINE, IT WILL BE STORED IN ED$.
  73.    '
  74.    
  75.    MID=39-Int(SX/2)
  76.    
  77.    Screen Open 7,640,38,8,Hires
  78.    Screen Display 7,,117,,
  79.    Flash Off 
  80.    Cls 0
  81.    Pen 6
  82.    Paper 4
  83.    Palette $AA,$FFF,$DDD,$333,$888,$F00,$FF0,$4A4
  84.    
  85.    XX=MID
  86.    YY=3
  87.    B[40,(YY-3)*8,600,(YY-3)*8+12,MSG$,1,7,6]
  88.    B[(MID*8)-5,(8*(YY-1))+4,(MID*8)+(SX*8)+5,(8*(YY-1))+19,"",1,7,6]
  89.    B[(MID*8)-2,(8*(YY-1))+6,(MID*8)+(SX*8)+2,(8*(YY-1))+17,"",0,4,6]
  90.    
  91.    Curs On 
  92.    Locate XX,YY
  93.    Print String$(" ",SX);
  94.    Ink 0
  95.    Bar 0,0 To 7,7
  96.    XC=0
  97.    MN=0
  98.    PX=0
  99.    L=Len(ED$)
  100.    If L>=SX
  101.       PX=L-SX
  102.    End If 
  103.    Clear Key 
  104.    Do 
  105.       Gosub _DED
  106.       Repeat 
  107.          A$=Inkey$
  108.          
  109.          S=Scancode
  110.          If(CHK=1) and(A$<>"") and(Scancode=0)
  111.             Timer=0
  112.          End If 
  113.          If Mouse Key=1
  114.             X=(X Screen(X Mouse))/8-XX
  115.             If X>=MN and X<=L
  116.                XC=X
  117.                Gosub _DED
  118.                Wait Vbl 
  119.             End If 
  120.          End If 
  121.       Until A$<>""
  122.       F=1
  123.       If A$=Chr$(13)
  124.          Exit 
  125.       End If 
  126.       If A$=Chr$(27)
  127.          ED$="_Esc_"
  128.          Exit 
  129.       End If 
  130.       If S=65 and XC+PX>MN
  131.          ED$=Left$(ED$,XC+PX-1)+Mid$(ED$,PX+XC+1)
  132.          E=1
  133.          L=L-1
  134.          S=79
  135.       End If 
  136.       If S=70 and XC+PX<L
  137.          ED$=Left$(ED$,XC+PX)+Mid$(ED$,PX+XC+2)
  138.          E=1
  139.          L=L-1
  140.          F=0
  141.       End If 
  142.       If S=79 and PX+XC>MN
  143.          F=0
  144.          If XC=0
  145.             PX=PX-1
  146.          Else 
  147.             XC=XC-1
  148.          End If 
  149.       End If 
  150.       If S=78 and PX+XC<L
  151.          F=0
  152.          If XC=SX
  153.             PX=PX+1
  154.          Else 
  155.             XC=XC+1
  156.          End If 
  157.       End If 
  158.       If F
  159.          If A$>=" " and L<ML
  160.             ED$=Left$(ED$,PX+XC)+A$+Mid$(ED$,PX+XC+1)
  161.             L=L+1
  162.             If L>SX
  163.                If XC>=SX
  164.                   PX=PX+1
  165.                Else 
  166.                   XC=XC+1
  167.                End If 
  168.             Else 
  169.                XC=XC+1
  170.             End If 
  171.          End If 
  172.       End If 
  173.    Loop 
  174.    Curs Off 
  175.    Goto _END
  176.    _DED:
  177.    Locate XX,YY
  178.    Print Mid$(ED$,PX+1,SX);
  179.    If E
  180.       If X Curs<XX+SX
  181.          Print " ";
  182.          E=0
  183.       End If 
  184.    End If 
  185.    Locate Min(XX+XC,XX+SX-1),YY
  186.    Return 
  187.    _END:
  188.    Screen Close 7
  189. End Proc