-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics.h
More file actions
118 lines (72 loc) · 2.93 KB
/
graphics.h
File metadata and controls
118 lines (72 loc) · 2.93 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
#ifndef GRAPHICS_H
#define GRAPHICS_H
#include "fracfast/fractals.h"
#include "fracfast/types.h"
#include <SDL2/SDL.h>
// const unsigned int SCALEFRAMES = 30,
// SCALETIME = 1500; // milliseconds
enum class Coloring {
escapeTime,
distance
};
struct GraphicsState {
HighPrecDomain domain;
SDL_Texture* pixels;
GraphicsState() {
pixels = NULL;
mpf_inits(domain.rMin, domain.rMax, domain.iMin, domain.iMax, NULL);
}
~GraphicsState() {
if(pixels != NULL)
SDL_DestroyTexture(pixels);
mpf_clears(domain.rMin, domain.rMax, domain.iMin, domain.iMax, NULL);
}
void update(const HighPrecDomain& d, SDL_Texture* p) {
if(pixels != NULL)
SDL_DestroyTexture(pixels);
pixels = p;
mpf_set(domain.rMin, d.rMin); mpf_set(domain.rMax, d.rMax); mpf_set(domain.iMin, d.iMin); mpf_set(domain.iMax, d.iMax);
}
void forceRedraw() {
pixels = NULL;
}
void destroy() {
if(pixels != NULL)
SDL_DestroyTexture(pixels);
}
};
class Graphics {
public:
Graphics();
~Graphics();
void initRenderer(SDL_Window* const window);
void drawClick(const int x, const int y);
void drawOrbit(const Fractal* const fractal, const double c[2], const Domain& domain, const Resolution& res);
void setSymmetry(const bool sym);
void setLineDetail(Fractal* const fractal, const double lineDetail);
void nextColoring();
// Sets the screen up for new frame
void setScreen();
// Updates screen; finish frame
void blit();
void draw(const Fractal* const fractal, const HighPrecDomain& domain, const Resolution& res);
void extendDraw(const Fractal* const fractal, const HighPrecDomain& domain, const Resolution& res);
void deepenDraw(const Fractal* const fractal, const HighPrecDomain& domain, const Resolution& res);
SDL_Texture* calculatePixels(const Fractal* const fractal, const HighPrecDomain& domain, const Resolution& res);
SDL_Texture* calculateMandelbrot(const Mandelbrot* const fractal, const HighPrecDomain& domain, const Resolution& res) const;
SDL_Texture* calculateJulia(const Julia* const fractal, const HighPrecDomain& domain, const Resolution& res);
void forceRedraw();
void refresh();
void drawCurrentC(const double xRatio, const double yRatio, const Resolution& res);
// void smoothScale(unsigned int x, unsigned int y);
void select(const Selection* const selection, const Resolution& res);
private:
SDL_Renderer* renderer;
bool symmetry; // Should use symmetry optimization
Coloring coloring;
GraphicsState prev;
// These are members so these GMP floats only have to be inited once
HighPrecDomain newDomain;
mpf_t pixelSize;
};
#endif // GRAPHICS_H