File: wxview.h

package info (click to toggle)
golly 3.3-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 20,176 kB
  • sloc: cpp: 72,638; ansic: 25,919; python: 7,921; sh: 4,245; objc: 3,721; java: 2,781; xml: 1,362; makefile: 530; javascript: 279; perl: 69
file content (200 lines) | stat: -rwxr-xr-x 8,029 bytes parent folder | download | duplicates (2)
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// This file is part of Golly.
// See docs/License.html for the copyright notice.

#ifndef _WXVIEW_H_
#define _WXVIEW_H_

#include "wx/glcanvas.h"    // for wxGLCanvas, wxGLContext

#include "bigint.h"         // for bigint
#include "lifealgo.h"       // for lifealgo
#include "wxselect.h"       // for Selection
#include "wxlayer.h"        // for Layer

// OpenGL version and relevant features
extern int glMajor;
extern int glMinor;
extern int glMaxTextureSize;

// OpenGL is used for viewing and editing patterns:

class PatternView : public wxGLCanvas
{
public:
    PatternView(wxWindow* parent, wxCoord x, wxCoord y, int wd, int ht, long style);
    ~PatternView();
    
    // edit functions
    void CutSelection();
    void CopySelection();
    void ClearSelection();
    void ClearOutsideSelection();
    bool GetClipboardPattern(Layer* templayer, bigint* t, bigint* l, bigint* b, bigint* r);
    void PasteClipboard(bool toselection);
    void AbortPaste();
    void CyclePasteLocation();
    void CyclePasteMode();
    void DisplaySelectionSize();
    bool SelectionExists();
    void SelectAll();
    void RemoveSelection();
    void ShrinkSelection(bool fit);
    void RandomFill();
    bool FlipSelection(bool topbottom, bool inundoredo = false);
    bool RotateSelection(bool clockwise, bool inundoredo = false);
    void SetCursorMode(wxCursor* curs);
    void CycleCursorMode();
    bool CopyRect(int top, int left, int bottom, int right,
                  lifealgo* srcalgo, lifealgo* destalgo,
                  bool erasesrc, const wxString& progmsg);
    void CopyAllRect(int top, int left, int bottom, int right,
                     lifealgo* srcalgo, lifealgo* destalgo,
                     const wxString& progmsg);
    void SaveCurrentSelection();
    void RememberNewSelection(const wxString& action);
    
    bool OutsideLimits(bigint& t, bigint& l, bigint& b, bigint& r);
    // return true if given rect is outside getcell/setcell limits
    
    bool GetCellPos(bigint& xpos, bigint& ypos);
    // return true and get mouse location's cell coords if over viewport
    
    bool PointInView(int x, int y);
    // return true if given screen position is in viewport
    
    // view functions
    void ZoomOut();
    void ZoomIn();
    void SetPixelsPerCell(int pxlspercell);
    void FitPattern();
    void FitSelection();
    void ViewOrigin();
    void ChangeOrigin();
    void RestoreOrigin();
    void SetViewSize(int wd, int ht);
    bool GridVisible();
    void ToggleGridLines();
    void ToggleCellIcons();
    void ToggleCellColors();
    void ToggleSmarterScaling();
    void UpdateScrollBars();         // update thumb positions
    void CheckCursor(bool active);   // make sure cursor is up to date
    int GetMag();                    // get magnification (..., -1=2:1, 0=1:1, 1=1:2, ...)
    void SetMag(int newmag);
    void SetPosMag(const bigint& x, const bigint& y, int mag);
    void GetPos(bigint& x, bigint& y);
    void FitInView(int force);
    bool CellVisible(const bigint& x, const bigint& y);
    bool CellInGrid(const bigint& x, const bigint& y);
    bool PointInGrid(int x, int y);
    bool RectOutsideGrid(const wxRect& rect);
    void TestAutoFit();
    
    // process keyboard and mouse events
    void ProcessKey(int key, int modifiers);
    void ProcessClick(int x, int y, int button, int modifiers);
    void ProcessClickedControl();
    
    void ResetMouseDown();
    // modal dialogs need to reset mouseisdown to false
    
