⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvglogicseditorform.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
var
  Index: Integer;
begin
  FActiveBox := Value;

  Index := cbNext.Items.IndexOfObject(Value.LogicElement.NextElement);
  if Index <> -1 then
    cbNext.ItemIndex := Index
  else
    cbNext.ItemIndex := 0;

  Index := cbNextFalse.Items.IndexOfObject(Value.LogicElement.NextFalseElement);
  if Index <> -1 then
    cbNextFalse.ItemIndex := Index
  else
    cbNextFalse.ItemIndex := 0;

  cbMode.ItemIndex := Integer(FActiveBox.LogicElement.IsFirst);
  eStepName.Text := FActiveBox.LogicElement.Caption;
end;

procedure TJvgLogicsEditorMain.OnTraceMessage(Sender: TJvgLogics;
  AStepResult: Boolean; const StepResult, ParsedResult, Msg: string);
begin
  mLog.Lines.Add(Msg);
  if reReslt.Text = '' then
    reReslt.Tag := 0;

  if Length(ParsedResult) = 0 then
    Exit;
  Tag := 1 - Tag;

  //  reReslt.Lines.BeginUpdate;

  reReslt.Text := reReslt.Text + ParsedResult;

  reReslt.SelStart := Length(reReslt.Text) - Length(ParsedResult);
  reReslt.SelLength := Length(ParsedResult);
  if Tag = 0 then
    reReslt.SelAttributes.Color := clRed
  else
    reReslt.SelAttributes.Color := clGreen;
  //  reReslt.SelAttributes.Color := RGB(100+Random(100), 100+Random(100), 100+Random(100));

  reReslt.SelLength := 0;
  //  reReslt.Lines.EndUpdate;
end;

//=== { TJvgGroupBoxPlus } ===================================================

procedure TJvgGroupBoxPlus.Paint;
var
  R: TRect;
  S: string;
begin
  inherited Paint;
  //  ChangeBitmapColor((Owner as TJvgLogicsEditorMain).iLink.Picture.Bitmap, GetPixel((Owner as TJvgLogicsEditorMain).iLink.Picture.Bitmap.Canvas.Handle, 0,0), IIF(LogicElement.NextElement<>nil, clGreen, clRed));
  //  BitBlt(Canvas.Handle, 100-14-3, 3, 14, 13, (Owner as TJvgLogicsEditorMain).iLink.Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);

  Canvas.Font.Color := clTeal; //clBlue;
  Canvas.Font.Style := [];
  S := LogicElement.Expression + ' ' + LogicRuleLabels[LogicElement.Rule] +
    ' ' + LogicElement.Value;
  R := Bounds(3, 20, Width - 6, Height - 22);
  Windows.DrawText(Canvas.Handle, PChar(S), Length(S), R,
    DT_WORDBREAK or DT_END_ELLIPSIS or DT_MODIFYSTRING);
end;

