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

📄 lcdscreeneditor.pas.svn-base

📁 LCDScreen is a couple of Delphi component which simulate a dot-LCD multilines screen. It is fully c
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
unit LCDScreenEditor;

////////////////////////////////////////////////////////////////////////////////
//
//  TLCDScreen / TLCDAnimator v2.5 (15/aug/01)
//  written by Jacques VOIRIN
//  E-Mail: jacques.voirin@iname.com
//
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//
//   This unit contain all the routines for the TLCDScreenLinesEditor
// (registering the editor, associate TLCDScreen.Lines to it), the syntax
// analysis and its form TLCDScreenLinesEditorForm.
//
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//
//  Please notice bugs or problems, suggestions and improvements at
//
//  jacques.voirin@iname.com
//
//////////////////////////////////////////////////////////////////////////////////


interface

uses
  Windows, SysUtils, Classes, Controls, Forms, StdCtrls, Graphics, Menus, 
  {$IFDEF  VER140}
    DesignIntf, DesignEditors,
  {$ELSE}
    DsgnIntf,
  {$ENDIF}
  Grids, ExtCtrls, Math, Dialogs, LCDScreen;

type

////////////////////////////////////////////////////////////////////////////////
//
// TLCDScreenEditor is the TComponentEditor which generate the custom context
// menu when TLCDScreen is left-clicked and then display the LCDScreenLinesEditorForm.
//
////////////////////////////////////////////////////////////////////////////////

  TLCDScreenEditor = class(TComponentEditor)
  public
    procedure ExecuteVerb(Index: Integer); override;
    function  GetVerb(Index: Integer): String; override;
    function  GetVerbCount: Integer; override;
  end;


////////////////////////////////////////////////////////////////////////////////
//
// TLCDScreenLinesEditorProperty is the TPropertyEditor in relation with 'Lines'
// property of TLCDScreen. Clicking on '...' in the Object Inspector display
// the LCDScreenLinesEditorForm.
//
////////////////////////////////////////////////////////////////////////////////

  TLCDScreenLinesEditorProperty = class(TPropertyEditor)
    procedure Edit; override;
    function  GetValue: String; override;
    function  GetAttributes: TPropertyAttributes; override;
    private
  end;


////////////////////////////////////////////////////////////////////////////////
//
// TLCDAnimatorCodeEditorForm is the CodeEditor form, which allow to write
// the code for the animation.
//
////////////////////////////////////////////////////////////////////////////////

  TLCDScreenLinesEditorForm = class(TForm)
    LinesStringGrid: TStringGrid;
    OkButton: TButton;
    CancelButton: TButton;
    InsertButton: TButton;
    AddButton: TButton;
    DeleteButton: TButton;
    ClearButton: TButton;
    EditButton: TButton;
    BlinkingButton: TButton;
    InverseButton: TButton;
    RemoveSpButton: TButton;
    OKEditButton: TButton;
    CancelEditButton: TButton;
    Bevel1: TBevel;
    LinesCellPUM: TPopupMenu;
    EditMenu: TMenuItem;
    N1: TMenuItem;
    InsertMenu: TMenuItem;
    AddMenu: TMenuItem;
    DeleteMenu: TMenuItem;
    N2: TMenuItem;
    ClearMenu: TMenuItem;
    N3: TMenuItem;
    BlinkingMenu: TMenuItem;
    LineGridPanel: TPanel;
    EditLinePanel: TPanel;
    LineEdit: TEdit;
    Timer: TTimer;
    UnderlineButton: TButton;
    StrikeButton: TButton;
    Bevel2: TBevel;
    procedure LinesStringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure LinesStringGridKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure LinesStringGridClick(Sender: TObject);
    procedure LinesStringGridMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure LineEditMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure LineEditMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure LineEditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure InsertButtonClick(Sender: TObject);
    procedure AddButtonClick(Sender: TObject);
    procedure DeleteButtonClick(Sender: TObject);
    procedure EditButtonClick(Sender: TObject);
    procedure CancelEditButtonClick(Sender: TObject);
    procedure OKEditButtonClick(Sender: TObject);
    procedure ClearButtonClick(Sender: TObject);
    procedure BlinkingButtonClick(Sender: TObject);
    procedure InverseButtonClick(Sender: TObject);
    procedure UnderlineButtonClick(Sender: TObject);
    procedure StrikeButtonClick(Sender: TObject);
    procedure TimerTimer(Sender: TObject);
    procedure BlinkingMenuClick(Sender: TObject);
    function  NbOfRealLines(Grid: TStringGrid): Byte;
    procedure RemoveSpButtonClick(Sender: TObject);
    procedure LineEditExit(Sender: TObject);
  end;

