Undos, Everything Must Change #

Today I worked on adding multiple undos. My original idea was to have a linked list, in which the constructor would also store the current state, and have a different function to restore. Then the undo and redo functions can simply move forwards and backwards through the list and restore the state. In the beginning the storing function took in 3 paramenters, because that's what I thought represented the current state. But then I noticed that I needed to add another variable (whether or not the selection was floated) and I realized that this could get out of control. So I decided that instead I should pass it a pointer to the current editor, and then the function could extract whatever data it needed, and if I wanted to extract more I just had to change the re/storing functions. This was when my problems started. The definitions for the state storing class and the editor class are stored in different files, but they both include pointers to each other and themselves. It took me a while to realize what was going on, since the compiler simply said "illegal argument" about the icnsEditorPtr variable in the constructor of the state class. In the end I had to include "stubs" in the icnsEditorClass.h file, which only gave the name of the class, but not the actual description.

Now it works, but it's rather flaky, especially when it comes to selections and drag and drop. But I can finally say that I'm done with all the major features of the editor. What will follow now is probably a gruelling month and a half in which I'll be fixing bugs, tweaking things, and realizing that I should start all over again

I'm already beginning to have thoughts of that, after I read a design section in "The C++ Language" (by Bjarne Stroustrup, C++'s creator). It said that one should focus more on the generalized view, and to look into the future and make the classes so that they can be reused. I realized that I could have done this project by having a generic editor class, from which I could derive an icnsEditorClass, but still be free to have others (such as a cursor editor, etc.) Perhaps the IB will appreciate the fact that I'll mention this in my "planned improvements" section, and not take too many points off :p

I also switched to a new "status" system. Before I had a few booleans, which told if I the window had just been resized, if the selection was floated and if it needed redrawing. However I decided that combine all of these into a long, and have specific bits in it signify states. Then I could use masks, and use a bitwise "and" to determine if the bit was on or not. Then adding new states, such as if the undo or redo commands could be executed would only involve adding a new flag, and not a whole new variable.

Post a Comment