-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.h
More file actions
146 lines (93 loc) · 4.02 KB
/
program.h
File metadata and controls
146 lines (93 loc) · 4.02 KB
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
#ifndef PROGRAM_H
#define PROGRAM_H
#include "graphics.h"
#include "fracfast/fractals.h"
#include "fracfast/types.h"
#include <SDL2/SDL.h>
#include <gmp.h>
#include <mutex>
const unsigned int DEFAULTWIDTH = 800;
const unsigned int DEFAULTHEIGHT = 600;
const unsigned int MINWIDTH = 400;
const unsigned int MINHEIGHT = 300;
const double SCALEFACTOR = 0.8;
const unsigned int DEFAULTDEEPEN = 50;
// All non-const public functions must lock/unlock 'rendering"
// TODO: Seperate Window class
class Program {
public:
Program(Graphics* const g, const unsigned int w, const unsigned int h, const uint32_t flags);
~Program();
void click(const unsigned int x, const unsigned int y, const bool print = true);
inline void lock(std::mutex& m);
inline void unlock(std::mutex& m);
bool isRendering() const;
unsigned int getWindowID() const;
void setC(const double c[2]);
void getC(double c[2]) const;
bool setDomain(const Domain& d);
Domain getDomain() const;
void setDeepen(const unsigned int d);
unsigned int getDeepen() const;
void deepen();
void unDeepen();
void setLineDetail(const double lineDetail);
void nextColoring();
void setJuliaWindow(Program* const p);
void getResolution(Resolution& res) const;
void resize(const Resolution& res);
void refresh();
void redraw();
void scale(const int scaleDirection);
void translate(const int realDirection, const int imagDirection);
void translateJuliaParameter(const int realDirection, const int imagDirection);
void setJuliaParameter(const double real, const double imag);
void nextFractal();
void home();
void setnMax(const unsigned long n, const bool doTick = true);
unsigned long getnMax() const;
void changenMax(const long n);
void toggleSymmetry();
void xyToComplex(const unsigned int x, const unsigned int y, double& c0, double& c1) const;
void xyToComplex(const unsigned int x, const unsigned int y, double c[2]) const;
void drawJuliaC(const bool juliaWin = false) const;
void drawJuliaC(const double c0, const double c1) const;
void showJuliaWindow();
void hideJuliaWindow();
void showWindow();
void hideWindow();
void orbit(const unsigned int x, const unsigned int y);
void beginRegionSelect(const unsigned int x, const unsigned int y);
void updateRegionSelect(const unsigned int x, const unsigned int y);
void setSelectedRegion();
void cancelSelect();
private:
SDL_Window* window;
Resolution res;
unsigned int nDeepen;
Graphics* const graphics;
Fractal* fractal;
// Mutex for signaling then fractal is rendering. When fractal is rendering, no changes may be made to the program state and in extension, no changes to the fractal
std::mutex renderingMutex;
bool rendering;
bool symmetry = true;
// For hinding/showing the Julia window
Program* juliaWindow = nullptr;
bool juliaWinUp = false;
bool isJuliaWin = false;
HighPrecDomain domain;
// These are members, because they are expensive to initialize every function invocation.
// Now, the constructor can initialize them once and every member function can use them with little overhead.
// They can always be used by other functions as well (i.e. through aliasing)
mpf_t xRatio, yRatio, dReal, dImag, t, scaleFactor;
Selection* selection;
// Scale at mouse position (x, y)
void scaleXY(const int scaleDirection, const unsigned int x, const unsigned int y);
// Draw fractal with current program state
void tick();
void translateTick();
void deepenTick();
void resetView();
void setResolution(const unsigned int w, const unsigned int h);
};
#endif // PROGRAM_H