procedure Register;


var
  LCDScreenLinesEditorForm: TLCDScreenLinesEditorForm;
  FBlinking: Boolean;
  LCDScreenNbOfChars, LCDScreenNbOfLines: Byte;
  PixOnColor, PixOffColor: TColor;

implementation

{$R *.DFM}




////////////////////////////////////////////////////////////////////////////////
//
//  General Intrest Routines.
//
//  Count LCDScreen's special characters (i.e. 10 <= Ord(x) <= 20)
//  in a String.
//
////////////////////////////////////////////////////////////////////////////////

function CountSpecialCharString(temp: String): Byte;
var col, maxspecialchar: Byte;
begin
  maxspecialchar := 0;
  if Length(temp) <> 0
  then for col := 0 to Length(temp)
  do if (Ord(temp[col]) >= 10) and (Ord(temp[col]) <= 20)
     then Inc(maxspecialchar);

  CountSpecialCharString := maxspecialchar;
end;


////////////////////////////////////////////////////////////////////////////////
//
// TLCDScreenEditor
//
// Result := 1; Only one personalized entry in the context menu
//
////////////////////////////////////////////////////////////////////////////////

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


////////////////////////////////////////////////////////////////////////////////
//
// TLCDScreenEditor
//
// Result := 'LCDScreen Lines Editor'; The caption of the personalized entry
//                                     in the context menu
//
////////////////////////////////////////////////////////////////////////////////

function  TLCDScreenEditor.GetVerb(Index: Integer): String;
begin
  Result := 'LCDScreen Lines Editor';
end;


////////////////////////////////////////////////////////////////////////////////
//
// TLCDScreenEditor
//
// This is te code displaying the editor form when 'LCDScreen Lines Editor' in
// the context menu is clicked or the component double-clicked;
//
////////////////////////////////////////////////////////////////////////////////

procedure TLCDScreenEditor.ExecuteVerb(Index: Integer);
var F: TLCDScreenLinesEditorForm;
    i, j, k, offset: Byte;
    tempstr: String;
begin
  F := TLCDScreenLinesEditorForm.Create(Application);
  try
    LCDScreenNbOfChars := (Component as TLCDScreen).NoOfChars;
    LCDScreenNbOfLines := (Component as TLCDScreen).NoOfLines;

    F.Caption := 'TLCDScreen Lines Editor - ' + (Component as TLCDScreen).Name + ' - [' +
                 InttoStr(LCDScreenNbOfLines) + ' Lines x ' +
                 InttoStr(LCDScreenNbOfChars) + ' Characters]';

    F.LinesStringGrid.RowCount := Max(LCDScreenNbOfLines, (Component as TLCDScreen).Lines.Count) + 2;

    PixOnColor  := (Component as TLCDScreen).PixelOn;
    PixOffColor := (Component as TLCDScreen).PixelOff;
    F.LinesStringGrid.Color := PixOffColor;
    F.LinesStringGrid.Font.Color := PixOnColor;

    k := LCDScreenNbOfChars;

    F.LinesStringGrid.Cells[0,0] := '*';

  { Load Code lines from TLCDScreen to LinesStringGrid }
    if (Component as TLCDScreen).Lines.Count <> 0
    then for i := 0 to (Component as TLCDScreen).Lines.Count - 1
         do begin
              F.LinesStringGrid.Cells[0, i + 1] := (Component as TLCDScreen).Lines[i];

              tempstr := (Component as TLCDScreen).Lines[i];
              if Length(tempstr) <> 0
              then begin
                     j := 0;
                     offset := 0;
                     repeat
                       if CountSpecialCharString(tempstr[j + 1]) = 0
                       then F.LinesStringGrid.Cells[j + 1 - offset, i + 1] := tempstr[j + 1]
                       else Inc(offset);
                       Inc(j);
                       until j >= Length(tempstr);
                     end;
              k := Max(Length(F.LinesStringGrid.Cells[0, i + 1]) -
                       CountSpecialCharString(F.LinesStringGrid.Cells[0, i + 1]), k);
              end;

    F.LinesStringGrid.ColCount := k + 2;

    if F.ShowModal = mrOK  //Display the Editor form
    then begin
           (Component as TLCDScreen).Lines.Clear;

  { UnLoad Code lines from LinesStringGrid to TLCDScreen }
           if F.LinesStringGrid.RowCount <> 0
           then for i := 1 to F.NbOfRealLines(F.LinesStringGrid)
                do (Component as TLCDScreen).Lines.Append(F.LinesStringGrid.Cells[0, i]);

           try Designer.Modified; except end;
           end;
  finally
    F.Free;
  end;
end;


////////////////////////////////////////////////////////////////////////////////
//
// TLCDScreenLinesEditorProperty
//
// Result := '(TStringList)'; The 'Lines' caption displayed in the Obj. Inspector
//
////////////////////////////////////////////////////////////////////////////////

function TLCDScreenLinesEditorProperty.GetValue: String;
begin
  Result := '(TStringList)';
end;


////////////////////////////////////////////////////////////////////////////////
//
// TLCDScreenLinesEditorProperty
//
// Result := [paDialog]; Indicates that the '...' button in the Object Inspector
//                       will bring up a dialog form
//
////////////////////////////////////////////////////////////////////////////////

function TLCDScreenLinesEditorProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog];
end;


////////////////////////////////////////////////////////////////////////////////
//
// TLCDScreenLinesEditorProperty
//
// The code displaying the editor form when the '...' button in the Object
// Inspector is clicked
//
////////////////////////////////////////////////////////////////////////////////

procedure TLCDScreenLinesEditorProperty.Edit;
var F: TLCDScreenLinesEditorForm;
    C: TPersistent;
    i, j, k, offset: Byte;
    tempstr: String;
begin
  C := GetComponent(0);
  F := TLCDScreenLinesEditorForm.Create(Application);

  try
    LCDScreenNbOfChars := (C as TLCDScreen).NoOfChars;
    LCDScreenNbOfLines := (C as TLCDScreen).NoOfLines;

    F.Caption := 'TLCDScreen Lines Editor - ' + (C as TLCDScreen).Name + ' - [' +
                 InttoStr(LCDScreenNbOfLines) + ' Lines x ' +
                 InttoStr(LCDScreenNbOfChars) + ' Characters]';

    F.LinesStringGrid.RowCount := Max(LCDScreenNbOfLines, (C as TLCDScreen).Lines.Count) + 2;

    PixOnColor  := (C as TLCDScreen).PixelOn;
    PixOffColor := (C as TLCDScreen).PixelOff;
    F.LinesStringGrid.Color := PixOffColor;
    F.LinesStringGrid.Font.Color := PixOnColor;

    k := LCDScreenNbOfChars;

    F.LinesStringGrid.Cells[0,0] := '*';

  { Load Code lines from TLCDScreen to LinesStringGrid }
    if (C as TLCDScreen).Lines.Count <> 0
    then for i := 0 to (C as TLCDScreen).Lines.Count - 1
         do begin
              F.LinesStringGrid.Cells[0, i + 1] := (C as TLCDScreen).Lines[i];

              tempstr := (C as TLCDScreen).Lines[i];
              if Length(tempstr) <> 0
              then begin
                     j := 0;
                     offset := 0;
                     repeat
                       if CountSpecialCharString(tempstr[j + 1]) = 0
                       then F.LinesStringGrid.Cells[j + 1 - offset, i + 1] := tempstr[j + 1]
                       else Inc(offset);
                       Inc(j);
                       until j >= Length(tempstr);
                     end;
              k := Max(Length(F.LinesStringGrid.Cells[0, i + 1]) -
                       CountSpecialCharString(F.LinesStringGrid.Cells[0, i + 1]), k);
              end;

    F.LinesStringGrid.ColCount := k + 2;

  if F.ShowModal = mrOk  //Display the Editor form
    then begin
           (C as TLCDScreen).Lines.Clear;

  { UnLoad Code lines from LinesStringGrid to TLCDScreen }
           if F.LinesStringGrid.RowCount <> 0
           then for i := 1 to F.NbOfRealLines(F.LinesStringGrid)
                do (C as TLCDScreen).Lines.Append(F.LinesStringGrid.Cells[0, i]);

           try Designer.Modified; except end;
           end;
  finally
    F.Free;
  end;
end;

////////////////////////////////////////////////////////////////////////////////
//
// Registration of the context menu and 'Lines  [...]' in the ObjectInspector.
//
////////////////////////////////////////////////////////////////////////////////

function TLCDScreenLinesEditorForm.NbOfRealLines(Grid: TStringGrid): Byte;
var i: Byte;
begin
  with Grid do begin
                 i := RowCount;
                 repeat
                   Dec(i);
                   until (Cells[0, i] <> '') or (i = 0);
                 end;

  NbOfRealLines := i;
end;


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// Begining of the routines for the Form Editor                               //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////


procedure TLCDScreenLinesEditorForm.LinesStringGridDrawCell(
  Sender: TObject; ACol, ARow: Integer; Rect: TRect;
  State: TGridDrawState);
var str: String;
    i, offset,

⌨️ 快捷键说明

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