Serializing Scribble’s New Stroke Information
All of these code changes, including the change to the mapping mode, invalidate previous Scribble file formats. For example, the x and y-coordinates of earlier Scribble drawings were based on pixel locations. Now they are interpreted according to 1/100ths of an inch. Also, because of the metric mapping mode, the sign of the y-coordinate reverses, and what used to be a positive value is now negative. To compensate for this reversal, you’ll modify the m_rectBounding
variable, which is a member of CStroke
, the class that stores Scribble’s stroke data.
What does this mean? If the new version of Scribble tries to read in stroke data from an older version of Scribble, it will still try to draw the stroke, but the old stroke data might map to an area, for example, outside the current window.
Recall that, earlier in the tutorial, when you defined a hint for Scribble in Lesson 8, you modified the way Scribble stored strokes by adding the member variable, m_rectBounding
. In that tutorial step, you incremented the schema number of the IMPLEMENT_SERIAL macro to distinguish between stroke data from different versions of Scribble. Because of the code changes you’ll make in following topics, you need to increment this schema number again.
Note After marking the version of Scribble data in this way, you’ll receive an error message “Unrecognized file format” if you try to load drawings from previous versions of Scribble. This is preferable to opening a drawing and seeing nothing on the screen.
To increment Scribble’s serialization
Open ScribbleDoc.cpp, search for the IMPLEMENT_SERIAL macro, and change the schema number parameter to 3.
IMPLEMENT_SERIAL( CStroke, CObject, 3 )