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

📄 dibanimeditor.pas

📁 Delphi控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit DIBAnimEditor;

{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: DIBAnimEditor.PAS, released August 28, 2000.

The Initial Developer of the Original Code is Peter Morris (pete@droopyeyes.com),
Portions created by Peter Morris are Copyright (C) 2000 Peter Morris.
All Rights Reserved.

Purpose of file:
Property editor for animations.

Contributor(s):
Sylane - sylane@excite.com


Last Modified: March 02, 2001

You may retrieve the latest version of this file at the Project JEDI home page,
located at http://www.delphi-jedi.org
or at http://www.stuckindoors.com/dib


Known Issues:
 Sylane: It's not possible to edit or rename the last node of the tree
         with dblclick or shortcut ! ! !

Data : 02 - Mar, 2001 :
By: Sylane - sylane@excite.com
Changes:
- Added a TDIBPalette component, otherwise the editor wouldn't work
	in 256 colors mode.
-	Added Shortcut for adding editing and deleting Animations/Frames
	Fixed a Bug occuring when Animations are deleted...
  	(The probleme may be much deeper but no more time available :)
- Added context menus to the TTreeView for convenience.


Date : 31 - Aug, 2000 :
By :pete@droopyeyes.com
Changes
Made TxxxxxxEditor to TxxxxxxxProperty to comply with VCL standards.
Made sure all unit names start with DIB to avoice conflicts with other people's
component packs.

-----------------------------------------------------------------------------}


interface

{$I OpenSource/dfs.inc}

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  {$IFDEF DFS_NO_DSGNINTF}
  DesignEditors, DesignIntf,
  {$ELSE}
  DsgnIntf,
  {$ENDIF}
  TypInfo, cDIBAnimMgr, ExtCtrls, ComCtrls, Menus, cDIB,
  cDIBControl, cDIBImage, cDIBPanel, StdCtrls, cDIBFadeLabel, Spin,
  cDIBSlider, cDIBDial, cDIBImageList, cDIBPalette;

type
  TfmAnimEditor = class(TForm)
    dicRender: TDIBImageContainer;
    diRender: TDIBImage;
    pnlControl: TDIBImageContainer;
    btnOK: TButton;
    pnlProperties: TPanel;
    tvAnimations: TTreeView;
    dflOpacity: TDIBFadeLabel;
    edOpacity: TEdit;
    dflScale: TDIBFadeLabel;
    edScale: TEdit;
    dflAngle: TDIBFadeLabel;
    edAngle: TEdit;
    mnMain: TMainMenu;
    Item1: TMenuItem;
    N2: TMenuItem;
    miDelete: TMenuItem;
    DIBFadeLabel1: TDIBFadeLabel;
    cbImageList: TComboBox;
    Animation1: TMenuItem;
    Frame1: TMenuItem;
    miNewAnimation: TMenuItem;
    miRenameAnimation: TMenuItem;
    miNewFrame: TMenuItem;
    miEditFrame: TMenuItem;
    dibPalette: TDIBPalette;
    pmAnimPop: TPopupMenu;
    miAnimNewFrame: TMenuItem;
    miAnimDeleteAnim: TMenuItem;
    miAnimRename: TMenuItem;
    pmFramePop: TPopupMenu;
    ChoseImage1: TMenuItem;
    DeleteFrame1: TMenuItem;
    pmBackPop: TPopupMenu;
    miBackNewAnim: TMenuItem;
    udOpacity: TUpDown;
    udScale: TUpDown;
    udAngle: TUpDown;
    procedure miDeleteClick(Sender: TObject);
    procedure tvAnimationsChange(Sender: TObject; Node: TTreeNode);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure edOpacityChange(Sender: TObject);
    procedure edScaleChange(Sender: TObject);
    procedure edAngleChange(Sender: TObject);
    procedure Item1Click(Sender: TObject);
    procedure miRenameAnimationClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cbImageListChange(Sender: TObject);
    procedure miNewAnimationClick(Sender: TObject);
    procedure miNewFrameClick(Sender: TObject);
    procedure miEditFrameClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure tvAnimationsDblClick(Sender: TObject);
    procedure tvAnimationsKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure tvAnimationsMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure tvAnimationsDragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure tvAnimationsDragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
  private
    { Private declarations }
    {$IFDEF DFS_NO_DSGNINTF}
    Designer: IDesigner;
    {$ELSE}
    Designer: IFormDesigner;
    {$ENDIF}
    FAnimations: TDIBAnimMgrList;
    FInternalUpdate: Boolean;

    procedure AddImageListItem(const S: string);
    procedure SetAnimations(const Value: TDIBAnimMgrList);
    procedure SetData;
    procedure UpdateNames;
  protected
  public
    { Public declarations }
    procedure UpdateDisplay;

    property Animations: TDIBAnimMgrList read FAnimations write SetAnimations;
  end;

  TDIBAnimMgrListProperty = class(TClassProperty)
  private
  protected
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
  published
  end;

  TDIBFrameListProperty = class(TClassProperty)
  private
  protected
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
  published
  end;

