view src/Fractal.cpp @ 4:df02a7de7fe2

I think I've got the Abstract Factory code working pretty robustly now, though I still need to make the factory singletons thread-safe
author Eris Caffee <discordia@eldalin.com>
date Tue, 26 Oct 2010 02:03:47 -0500
parents 0f4ad525f49a
children d691ce98f406
line source
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) 2010 Sarah Eris Horsley Caffee
4 //
5 // mandelbrot - A simple Mandelbrot Set viewer.
6 //
7 // Fractal.cpp
8 // Fractal calculator virtual class implementation. Actual fractals should
9 // implement this.
10 //
11 ////////////////////////////////////////////////////////////////////////////////
13 #include <string>
15 #include "SDL.h"
17 #include "Fractal.h"
20 ////////////////////////////////////////////////////////////////////////////////
22 Fractal::Fractal() :
23 display_name ("No fractal"),
24 fractal_name ("No fractal"),
25 re_min (0),
26 im_max (0),
27 size (0),
28 max_iter (0),
29 surface (NULL),
30 calc_needed (false)
31 {
32 }
34 ////////////////////////////////////////////////////////////////////////////////
35 double Fractal::get_re_min() const
36 {
37 return re_min;
38 }
41 ////////////////////////////////////////////////////////////////////////////////
42 double Fractal::set_re_min(const double r_min)
43 {
44 double t = re_min;
45 re_min = r_min;
46 return t;
47 }
50 ////////////////////////////////////////////////////////////////////////////////
51 double Fractal::get_im_max() const
52 {
53 return im_max;
54 }
57 ////////////////////////////////////////////////////////////////////////////////
58 double Fractal::set_im_max(const double i_max)
59 {
60 double t = im_max;
61 im_max = i_max;
62 return t;
63 }
66 ////////////////////////////////////////////////////////////////////////////////
67 double Fractal::get_size() const
68 {
69 return size;
70 }
73 ////////////////////////////////////////////////////////////////////////////////
74 double Fractal::set_size(const double s)
75 {
76 double t;
77 if (s > 0.0)
78 size = s;
79 else
80 size = 1.0;
81 return t;
82 }
85 ////////////////////////////////////////////////////////////////////////////////
86 unsigned int Fractal::get_max_iter() const
87 {
88 return max_iter;
89 }
92 ////////////////////////////////////////////////////////////////////////////////
93 unsigned int Fractal::set_max_iter(const unsigned int iter)
94 {
95 unsigned int t;
96 if (iter > 0)
97 max_iter = iter;
98 else
99 max_iter = 1;
100 return t;
101 }
104 ////////////////////////////////////////////////////////////////////////////////
105 unsigned int Fractal::inc_max_iter()
106 {
107 unsigned int t;
108 max_iter++;
109 return t;
110 }
113 ////////////////////////////////////////////////////////////////////////////////
114 unsigned int Fractal::dec_max_iter()
115 {
116 unsigned int t;
117 if (max_iter > 0)
118 max_iter--;
119 return t;
120 }
123 ////////////////////////////////////////////////////////////////////////////////
124 void Fractal::set_calc_needed()
125 {
126 calc_needed = true;
127 }
130 ////////////////////////////////////////////////////////////////////////////////
131 std::string const & Fractal::get_display_name() const
132 {
133 return display_name;
134 }
137 ////////////////////////////////////////////////////////////////////////////////
138 std::string const & Fractal::get_fractal_name() const
139 {
140 return fractal_name;
141 }
144 ////////////////////////////////////////////////////////////////////////////////
145 void Fractal::draw_pixel(int x, int y, Uint32 * color)
146 {
147 static char * data;
149 if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface);
151 data = (char *) surface->pixels
152 + y * surface->pitch
153 + x * surface->format->BytesPerPixel;
154 memcpy(data, color, surface->format->BytesPerPixel);
156 if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);
157 }
159 ////////////////////////////////////////////////////////////////////////////////
161 std::map <std::string, FractalCreator *> & get_Fractal_map()
162 {
163 static std::map <std::string, FractalCreator *> the_Fractal_map;
164 return the_Fractal_map;
165 }