| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
#ifndef FIFE_GENERICRENDERER_H |
| 23 |
#define FIFE_GENERICRENDERER_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
|
| 27 |
// 3rd party library includes |
| 28 |
|
| 29 |
// FIFE includes |
| 30 |
// These includes are split up in two parts, separated by one empty line |
| 31 |
// First block: files included from the FIFE root src directory |
| 32 |
// Second block: files included from the same folder |
| 33 |
#include "model/structures/renderernode.h" |
| 34 |
#include "view/rendererbase.h" |
| 35 |
#include "video/animation.h" |
| 36 |
|
| 37 |
namespace FIFE { |
| 38 |
class RenderBackend; |
| 39 |
class IFont; |
| 40 |
|
| 41 |
class GenericRendererElementInfo { |
| 42 |
public: |
| 43 |
virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend) {}; |
| 44 |
virtual ~GenericRendererElementInfo() {}; |
| 45 |
}; |
| 46 |
|
| 47 |
class GenericRendererLineInfo : public GenericRendererElementInfo { |
| 48 |
public: |
| 49 |
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend); |
| 50 |
GenericRendererLineInfo(RendererNode n1, RendererNode n2, uint8_t r, uint8_t g, uint8_t b, uint8_t a); |
| 51 |
virtual ~GenericRendererLineInfo() {}; |
| 52 |
private: |
| 53 |
RendererNode m_edge1; |
| 54 |
RendererNode m_edge2; |
| 55 |
uint8_t m_red; |
| 56 |
uint8_t m_green; |
| 57 |
uint8_t m_blue; |
| 58 |
uint8_t m_alpha; |
| 59 |
}; |
| 60 |
class GenericRendererPointInfo : public GenericRendererElementInfo { |
| 61 |
public: |
| 62 |
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend); |
| 63 |
GenericRendererPointInfo(RendererNode n, uint8_t r, uint8_t g, uint8_t b, uint8_t a); |
| 64 |
virtual ~GenericRendererPointInfo() {}; |
| 65 |
private: |
| 66 |
RendererNode m_anchor; |
| 67 |
uint8_t m_red; |
| 68 |
uint8_t m_green; |
| 69 |
uint8_t m_blue; |
| 70 |
uint8_t m_alpha; |
| 71 |
}; |
| 72 |
class GenericRendererTriangleInfo : public GenericRendererElementInfo { |
| 73 |
public: |
| 74 |
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend); |
| 75 |
GenericRendererTriangleInfo(RendererNode n1, RendererNode n2, RendererNode n3, uint8_t r, uint8_t g, uint8_t b, uint8_t a); |
| 76 |
virtual ~GenericRendererTriangleInfo() {}; |
| 77 |
private: |
| 78 |
RendererNode m_edge1; |
| 79 |
RendererNode m_edge2; |
| 80 |
RendererNode m_edge3; |
| 81 |
uint8_t m_red; |
| 82 |
uint8_t m_green; |
| 83 |
uint8_t m_blue; |
| 84 |
uint8_t m_alpha; |
| 85 |
}; |
| 86 |
class GenericRendererQuadInfo : public GenericRendererElementInfo { |
| 87 |
public: |
| 88 |
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend); |
| 89 |
GenericRendererQuadInfo(RendererNode n1, RendererNode n2, RendererNode n3, RendererNode n4, uint8_t r, uint8_t g, uint8_t b, uint8_t a); |
| 90 |
virtual ~GenericRendererQuadInfo() {}; |
| 91 |
private: |
| 92 |
RendererNode m_edge1; |
| 93 |
RendererNode m_edge2; |
| 94 |
RendererNode m_edge3; |
| 95 |
RendererNode m_edge4; |
| 96 |
uint8_t m_red; |
| 97 |
uint8_t m_green; |
| 98 |
uint8_t m_blue; |
| 99 |
uint8_t m_alpha; |
| 100 |
}; |
| 101 |
|
| 102 |
class GenericRendererVertexInfo : public GenericRendererElementInfo { |
| 103 |
public: |
| 104 |
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend); |
| 105 |
GenericRendererVertexInfo(RendererNode center, int32_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a); |
| 106 |
virtual ~GenericRendererVertexInfo() {}; |
| 107 |
private: |
| 108 |
RendererNode m_center; |
| 109 |
int32_t m_size; |
| 110 |
uint8_t m_red; |
| 111 |
uint8_t m_green; |
| 112 |
uint8_t m_blue; |
| 113 |
uint8_t m_alpha; |
| 114 |
}; |
| 115 |
|
| 116 |
class GenericRendererImageInfo : public GenericRendererElementInfo { |
| 117 |
public: |
| 118 |
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend); |
| 119 |
GenericRendererImageInfo(RendererNode n, ImagePtr image, bool zoomed = true); |
| 120 |
virtual ~GenericRendererImageInfo() {}; |
| 121 |
private: |
| 122 |
RendererNode m_anchor; |
| 123 |
ImagePtr m_image; |
| 124 |
bool m_zoomed; |
| 125 |
}; |
| 126 |
class GenericRendererAnimationInfo : public GenericRendererElementInfo { |
| 127 |
public: |
| 128 |
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend); |
| 129 |
GenericRendererAnimationInfo(RendererNode n, AnimationPtr animation, bool zoomed = true); |
| 130 |
virtual ~GenericRendererAnimationInfo() {}; |
| 131 |
private: |
| 132 |
RendererNode m_anchor; |
| 133 |
AnimationPtr m_animation; |
| 134 |
uint32_t m_start_time; |
| 135 |
float m_time_scale; |
| 136 |
bool m_zoomed; |
| 137 |
}; |
| 138 |
class GenericRendererTextInfo : public GenericRendererElementInfo { |
| 139 |
public: |
| 140 |
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend); |
| 141 |
GenericRendererTextInfo(RendererNode n, IFont* font, std::string text, bool zoomed = true); |
| 142 |
virtual ~GenericRendererTextInfo() {}; |
| 143 |
private: |
| 144 |
RendererNode m_anchor; |
| 145 |
IFont* m_font; |
| 146 |
std::string m_text; |
| 147 |
bool m_zoomed; |
| 148 |
}; |
| 149 |
class GenericRendererResizeInfo : public GenericRendererElementInfo { |
| 150 |
public: |
| 151 |
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend); |
| 152 |
GenericRendererResizeInfo(RendererNode n, ImagePtr image, int32_t width, int32_t height, bool zoomed = true); |
| 153 |
virtual ~GenericRendererResizeInfo() {}; |
| 154 |
private: |
| 155 |
RendererNode m_anchor; |
| 156 |
ImagePtr m_image; |
| 157 |
int32_t m_width; |
| 158 |
int32_t m_height; |
| 159 |
bool m_zoomed; |
| 160 |
}; |
| 161 |
class GenericRenderer: public RendererBase { |
| 162 |
public: |
| 163 |
/** Constructor. |
| 164 |
* |
| 165 |
* @param renderbackend The renderbackend to use. |
| 166 |
* @param position The position for this renderer in rendering pipeline. |
| 167 |
* @ see setPipelinePosition |
| 168 |
*/ |
| 169 |
GenericRenderer(RenderBackend* renderbackend, int32_t position); |
| 170 |
|
| 171 |
/** Copy Constructor. |
| 172 |
*/ |
| 173 |
GenericRenderer(const GenericRenderer& old); |
| 174 |
|
| 175 |
/** Makes copy of this renderer. |
| 176 |
*/ |
| 177 |
RendererBase* clone(); |
| 178 |
|
| 179 |
/** Destructor. |
| 180 |
*/ |
| 181 |
virtual ~GenericRenderer(); |
| 182 |
|
| 183 |
/** This method is called by the view to ask renderer to draw its rendering aspect based on |
| 184 |
* given parameters. |
| 185 |
* |
| 186 |
* @param cam Camera view to draw |
| 187 |
* @param layer Current layer to be rendered |
| 188 |
* @param instances Instances on the current layer |
| 189 |
*/ |
| 190 |
void render(Camera* cam, Layer* layer, RenderList& instances); |
| 191 |
|
| 192 |
/** Returns the renderer name. |
| 193 |
* |
| 194 |
* @return The name as string. |
| 195 |
*/ |
| 196 |
std::string getName() { return "GenericRenderer"; } |
| 197 |
|
| 198 |
/** Gets instance for interface access. |
| 199 |
*/ |
| 200 |
static GenericRenderer* getInstance(IRendererContainer* cnt); |
| 201 |
|
| 202 |
/** Adds a line. |
| 203 |
* |
| 204 |
* @param group The group name as string. |
| 205 |
* @param n1 A RendererNode, contains the coordinates. |
| 206 |
* @param n2 A RendererNode, contains the coordinates. |
| 207 |
* @param r The value for red, range 0-255. |
| 208 |
* @param g The value for green, range 0-255. |
| 209 |
* @param b The value for blue, range 0-255. |
| 210 |
* @param a The value for alpha, range 0-255. Default value is 255, full opaque. |
| 211 |
*/ |
| 212 |
void addLine(const std::string &group, RendererNode n1, RendererNode n2, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); |
| 213 |
|
| 214 |
/** Adds a point. |
| 215 |
* |
| 216 |
* @param group The group name as string. |
| 217 |
* @param n A RendererNode, contains the coordinates. |
| 218 |
* @param r The value for red, range 0-255. |
| 219 |
* @param g The value for green, range 0-255. |
| 220 |
* @param b The value for blue, range 0-255. |
| 221 |
* @param a The value for alpha, range 0-255. Default value is 255, full opaque. |
| 222 |
*/ |
| 223 |
void addPoint(const std::string &group, RendererNode n, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); |
| 224 |
|
| 225 |
/** Adds a triangle. |
| 226 |
* |
| 227 |
* @param group The group name as string. |
| 228 |
* @param n1 A RendererNode, contains the coordinates. |
| 229 |
* @param n2 A RendererNode, contains the coordinates. |
| 230 |
* @param n3 A RendererNode, contains the coordinates. |
| 231 |
* @param r The value for red, range 0-255. |
| 232 |
* @param g The value for green, range 0-255. |
| 233 |
* @param b The value for blue, range 0-255. |
| 234 |
* @param a The value for alpha, range 0-255. Default value is 255, full opaque. |
| 235 |
*/ |
| 236 |
void addTriangle(const std::string &group, RendererNode n1, RendererNode n2, RendererNode n3, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); |
| 237 |
|
| 238 |
/** Adds a quad. |
| 239 |
* |
| 240 |
* @param group The group name as string. |
| 241 |
* @param n1 A RendererNode, contains the coordinates. |
| 242 |
* @param n2 A RendererNode, contains the coordinates. |
| 243 |
* @param n3 A RendererNode, contains the coordinates. |
| 244 |
* @param n4 A RendererNode, contains the coordinates. |
| 245 |
* @param r The value for red, range 0-255. |
| 246 |
* @param g The value for green, range 0-255. |
| 247 |
* @param b The value for blue, range 0-255. |
| 248 |
* @param a The value for alpha, range 0-255. Default value is 255, full opaque. |
| 249 |
*/ |
| 250 |
void addQuad(const std::string &group, RendererNode n1, RendererNode n2, RendererNode n3, RendererNode n4, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); |
| 251 |
|
| 252 |
/** Adds a vertex. |
| 253 |
* |
| 254 |
* @param group The group name as string. |
| 255 |
* @param n A RendererNode, contains the coordinates. |
| 256 |
* @param size The size of the vertex. |
| 257 |
* @param r The value for red, range 0-255. |
| 258 |
* @param g The value for green, range 0-255. |
| 259 |
* @param b The value for blue, range 0-255. |
| 260 |
* @param a The value for alpha, range 0-255. Default value is 255, full opaque. |
| 261 |
*/ |
| 262 |
void addVertex(const std::string &group, RendererNode n, int32_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255); |
| 263 |
|
| 264 |
/** Adds text. |
| 265 |
* |
| 266 |
* @param group The group name as string. |
| 267 |
* @param n A RendererNode, contains the coordinates. |
| 268 |
* @param font The used font. |
| 269 |
* @param text The text as string. |
| 270 |
* @param zoomed A flag that indicates whether the camera zoom to be used. Default is true. |
| 271 |
*/ |
| 272 |
void addText(const std::string &group, RendererNode n, IFont* font, const std::string &text, bool zoomed = true); |
| 273 |
|
| 274 |
/** Adds an image. |
| 275 |
* |
| 276 |
* @param group The group name as string. |
| 277 |
* @param n A RendererNode, contains the coordinates. |
| 278 |
* @param image The used image. |
| 279 |
* @param zoomed A flag that indicates whether the camera zoom to be used. Default is true. |
| 280 |
*/ |
| 281 |
void addImage(const std::string &group, RendererNode n, ImagePtr image, bool zoomed = true); |
| 282 |
|
| 283 |
/** Adds an animation. |
| 284 |
* |
| 285 |
* @param group The group name as string. |
| 286 |
* @param n A RendererNode, contains the coordinates. |
| 287 |
* @param animation The used animation. |
| 288 |
* @param zoomed A flag that indicates whether the camera zoom to be used. Default is true. |
| 289 |
*/ |
| 290 |
void addAnimation(const std::string &group, RendererNode n, AnimationPtr animation, bool zoomed = true); |
| 291 |
|
| 292 |
/** Adds an image with another size. |
| 293 |
* |
| 294 |
* @param group The group name as string. |
| 295 |
* @param n A RendererNode, contains the coordinates. |
| 296 |
* @param image The used image. |
| 297 |
* @param width New width of the image. |
| 298 |
* @param height New height of the image. |
| 299 |
* @param zoomed A flag that indicates whether the camera zoom to be used. Default is true. |
| 300 |
*/ |
| 301 |
void resizeImage(const std::string &group, RendererNode n, ImagePtr image, int32_t width, int32_t height, bool zoomed = true); |
| 302 |
|
| 303 |
/** Removes all elements of a group. |
| 304 |
* |
| 305 |
* @param group The group name as string. |
| 306 |
*/ |
| 307 |
void removeAll(const std::string &group); |
| 308 |
|
| 309 |
/** Removes all elements. |
| 310 |
*/ |
| 311 |
void removeAll(); |
| 312 |
|
| 313 |
/** Resets the renderer. |
| 314 |
*/ |
| 315 |
void reset(); |
| 316 |
|
| 317 |
private: |
| 318 |
//! A map that holds the groups together with the appended render elements. |
| 319 |
std::map<std::string, std::vector<GenericRendererElementInfo*> > m_groups; |
| 320 |
}; |
| 321 |
|
| 322 |
} |
| 323 |
|
| 324 |
#endif |