File: wxselect.h

package info (click to toggle)
golly 2.6-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,440 kB
  • ctags: 8,558
  • sloc: cpp: 55,629; python: 7,963; sh: 4,420; objc: 3,613; java: 2,791; ansic: 2,512; xml: 1,379; perl: 1,172; makefile: 54
file content (174 lines) | stat: -rw-r--r-- 6,648 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*** /
 
 This file is part of Golly, a Game of Life Simulator.
 Copyright (C) 2013 Andrew Trevorrow and Tomas Rokicki.
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 Web site:  http://sourceforge.net/projects/golly
 Authors:   rokicki@gmail.com  andrew@trevorrow.com
 
 / ***/

#ifndef _WXSELECT_H_
#define _WXSELECT_H_

#include "bigint.h"     // for bigint
#include "lifealgo.h"   // for lifealgo

// Most editing functions operate on the current selection.
// The Selection class encapsulates all selection-related operations.

class Selection {
public:
    Selection();
    Selection(int t, int l, int b, int r);
    ~Selection();
    
    bool operator==(const Selection& sel) const;
    bool operator!=(const Selection& sel) const;
    
    bool Exists();
    // return true if the selection exists
    
    void Deselect();
    // remove the selection
    
    bool TooBig();
    // return true if any selection edge is outside the editable limits
    
    void DisplaySize();
    // display the selection's size in the status bar
    
    void SetRect(int x, int y, int wd, int ht);
    // set the selection to the given rectangle
    
    void GetRect(int* x, int* y, int* wd, int* ht);
    // return the selection rectangle
    
    void SetEdges(bigint& t, bigint& l, bigint& b, bigint& r);
    // set the selection using the given rectangle edges
    
    void CheckGridEdges();
    // change selection edges if necessary to ensure they are inside a bounded grid
    
    bool Contains(bigint& t, bigint& l, bigint& b, bigint& r);
    // return true if the selection encloses the given rectangle
    
    bool Outside(bigint& t, bigint& l, bigint& b, bigint& r);
    // return true if the selection is completely outside the given rectangle
    
    bool ContainsCell(int x, int y);
    // return true if the given cell is within the selection
    
    void Advance();
    // advance the pattern inside the selection by one generation
    
    void AdvanceOutside();
    // advance the pattern outside the selection by one generation
    
    void Modify(const bigint& xclick, const bigint& yclick,
                bigint& anchorx, bigint& anchory,
                bool* forceh, bool* forcev);
    // modify the existing selection based on where the user clicked
    
    void SetLeftRight(const bigint& x, const bigint& anchorx);
    // set the selection's left and right edges
    
    void SetTopBottom(const bigint& y, const bigint& anchory);
    // set the selection's top and bottom edges
    
    void Fit();
    // fit the selection inside the current viewport
    
    void Shrink(bool fit);
    // shrink the selection so it just encloses all the live cells
    // and optionally fit the new selection inside the current viewport
    
    bool Visible(wxRect* visrect);
    // return true if the selection is visible in the current viewport
    // and, if visrect is not NULL, set it to the visible rectangle
    
    void Clear();
    // kill all cells inside the selection
    
    void ClearOutside();
    // kill all cells outside the selection
    
    void CopyToClipboard(bool cut);
    // copy the selection to the clipboard (using RLE format) and
    // optionally clear the selection if cut is true
    
    bool CanPaste(const bigint& wd, const bigint& ht, bigint& top, bigint& left);
    // return true if the selection fits inside a rectangle of size ht x wd;
    // if so then top and left are set to the selection's top left corner
    
    void RandomFill();
    // randomly fill the selection
    
    bool Flip(bool topbottom, bool inundoredo);
    // return true if selection was successfully flipped
    
    bool Rotate(bool clockwise, bool inundoredo);
    // return true if selection was successfully rotated
    
private:
    bool SaveOutside(bigint& t, bigint& l, bigint& b, bigint& r);
    // remember live cells outside the selection
    
    void EmptyUniverse();
    // kill all cells by creating a new, empty universe
    
    void AddRun(int state, int multistate, unsigned int &run,
                unsigned int &linelen, char* &chptr);
    
    void AddEOL(char* &chptr);
    // these routines are used by CopyToClipboard to create RLE data
    
    bool SaveDifferences(lifealgo* oldalgo, lifealgo* newalgo,
                         int itop, int ileft, int ibottom, int iright);
    // compare same rectangle in the given universes and remember the differences
    // in cell states; return false only if user aborts lengthy comparison
    
    bool FlipRect(bool topbottom, lifealgo* srcalgo, lifealgo* destalgo, bool erasesrc,
                  int top, int left, int bottom, int right);
    // called by Flip to flip given rectangle from source universe to
    // destination universe and optionally kill cells in the source rectangle;
    // return false only if user aborts lengthy flip
    
    bool RotateRect(bool clockwise, lifealgo* srcalgo, lifealgo* destalgo, bool erasesrc,
                    int itop, int ileft, int ibottom, int iright,
                    int ntop, int nleft, int nbottom, int nright);
    // called by Rotate to rotate given rectangle from source universe to
    // destination universe and optionally kill cells in the source rectangle;
    // return false only if user aborts lengthy rotation
    
    bool RotatePattern(bool clockwise,
                       bigint& newtop, bigint& newbottom,
                       bigint& newleft, bigint& newright,
                       bool inundoredo);
    // called by Rotate when the selection encloses the entire pattern;
    // return false only if user aborts lengthy rotation
    
    bigint seltop, selleft, selbottom, selright;
    // currently we only support a single rectangular selection
    // which is represented by these edges; eventually we might
    // support arbitrarily complex selection shapes by maintaining
    // a list or dynamic array of non-overlapping rectangles
    
    bool exists;      // does the selection exist?
};

#endif