procedure TJvgLogicsEditorMain.SBEraseBkgndEvent(Sender: TObject; DC: HDC);
var
  LogicElement: TJvgLogicElement;
  I: Integer;
  PenFalse, Pen, PenTrue, OldPen, PenGrid: HPen;
  Brush: HBrush;
  PrevBox, PrevFalseBox: TJvgGroupBoxPlus;
  Bmp: TBitmap;

  function FindBox(LogicElement: TJvgLogicElement): TJvgGroupBoxPlus;
  var
    I: Integer;
  begin
    Result := nil;
    if LogicElement <> nil then
      for I := 0 to SB.ControlCount - 1 do
        if SB.Controls[I] is TJvgGroupBoxPlus then
          if TJvgGroupBoxPlus(SB.Controls[I]).LogicElement = LogicElement then
          begin
            Result := TJvgGroupBoxPlus(SB.Controls[I]);
            Break;
          end;
  end;

  procedure Line(X, Y, X2, Y2: Integer; IsTrueLine: Boolean);
  const
    R = 5;
  begin
    if IsTrueLine then
      SelectObject(DC, PenTrue)
    else
      SelectObject(DC, PenFalse);
    MoveToEx(DC, X, Y, nil);
    LineTo(DC, X2, Y2);
    SelectObject(DC, Pen);
    if (Abs(X2 - X) < 500) and (Abs(Y2 - Y) < 500) then
      MoveToEx(DC, X, Y + 1, nil);
    LineTo(DC, X2, Y2 + 1);
    Ellipse(DC, X - R - 2, Y - R - 2, X + R * 2 - 2, Y + R * 2 - 2);
    Ellipse(DC, X2 - R - 2, Y2 - R - 2, X2 + R * 2 - 2, Y2 + R * 2 - 2);
  end;

  procedure DrawGrid;
  var
    I: Integer;
  const
    cStep = 14;
  begin
    FillRect(DC, SB.ClientRect, Brush);
    for I := 1 to SB.Width div cStep do
    begin
      MoveToEx(DC, I*cStep, 0, nil);
      LineTo(DC, I*cStep, SB.Height);
    end;
    for I := 1 to SB.Height div cStep do
    begin
      MoveToEx(DC, 0, I*cStep, nil);
      LineTo(DC, SB.Width, I*cStep);
    end;
  end;

begin
  OldPen := 0;
  PenGrid := 0;
  try
    Brush := CreateSolidBrush(clWhite);
    Pen := CreatePen(PS_SOLID, 1, clBlack);
    PenGrid := CreatePen(PS_SOLID, 1, $E0E0E0);
    //PenLong := CreatePen( PS_DASHDOT, 1, $E0E0E0 );
    PenTrue := CreatePen(PS_SOLID, 1, $FF9090);
    PenFalse := CreatePen(PS_SOLID, 1, $009090);
    OldPen := SelectObject(DC, PenGrid);
//    OldBrush := SelectObject(DC, Brush);

    DrawGrid;

    for I := 0 to SB.ControlCount - 1 do
      if SB.Controls[I] is TJvgGroupBoxPlus then
      begin
        LogicElement := TJvgGroupBoxPlus(SB.Controls[I]).LogicElement;
        if LogicElement = nil then
          Exit;

        if LogicElement.IsFirst then
        begin
          MoveToEx(DC, 0, 0, nil);
          LineTo(DC, SB.Controls[I].Left, SB.Controls[I].Top);
        end;

        PrevBox := FindBox(LogicElement.NextElement);
        if Assigned(PrevBox) then
        begin
          Line(SB.Controls[I].Left + SB.Controls[I].Width, SB.Controls[I].Top,
            PrevBox.Left, PrevBox.Top, True);
          DeleteObject(SelectObject(DC, OldPen));
        end;

        PrevFalseBox := FindBox(LogicElement.NextFalseElement);
        if Assigned(PrevFalseBox) then
        begin
          Line(SB.Controls[I].Left + SB.Controls[I].Width, SB.Controls[I].Top +
            SB.Controls[I].Height, PrevFalseBox.Left, PrevFalseBox.Top, False);
          DeleteObject(SelectObject(DC, OldPen));
        end;

        Bmp := TBitmap.Create;
        if LogicElement.NextElement <> nil then
        begin
          ImageList.GetBitmap(0, Bmp);
          BitBlt(DC, SB.Controls[I].Left + SB.Controls[I].Width - 3,
            SB.Controls[I].Top, Bmp.Width, Bmp.Height, Bmp.Canvas.Handle, 0, 0,
            SRCCOPY);
        end;

        if LogicElement.NextFalseElement <> nil then
        begin
          ImageList.GetBitmap(1, Bmp);
          BitBlt(DC, SB.Controls[I].Left + SB.Controls[I].Width - 3,
            SB.Controls[I].Top + SB.Controls[I].Height - 17, Bmp.Width,
            Bmp.Height, Bmp.Canvas.Handle, 0, 0, SRCCOPY);
        end;

        if LogicElement.IsFirst then
        begin
          ImageList.GetBitmap(2, Bmp);
          BitBlt(DC, SB.Controls[I].Left - 20, SB.Controls[I].Top, Bmp.Width,
            Bmp.Height, Bmp.Canvas.Handle, 0, 0, SRCCOPY);
        end;

        Bmp.Free;
      end;
  finally
    SelectObject(DC, Pen);
    DeleteObject(SelectObject(DC, OldPen));
    DeleteObject(PenTrue);
    DeleteObject(PenFalse);
    DeleteObject(PenGrid);
    DeleteObject(Brush);
  end;
  //  for I := 0 to SB.ControlCount-1 do
  //    if (SB.Controls[I] is TJvgShapePlus) then (SB.Controls[I] as TJvgShapePlus).Paint;
end;

procedure TJvgLogicsEditorMain.cbNextChange(Sender: TObject);
begin
  if FActiveBox <> nil then
  begin
    if FActiveBox.LogicElement <> cbNext.Items.Objects[cbNext.ItemIndex] then
      FActiveBox.LogicElement.NextElement :=
        TJvgLogicElement(cbNext.Items.Objects[cbNext.ItemIndex]);
    UpdateView;
  end;
end;

procedure TJvgLogicsEditorMain.cbModeChange(Sender: TObject);
begin
  if FActiveBox <> nil then
    FActiveBox.LogicElement.IsFirst := cbMode.ItemIndex = 1;
end;

//=== { TJvgLogicsEditor } ===================================================

procedure TJvgLogicsEditor.ExecuteVerb(Index: Integer);
begin
  if Index = 0 then
    ShowEditor(TJvgLogicProducer(Component));
end;

function TJvgLogicsEditor.GetVerb(Index: Integer): string;
begin
  case Index of
    0:
      Result := RsEditComponentEllipsis;
  end;
end;

function TJvgLogicsEditor.GetVerbCount: Integer;
begin
  Result := 1;
end;

procedure TJvgLogicsEditor.ShowEditor(LogicProducer: TJvgLogicProducer);
var
  glLogicsEditor: TJvgLogicsEditorMain;
//  Logics: TJvgLogics;
begin
//  Logics := LogicProducer.Logics;
  {  with Logics.Add do
    begin
      Left := 10; Top := 10;
      IsFirst := True;
    end;

    with Logics.Add do
    begin
      Left := 200; Top := 30;
      PrevElementID := Logics[0].ID;
    end;

    Logics[0].NextElementID := Logics[1].ID;

    with Logics.Add do
    begin
      Left := 200; Top := 100;
    end;
  }
  try
    glLogicsEditor := TJvgLogicsEditorMain.Create(nil);
    glLogicsEditor.Execute(LogicProducer);
  finally
    FreeAndNil(glLogicsEditor);
  end;
end;

procedure TJvgLogicsEditorMain.tbNewClick(Sender: TObject);
var
  LogicElement: TJvgLogicElement;
begin
  LogicElement := Logics.Add;
  with LogicElement do
  begin
    Left := SB.Width div 2;
    Top := SB.Height div 2;
    AddBox(LogicElement);
  end;
end;

procedure TJvgLogicsEditorMain.cbNextFalseChange(Sender: TObject);
begin
  if FActiveBox <> nil then
  begin
    if FActiveBox.LogicElement <> cbNextFalse.Items.Objects[cbNextFalse.ItemIndex] then
    begin
      FActiveBox.LogicElement.NextFalseElement :=
        TJvgLogicElement(cbNextFalse.Items.Objects[cbNextFalse.ItemIndex]);
    end;
    UpdateView;
  end;
end;

