
03072016, 12:08 PM

Ultimate Contributor


Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,860


Positioning a STRETCHED graphic path
My program requires that I stretch a path various degrees in relation to lines that are drawn on the graphic.
Better explained in the attached image.
The first pair of lines is 50 pixels apart and the 2nd pair is 250 pixels apart.
The path is a 6 point path that forms a simple bracket.
The leftmost bracket is the original unaltered bracket. The next bracket is stretched to 68%, and the third to 335%
The 2nd and 3rd brackets are sized according to the spacing of the lines.
My problem is I can't figure out a generic formula to use for:
 the stretchY variable.
 offsets for the GdipTranslateMatrix function
The line spacing is determined by the user at runtime, as well as the positioning of the line pairs, so nothing can be precalculated.
Any help would be appreciated.
Code:
Private Sub Command1_Click()
Picture1.Cls
Dim graphics As Long
stat = GdipCreateFromHDC(Picture1.hdc, graphics)
stat = GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias)
Dim j As Long
Dim blackPen As Long
stat = GdipCreatePen1(&HFF000000, 1, UnitPixel, blackPen)
Dim blackBrush As Long
stat = GdipCreateSolidFill(&HFF000000, blackBrush)
Call LoadPath01
'draw 1st pair of lines 50 pixels apart
stat = GdipDrawLine(graphics, blackPen, 125, 50, 275, 50)
stat = GdipDrawLine(graphics, blackPen, 125, 100, 275, 100)
'draw 2nd pair of lines 250 pixels apart
stat = GdipDrawLine(graphics, blackPen, 350, 50, 500, 50)
stat = GdipDrawLine(graphics, blackPen, 350, 300, 500, 300)
Dim scaleFac As Single
scaleFac = 0.25
Dim stretchY As Single
Dim matrix As Long
'draw bracket unstretched
Dim pathToDraw As Long
'stat = GdipCreatePath(FillModeAlternate, pathToDraw) 'see other
stat = GdipCreatePath(FillModeWinding, pathToDraw)
stat = GdipAddPathPath(pathToDraw, Path10, 0)
'stat = GdipDeleteMatrix(matrix)
stat = GdipCreateMatrix(matrix)
stretchY = 1
stat = GdipScaleMatrix(matrix, scaleFac, scaleFac * stretchY, MatrixOrderAppend)
stat = GdipTranslateMatrix(matrix, 30, 50, MatrixOrderAppend)
stat = GdipTransformPath(pathToDraw, matrix)
stat = GdipFillPath(graphics, blackBrush, pathToDraw)
'draw bracket stretched to match 1st pair of lines
stat = GdipResetPath(pathToDraw)
stat = GdipAddPathPath(pathToDraw, Path10, 0)
stat = GdipDeleteMatrix(matrix)
stat = GdipCreateMatrix(matrix)
stretchY = 0.68
stat = GdipScaleMatrix(matrix, scaleFac, scaleFac * stretchY, MatrixOrderAppend)
stat = GdipTranslateMatrix(matrix, 55, 1, MatrixOrderAppend)
stat = GdipTransformPath(pathToDraw, matrix)
stat = GdipFillPath(graphics, blackBrush, pathToDraw)
'draw bracket stretched to match 2nd pair of lines
stat = GdipResetPath(pathToDraw)
stat = GdipAddPathPath(pathToDraw, Path10, 0)
stat = GdipCreateMatrix(matrix)
stretchY = 3.35
stat = GdipScaleMatrix(matrix, scaleFac, scaleFac * stretchY, MatrixOrderAppend)
stat = GdipTranslateMatrix(matrix, 280, 202, MatrixOrderAppend)
stat = GdipTransformPath(pathToDraw, matrix)
stat = GdipFillPath(graphics, blackBrush, pathToDraw)
' Cleanup
stat = GdipDeletePath(Path10)
stat = GdipDeletePath(pathToDraw)
stat = GdipDeleteBrush(blackBrush)
stat = GdipDeletePen(blackPen)
stat = GdipDeleteGraphics(graphics)
Picture1.Refresh
End Sub

Last edited by mms; 03072016 at 12:16 PM.

Tags

stat, stretchy, dim, scalefac, lines, bracket, matrixorderappend, pair, blackpen, pathtodraw, blackbrush, draw, gdipdrawlinegraphics, stretched, pixels, 2nd, matrix, path, gdipaddpathpathpathtodraw, gdipfillpathgraphics, path10, gdipcreatematrixmatrix, gdipscalematrixmatrix, gdiptranslatematrixmatrix, match 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)


Thread Tools 

Display Modes 
Linear Mode

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off