    // data
    bool waitingforclick;         // waiting for paste click?
    bool drawingcells;            // drawing cells due to dragging mouse?
    bool selectingcells;          // selecting cells due to dragging mouse?
    bool movingview;              // moving view due to dragging mouse?
    bool nopattupdate;            // disable pattern updates?
    bool showcontrols;            // draw translucent controls?
    bool mouseisdown;             // mouse button held down?
    int whichbuttondown;          // which mouse button is down
    wxRect controlsrect;          // location of translucent controls
    wxRect pasterect;             // area to be pasted
    wxCursor* oldcursor;          // non-NULL if shift key has toggled cursor
    wxCursor* restorecursor;      // non-NULL if cursor changed due to middle button click
    
    int tileindex;
    // if the tileindex is >= 0 then this is a tiled window (such windows
    // lie on top of the main viewport window when tilelayers is true);
    // the tileindex matches the layer position
    
private:
    // any class wishing to process wxWidgets events must use this macro
    DECLARE_EVENT_TABLE()
    
    // event handlers
    void OnPaint(wxPaintEvent& event);
    void OnSize(wxSizeEvent& event);
    void OnKeyDown(wxKeyEvent& event);
    void OnKeyUp(wxKeyEvent& event);
    void OnChar(wxKeyEvent& event);
    void OnMouseDown(wxMouseEvent& event);
    void OnMouseUp(wxMouseEvent& event);
#if wxCHECK_VERSION(2, 8, 0)
    void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
#endif
    void OnMouseWheel(wxMouseEvent& event);
    void OnMouseMotion(wxMouseEvent& event);
    void OnMouseEnter(wxMouseEvent& event);
    void OnMouseExit(wxMouseEvent& event);
    void OnDragTimer(wxTimerEvent& event);
    void OnScroll(wxScrollWinEvent& event);
    void OnEraseBackground(wxEraseEvent& event);
    
    // edit functions
    void RememberOneCellChange(int cx, int cy, int oldstate, int newstate);
    void StartDrawingCells(int x, int y);
    void DrawCells(int x, int y);
    void PickCell(int x, int y);
    void StartSelectingCells(int x, int y, bool shiftdown);
    void SelectCells(int x, int y);
    void StartMovingView(int x, int y);
    void MoveView(int x, int y);
    void StopDraggingMouse();
    void RestoreSelection();
    void ZoomInPos(int x, int y);
    void ZoomOutPos(int x, int y);
    void SetPasteRect(wxRect& rect, bigint& wd, bigint& ht);
    void PasteTemporaryToCurrent(bool toselection,
                                 bigint top, bigint left, bigint bottom, bigint right);
    bool FlipPastePattern(bool topbottom);
    bool RotatePastePattern(bool clockwise);
    
    // scroll functions
    void PanUp(int amount);
    void PanDown(int amount);
    void PanLeft(int amount);
    void PanRight(int amount);
    void PanNE();
    void PanNW();
    void PanSE();
    void PanSW();
    int SmallScroll(int xysize);
    int BigScroll(int xysize);
    
    // data
    wxGLContext* glcontext;       // OpenGL context for this canvas
    bool initgl;                  // need to initialize GL state?
    wxTimer* dragtimer;           // timer used while dragging mouse
    int cellx, celly;             // current cell's 32-bit position
    bigint bigcellx, bigcelly;    // current cell's position
    int initselx, initsely;       // location of initial selection click
    bool forceh;                  // resize selection horizontally?
    bool forcev;                  // resize selection vertically?
    bigint anchorx, anchory;      // anchor cell of current selection
    Selection prevsel;            // previous selection
    int drawstate;                // new cell state (0..255)
    int pastex, pastey;           // where user wants to paste clipboard pattern
    int hthumb, vthumb;           // current thumb box positions
    int realkey;                  // key code set by OnKeyDown
    wxString debugkey;            // display debug info for OnKeyDown and OnChar
};

const wxString empty_pattern       = _("All cells are dead.");
const wxString empty_selection     = _("There are no live cells in the selection.");
const wxString empty_outside       = _("There are no live cells outside the selection.");
const wxString no_selection        = _("There is no selection.");
const wxString selection_too_big   = _("Selection is outside +/- 10^9 boundary.");
const wxString pattern_too_big     = _("Pattern is outside +/- 10^9 boundary.");
const wxString origin_restored     = _("Origin restored.");

#endif