📄 u_main.pas
字号:
{橡片擦}
procedure TF_main.b_eraseClick(Sender: TObject);
begin
setButtonDown(b_erase); //按钮下陷
end;
{***********************************************************
* 画图部分:控制鼠标
*************************************************************}
{按下鼠标}
procedure Tf_main.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
downBegin:=true;//第一次按下
if downButton = b_line then //画直线
begin
PaintBox1.Canvas.Pen.Mode:= pmNotXor;//非异或模式
PaintBox1.Canvas.Pen.Style:= psDot;//点划线
end
else if downButton=b_curve then//画曲线
begin
PaintBox1.Canvas.Pen.Mode:= pmCopy;//在Color属性中指定的画笔颜色
PaintBox1.Canvas.Pen.Style:= psSolid;//实线
end
else if downButton=b_retangle then//画矩形
begin
//设置画布画刷颜色和模式
PaintBox1.Canvas.Brush.Color:= PaintBox1.Canvas.Pen.Color ;
PaintBox1.Canvas.Brush.Style:= bsClear;// 空心
PaintBox1.Canvas.Pen.Mode:= pmNotXor;//非异或模式
PaintBox1.Canvas.Pen.Style:= psDot;//点划线
end
else if downButton=b_roundRetangle then//画圆角矩形
begin
//设置画布画刷颜色和模式
PaintBox1.Canvas.Brush.Color:= PaintBox1.Canvas.Pen.Color ;
PaintBox1.Canvas.Brush.Style:= bsClear;// 空心
PaintBox1.Canvas.Pen.Mode:= pmNotXor;//非异或模式
PaintBox1.Canvas.Pen.Style:= psDot;//点划线
end
else if downButton=b_polygon then//画多边形
begin
PaintBox1.Canvas.Pen.Mode:= pmNotXor;//非异或模式
PaintBox1.Canvas.Pen.Style:= psDot;//点划线
if polygonFirst then//开始画多边形
polygonFirst:= false
else
begin
xTo := x; yTo :=y;//设置终点
exit;//结束
end;
end
else if (downButton=b_ellipse) or (downButton=b_round) then//画椭圆
begin
//设置画布画刷颜色和模式
PaintBox1.Canvas.Brush.Color:= PaintBox1.Canvas.Pen.Color ;
PaintBox1.Canvas.Brush.Style:= bsClear;// 空心
PaintBox1.Canvas.Pen.Mode:= pmNotXor;//非异或模式
PaintBox1.Canvas.Pen.Style:= psDot;//点划线
end
else if (downButton=b_cardinal) or (downButton=b_bazier) then
begin //画插值曲线 或逼近曲线
PaintBox1.Canvas.Pen.Mode:= pmCopy;//在Color属性中指定的画笔颜色
PaintBox1.Canvas.Pen.Style:= psSolid;//实线
end
else if (downButton=b_retangleCut) then //裁剪
begin
//设置画布画刷颜色和模式
PaintBox1.Canvas.Brush.Color:= PaintBox1.Canvas.Pen.Color ;
PaintBox1.Canvas.Brush.Style:= bsClear;// 空心
PaintBox1.Canvas.Pen.Mode:= pmNotXor;//非异或模式
PaintBox1.Canvas.Pen.Style:= psDot;//点划线
end
else if (downButton=b_transform) then //坐标变换
begin
//设置画布画刷颜色和模式
PaintBox1.Canvas.Brush.Color:= PaintBox1.Canvas.Pen.Color ;
PaintBox1.Canvas.Brush.Style:= bsClear;// 空心
PaintBox1.Canvas.Pen.Mode:= pmNotXor;//非异或模式
PaintBox1.Canvas.Pen.Style:= psDot;//点划线
end
else if (downButton=b_getColor) then //取色
begin
//设置画笔颜色
PaintBox1.Canvas.Pen.Color :=PaintBox1.Canvas.Pixels[x,y];
//状态栏的颜色与画笔颜色一样
StatusBar.Color := PaintBox1.Canvas.Pen.Color;
end
else if (downButton=b_erase) then //橡皮
begin
{设置画布画刷颜色和模式 }
PaintBox1.Canvas.Brush.Color:= clwhite ;
{设置画笔}
PaintBox1.Canvas.Pen.Mode:= pmNotXor;//非异或模式
PaintBox1.Canvas.Pen.Style:= psDot;//点划线
showEraser(x,y); //显示橡片擦
end;
//设定初始点的坐标
xFrom := x; yFrom := y;
xTo := x; yTo :=y;
end;
{放松鼠标}
procedure Tf_main.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i,j:integer;
color:TColor;
begin
if downButton = b_line then //画直线
begin
PaintBox1.Canvas.Pen.Style:= psSolid;//实线
PaintBox1.Canvas.Pen.Mode:= pmCopy;//在Color属性中指定的画笔颜色
drawLine(xFrom,yFrom,x,y);//画新的直线
end
else if downButton = b_retangle then //画矩形
begin
PaintBox1.Canvas.Pen.Style:= psSolid;//实线
PaintBox1.Canvas.Pen.Mode:= pmCopy;//在Color属性中指定的画笔颜色
PaintBox1.Canvas.Rectangle(xFrom,yFrom,x,y);//画新矩形
end
else if downButton = b_roundRetangle then //画圆角矩形
begin
PaintBox1.Canvas.Pen.Style:= psSolid;//实线
PaintBox1.Canvas.Pen.Mode:= pmCopy;//在Color属性中指定的画笔颜色
drawRoundRetangle(xFrom,yFrom,x,y);//画新圆角矩形
end
else if downButton = b_polygon then //画多边形
begin
PaintBox1.Canvas.Pen.Style:= psSolid;//实线
PaintBox1.Canvas.Pen.Mode:= pmCopy;//在Color属性中指定的画笔颜色
drawLine(xFrom,yFrom,x,y);//画新的直线
xFrom := x; yFrom :=y;//新的起点
end
else if (downButton=b_ellipse) then //画椭圆
begin
PaintBox1.Canvas.Pen.Style:= psSolid;//实线
PaintBox1.Canvas.Pen.Mode:= pmCopy;//在Color属性中指定的画笔颜色
f_main.PaintBox1.Canvas.Ellipse(xFrom,yFrom,x,y);//画新椭圆
end
else if (downButton=b_round) then //画圆
begin
PaintBox1.Canvas.Pen.Style:= psSolid;//实线
PaintBox1.Canvas.Pen.Mode:= pmCopy;//在Color属性中指定的画笔颜色
if (y-yFrom)>=(x-xFrom) then
f_main.PaintBox1.Canvas.Ellipse(xFrom,yFrom,x,yFrom+(x-xFrom))//画新圆
else
f_main.PaintBox1.Canvas.Ellipse(xFrom,yFrom,xFrom+(y-yFrom),y);//画新圆
end
else if (downButton=b_cardinal) then//画插值曲线
begin
curveNum:= curveNum+1;//输入点数加1
curvePoint[1,curveNum]:= x;
curvePoint[2,curveNum]:= y;
PaintBox1.Canvas.Ellipse(x,y,x+3,y+3);//显示输入点
if curveNum>= strtoint(f_setCurve.e_curveNum.Text) then //大于设置的输入点数
begin
m:= strtoint(f_setCurve.e_num.Text);//控制曲线的密度
drawCardinal(strtoint(f_setCurve.e_curveNum.Text)); //画插值曲线
curveNum:= 0;//重新开始
end;
end
else if (downButton=b_baZier) then//画逼近曲线
begin
curveNum:= curveNum+1;//输入点数加1
curvePoint[1,curveNum]:= x;
curvePoint[2,curveNum]:= y;
PaintBox1.Canvas.Ellipse(x,y,x+3,y+3);//显示输入点
if curveNum>= strtoint(f_setCurve.e_curveNum.Text) then //大于设置的输入点数
begin
m:= strtoint(f_setCurve.e_num.Text);//控制曲线的密度
drawBazier(strtoint(f_setCurve.e_curveNum.Text)); //画逼近曲线
curveNum:= 0;//重新开始
end;
end
else if (downButton=b_boundfill) then//边界填充
begin
//设置画布画刷颜色和模式
PaintBox1.Canvas.Brush.Color:= PaintBox1.Canvas.Pen.Color ;
PaintBox1.Canvas.Brush.Style:= bssolid;// 实心
PaintBox1.Canvas.FloodFill(x,y,PaintBox1.Canvas.Pen.Color,fsBorder );
end
else if (downButton=b_floodfill) then//泛滥填充
begin
//设置画布画刷颜色和模式
PaintBox1.Canvas.Brush.Color:= PaintBox1.Canvas.Pen.Color ; //为画笔颜色
PaintBox1.Canvas.Brush.Style:= bssolid;// 实心
PaintBox1.Canvas.FloodFill(x,y,PaintBox1.Canvas.Pixels[x,y], fsSurface);
end
else if downButton = b_retangleCut then //剪裁
begin
//设置画布画刷颜色和模式
PaintBox1.Canvas.Brush.Color:= clwhite ; //为白色
PaintBox1.Canvas.Brush.Style:= bssolid;// 实心
f_main.PaintBox1.Canvas.FillRect( Rect(xFrom,yFrom,x,y) );//填充
end
else if downButton = b_transform then //坐标变换
begin
PaintBox1.Canvas.Rectangle(xFrom,yFrom,x,y);//擦除矩形
setRect:= Rect(xFrom,yFrom,x,y);//选定区域
transform(xFrom,yFrom,x,y);//对选定区域坐标变换
end
else if (downButton=b_erase) then //橡皮
begin
doErase(xFrom,yFrom);//擦除
end;
end;
{移动鼠标}
procedure TF_main.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var xd,yd:integer;
begin
if (ssLeft in Shift) then //按下左键
begin
if downButton=b_line then //画直线
begin
drawLine(xFrom,yFrom,xTo,yTo);//画掉旧直线
drawLine(xFrom,yFrom,x,y); //画新直线
xTo:= x; yTo:= y;//保存旧点
end
else if downbutton= b_curve then //画曲线
begin
drawLine(xFrom,yFrom,x,y); //画新直线
xFrom:= x; yFrom:= y;//保存旧点
end
else if downButton=b_retangle then //画矩形
begin
PaintBox1.Canvas.Rectangle(xFrom,yFrom,xTo,yTo);//画旧矩形
PaintBox1.Canvas.Rectangle(xFrom,yFrom,x,y);//画新矩形
xTo:= x; yTo:= y;//保存旧点
end
else if downButton=b_roundRetangle then //画圆角矩形
begin
drawRoundRetangle(xFrom,yFrom,xTo,yTo);//画旧圆角矩形
drawRoundRetangle(xFrom,yFrom,x,y);//画新圆角矩形
xTo:= x; yTo:= y;//保存旧点
end
else if downButton=b_polygon then //画多边形
begin
if downBegin then //第一次按下
downBegin:=false
else
drawLine(xFrom,yFrom,xTo,yTo);//画掉旧直线
drawLine(xFrom,yFrom,x,y); //画新直线
xTo:= x; yTo:= y;//保存旧点
end
else if downButton=b_ellipse then //画椭圆形
begin
PaintBox1.Canvas.Ellipse(xFrom,yFrom,xTo,yTo);//画旧椭圆
PaintBox1.Canvas.Ellipse(xFrom,yFrom,x,y);//画新椭圆
xTo:= x; yTo:= y;//保存旧点
end
else if downButton=b_round then //画圆形
begin
yd:= (y-yFrom);
xd:= (x-xFrom);
if yd>=xd then
begin
PaintBox1.Canvas.Ellipse(xFrom,yFrom,xTo,yTo);//画旧圆
PaintBox1.Canvas.Ellipse(xFrom,yFrom,x,yFrom+xd);//画新圆
xTo:= x; yTo:= yFrom+xd;//保存旧点
end
else
begin
PaintBox1.Canvas.Ellipse(xFrom,yFrom,xTo,yTo);//画旧圆
PaintBox1.Canvas.Ellipse(xFrom,yFrom,xFrom+yd,y);//画新圆
xTo:= xFrom+yd; yTo:= y;//保存旧点
end;
end
else if downButton=b_retangleCut then //剪裁
begin
PaintBox1.Canvas.Rectangle(xFrom,yFrom,xTo,yTo);//画旧矩形
PaintBox1.Canvas.Rectangle(xFrom,yFrom,x,y);//画新矩形
xTo:= x; yTo:= y;//保存旧点
end
else if downButton=b_transform then //坐标变换
begin
PaintBox1.Canvas.Rectangle(xFrom,yFrom,xTo,yTo);//画旧矩形
PaintBox1.Canvas.Rectangle(xFrom,yFrom,x,y);//画新矩形
xTo:= x; yTo:= y;//保存旧点
end
else if (downButton=b_erase) then //橡皮
begin
doErase(xFrom,yFrom);//擦除
showEraser(x,y); //显示橡片擦
xFrom:= x; yFrom:= y;//保存旧点
end;
end;//end 按下左键
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -