📄 jvqsimlogic.pas
字号:
end;
//=== { TJvSimLight } ========================================================
constructor TJvSimLight.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FLit := False;
Width := 65;
Height := 65;
FColorOn := clLime;
FColorOff := clGreen;
FConnectors := TList.Create;
end;
destructor TJvSimLight.Destroy;
begin
FConnectors.Free;
inherited Destroy;
end;
procedure TJvSimLight.AnchorConnectors;
var
Wc: TWinControl;
I: Integer;
Con: TJvSIMConnector;
R, Rc: TRect;
P: TPoint;
begin
Wc := Parent;
FConnectors.Clear;
R := BoundsRect;
InflateRect(R, 8, 8);
P := Point(Left, Top);
for I := 0 to Wc.ControlCount - 1 do
if Wc.Controls[I] is TJvSIMConnector then
begin
Con := TJvSIMConnector(Wc.Controls[I]);
// check for corners in bounds
Rc := Con.BoundsRect;
// TL
if PtInRect(R, Point(Rc.Left, Rc.Top)) then
begin
FConnectors.Add(Con);
Con.AnchorCorner(P, jcmTL);
end
// TR
else
if PtInRect(R, Point(Rc.Right, Rc.Top)) then
begin
FConnectors.Add(Con);
Con.AnchorCorner(P, jcmTR);
end
// BR
else
if PtInRect(R, Point(Rc.Right, Rc.Bottom)) then
begin
FConnectors.Add(Con);
Con.AnchorCorner(P, jcmBR);
end
// BL
else
if PtInRect(R, Point(Rc.Left, Rc.Bottom)) then
begin
FConnectors.Add(Con);
Con.AnchorCorner(P, jcmBL);
end
end;
end;
procedure TJvSimLight.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
FMdp := Point(X, Y);
FDoMove := True;
FOldp := Point(X, Y);
AnchorConnectors;
end;
procedure TJvSimLight.MouseMove(Shift: TShiftState; X, Y: Integer);
var
P: TPoint;
begin
P := ClientToScreen(Point(X, Y));
P := Parent.ScreenToClient(P);
if ssLeft in Shift then
begin
if FDoMove then
begin
FNewLeft := P.X - FMdp.X;
FNewTop := P.Y - FMdp.Y;
MoveConnectors;
Left := FNewLeft;
Top := FNewTop;
end
end;
end;
procedure TJvSimLight.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
BinCheck(Self);
end;
procedure TJvSimLight.MoveConnectors;
var
I: Integer;
Con: TJvSIMConnector;
begin
for I := 0 to FConnectors.Count - 1 do
begin
Con := TJvSIMConnector(FConnectors[I]);
Con.MoveConnector(Point(FNewLeft, FNewTop));
end;
end;
procedure TJvSimLight.Paint;
var
TlPoly, BrPoly: array [0..2] of TPoint;
xw, yh: Integer;
R: TRect;
HiColor, LoColor, SurfCol: TColor;
procedure DrawFrame;
begin
// rgn := CreatePolygonRgn(TlPoly,3,WINDING);
// SelectClipRgn(Canvas.handle,rgn);
with Canvas do
begin
Brush.Color := SurfCol;
Pen.Color := HiColor;
Pen.Width := 2;
Ellipse(15, 15, xw - 15, yh - 15);
end;
// SelectClipRgn(Canvas.handle,0);
// DeleteObject(rgn);
// rgn := CreatePolygonRgn(BrPoly,3,WINDING);
// SelectClipRgn(Canvas.handle,rgn);
with Canvas do
begin
Brush.Color := SurfCol;
Pen.Color := LoColor;
Pen.Width := 2;
Arc(15, 15, xw - 15, yh - 15, 0, yh, xw, 0);
Pen.Width := 1;
end;
// SelectClipRgn(Canvas.handle,0);
// DeleteObject(rgn);
end;
begin
if Lit then
SurfCol := ColorOn
else
SurfCol := ColorOff;
Canvas.Brush.Style := bsSolid;
R := ClientRect;
Canvas.Brush.Color := clSilver;
Canvas.FillRect(R);
Frame3D(Canvas, R, clBtnHighlight, clBtnShadow, 1);
xw := Width - 1;
yh := Height - 1;
// cr := Width div 4;
// x4 := Width div 4;
// topleft region
TlPoly[0] := Point(Left, Top + yh);
TlPoly[1] := Point(Left, Top);
TlPoly[2] := Point(Left + xw, Top);
// Bottom Right region
BrPoly[0] := Point(Left + xw, Top);
BrPoly[1] := Point(Left + xw, Top + yh);
BrPoly[2] := Point(Left, Top + yh);
Canvas.Pen.Style := psSolid;
HiColor := clBtnHighlight;
LoColor := clBtnShadow;
DrawFrame;
end;
procedure TJvSimLight.Resize;
begin
Width := 65;
Height := 65;
end;
procedure TJvSimLight.SetLit(const Value: Boolean);
begin
if Value <> FLit then
begin
FLit := Value;
Invalidate;
end;
end;
procedure TJvSimLight.SetColorOff(const Value: TColor);
begin
if Value <> FColorOff then
begin
FColorOff := Value;
Invalidate;
end;
end;
procedure TJvSimLight.SetColorOn(const Value: TColor);
begin
if Value <> FColorOn then
begin
FColorOn := Value;
Invalidate;
end;
end;
//=== { TJvSimBin } ==========================================================
constructor TJvSimBin.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 65;
Height := 65;
FBmpBin := TBitmap.Create;
FBmpBin.LoadFromResourceName(HInstance, 'JvSimLogicBoxBIN'); // do not localize
end;
destructor TJvSimBin.Destroy;
begin
FBmpBin.Free;
inherited Destroy;
end;
procedure TJvSimBin.Paint;
var
Rf: TRect;
begin
Rf := ClientRect;
Canvas.Brush.Color := clSilver;
Canvas.FillRect(Rect(0, 0, Width, Height));
Frame3D(Canvas, Rf, clBtnHighlight, clBtnShadow, 1);
Canvas.Draw(16, 16, FBmpBin);
end;
procedure TJvSimBin.Resize;
begin
inherited Resize;
Width := 65;
Height := 65;
end;
//=== { TJvSimLogicBox } =====================================================
constructor TJvSimLogicBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 130;
Height := 65;
FBmpCon := TBitmap.Create;
FBmpLogic := TBitmap.Create;
FBmpButton := TBitmap.Create;
FBmpLight := TBitmap.Create;
FBmpRev := TBitmap.Create;
FBmpBin := TBitmap.Create;
FBmpCon.LoadFromResourceName(HInstance, 'JvSimLogicBoxCON'); // do not localize
FBmpLogic.LoadFromResourceName(HInstance, 'JvSimLogicBoxLOGIC'); // do not localize
FBmpButton.LoadFromResourceName(HInstance, 'JvSimLogicBoxBUTTON'); // do not localize
FBmpLight.LoadFromResourceName(HInstance, 'JvSimLogicBoxLIGHT'); // do not localize
FBmpRev.LoadFromResourceName(HInstance, 'JvSimLogicBoxREV'); // do not localize
FBmpBin.LoadFromResourceName(HInstance, 'JvSimLogicBoxBIN'); // do not localize
FRCon := Rect(0, 0, 32, 32);
FRLogic := Rect(33, 0, 64, 32);
FRButton := Rect(0, 33, 32, 64);
FRLight := Rect(33, 33, 64, 64);
FRRev := Rect(65, 0, 97, 32);
FDCon := False;
FDLogic := False;
FDButton := False;
FDLight := False;
FDRev := False;
FCpu := TTimer.Create(Self);
FCpu.Enabled := False;
FCpu.OnTimer := CpuOnTimer;
FCpu.Interval := 50;
end;
destructor TJvSimLogicBox.Destroy;
begin
FCpu.Free;
FBmpCon.Free;
FBmpLogic.Free;
FBmpButton.Free;
FBmpLight.Free;
FBmpRev.Free;
FBmpBin.Free;
inherited Destroy;
end;
procedure TJvSimLogicBox.Loaded;
begin
inherited Loaded;
FCpu.Enabled := True;
end;
procedure TJvSimLogicBox.CpuOnTimer(Sender: TObject);
var
Wc: TWinControl;
I: Integer;
begin
Wc := Parent;
// reset inputs
{ for I:=0 to Wc.ControlCount-1 do
if (Wc.Controls[I] is TJvLogic) then
begin
sLogic:=TJvLogic(Wc.Controls[I]);
for j:=0 to 2 do
sLogic.FGates[j].State:=False;
end
else
if (Wc.Controls[I] is TJvSimLight) then
begin
sLight:=TJvSimLight(Wc.Controls[I]);
sLight.Lit:=False;
end;}
// make connections
for I := 0 to Wc.ControlCount - 1 do
if Wc.Controls[I] is TJvSIMConnector then
TJvSIMConnector(Wc.Controls[I]).Connect;
end;
procedure TJvSimLogicBox.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
P: TPoint;
begin
P := Point(X, Y);
FDCon := False;
FDLogic := False;
FDButton := False;
FDLight := False;
if PtInRect(FRCon, P) then
FDCon := True
else
if PtInRect(FRLogic, P) then
FDLogic := True
else
if PtInRect(FRButton, P) then
FDButton := True
else
if PtInRect(FRLight, P) then
FDLight := True
else
if PtInRect(FRRev, P) then
FDRev := True;
Invalidate;
end;
procedure TJvSimLogicBox.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
Wc: TWinControl;
l, t: Integer;
begin
Wc := Parent;
l := Left;
t := Top + Height + 10;
if FDCon then
with TJvSIMConnector.Create(Wc) do
begin
Parent := Wc;
Left := l;
Top := t;
end
else
if FDLogic then
with TJvLogic.Create(Wc) do
begin
Parent := Wc;
Left := l;
Top := t;
end
else
if FDButton then
with TJvSimButton.Create(Wc) do
begin
Parent := Wc;
Left := l;
Top := t;
end
else
if FDLight then
with TJvSimLight.Create(Wc) do
begin
Parent := Wc;
Left := l;
Top := t;
end
else
if FDRev then
with TJvSimReverse.Create(Wc) do
begin
Parent := Wc;
Left := l;
Top := t;
end;
FDCon := False;
FDLogic := False;
FDButton := False;
FDLight := False;
FDRev := False;
Invalidate;
end;
procedure TJvSimLogicBox.Paint;
var
Rb: TRect;
begin
with Canvas do
begin
Brush.Color := clSilver;
FillRect(ClientRect);
Rb := FRCon;
if not FDCon then
Frame3D(Canvas, Rb, clBtnHighlight, clBtnShadow, 1)
else
Frame3D(Canvas, Rb, clBtnShadow, clBtnHighlight, 1);
Draw(4, 4, FBmpCon);
Rb := FRLogic;
if not FDLogic then
Frame3D(Canvas, Rb, clBtnHighlight, clBtnShadow, 1)
else
Frame3D(Canvas, Rb, clBtnShadow, clBtnHighlight, 1);
Draw(36, 4, FBmpLogic);
Rb := FRButton;
if not FDButton then
Frame3D(Canvas, Rb, clBtnHighlight, clBtnShadow, 1)
else
Frame3D(Canvas, Rb, clBtnShadow, clBtnHighlight, 1);
Draw(4, 36, FBmpButton);
Rb := FRLight;
if not FDLight then
Frame3D(Canvas, Rb, clBtnHighlight, clBtnShadow, 1)
else
Frame3D(Canvas, Rb, clBtnShadow, clBtnHighlight, 1);
Draw(36, 36, FBmpLight);
Rb := FRRev;
if not FDRev then
Frame3D(Canvas, Rb, clBtnHighlight, clBtnShadow, 1)
else
Frame3D(Canvas, Rb, clBtnShadow, clBtnHighlight, 1);
Draw(Rb.Left + 3, Rb.Top + 3, FBmpRev);
// Draw bin
Draw(100, 16, FBmpBin);
end;
end;
procedure TJvSimLogicBox.Resize;
begin
Width := 130;
Height := 65;
end;
//=== { TJvSimReverse } ======================================================
constructor TJvSimReverse.Create(AOwner: TComponent);
var
I: Integer;
begin
inherited Create(AOwner);
Width := 42;
Height := 42;
// initialize Gates
FGates[0].Pos := Point(28, 14);
FGates[1].Pos := Point(14, 1);
FGates[2].Pos := Point(1, 14);
FGates[3].Pos := Point(14, 28);
for I := 0 to 3 do
begin
FGates[I].State := False;
FGates[I].Active := True;
FGates[I].Style := jgsDO;
end;
FGates[0].Style := jgsDI;
FConnectors := TList.Create;
end;
destructor TJvSimReverse.Destroy;
begin
FConnectors.Free;
inherited Destroy;
end;
procedure TJvSimReverse.AnchorConnectors;
var
Wc: TWinControl;
I: Integer;
Con: TJvSIMConnector;
R, Rc: TRect;
P: TPoint;
begin
Wc := Parent;
FConnectors.Clear;
R := BoundsRect;
InflateRect(R, 8, 0);
P := Point(Left, Top);
for I := 0 to Wc.ControlCount - 1 do
if Wc.Controls[I] is TJvSIMConnector then
begin
Con := TJvSIMConnector(Wc.Controls[I]);
// check for corners in bounds
Rc := Con.BoundsRect;
// TL
if PtInRect(R, Point(Rc.Left, Rc.Top)) then
begin
FConnectors.Add(Con);
Con.AnchorCorner(P, jcmTL);
end
// TR
else
if PtInRect(R, Point(Rc.Right, Rc.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -