home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / basic / mlib30 / mlibdata.bas < prev    next >
Encoding:
BASIC Source File  |  1994-02-21  |  10.4 KB  |  242 lines

  1.  DEFINT A-Z
  2.  '============================== MLIBDATA.BAS================================
  3.  '                  THIS SAMPLE PROGRAM IS PROVIDED AS IS.
  4.  '
  5.  ' You may modify/use this code in any way you wish, provided that you agree
  6.  ' that Terry Venn has no warranties, obligations or liabilities for any code
  7.  ' contained in this sample program.
  8.  '
  9.  ' MLIBDATA.BAS is a sample program that converts raw binary pointer shape
  10.  ' information into BASIC's DATA statements, which can be used in your code
  11.  ' for changing shapes.
  12.  '
  13.  ' QB refers to: QuickBasic 4.5
  14.  ' VBDOS refers to: Visual Basic for DOS
  15.  '
  16.  ' To run this sample program from inside the QB environment, start the QB
  17.  ' editor by typing: QB/L MLIBN
  18.  '
  19.  ' To run this sample program from inside the VBDOS environment, start the
  20.  ' editor by typing: VBDOS/L MLIBF
  21.  '
  22.  ' QuickBasic and Visual Basic are trademarks of Microsoft Corporation.
  23.  '===========================================================================
  24.  
  25.  ' $INCLUDE: 'MLIB.BI'
  26.  
  27. DECLARE SUB ReadData ()
  28. DECLARE SUB Target ()
  29. DECLARE SUB GetInput (SHP$, DAT$, RNum%)
  30. DECLARE SUB Cvt2Data (SHP$, DAT$, RNum%)
  31.  
  32. '============================================================================
  33.                                                  '
  34. SCREEN 12: CLS : CALL InitPointer(NumBut%)       '
  35.                                                  '
  36. IF NumBut% = 0 THEN SCREEN 0: END                'No mouse.
  37.                                                  '
  38. CALL GetInput(SHP$, DAT$, RNum%)                 'User input.
  39.                                                  '
  40. CALL Cvt2Data(SHP$, DAT$, RNum%)                 'Convert to DATA statements.
  41.                                                  '
  42. CALL ReadData                                    'Convert DATA into a shape.
  43.                                                  '
  44. CLS : CALL Target                                'Draw a background.
  45.                                                  '
  46. PRINT "  <DATA created pointer shape shown.>";   '
  47.                                                  '
  48. PRINT "                <Press a key to end.>"    '
  49.                                                  '
  50. CALL ShowPointer                                 '
  51.                                                  '
  52. DO: LOOP UNTIL LEN(INKEY$)                       '
  53.                                                  '
  54. SCREEN 0: END                                    '
  55.                                                  '
  56. '============================================================================
  57.  
  58. '=======================< Example output of this program >===================
  59.  
  60. 'The first 2 data constants (in each block) contain the hot spot x,y values.
  61. 'You must copy and paste your own to display other shapes.
  62. 'Just run this demo, next ALT+F+L oad DATA filename, copy and paste it here.
  63. 'Subroutine ReadData() converts this DATA back into a pointer shape.
  64.  
  65. 'Arrow pointer, in SOLID format.
  66. 'REM this DATA block to show next shape.
  67.  
  68. 'Source      : MLIBSAM.SHP
  69. 'Destination : DATA.DAT
  70. 'Record      : 1
  71. 'Format      : SOLID
  72. DATA &H0,&H0,&H3FFF,&HFFF,&H3FF,&HFF,&H3F,&HF,&H3
  73. DATA &H1,&H3F,&H81F,&H1C0F,&H3E07,&H7F03,&HFF83,&HFFC7,&HFFFF
  74. DATA &H0,&H4000,&H7000,&H7C00,&H7F00,&H7FC0,&H7FF0,&H7F00,&H6780
  75. DATA &H43C0,&H1E0,&HF0,&H78,&H38,&H0,&H0
  76.  
  77. 'Arrow pointer, in TRANSparent format.
  78.  
  79. 'Source      : MLIBSAM.SHP
  80. 'Destination : DATA.DAT
  81. 'Record      : 19
  82. 'Format      : TRANS
  83. DATA &H0,&H0,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF
  84. DATA &HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF,&HFFFF
  85. DATA &HC000,&HF000,&HFC00,&HFF00,&HFFC0,&HFFF0,&HFFFC,&HFFFE,&HFFC0
  86. DATA &HF7E0,&HE3F0,&HC1F8,&H80FC,&H7C,&H38,&H0
  87.  
  88. '============================================================================
  89.  
  90. SUB Cvt2Data (SHP$, DAT$, RNum%)
  91.  
  92. FH1% = FREEFILE: OPEN SHP$ FOR BINARY AS #FH1%   '
  93. FH2% = FREEFILE: OPEN DAT$ FOR OUTPUT AS #FH2%   'Sequential output.
  94. EndData% = RNum% * 80 - 1                        'Calculate end of data, work
  95. StartData% = EndData% - 62                       'backwards.Why? Because.
  96. Xoff% = StartData% - 14                          'Hot spot X offset.
  97. Yoff% = Xoff% + 2                                'Hot spot Y offset.
  98.                                                  '
  99. DIM Format AS STRING * 10: CLS                     '
  100.                                                  '
  101. RNum% = RNum% - 1                                'Get actual record.
  102. GET #FH1%, Xoff%, HotX%                          'Get the hot spots.
  103. GET #FH1%, Yoff%, HotY%                          '
  104. GET #FH1%, Yoff% + 2, Format                     'Solid or Transparent shape.
  105.                                                  '
  106. PRINT #FH2%, "'Source      : "; SHP$             'Print to file.
  107. PRINT #FH2%, "'Destination : "; DAT$
  108. PRINT #FH2%, "'Record      :"; RNum%
  109. PRINT #FH2%, "'Format      : "; Format
  110. PRINT #FH2%, "DATA "; "&H"; HEX$(HotX%); ","; "&H"; HEX$(HotY%);
  111.  
  112. PRINT "'Source      : "; SHP$                    'Print to screen.
  113. PRINT "'Destination : "; DAT$
  114. PRINT "'Record      :"; RNum%
  115. PRINT "'Format      : "; Format
  116. PRINT "DATA "; "&H"; HEX$(HotX%); ","; "&H"; HEX$(HotY%);
  117. Cntr% = 2
  118.  
  119. FOR OffSet% = StartData% TO EndData% STEP 2      '64 bytes.
  120.  
  121.   Cntr% = Cntr% + 1
  122.   GET #FH1%, OffSet%, Get2Byte%
  123.   SHPDAT$ = SHPDAT$ + MKI$(Get2Byte%)
  124.  
  125.   SELECT CASE Cntr%
  126.      CASE IS = 1
  127.         PRINT #FH2%, "DATA "; "&H"; HEX$(Get2Byte%);
  128.         PRINT "DATA "; "&H"; HEX$(Get2Byte%);
  129.      CASE IS <= 8
  130.         PRINT #FH2%, ","; ; "&H"; HEX$(Get2Byte%);
  131.         PRINT ","; "&H"; HEX$(Get2Byte%);
  132.      CASE IS > 8
  133.         PRINT #FH2%, ","; ; "&H"; HEX$(Get2Byte%)
  134.         PRINT ","; "&H"; HEX$(Get2Byte%)
  135.         Cntr% = 0
  136.   END SELECT
  137.  
  138. NEXT OffSet%
  139.  
  140. CLOSE
  141. PRINT : PRINT : PRINT "Converted pointer shape shown."
  142. PRINT : PRINT : PRINT "Press a key to continue."
  143.  
  144. ShowPointer                                      'Show the shape that was
  145. CALL ChangePointer(SHPDAT$, HotX%, HotY%)        'just converted to DATA
  146. Hold$ = INPUT$(1): HidePointer                   'statements.
  147.  
  148. END SUB
  149.  
  150. SUB GetInput (SHP$, DAT$, RNum%)
  151.  
  152. TryAgain1:
  153.  
  154. PRINT "               ┌───────────────────────────────────────────────────┐"
  155. PRINT "               │                                                   │"
  156. PRINT "               │       Source: Name of the [XXX.SHP] file that     │"
  157. PRINT "               │               contains the shape information      │"
  158. PRINT "               │               to convert to DATA statements.      │"
  159. PRINT "               │                                                   │"
  160. PRINT "               │               NOTE! You must supply the complete  │"
  161. PRINT "               │               filename.                           │"
  162. PRINT "               │                                                   │"
  163. PRINT "               │  Destination: Name of the output file that will   │"
  164. PRINT "               │               hold the DATA statements.           │"
  165. PRINT "               │                                                   │"
  166. PRINT "               │                                                   │"
  167. PRINT "               │ Shape number: Number of the desired shape.        │"
  168. PRINT "               │               (Run MLIBVIEW.BAS to get number)    │"
  169. PRINT "               │                                                   │"
  170. PRINT "               └───────────────────────────────────────────────────┘"
  171.  
  172.  
  173. INPUT "Source       <ENTER=[MLIBSAM.SHP]> : "; SHP$ 'File to open.
  174. INPUT "Destination  <ENTER=[DATA.DAT]> : "; DAT$ 'Data output file.
  175.                                                  '
  176. IF LEN(SHP$) = 0 THEN SHP$ = "MLIBSAM.SHP"       '
  177. IF LEN(DAT$) = 0 THEN DAT$ = "DATA.DAT"          '
  178.                                                  '
  179. FH% = FREEFILE                                   '
  180. OPEN SHP$ FOR INPUT AS #FH%                      '
  181.                                                  '
  182. MaxRec% = (LOF(FH%) \ 80) - 1: CLOSE             'Calculate number of records,
  183.                                                  'minus 1, header not counted.
  184. TryAgain:                                        '
  185.                                                  '
  186. PRINT "Shape number < 1 -"; MaxRec%; ">  : ";    'Get which record...
  187.                                                  '
  188. INPUT RNum%                                      '
  189.                                                  '
  190. IF RNum% <= 0 THEN                               '
  191.    PRINT "Bad shape number.  Redo..."            '
  192.    GOTO TryAgain                                 '
  193. ELSEIF RNum > MaxRec% THEN                       'Passed end of file.
  194.    PRINT "Bad shape number.  Redo..."            '
  195.    GOTO TryAgain                                 '
  196. END IF                                           '
  197.                                                  '
  198. RNum% = RNum% + 1                                'Skip over header.
  199.                                                  '
  200. END SUB                                          '
  201.  
  202. '
  203. '****************************************************************************
  204. '*                                                                          *
  205. '* Read the shape DATA into SHPDAT$, then tell the Changepointer            *
  206. '* routine to change the mouse cursor to the new shape.                     *
  207. '*                                                                          *
  208. '****************************************************************************
  209. '
  210. SUB ReadData
  211.  
  212. '============================================================================
  213.  
  214. READ HotX%, HotY%                                'First 2 statements are
  215.                                                  'X and Y hot spots.
  216. FOR xdata = 1 TO 32                              '
  217.    READ SHPdata%                                 '
  218.    SHPDAT$ = SHPDAT$ + MKI$(SHPdata%)            'Build data string.
  219. NEXT xdata                                       '
  220.                                                  '
  221. CALL ChangePointer(SHPDAT$, HotX%, HotY%)        'Change it.
  222.                                                  '
  223. '============================================================================
  224.  
  225. END SUB
  226.  
  227. SUB Target
  228.  
  229. LINE (15, 16)-(615, 465), 15, BF
  230.                                                
  231. Colr% = 0
  232. FOR Size% = 220 TO 20 STEP -20
  233.  
  234.    Colr% = Colr% + 1
  235.    CIRCLE (320, 240), Size%, Colr%
  236.    PAINT (320, 240), Colr%, Colr%
  237.  
  238. NEXT
  239.  
  240. END SUB
  241.  
  242.