home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_BAS / DNALIB59.ZIP / SCROLBOX.BAS < prev    next >
BASIC Source File  |  1994-02-07  |  14KB  |  495 lines

  1. DECLARE SUB PopWind(Title$,TopRow%,LeftColumn%,BottomRow%,RightColumn%,Attr%,Shadow%,Border%)
  2. DECLARE SUB SaveScreen(ScreenID$,TopRow%,LeftColumn%,BottomRow%,RightColumn%,Shadow%)
  3. DECLARE SUB RestoreScreen(ScreenID$,TopRow%,LeftColumn%)
  4. DECLARE SUB CalcByte(Attr%,LowByte%,HiByte%)
  5. DECLARE SUB Clicked(Rgt%,Lft%,Row%,Col%)
  6. DECLARE SUB HideCursor()
  7. DECLARE SUB ShowCursor()
  8. DECLARE SUB LocateCursor(Row%,Col%)
  9. DECLARE FUNCTION LeftButtonReleased%()
  10. DECLARE FUNCTION RightButtonReleased%()
  11.  
  12. SUB ScrollBox(Choices$(),Rtrn$,Title$,Mouse%,Winsize%,Tag%,Cntr%,Scrolling%,TextColor%,HiAttr%,Attr%,TopRow%,LeftColumn%,Shadow%,Border%) PUBLIC
  13.  
  14. CalcByte Attr%,FGround%,BGround%
  15. CalcByte HiAttr%,HiFG%,HiBG%
  16.  
  17. i% = 0                                      'loop counter
  18. j% = 0                                      'loop compare
  19. Maxlength% = 0                              'string length counter
  20.  
  21. IF Mouse% THEN HideCursor
  22.  
  23. DO
  24.  
  25. INCR i%
  26. INCR j%                                 'first find out how many
  27.                     'strings there are and the
  28. IF LEN (Choices$(i%)) = 0 THEN          'length of the longest one
  29.   DECR i%
  30. ELSEIF LEN (Choices$(i%)) > Maxlength% THEN
  31.   Maxlength% = LEN (Choices$(i%))
  32. END IF
  33.  
  34. LOOP WHILE i% = j%
  35.  
  36. Count% = i%
  37. Rtrn$ = ""
  38. INCR Maxlength%                'add a space
  39. LessThanWinsize% = 0           'initialize to zero
  40.  
  41. IF Cntr% < 2 THEN
  42.   FOR i% = 1 TO Count%
  43.     Choices$(i%) = " " + Choices$(i%)
  44.   NEXT i%
  45. END IF
  46.  
  47. IF Count% <= Winsize% - 1 THEN
  48.   LessThanWinsize% = 1
  49. END IF
  50.  
  51. IF LessThanWinsize% THEN      'we need to transfer Count% to Finish%
  52.   Finish% = Count%
  53.   ScrollBar% = 0
  54. ELSE                          'fixed size scrolling box
  55.   Finish% = Winsize%
  56.   IF Scrolling% THEN
  57.     ScrollBar% = 0
  58.   ELSE
  59.     ScrollBar% = Count% \ (Winsize% - 2)
  60.   END IF
  61. END IF
  62.  
  63. SELECT CASE Cntr%
  64.  
  65.     CASE 1
  66.       Centre% = 1            'centre the window
  67.  
  68.     CASE 2
  69.       CentreText% = 1        'centre text in window
  70.  
  71.     CASE 3
  72.       Centre% = 1            'centre both window and text
  73.       CentreText% = 1
  74.  
  75. END SELECT
  76.  
  77. IF Centre% THEN                            'do they want it centred
  78.   LeftColumn% = 40 - ((Maxlength% + 2) \ 2)
  79.   RightColumn% = LeftColumn% + (Maxlength% + 2)
  80.   TopRow% = (25 - Finish% ) \ 2
  81.   BottomRow% = TopRow% + (Finish% + 1)
  82. ELSE
  83.   RightColumn% = LeftColumn% + (Maxlength% + 2)
  84.   BottomRow% = TopRow% + (Finish% + 1)
  85. END IF
  86.  
  87. SaveScreen ScrollScreen$,TopRow%,LeftColumn%,BottomRow%,RightColumn%,Shadow%
  88. PopWind Title$,TopRow%,LeftColumn%,BottomRow%,RightColumn%,Attr%,Shadow%,Border%
  89.  
  90. IF Mouse% AND Scrolling% THEN
  91.   COLOR FGround%,BGround%
  92.   LOCATE BottomRow%,RightColumn% - 6
  93.   PRINT CHR$(91,30,32,31,93);
  94. END IF
  95.  
  96. IF Mouse% THEN
  97.   Test% = LEN(Title$)
  98.     IF Test% + 12 <= RightColumn% - LeftColumn% THEN
  99.       COLOR FGround%,BGround%
  100.       LOCATE TopRow%,LeftColumn% + 2,0
  101.       PRINT CHR$(91,254,93);
  102.     ELSE
  103.       COLOR FGround%,BGround%
  104.       LOCATE BottomRow%,LeftColumn% + 2,0
  105.       PRINT CHR$(91,254,93);
  106.     END IF
  107. END IF
  108.  
  109. Pointer% = 1                      'initialize all these
  110. Start% = 1
  111. SelectionMade% = 0
  112.  
  113. DO
  114. PrintRoutine:
  115. IF Mouse% THEN HideCursor
  116. Bar% = 0
  117. Row% = TopRow% + 1
  118. Col% = LeftColumn% + 1
  119.  
  120. FOR a% = Start% TO Finish%
  121.   IF Scrolling% < 1 AND a% = Pointer% THEN
  122.     COLOR HiFG%,HiBG%
  123.     LOCATE Row%,Col%,0
  124.     MouseRow% = Row%
  125.     IF CentreText% THEN
  126.       b% = (Maxlength% + 1) - LEN(Choices$(a%))
  127.       c% = b% \ 2
  128.       d% = b% - c%
  129.       PRINT SPACE$(c%) + Choices$(a%) + SPACE$(d%)
  130.     ELSE
  131.       PRINT Choices$(a%) + SPACE$(Maxlength% - LEN(Choices$(a%)) + 1)
  132.     END IF
  133.   ELSE
  134.     COLOR TextColor%,BGround%
  135.     LOCATE Row%,Col%,0
  136.     IF CentreText% THEN
  137.       b% = (Maxlength% + 1) - LEN(Choices$(a%))
  138.       c% = b% \ 2
  139.       d% = b% - c%
  140.       PRINT SPACE$(c%) + Choices$(a%) + SPACE$(d%)
  141.     ELSE
  142.       PRINT Choices$(a%) + SPACE$(Maxlength% - LEN(Choices$(a%)) + 1)
  143.     END IF
  144.   END IF
  145.   IF ScrollBar% THEN
  146.     COLOR FGround%,BGround%
  147.     LOCATE Row%,RightColumn%,0
  148.     IF a% = Start% THEN
  149.       PRINT CHR$(24);
  150.     ELSEIF a% = Finish% THEN
  151.       PRINT CHR$(25);
  152.     ELSE
  153.       IF Bar% =  0 THEN
  154.         c% = Pointer%
  155.         FOR i% = 1 TO ScrollBar%
  156.           b% = c% \ ScrollBar%
  157.           IF a% = b% + Start% THEN
  158.             Bar% = 1
  159.             EXIT FOR
  160.           ELSE
  161.             INCR c%
  162.           END IF
  163.         NEXT i%
  164.     IF Bar%  THEN
  165.       PRINT CHR$(219);
  166.         ELSE
  167.           IF Bar% = 0 AND a% = Finish% - 1 THEN
  168.             PRINT CHR$(219);
  169.           ELSE
  170.             PRINT CHR$(176);
  171.           END IF
  172.     END IF
  173.       ELSE
  174.         PRINT CHR$(176);
  175.       END IF
  176.     END IF
  177.   END IF
  178.   INCR Row%
  179. NEXT a%
  180.  
  181. WHILE NOT INSTAT
  182.   IF Mouse% THEN
  183.     IF SaveMouse% THEN LocateCursor MouseRow%,MCol%
  184.     Rgt% = 0:Lft% = 0:MRow% = 0:MCol% = 0:SaveMouse% = 0
  185.     ShowCursor
  186.     Clicked Rgt%,Lft%,MRow%,MCol%
  187.     IF MRow% >= TopRow% AND MRow% =< BottomRow% AND MCol% >= LeftColumn% AND MCol% =< RightColumn% THEN
  188.       IF MRow% > TopRow% AND MRow% < BottomRow% AND MCol% > LeftColumn% AND MCol% < RightColumn% THEN
  189.         IF Scrolling% = 0 THEN
  190.           HideCursor
  191.           IF RightButtonReleased% THEN
  192.             IF Tag% THEN
  193.               Chose% = 32: GOTO KeyBoardRoutine
  194.             END IF
  195.           ELSEIF LeftButtonReleased% THEN
  196.               Chose% = 13: GOTO KeyBoardRoutine
  197.           END IF
  198.           IF LessThanWinsize% THEN
  199.             Pointer% = MRow% - TopRow%
  200.             GOTO PrintRoutine
  201.           ELSE
  202.             Offset% = MRow% - (TopRow% + 1)
  203.             Pointer% = Start% + Offset%
  204.             GOTO PrintRoutine
  205.           END IF
  206.         END IF
  207.       ELSE
  208.         SELECT CASE MRow%
  209.           CASE TopRow%
  210.             IF MCol% = LeftColumn% + 3 THEN
  211.               IF LeftButtonReleased% THEN  'Cancel Box bottom
  212.                 Chose% = 27: GOTO KeyBoardRoutine
  213.               END IF
  214.             END IF
  215.           CASE TopRow% + 1
  216.             IF MCol% = RightColumn% THEN
  217.               IF LeftButtonReleased% THEN
  218.                 Chose% = -73: GOTO KeyBoardRoutine
  219.               END IF
  220.             END IF
  221.           CASE BottomRow% - 1
  222.             IF MCol% = RightColumn% THEN
  223.               IF LeftButtonReleased% THEN
  224.                 Chose% = -81: GOTO KeyBoardRoutine
  225.               END IF
  226.             END IF
  227.           CASE BottomRow%
  228.             SELECT CASE MCol%
  229.               CASE LeftColumn% + 3
  230.                 IF LeftButtonReleased% THEN  'Cancel Box bottom
  231.                   Chose% = 27: GOTO KeyBoardRoutine
  232.                 END IF
  233.               CASE RightColumn% - 5
  234.                 IF Scrolling% THEN
  235.                   IF Lft% THEN Chose% = -72: GOTO KeyBoardRoutine
  236.                 END IF
  237.               CASE RightColumn% - 3
  238.                 IF Scrolling% THEN
  239.                   IF Lft% THEN Chose% = -80: GOTO KeyBoardRoutine
  240.                 END IF
  241.             END SELECT
  242.         END SELECT
  243.       END IF
  244.     ELSE
  245.       IF LeftButtonReleased% THEN
  246.         Chose% = 27: GOTO KeyBoardRoutine
  247.       END IF
  248.     END IF
  249.   END IF
  250. WEND
  251.  
  252. Ky$ = INKEY$
  253.  
  254. IF LEN(Ky$) = 1 THEN
  255.   Chose% = ASC(Ky$)
  256. ELSE
  257.   Chose% = -ASC(RIGHT$(Ky$,1))
  258. END IF
  259.  
  260. KeyBoardRoutine:
  261.  
  262. IF Mouse% THEN
  263.   IF MRow% > TopRow% AND MRow% < BottomRow% AND_
  264.     MCol% > LeftColumn% AND MCol% < RightColumn% THEN
  265.     SaveMouse% = 1
  266.     LocateCursor 1,1
  267.   END IF
  268. END IF
  269.  
  270. SELECT CASE Chose%
  271.     CASE 13                          'enter key, exit and pass the
  272.       SelectionMade% = 1                'selection to Rtrn$
  273.       IF Tag% > 0 THEN
  274.         IF LEN(Rtrn$) THEN
  275.           Rtrn$ = Rtrn$
  276.         ELSE
  277.           Rtrn$ = "EMPTY"
  278.         END IF
  279.       ELSE
  280.           Rtrn$ = LTRIM$(Choices$(Pointer%))
  281.       END IF
  282.     CASE 27                          'Esc key, just exit routine
  283.       SelectionMade% = 1
  284.       Rtrn$ = ""
  285.     CASE 32
  286.       IF Tag% THEN
  287.         IF INSTR(Choices$(Pointer%),CHR$(Tag%)) THEN
  288.           Rtrn$ = REMOVE$(Rtrn$,Choices$(Pointer%))
  289.           Choices$(Pointer%) = " " + LTRIM$(Choices$(Pointer%),CHR$(Tag%))
  290.         ELSE
  291.           Choices$(Pointer%) = CHR$(Tag%) + LTRIM$(Choices$(Pointer%))
  292.           Rtrn$ = Rtrn$ + Choices$(Pointer%)
  293.         END IF
  294.         IF LessThanWinsize% THEN     'it's not a scrolling box
  295.           IF Pointer% < Finish% THEN
  296.         INCR Pointer%
  297.           ELSE
  298.         Pointer% = Start%
  299.           END IF
  300.         ELSE                              'it's a scrolling box
  301.           IF Pointer% < Finish% THEN
  302.         INCR Pointer%
  303.           ELSEIF Finish% < Count% THEN    'check to see if we have
  304.         INCR Pointer%                 'any more choices waiting
  305.         INCR Start%
  306.         INCR Finish%
  307.           END IF
  308.         END IF
  309.       ELSE
  310.         IF Scrolling% THEN
  311.           SelectionMade% = 1
  312.         END IF
  313.       END IF
  314.     CASE 65 TO 90,97 TO 122
  315.           IF Scrolling% = 0 THEN
  316.         Found% = 0
  317.         Marker% = Pointer%
  318.         IF Pointer% + 1 <= Count% THEN  'search forward from pointer
  319.           FOR i% = Pointer% + 1 TO Count%
  320.         Temp$ = LEFT$(Choices$(i%),2)       'get two characters
  321.         TestKey$ = UCASE$(RIGHT$(Temp$,1))  'char after the space or tag
  322.           IF TestKey$ = UCASE$(CHR$(Chose%)) THEN 'compare first char to key
  323.             Found% = 1
  324.             Pointer% = i%
  325.             IF LessThanWinsize% = 0 THEN
  326.               IF Pointer% + Winsize% <= Count% THEN
  327.             Finish% = Pointer% + (Winsize% - 1)
  328.             Start% = Finish% - (Winsize% - 1)
  329.               ELSE
  330.             Finish% = Count%
  331.             Start% = Finish% - (Winsize% - 1)
  332.               END IF
  333.             END IF
  334.             EXIT FOR
  335.           END IF
  336.           NEXT i%
  337.         END IF
  338.         IF Found% = 0 THEN
  339.           FOR j% = 1 TO Pointer%
  340.         Temp$ = LEFT$(Choices$(j%),2)
  341.         TestKey$ = UCASE$(RIGHT$(Temp$,1))
  342.           IF TestKey$ = UCASE$(CHR$(Chose%)) THEN
  343.             Found% = 1
  344.             Pointer% = j%
  345.             IF Pointer% = Marker% THEN
  346.               BEEP:EXIT FOR
  347.             ELSE
  348.               IF LessThanWinsize% = 0 THEN
  349.             IF Pointer% + Winsize% <= Count% THEN
  350.               Finish% = Pointer% + (Winsize% - 1)
  351.               Start% = Finish% - (Winsize% - 1)
  352.             ELSE
  353.               Finish% = Count%
  354.               Start% = Finish% - (Winsize% - 1)
  355.             END IF
  356.               END IF
  357.             END IF
  358.             EXIT FOR
  359.           END IF
  360.           NEXT j%
  361.         END IF
  362.         IF Found% = 0 THEN
  363.           BEEP
  364.         END IF
  365.       ELSE
  366.         SelectionMade% = 1
  367.       END IF
  368.     CASE -71  'home key
  369.       IF Scrolling% THEN
  370.         IF Start% > 1 THEN
  371.           Start% = 1
  372.           Finish% = (Start% + (Winsize% - 1))
  373.               Pointer% = Start%
  374.         END IF
  375.       ELSE
  376.         Pointer% = Start%
  377.       END IF
  378.     CASE -72  'up arrow
  379.       IF LessThanWinsize% THEN    'it's not a scrolling box
  380.         IF Pointer% > Start% THEN
  381.           DECR Pointer%
  382.         ELSE
  383.           Pointer% = Finish%
  384.         END IF
  385.       ELSE                            'it's a scrolling box
  386.         IF Scrolling% THEN
  387.           IF Start% > 1 THEN
  388.         DECR Start%
  389.         DECR Finish%
  390.                 DECR Pointer%
  391.           END IF
  392.         ELSE
  393.           IF Pointer% > Start% THEN
  394.         DECR Pointer%
  395.           ELSEIF Start% > 1 THEN
  396.         DECR Pointer%
  397.         DECR Start%
  398.         DECR Finish%
  399.           END IF
  400.         END IF
  401.       END IF
  402.     CASE -73  'page up
  403.       IF Start% - (Winsize% - 1) >= 1 THEN    'this block handles the
  404.         DECR Start%,(Winsize% - 1)            'pageing
  405.         DECR Pointer%,(Winsize% - 1)
  406.         DECR Finish%,(Winsize% - 1)
  407.       ELSE
  408.         Pointer% = 1
  409.         Start% = 1
  410.         IF LessThanWinsize% THEN    'if we jump back to Start% make
  411.           Finish% = Count%              'sure we check to see what kind
  412.         ELSE                            'of scroll box and set Finish%
  413.           Finish% = Winsize%            'accordingly
  414.         END IF
  415.       END IF
  416.     CASE -79  'end key
  417.       IF Scrolling% THEN                      'if we are using the
  418.         IF Finish < Count% THEN                   'routine as a scroll
  419.           Start% = (Count% - (Winsize% - 1))      'box, and not a pick
  420.           Finish% = Count%                        'list we handle
  421.               Pointer% = Count%
  422.         END IF
  423.       ELSE
  424.         Pointer% = Finish%
  425.       END IF
  426.     CASE -80  'down arrow
  427.       IF LessThanWinsize% THEN    'it's not a scrolling box
  428.         IF Pointer% < Finish% THEN
  429.           INCR Pointer%
  430.         ELSE
  431.           Pointer% = Start%
  432.         END IF
  433.       ELSE                            'it's a scrolling box
  434.         IF Scrolling% THEN
  435.           IF Finish% < Count% THEN
  436.         INCR Start%
  437.         INCR Finish%
  438.                 INCR Pointer%
  439.           END IF
  440.         ELSE
  441.           IF Pointer% < Finish% THEN
  442.         INCR Pointer%
  443.           ELSEIF Finish% < Count% THEN    'check to see if we have
  444.         INCR Pointer%                 'any more choices waiting
  445.         INCR Start%
  446.         INCR Finish%
  447.           END IF
  448.         END IF
  449.       END IF
  450.     CASE -81  'page down
  451.       IF Finish% + (Winsize% - 1) <= Count% THEN    'this block handles
  452.         INCR Start%,(Winsize% - 1)                  'the pageing
  453.         INCR Finish%,(Winsize% - 1)
  454.         INCR Pointer%,(Winsize% - 1)
  455.       ELSE
  456.         Pointer% = Count%
  457.         Finish% = Count%
  458.         IF LessThanWinsize% THEN       'if we jump to Finish% make
  459.           Start% = 1                       'sure we check to see what
  460.         ELSE                               'kind of scroll box and set
  461.           Start% = Count% - (Winsize% - 1) 'Start% accordingly
  462.         END IF
  463.       END IF
  464.     CASE ELSE
  465.       IF Scrolling% THEN
  466.         SelectionMade% = 1
  467.       ELSE
  468.         BEEP
  469.       END IF
  470. END SELECT
  471.  
  472.  
  473.  
  474. LOOP UNTIL SelectionMade%
  475.  
  476.  
  477.  
  478. FOR i% = 1 TO Count%
  479.   IF INSTR(Choices$(i%),CHR$(Tag%)) THEN
  480.     Choices$(i%) = LTRIM$(Choices$(i%),CHR$(Tag%)) 'remove tag char
  481.   ELSE
  482.     Choices$(i%) = LTRIM$(Choices$(i%))            'remove the space
  483.   END IF
  484. NEXT i%
  485.  
  486. IF Mouse% THEN HideCursor
  487. IF SaveMouse% THEN LocateCursor MouseRow%,MCol%
  488.  
  489. RestoreScreen ScrollScreen$,TopRow%,LeftColumn%
  490.  
  491. END SUB
  492.  
  493.  
  494.  
  495.