comparison engine/core/view/renderers/genericrenderer.cpp @ 445:f855809822cf

* Fixed GenericRenderer, now it only render to a specific layer. If the node is only a point then it used the last active layer. fixes #[ticket:458]
author helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 24 Mar 2010 16:11:30 +0000
parents ad1f09d954f9
children 16c2b3ee59ce
comparison
equal deleted inserted replaced
444:79678719d569 445:f855809822cf
47 47
48 48
49 namespace FIFE { 49 namespace FIFE {
50 static Logger _log(LM_VIEWVIEW); 50 static Logger _log(LM_VIEWVIEW);
51 51
52 GenericRendererNode::GenericRendererNode(Instance* attached_instance, Location* relative_location, Layer* relative_layer, const Point &relative_point):
53 m_instance(attached_instance),
54 m_location(relative_location),
55 m_layer(relative_layer),
56 m_point(relative_point) {
57 }
52 GenericRendererNode::GenericRendererNode(Instance* attached_instance, Location* relative_location, const Point &relative_point): 58 GenericRendererNode::GenericRendererNode(Instance* attached_instance, Location* relative_location, const Point &relative_point):
53 m_instance(attached_instance), 59 m_instance(attached_instance),
54 m_location(relative_location), 60 m_location(relative_location),
61 m_layer(NULL),
62 m_point(relative_point) {
63 }
64 GenericRendererNode::GenericRendererNode(Instance* attached_instance, Layer* relative_layer, const Point &relative_point):
65 m_instance(attached_instance),
66 m_location(NULL),
67 m_layer(relative_layer),
55 m_point(relative_point) { 68 m_point(relative_point) {
56 } 69 }
57 GenericRendererNode::GenericRendererNode(Instance* attached_instance, const Point &relative_point): 70 GenericRendererNode::GenericRendererNode(Instance* attached_instance, const Point &relative_point):
58 m_instance(attached_instance), 71 m_instance(attached_instance),
59 m_location(NULL), 72 m_location(NULL),
73 m_layer(NULL),
74 m_point(relative_point) {
75 }
76 GenericRendererNode::GenericRendererNode(Location* attached_location, Layer* relative_layer, const Point &relative_point):
77 m_instance(NULL),
78 m_location(attached_location),
79 m_layer(relative_layer),
60 m_point(relative_point) { 80 m_point(relative_point) {
61 } 81 }
62 GenericRendererNode::GenericRendererNode(Location* attached_location, const Point &relative_point): 82 GenericRendererNode::GenericRendererNode(Location* attached_location, const Point &relative_point):
63 m_instance(NULL), 83 m_instance(NULL),
64 m_location(attached_location), 84 m_location(attached_location),
85 m_layer(NULL),
86 m_point(relative_point) {
87 }
88 GenericRendererNode::GenericRendererNode(Layer* attached_layer, const Point &relative_point):
89 m_instance(NULL),
90 m_location(NULL),
91 m_layer(attached_layer),
65 m_point(relative_point) { 92 m_point(relative_point) {
66 } 93 }
67 GenericRendererNode::GenericRendererNode(const Point &attached_point): 94 GenericRendererNode::GenericRendererNode(const Point &attached_point):
68 m_instance(NULL), 95 m_instance(NULL),
69 m_location(NULL), 96 m_location(NULL),
97 m_layer(NULL),
70 m_point(attached_point) { 98 m_point(attached_point) {
71 } 99 }
72 GenericRendererNode::~GenericRendererNode() { 100 GenericRendererNode::~GenericRendererNode() {
73 } 101 }
74 102
95 } 123 }
96 void GenericRendererNode::setAttached(Location* attached_location) { 124 void GenericRendererNode::setAttached(Location* attached_location) {
97 m_instance = NULL; 125 m_instance = NULL;
98 m_location = attached_location; 126 m_location = attached_location;
99 } 127 }
128 void GenericRendererNode::setAttached(Layer* attached_layer) {
129 m_layer = attached_layer;
130 }
100 void GenericRendererNode::setAttached(const Point &attached_point) { 131 void GenericRendererNode::setAttached(const Point &attached_point) {
101 m_instance = NULL; 132 m_instance = NULL;
102 m_location = NULL; 133 m_location = NULL;
103 m_point = attached_point; 134 m_point = attached_point;
104 } 135 }
133 if(m_instance != NULL || m_location == NULL) { 164 if(m_instance != NULL || m_location == NULL) {
134 throw NotSupported("No location attached."); 165 throw NotSupported("No location attached.");
135 } 166 }
136 return m_location; 167 return m_location;
137 } 168 }
169 Layer* GenericRendererNode::getAttachedLayer() {
170 if(m_layer == NULL) {
171 throw NotSupported("No layer attached.");
172 }
173 return m_layer;
174 }
138 Point GenericRendererNode::getAttachedPoint() { 175 Point GenericRendererNode::getAttachedPoint() {
139 if(m_instance != NULL || m_location != NULL) { 176 if(m_instance != NULL || m_location != NULL) {
140 throw NotSupported("No point attached."); 177 throw NotSupported("No point attached.");
141 } 178 }
142 return m_point; 179 return m_point;
159 return m_instance; 196 return m_instance;
160 } 197 }
161 Location* GenericRendererNode::getLocation() { 198 Location* GenericRendererNode::getLocation() {
162 return m_location; 199 return m_location;
163 } 200 }
201 Layer* GenericRendererNode::getLayer() {
202 return m_layer;
203 }
164 Point GenericRendererNode::getPoint() { 204 Point GenericRendererNode::getPoint() {
165 return m_point; 205 return m_point;
166 } 206 }
167 207
168 Point GenericRendererNode::getCalculatedPoint(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { 208 Point GenericRendererNode::getCalculatedPoint(Camera* cam, Layer* layer, std::vector<Instance*>& instances) {
169 ScreenPoint p; 209 ScreenPoint p;
170 if(m_instance != NULL) { 210 if(m_instance != NULL) {
211 if(m_layer == NULL) {
212 m_layer = m_instance->getLocation().getLayer();
213 }
171 if(m_location != NULL) { 214 if(m_location != NULL) {
172 p = cam->toScreenCoordinates(m_instance->getLocationRef().getMapCoordinates() + m_location->getMapCoordinates()); 215 p = cam->toScreenCoordinates(m_instance->getLocationRef().getMapCoordinates() + m_location->getMapCoordinates());
173 } 216 } else {
174 else {
175 p = cam->toScreenCoordinates(m_instance->getLocation().getMapCoordinates()); 217 p = cam->toScreenCoordinates(m_instance->getLocation().getMapCoordinates());
176 } 218 }
177 } 219 } else if(m_location != NULL) {
178 else if(m_location != NULL) { 220 if(m_layer == NULL) {
221 m_layer = m_location->getLayer();
222 }
179 p = cam->toScreenCoordinates(m_location->getMapCoordinates()); 223 p = cam->toScreenCoordinates(m_location->getMapCoordinates());
180 } 224 } else if(m_layer == NULL) {
181 else 225 const std::list<Layer*>& layers = cam->getRenderer("GenericRenderer")->getActiveLayers();
182 return m_point; 226 std::list<Layer*>::const_iterator layer_it = layers.begin();
227 for (; layer_it != layers.end(); ++layer_it) {
228 setAttached(*layer_it);
229 }
230 }
183 return Point(m_point.x + p.x, m_point.y + p.y); 231 return Point(m_point.x + p.x, m_point.y + p.y);
184 } 232 }
185 233
186 GenericRendererLineInfo::GenericRendererLineInfo(GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b): 234 GenericRendererLineInfo::GenericRendererLineInfo(GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b):
187 GenericRendererElementInfo(), 235 GenericRendererElementInfo(),
192 m_blue(b) { 240 m_blue(b) {
193 } 241 }
194 void GenericRendererLineInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { 242 void GenericRendererLineInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
195 Point p1 = m_edge1.getCalculatedPoint(cam, layer, instances); 243 Point p1 = m_edge1.getCalculatedPoint(cam, layer, instances);
196 Point p2 = m_edge2.getCalculatedPoint(cam, layer, instances); 244 Point p2 = m_edge2.getCalculatedPoint(cam, layer, instances);
197 renderbackend->drawLine(p1, p2, m_red, m_green, m_blue); 245 if(m_edge1.getLayer() == layer) {
246 renderbackend->drawLine(p1, p2, m_red, m_green, m_blue);
247 }
198 } 248 }
199 249
200 GenericRendererPointInfo::GenericRendererPointInfo(GenericRendererNode anchor, uint8_t r, uint8_t g, uint8_t b): 250 GenericRendererPointInfo::GenericRendererPointInfo(GenericRendererNode anchor, uint8_t r, uint8_t g, uint8_t b):
201 GenericRendererElementInfo(), 251 GenericRendererElementInfo(),
202 m_anchor(anchor), 252 m_anchor(anchor),
204 m_green(g), 254 m_green(g),
205 m_blue(b) { 255 m_blue(b) {
206 } 256 }
207 void GenericRendererPointInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { 257 void GenericRendererPointInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
208 Point p = m_anchor.getCalculatedPoint(cam, layer, instances); 258 Point p = m_anchor.getCalculatedPoint(cam, layer, instances);
209 renderbackend->putPixel(p.x, p.y, m_red, m_green, m_blue); 259 if(m_anchor.getLayer() == layer) {
260 renderbackend->putPixel(p.x, p.y, m_red, m_green, m_blue);
261 }
210 } 262 }
211 263
212 GenericRendererQuadInfo::GenericRendererQuadInfo(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b): 264 GenericRendererQuadInfo::GenericRendererQuadInfo(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b):
213 GenericRendererElementInfo(), 265 GenericRendererElementInfo(),
214 m_edge1(n1), 266 m_edge1(n1),
222 void GenericRendererQuadInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { 274 void GenericRendererQuadInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
223 Point p1 = m_edge1.getCalculatedPoint(cam, layer, instances); 275 Point p1 = m_edge1.getCalculatedPoint(cam, layer, instances);
224 Point p2 = m_edge2.getCalculatedPoint(cam, layer, instances); 276 Point p2 = m_edge2.getCalculatedPoint(cam, layer, instances);
225 Point p3 = m_edge3.getCalculatedPoint(cam, layer, instances); 277 Point p3 = m_edge3.getCalculatedPoint(cam, layer, instances);
226 Point p4 = m_edge4.getCalculatedPoint(cam, layer, instances); 278 Point p4 = m_edge4.getCalculatedPoint(cam, layer, instances);
227 renderbackend->drawQuad(p1, p2, p3, p4, m_red, m_green, m_blue); 279 if(m_edge1.getLayer() == layer) {
280 renderbackend->drawQuad(p1, p2, p3, p4, m_red, m_green, m_blue);
281 }
228 } 282 }
229 283
230 GenericRendererVertexInfo::GenericRendererVertexInfo(GenericRendererNode center, int size, uint8_t r, uint8_t g, uint8_t b): 284 GenericRendererVertexInfo::GenericRendererVertexInfo(GenericRendererNode center, int size, uint8_t r, uint8_t g, uint8_t b):
231 GenericRendererElementInfo(), 285 GenericRendererElementInfo(),
232 m_center(center), 286 m_center(center),
235 m_green(g), 289 m_green(g),
236 m_blue(b) { 290 m_blue(b) {
237 } 291 }
238 void GenericRendererVertexInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { 292 void GenericRendererVertexInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
239 Point p = m_center.getCalculatedPoint(cam, layer, instances); 293 Point p = m_center.getCalculatedPoint(cam, layer, instances);
240 renderbackend->drawVertex(p, m_size, m_red, m_green, m_blue); 294 if(m_center.getLayer() == layer) {
295 renderbackend->drawVertex(p, m_size, m_red, m_green, m_blue);
296 }
241 } 297 }
242 298
243 GenericRendererImageInfo::GenericRendererImageInfo(GenericRendererNode anchor, int image): 299 GenericRendererImageInfo::GenericRendererImageInfo(GenericRendererNode anchor, int image):
244 GenericRendererElementInfo(), 300 GenericRendererElementInfo(),
245 m_anchor(anchor), 301 m_anchor(anchor),
246 m_image(image) { 302 m_image(image) {
247 } 303 }
248 void GenericRendererImageInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { 304 void GenericRendererImageInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
249 Point p = m_anchor.getCalculatedPoint(cam, layer, instances); 305 Point p = m_anchor.getCalculatedPoint(cam, layer, instances);
250 Image* img = &imagepool->getImage(m_image); 306 if(m_anchor.getLayer() == layer) {
251 Rect r; 307 Image* img = &imagepool->getImage(m_image);
252 r.x = p.x-img->getWidth()/2; 308 Rect r;
253 r.y = p.y-img->getHeight()/2; 309 r.x = p.x-img->getWidth()/2;
254 r.w = img->getWidth(); 310 r.y = p.y-img->getHeight()/2;
255 r.h = img->getHeight(); 311 r.w = img->getWidth();
256 img->render(r); 312 r.h = img->getHeight();
313 img->render(r);
314 }
257 } 315 }
258 316
259 GenericRendererAnimationInfo::GenericRendererAnimationInfo(GenericRendererNode anchor, int animation): 317 GenericRendererAnimationInfo::GenericRendererAnimationInfo(GenericRendererNode anchor, int animation):
260 GenericRendererElementInfo(), 318 GenericRendererElementInfo(),
261 m_anchor(anchor), 319 m_anchor(anchor),
263 m_start_time(TimeManager::instance()->getTime()), 321 m_start_time(TimeManager::instance()->getTime()),
264 m_time_scale(1.0) { 322 m_time_scale(1.0) {
265 } 323 }
266 void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { 324 void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
267 Point p = m_anchor.getCalculatedPoint(cam, layer, instances); 325 Point p = m_anchor.getCalculatedPoint(cam, layer, instances);
268 Animation& animation = animpool->getAnimation(m_animation); 326 if(m_anchor.getLayer() == layer) {
269 int animtime = scaleTime(m_time_scale, TimeManager::instance()->getTime() - m_start_time) % animation.getDuration(); 327 Animation& animation = animpool->getAnimation(m_animation);
270 Image* img = animation.getFrameByTimestamp(animtime); 328 int animtime = scaleTime(m_time_scale, TimeManager::instance()->getTime() - m_start_time) % animation.getDuration();
271 Rect r; 329 Image* img = animation.getFrameByTimestamp(animtime);
272 r.x = p.x-img->getWidth()/2; 330 Rect r;
273 r.y = p.y-img->getHeight()/2; 331 r.x = p.x-img->getWidth()/2;
274 r.w = img->getWidth(); 332 r.y = p.y-img->getHeight()/2;
275 r.h = img->getHeight(); 333 r.w = img->getWidth();
276 img->render(r); 334 r.h = img->getHeight();
335 img->render(r);
336 }
277 } 337 }
278 338
279 GenericRendererTextInfo::GenericRendererTextInfo(GenericRendererNode anchor, AbstractFont* font, std::string text): 339 GenericRendererTextInfo::GenericRendererTextInfo(GenericRendererNode anchor, AbstractFont* font, std::string text):
280 GenericRendererElementInfo(), 340 GenericRendererElementInfo(),
281 m_anchor(anchor), 341 m_anchor(anchor),
282 m_font(font), 342 m_font(font),
283 m_text(text) { 343 m_text(text) {
284 } 344 }
285 void GenericRendererTextInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { 345 void GenericRendererTextInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
286 Point p = m_anchor.getCalculatedPoint(cam, layer, instances); 346 Point p = m_anchor.getCalculatedPoint(cam, layer, instances);
287 Image* img = m_font->getAsImageMultiline(m_text); 347 if(m_anchor.getLayer() == layer) {
288 Rect r; 348 Image* img = m_font->getAsImageMultiline(m_text);
289 r.x = p.x-img->getWidth()/2; 349 Rect r;
290 r.y = p.y-img->getHeight()/2; 350 r.x = p.x-img->getWidth()/2;
291 r.w = img->getWidth(); 351 r.y = p.y-img->getHeight()/2;
292 r.h = img->getHeight(); 352 r.w = img->getWidth();
293 img->render(r); 353 r.h = img->getHeight();
354 img->render(r);
355 }
294 } 356 }
295 357
296 GenericRenderer* GenericRenderer::getInstance(IRendererContainer* cnt) { 358 GenericRenderer* GenericRenderer::getInstance(IRendererContainer* cnt) {
297 return dynamic_cast<GenericRenderer*>(cnt->getRenderer("GenericRenderer")); 359 return dynamic_cast<GenericRenderer*>(cnt->getRenderer("GenericRenderer"));
298 } 360 }