📄 picfuns.pas
字号:
arcToPolyAngle: Single; //圆弧转换成多边形的角度
arcToPolyNumber: Integer; //圆弧转换成多边形的边数
arcVertexPoint: array of TPoint; //多边形的顶点
startAngle, endAngle: Single; //起点和终点的夹角
dx, dy: Integer; //坐标之差
aa: Single; //临时角度
i: Integer; //循环变量
circleHrgn: HRGN;
cellHrgn: HRGN;
begin
//初始化参数
diffRadius := 5;
arcToPolyAngle := 5.0 * PI / 180;
//圆心
centerPoint.x := (rb.X + tl.X) div 2;
centerPoint.y := (rb.Y + tl.Y) div 2;
//Y向半径
radiusY := abs(rb.Y - tl.Y) div 2;
//细长比
asp := abs((rb.X - tl.X) / (rb.Y - tl.Y));
//****** 计算角度 ******
//起点角度
dx := arcsp.X - centerPoint.x;
dy := arcsp.Y - centerPoint.y;
//起点角度的绝对值
if dx = 0 then startAngle := PI / 2 else startAngle := Abs(ArcTan(dy / dx * asp));
//确定起点角度的大小
if (dx > 0) and (dy < 0) then
startAngle := startAngle
else if (dx < 0) and (dy < 0) then
startAngle := PI - startAngle
else if (dx < 0) and (dy > 0) then
startAngle := PI + startAngle
else
startAngle := PI + PI - startAngle;
//终点角度
dx := arcep.X - centerPoint.x;
dy := arcep.Y - centerPoint.y;
//终点角度绝对值
if dx = 0 then endAngle := PI / 2 else endAngle := Abs(ArcTan(dy / dx * asp));
//确定终点角度的大小
if (dx > 0) and (dy < 0) then
endAngle := endAngle
else if (dx < 0) and (dy < 0) then
endAngle := PI - endAngle
else if (dx < 0) and (dy > 0) then
endAngle := PI + endAngle
else
endAngle := PI + PI - endAngle;
//计算外圆
bigRadius := radiusY + diffRadius;
//计算顶点数
if endAngle < startAngle then begin //终点角度小于起点角度
arcToPolyNumber := Trunc((2 * PI + (endAngle - startAngle)) / arcToPolyAngle) + 2;
end else begin //终点角度大于起点角度
arcToPolyNumber := Trunc((endAngle - startAngle) / arcToPolyAngle) + 2;
end;
//设置顶点数组
SetLength(arcVertexPoint, arcToPolyNumber + 3);
//计算外圆
for i := 1 to arcToPolyNumber - 1 do begin
aa := startAngle + (i - 1) * arcToPolyAngle;
arcVertexPoint[i].x := Round(centerPoint.x + bigRadius * cos(aa) * asp);
arcVertexPoint[i].y := Round(centerPoint.y - bigRadius * sin(aa));
end;
arcVertexPoint[arcToPolyNumber].x := Round(centerPoint.x + bigRadius * Cos(endAngle) * asp);
arcVertexPoint[arcToPolyNumber].y := Round(centerPoint.y - bigRadius * Sin(endAngle));
circleHrgn := CreateEllipticRgn(tl.X, tl.Y, rb.X, rb.Y);
cellHrgn := 0;
case arct of //图像类型
1: //Pie
begin
arcVertexPoint[arcToPolyNumber + 1] := centerPoint; //首尾相接
arcVertexPoint[arcToPolyNumber + 2] := arcVertexPoint[1]; //首尾相接
cellHrgn := createPolygonRgn(arcVertexPoint[1], arcToPolyNumber + 2, ALTERNATE);
CombineRGN(cellHrgn, cellHrgn, circleHrgn, RGN_AND);
DeleteObject(circleHrgn);
end;
2: // Chord
begin
arcVertexPoint[arcToPolyNumber + 1] := arcVertexPoint[1]; //首尾相接
cellHrgn := createPolygonRgn(arcVertexPoint[1], arcToPolyNumber + 1,ALTERNATE);
CombineRGN(cellHrgn, cellHrgn, circleHrgn, RGN_AND);
DeleteObject(circleHrgn);
end;
end;
Result := cellHrgn;
end;
function PointToCirclePoint(StartPoint:TPoint;EndPoint:TPoint;APoint:TPoint): TPoint;
//计算点(X,Y)与圆心的连线同圆的交点
var
radius: Integer; //Y方向的半径
dX, dY: Integer;
asp: Single; //细长比
centerX, centerY: Integer; //圆心坐标
tempAngle: Single; //夹角
circlePoint: TPoint; //交点
pp:array[1..3] of TPoint;
begin
//调整数值,确保circleright>=circleLeft,circlebottom>=circletop
pp[1].X := Min(StartPoint.X, EndPoint.X);
pp[1].Y := Min(StartPoint.Y, EndPoint.Y);
pp[2].X := Max(StartPoint.X, EndPoint.X);
pp[2].Y := Max(StartPoint.Y, EndPoint.Y);
//计算细长比
asp := ((pp[2].Y - pp[1].y) / (pp[2].X - pp[1].x));
radius := (pp[2].Y - pp[1].Y) div 2; //方向半径
centerX := (pp[2].X + pp[1].X) div 2; // 圆心
centerY := (pp[2].Y + pp[1].Y) div 2;
//计算与圆心连线同水平线的夹角
dX := APoint.X - centerX;
dY := APoint.Y - centerY;
if (Abs(dX) > 0.000000000001) then //'终点与圆心的连线同X 轴的夹角不为90度
tempAngle := Abs(ArcTan(dY / (dX * asp))) //角度的绝对值
else
tempAngle := PI / 2; //终点与圆心的连线同X 轴的夹角为90度
//确定角度的正负,及大小
if (dX >= 0) and (dY <= 0) then
tempAngle := tempAngle
else if (dX <= 0) and (dY <= 0) then
tempAngle := PI - tempAngle
else if (dX <= 0) and (dY >= 0) then
tempAngle := -PI + tempAngle
else
tempAngle := -tempAngle;
circlePoint.X := Round(centerX + radius * Cos(tempAngle) / asp);
circlePoint.Y := Round(centerY - radius * Sin(tempAngle));
Result := circlePoint;
end;
//Flagtag =1 以宽为准, 2 已高为准 3 已大尺寸为准
function GetRectMaxFontSize(dRect:TRect;Text:String;Font:TFont;Flagtag:Integer):Integer;
var
bt:TBitmap;
tw,th:Integer;
rw,rh:integer;
ftag:Integer;
fSize:Integer;
begin
Result:=Font.Size;
if FlagTag=0 then Exit;
bt:=TBitmap.Create;
try
bt.Canvas.Font.Name:=Font.Name;
bt.Canvas.Font.Size:=2;
rw:=(dRect.Right-dRect.Left);
rh:=(dRect.Bottom-dRect.Top);
Case Flagtag of
1: begin
ftag:=1; //宽
fSize:=rw;
end;
2: begin
ftag:=2;
fSize:=rh;
end;
else
begin
tw:=bt.Canvas.TextWidth(Text);
th:=bt.Canvas.TextHeight(Text);
tw:=rw-tw;
th:=rh-th;
if tw>th then begin
ftag:=1; //宽
fSize:=rw;
end else begin
ftag:=2;
fSize:=rh;
end;
end;
end;
While True do begin
Case ftag of
1: begin //宽
tw:=bt.Canvas.TextWidth(Text);
if tw>fSize then begin
Result:=bt.Canvas.Font.Size-1;
Break;
end;
end;
else
begin
th:=bt.Canvas.TextHeight(Text);
if th>fSize then begin
Result:=bt.Canvas.Font.Size-1;
Break;
end;
end;
end;
bt.Canvas.Font.Size:=bt.Canvas.Font.Size+1;
end;
finally
bt.Free;
end;
end;
procedure LoadScreenCursor;
begin
Screen.Cursors[CURSOR_LINE] := LoadCursor(HInstance, 'CUR_LINE'); //直线
Screen.Cursors[CURSOR_RECT] := LoadCursor(HInstance, 'CUR_RECT'); //矩形
Screen.Cursors[CURSOR_ROUN] := LoadCursor(HInstance, 'CUR_ROUN'); //圆矩形
Screen.Cursors[CURSOR_CIRC] := LoadCursor(HInstance, 'CUR_CIRC'); //圆
Screen.Cursors[CURSOR_ARCC] := LoadCursor(HInstance, 'CUR_ARCC'); //圆弧
Screen.Cursors[CURSOR_POLY] := LoadCursor(HInstance, 'CUR_POLY'); //多边形
Screen.Cursors[CURSOR_CURVE] := LoadCursor(HInstance, 'CUR_CURVE'); //曲线
Screen.Cursors[CURSOR_TEXT] := LoadCursor(HInstance, 'CUR_TEXT'); //文本
//Screen.Cursors[CURSOR_IMAG] := LoadCursor(HInstance, 'CUR_IMAG'); //图象
Screen.Cursors[CURSOR_LINE_END] := LoadCursor(HInstance, 'CUR_LINE_END'); //线端点
Screen.Cursors[CURSOR_TRUN_VER] := LoadCursor(HInstance, 'CUR_TRUN_VER'); //变形点
//网格图元需要的Cusor
//Screen.Cursors[CURSOR_READY_DRAW]:= LoadCursor(HInstance, 'CUR_READY_DRAW');
end;
initialization
LoadScreenCursor;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -