Simple implementation of drawing curve in Window drawing program

xiaoxiao2021-03-06  45

Simple implementation of drawing curve in Window drawing program

Below is a very prior program, mimic the drawing curve in the drawing program of Windows. In fact, the principle is simple, it is a Polybezier function. That interested can be packaged into a class, which is convenient to use .unit unit1;

Interface

Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;

type TStep = (sStartEnd, sCtrl1, sCtrl2); TForm1 = class (TForm) Button1: TButton; procedure FormCreate (Sender: TObject); procedure FormMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer) ; procedure FormMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormMouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormPaint (Sender: TObject); private {Private Declarations}}: boolean; osok: boolean; // Identify whether the reach of the Bezier line completes Step: tstep; / / indication StartP: tpoint; // The following is the four point coordinate ENDP: TPOINT; CTRP1 : Tpoint; ctrp2: tpoint; public {public declarations}

Var Form1: TFORM1;

IMPLEMENTATION

{$ R * .dfm}

Procedure TForm1.FormCreate (Sender: TOBJECT); begin self.doublebuffered: = true; isdown: = false; step: = sstartend; isok: = false;

procedure TForm1.FormMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin isDown: = true; if Button = mbLeft then begin if (Step = sStartEnd) then begin StartP.X: = X Startp.y: = Y; ENDP: = Point (x, y); ISOK: = false; end else if (step = sctrl1) THEN BEGIN CTRP1: = Point (x, y); ctrp2: = Point (x, Y); ELSE IF (Step = sctrl2) THEN BEGIN CTRP2: = POINT (X, Y); END; END;

Procedure TForm1.FormMousemove (Sender: Tobject; Shift: TshiftState; x, y: integer); begin if isdown and (shift = [ssleft) THEN BEGIN ENDP.X: = X; ENDP. Y: = Y; Else if step = sctr1 the begin Ctrp1: = Point (x, y); ctrp2: = Point (x, y); end else if (step = sctrl2) Then Begin Ctrp2: = Point (x, Y); end; self.Invalidate; end; end; procedure TForm1.FormMouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if isDown and (Button = mbLeft) then begin isDown: = False; if step: = sctrl1 else if step = sctrl1 dam: = sctrl2 else if step = sctrl2 The begin: = SSTARTEND; ISOK: = TRUE; END; END;

Procedure TForm1.FormPaint (Sender: TOBJECT); Begin if not isok the beginning of step = sstartnd the beginning, self.canvas.moveto (startp.x, startp.y); self.canvas.lineto (Endp.x, endp.y ); Else Begin Self.canvas.Polybezier ([StartP, CTRP1, CTRP2, ENDP]); End; Else Begin Self.canvas.Polybezier ([StartP, CTRP1, CTRP2, ENDP]); END;

End.

Author Blog:

http://blog.9cbs.net/linzhenngqun/

related articles

C Implementation: Four Cragmatic Value Window Draw Program The Simple Implementation of the Control of Control Moving Class in the Window Draw Program The implementation of the implementation of the implementation of the mobile class is one of the implementation of the implementation of the mobile class.

转载请注明原文地址:https://www.9cbs.com/read-79217.html

New Post(0)