home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Update_wid2141181222009.psc / LineGS.cls < prev    next >
Text File  |  2009-01-12  |  28KB  |  943 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "LineGS"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  16. Attribute VB_Ext_KEY = "Member0" ,"SmoothLineDIB"
  17. Option Explicit
  18.  
  19. 'Original TMT Pascal/Asm code by Jonas Widarsson
  20. '
  21. 'Implemented in Vb6 by Dana Seaman
  22. 'Send comments/bug reports to dseaman@ieg.com.br
  23. '
  24. Public Enum cThickness
  25.    Thin
  26.    Thick
  27. End Enum
  28. Private Type RGBQUAD
  29.    Blue                 As Byte
  30.    Green                As Byte
  31.    Red                  As Byte
  32.    Reserved             As Byte
  33. End Type
  34.  
  35. Private Type BITMAPINFOHEADER
  36.    biSize               As Long
  37.    biWidth              As Long
  38.    biHeight             As Long
  39.    biPlanes             As Integer
  40.    biBitCount           As Integer
  41.    biCompression        As Long
  42.    biSizeImage          As Long
  43.    biXPelsPerMeter      As Long
  44.    biYPelsPerMeter      As Long
  45.    biClrUsed            As Long
  46.    biClrImportant       As Long
  47. End Type
  48.  
  49. Private Type BITMAPINFO
  50.    bmiHeader            As BITMAPINFOHEADER
  51. End Type
  52.  
  53. Private Type RECT
  54.    Left     As Long
  55.    Top      As Long
  56.    Right    As Long
  57.    Bottom   As Long
  58. End Type
  59.  
  60. Private Const DIB_RGB_COLORS As Long = 0
  61. Private Const Pi        As Single = 3.141592
  62. Private Const HalfPi    As Single = Pi / 2
  63. Private Const cThin     As Single = Pi * 0.34
  64. Private Const cThick    As Single = Pi * 0.17
  65. Private Const Rads      As Single = Pi / 180
  66. Private Const PS_SOLID  As Long = 0
  67.  
  68. Private Binfo           As BITMAPINFO
  69. Private buf()           As RGBQUAD
  70. Private InDIBits        As Boolean
  71. Private Red             As Long
  72. Private Green           As Long
  73. Private Blue            As Long
  74. Private m_Color         As Long
  75. Private m_hDC           As Long
  76. Private m_W1            As Long
  77. Private m_H1            As Long
  78. Private m_Handle        As Long
  79.  
  80. Private Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long
  81. Private Declare Function OleTranslateColor Lib "OLEPRO32.DLL" (ByVal OLE_COLOR As Long, ByVal HPALETTE As Long, pccolorref As Long) As Long
  82. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
  83. Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
  84. Private Declare Function GetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
  85. Private Declare Function SetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
  86.  
  87. 'Public Sub Widget(rct As RECT)
  88.  
  89. 'End Sub
  90. Private Function TranslateColour(ByVal clr As OLE_COLOR, _
  91.    Optional hPal As Long = 0) As Long
  92.    If OleTranslateColor(clr, hPal, TranslateColour) Then
  93.       TranslateColour = vbBlack 'CLR_INVALID
  94.    End If
  95. End Function
  96.  
  97. Public Sub DIB(ByVal hdc As Long, ByVal Handle As Long, ByVal W1 As Long, ByVal H1 As Long)
  98.    m_hDC = hdc
  99.    m_Handle = Handle
  100.    m_W1 = W1
  101.    m_H1 = H1
  102.    Pic2Array
  103. End Sub
  104.  
  105. Private Sub Pic2Array()
  106.    ReDim buf(0 To (m_W1 - 1), m_H1 - 1) As RGBQUAD
  107.    With Binfo.bmiHeader
  108.       .biSize = 40
  109.       .biWidth = m_W1
  110.       .biHeight = -m_H1
  111.       .biPlanes = 1
  112.       .biBitCount = 32
  113.       .biCompression = 0
  114.       .biClrUsed = 0
  115.       .biClrImportant = 0
  116.       .biSizeImage = m_W1 * m_H1
  117.    End With
  118.    'Copy hDC to Array
  119.    GetDIBits m_hDC, m_Handle, 0, m_H1, buf(0, 0), Binfo, DIB_RGB_COLORS
  120.    'Set local flag
  121.    InDIBits = True
  122. End Sub
  123.  
  124. Public Sub CircleGP(ByVal hdc As Long, _
  125.    ByVal X1 As Long, _
  126.    ByVal Y1 As Long, _
  127.    ByVal RadiusX As Long, _
  128.    ByVal RadiusY As Long, _
  129.    ByVal Color As OLE_COLOR, _
  130.    Optional ByVal Thickness As cThickness = Thick)
  131.  
  132.    Dim Bbg              As Byte
  133.    Dim Gbg              As Byte
  134.    Dim Rbg              As Byte
  135.    Dim savAlpha(1 To 4) As Byte
  136.    Dim Bblend           As Long
  137.    Dim Bgr              As Long
  138.    Dim Cl               As Long
  139.    Dim Gblend           As Long
  140.    Dim Strength         As Long
  141.    Dim StrengthI        As Long
  142.    Dim Quadrant         As Long
  143.    Dim Radius           As Long
  144.    Dim Rblend           As Long
  145.    Dim RX1              As Long
  146.    Dim RX2              As Long
  147.    Dim RY1              As Long
  148.    Dim RY2              As Long
  149.    Dim savX(1 To 4)     As Long
  150.    Dim savY(1 To 4)     As Long
  151.    Dim X4               As Long
  152.    Dim Y4               As Long
  153.    Dim NewColor         As Long
  154.    Dim Ax               As Single
  155.    Dim Ay               As Single
  156.    Dim Bx               As Single
  157.    Dim By               As Single
  158.    Dim L1               As Single
  159.    Dim L2               As Single
  160.    Dim L3               As Single
  161.    Dim L4               As Single
  162.    Dim sngAngle         As Single
  163.    Dim sngPointSpacing  As Single
  164.    Dim X2               As Single
  165.    Dim Xp5              As Single
  166.    Dim Y2               As Single
  167.  
  168.    m_hDC = hdc
  169.  
  170.    SetRGBComponents Color
  171.  
  172.    Radius = RadiusX
  173.    If RadiusY > RadiusX Then
  174.       Radius = RadiusY
  175.    End If
  176.  
  177.    sngPointSpacing = GetPointSpacing(Radius, Thickness)
  178.  
  179.    For sngAngle = 0 To HalfPi Step sngPointSpacing
  180.       X2 = RadiusX * Cos(sngAngle)
  181.       Y2 = RadiusY * Sin(sngAngle)
  182.       'Prevents error when vb rounds .5 down
  183.       If X2 = Int(X2) Then X2 = X2 + 0.001
  184.       If Y2 = Int(Y2) Then Y2 = Y2 + 0.001
  185.       For Quadrant = 0 To 3
  186.          Select Case Quadrant
  187.             Case 0 '0-90░
  188.                Ax = X2 + X1 - 0.5
  189.                Ay = -Y2 + Y1 - 0.5
  190.             Case 1 '90-180░
  191.                Ax = X2 + X1 - 0.5
  192.                Ay = Y2 + Y1 - 0.5
  193.             Case 2 '180-270░
  194.                Ax = -X2 + X1 - 0.5
  195.                Ay = Y2 + Y1 - 0.5
  196.             Case 3 '270-360░
  197.                Ax = -X2 + X1 - 0.5
  198.                Ay = -Y2 + Y1 - 0.5
  199.          End Select
  200.          Bx = Ax + 1
  201.          By = Ay + 1
  202.          RX1 = Ax
  203.          RX2 = RX1 + 1
  204.          Xp5 = RX1 + 0.5
  205.          RY1 = Ay
  206.          RY2 = By
  207.          L1 = RY1 + 0.5 - Ay
  208.          L2 = 256 * (Xp5 - Ax) - Xp5 + Ax
  209.          L3 = 255 - L2
  210.          L4 = By - RY2 + 0.5
  211.          savX(1) = RX1
  212.          savY(1) = RY1
  213.          savX(2) = RX2
  214.          savY(2) = RY1
  215.          savY(3) = RY2
  216.          savX(3) = RX1
  217.          savY(4) = RY2
  218.          savX(4) = RX2
  219.          savAlpha(1) = L1 * L2
  220.          savAlpha(2) = L1 * L3
  221.          savAlpha(3) = L4 * L2
  222.          savAlpha(4) = L4 * L3
  223.  
  224.          For Cl = 1 To 4
  225.             Strength = savAlpha(Cl)
  226.             X4 = savX(Cl)
  227.             Y4 = savY(Cl)
  228.             If Strength > 252 Then '> 99%
  229.                SetPixelV m_hDC, X4, Y4, Color
  230.             Else
  231.                Bgr = GetPixel(m_hDC, X4, Y4)
  232.                If Bgr Then 'if not black
  233.                   Rbg = Bgr And &HFF&
  234.                   Gbg = (Bgr And &HFF00&) \ &H100&
  235.                   Bbg = (Bgr And &HFF0000) \ &H10000
  236.                Else
  237.                   Rbg = 0
  238.                   Gbg = 0
  239.                   Bbg = 0
  240.                End If
  241.                StrengthI = 255 - Strength
  242.                Rblend = StrengthI * Rbg + Strength * Red
  243.                Gblend = StrengthI * Gbg + Strength * Green
  244.                Bblend = StrengthI * Bbg + Strength * Blue
  245.                NewColor = RGB(Rblend \ 256, Gblend \ 256, Bblend \ 256)
  246.                SetPixelV m_hDC, X4, Y4, NewColor
  247.             End If
  248.          Next
  249.       Next
  250.    Next
  251.  
  252. End Sub
  253.  
  254. Public Sub ArcGP(ByVal hdc As Long, _
  255.    ByVal X1 As Long, _
  256.    ByVal Y1 As Long, _
  257.    ByVal RadiusX As Long, _
  258.    ByVal RadiusY As Long, _
  259.    ByVal StartAngle As Single, _
  260.    ByVal StopAngle As Single, _
  261.    ByVal Color As OLE_COLOR, _
  262.    Optional ByVal Thickness As cThickness = Thick)
  263.  
  264.    Dim Bbg              As Byte
  265.    Dim Gbg              As Byte
  266.    Dim Rbg              As Byte
  267.    Dim savAlpha(1 To 4) As Byte
  268.    Dim Bblend           As Long
  269.    Dim Bgr              As Long
  270.    Dim Cl               As Long
  271.    Dim Gblend           As Long
  272.    Dim Strength         As Long
  273.    Dim StrengthI        As Long
  274.    Dim Radius           As Long
  275.    Dim Rblend           As Long
  276.    Dim RX1              As Long
  277.    Dim RX2              As Long
  278.    Dim RY1              As Long
  279.    Dim RY2              As Long
  280.    Dim savX(1 To 4)     As Long
  281.    Dim savY(1 To 4)     As Long
  282.    Dim X4               As Long
  283.    Dim Y4               As Long
  284.    Dim NewColor         As Long
  285.    Dim Ax               As Single
  286.    Dim Ay               As Single
  287.    Dim Bx               As Single
  288.    Dim By               As Single
  289.    Dim L1               As Single
  290.    Dim L2               As Single
  291.    Dim L3               As Single
  292.    Dim L4               As Single
  293.    Dim sngAngle         As Single
  294.    Dim sngPointSpacing  As Single
  295.    Dim X2               As Single
  296.    Dim Xp5              As Single
  297.    Dim Y2               As Single
  298.  
  299.    m_hDC = hdc
  300.  
  301.    SetRGBComponents Color
  302.  
  303.    Radius = RadiusX
  304.    If RadiusY > RadiusX Then
  305.       Radius = RadiusY
  306.    End If
  307.  
  308.    sngPointSpacing = GetPointSpacing(Radius, Thickness)
  309.  
  310.    If StartAngle > StopAngle Then
  311.       StopAngle = StopAngle + 360
  312.    End If
  313.    'Convert to Radians
  314.    StartAngle = StartAngle * Rads
  315.    StopAngle = StopAngle * Rads
  316.  
  317.    For sngAngle = StartAngle To StopAngle Step sngPointSpacing
  318.       X2 = RadiusX * Cos(sngAngle - HalfPi)
  319.       Y2 = RadiusY * Sin(sngAngle - HalfPi)
  320.       'Prevents error when vb rounds .5 down
  321.       If X2 = Int(X2) Then X2 = X2 + 0.001
  322.       If Y2 = Int(Y2) Then Y2 = Y2 + 0.001
  323.       Ax = X2 + X1 - 0.5
  324.       Ay = Y2 + Y1 - 0.5
  325.       Bx = Ax + 1
  326.       By = Ay + 1
  327.       RX1 = Ax
  328.       RX2 = RX1 + 1
  329.       Xp5 = RX1 + 0.5
  330.       RY1 = Ay
  331.       RY2 = By
  332.       L1 = RY1 + 0.5 - Ay
  333.       L2 = 256 * (Xp5 - Ax) - Xp5 + Ax
  334.       L3 = 255 - L2
  335.       L4 = By - RY2 + 0.5
  336.       savX(1) = RX1
  337.       savY(1) = RY1
  338.       savX(2) = RX2
  339.       savY(2) = RY1
  340.       savY(3) = RY2
  341.       savX(3) = RX1
  342.       savY(4) = RY2
  343.       savX(4) = RX2
  344.       savAlpha(1) = L1 * L2
  345.       savAlpha(2) = L1 * L3
  346.       savAlpha(3) = L4 * L2
  347.       savAlpha(4) = L4 * L3
  348.  
  349.       For Cl = 1 To 4
  350.          Strength = savAlpha(Cl)
  351.          X4 = savX(Cl)
  352.          Y4 = savY(Cl)
  353.          If Strength > 252 Then '> 99%
  354.             SetPixelV m_hDC, X4, Y4, Color
  355.          Else
  356.             Bgr = GetPixel(m_hDC, X4, Y4)
  357.             If Bgr Then 'if not black
  358.                Rbg = Bgr And &HFF&
  359.                Gbg = (Bgr And &HFF00&) \ &H100&
  360.                Bbg = (Bgr And &HFF0000) \ &H10000
  361.             Else
  362.                Rbg = 0
  363.                Gbg = 0
  364.                Bbg = 0
  365.             End If
  366.             StrengthI = 255 - Strength
  367.             Rblend = StrengthI * Rbg + Strength * Red
  368.             Gblend = StrengthI * Gbg + Strength * Green
  369.             Bblend = StrengthI * Bbg + Strength * Blue
  370.             NewColor = RGB(Rblend \ 256, Gblend \ 256, Bblend \ 256)
  371.             SetPixelV m_hDC, X4, Y4, NewColor
  372.          End If
  373.       Next
  374.    Next
  375.  
  376. End Sub
  377.  
  378. Private Function GetPointSpacing(Radius As Long, Thickness As cThickness) As Single
  379.    Dim sngLS            As Single
  380.  
  381.    If Thickness = Thick Then
  382.       sngLS = cThick
  383.    Else
  384.       sngLS = cThin
  385.    End If
  386.  
  387.    If Radius < 0 Then
  388.       GetPointSpacing = -sngLS / Radius
  389.    ElseIf Radius = 0 Then
  390.       GetPointSpacing = sngLS
  391.    Else
  392.       GetPointSpacing = sngLS / Radius
  393.    End If
  394.  
  395. End Function
  396.  
  397. Public Sub CircleDIB(ByVal X1 As Long, _
  398.    ByVal Y1 As Long, _
  399.    ByVal RadiusX As Long, _
  400.    ByVal RadiusY As Long, _
  401.    ByVal Color As OLE_COLOR, _
  402.    Optional ByVal Thickness As cThickness = Thick)
  403.  
  404. On Error Resume Next
  405.    Dim Bbg              As Byte
  406.    Dim Gbg              As Byte
  407.    Dim Rbg              As Byte
  408.    Dim savAlpha(1 To 4) As Byte
  409.    Dim Cl               As Long
  410.    Dim Strength         As Long
  411.    Dim StrengthI        As Long
  412.    Dim Quadrant         As Long
  413.    Dim Radius           As Long
  414.    Dim RX1              As Long
  415.    Dim RX2              As Long
  416.    Dim RY1              As Long
  417.    Dim RY2              As Long
  418.    Dim savX(1 To 4)     As Long
  419.    Dim savY(1 To 4)     As Long
  420.    Dim X4               As Long
  421.    Dim Y4               As Long
  422.    Dim Ax               As Single
  423.    Dim Ay               As Single
  424.    Dim Bx               As Single
  425.    Dim By               As Single
  426.    Dim L1               As Single
  427.    Dim L2               As Single
  428.    Dim L3               As Single
  429.    Dim L4               As Single
  430.    Dim sngAngle         As Single
  431.    Dim sngPointSpacing  As Single
  432.    Dim X2               As Single
  433.    Dim Xp5              As Single
  434.    Dim Y2               As Single
  435.  
  436.    If Not InDIBits Then
  437.       MsgBox "You must create a DIB array" & vbCrLf & _
  438.          "before calling CircleDIB."
  439.       Exit Sub
  440.    End If
  441.  
  442.    SetRGBComponents Color
  443.  
  444.    Radius = RadiusX
  445.    If RadiusY > RadiusX Then
  446.       Radius = RadiusY
  447.    End If
  448.  
  449.    sngPointSpacing = GetPointSpacing(Radius, Thickness)
  450.  
  451.    For sngAngle = 0 To HalfPi Step sngPointSpacing
  452.       X2 = RadiusX * Cos(sngAngle)
  453.       Y2 = RadiusY * Sin(sngAngle)
  454.       'Prevents error when vb rounds .5 down
  455.       If X2 = Int(X2) Then X2 = X2 + 0.001
  456.       If Y2 = Int(Y2) Then Y2 = Y2 + 0.001
  457.       For Quadrant = 0 To 3
  458.          Select Case Quadrant
  459.             Case 0 '0-90░
  460.                Ax = X2 + X1 - 0.5
  461.                Ay = -Y2 + Y1 - 0.5
  462.             Case 1 '90-180░
  463.                Ax = X2 + X1 - 0.5
  464.                Ay = Y2 + Y1 - 0.5
  465.             Case 2 '180-270░
  466.                Ax = -X2 + X1 - 0.5
  467.                Ay = Y2 + Y1 - 0.5
  468.             Case 3 '270-360░
  469.                Ax = -X2 + X1 - 0.5
  470.                Ay = -Y2 + Y1 - 0.5
  471.          End Select
  472.  
  473.          Bx = Ax + 1
  474.          By = Ay + 1
  475.          RX1 = Ax
  476.          RX2 = RX1 + 1
  477.          Xp5 = RX1 + 0.5
  478.          RY1 = Ay
  479.          RY2 = By
  480.          L1 = RY1 + 0.5 - Ay
  481.          L2 = 256 * (Xp5 - Ax) - Xp5 + Ax
  482.          L3 = 255 - L2
  483.          L4 = By - RY2 + 0.5
  484.          savX(1) = RX1
  485.          savY(1) = RY1
  486.          savX(2) = RX2
  487.          savY(2) = RY1
  488.          savY(3) = RY2
  489.          savX(3) = RX1
  490.          savY(4) = RY2
  491.          savX(4) = RX2
  492.          savAlpha(1) = L1 * L2
  493.          savAlpha(2) = L1 * L3
  494.          savAlpha(3) = L4 * L2
  495.          savAlpha(4) = L4 * L3
  496.  
  497.          For Cl = 1 To 4
  498.             Strength = savAlpha(Cl)
  499.             X4 = savX(Cl)
  500.             Y4 = savY(Cl)
  501.             'Check if in bounds
  502.             If X4 >= 0 And X4 < m_W1 And Y4 >= 0 And Y4 <= m_H1 Then
  503.                If Strength > 252 Then  '> 99%
  504.                   'No blending
  505.                   buf(X4, Y4).Blue = Blue
  506.                   buf(X4, Y4).Green = Green
  507.                   buf(X4, Y4).Red = Red
  508.                Else
  509.                   Bbg = buf(X4, Y4).Blue
  510.                   Gbg = buf(X4, Y4).Green
  511.                   Rbg = buf(X4, Y4).Red
  512.                   'Blend % of bgColor with % of Color
  513.                   StrengthI = 255 - Strength
  514.                   buf(X4, Y4).Red = (StrengthI * Rbg + Strength * Red) \ 256
  515.                   buf(X4, Y4).Green = (StrengthI * Gbg + Strength * Green) \ 256
  516.                   buf(X4, Y4).Blue = (StrengthI * Bbg + Strength * Blue) \ 256
  517.                End If
  518.             End If
  519.          Next
  520.       Next
  521.    Next
  522. End Sub
  523.  
  524. Public Sub ArcDIB(ByVal X1 As Long, _
  525.    ByVal Y1 As Long, _
  526.    ByVal RadiusX As Long, _
  527.    ByVal RadiusY As Long, _
  528.    ByVal StartAngle As Single, _
  529.    ByVal StopAngle As Single, _
  530.    ByVal Color As OLE_COLOR, _
  531.    Optional ByVal Thickness As cThickness = Thick)
  532.  
  533.    Dim Bbg              As Byte
  534.    Dim Gbg              As Byte
  535.    Dim Rbg              As Byte
  536.    Dim savAlpha(1 To 4) As Byte
  537.    Dim Cl               As Long
  538.    Dim Strength         As Long
  539.    Dim StrengthI        As Long
  540.    Dim Radius           As Long
  541.    Dim RX1              As Long
  542.    Dim RX2              As Long
  543.    Dim RY1              As Long
  544.    Dim RY2              As Long
  545.    Dim savX(1 To 4)     As Long
  546.    Dim savY(1 To 4)     As Long
  547.    Dim X4               As Long
  548.    Dim Y4               As Long
  549.    Dim Ax               As Single
  550.    Dim Ay               As Single
  551.    Dim Bx               As Single
  552.    Dim By               As Single
  553.    Dim L1               As Single
  554.    Dim L2               As Single
  555.    Dim L3               As Single
  556.    Dim L4               As Single
  557.    Dim sngAngle         As Single
  558.    Dim sngPointSpacing  As Single
  559.    Dim X2               As Single
  560.    Dim Xp5              As Single
  561.    Dim Y2               As Single
  562.  
  563.    If Not InDIBits Then
  564.       MsgBox "You must create a DIB array" & vbCrLf & _
  565.          "before calling CircleDIB."
  566.       Exit Sub
  567.    End If
  568.  
  569.    SetRGBComponents Color
  570.  
  571.    Radius = RadiusX
  572.    If RadiusY > RadiusX Then
  573.       Radius = RadiusY
  574.    End If
  575.  
  576.    sngPointSpacing = GetPointSpacing(Radius, Thickness)
  577.  
  578.    If StartAngle > StopAngle Then
  579.       StopAngle = StopAngle + 360
  580.    End If
  581.    'Convert to Radians
  582.    StartAngle = StartAngle * Rads
  583.    StopAngle = StopAngle * Rads
  584.  
  585.    For sngAngle = StartAngle To StopAngle Step sngPointSpacing
  586.       X2 = RadiusX * Cos(sngAngle - HalfPi)
  587.       Y2 = RadiusY * Sin(sngAngle + HalfPi)
  588.       'Prevents error when vb rounds .5 down
  589.       If X2 = Int(X2) Then X2 = X2 + 0.001
  590.       If Y2 = Int(Y2) Then Y2 = Y2 + 0.001
  591.       Ax = X2 + X1 - 0.5
  592.       Ay = Y2 + Y1 - 0.5
  593.       Bx = Ax + 1
  594.       By = Ay + 1
  595.       RX1 = Ax
  596.       RX2 = RX1 + 1
  597.       Xp5 = RX1 + 0.5
  598.       RY1 = Ay
  599.       RY2 = By
  600.       L1 = RY1 + 0.5 - Ay
  601.       L2 = 256 * (Xp5 - Ax) - Xp5 + Ax
  602.       L3 = 255 - L2
  603.       L4 = By - RY2 + 0.5
  604.       savX(1) = RX1
  605.       savY(1) = RY1
  606.       savX(2) = RX2
  607.       savY(2) = RY1
  608.       savY(3) = RY2
  609.       savX(3) = RX1
  610.       savY(4) = RY2
  611.       savX(4) = RX2
  612.       savAlpha(1) = L1 * L2
  613.       savAlpha(2) = L1 * L3
  614.       savAlpha(3) = L4 * L2
  615.       savAlpha(4) = L4 * L3
  616.  
  617.       For Cl = 1 To 4
  618.          Strength = savAlpha(Cl)
  619.          X4 = savX(Cl)
  620.          Y4 = savY(Cl)
  621.          'Check if in bounds
  622.          If X4 >= 0 And X4 < m_W1 And Y4 >= 0 And Y4 <= m_H1 Then
  623.             If Strength > 252 Then  '> 99%
  624.                'No blending
  625.                buf(X4, Y4).Blue = Blue
  626.                buf(X4, Y4).Green = Green
  627.                buf(X4, Y4).Red = Red
  628.             Else
  629.                Bbg = buf(X4, Y4).Blue
  630.                Gbg = buf(X4, Y4).Green
  631.                Rbg = buf(X4, Y4).Red
  632.                'Blend % of bgColor with % of Color
  633.                StrengthI = 255 - Strength
  634.                buf(X4, Y4).Red = (StrengthI * Rbg + Strength * Red) \ 256
  635.                buf(X4, Y4).Green = (StrengthI * Gbg + Strength * Green) \ 256
  636.                buf(X4, Y4).Blue = (StrengthI * Bbg + Strength * Blue) \ 256
  637.             End If
  638.          End If
  639.       Next
  640.    Next
  641. End Sub
  642.  
  643. Public Sub SetRGBComponents(ByVal Color As OLE_COLOR)
  644.  
  645.    Color = TranslateColour(Color)
  646.    m_Color = Color 'make available global
  647.    If Color Then
  648.       Red = Color And &HFF&
  649.       Green = Color \ 256 And &HFF
  650.       Blue = Color \ 65536
  651.    Else 'Color is Black
  652.       Red = 0
  653.       Green = 0
  654.       Blue = 0
  655.    End If
  656. End Sub
  657.  
  658. Public Sub LineGP(ByVal hdc As Long, _
  659.    ByVal X1 As Integer, _
  660.    ByVal Y1 As Integer, _
  661.    ByVal X2 As Integer, _
  662.    ByVal Y2 As Integer, _
  663.    ByVal Color As OLE_COLOR)
  664.  
  665.    Dim XScope           As Long
  666.    Dim YScope           As Long
  667.    Dim XDir             As Long
  668.    Dim YDir             As Long
  669.    Dim LinearDeviance   As Long
  670.    Dim Counter          As Long
  671.    Dim AntiAliasStrength As Long
  672.    Dim EndPointIntensity As Long
  673.  
  674.    Const HalfIntensity As Long = 127
  675.  
  676.    'Blended lines, maximum blend at transition,
  677.    'tapering off too minimum.
  678.    '
  679.    '            ----------
  680.    'Min    Max/Max     Min
  681.    '----------
  682.    '
  683.    m_hDC = hdc
  684.    m_Color = Color
  685.  
  686.    XScope = X2 - X1
  687.    YScope = Y2 - Y1
  688.  
  689.    If XScope < 0 Then
  690.       XScope = Abs(XScope)
  691.       XDir = -1
  692.    Else
  693.       XDir = 1
  694.    End If
  695.  
  696.    If YScope < 0 Then
  697.       YScope = Abs(YScope)
  698.       YDir = -1
  699.    Else
  700.       YDir = 1
  701.    End If
  702.  
  703.    If XScope + YScope = 0 Then
  704.       'Exit if line length is 0
  705.       Exit Sub
  706.    End If
  707.  
  708.    SetRGBComponents Color
  709.  
  710.    If XScope > YScope Then
  711.       'Output EndPoints outside of main loop.
  712.       EndPointIntensity = (85 * YScope) \ XScope
  713.       PutPixelGP X1 - XDir, Y1 - YDir, EndPointIntensity
  714.       PutPixelGP X1 - XDir, Y1, HalfIntensity
  715.       PutPixelGP X2 + XDir, Y2 + YDir, EndPointIntensity
  716.       PutPixelGP X2 + XDir, Y2, HalfIntensity
  717.       '-----
  718.       LinearDeviance = XScope \ 2
  719.       For Counter = 0 To XScope
  720.          'Main line, output full strength direct to hDC.
  721.          SetPixelV m_hDC, X1, Y1, m_Color
  722.          'Output the blended lines for anti-alias effect.
  723.          AntiAliasStrength = (LinearDeviance * 255) \ XScope
  724.          PutPixelGP X1, Y1 - YDir, 255 - AntiAliasStrength
  725.          PutPixelGP X1, Y1 + YDir, AntiAliasStrength
  726.          LinearDeviance = (LinearDeviance + YScope)
  727.          If LinearDeviance >= XScope Then
  728.             LinearDeviance = LinearDeviance - XScope
  729.             Y1 = Y1 + YDir
  730.          End If
  731.          X1 = X1 + XDir
  732.       Next
  733.    Else
  734.       'Output EndPoints outside of main loop.
  735.       EndPointIntensity = (85 * XScope) \ YScope
  736.       PutPixelGP X1 - XDir, Y1 - YDir, EndPointIntensity
  737.       PutPixelGP X1, Y1 - YDir, HalfIntensity
  738.       PutPixelGP X2 + XDir, Y2 + YDir, EndPointIntensity
  739.       PutPixelGP X2, Y2 + YDir, HalfIntensity
  740.       '-----
  741.       LinearDeviance = YScope \ 2
  742.       For Counter = 0 To YScope
  743.          'Main line, output full strength direct to hDC.
  744.          SetPixelV m_hDC, X1, Y1, m_Color
  745.          'Output the blended lines for anti-alias effect.
  746.          AntiAliasStrength = (LinearDeviance * 255) \ YScope
  747.          PutPixelGP X1 - XDir, Y1, 255 - AntiAliasStrength
  748.          PutPixelGP X1 + XDir, Y1, AntiAliasStrength
  749.          LinearDeviance = LinearDeviance + XScope
  750.          If (LinearDeviance >= YScope) Then
  751.             LinearDeviance = LinearDeviance - YScope
  752.             X1 = X1 + XDir
  753.          End If
  754.          Y1 = Y1 + YDir
  755.       Next
  756.    End If
  757.  
  758. End Sub
  759.  
  760. Public Sub LineDIB(ByVal X1 As Integer, _
  761.    ByVal Y1 As Integer, _
  762.    ByVal X2 As Integer, _
  763.    ByVal Y2 As Integer, _
  764.    ByVal Color As OLE_COLOR)
  765.  
  766.    'Blended lines, maximum blend at transition,
  767.    'tapering off too minimum.
  768.    '
  769.    '            ----------
  770.    'Min    Max/Max     Min
  771.    '----------
  772.    '
  773.  
  774.    If Not InDIBits Then
  775.       MsgBox "You must create a DIB array" & vbCrLf & _
  776.          "before calling LineDIB."
  777.       Exit Sub
  778.    End If
  779.  
  780.    Dim XScope           As Long
  781.    Dim YScope           As Long
  782.    Dim XDir             As Long
  783.    Dim YDir             As Long
  784.    Dim LinearDeviance   As Long
  785.    Dim Counter          As Long
  786.    Dim AntiAliasStrength As Long
  787.    Dim EndPointIntensity As Long
  788.  
  789.    Const HalfIntensity As Long = 127
  790.  
  791.    XScope = X2 - X1
  792.    YScope = Y2 - Y1
  793.  
  794.    If XScope < 0 Then
  795.       XScope = Abs(XScope)
  796.       XDir = -1
  797.    Else
  798.       XDir = 1
  799.    End If
  800.  
  801.    If YScope < 0 Then
  802.       YScope = Abs(YScope)
  803.       YDir = -1
  804.    Else
  805.       YDir = 1
  806.    End If
  807.  
  808.    If XScope + YScope = 0 Then
  809.       'Exit if line length is 0
  810.       Exit Sub
  811.    End If
  812.  
  813.    SetRGBComponents Color
  814.  
  815.    If XScope > YScope Then
  816.       'Output EndPoints outside of main loop.
  817.       EndPointIntensity = (85 * YScope) \ XScope
  818.       PutPixelDIB X1 - XDir, Y1 - YDir, EndPointIntensity
  819.       PutPixelDIB X1 - XDir, Y1, HalfIntensity
  820.       PutPixelDIB X2 + XDir, Y2 + YDir, EndPointIntensity
  821.       PutPixelDIB X2 + XDir, Y2, HalfIntensity
  822.       '-----
  823.       LinearDeviance = XScope \ 2
  824.       For Counter = 0 To XScope
  825.          'Main line, output full strength direct to DIB array.
  826.          PutPixelDIB X1, Y1, 255
  827.          'Output the blended lines for anti-alias effect.
  828.          AntiAliasStrength = (LinearDeviance * 255) \ XScope
  829.          PutPixelDIB X1, Y1 - YDir, 255 - AntiAliasStrength
  830.          PutPixelDIB X1, Y1 + YDir, AntiAliasStrength
  831.          LinearDeviance = (LinearDeviance + YScope)
  832.          If LinearDeviance >= XScope Then
  833.             LinearDeviance = LinearDeviance - XScope
  834.             Y1 = Y1 + YDir
  835.          End If
  836.          X1 = X1 + XDir
  837.       Next
  838.    Else
  839.       'Output EndPoints outside of main loop.
  840.       EndPointIntensity = (85 * XScope) \ YScope
  841.       PutPixelDIB X1 - XDir, Y1 - YDir, EndPointIntensity
  842.       PutPixelDIB X1, Y1 - YDir, HalfIntensity
  843.       PutPixelDIB X2 + XDir, Y2 + YDir, EndPointIntensity
  844.       PutPixelDIB X2, Y2 + YDir, HalfIntensity
  845.       '-----
  846.       LinearDeviance = YScope \ 2
  847.       For Counter = 0 To YScope
  848.          'Main line, output full strength direct to DIB array.
  849.          PutPixelDIB X1, Y1, 255
  850.          'Output the blended lines for anti-alias effect.
  851.          AntiAliasStrength = (LinearDeviance * 255) \ YScope
  852.          PutPixelDIB X1 - XDir, Y1, 255 - AntiAliasStrength
  853.          PutPixelDIB X1 + XDir, Y1, AntiAliasStrength
  854.          LinearDeviance = LinearDeviance + XScope
  855.          If (LinearDeviance >= YScope) Then
  856.             LinearDeviance = LinearDeviance - YScope
  857.             X1 = X1 + XDir
  858.          End If
  859.          Y1 = Y1 + YDir
  860.       Next
  861.    End If
  862.  
  863. End Sub
  864.  
  865. Public Sub Array2Pic()
  866.    'If we have an array copy back to hDC
  867.    If InDIBits Then
  868.       SetDIBits m_hDC, m_Handle, 0, m_H1, buf(0, 0), Binfo, DIB_RGB_COLORS
  869.       InDIBits = False
  870.       'Erase buf '* Moved to Class_Terminate
  871.    End If
  872. End Sub
  873.  
  874. Private Sub PutPixelGP(ByVal X As Long, _
  875.    ByVal Y As Long, _
  876.    ByVal Strength As Long)
  877.  
  878.    Dim Color            As Long
  879.    Dim bgColor          As Long
  880.    Dim Rbg              As Long
  881.    Dim Gbg              As Long
  882.    Dim Bbg              As Long
  883.    Dim Rblend           As Long
  884.    Dim Gblend           As Long
  885.    Dim Bblend           As Long
  886.    Dim StrengthI        As Long
  887.  
  888.    If Strength > 252 Then '99%
  889.       SetPixelV m_hDC, X, Y, m_Color
  890.    Else
  891.       '##### Get Background Pixel components
  892.       bgColor = GetPixel(m_hDC, X, Y)
  893.       If bgColor Then 'i.e. Not Black
  894.          Rbg = bgColor And &HFF&
  895.          Gbg = (bgColor And &HFF00&) \ &H100&
  896.          Bbg = (bgColor And &HFF0000) \ &H10000
  897.       End If
  898.       '##### Blend % of bgColor with % of m_Color
  899.       StrengthI = 255 - Strength
  900.       Rblend = StrengthI * Rbg + Strength * Red
  901.       Gblend = StrengthI * Gbg + Strength * Green
  902.       Bblend = StrengthI * Bbg + Strength * Blue
  903.       '##### Write
  904.       Color = RGB(Rblend \ 256, Gblend \ 256, Bblend \ 256)
  905.       SetPixelV m_hDC, X, Y, Color
  906.    End If
  907.  
  908. End Sub
  909.  
  910. Private Sub PutPixelDIB(ByVal X As Long, _
  911.    ByVal Y As Long, _
  912.    ByVal Strength As Long)
  913.  
  914.    Dim Rbg              As Long
  915.    Dim Gbg              As Long
  916.    Dim Bbg              As Long
  917.    Dim StrengthI        As Long
  918.  
  919.    'Check if in bounds
  920.    If X < 0 Or X >= m_W1 Or Y < 0 Or Y > m_H1 Then
  921.       Exit Sub
  922.    End If
  923.    If Strength > 252 Then '99%
  924.       buf(X, Y).Blue = Blue
  925.       buf(X, Y).Green = Green
  926.       buf(X, Y).Red = Red
  927.    Else
  928.       '##### Get Background Pixel components
  929.       Bbg = buf(X, Y).Blue
  930.       Gbg = buf(X, Y).Green
  931.       Rbg = buf(X, Y).Red
  932.       '##### Blend % of bgColor with % of m_Color
  933.       StrengthI = 255 - Strength
  934.       buf(X, Y).Red = (StrengthI * Rbg + Strength * Red) \ 256
  935.       buf(X, Y).Green = (StrengthI * Gbg + Strength * Green) \ 256
  936.       buf(X, Y).Blue = (StrengthI * Bbg + Strength * Blue) \ 256
  937.    End If
  938. End Sub
  939.  
  940. Private Sub Class_Terminate()
  941.    Erase buf()
  942. End Sub
  943.