📄 jvqsimlogic.pas
字号:
if nw < d2 then
begin
Left := Left + nw - D;
Width := -nw + D + D;
FMode := jcmTR;
FShape := jcsTRBL;
case FConPos of
jcpTL:
FConPos := jcpTR;
jcpBR:
FConPos := jcpBL;
end;
FEdge := 1 - FEdge;
end
else
Width := nw;
nh := Height + (FMdp.Y - Y);
if nh < d2 then
begin
Top := Top + nh - D;
Height := -nh + D + D;
FMode := jcmBL;
FShape := jcsTRBL;
case FConPos of
jcpTL:
FConPos := jcpBL;
jcpBR:
FConPos := jcpTR;
end;
end
else
Height := nh;
end;
jcmTR:
begin
Top := P.Y - FMdp.Y;
nw := X + FMdp.X;
if nw < d2 then
begin
Left := Left + nw - D;
Width := -nw + D + D;
FMode := jcmTL;
FShape := jcsTLBR;
case FConPos of
jcpTR:
FConPos := jcpTL;
jcpBL:
FConPos := jcpBR;
end;
FEdge := 1 - FEdge;
end
else
Width := nw;
nh := Height + (FMdp.Y - Y);
if nh < d2 then
begin
Top := Top + nh - D;
Height := -nh + D + D;
FMode := jcmBR;
FShape := jcsTLBR;
case FConPos of
jcpTR:
FConPos := jcpBR;
jcpBL:
FConPos := jcpTL;
end;
end
else
Height := nh;
end;
jcmBR:
begin
nw := X + FMdp.X;
if nw < d2 then
begin
Left := Left + nw - D;
Width := -nw + D + D;
FMode := jcmBL;
FShape := jcsTRBL;
case FConPos of
jcpBR:
FConPos := jcpBL;
jcpTL:
FConPos := jcpTR;
end;
FEdge := 1 - FEdge;
end
else
Width := nw;
nh := Y + FMdp.Y;
if nh < d2 then
begin
Top := Top + nh - D;
Height := -nh + D + D;
FMode := jcmTR;
FShape := jcsTRBL;
case FConPos of
jcpBR:
FConPos := jcpTR;
jcpTL:
FConPos := jcpBL;
end;
end
else
Height := nh;
end;
jcmBL:
begin
Left := P.X - FMdp.X;
nw := Width + (FMdp.X - X);
if nw < d2 then
begin
Left := Left + nw - D;
Width := -nw + D + D;
FMode := jcmBR;
FShape := jcsTLBR;
case FConPos of
jcpBL:
FConPos := jcpBR;
jcpTR:
FConPos := jcpTL;
end;
FEdge := 1 - FEdge;
end
else
Width := nw;
nh := Y + FMdp.Y;
if nh < d2 then
begin
Top := Top + nh - D;
Height := -nh + D + D;
FMode := jcmTL;
FShape := jcsTLBR;
case FConPos of
jcpBL:
FConPos := jcpTL;
jcpTR:
FConPos := jcpBR;
end;
end
else
Height := nh;
end;
end;
end;
end;
procedure TJvSIMConnector.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
if ssLeft in Shift then
DoMouseMove(X - FOldp.X, Y - FOldp.Y);
end;
procedure TJvSIMConnector.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
if not FDoEdge then
DisconnectFinal;
BinCheck(Self);
end;
procedure TJvSIMConnector.DisconnectFinal;
begin
if FDisCon = nil then
Exit;
if FDisCon is TJvSimLight then
TJvSimLight(FDisCon).Lit := False
else
if FDisCon is TJvLogic then
begin
if FDisConI = 1 then
TJvLogic(FDisCon).Input1 := False
else
if FDisConI = 2 then
TJvLogic(FDisCon).Input2 := False
else
if FDisConI = 3 then
TJvLogic(FDisCon).Input3 := False
end;
end;
procedure TJvSIMConnector.Notification(AComponent: TComponent;
Operation: TOperation);
begin
if (Operation = opRemove) and (AComponent = FromLogic) then
FromLogic := nil;
if (Operation = opRemove) and (AComponent = ToLogic) then
ToLogic := nil;
end;
procedure TJvSIMConnector.Paint;
var
D, d2, w2, xw, yh: Integer;
begin
D := FConSize;
d2 := D div 2;
w2 := Round(FEdge * Width);
xw := Width - 1;
yh := Height - 1;
with Canvas do
begin
Brush.Color := clLime;
case FShape of
jcsTLBR:
// a connector is drawn depending in the FConPos
begin
// start new code
case FConPos of
jcpTL: // Draw regular connector
begin
MoveTo(D, d2);
LineTo(w2, d2);
LineTo(w2, yh - d2);
LineTo(xw - D, yh - d2);
Brush.Color := clRed;
Rectangle(0, 0, D, D);
Brush.Color := clLime;
Rectangle(xw - D, yh - D, xw, yh);
end;
jcpBR:
begin
MoveTo(D, d2);
LineTo(xw - d2, d2);
LineTo(xw - d2, yh - D);
Brush.Color := clLime;
Rectangle(0, 0, D, D);
Brush.Color := clRed;
Rectangle(xw - D, yh - D, xw, yh);
end;
end;
// end new code
{ MoveTo(D,d2);
LineTo(w2,d2);
LineTo(w2,yh-d2);
LineTo(xw-D,yh-d2);
case FConPos of
jcpTL: Brush.Color:=clRed;
else Brush.Color:=clLime;
end;
Rectangle(0,0,D,D);
case FConPos of
jcpBR: Brush.Color:=clRed;
else Brush.Color:=clLime;
end;
Rectangle(xw-D,yh-D,xw,yh);}
end;
jcsTRBL:
begin
// start new code
case FConPos of
jcpTR: // Draw reverted connector
begin
MoveTo(xw - d2, D);
LineTo(xw - d2, yh - d2);
LineTo(D, yh - d2);
Brush.Color := clRed;
Rectangle(xw - D, 0, xw, D);
Brush.Color := clLime;
Rectangle(0, yh - D, D, yh);
end;
jcpBL: // Draw regular connector
begin
MoveTo(xw - D, d2);
LineTo(w2, d2);
LineTo(w2, yh - d2);
LineTo(D - 1, yh - d2);
Brush.Color := clLime;
Rectangle(xw - D, 0, xw, D);
Brush.Color := clRed;
Rectangle(0, yh - D, D, yh);
end;
end;
// end new code
{ MoveTo(xw-D,d2);
LineTo(w2,d2);
LineTo(w2,yh-d2);
LineTo(D-1,yh-d2);
case FConPos of
jcpTR: Brush.Color:=clRed;
else Brush.Color:=clLime;
end;
Rectangle(xw-D,0,xw,D);
case FConPos of
jcpBL: Brush.Color:=clRed;
else Brush.Color:=clLime;
end;
Rectangle(0,yh-D,D,yh);}
end;
end;
end;
end;
procedure TJvSIMConnector.SetFromGate(const Value: Integer);
begin
FFromGate := Value;
end;
procedure TJvSIMConnector.SetFromLogic(const Value: TJvLogic);
begin
FFromLogic := Value;
end;
procedure TJvSIMConnector.SetToGate(const Value: Integer);
begin
FToGate := Value;
end;
procedure TJvSIMConnector.SetToLogic(const Value: TJvLogic);
begin
FToLogic := Value;
end;
procedure TJvSIMConnector.SetFromPoint(const Value: TJvPointX);
begin
if Assigned(Value) then
FFromPoint.Assign(Value);
end;
procedure TJvSIMConnector.SetToPoint(const Value: TJvPointX);
begin
if Assigned(Value) then
FToPoint.Assign(Value);
end;
procedure TJvSIMConnector.AnchorCorner(LogTL: TPoint; ACorner: TJvConMode);
var
Rc: TRect;
begin
FConMode := ACorner;
Rc := BoundsRect;
FConHot := FConPos;
case ACorner of
jcmTL:
begin
FConOffset := Point(Rc.Left - LogTL.X, Rc.Top - LogTL.Y);
FConAnchor := Parent.ScreenToClient(ClientToScreen(Point(Width, Height)));
end;
jcmTR:
begin
FConOffset := Point(Rc.Right - LogTL.X, Rc.Top - LogTL.Y);
FConAnchor := Parent.ScreenToClient(ClientToScreen(Point(0, Height)));
end;
jcmBR:
begin
FConOffset := Point(Rc.Right - LogTL.X, Rc.Bottom - LogTL.Y);
FConAnchor := Parent.ScreenToClient(ClientToScreen(Point(0, 0)));
end;
jcmBL:
begin
FConOffset := Point(Rc.Left - LogTL.X, Rc.Bottom - LogTL.Y);
FConAnchor := Parent.ScreenToClient(ClientToScreen(Point(Width, 0)));
end;
end;
end;
procedure TJvSIMConnector.MoveConnector(LogTL: TPoint);
var
nw, nh: Integer;
D: Integer;
nc: TPoint;
begin
D := FConSize;
// d2 := D div 2;
nc := Point(LogTL.X + FConOffset.X, LogTL.Y + FConOffset.Y);
case FConMode of
jcmTL:
begin
nw := FConAnchor.X - nc.X;
if nw < D then
begin
Left := FConAnchor.X - D;
Width := -nw + D + D;
end
else
begin
Left := nc.X;
Width := FConAnchor.X - Left;
end;
nh := FConAnchor.Y - nc.Y;
// adjust new hot position
if (nw < D) and not (nh < D) then
begin
case FConHot of
jcpTL:
FConPos := jcpTR;
jcpBR:
FConPos := jcpBL;
end;
FShape := jcsTRBL;
end
else
if (nw < D) and (nh < D) then
begin
case FConHot of
jcpTL:
FConPos := jcpBR;
jcpBR:
FConPos := jcpTL;
end;
FShape := jcsTLBR;
end
else
if (not nw < D) and (nh < D) then
begin
case FConHot of
jcpTL:
FConPos := jcpBL;
jcpBR:
FConPos := jcpTR;
end;
FShape := jcsTRBL;
end
else
begin
case FConHot of
jcpTL:
FConPos := jcpTL;
jcpBR:
FConPos := jcpBR;
end;
FShape := jcsTLBR;
end;
// end of adjust TL new hot
if nh < D then
begin
Top := FConAnchor.Y - D;
Height := -nh + D + D;
end
else
begin
Top := nc.Y;
Height := FConAnchor.Y - Top;
end;
end;
jcmTR:
begin
nw := nc.X - FConAnchor.X;
if nw <= 0 then
begin
Left := FConAnchor.X + nw - D;
Width := -nw + D + D;
end
else
if nw <= D then
begin
Left := nc.X - D;
Width := -nw + D + D;
end
else
Width := nw;
nh := FConAnchor.Y - nc.Y;
// adjust TR new hot position
if (nw < D) and (not (nh < D)) then
begin
case FConHot of
jcpTR:
FConPos := jcpTL;
jcpBL:
FConPos := jcpBR;
end;
FShape := jcsTLBR;
end
else
if (nw < D) and (nh < D) then
begin
case FConHot of
jcpTR:
FConPos := jcpBL;
jcpBL:
FConPos := jcpTR;
end;
FShape := jcsTRBL;
end
else
if (not nw < D) and (nh < D) then
begin
case FConHot of
jcpTR:
FConPos := jcpBR;
jcpBL:
FConPos := jcpTL;
end;
FShape := jcsTLBR;
end
else
begin
case FConHot of
jcpTR:
FConPos := jcpTR;
jcpBL:
FConPos := jcpBL;
end;
FShape := jcsTRBL;
end;
// end of adjust TR new hot
if nh < D then
begin
Top := FConAnchor.Y - D;
Height := -nh + D + D;
end
else
begin
Top := FConAnchor.Y - nh;
Height := nh;
end;
end;
jcmBR:
begin
nw := nc.X - FConAnchor.X;
if nw <= 0 then
begin
Left := nc.X - D;
Width := -nw + D + D;
end
else
if nw <= D then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -