home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / basic / QBSCR20.ZIP / PC.BAS < prev    next >
Encoding:
BASIC Source File  |  1992-07-08  |  9.0 KB  |  286 lines

  1. ' ──────────────────────────────────────────────────────────────────────────
  2. '
  3. '                                P C . B A S
  4. '
  5. '            A Companion Utility for the QBSCR Screen Routines
  6. '
  7. '      Executable, source code, and documentation copyright (c) 1992 by
  8. '                                Tony Martin
  9. ' --------------------------------------------------------------------------
  10. '
  11. ' This program allows you to experiment with EGA/VGA palette colors, and to
  12. ' determine the exact Red, Green, and Blue color values that are required to
  13. ' make the colors you want.  Simply adjust the R, G, and B values up and down
  14. ' until you see the color(s) you desire.  Use the R, G, B values that are
  15. ' then displayed in your own programs, with the QBSCR rgbRGB% function.
  16. '
  17. ' This program was provided primarily as an example of the use of the QBSCR
  18. ' 3D and palette routines.  It weighs in at considerably less than 300 lines,
  19. ' including white space and commentary.  It fully supports the mouse as well
  20. ' as the keyboard.  It took only about an hour and a half to write.
  21. '
  22. ' To load this source code and recompile it, use this command:
  23. '
  24. '                            QB PC /L QBSCR20
  25. '
  26. ' Once loaded and compiled, this will result in a compiled EXE file of about
  27. ' 120K.  That's because it will compile-in the entire QBSCR library.  Notice
  28. ' that the EXE included with the QBSCR Screen Routines is less than 37K. You
  29. ' can make an EXE this size as well by using the Source Builder program to
  30. ' make a QBSCR source file that contains only the QBSCR routines that PC
  31. ' needs.  These routines are:
  32. '
  33. '    EgaPresent%, DepressedBox, RaisedBox, DrawButton, PressedButton,
  34. '    PressButton, Center, OffCenter, rgbRGB%, MouseInit%, MouseShow,
  35. '    MouseHide, GetEvent%
  36. '
  37. ' Once you create this source file, load PC into QB like this:
  38. '
  39. '                              QB PC /L QB
  40. '
  41. ' making sure that the files QB.QLB and QB.LIB are available (they come with
  42. ' QuickBASIC).  The File/Load the file you created with Source Builder and
  43. ' compile to an EXE.  You should get an EXE about 36.5K. 
  44. ' ──────────────────────────────────────────────────────────────────────────
  45.  
  46.  
  47. '$INCLUDE: 'qbscr.inc'
  48. '$INCLUDE: 'mouse.bi'
  49. '$INCLUDE: 'colconst.bas'
  50.  
  51. CONST PSLOT = 6    ' The palette slot we'll be changing.
  52.  
  53. ' ***
  54. ' *** Check to see if an EGA or VGA card is present.  If not, then exit.
  55. ' ***
  56. IF EgaPresent% = FALSE THEN
  57.     PRINT "This program requires and EGA or VGA card, and one was not detected."
  58.     END
  59. END IF
  60.  
  61.  
  62. ' ***
  63. ' *** Clear the screen and draw the interface.
  64. ' ***
  65. COLOR WHITE, BLACK
  66. CLS
  67. COLOR BLACK, WHITE  ' Draw a grey background mat.
  68. FOR i% = 2 TO 23
  69.     LOCATE i%, 9, 0: PRINT SPACE$(64);
  70. NEXT i%
  71.  
  72. ' *** Various windows and boxes
  73. DepressedBox SINGLEBORDER, 10, 2, 71, 23, 0, 7, STYLE3D   ' Main window.
  74. RaisedBox SINGLEBORDER, 13, 3, 68, 5, 0, 7, STYLE3D       ' Title bar.
  75. RaisedBox SINGLEBORDER, 13, 6, 38, 18, 0, 7, STYLE3D      ' Color box, pt 1.
  76. DepressedBox SINGLEBORDER, 15, 7, 36, 17, 0, 7, STYLE3D   ' Color box, pt 2.
  77. DepressedBox SINGLEBORDER, 42, 6, 68, 18, 0, 7, STYLE3D   ' Controls box.
  78.  
  79. ' *** Control Buttons
  80. DrawButton SINGLEBORDER, 44, 8, 50, 10, 0, 7, "+", STYLE3D  ' Red + button.
  81. DrawButton SINGLEBORDER, 52, 8, 58, 10, 0, 7, "+", STYLE3D  ' Green + button.
  82. DrawButton SINGLEBORDER, 60, 8, 66, 10, 0, 7, "+", STYLE3D  ' Blue + button.
  83. DrawButton SINGLEBORDER, 44, 14, 50, 16, 0, 7, "-", STYLE3D  ' Red - button.
  84. DrawButton SINGLEBORDER, 52, 14, 58, 16, 0, 7, "-", STYLE3D  ' Green - button.
  85. DrawButton SINGLEBORDER, 60, 14, 66, 16, 0, 7, "-", STYLE3D  ' Blue - button.
  86.  
  87. ' *** RGB Value Windows
  88. PressedButton SINGLEBORDER, 44, 11, 50, 13, 0, 7, "0", STYLE3D  ' Red.
  89. PressedButton SINGLEBORDER, 52, 11, 58, 13, 0, 7, "0", STYLE3D  ' Green.
  90. PressedButton SINGLEBORDER, 60, 11, 66, 13, 0, 7, "0", STYLE3D  ' Blue.
  91.  
  92. ' *** The DONE Button
  93. DrawButton SINGLEBORDER, 35, 20, 45, 22, 0, 7, "Done!", STYLE3D
  94.  
  95. ' *** Text Labels
  96. COLOR blue, WHITE
  97. Center "The QBSCR Screen Routines ∙ Palette Calculator", 4
  98. COLOR BRIGHT + CYAN, WHITE
  99. OffCenter "Color Display", 19, 13, 38
  100. OffCenter "Palette Controls", 19, 42, 68
  101. LOCATE 7, 47, 0: PRINT "R       G       B";
  102. LOCATE 17, 47, 0: PRINT "r       g       b";
  103.  
  104. ' ***
  105. ' *** Initialize the palette slot we'll be using for the color display.  The
  106. ' *** color 6 (brown) has always appalled me, so we'll use that one.  Our
  107. ' *** initial setting will be R=0, G=0, B=0, or black.  Once the palette for
  108. ' *** this is set, draw in the color square.
  109. ' ***
  110. r% = 0
  111. G% = 0
  112. b% = 0
  113. PALETTE PSLOT, rgbRGB%(r%, G%, b%)
  114. COLOR 6, 0
  115. FOR i% = 8 TO 16
  116.     LOCATE i%, 17, 0: PRINT STRING$(18, 219);
  117. NEXT i%
  118.  
  119.  
  120. ' ***
  121. ' *** Now check to see if a mouse is available.  If so, turn it on.
  122. ' ***
  123. mouseExists% = MouseInit%
  124. IF mouseExists% THEN
  125.     MouseShow
  126. END IF
  127.  
  128.  
  129. ' ***
  130. ' *** Sit in a loop waiting for events. The following events are significant:
  131. ' ***
  132. ' ***    Event           Causes this action
  133. ' ***    ------------------------------------------------------------------
  134. ' ***    R key           Increase red value
  135. ' ***    r key           Decrease red value
  136. ' ***    G key           Increase green value
  137. ' ***    g key           Decrease green value
  138. ' ***    B key           Increase blue value
  139. ' ***    b key           Decrease blue value
  140. ' ***    D, d keys       Done - quit program
  141. ' ***    Esc key                 "
  142. ' ***    Left mouse      Depends on location
  143. ' ***    Right mouse     Done - Quit program
  144. ' ***
  145. done% = FALSE
  146. WHILE done% = FALSE
  147.  
  148.     ' ***
  149.     ' *** This update% flag will tell the program whether or not we actually
  150.     ' *** need to update the palette display.
  151.     ' ***
  152.     update% = FALSE
  153.  
  154.     ' ***
  155.     ' *** Now we wait on an event from the user.  The QBSCR routine GetEvent
  156.     ' *** will do very nicely here.
  157.     ' ***
  158.     event% = getEvent%(mouseExists%, theKey%, mx%, my%)
  159.  
  160.     ' ***
  161.     ' *** At this point, we definitely have an event of some kind, so we must
  162.     ' *** decide what to do with it.
  163.     ' ***
  164.     SELECT CASE event%
  165.     CASE EMpressedLeft
  166.         IF (mx% >= 44) AND (mx% <= 50) AND (my% >= 8) AND (my% <= 10) THEN
  167.             PressButton SINGLEBORDER, 44, 8, 50, 10, 0, 7, "+", STYLE3D
  168.             IF r% < 3 THEN
  169.                 r% = r% + 1      ' Increase red.
  170.                 update% = TRUE
  171.             END IF
  172.         END IF
  173.         IF (mx% >= 44) AND (mx% <= 50) AND (my% >= 14) AND (my% <= 16) THEN
  174.             PressButton SINGLEBORDER, 44, 14, 50, 16, 0, 7, "-", STYLE3D
  175.             IF r% > 0 THEN
  176.                 r% = r% - 1      ' Decrease red.
  177.                 update% = TRUE
  178.             END IF
  179.         END IF
  180.         IF (mx% >= 52) AND (mx% <= 58) AND (my% >= 8) AND (my% <= 10) THEN
  181.             PressButton SINGLEBORDER, 52, 8, 58, 10, 0, 7, "+", STYLE3D
  182.             IF G% < 3 THEN
  183.                 G% = G% + 1      ' Increase green.
  184.                 update% = TRUE
  185.             END IF
  186.         END IF
  187.         IF (mx% >= 52) AND (mx% <= 58) AND (my% >= 14) AND (my% <= 16) THEN
  188.             PressButton SINGLEBORDER, 52, 14, 58, 16, 0, 7, "-", STYLE3D
  189.             IF G% > 0 THEN
  190.                 G% = G% - 1      ' Decrease green.
  191.                 update% = TRUE
  192.             END IF
  193.         END IF
  194.         IF (mx% >= 60) AND (mx% <= 66) AND (my% >= 8) AND (my% <= 10) THEN
  195.             PressButton SINGLEBORDER, 60, 8, 66, 10, 0, 7, "+", STYLE3D
  196.             IF b% < 3 THEN
  197.                 b% = b% + 1      ' Increase blue.
  198.                 update% = TRUE
  199.             END IF
  200.         END IF
  201.         IF (mx% >= 60) AND (mx% <= 66) AND (my% >= 14) AND (my% <= 16) THEN
  202.             PressButton SINGLEBORDER, 60, 14, 66, 16, 0, 7, "-", STYLE3D
  203.             IF b% > 0 THEN
  204.                 b% = b% - 1      ' Decrease blue.
  205.                 update% = TRUE
  206.             END IF
  207.         END IF
  208.         IF (mx% >= 35) AND (mx% <= 45) AND (my% >= 20) AND (my% <= 22) THEN
  209.             PressButton SINGLEBORDER, 35, 20, 45, 22, 0, 7, "Done!", STYLE3D
  210.             done% = TRUE
  211.         END IF
  212.     CASE EMpressedRight
  213.         done% = TRUE
  214.     CASE EKpressed
  215.         
  216.         ' ***
  217.         ' *** If we're here, a key was pressed.  If that is the case, then we
  218.         ' *** must act based on which key was pressed.
  219.         ' ***
  220.         SELECT CASE theKey%
  221.         CASE 82      ' R - Increase red
  222.             IF r% < 3 THEN
  223.                 r% = r% + 1
  224.                 update% = TRUE
  225.             END IF
  226.         CASE 114     ' r - Decrease red
  227.             IF r% > 0 THEN
  228.                 r% = r% - 1
  229.                 update% = TRUE
  230.             END IF
  231.         CASE 71      ' Increase green
  232.             IF G% < 3 THEN
  233.                 G% = G% + 1
  234.                 update% = TRUE
  235.             END IF
  236.         CASE 103     ' Decrease green
  237.             IF G% > 0 THEN
  238.                 G% = G% - 1
  239.                 update% = TRUE
  240.             END IF
  241.         CASE 66      ' Increase blue
  242.             IF b% < 3 THEN
  243.                 b% = b% + 1
  244.                 update% = TRUE
  245.             END IF
  246.         CASE 98      ' Decrease blue
  247.             IF b% > 0 THEN
  248.                 b% = b% - 1
  249.                 update% = TRUE
  250.             END IF
  251.         CASE 68, 100 ' D, d - Quit
  252.             done% = TRUE
  253.         CASE 27      ' Esc - Quit
  254.             done% = TRUE
  255.         CASE ELSE
  256.         END SELECT
  257.     CASE ELSE
  258.     END SELECT
  259.  
  260.     ' ***
  261.     ' *** If our update% flag is TRUE, we must update the palette display, as
  262.     ' *** well as our numerical display.
  263.     ' ***
  264.     IF update% THEN
  265.         IF mouseExists% THEN
  266.             MouseHide
  267.         END IF
  268.         PALETTE PSLOT, rgbRGB%(r%, G%, b%)
  269.         COLOR 0, 7
  270.         LOCATE 12, 47, 0: PRINT LTRIM$(STR$(r%));
  271.         LOCATE 12, 55, 0: PRINT LTRIM$(STR$(G%));
  272.         LOCATE 12, 63, 0: PRINT LTRIM$(STR$(b%));
  273.         IF mouseExists% THEN
  274.             MouseShow
  275.         END IF
  276.     END IF
  277.  
  278. WEND
  279.  
  280. IF mouseExists% THEN
  281.     MouseHide
  282. END IF
  283. COLOR 7, 0
  284. CLS
  285.  
  286.