1 // This file is part of Golly. 2 // See docs/License.html for the copyright notice. 3 4 #ifndef _WXSELECT_H_ 5 #define _WXSELECT_H_ 6 7 #include "bigint.h" // for bigint 8 #include "lifealgo.h" // for lifealgo 9 10 // Most editing functions operate on the current selection. 11 // The Selection class encapsulates all selection-related operations. 12 13 class Selection { 14 public: 15 Selection(); 16 Selection(int t, int l, int b, int r); 17 ~Selection(); 18 19 bool operator==(const Selection& sel) const; 20 bool operator!=(const Selection& sel) const; 21 22 bool Exists(); 23 // return true if the selection exists 24 25 void Deselect(); 26 // remove the selection 27 28 bool TooBig(); 29 // return true if any selection edge is outside the editable limits 30 31 void DisplaySize(); 32 // display the selection's size in the status bar 33 34 void SetRect(int x, int y, int wd, int ht); 35 // set the selection to the given rectangle 36 37 void GetRect(int* x, int* y, int* wd, int* ht); 38 // return the selection rectangle 39 40 void SetEdges(bigint& t, bigint& l, bigint& b, bigint& r); 41 // set the selection using the given rectangle edges 42 43 void CheckGridEdges(); 44 // change selection edges if necessary to ensure they are inside a bounded grid 45 46 bool Contains(bigint& t, bigint& l, bigint& b, bigint& r); 47 // return true if the selection encloses the given rectangle 48 49 bool Outside(bigint& t, bigint& l, bigint& b, bigint& r); 50 // return true if the selection is completely outside the given rectangle 51 52 bool ContainsCell(int x, int y); 53 // return true if the given cell is within the selection 54 55 void Advance(); 56 // advance the pattern inside the selection by one generation 57 58 void AdvanceOutside(); 59 // advance the pattern outside the selection by one generation 60 61 void Modify(const bigint& xclick, const bigint& yclick, 62 bigint& anchorx, bigint& anchory, 63 bool* forceh, bool* forcev); 64 // modify the existing selection based on where the user clicked 65 66 void SetLeftRight(const bigint& x, const bigint& anchorx); 67 // set the selection's left and right edges 68 69 void SetTopBottom(const bigint& y, const bigint& anchory); 70 // set the selection's top and bottom edges 71 72 void Fit(); 73 // fit the selection inside the current viewport 74 75 void Shrink(bool fit, bool remove_if_empty = false); 76 // shrink the selection so it just encloses all the live cells 77 // and optionally fit the new selection inside the current viewport; 78 // if remove_if_empty is true then an empty selection is removed 79 80 bool Visible(wxRect* visrect); 81 // return true if the selection is visible in the current viewport 82 // and, if visrect is not NULL, set it to the visible rectangle 83 84 void Clear(); 85 // kill all cells inside the selection 86 87 void ClearOutside(); 88 // kill all cells outside the selection 89 90 void CopyToClipboard(bool cut); 91 // copy the selection to the clipboard (using RLE format) and 92 // optionally clear the selection if cut is true 93 94 bool CanPaste(const bigint& wd, const bigint& ht, bigint& top, bigint& left); 95 // return true if the selection fits inside a rectangle of size ht x wd; 96 // if so then top and left are set to the selection's top left corner 97 98 void RandomFill(); 99 // randomly fill the selection 100 101 bool Flip(bool topbottom, bool inundoredo); 102 // return true if selection was successfully flipped 103 104 bool Rotate(bool clockwise, bool inundoredo); 105 // return true if selection was successfully rotated 106 107 private: 108 bool SaveOutside(bigint& t, bigint& l, bigint& b, bigint& r); 109 // remember live cells outside the selection 110 111 void EmptyUniverse(); 112 // kill all cells by creating a new, empty universe 113 114 void AddRun(int state, int multistate, unsigned int &run, 115 unsigned int &linelen, char* &chptr); 116 117 void AddEOL(char* &chptr); 118 // these routines are used by CopyToClipboard to create RLE data 119 120 bool SaveDifferences(lifealgo* oldalgo, lifealgo* newalgo, 121 int itop, int ileft, int ibottom, int iright); 122 // compare same rectangle in the given universes and remember the differences 123 // in cell states; return false only if user aborts lengthy comparison 124 125 bool FlipRect(bool topbottom, lifealgo* srcalgo, lifealgo* destalgo, bool erasesrc, 126 int top, int left, int bottom, int right); 127 // called by Flip to flip given rectangle from source universe to 128 // destination universe and optionally kill cells in the source rectangle; 129 // return false only if user aborts lengthy flip 130 131 bool RotateRect(bool clockwise, lifealgo* srcalgo, lifealgo* destalgo, bool erasesrc, 132 int itop, int ileft, int ibottom, int iright, 133 int ntop, int nleft, int nbottom, int nright); 134 // called by Rotate to rotate given rectangle from source universe to 135 // destination universe and optionally kill cells in the source rectangle; 136 // return false only if user aborts lengthy rotation 137 138 bool RotatePattern(bool clockwise, 139 bigint& newtop, bigint& newbottom, 140 bigint& newleft, bigint& newright, 141 bool inundoredo); 142 // called by Rotate when the selection encloses the entire pattern; 143 // return false only if user aborts lengthy rotation 144 145 bigint seltop, selleft, selbottom, selright; 146 // currently we only support a single rectangular selection 147 // which is represented by these edges; eventually we might 148 // support arbitrarily complex selection shapes by maintaining 149 // a list or dynamic array of non-overlapping rectangles 150 151 bool exists; // does the selection exist? 152 }; 153 154 #endif 155