Command Pattern for undo/redo in paint application

后端 未结 2 1228
时光取名叫无心
时光取名叫无心 2021-02-06 14:47

I would like to implement undo/redo in a small paint application. It seems the Command Pattern fits the use nicely, but I am unsure how to best implement it.

As I unders

相关标签:
2条回答
  • 2021-02-06 15:20

    I would stick with command pattern and first try a naive solution (=the most memory-hungry). For some graphical operations it may be even necessary to keep a copy of the entire image in the command object (eg. think of filters). This is a common problem also in professional image editing applications, they often have a memory or step limit of last commands that are remembered. And if the memory consumption is really large you may think of swapping the oldest entries in command-history to file system. I think user will not mind waiting a second until the change is undone.

    0 讨论(0)
  • 2021-02-06 15:24

    Maybe, it would be better not to store copy of entire image in command, but store only copy of area, which is changing by command. Of course, this is not a panacea

    0 讨论(0)
提交回复
热议问题