home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH7 / SRC / OBJ1PICT.CLS < prev    next >
Encoding:
Text File  |  1995-10-26  |  3.0 KB  |  111 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "ObjPicture"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. Option Explicit
  9.  
  10. Public Objects As New Collection
  11. ' ************************************************
  12. ' Compute the world coordinate bounds for the
  13. ' picture.
  14. ' ************************************************
  15. Sub Bound(xmin As Single, ymin As Single, xmax As Single, ymax As Single)
  16. Dim x1 As Single
  17. Dim y1 As Single
  18. Dim x2 As Single
  19. Dim y2 As Single
  20. Dim obj As Object
  21. Dim i As Integer
  22.  
  23.     If Objects.Count < 1 Then
  24.         xmin = 0
  25.         xmax = 1
  26.         ymin = 0
  27.         ymax = 1
  28.         Exit Sub
  29.     End If
  30.     
  31.     Set obj = Objects.Item(1)
  32.     obj.Bound xmin, ymin, xmax, ymax
  33.     
  34.     For i = 2 To Objects.Count
  35.         Set obj = Objects.Item(i)
  36.         obj.Bound x1, y1, x2, y2
  37.         If x1 < xmin Then xmin = x1
  38.         If y1 < ymin Then ymin = y1
  39.         If x2 > xmax Then xmax = x2
  40.         If y2 > ymax Then ymax = y2
  41.     Next i
  42. End Sub
  43. ' ************************************************
  44. ' Read the picture from a file using Input.
  45. ' ************************************************
  46. Sub FileInput(filenum As Integer)
  47. Dim num As Integer
  48. Dim i As Integer
  49. Dim obj As Object
  50. Dim obj_type As String
  51.  
  52.     ' Read the number of objects in the file.
  53.     Input #filenum, num
  54.     
  55.     ' Repeatedly read objects from the file.
  56.     For i = 1 To num
  57.         Input #filenum, obj_type
  58.         Select Case obj_type
  59.             Case "APF PICTURE"
  60.                 Set obj = New ObjPicture
  61.             Case "LINE"
  62.                 Set obj = New ObjLine
  63.             Case "RECTANGLE"
  64.                 Set obj = New ObjRectangle
  65.             Case "SQUARE"
  66.                 Set obj = New ObjSquare
  67.             Case "POLYGON"
  68.                 Set obj = New ObjPolygon
  69.             Case "CIRCLE"
  70.                 Set obj = New ObjCircle
  71.             Case "ARC"
  72.                 Set obj = New ObjArc
  73.             Case Else
  74.                 Beep
  75.                 MsgBox "Unknown object type """ & obj_type & """.", , vbExclamation
  76.                 Exit Sub
  77.         End Select
  78.         obj.FileInput filenum
  79.         Objects.Add obj
  80.     Next i
  81. End Sub
  82. Function ObjectType() As String
  83.     ObjectType = "APF PICTURE"
  84. End Function
  85. ' ************************************************
  86. ' Draw the picture on a Form, Printer, or
  87. ' PictureBox.
  88. ' ************************************************
  89. Sub Draw(canvas As Object)
  90. Dim obj As Object
  91.  
  92.     For Each obj In Objects
  93.         obj.Draw canvas
  94.     Next obj
  95. End Sub
  96. ' ************************************************
  97. ' Write the picture to a file using Write.
  98. ' Begin with "APF PICTURE" to identify this object.
  99. ' ************************************************
  100. Sub FileWrite(filenum As Integer)
  101. Dim obj As Object
  102.  
  103.     Write #filenum, "APF PICTURE"
  104.     Write #filenum, Objects.Count
  105.     
  106.     For Each obj In Objects
  107.         obj.FileWrite filenum
  108.     Next obj
  109. End Sub
  110.  
  111.