1 // This file is part of Golly. 2 // See docs/License.html for the copyright notice. 3 4 #ifndef _WXLAYER_H_ 5 #define _WXLAYER_H_ 6 7 #include "bigint.h" // for bigint class 8 #include "viewport.h" // for viewport class 9 #include "wxselect.h" // for Selection class 10 #include "wxundo.h" // for UndoRedo class 11 #include "wxalgos.h" // for algo_type 12 13 // Golly supports multiple layers. Each layer is a separate universe 14 // (unless cloned) with its own algorithm, rule, viewport, window title, 15 // selection, undo/redo history, etc. 16 17 class Layer { 18 public: 19 Layer(); 20 ~Layer(); 21 22 // if this is a cloned layer then cloneid is > 0 and all the other clones 23 // have the same cloneid 24 int cloneid; 25 26 lifealgo* algo; // this layer's universe (shared by clones) 27 algo_type algtype; // type of universe (index into algoinfo) 28 bool hyperspeed; // use acceleration while generating? 29 bool showhashinfo; // show hashing info? 30 bool autofit; // auto fit pattern while generating? 31 bool dirty; // user has modified pattern? 32 bool savedirty; // state of dirty flag before drawing/script change 33 bool stayclean; // script has reset dirty flag? 34 int currbase; // current base step 35 int currexpo; // current step exponent 36 int drawingstate; // current drawing state 37 wxCursor* curs; // current cursor 38 UndoRedo* undoredo; // undo/redo history (shared by clones) 39 40 // each layer (cloned or not) has its own viewport for displaying patterns; 41 // note that we use a pointer to the viewport to allow temporary switching 42 // in wxrender.cpp (eg. in DrawStackedLayers) 43 viewport* view; 44 45 // WARNING: this string is used to remember the current rule when 46 // switching to another layer; to determine the current rule at any 47 // time, use currlayer->algo->getrule() 48 wxString rule; 49 50 Selection currsel; // current selection 51 Selection savesel; // for saving/restoring selection 52 53 bigint originx; // X origin offset 54 bigint originy; // Y origin offset 55 56 wxString currfile; // full path of current pattern file 57 wxString currname; // name seen in window title and Layer menu 58 59 // for saving and restoring starting pattern 60 algo_type startalgo; // starting algorithm 61 bool savestart; // need to save starting pattern? 62 bool startdirty; // starting state of dirty flag 63 wxString startname; // starting currname 64 wxString startrule; // starting rule 65 bigint startgen; // starting generation (>= 0) 66 bigint startx, starty; // starting location 67 int startbase; // starting base step 68 int startexpo; // starting step exponent 69 int startmag; // starting scale 70 Selection startsel; // starting selection 71 72 // temporary file used to restore starting pattern or to show comments; 73 // each non-cloned layer uses a different temporary file 74 wxString tempstart; 75 76 // used when tilelayers is true 77 PatternView* tilewin; // tile window 78 wxRect tilerect; // tile window's size and position 79 80 // color scheme for this layer 81 wxColor fromrgb; // start of gradient 82 wxColor torgb; // end of gradient 83 unsigned char cellr[256]; // red components for states 0..255 84 unsigned char cellg[256]; // green components for states 0..255 85 unsigned char cellb[256]; // blue components for states 0..255 86 87 // icons for this layer 88 wxBitmap** icons7x7; // icons for scale 1:8 89 wxBitmap** icons15x15; // icons for scale 1:16 90 wxBitmap** icons31x31; // icons for scale 1:32 91 92 // texture atlases for rendering icons 93 unsigned char* atlas7x7; // atlas for 7x7 icons 94 unsigned char* atlas15x15; // atlas for 15x15 icons 95 unsigned char* atlas31x31; // atlas for 31x31 icons 96 97 int numicons; // number of icons (= number of live states) 98 bool multicoloricons; // are icons multi-colored? (grayscale if not) 99 100 // used if the layer has a timeline (see wxtimeline.cpp) 101 int currframe; // current frame in timeline 102 int autoplay; // +ve = play forwards, -ve = play backwards, 0 = stop 103 int tlspeed; // controls speed at which frames are played 104 }; 105 106 const int MAX_LAYERS = 10; // maximum number of layers 107 extern int numlayers; // number of existing layers 108 extern int numclones; // number of cloned layers 109 extern int currindex; // index of current layer (0..numlayers-1) 110 extern Layer* currlayer; // pointer to current layer 111 112 Layer* GetLayer(int index); 113 // Return a pointer to the layer specified by the given index. 114 115 void AddLayer(); 116 // Add a new layer (with an empty universe) and make it the current layer. 117 // The first call creates the initial layer. Later calls insert the 118 // new layer immediately after the old current layer. The new layer 119 // inherits the same type of universe, the same rule, the same scale 120 // and location, and the same cursor. 121 122 void CloneLayer(); 123 // Like AddLayer but shares the same universe and undo/redo history 124 // as the current layer. All the current layer's settings are duplicated 125 // and most will be kept synchronized; ie. changing one clone changes all 126 // the others, but each cloned layer has a separate viewport so the same 127 // pattern can be viewed at different scales and locations. 128 129 void SyncClones(); 130 // If the current layer is a clone then this call ensures the universe 131 // and settings in its other clones are correctly synchronized. 132 133 void DuplicateLayer(); 134 // Like AddLayer but makes a copy of the current layer's pattern. 135 // Also duplicates all the current settings but, unlike a cloned layer, 136 // the settings are not kept synchronized. 137 138 void DeleteLayer(); 139 // Delete the current layer. The current layer changes to the previous 140 // index, unless layer 0 was deleted, in which case the current layer 141 // is the new layer at index 0. 142 143 void DeleteOtherLayers(); 144 // Delete all layers except the current layer. 145 146 void SetLayer(int index); 147 // Set the current layer using the given index (0..numlayers-1). 148 149 void MoveLayer(int fromindex, int toindex); 150 // Move the layer at fromindex to toindex and make it the current layer. 151 // This is called by MoveLayerDialog and the movelayer script command. 152 153 void MoveLayerDialog(); 154 // Bring up a dialog that allows the user to move the current layer 155 // to a new index (which becomes the current layer). 156 157 void NameLayerDialog(); 158 // Bring up a dialog that allows the user to change the name of the 159 // current layer. 160 161 void MarkLayerDirty(); 162 // Set dirty flag in current layer and any of its clones. 163 // Also prefix window title and layer name(s) with an asterisk. 164 165 void MarkLayerClean(const wxString& title); 166 // Reset dirty flag in current layer and any of its clones. 167 // Also set window title, removing asterisk from it and layer name(s). 168 169 void ToggleSyncViews(); 170 // Toggle the syncviews flag. When true, every layer uses the same 171 // scale and location as the current layer. 172 173 void ToggleSyncCursors(); 174 // Toggle the synccursors flag. When true, every layer uses the same 175 // cursor as the current layer. 176 177 void ToggleStackLayers(); 178 // Toggle the stacklayers flag. When true, the rendering code displays 179 // all layers using the same scale and location as the current layer. 180 // Layer 0 is drawn first (100% opaque), then all the other layers 181 // are drawn as overlays using an opacity set by the user. The colors 182 // for the live cells in each layer can be set via the Prefs dialog. 183 184 void ToggleTileLayers(); 185 // Toggle the tilelayers flag. When true, the rendering code displays 186 // all layers in tiled sub-windows. 187 188 bool CanSwitchLayer(int index); 189 // Return true if the user can switch to the given layer. 190 191 void SwitchToClickedTile(int index); 192 // If allowed, change current layer to clicked tile. 193 194 void ResizeLayers(int wd, int ht); 195 // Resize the viewport in all layers. 196 197 bool RestoreRule(const wxString& rule); 198 // Try to set the current layer's rule to a previously known rule. 199 // If this succeeds return true, but if it fails then warn the user, 200 // switch to the current algorithm's default rule, and return false. 201 // The latter can happen if a .rule file was deleted or was edited 202 // and some sort of error introduced. 203 204 Layer* CreateTemporaryLayer(); 205 // Create a temporary layer with the same algo type as currlayer. 206 207 208 // Layer bar routines: 209 210 void CreateLayerBar(wxWindow* parent); 211 // Create layer bar window at top of given parent window. 212 213 int LayerBarHeight(); 214 // Return height of layer bar. 215 216 void ResizeLayerBar(int wd); 217 // Change width of layer bar. 218 219 void UpdateLayerBar(); 220 // Update state of buttons in layer bar. 221 222 void UpdateLayerButton(int index, const wxString& name); 223 // Update the name in the specified layer button. 224 225 void RedrawLayerBar(); 226 // Redraw layer bar. This is needed because UpdateLayerBar doesn't 227 // refresh the layer bar (to avoid unwanted flashing). 228 229 void ToggleLayerBar(); 230 // Show/hide the layer bar. 231 232 233 // Color handling routines: 234 235 void CreateColorGradient(); 236 // Create a color gradient for the current layer using 237 // currlayer->fromrgb and currlayer->torgb. 238 239 void UpdateIconColors(); 240 // Update the icon texture atlases for the current layer. 241 // Must be called BEFORE calling UpdateCloneColors. 242 243 void UpdateCloneColors(); 244 // If current layer has clones then update their colors. 245 246 void UpdateLayerColors(); 247 // Update the cell colors and icons for the current layer (and its clones) 248 // according to the current algo and rule. Must be called very soon 249 // after any algo/rule change, and before the viewport is updated. 250 251 void InvertCellColors(); 252 // Invert the cell colors in all layers, including the dead cell color, 253 // grid lines, and the colors in all icons. 254 255 void InvertIconColors(unsigned char* atlasptr, int iconsize, int numicons); 256 // Invert the icon colors in the given texture atlas. 257 258 void SetLayerColors(); 259 // Open a dialog to change the current layer's colors. 260 261 #endif 262