![]() |
|
'This smaple shows how you can use B�zier mode for drawing. 'For API users: "body" is "points" in czech don't forgot it!! 'maximaly you can use 10000/3 points 'By Cima from Black Cat Studio(BCS)2001 'cima.m@sezam.cz Private Type POINTAPI X As Long Y As Long End Type Private Const nekolik = 10000 Dim pts(0 To nekolik) As POINTAPI Dim sel As Long Dim done As Boolean Dim body As Long Private Declare Function PolyBezier Lib "gdi32.dll" (ByVal hdc As Long, lppt As POINTAPI, ByVal cPoints As Long) As Long Private Sub Form_load() Me.ScaleMode = vbPixels If Not done = True Then For i = 0 To 3 pts(i).X = i * 10 + 100 pts(i).Y = i * 10 + 100 Next body = 4 Me.ForeColor = vbGreen done = True End If End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then Dim vzd As POINTAPI vzd.X = (pts(body - 1).X - X) / 3 vzd.Y = (pts(body - 1).Y - Y) / 3 pts(body).X = pts(body - 1).X - vzd.X pts(body).Y = pts(body - 1).Y - vzd.Y pts(body + 1).X = pts(body - 1).X - vzd.X * 2 pts(body + 1).Y = pts(body - 1).Y - vzd.Y * 2 pts(body + 2).X = X pts(body + 2).Y = Y body = body + 3 Call vykreslit End If End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then For i = 0 To body - 1 If (X > pts(i).X - 5 And X < pts(i).X + 5) And (Y > pts(i).Y - 5 And Y < pts(i).Y + 5) Then sel = i Exit For End If Next Me.Cls If sel Mod 3 = 0 Or sel = 0 Then If Not sel = 0 Then pts(sel - 1).X = X + (pts(sel - 1).X - pts(sel).X) pts(sel - 1).Y = Y + (pts(sel - 1).Y - pts(sel).Y) End If If Not sel = body - 1 Then pts(sel + 1).X = X + (pts(sel + 1).X - pts(sel).X) pts(sel + 1).Y = Y + (pts(sel + 1).Y - pts(sel).Y) End If End If pts(sel).X = X pts(sel).Y = Y Call vykreslit ElseIf Button = 2 Then 'will be useful End If End Sub Private Sub boxhere(X As Long, Y As Long) Dim m As Long m = 3 Me.Line (X - m, Y - m)-(X + m, Y - m), RGB(0, 0, 0) Me.Line (X - m, Y - m)-(X - m, Y + m), RGB(0, 0, 0) Me.Line (X + m, Y - m)-(X + m, Y + m), RGB(0, 0, 0) Me.Line (X + m, Y + m)-(X - m - 1, Y + m), RGB(0, 0, 0) End Sub Private Sub vykreslit() 'to Draw it Me.ForeColor = vbGreen PolyBezier Me.hdc, pts(0), Int(body) Me.DrawStyle = 2 For i = 3 To body - 1 Step 3 Me.Line (pts(i).X, pts(i).Y)-(pts(i - 1).X, pts(i - 1).Y), RGB(0, 0, 255) Next For i = 1 To body - 1 Step 3 Me.Line (pts(i).X, pts(i).Y)-(pts(i - 1).X, pts(i - 1).Y), RGB(0, 0, 255) Next Me.DrawStyle = 0 For i = 0 To body - 1 Call boxhere(pts(i).X, pts(i).Y) Next End Sub Private Sub Form_Paint() 'draw the b�zier PolyBezier Me.hdc, pts(0), 4 Me.Line (pts(0).X, pts(0).Y)-(pts(1).X, pts(1).Y), RGB(0, 0, 255) Me.Line (pts(3).X, pts(3).Y)-(pts(2).X, pts(2).Y), RGB(0, 0, 255) For i = 0 To 3 Call boxhere(pts(i).X, pts(i).Y) Next End Sub |