各位高手: 大家好! 几乎所有的图形编辑软件都有undo与redo操作, 用c++builder或delphi如何
高效地编程实现 ?? 高效地全程操作如何编程 ?? 听说与command 模式和堆栈
有关. 具体如何编程呢 ??
请教具体编程思路, 请给出代码, 最好提供针对性的c++builder或delphi
完整例子. 谢谢 !!
高效地编程实现 ?? 高效地全程操作如何编程 ?? 听说与command 模式和堆栈
有关. 具体如何编程呢 ??
请教具体编程思路, 请给出代码, 最好提供针对性的c++builder或delphi
完整例子. 谢谢 !!
解决方案 »
- Qreport预览时窗体如何最大化??
- 利用 TMediaPlayer 多线程播放.同时播放多个文件.
- @@为什么我的程序在关闭delphi的时候出错:Access violation at address 0083B551 in module ‘VCL70.BPL’.Read of address FFFFFFFF.
- 怎样设置ValueListEditor控件的某一个Cell的焦点?
- 如何将sql server数据库中的某些表的数据导出?它的结构可以用sql脚本导出,但是数据呢?在线等待。多谢!!
- 大家新年好,有个问题好久没人能正确回答,给大家送个礼..........
- 关于VCLZip控件的分盘压缩和解压缩的问题(★★★着急,在线等侍★★★)
- DELPHI问题大观(1):在中国的程序员,有多少delphi程序员?又有多少delphi高手?(null)
- 表循环速度慢的问题.
- 代码?机器?问题(简单ADO代码),请进……
- createoleobject对象的问题?
- 求助高手?
以免影响大家阅读, 谢谢合作 !!
我升星了,你快加油啊!
用鼠标选定, 移动, 旋转, 改变形状等, 还有, 整个图形(包括原画布及后来各种画上去的)
能进行模糊,锐化等操作. 这样的软件实现UNDO 和 REDO如何编程啊?? 高效地全程操作如何编程啊 ?? 请把代码给我 [email protected] 谢谢!!
Classes;type
TUnDoItem = class(TCollectionItem)
private
FActionName: string;
FState: TStream; //Used to Save Your Graphics At Each Undo&Redo
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
property ActionName: string read FActionName write FActionName;
property State: TStream read FState;
end; TUnDoStack = class(TCollection)
private
FCurrent: Integer;
//FNetGraphics: TNetGraphics;
procedure ClearUndoStack;
procedure PushState(const AActionName: string);
procedure Undo;
procedure Redo;
function NextUndoAction: string;
function NextRedoAction: string;
protected
public
constructor Create(const ANetGraphics: TNetGraphics);
end;implementation{ TUnDoItem }constructor TUnDoItem.Create(Collection: TCollection);
begin
inherited Create(Collection);
FState := TMemoryStream.Create;
end;destructor TUnDoItem.Destroy;
begin
FState.Free;
inherited;
end;{ TUnDoStack }procedure TUnDoStack.ClearUndoStack;
begin
Clear;
FCurrent := -1;
PushState('');
end;constructor TUnDoStack.Create(ANetGraphics: TNetGraphics);
begin
inherited Create(TUnDoItem);
Assert(ANetGraphics <> nil, 'ANetGraphics Is Nil');
FNetGraphics := ANetGraphics;
FCurrent := -1;
end;function TUnDoStack.NextRedoAction: string;
begin
Result := '';
//Change Condition From On Line to MutilLines Which Is From Martin Fowler's Refactor
if FCurrent >= -1 then
if FCurrent < Pred(Count) then
Result := TUndoItem(Items[Succ(FCurrent)]).ActionName;
end;function TUnDoStack.NextUndoAction: string;
begin
Result := '';
//Change Condition From On Line to MutilLines Which Is From Martin Fowler's Refactor
if FCurrent > -1 then
if FCurrent < Count then
Result := TUndoItem(Items[FCurrent]).ActionName;
end;procedure TUnDoStack.PushState(const AActionName: string);
begin
while FCurrent < Pred(Count) do
Items[Pred(Count)].Free; with TUndoItem(Add) do
begin
ActionName := AActionName;
//......
{Save Your Graphics Here}
FNetGraphics.SaveToStream(FState);//Here is My Application's Coding;
//......
Inc(FCurrent);
end; if Count > 20 then //Set Max Count of UNDO&REDO
begin
Items[0].Free;
Dec(FCurrent);
end;
end;procedure TUnDoStack.Redo;
begin
//Change Condition From On Line to MutilLines Which Is From Martin Fowler's Refactor
if FCurrent >= -1 then
if FCurrent < Pred(Count) then
begin
//......
{Initial Your Graphics Here}
FNetGraphics.Clear; //Here is My Application's Coding;
//......
With TUndoItem(Items[Succ(FCurrent)]) do
begin
FState.Position := 0;
//......
{Load Your Graphics Here}
FNetGraphics.LoadFromStream(FState); //Here is My Application's Coding;
//......
end;
Inc(FCurrent);
end;
end;procedure TUnDoStack.Undo;
begin
//Change Condition From On Line to MutilLines Which Is From Martin Fowler's Refactor
if FCurrent > 0 then
if FCurrent <= Count then
begin
//......
{Initial Your Graphics Here}
FNetGraphics.Clear; //Here is My Application's Coding;
//......
With TUndoItem(Items[Pred(FCurrent)]) do
begin
FState.Position := 0;
//......
{Load Your Graphics Here}
FNetGraphics.LoadFromStream(FState); //Here is My Application's Coding;
//......
end;
Dec(FCurrent);
end;
end;...........................版权所有 版权人: 老冯
完整例子. 谢谢 !!
我说的是"介绍"网上的针对性c++builder或delphi完整例子 !! 谁介绍200分全部给谁.
=================================================================================
老弟说的好!你就是给了他完整的例子,也不知道那天给你分。我在楼主另一帖给了较完整的例子,也没见说正确与否,更不见楼主有接帖的意思,没意思。所以我现在回帖前总是搜索一下发帖人是否有老帖未接的,如果问题基本解决楼主不接帖的,我就是知道也不回帖的。见楼主另一帖:http://community.csdn.net/Expert/topic/5185/5185934.xml?temp=.7544062
详细信息请看:
http://www.codeidea.com