var
  fmAnimEditor: TfmAnimEditor;

implementation

uses 
  DIBImageIndexEditor;

{$R *.DFM}

{ TDIBAnimMgrListProperty }

procedure TDIBAnimMgrListProperty.Edit;
begin
  fmAnimEditor := TfmAnimEditor.Create(Application);

  with fmAnimEditor do
    try
      Designer := Self.Designer;
      Animations := TDIBAnimMgrList(Self.GetOrdValue);
      UpdateDisplay;
      ShowModal;
    finally
      fmAnimEditor.Release;
      fmAnimEditor := nil;
    end;
end;

function TDIBAnimMgrListProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog, paReadOnly];
end;

function TDIBAnimMgrListProperty.GetValue: string;
begin
  Result := '(Animations)';
end;

{ TDIBFrameListProperty }

procedure TDIBFrameListProperty.Edit;
begin
end;

function TDIBFrameListProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paReadOnly];
end;

function TDIBFrameListProperty.GetValue: string;
begin
  Result := 'USE EDITOR';
end;

{ TfmAnimEditor }

procedure TfmAnimEditor.SetAnimations(const Value: TDIBAnimMgrList);
begin
  FAnimations := Value;
end;

procedure TfmAnimEditor.UpdateDisplay;
var
  Main, Child: Integer;
  Item: TTreeNode;
begin
  tvAnimations.Items.Clear;
  for Main := 0 to FAnimations.Count - 1 do with FAnimations[Main].Animation do 
    begin
      Item := tvAnimations.Items.AddObject(nil, Name, FAnimations[Main].Animation);
      for Child := 0 to Frames.Count - 1 do
        tvAnimations.Items.AddChildObject(Item, Frames[Child].DisplayName, Frames[Child]);
    end;
end;

procedure TfmAnimEditor.miDeleteClick(Sender: TObject);
var
  NeedNameUpdate: Boolean;
  {Sylane 2/03/2001}
  lIndex: Integer;
  {End Sylane 2/03/2001}
begin
  if tvAnimations.Selected = nil then Exit;
  NeedNameUpdate := TObject(tvAnimations.Selected.Data) is TDIBFrameItem;
  {Sylane 2/03/2001}
  //  TObject(tvAnimations.Selected.Data).Free;
  if tvAnimations.Selected.Parent = nil then
  begin
    for lIndex := 0 to (fAnimations.Count - 1) do
      if fAnimations[lIndex].Animation = TDIBAnimation(tvAnimations.Selected.Data) then
      begin
        fAnimations.Delete(lIndex);
        break;
      end;
  end
  else
    TObject(tvAnimations.Selected.Data).Free;
  {End Sylane 2/03/2001}
  tvAnimations.Items.Delete(tvAnimations.Selected);

  if NeedNameUpdate then UpdateNames;
end;

procedure TfmAnimEditor.tvAnimationsChange(Sender: TObject;
  Node: TTreeNode);
var
  Animation: TDIBAnimation;
begin
  if tvAnimations.Selected = nil then exit;

  if TObject(Node.Data) is TDIBFrameItem then with TDIBFrameItem(Node.Data) do 
    begin
      FInternalUpdate := True;
      try
        cbImageList.Enabled := False;
        cbImageList.ItemIndex := -1;

⌨️ 快捷键说明

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