home *** CD-ROM | disk | FTP | other *** search
- ' ──────────────────────────────────────────────────────────────────────────
- '
- ' Q D E M O _ D . B A S
- '
- ' This file is a subcomponent of the QBSCR Screen Routines Demonstration
- ' program QDEMO. It is not meant to run as a standalone program. Use only
- ' in conjunction with the QDEMO.BAS program. See QBSCR documentation or
- ' QDEMO.BAS for more information.
- '
- ' ──────────────────────────────────────────────────────────────────────────
-
- '$INCLUDE: 'qbscr.inc'
- '$INCLUDE: 'mouse.bi'
-
- CONST NEEDMOUSE4GETEVENT = -4
- CONST VIEWLISTMISSING = -11
- CONST SELECTMISSING = -13
-
- COMMON SHARED kolor%
- COMMON SHARED mouseExists%
-
- DECLARE SUB SelectListDemo ()
- DECLARE SUB ViewListDemo ()
- DECLARE SUB InfoBox (messageNum%)
-
- SUB EditDemo
-
- ' ────────────────────────────────────────────────────────────────────────
- ' This demo will utilize the EditString function to accept a user's name.
- ' It will then use the name to fill in the red-shirt in an excerpt from
- ' a Start Trek episode.
- ' ────────────────────────────────────────────────────────────────────────
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Establish a frameType and buttonStyle based on kolor%.
- ' ────────────────────────────────────────────────────────────────────────
- IF kolor% THEN
- ft1% = 6
- ft2% = 7
- bs% = STYLE3D
- ELSE
- ft1% = 0
- ft2% = 0
- bs% = STYLE2D
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' If the mouse is around, turn it off whilst we display.
- ' ────────────────────────────────────────────────────────────────────────
- IF mouseExists% THEN
- MouseHide
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Add windows and buttons to the display.
- ' ────────────────────────────────────────────────────────────────────────
- MakeWindow 6, 6, 23, 75, 0, 7, 0, ft1%, -1, 0, ""
- MakeWindow 20, 30, 22, 51, 0, 7, 0, ft2%, -1, 0, ""
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Add text to the window.
- ' ────────────────────────────────────────────────────────────────────────
- Center "This demo will illustrate the editing capabilities of the", 8
- Center "QBSCR EditString routine. Enter your LAST NAME in the field", 9
- Center "below, using the following editing capabilities (ESC quits):", 10
- Center "Edit Function... ...Use this key(s)", 12
- Center "────────────────────────────────────────────────", 13
- Center "Cursor Left, Cursor Right . . . . . . . . . " + CHR$(27) + " " + CHR$(26), 14
- Center "Delete character left of cursor . . . Backspace", 15
- Center "Delete character at cursor . . . . . . . . Del", 16
- Center "Clear line . . . . . . . . . . . . . . Ctrl + Y", 17
- Center "Finished editing . . . . . . . . . . . . Enter", 18
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Get a name from the user by using the EditString function.
- ' ────────────────────────────────────────────────────────────────────────
- userName$ = SPACE$(18)
- EditString userName$, 32, 21, 0, 7
-
- ' ────────────────────────────────────────────────────────────────────────
- ' If the user hit the ESC key, then get out now.
- ' ────────────────────────────────────────────────────────────────────────
- IF LTRIM$(RTRIM$(userName$)) = "" THEN
- EXIT SUB
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Since the user did not hit the ESC key, we will assume that they en-
- ' tered a valid name of some sort. Build a sample Star Trek excerpt
- ' using the name entered.
- ' ────────────────────────────────────────────────────────────────────────
- RANDOMIZE TIMER
- rnum% = INT(RND(1) * 6) + 1
- SELECT CASE rnum%
- CASE 1
- absurdOccupation$ = "rocket scientist"
- CASE 2
- absurdOccupation$ = "programmer"
- CASE 3
- absurdOccupation$ = "TV evangelist"
- CASE 4
- absurdOccupation$ = "Vulcan"
- CASE 5
- absurdOccupation$ = "Klingon Gartha Lizard"
- CASE 6
- absurdOccupation$ = "used car salesman"
- END SELECT
-
- MakeWindow 3, 6, 23, 75, 0, 7, 0, ft1%, -1, 0, ""
- MakeWindow 4, 21, 6, 60, 0, 7, 0, ft2%, -1, 0, ""
- DrawButton SINGLEBORDER, 8, 20, 17, 22, 0, 7, "OK", bs%
- Center "Your Own Star Trek Episode", 5
- LOCATE 8, 9, 0: PRINT " As Ensign "; RTRIM$(userName$); " stepped on the loose rock, it";
- LOCATE 9, 9, 0: PRINT "exploded, sending the red-shirt flying throught the air, land-";
- LOCATE 10, 9, 0: PRINT "ing with a thud at Kirk's feet.";
- LOCATE 11, 9, 0: PRINT " McCoy leaned down and scanned the Ensign briefly."
- LOCATE 12, 9, 0: PRINT " "; CHR$(34); "He's dead, Jim."; CHR$(34);
- LOCATE 13, 9, 0: PRINT " "; CHR$(34); "He was the third son of my eighth girlfriend. Can't you"
- LOCATE 14, 9, 0: PRINT "do anything for him Bones?"; CHR$(34);
- LOCATE 15, 9, 0: PRINT " "; CHR$(34); "I'm a doctor, not a "; absurdOccupation$; ", Jim!";
- LOCATE 16, 9, 0: PRINT "I can't bring them back from the dead."; CHR$(34);
- LOCATE 17, 9, 0: PRINT " "; CHR$(34); "My God, Bones,"; CHR$(34); " said Kirk, his jaw set firmly. "; CHR$(34); "What is";
- LOCATE 18, 9, 0: PRINT "space travel coming to?"; CHR$(34);
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Sit in a loop waiting for the user to say "I'm done."
- ' ────────────────────────────────────────────────────────────────────────
- done% = FALSE
- WHILE done% = FALSE
-
- ' ──────────────────────────────────────────────────────────────────────
- ' If mouse is around, turn him on.
- ' ──────────────────────────────────────────────────────────────────────
- IF mouseExists% THEN
- MouseShow
- END IF
-
- ' ──────────────────────────────────────────────────────────────────────
- ' Use the QBSCR GetEvent% function to get mouse events and keyboard
- ' keypresses.
- ' ──────────────────────────────────────────────────────────────────────
- result% = getEvent(mouseExists%, kc%, mx%, my%)
-
- ' ──────────────────────────────────────────────────────────────────────
- ' Decide what to do, if anything, based on the event returned by the
- ' getEvent routine.
- ' ──────────────────────────────────────────────────────────────────────
- SELECT CASE result%
- CASE EMpressedLeft ' Mouse left button pressed.
- IF (mx% >= 8) AND (mx% <= 17) AND (my% >= 20) AND (my% <= 22) THEN
- IF kolor% THEN
- PressButton SINGLEBORDER, 8, 20, 17, 22, 0, 7, "OK", bs%
- END IF
- done% = TRUE
- END IF
- CASE EKpressed ' Keyboard key pressed.
- IF kc% = ASC("O") OR kc% = ASC("o") OR kc% = 27 OR kc% = 13 THEN
- done% = TRUE
- END IF
- CASE ELSE
- END SELECT
- WEND
-
- END SUB
-
- SUB EventsDemo
-
- ' ────────────────────────────────────────────────────────────────────────
- ' This demo will illustrate the use of the GetEvent% function and the
- ' kinds of things you can do with it. After displaying some text and
- ' two buttons, if the user chooses to proceed, a mock control panel will
- ' be displayed depiciting nonsense controls and buttons. Moving the mouse
- ' around will cause different things to happen. If the user does not
- ' have a mouse, then this demo will display a message and exit.
- ' ────────────────────────────────────────────────────────────────────────
-
- ' ────────────────────────────────────────────────────────────────────────
- ' If there is no mouse here, then display a simple message and exit.
- ' ────────────────────────────────────────────────────────────────────────
- IF mouseExists% = FALSE THEN
- InfoBox NEEDMOUSE4GETEVENT
- EXIT SUB
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Set color-dependent data.
- ' ────────────────────────────────────────────────────────────────────────
- IF kolor% THEN
- ft1% = 6
- ft2% = 7
- bs% = STYLE3D
- ELSE
- ft1% = 0
- ft2% = 0
- bs% = STYLE2D
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Hide the mouse while we draw on the screen.
- ' ────────────────────────────────────────────────────────────────────────
- MouseHide
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Display the initial window, text and buttons.
- ' ────────────────────────────────────────────────────────────────────────
- MakeWindow 3, 7, 23, 74, 0, 7, 0, ft1%, -1, 0, ""
- MakeWindow 4, 21, 6, 60, 0, 7, 0, ft2%, -1, 0, ""
- DrawButton SINGLEBORDER, 9, 20, 18, 22, 0, 7, "Events", bs%
- DrawButton SINGLEBORDER, 20, 20, 29, 22, 0, 7, "Cancel", bs%
- COLOR 0, 7
- Center "QBSCR GetEvent Demo", 5
-
- LOCATE 8, 10, 0: PRINT "The QBSCR Screen Routines needed a new capability when mouse";
- LOCATE 9, 10, 0: PRINT "support was added. QuickBASIC provided a way to obtain key-";
- LOCATE 10, 10, 0: PRINT "board events via the INPUT$() and INKEY$ functions, but there";
- LOCATE 11, 10, 0: PRINT "way to conventiently collect mouse as well as keyboard events.";
-
- LOCATE 13, 10, 0: PRINT "Enter the GetEvent% function. With one call, you will get the";
- LOCATE 14, 10, 0: PRINT "first keyborad OR mouse event that occurs, including mouse";
- LOCATE 15, 10, 0: PRINT "button presses, releases, mouse movement and position, and";
- LOCATE 16, 10, 0: PRINT "all keyboard keys, including extended function and arrow keys.";
-
- LOCATE 18, 10, 0: PRINT "Select Events to play, or Cancel to retutn to the menu.";
-
- ' ────────────────────────────────────────────────────────────────────────
- ' If the mouse is around, turn him (it) back on.
- ' ────────────────────────────────────────────────────────────────────────
- MouseShow
- done% = FALSE
- doEvents% = FALSE
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Sit in a loop until the user does something right. When they do, then
- ' we move on.
- ' ────────────────────────────────────────────────────────────────────────
- WHILE done% = FALSE
-
- result% = getEvent%(mouseExists%, kc%, mx%, my%)
-
- SELECT CASE result%
- CASE EMpressedLeft
- IF (mx% >= 9) AND (mx% <= 18) AND (my% >= 20) AND (my% <= 22) THEN
- PressButton SINGLEBORDER, 9, 20, 18, 22, 0, 7, "Events", bs%
- done% = TRUE
- doEvents% = TRUE
- END IF
- IF (mx% >= 20) AND (mx% <= 29) AND (my% >= 20) AND (my% <= 22) THEN
- PressButton SINGLEBORDER, 20, 20, 29, 22, 0, 7, "Cancel", bs%
- done% = TRUE
- END IF
- CASE EMpressedRight
- done% = TRUE
- CASE EKpressed
- IF (kc% = ASC("E")) OR (kc% = ASC("e")) THEN
- done% = TRUE
- doEvents% = TRUE
- END IF
- IF (kc% = ASC("C")) OR (kc% = ASC("c")) OR (kc% = 27) THEN
- done% = TRUE
- END IF
- CASE ELSE
- END SELECT
-
- WEND
-
- ' ────────────────────────────────────────────────────────────────────────
- ' If the user hit cancel, then get outta here.
- ' ────────────────────────────────────────────────────────────────────────
- IF doEvents% = FALSE THEN
- EXIT SUB
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Now we do the fun stuff, the demo part. First draw the interface.
- ' ────────────────────────────────────────────────────────────────────────
- MouseHide
- MakeWindow 3, 7, 23, 74, 0, 7, 0, ft1%, -1, 0, ""
- MakeWindow 4, 21, 6, 60, 0, 7, 0, ft2%, -1, 0, ""
- MakeWindow 9, 10, 11, 71, 0, 7, 0, ft2%, -1, 0, ""
- MakeWindow 14, 10, 19, 71, 0, 7, 0, ft2%, -1, 0, ""
- Center "Demonstrating the usage of GetEvent", 5
- LOCATE 8, 11, 0: PRINT "Last Event";
- LOCATE 13, 11, 0: PRINT "Comments";
- LOCATE 10, 12, 0: PRINT "Waiting for first event";
- DrawButton SINGLEBORDER, 10, 20, 19, 22, 0, 7, "Done", bs%
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Now sit in a loop waiting for events. As they occur, display event
- ' information and humorous or informative commentary. Since we're doing
- ' alot here, things may look a little complicated. They're not, really,
- ' just long-winded.
- ' ────────────────────────────────────────────────────────────────────────
- MouseShow
- done% = FALSE
- WHILE done% = FALSE
-
- result% = getEvent%(mouseExists%, kc%, mx%, my%)
-
- SELECT CASE result%
- CASE EMpressedLeft ' Left mouse button pressed.
- LOCATE 10, 12, 0: PRINT SPACE$(59);
- LOCATE 10, 12, 0: PRINT "Left button pressed.";
- ' ─── Mouse was clicked on the Done button ──────────────────────────
- IF (mx% >= 10) AND (mx% <= 19) AND (my% >= 20) AND (my% <= 22) THEN
- MouseHide
- Wipe 14, 19, 10, 71, 7
- LOCATE 15, 12, 0: PRINT "Oh well, Goodbye!";
- PressButton SINGLEBORDER, 10, 20, 19, 22, 0, 7, "Done", bs%
- done% = TRUE
- MouseShow
- ELSE ' Mouse was clicked, but NOT on the done button.
- MouseHide
- Wipe 14, 19, 10, 71, 7
- ' ─── Mouse clicked in Events Box ─────────────────────────────────
- IF (mx% >= 10) AND (mx% <= 71) AND (my% >= 9) AND (my% <= 11) THEN
- LOCATE 15, 12, 0: PRINT "The mouse was clicked in the Events Box, even though no";
- LOCATE 16, 12, 0: PRINT "cheese is present there.";
- ELSEIF (mx% >= 10) AND (mx% <= 71) AND (my% >= 14) AND (my% <= 19) THEN
- ' ─── Mouse clicked in comments box ─────────────────────────────
- LOCATE 15, 12, 0: PRINT "The mouse was clicked in the Comments Box. Imagine, in";
- LOCATE 16, 12, 0: PRINT "MY box! Of all the temerity!";
- ELSE
- ' ─── Mouse clicked anywhere else ───────────────────────────────
- LOCATE 15, 12, 0: PRINT "The mouse was clicked in some out-of-the-way locale, not";
- LOCATE 16, 12, 0: PRINT "of any interest whatsoever.";
- END IF
- MouseShow
- END IF
- CASE EMpressedRight ' Right mouse button pressed.
- MouseHide
- LOCATE 10, 12, 0: PRINT SPACE$(59);
- LOCATE 10, 12, 0: PRINT "Right button pressed.";
- Wipe 14, 19, 10, 71, 7
- LOCATE 15, 12, 0: PRINT "Hah! You thought pressing the right mouse button would get";
- LOCATE 16, 12, 0: PRINT "get you out of this ridiculous demo, didn't you? Well for";
- LOCATE 17, 12, 0: PRINT "once, smarty-pants, the computer out-witted the user!";
- LOCATE 18, 12, 0: PRINT "Hahahahahaha!";
- MouseShow
- CASE EMreleasedLeft ' Left mouse button released.
- MouseHide
- LOCATE 10, 12, 0: PRINT SPACE$(59);
- LOCATE 10, 12, 0: PRINT "Left button released.";
- Wipe 14, 19, 10, 71, 7
- LOCATE 15, 12, 0: PRINT "You let go of the left mouse button. Slippery fingers?";
- MouseShow
- CASE EMreleasedRight ' Right mouse button released.
- MouseHide
- LOCATE 10, 12, 0: PRINT SPACE$(59);
- LOCATE 10, 12, 0: PRINT "Right button released.";
- Wipe 14, 19, 10, 71, 7
- LOCATE 15, 12, 0: PRINT "You let go of the right mouse button. Think twice next";
- LOCATE 16, 12, 0: PRINT "time before you try to run out on ME.";
- MouseShow
- CASE EMmoved ' Mouse was moved.
- MouseHide
- LOCATE 10, 12, 0: PRINT SPACE$(59);
- LOCATE 10, 12, 0: PRINT "Mouse moved to coordinates X:"; mx%; " Y:"; my%
- Wipe 14, 19, 10, 71, 7
- IF (mx% >= 10) AND (mx% <= 71) AND (my% >= 9) AND (my% <= 11) THEN
- ' ─── Mouse moved into Events Box ─────────────────────────────────
- LOCATE 15, 12, 0: PRINT "The mouse is vacationing in the sunny land of the Last";
- LOCATE 16, 12, 0: PRINT "Event box. That sneaky little squeaker...";
- ELSEIF (mx% >= 10) AND (mx% <= 71) AND (my% >= 14) AND (my% <= 19) THEN
- ' ─── Mouse moved into Comments box ───────────────────────────────
- LOCATE 15, 12, 0: PRINT "Hey! Get your furry little track ball outta MY box! I";
- LOCATE 16, 12, 0: PRINT "don't recall inviting you!";
- ELSEIF (mx% >= 10) AND (mx% <= 19) AND (my% >= 20) AND (my% <= 22) THEN
- ' ─── Mouse moved into Done button ────────────────────────────────
- LOCATE 15, 12, 0: PRINT "Wait! You weren't thinking of leaving were you? Move";
- LOCATE 16, 12, 0: PRINT "that mouse off of the Done button; I promise I'll be a";
- LOCATE 17, 12, 0: PRINT "bit nicer, really! Please...?";
- ELSE
- LOCATE 15, 12, 0: PRINT "The mouse was moved, alright, but not to anywhere I'd";
- LOCATE 16, 12, 0: PRINT "admit to in public.";
- END IF
- MouseShow
- CASE EKpressed ' Key was pressed on the keyboard.
- MouseHide
- LOCATE 10, 12, 0: PRINT SPACE$(59);
- IF (kc% <= 255 AND kc% >= 0) THEN ' Normal key (letters, numbers)
- LOCATE 10, 12, 0: PRINT "Normal key pressed: "; CHR$(kc%);
- Wipe 14, 19, 10, 71, 7
- LOCATE 15, 12, 0: PRINT "Average, evryday, normal, boring key was pressed.";
- ELSE ' Extended key (arrow, PgUp, End, etc.)
- Wipe 14, 19, 10, 71, 7
- LOCATE 15, 12, 0: PRINT "Now THAT'S a more intersting key to press!";
- LOCATE 10, 12, 0: PRINT "Extended key pressed:";
- ' ─── Display the extended key that was pressed ───────────────────
- SELECT CASE kc%
- CASE F1: PRINT " F1";
- CASE F2: PRINT " F2";
- CASE F3: PRINT " F3";
- CASE F4: PRINT " F4";
- CASE F5: PRINT " F5";
- CASE F6: PRINT " F6";
- CASE F7: PRINT " F7";
- CASE F8: PRINT " F8";
- CASE F9: PRINT " F9";
- CASE F10: PRINT " F10";
- CASE UPARROW: PRINT " Up Arrow";
- CASE DOWNARROW: PRINT " Down Arrow";
- CASE LEFTARROW: PRINT " Left Arrow";
- CASE RIGHTARROW: PRINT " Right Arrow";
- CASE HOMEKEY: PRINT " Home";
- CASE ENDKEY: PRINT " End";
- CASE PGUP: PRINT " PgUp";
- CASE PGDN: PRINT " PgDn";
- CASE INSERT: PRINT " Ins";
- CASE DELETE: PRINT " Del";
- CASE ELSE: PRINT " Unknown Key";
- END SELECT
- END IF
- ' ─── If key was D, d, or Esc, then exit. ───────────────────────────
- IF (kc% = ASC("D")) OR (kc% = ASC("d")) OR (kc% = 27) THEN
- done% = TRUE
- END IF
- MouseShow
- CASE ELSE
- END SELECT
-
- WEND
-
- END SUB
-
- SUB ListDemo
-
- ' ────────────────────────────────────────────────────────────────────────
- ' This demo will illustrate the two types of lists available, the View-
- ' List and the selectList. This routine will display a submenu with
- ' these two choices, and will kick off the appropriate demo.
- ' ────────────────────────────────────────────────────────────────────────
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Define frameType based on kolor%.
- ' ────────────────────────────────────────────────────────────────────────
- IF kolor% THEN
- ft% = 6
- ELSE
- ft% = 0
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' If the mouse is about, turn it off.
- ' ────────────────────────────────────────────────────────────────────────
- IF mouseExists% THEN
- MouseHide
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Prepare the submenu. This involves drawing a window in which it will
- ' reside and defining the menu choices.
- ' ────────────────────────────────────────────────────────────────────────
- MakeWindow 8, 50, 11, 68, 0, 7, 0, ft%, -1, 0, ""
-
- DIM m$(2)
- m$(1) = "^Selectable List"
- m$(2) = "^Viewing List"
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Call the submenu to get a response from the user.
- ' ────────────────────────────────────────────────────────────────────────
- result% = MakeMenu%(m$(), 2, "L", 52, 69, 9, "^", "|", 0, 7, 15, 0, 15, 7, mouseExists%)
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Decide what to do from here based on the user's menu selection.
- ' ────────────────────────────────────────────────────────────────────────
- SELECT CASE result%
- CASE 1 ' Selectable List
- SelectListDemo
- CASE 2 ' Viewing List
- ViewListDemo
- CASE ELSE
- END SELECT
-
- END SUB
-
- SUB SelectListDemo
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Right off the bat, check to see if the file that contains the list of
- ' items from which a selection will be made is on disk. If so, then
- ' proceed. If not, then exit now.
- ' ────────────────────────────────────────────────────────────────────────
- IF FirstFile%("SELECT.TXT", NormalAttr, dta$) = FALSE THEN
- InfoBox SELECTMISSING
- EXIT SUB
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' This demo will illustrate the SelectList routine.
- ' ────────────────────────────────────────────────────────────────────────
- DIM list$(50)
- DIM scr%(BlockSize%(1, 80, 10, 17))
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Turn the mouse off if it's around.
- ' ────────────────────────────────────────────────────────────────────────
- IF mouseExists% THEN
- MouseHide
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Define color-based data.
- ' ────────────────────────────────────────────────────────────────────────
- IF kolor% THEN
- ft1% = 6
- ft2% = 7
- bs% = STYLE3D
- ELSE
- ft1% = 0
- ft2% = 0
- bs% = STYLE2D
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Make a window in which the demo will reside, as well as a title box.
- ' ────────────────────────────────────────────────────────────────────────
- MakeWindow 2, 6, 23, 75, 0, 7, 0, ft1%, -1, 0, ""
- MakeWindow 3, 21, 5, 60, 0, 7, 0, ft2%, -1, 0, ""
- MakeWindow 20, 30, 22, 73, 0, 7, 0, ft2%, -1, 0, ""
- Center "SelectList Demo", 4
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Add buttons to window.
- ' ────────────────────────────────────────────────────────────────────────
- DrawButton SINGLEBORDER, 8, 20, 17, 22, 0, 7, "Done", bs%
- DrawButton SINGLEBORDER, 19, 20, 28, 22, 0, 7, "List", bs%
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Display some text explaining the SelectList function.
- ' ────────────────────────────────────────────────────────────────────────
- COLOR 0, 7
- LOCATE 7, 9, 0: PRINT "The QBSCR routine SelectList displays a scrolling list of items";
- LOCATE 8, 9, 0: PRINT "from which the user may select one item. Selection is made via";
- LOCATE 9, 9, 0: PRINT "a highlight bar that moves up and down. Once the item desired";
- LOCATE 10, 9, 0: PRINT "is highlighted, the ENTER key selects it. the bar may also be";
- LOCATE 11, 9, 0: PRINT "moved by hitting the first letter of the item to be chosen.";
- LOCATE 13, 9, 0: PRINT "Mouse support is also provided. A scroll bar on the right side";
- LOCATE 14, 9, 0: PRINT "of the window allows mouse scrolling, and the user simply left-";
- LOCATE 15, 9, 0: PRINT "clicks the item desired.";
- LOCATE 17, 9, 0: PRINT "Click on the List button or hit 'L' to try it out (you will";
- LOCATE 18, 9, 0: PRINT "select a hobby from a list) or click Done (or hit D) to exit.";
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Set up the selectable list.
- ' ────────────────────────────────────────────────────────────────────────
- OPEN "SELECT.TXT" FOR INPUT AS #1
- numHobbies% = 0
- WHILE (NOT (EOF(1)))
- numHobbies% = numHobbies% + 1
- LINE INPUT #1, list$(numHobbies%)
- list$(numHobbies%) = RTRIM$(list$(numHobbies%))
- WEND
- CLOSE #1
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Sit in a loop waiting for input. If the List button is activated,
- ' then display the selectable list. When we return from it, display a
- ' message based on what hobby they selected. If the Done button is
- ' activated, then get outta here.
- ' ────────────────────────────────────────────────────────────────────────
- IF mouseExists% THEN
- MouseShow
- END IF
- done% = FALSE
- WHILE done% = FALSE
-
- result% = getEvent%(mouseExists%, kc%, mx%, my%)
-
- SELECT CASE result%
- CASE EMpressedLeft ' Left mouse button pressed
- IF (mx% >= 19) AND (mx% < 28) AND (my% >= 20) AND (my% <= 22) THEN
- PressButton SINGLEBORDER, 19, 20, 28, 22, 0, 7, "List", bs%
- IF mouseExists% THEN
- MouseHide
- END IF
- BlockSave 1, 80, 10, 17, scr%(), GetVideoSegment!
- sResult$ = SelectList$(list$(), numHobbies%, 11, 16, 22, 25, 0, 7, 15, 0, ft1%, 0, -1, "", mouseExists%)
- IF mouseExists% THEN
- MouseHide
- END IF
- BlockRestore 1, 80, 10, 17, scr%(), GetVideoSegment!
- COLOR 0, 7
- LOCATE 21, 32, 0: PRINT SPACE$(40);
- IF UCASE$(RTRIM$(sResult$)) = "NONE" THEN
- LOCATE 21, 32, 0: PRINT "None?? Get a life!";
- ELSEIF UCASE$(LEFT$(sResult$, 9)) = "COMPUTING" THEN
- LOCATE 21, 32, 0: PRINT "Don't you ever get tired of this box?";
- ELSE
- IF LTRIM$(RTRIM$(sResult$)) = "" THEN
- LOCATE 21, 32, 0: PRINT RTRIM$(sResult$); "Surely you're interested in something!";
- ELSE
- LOCATE 21, 32, 0: PRINT RTRIM$(sResult$); ", eh? Nifty!";
- END IF
- END IF
- IF mouseExists% THEN
- MouseShow
- END IF
- END IF
- IF (mx% >= 8) AND (mx% < 17) AND (my% >= 20) AND (my% <= 22) THEN
- PressButton SINGLEBORDER, 8, 20, 17, 22, 0, 7, "Done", bs%
- done% = TRUE
- END IF
- CASE EMpressedRight ' Right mouse button pressed.
- done% = TRUE
- CASE EKpressed ' A key was pressed on the keyboard.
- IF (kc% = ASC("L")) OR (kc% = ASC("l")) THEN
- IF mouseExists% THEN
- MouseHide
- END IF
- BlockSave 1, 80, 10, 17, scr%(), GetVideoSegment!
- sResult$ = SelectList$(list$(), numHobbies%, 11, 16, 22, 25, 0, 7, 15, 0, ft1%, 0, -1, "", mouseExists%)
- IF mouseExists% THEN
- MouseHide
- END IF
- BlockRestore 1, 80, 10, 17, scr%(), GetVideoSegment!
- COLOR 0, 7
- LOCATE 21, 32, 0: PRINT SPACE$(40);
- IF UCASE$(RTRIM$(sResult$)) = "NONE" THEN
- LOCATE 21, 32, 0: PRINT "None?? Get a life!";
- ELSEIF UCASE$(LEFT$(sResult$, 9)) = "COMPUTING" THEN
- LOCATE 21, 32, 0: PRINT "Don't you ever get tired of this box?";
- ELSE
- IF LTRIM$(RTRIM$(sResult$)) = "" THEN
- LOCATE 21, 32, 0: PRINT RTRIM$(sResult$); "Surely you're interested in something!";
- ELSE
- LOCATE 21, 32, 0: PRINT RTRIM$(sResult$); ", eh? Nifty!";
- END IF
- END IF
- IF mouseExists% THEN
- MouseShow
- END IF
- END IF
- IF (kc% = ASC("D")) OR (kc% = ASC("d")) OR (kc% = 27) THEN
- done% = TRUE
- END IF
- CASE ELSE
- END SELECT
-
- WEND
-
- END SUB
-
- SUB ViewListDemo
-
- ' ────────────────────────────────────────────────────────────────────────
- ' This demo will illustrate the ViewList routine. It reads a text file
- ' from disk that explains how ViewList works, and then uses ViewList to
- ' display it.
- ' ────────────────────────────────────────────────────────────────────────
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Turn the mouse off if it's around.
- ' ────────────────────────────────────────────────────────────────────────
- IF mouseExists% THEN
- MouseHide
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Define color-based data.
- ' ────────────────────────────────────────────────────────────────────────
- IF kolor% THEN
- ft1% = 6
- ELSE
- ft1% = 0
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Display a "Wait" window.
- ' ────────────────────────────────────────────────────────────────────────
- MakeWindow 9, 21, 13, 60, 0, 7, 0, ft1%, -1, 0, ""
- COLOR 0, 7
- Center "Loading text...Please wait.", 11
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Check to see if the file VIEWLIST.TXT exists. If so, proceed. If not,
- ' then display an error and exit this function.
- ' ────────────────────────────────────────────────────────────────────────
- IF FirstFile%("VIEWLIST.TXT", NormalAttr, dta$) = FALSE THEN
- InfoBox VIEWLISTMISSING
- EXIT SUB
- END IF
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Load text from file.
- ' ────────────────────────────────────────────────────────────────────────
- DIM txt$(100)
- OPEN "VIEWLIST.TXT" FOR INPUT AS #1
- numLines% = 0
- WHILE (NOT (EOF(1)))
- numLines% = numLines% + 1
- LINE INPUT #1, txt$(numLines%)
- txt$(numLines%) = RTRIM$(txt$(numLines%))
- WEND
- CLOSE #1
-
- ' ────────────────────────────────────────────────────────────────────────
- ' Call ViewList to run the demo.
- ' ────────────────────────────────────────────────────────────────────────
- ViewList txt$(), numLines%, 64, 9, 23, 8, 0, 7, ft1%, 0, -1, "", mouseExists%
-
- END SUB
-
-