procedure TJvgLogicsEditorMain.eStepNameChange(Sender: TObject);
begin
  if Assigned(ActiveBox) then
  begin
    ActiveBox.LogicElement.Caption := eStepName.Text;
    ActiveBox.Caption := eStepName.Text;
  end;
end;


procedure TJvgLogicsEditorMain.ToolButton5Click(Sender: TObject);
var
  I: Integer;
begin
  pLog.Visible := True;

  mLog.Lines.Clear;
  reReslt.Text := '';

  Logics.Analyze;

  for I := 0 to SB.ControlCount - 1 do
    if SB.Controls[I] is TJvgGroupBoxPlus then
      if TJvgGroupBoxPlus(SB.Controls[I]).LogicElement.IsTrue then
        TJvgGroupBoxPlus(SB.Controls[I]).Colors.Caption := clGreen;
end;

procedure TJvgLogicsEditorMain.ToolButton7Click(Sender: TObject);
var
  CommentArea: TJvgCommentArea;
begin
  CommentArea := LogicProducer.CommentAreas.Add;
  with CommentArea do
  begin
    Left := SB.Width div 2;
    Top := SB.Height div 2;
    Width := 100;
    Height := 100;
    AddShape(CommentArea);
  end;
end;

//=== { TJvgShapePlus } ======================================================

procedure TJvgShapePlus.Paint;
var
  R: TRect;
  S: string;
begin
  inherited Paint;
  Canvas.Font.Color := clBlue;
  Canvas.Font.Style := [fsBold];
  S := CommentArea.Text;
  R := Bounds(3, 2, Width, Height);
  Windows.DrawText(Canvas.Handle, PChar(S), Length(S), R, DT_WORDBREAK);
end;

procedure TJvgLogicsEditorMain.cbIgnoreSpacesClick(Sender: TObject);
begin
  LogicProducer.IgnoreSpaces := cbIgnoreSpaces.Checked;
end;

procedure TJvgLogicsEditorMain.pLeftDockOver(Sender: TObject; Source:
  TDragDockObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
begin
  Accept := True;
end;

procedure TJvgLogicsEditorMain.pLeftUnDock(Sender: TObject; Client: TControl;
  NewTarget: TWinControl; var Allow: Boolean);
begin
  (Sender as TWinControl).Height := 6;
end;

procedure TJvgLogicsEditorMain.pLeftDockDrop(Sender: TObject; Source:
  TDragDockObject; X, Y: Integer);
begin
  (Sender as TWinControl).Height := 100;
  // (rom) needs reevaluation. Move it out of the screen needs bigger values.
  SBar.Top := 1500;
end;

procedure TJvgLogicsEditorMain.ToolButton8Click(Sender: TObject);
var
  I: Integer;
begin
  if Logics.TraceItem = nil then
  begin
    Logics.StartAnalyze;
    reReslt.Text := '';
  end;
  tbStop.Enabled := True;

  Logics.AnalyzeStep;

  for I := 0 to SB.ControlCount - 1 do
    if SB.Controls[I] is TJvgGroupBoxPlus then
      if TJvgGroupBoxPlus(SB.Controls[I]).LogicElement.IsTrue then
        TJvgGroupBoxPlus(SB.Controls[I]).Colors.Caption := clGreen;
end;

procedure TJvgLogicsEditorMain.tbStopClick(Sender: TObject);
var
  I: Integer;
begin
  Logics.TraceItem := nil;
  tbStop.Enabled := False;

  for I := 0 to SB.ControlCount - 1 do
    if SB.Controls[I] is TJvgGroupBoxPlus then
      if TJvgGroupBoxPlus(SB.Controls[I]).LogicElement.IsTrue then
        TJvgGroupBoxPlus(SB.Controls[I]).Colors.Caption := clBtnShadow;
end;

procedure TJvgLogicsEditorMain.TabSet1Change(Sender: TObject; NewTab: Integer;
  var AllowChange: Boolean);
begin
  PC.ActivePageIndex := NewTab;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -