Programming Implementation of the graphic editing software undo and redo (how to program using C ++ builder or Delphi ??)

Source: Internet
Author: User
Programming Implementation of the graphic editing software undo and redo (how to program using C ++ builder or Delphi ??) Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiMultimedia/html/delphi_2006120713533775.html
Dear colleagues!

Almost all graphic editing software has undo and redo operations. How does one use C ++ builder or Delphi?
Efficient programming implementation ?? How to program full-process operations efficiently ?? Heard and command mode and stack
Related. how to program ??

Please provide specific programming ideas Code , It is best to provide targeted C ++ builder or Delphi
Complete example. Thank you !!

Note: If you reference someone else's post too long, please only provide the URL, do not post the post content directly,
Thank you for your cooperation !!

Start with the command mode.

Generally, the change history is stored in the virtual memory, so that many processes are irreversible.

Mode: Implement undo and redo by creating a stack on your own.AlgorithmConsider it as needed. Different applications have different algorithms. This is how my network cabling auxiliary design system is designed.

Ladies and Gentlemen:
Can code be provided ?? Thank you !!

Yes. Serving members wholeheartedly is our purpose.

To sanmaotuo (laifeng)
I got a star. Come on!

My graphic editing function is like this: you can draw lines, circles, ovans, and various elements on the canvas.
Select, move, rotate, and change the shape with the mouse, as well as the entire image (including the original layout and subsequent painting)
Can perform operations such as fuzzy and sharpening. How can I program undo and redo with such software ?? How to program the entire process efficiently ?? Please give me the code happymanfreeman@sohu.com thank you !!

I got a star. Come on!

---------------------

Congratulations, big brother. I must redouble my efforts.

Interface

Uses
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;

................................ All copyright moderators: laifeng

Learn the Undo and redo functions of Dr. Feng! I used to add an index variable to a list. Khan...

Please introduce the targeted C ++ builder or Delphi
Complete example. Thank you !!

It is impossible to give you a complete example.


I am talking about "Introduction" targeted C ++ builder or Delphi on the Internet

Complete example !! Who will introduce all the users in 200.

It is your rights and obligations to whom it is assigned. However, csdn is not the cradle for cultivating slots.

It is your rights and obligations to whom it is assigned. However, csdn is not the cradle for cultivating slots.
========================================================== ========================================================== =
What I said! You just gave him a complete example, and I don't know how to score you that day. I gave a complete example in another post by the landlord, and I didn't see whether it was correct or not. I don't even know what the landlord meant to answer the post. Therefore, before replying to the post, I always search for whether the poster has an old post that is not answered. If the problem is basically solved and the poster does not answer the post, I will know and will not reply to the post.

See another post by the landlord:

Http://community.csdn.net/Expert/topic/5185/5185934.xml? Temp =. 7544062.

Sorry, some posts are missing due to busy times. Don't be surprised! Now let's take a look at the above posts, such as problem solving,
Immediately score and close the post.

!! :)

Everyone has

Post is beautiful

Vector graphics engine tcad XP (CAD Component)
For more information, see:
Http://www.codeidea.com

How stack is used.

Http://www.codeidea.com/cn/

All of them are closed. Our friends in Huzhou are still selling advertisements to your boss Hongbin.

If your operation object is not large, you can use the object cloning method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.