home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH8 / SRC / TILEHEX.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-12  |  6.0 KB  |  202 lines

  1. VERSION 4.00
  2. Begin VB.Form TileForm 
  3.    Caption         =   "Tile"
  4.    ClientHeight    =   4350
  5.    ClientLeft      =   1740
  6.    ClientTop       =   1185
  7.    ClientWidth     =   5535
  8.    Height          =   5040
  9.    Left            =   1680
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   290
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   369
  14.    Top             =   555
  15.    Width           =   5655
  16.    Begin VB.PictureBox Canvas 
  17.       AutoRedraw      =   -1  'True
  18.       Height          =   4335
  19.       Left            =   1200
  20.       ScaleHeight     =   285
  21.       ScaleMode       =   3  'Pixel
  22.       ScaleWidth      =   285
  23.       TabIndex        =   0
  24.       Top             =   0
  25.       Width           =   4335
  26.    End
  27.    Begin VB.Image Tile 
  28.       Height          =   405
  29.       Index           =   4
  30.       Left            =   0
  31.       Picture         =   "TileHex.frx":0000
  32.       Top             =   3240
  33.       Width           =   465
  34.    End
  35.    Begin VB.Image Mask 
  36.       Height          =   405
  37.       Index           =   4
  38.       Left            =   600
  39.       Picture         =   "TileHex.frx":07A2
  40.       Top             =   3240
  41.       Visible         =   0   'False
  42.       Width           =   465
  43.    End
  44.    Begin VB.Image Mask 
  45.       Height          =   405
  46.       Index           =   3
  47.       Left            =   600
  48.       Picture         =   "TileHex.frx":0F44
  49.       Top             =   2760
  50.       Visible         =   0   'False
  51.       Width           =   465
  52.    End
  53.    Begin VB.Image Tile 
  54.       Height          =   405
  55.       Index           =   3
  56.       Left            =   0
  57.       Picture         =   "TileHex.frx":16E6
  58.       Top             =   2760
  59.       Width           =   465
  60.    End
  61.    Begin VB.Image Tile 
  62.       Height          =   735
  63.       Index           =   2
  64.       Left            =   0
  65.       Picture         =   "TileHex.frx":1E88
  66.       Top             =   1920
  67.       Width           =   735
  68.    End
  69.    Begin VB.Image Mask 
  70.       Height          =   735
  71.       Index           =   2
  72.       Left            =   840
  73.       Picture         =   "TileHex.frx":2CBE
  74.       Top             =   1920
  75.       Visible         =   0   'False
  76.       Width           =   735
  77.    End
  78.    Begin VB.Image Tile 
  79.       Height          =   735
  80.       Index           =   1
  81.       Left            =   0
  82.       Picture         =   "TileHex.frx":3AF4
  83.       Top             =   1080
  84.       Width           =   735
  85.    End
  86.    Begin VB.Image Mask 
  87.       Height          =   735
  88.       Index           =   1
  89.       Left            =   840
  90.       Picture         =   "TileHex.frx":492A
  91.       Top             =   1080
  92.       Visible         =   0   'False
  93.       Width           =   735
  94.    End
  95.    Begin VB.Image Mask 
  96.       Height          =   975
  97.       Index           =   0
  98.       Left            =   840
  99.       Picture         =   "TileHex.frx":5760
  100.       Top             =   0
  101.       Visible         =   0   'False
  102.       Width           =   1110
  103.    End
  104.    Begin VB.Image Tile 
  105.       Height          =   975
  106.       Index           =   0
  107.       Left            =   0
  108.       Picture         =   "TileHex.frx":5AB6
  109.       Top             =   0
  110.       Width           =   1110
  111.    End
  112.    Begin VB.Menu mnuFile 
  113.       Caption         =   "&File"
  114.       Begin VB.Menu mnuFileExit 
  115.          Caption         =   "E&xit"
  116.       End
  117.    End
  118. Attribute VB_Name = "TileForm"
  119. Attribute VB_Creatable = False
  120. Attribute VB_Exposed = False
  121. Option Explicit
  122. Const MAX_TILE = 4
  123. Const MERGEPAINT = &HBB0226
  124. Const SRCAND = &H8800C6
  125. Dim TileChoice As Integer
  126. Dim ColDx(0 To MAX_TILE) As Integer
  127. Dim RowDx(0 To MAX_TILE) As Integer
  128. Dim RowDy(0 To MAX_TILE) As Integer
  129. ' ************************************************
  130. ' Tile the control with the Tile.
  131. ' ************************************************
  132. Sub TilePicture(pic As PictureBox, tile_image As Image, mask_image As Image, cdx As Integer, rdx As Integer, rdy As Integer)
  133. Dim x As Integer
  134. Dim y As Integer
  135. Dim x1 As Integer
  136. Dim x2 As Integer
  137. Dim startx As Integer
  138.     pic.Cls     ' Clear the picture box.
  139.     ' Start above and to the left of the drawing area.
  140.     y = -tile_image.Height
  141.     x1 = -tile_image.Width
  142.     x2 = x1 + rdx
  143.     startx = x1
  144.     ' Copy the tile until we're to the right and
  145.     ' below the drawing area.
  146.     Do While y <= pic.ScaleHeight
  147.         x = startx
  148.         Do While x <= pic.ScaleWidth
  149.             ' Copy the mask with MERGEPAINT.
  150.             pic.PaintPicture mask_image.Picture, x, y, , , , , , , MERGEPAINT
  151.             
  152.             ' Copy the mask with SRCAND.
  153.             pic.PaintPicture tile_image.Picture, x, y, , , , , , , SRCAND
  154.             x = x + cdx
  155.         Loop
  156.         If startx = x1 Then
  157.             startx = x2
  158.         Else
  159.             startx = x1
  160.         End If
  161.         y = y + rdy
  162.     Loop
  163. End Sub
  164. ' ************************************************
  165. ' Initialize row and column offsets.
  166. ' ************************************************
  167. Private Sub Form_Load()
  168.     ColDx(0) = 108
  169.     RowDx(0) = 54
  170.     RowDy(0) = 31
  171.     ColDx(1) = 72
  172.     RowDx(1) = 35
  173.     RowDy(1) = 20
  174.     ColDx(2) = ColDx(1)
  175.     RowDx(2) = RowDx(1)
  176.     RowDy(2) = RowDy(1)
  177.     ColDx(3) = ColDx(1)
  178.     RowDx(3) = RowDx(1)
  179.     RowDy(3) = RowDy(1)
  180.     ColDx(4) = 46
  181.     RowDx(4) = 23
  182.     RowDy(4) = 13
  183. End Sub
  184. ' ************************************************
  185. ' Tile the form.
  186. ' ************************************************
  187. Private Sub Form_Resize()
  188.     Canvas.Move Canvas.Left, 0, _
  189.         TileForm.ScaleWidth - Canvas.Left, _
  190.         TileForm.ScaleHeight
  191.     TilePicture Canvas, Tile(TileChoice), Mask(TileChoice), ColDx(TileChoice), RowDx(TileChoice), RowDy(TileChoice)
  192. End Sub
  193. Private Sub mnuFileExit_Click()
  194.     Unload Me
  195. End Sub
  196. Private Sub Tile_Click(Index As Integer)
  197.     MousePointer = vbHourglass
  198.     TileChoice = Index
  199.     TilePicture Canvas, Tile(TileChoice), Mask(TileChoice), ColDx(TileChoice), RowDx(TileChoice), RowDy(TileChoice)
  200.     MousePointer = vbDefault
  201. End Sub
  202.