home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MSMOUSE1.ZIP / BAS.ZIP / PENCIL.BAS < prev    next >
Encoding:
BASIC Source File  |  1988-12-19  |  18.9 KB  |  671 lines

  1.   '******************************************************
  2.   '*  PENCIL.BAS                                        *
  3.   '*                                                    *
  4.   '*  Translation to QuickBASIC 4.5 of the PENCIL.C     *
  5.   '*  program.  See the PENCIL.C listing for a more     *
  6.   '*  detailed description.                             *
  7.   '*                                                    *
  8.   '*  Original author:  Greg Lee                        *
  9.   '*  Translated by:    J. C. Craig                     *
  10.   '*                                                    *
  11.   '*  Load QBMOUSE.QLB into memory with QuickBASIC...   *
  12.   '*  QB /L QBMOUSE.QLB                                 *
  13.   '******************************************************
  14.  
  15.     DEFINT A-Z
  16.  
  17.     DECLARE SUB MouseReset ()
  18.     DECLARE SUB MouseWindow (minX%, minY%, maxX%, maxY%)
  19.     DECLARE SUB DrawScreen ()
  20.     DECLARE SUB DrawCursor (cursormask%)
  21.     DECLARE SUB RightButton (press%, release%, now%)
  22.     DECLARE SUB CallMenu ()
  23.     DECLARE SUB MouseCursor (switch%)
  24.     DECLARE SUB PopUpMenu (menuselect%, attribute%)
  25.     DECLARE SUB MousePosition (x%, y%)
  26.     DECLARE SUB LeftButton (press%, release%, now%)
  27.     DECLARE SUB Pencil ()
  28.     DECLARE SUB Eraser ()
  29.     DECLARE SUB Mouse (m1%, m2%, m3%, m4%)
  30.  
  31.     CONST PencilMenu = 0        ' pencil menu selected
  32.     CONST EraserMenu = 1        ' eraser menu selected
  33.     CONST Quit = 2              ' quit selected
  34.     CONST InverseColor = 0      ' inverse color of menu
  35.     CONST NormalColor = 1       ' normal color of menu
  36.     CONST PencilCursor = 0      ' use pencil cursor
  37.     CONST EraserCursor = 1      ' use eraser cursor
  38.     CONST mMouseCursor = 2      ' use mouse cursor
  39.     CONST hide = 0              ' hide mouse cursor
  40.     CONST show = 1              ' show mouse cursor
  41.  
  42.     DIM cursor(32), saveScreen(5700)
  43.  
  44.     COMMON SHARED xmax, ymax, cursor(), saveScreen()
  45.     COMMON SHARED white, black
  46.  
  47.   ' Which video mode given on command line?
  48.     SELECT CASE COMMAND$
  49.  
  50.       ' Hercules 720 x 348 ?
  51.     CASE "H"
  52.         DEF SEG = &H40
  53.         POKE &H49, 6            ' Sets HGC page 0
  54.         DEF SEG
  55.         MouseReset
  56.         SCREEN 3, , 0, 0        ' Switch to Hercules Graphics mode
  57.         xmax = 720
  58.         ymax = 348
  59.  
  60.       ' CGA 320 x 200 ?
  61.     CASE "5"
  62.         SCREEN 1
  63.         xmax = 320
  64.         ymax = 200
  65.         white = 3
  66.         MouseReset
  67.  
  68.       ' CGA 640 x 200 ?
  69.     CASE "6"
  70.         SCREEN 2
  71.         xmax = 640
  72.         ymax = 200
  73.         white = 1
  74.         MouseReset
  75.  
  76.       ' EGA 640 x 350 ?
  77.     CASE "16"
  78.         SCREEN 9
  79.         xmax = 640
  80.         ymax = 350
  81.         white = 15
  82.         MouseReset
  83.  
  84.       ' VGA 640 x 480 ?
  85.     CASE "18"
  86.         SCREEN 11
  87.         xmax = 640
  88.         ymax = 480
  89.         white = 1
  90.         MouseReset
  91.  
  92.       ' Video mode not recognized ?
  93.     CASE ELSE
  94.         PRINT
  95.         PRINT " USAGE: pencil <video mode selection>"
  96.         PRINT
  97.         PRINT "  Adapter        Video mode selection"
  98.         PRINT "  -----------    --------------------"
  99.         PRINT "  CGA 320x200             5"
  100.         PRINT "  CGA 640x200             6"
  101.         PRINT "  EGA 640x350             16"
  102.         PRINT "  VGA 640x480             18"
  103.         PRINT "  Herc 720x348            h"
  104.         PRINT "  For example: pencil 6"
  105.         SYSTEM
  106.     END SELECT
  107.  
  108.   ' Draw first screen
  109.     LINE (0, 0)-(xmax - 1, ymax - 1), , B
  110.     LINE (2, 2)-(xmax - 3, ymax - 3), , B
  111.     LINE (3, 3)-(xmax - 4, ymax - 4), black, BF
  112.  
  113.   ' Startup - draw borders and mouse, wait for right button release
  114.     DO
  115.  
  116.       ' Draw mouse cursor
  117.         DrawCursor mMouseCursor
  118.  
  119.       ' Watch for right button release
  120.         DO
  121.             RightButton press, release, now
  122.         LOOP UNTIL release
  123.  
  124.       ' Do menu items
  125.         CallMenu
  126.  
  127.     LOOP
  128.  
  129.   '-----------------------------------------
  130.   ' Display menu and act on user selections
  131.   '-----------------------------------------
  132.     SUB CallMenu STATIC
  133.  
  134.       ' Set flag to cause update of menu items
  135.         refresh = 1
  136.  
  137.       ' Main loop, wait for and act on user selections
  138.         DO
  139.  
  140.           ' Need to refresh the display of the menu items?
  141.             IF refresh THEN
  142.  
  143.                 refresh = 0
  144.                 endCallMenu = 0
  145.                 lastmenuselector = -1
  146.  
  147.               ' Hide the mouse cursor
  148.                 MouseCursor hide
  149.  
  150.               ' Save copy of menu area of screen
  151.                 GET (1, 1)-(xmax - 1, ymax \ 10), saveScreen
  152.  
  153.               ' Draw menu borders
  154.                 LINE (0, 0)-(xmax \ 3, ymax \ 10), , B
  155.                 LINE ((xmax \ 3) + 1, 0)-((xmax \ 3) * 2, ymax \ 10), , B
  156.                 LINE ((xmax \ 3) * 2 + 1, 0)-(xmax - 1, ymax \ 10), , B
  157.  
  158.               ' Draw the three menu items
  159.                 PopUpMenu PencilMenu, NormalColor
  160.                 PopUpMenu EraserMenu, NormalColor
  161.                 PopUpMenu Quit, NormalColor
  162.  
  163.             END IF
  164.  
  165.           ' Get current mouse position
  166.             MousePosition x, y
  167.  
  168.           ' Adjust horizontal value for virtual screen vs. physical
  169.             IF xmax = 320 THEN
  170.                 menuselector = (x \ 2) \ (xmax \ 3)
  171.             ELSE
  172.                 menuselector = x \ (xmax \ 3)
  173.             END IF
  174.  
  175.           ' Update menu items if mouse has moved to new selection
  176.             IF menuselector <> lastmenuselector THEN
  177.                 PopUpMenu lastmenuselector, NormalColor
  178.                 PopUpMenu menuselector, InverseColor
  179.                 lastmenuselector = menuselector
  180.             END IF
  181.  
  182.           ' Get status of left mouse button
  183.             LeftButton press, release, now
  184.  
  185.           ' Menu item selected if left button released
  186.             IF release THEN
  187.  
  188.               ' Restore screen behind menu
  189.                 PUT (1, 1), saveScreen, PSET
  190.  
  191.               ' Which item was selected?
  192.                 SELECT CASE menuselector
  193.  
  194.                   ' "Pencil" selected?
  195.                 CASE PencilMenu
  196.                     Pencil
  197.                     refresh = 1
  198.  
  199.                   ' "Eraser" selected?
  200.                 CASE EraserMenu
  201.                     Eraser
  202.                     refresh = 1
  203.  
  204.                   ' Must be "QUIT" was selected
  205.                 CASE ELSE
  206.                     CLS
  207.                     MouseReset
  208.                     SCREEN 0
  209.                     WIDTH 80
  210.                     END
  211.                 END SELECT
  212.  
  213.             END IF
  214.  
  215.           ' Get status of right mouse button
  216.             RightButton press, release, now
  217.  
  218.           ' Exit the menu if the right button was released
  219.             IF release THEN
  220.  
  221.               ' Restore the screen behind menu
  222.                 PUT (1, 1), saveScreen, PSET
  223.  
  224.               ' Signal to exit CallMenu processing loop
  225.                 endCallMenu = 1
  226.  
  227.             END IF
  228.  
  229.         LOOP UNTIL endCallMenu
  230.  
  231.     END SUB
  232.  
  233.   '------------------------------------------
  234.   ' Sets one of three graphics mode cursors
  235.   '------------------------------------------
  236.     SUB DrawCursor (cursormask) STATIC
  237.  
  238.       ' set screen mask (same for all three cursors)
  239.         cursor(0) = &HFFFF
  240.         cursor(1) = &HFFFF
  241.         cursor(2) = &HFFFF
  242.         cursor(3) = &HFFFF
  243.         cursor(4) = &HFFFF
  244.         cursor(5) = &HFFFF
  245.         cursor(6) = &HFFFF
  246.         cursor(7) = &HFFFF
  247.         cursor(8) = &HFFFF
  248.         cursor(9) = &HFFFF
  249.         cursor(10) = &HFFFF
  250.         cursor(11) = &HFFFF
  251.         cursor(12) = &HFFFF
  252.         cursor(13) = &HFFFF
  253.         cursor(14) = &HFFFF
  254.         cursor(15) = &HFFFF
  255.  
  256.       ' Set one of the three cursor masks
  257.         SELECT CASE cursormask
  258.  
  259.         CASE PencilCursor
  260.  
  261.             cursor(16) = &H0
  262.             cursor(17) = &H0
  263.             cursor(18) = &H0
  264.             cursor(19) = &H20
  265.             cursor(20) = &H50
  266.             cursor(21) = &H88
  267.             cursor(22) = &H150
  268.             cursor(23) = &H220
  269.             cursor(24) = &H440
  270.             cursor(25) = &H880
  271.             cursor(26) = &H1100
  272.             cursor(27) = &H2200
  273.             cursor(28) = &H4400
  274.             cursor(29) = &H8800
  275.             cursor(30) = &HD000
  276.             cursor(31) = &HE000
  277.  
  278.         CASE EraserCursor
  279.  
  280.             cursor(16) = &HFFC0
  281.             cursor(17) = &H8040
  282.             cursor(18) = &H8040
  283.             cursor(19) = &H8040
  284.             cursor(20) = &H8040
  285.             cursor(21) = &H8040
  286.             cursor(22) = &H8040
  287.             cursor(23) = &H8040
  288.             cursor(24) = &H8040
  289.             cursor(25) = &H8040
  290.             cursor(26) = &HFFC0
  291.             cursor(27) = &H0
  292.             cursor(28) = &H0
  293.             cursor(29) = &H0
  294.             cursor(30) = &H0
  295.             cursor(31) = &H0
  296.  
  297.         CASE mMouseCursor
  298.  
  299.           ' Draw a two-button mouse
  300.             cursor(16) = &H660
  301.             cursor(17) = &HE70
  302.             cursor(18) = &HE70
  303.             cursor(19) = &HE70
  304.             cursor(20) = &HE70
  305.             cursor(21) = &H0
  306.             cursor(22) = &HFF0
  307.             cursor(23) = &HFF0
  308.             cursor(24) = &HFF0
  309.             cursor(25) = &HFF0
  310.             cursor(26) = &HFF0
  311.             cursor(27) = &H7E0
  312.             cursor(28) = &H0
  313.             cursor(29) = &H0
  314.             cursor(30) = &H0
  315.             cursor(31) = &H0
  316.  
  317.         CASE ELSE
  318.         END SELECT
  319.  
  320.       ' Set Graphics Cursor Block
  321.         m1 = 9  'Mouse Function 9
  322.         m2 = 0  'Hot spot X
  323.         IF cursormask = PencilCursor THEN
  324.             m3 = 16             'Hot spot Y
  325.         ELSE
  326.             m3 = 0
  327.         END IF
  328.         m4 = VARPTR(cursor(0))  'Address of cursor data
  329.         Mouse m1, m2, m3, m4
  330.  
  331.       ' Show the cursor
  332.         MouseCursor show
  333.  
  334.     END SUB
  335.  
  336.   '--------------------------------------------------
  337.   ' Create rectangular eraser to delete pencil marks
  338.   '--------------------------------------------------
  339.     SUB Eraser
  340.  
  341.       ' Limit eraser (mouse) motion to inside of screen border
  342.         IF xmax = 320 THEN
  343.             MouseWindow 6, 3, xmax * 2 - 26, ymax - 14
  344.         ELSE
  345.             MouseWindow 3, 3, xmax - 13, ymax - 14
  346.         END IF
  347.  
  348.       ' Set cursor to the eraser
  349.         DrawCursor EraserCursor
  350.  
  351.       ' Work with eraser until right button released
  352.         DO
  353.  
  354.           ' Get status of left mouse button
  355.             LeftButton press, release, now
  356.  
  357.           ' Is left button now pressed?
  358.             IF now THEN
  359.  
  360.               ' Delete the old eraser image
  361.                 IF xold THEN
  362.                     LINE (x, y)-(x + 9, y + 10), black, BF
  363.                 END IF
  364.  
  365.               ' If button was just now pressed hide the cursor
  366.                 IF press THEN
  367.                     MouseCursor hide
  368.                 END IF
  369.  
  370.               ' Get the current mouse position
  371.                 MousePosition x, y
  372.  
  373.               ' Adjust horizontal X for virtual vs. physical screen
  374.                 IF xmax = 320 THEN
  375.                     x = x \ 2
  376.                 END IF
  377.  
  378.               ' Draw outline of eraser
  379.                 LINE (x, y)-(x + 9, y + 10), white, B
  380.  
  381.               ' Erase the center part of the eraser rectangle
  382.                 LINE (x + 1, y + 1)-(x + 8, y + 9), black, BF
  383.  
  384.               ' Record current eraser position
  385.                 xold = x
  386.                 yold = y
  387.  
  388.               ' Left mouse button is not now pressed...
  389.             ELSE
  390.  
  391.               ' Erase any old eraser image
  392.                 IF xold THEN
  393.                     LINE (x, y)-(x + 9, y + 10), black, BF
  394.                 END IF
  395.  
  396.               ' Show the mouse cursor
  397.                 MouseCursor show
  398.  
  399.               ' Get status of the right mouse button
  400.                 RightButton press, rightRelease, now
  401.  
  402.               ' If right button then reset mouse motion limits
  403.                 IF rightRelease THEN
  404.                     IF xmax = 320 THEN
  405.                         MouseWindow 0, 0, xmax * 2 - 2, ymax - 1
  406.                     ELSE
  407.                         MouseWindow 0, 0, xmax - 1, ymax - 1
  408.                     END IF
  409.                 END IF
  410.  
  411.               ' Clear out the eraser image location
  412.                 xold = 0
  413.                 yold = 0
  414.  
  415.             END IF
  416.  
  417.         LOOP UNTIL rightRelease
  418.  
  419.     END SUB
  420.  
  421.   '-------------------------------------
  422.   ' Get status of the left mouse button
  423.   '-------------------------------------
  424.     SUB LeftButton (press, release, now) STATIC
  425.  
  426.         m1 = 5  'Get Button Press Information
  427.         m2 = 0  'For the left button
  428.         Mouse m1, m2, m3, m4
  429.  
  430.         press = m2              'Presses returned in M2
  431.  
  432.         m1 = 6  'Get Button Release Information
  433.         m2 = 0  'For the left button
  434.         Mouse m1, m2, m3, m4
  435.  
  436.         release = m2            'Releases returned in M2
  437.         now = m1 AND 1          'Bit 0 = left button pressed
  438.  
  439.     END SUB
  440.  
  441.   '-------------------------------
  442.   ' Show or hide the mouse cursor
  443.   '-------------------------------
  444.     SUB MouseCursor (switch) STATIC
  445.  
  446.       ' If switch is non-zero then show the cursor, else hide it
  447.         IF switch THEN
  448.             m1 = 1
  449.         ELSE
  450.             m1 = 2
  451.         END IF
  452.  
  453.         Mouse m1, m2, m3, m4
  454.  
  455.     END SUB
  456.  
  457.   '-------------------------------------------------------------
  458.   ' Get the current mouse position (virtual screen coordinates)
  459.   '-------------------------------------------------------------
  460.     SUB MousePosition (x, y) STATIC
  461.         m1 = 3  'Get Button Status and Mouse Position
  462.         Mouse m1, m2, x, y
  463.     END SUB
  464.  
  465.   '------------------------
  466.   ' Mouse Reset and Status
  467.   '------------------------
  468.     SUB MouseReset STATIC
  469.  
  470.         m1 = 0  'Mouse Function 0
  471.         Mouse m1, m2, m3, m4
  472.  
  473.       ' Was mouse found?
  474.         IF m1 = 0 THEN
  475.             PRINT "Mouse not found"
  476.             SYSTEM
  477.         END IF
  478.  
  479.     END SUB
  480.  
  481.   '----------------------------------------------------------
  482.   ' Set mouse motion limits using virtual screen coordinates
  483.   '----------------------------------------------------------
  484.     SUB MouseWindow (minX, minY, maxX, maxY) STATIC
  485.  
  486.       'Set Minimum and Maximum Horizontal Cursor Position
  487.         m1 = 7
  488.         Mouse m1, m2, minX, maxX
  489.  
  490.       'Set Minimum and Maximum Vertical Cursor Position
  491.         m1 = 8
  492.         Mouse m1, m2, minY, maxY
  493.  
  494.     END SUB
  495.  
  496.   '----------------------------------------------------------------
  497.   ' Creates pencil mouse cursor, draws lines while left button is
  498.   ' pressed, and returns to the menu when right button is released
  499.   '----------------------------------------------------------------
  500.     SUB Pencil
  501.  
  502.       ' Limit mouse motion, adjusted for virtual screen
  503.         IF xmax = 320 THEN
  504.             MouseWindow 4, 2, xmax * 2 - 6, ymax - 3
  505.         ELSE
  506.             MouseWindow 3, 3, xmax - 4, ymax - 4
  507.         END IF
  508.  
  509.       ' Set the Pencil cursor
  510.         DrawCursor PencilCursor
  511.  
  512.       ' Processing loop, until right button is released
  513.         DO
  514.  
  515.           ' Get status of left mouse button
  516.             LeftButton press, release, now
  517.  
  518.           ' Is left mouse button now pressed?
  519.             IF now THEN
  520.  
  521.               ' Get current mouse position
  522.                 MousePosition x, y
  523.  
  524.               ' Adjust for virtual vs. physical screen
  525.                 IF xmax = 320 THEN
  526.                     x = x \ 2
  527.                 END IF
  528.  
  529.               ' Continue drawing line if started
  530.                 IF xold THEN
  531.                     LINE (xold, yold)-(x, y)
  532.  
  533.                   ' If just starting a line then hide the pencil
  534.                 ELSE
  535.                     MouseCursor hide
  536.                 END IF
  537.  
  538.               ' Record current line endpoint
  539.                 xold = x
  540.                 yold = y
  541.  
  542.               ' Left mouse button is not now pressed
  543.             ELSE
  544.  
  545.               ' Clear out line endpoint
  546.                 xold = 0
  547.  
  548.               ' Show the pencil
  549.                 MouseCursor show
  550.  
  551.               ' Get status of right mouse button
  552.                 RightButton press, release, now
  553.  
  554.               ' If right button released reset mouse limits
  555.                 IF release THEN
  556.                     IF xmax = 320 THEN
  557.                         MouseWindow 0, 0, xmax * 2 - 2, ymax - 1
  558.                     ELSE
  559.                         MouseWindow 0, 0, xmax - 1, ymax - 1
  560.                     END IF
  561.                 END IF
  562.  
  563.             END IF
  564.  
  565.         LOOP UNTIL release
  566.  
  567.     END SUB
  568.  
  569.   '--------------------------------------------
  570.   ' Draw one of the three menu selection boxes
  571.   '--------------------------------------------
  572.     SUB PopUpMenu (menuselect, attribute) STATIC
  573.  
  574.       ' One selection only will be highlighted
  575.         IF attribute = InverseColor THEN
  576.             fillcolor = white
  577.         ELSE
  578.             fillcolor = black
  579.         END IF
  580.  
  581.       ' Which item is being drawn?
  582.         SELECT CASE menuselect
  583.  
  584.         CASE PencilMenu
  585.  
  586.           ' Determine box corners
  587.             x1 = 1
  588.             y1 = 1
  589.             x2 = xmax \ 3 - 1
  590.             y2 = ymax \ 10 - 1
  591.  
  592.           ' Draw solid rectangle
  593.             LINE (x1, y1)-(x2, y2), fillcolor, BF
  594.  
  595.           ' Locate label, adjusted for virtual vs. physical screen
  596.             IF xmax = 320 THEN
  597.                 LOCATE 2, 5
  598.             ELSE
  599.                 LOCATE 2, 11
  600.             END IF
  601.  
  602.           ' Label the menu item
  603.             PRINT "Pencil";
  604.  
  605.         CASE EraserMenu
  606.  
  607.           ' Determine box corners
  608.             x1 = xmax \ 3 + 1
  609.             y1 = 1
  610.             x2 = (xmax \ 3) * 2 - 1
  611.             y2 = ymax \ 10 - 1
  612.  
  613.           ' Draw solid rectangle
  614.             LINE (x1, y1)-(x2, y2), fillcolor, BF
  615.  
  616.           ' Locate label, adjusted for virtual vs. physical screen
  617.             IF xmax = 320 THEN
  618.                 LOCATE 2, 18
  619.             ELSE
  620.                 LOCATE 2, 37
  621.             END IF
  622.  
  623.           ' Label the menu item
  624.             PRINT "Eraser";
  625.  
  626.         CASE ELSE
  627.  
  628.           ' Determine box corners
  629.             x1 = (xmax \ 3) * 2 + 1
  630.             y1 = 1
  631.             x2 = xmax - 2
  632.             y2 = ymax \ 10 - 1
  633.  
  634.           ' Draw solid rectangle
  635.             LINE (x1, y1)-(x2, y2), fillcolor, BF
  636.  
  637.           ' Locate label, adjusted for virtual vs. physical screen
  638.             IF xmax = 320 THEN
  639.                 LOCATE 2, 32
  640.             ELSE
  641.                 LOCATE 2, 65
  642.             END IF
  643.  
  644.           ' Label the menu item
  645.             PRINT "QUIT";
  646.  
  647.         END SELECT
  648.  
  649.     END SUB
  650.  
  651.   '--------------------------------------
  652.   ' Get status of the right mouse button
  653.   '--------------------------------------
  654.     SUB RightButton (press, release, now) STATIC
  655.  
  656.         m1 = 5  'Get Button Press Information
  657.         m2 = 1  'For the right button
  658.         Mouse m1, m2, m3, m4
  659.  
  660.         press = m2              'Presses returned in M2
  661.  
  662.         m1 = 6  'Get Button Release Information
  663.         m2 = 1  'For the right button
  664.         Mouse m1, m2, m3, m4
  665.  
  666.         release = m2            'Releases returned in M2
  667.         now = m1 AND 2          'Bit 1 = right button pressed
  668.  
  669.     END SUB
  670.  
  671.