将撤消选项放入 OpenTk 项目中
你好,我正在制作画笔之类的东西,它在 glcontrol
中绘制一些基本形状,现在我想添加撤消选项,我真的不知道这将如何工作,所以请给我任何提示
Hi there i was making Paint Brush kind of thing which Draws some basic shapes in glcontrol
now i want to add Undo Option, I Really donot have idea how will this work so please give me any Hint
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先要了解的是:OpenGL 只是一个绘图 API。您发送绘图命令,它只会更改目标帧缓冲区中某些像素的颜色。 OpenGL 中没有将几何图形抽象为可操作对象的高级功能。这就是场景图的作用。
撤消/重做历史记录需要将所有绘图操作存储在单独的结构中,例如绘图操作的链接列表。
每个新操作都会附加到列表中。撤销将通过后退步骤来实现。一些撤消步骤之后的任何新操作都会丢弃尾部并构建一个新的尾部。
在 OpenGL 方面,您可以在撤消/重做后重绘整个列表,或者为每个步骤存储帧缓冲区的状态;然而,这会消耗大量内存,因此仅存储差异,并使用一些简单的压缩方案(游程长度和预先分割成图块)可以节省内存。
First thing to understand: OpenGL is just a drawing API. You send drawing commands and it will just change the colour of some pixels in the target framebuffer. There's no high level functionality in OpenGL that abstracts geometry into manipulateable objects. This is what a scene graph does.
A undo/redo history requires to store all the drawing operations in a separate structure, a linked list of drawing operations for example.
Each new operation is appended to the list. Undoing would be implementing by going back steps. Any new operation after some undo steps would discard the tail and build a new one.
On the OpenGL side you could either redraw the whole list after an Undo/Redo, or for every step store the state of framebuffer; this however would eat up a lot of memory so storing just the differences, and using some simple compression scheme (runlength and prior segmenting into tiles) saves memory.