You've already forked lazarus-ccr
richmemo: added inline objects demo.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3848 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
8453
components/richmemo/samples/inline/mainform.lfm
Normal file
8453
components/richmemo/samples/inline/mainform.lfm
Normal file
File diff suppressed because it is too large
Load Diff
163
components/richmemo/samples/inline/mainform.pas
Normal file
163
components/richmemo/samples/inline/mainform.pas
Normal file
@ -0,0 +1,163 @@
|
||||
unit mainform;
|
||||
{
|
||||
Richmemo Inline demo
|
||||
|
||||
Author: Dmitry 'skalogryz' Boyarintsev
|
||||
|
||||
*****************************************************************************
|
||||
* *
|
||||
* This file is part of the Rich Memo package *
|
||||
* You're free to use the project and the file in anyway you find fit. *
|
||||
* You're free to copy and modify the file. No need to keep the refernce *
|
||||
* to the origin of the file. *
|
||||
* *
|
||||
*****************************************************************************
|
||||
}
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Types, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
||||
LCLIntf, StdCtrls, ExtCtrls, RichMemo, RichMemoUtils;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
Button1: TButton;
|
||||
Button2: TButton;
|
||||
Button3: TButton;
|
||||
ImageList1: TImageList;
|
||||
OpenDialog1: TOpenDialog;
|
||||
RichMemo1: TRichMemo;
|
||||
Timer1: TTimer;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure Button2Click(Sender: TObject);
|
||||
procedure Button3Click(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
procedure Timer1Timer(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
public
|
||||
{ public declarations }
|
||||
framecnt : Integer;
|
||||
anims : TList;
|
||||
procedure AnimRemove(Sender: TObject);
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
type
|
||||
{ TInlineImage }
|
||||
|
||||
TInlineImage = class(TRichMemoInline)
|
||||
public
|
||||
imageList : TImageList;
|
||||
frame : integer;
|
||||
startTime : LongWord;
|
||||
// in this particular demo, each animated image gets its own timer
|
||||
// infact, this is ineffecient way and it should only be one timer used
|
||||
visible : Boolean;
|
||||
OnRemove : TNotifyEvent;
|
||||
destructor Destroy; override;
|
||||
procedure Draw(Canvas: TCanvas; const ASize: TSize); override;
|
||||
procedure SetVisible(AVisible: Boolean); override;
|
||||
end;
|
||||
|
||||
{ TInlineImage }
|
||||
|
||||
destructor TInlineImage.Destroy;
|
||||
begin
|
||||
if Assigned(OnRemove) then OnRemove(self);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
||||
procedure TInlineImage.Draw(Canvas: TCanvas; const ASize: TSize);
|
||||
begin
|
||||
imageList.Draw(Canvas, 0,0, frame);
|
||||
end;
|
||||
|
||||
procedure TInlineImage.SetVisible(AVisible: Boolean);
|
||||
begin
|
||||
visible:=AVisible;
|
||||
end;
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.Button1Click(Sender: TObject);
|
||||
begin
|
||||
if OpenDialog1.Execute then
|
||||
LoadRTFFile( RichMemo1, OpenDialog1.FileName );
|
||||
end;
|
||||
|
||||
procedure TForm1.Button2Click(Sender: TObject);
|
||||
var
|
||||
inlineimg : TInlineImage;
|
||||
begin
|
||||
inlineimg := TInlineImage.Create;
|
||||
inlineimg.imageList:=ImageList1;
|
||||
inlineimg.frame:=framecnt;
|
||||
RichMemo1.InDelInline(inlineimg, RichMemo1.SelStart, 0, Size(round(ImageList1.Width*72/96),round(ImageList1.Height*72/96)));
|
||||
|
||||
inc(framecnt);
|
||||
if framecnt>=ImageList1.Count then framecnt:=0;
|
||||
end;
|
||||
|
||||
procedure TForm1.Button3Click(Sender: TObject);
|
||||
var
|
||||
inlineimg : TInlineImage;
|
||||
i : integer;
|
||||
begin
|
||||
inlineimg := TInlineImage.Create;
|
||||
inlineimg.imageList:=ImageList1;
|
||||
inlineimg.startTime:=GetTickCount;
|
||||
anims.add(inlineimg);
|
||||
RichMemo1.InDelInline(inlineimg, RichMemo1.SelStart, 0, Size(round(ImageList1.Width*72/96),round(ImageList1.Height*72/96)));
|
||||
end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
begin
|
||||
anims:=TList.Create;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormDestroy(Sender: TObject);
|
||||
begin
|
||||
anims.Free;
|
||||
anims:=nil;
|
||||
end;
|
||||
|
||||
procedure TForm1.Timer1Timer(Sender: TObject);
|
||||
var
|
||||
i : integer;
|
||||
im : TInlineImage;
|
||||
diff : LongWord;
|
||||
tck : LongWord;
|
||||
begin
|
||||
tck:=GetTickCount;
|
||||
for i:=0 to anims.Count-1 do begin
|
||||
im := TInlineImage(anims[i]);
|
||||
if not im.visible then Exit;
|
||||
diff:=tck-im.startTime;
|
||||
im.frame:=round(diff/55) mod im.imageList.Count;
|
||||
im.Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.AnimRemove(Sender: TObject);
|
||||
begin
|
||||
if Assigned(anims) then anims.Remove(Sender);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
92
components/richmemo/samples/inline/testinline.lpi
Normal file
92
components/richmemo/samples/inline/testinline.lpi
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="testinline"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
</i18n>
|
||||
<VersionInfo>
|
||||
<StringTable ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="\usr\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="2">
|
||||
<Item1>
|
||||
<PackageName Value="richmemopackage"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="2">
|
||||
<Unit0>
|
||||
<Filename Value="testinline.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="testinline"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="mainform.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="mainform"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="testinline"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<MsgFileName Value=""/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
20
components/richmemo/samples/inline/testinline.lpr
Normal file
20
components/richmemo/samples/inline/testinline.lpr
Normal file
@ -0,0 +1,20 @@
|
||||
program testinline;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, mainform, richmemopackage;
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
RequireDerivedFormResource := True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
Reference in New Issue
Block a user