-
Notifications
You must be signed in to change notification settings - Fork 3
CalChart Code Videos
Here you'll find a series of videos designed to help introduce you to various aspects of the CalChart code. Many of these videos build on one another, and thus, they're listed below in the order in which they're best viewed.
The videos are really designed to explain how the code works, so if you've already gone through the videos, and just want a quick refresher on some of the topics, you can refer to the notes on the Quick Reference page, instead of re-watching the entire videos.
An Introduction to Frames (Watch "Program Startup" first)
[How to Make Your Own Menu Tool] (http://www.youtube.com/watch?v=fQOsC8hqh-k) (Watch "An Introduction to Frames" first)
[Locating the Show Data] (http://www.youtube.com/watch?v=scrfFxcRP7g)
[The Frame-Canvas-View Trio] (http://www.youtube.com/watch?v=9c5nbC_ih88)
[Views] (http://www.youtube.com/watch?v=Vbb8tAnuKu4) (Watch "How to Make Your Own Menu Tool" first)
[Commands] (http://www.youtube.com/watch?v=rJkTFGDKA7g) (Watch "Locating the Show Data" first)
[Saving and Loading Show Files] (http://www.youtube.com/watch?v=KD0LgF_yyMc) (Watch "Program Startup" and "Locating the Show Data" first)
[Making a New Show] (http://www.youtube.com/watch?v=g1Q6aLNscJM) (Watch "Views" and "Saving and Loading Show Files" first)
The program starts in the OnInit() method of the CalChartApp class.
The CalChartApp class is defined in calchartapp.h and calchartapp.cpp.
The CalChartApp is, itself, invisible - during the OnInit() method, however, it creates a TopFrame, which is the first window that you see when you open the program.
After the OnInit() method completes, control of the program is essentially granted to the *TopFrame.
When you're reading through the code for a frame class (e.g. the FieldFrame or AnimationFrame), there are essentially two strong indicators that a particular method of that class is directly linked to one of the tools that the user can access in that frame (either via a toolbar or drop-down menu):
-
The "OnCmd" prefix in the method name:
e.g. void OnCmdAbout(wxCommandEvent& event);
-
The presence of a single parameter, where that parameter is some kind of wxWidgets event:
e.g. void OnCmdAbout(wxCommandEvent& event);
The second indicator is stronger than the first, because while not all methods that are linked to tools have names beginning with the "OnCmd" prefix, they all do accept a wxWidgets event as their parameter. There are some exceptions to the rules provided above: there are a few methods that accept a wxWidgets event as a parameter, yet are not directly linked to any tool that the user can select - these methods, however, are so sparse that you need not really worry about them. You just need to be aware of them, so that they don't surprise you if you encounter them.
There are essentially four steps to making your own tool:
-
In the class of your target frame, make a method that will be called when your tool is activated by the user. Make sure that the method has one parameter: a wxCommandEvent&.
-
In the cpp file for your target frame, locate the block of code located between the BEGIN_EVENT_TABLE and END_EVENT_TABLE macro calls. Create a call to the EVT_MENU macro, so that the first parameter is the event type that prompts your tool, and the second parameter is the method that contains the code for your tool. That is: EVT_MENU( [event type], [your method]).
-
Find the place where your target frame builds its menus (which is likely in the frame's constructor). Add your own tool to your target menu. This should cause you to add a line of code that resembles this: [target menu]->Append( [event type], [name of tool], [description of tool]).
-
In ui_enums.h, add your event type to the enumeration of all event types.
All data is ultimately found within the CalChartDoc class.
The CalChartDoc keeps track of:
-
The show mode (represented by the ShowMode class, found in modes.h and modes.cpp).
-
A show (represented by the CC_show class, found in cc_show.h and cc_show.cpp).
A CalChart show (CC_show) keeps track of:
-
A list of stuntsheets (each represented by the CC_sheet class, found in cc_sheet.h and cc_sheet.cpp).
-
A list containing the labels for each dot on the field.
A CalChart stuntsheet (CC_sheet) keeps track of:
-
A list of points (each represented by the CC_point class, found in cc_point.h and cc_point.cpp).
-
A continuity for each dot type (where the continuities are represented by the CC_continuity class, found in cc_continuity.h and cc_continuity.cpp).
-
A print continuity (represented by the CC_print_continuity class, found in cc_text.h and cc_text.cpp).
A CalChart point (CC_point) keeps track of:
-
Its position.
-
The positions of its "reference points"
A frame is a window of the program.
A canvas is a region of the frame, to which the programmer can draw anything he/she likes.
For information on views, refer to the "Views" section.
Views are connected to the CalChartDoc.
When the CalChartDoc is changed in some way (e.g. points are moved, or a new dot is selected), the views are notified about the change.
Some views, like the AnimationView and FieldView, have a visual appearance. The AnimationCanvas and the FieldCanvas defer to the AnimationView and FieldView, respectively, to decide what should be drawn to the canvas.
Changes are made to the show indirectly: CalChart commands are submitted to a command processor that is associated with the CalChartDoc. The command processor then applies changes to the show by calling the Do() method of the submitted commands. The command processor stores the commands that are submitted, so it can undo them later.
Before CalChart commands make any changes to the show, they save a snapshot of the CalChartDoc.
When CalChart commands are undone, they simply restore the CalChartDoc snapshot that was taken before changes were made.
The wxDocManager delegates the tasks of saving and loading files.
When a show file is loaded, the wxDocManager creates a CalChartDoc object and a FieldView object. It links the FieldView to the CalChartDoc, and calls the OnOpenDocument(...) method of the CalChartDoc. When this method is called, the CalChartDoc loads from a file. Upon creation, the FieldView creates the FieldFrame.
When a show file is saved, the wxDocManager calls the OnSaveDocument(...) method of the CalChartDoc, causing the CalChartDoc to save itself to a file.
Saving and loading are
When a new show is created, the wxDocManager creates a CalChartDoc and FieldView, and links them together.
The wxDocManager then calls the OnNewDocument() method of the CalChartDoc.
The CalChartDoc sends an update to the connected FieldView, instructing it to set up the new show.
The FieldView sets up the "New Show Setup Wizard" in response.