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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
|
/***************************************************************************
* Copyright (C) 2005-2019 by the FIFE team *
* http://www.fifengine.net *
* This file is part of FIFE. *
* *
* FIFE is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef FIFE_GENERICRENDERER_H
#define FIFE_GENERICRENDERER_H
// Standard C++ library includes
// 3rd party library includes
// FIFE includes
// These includes are split up in two parts, separated by one empty line
// First block: files included from the FIFE root src directory
// Second block: files included from the same folder
#include "model/structures/renderernode.h"
#include "view/rendererbase.h"
#include "video/animation.h"
namespace FIFE {
class RenderBackend;
class IFont;
class GenericRendererElementInfo {
public:
virtual void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend) {};
virtual ~GenericRendererElementInfo() {};
};
class GenericRendererLineInfo : public GenericRendererElementInfo {
public:
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
GenericRendererLineInfo(RendererNode n1, RendererNode n2, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
virtual ~GenericRendererLineInfo() {};
private:
RendererNode m_edge1;
RendererNode m_edge2;
uint8_t m_red;
uint8_t m_green;
uint8_t m_blue;
uint8_t m_alpha;
};
class GenericRendererPointInfo : public GenericRendererElementInfo {
public:
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
GenericRendererPointInfo(RendererNode n, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
virtual ~GenericRendererPointInfo() {};
private:
RendererNode m_anchor;
uint8_t m_red;
uint8_t m_green;
uint8_t m_blue;
uint8_t m_alpha;
};
class GenericRendererTriangleInfo : public GenericRendererElementInfo {
public:
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
GenericRendererTriangleInfo(RendererNode n1, RendererNode n2, RendererNode n3, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
virtual ~GenericRendererTriangleInfo() {};
private:
RendererNode m_edge1;
RendererNode m_edge2;
RendererNode m_edge3;
uint8_t m_red;
uint8_t m_green;
uint8_t m_blue;
uint8_t m_alpha;
};
class GenericRendererQuadInfo : public GenericRendererElementInfo {
public:
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
GenericRendererQuadInfo(RendererNode n1, RendererNode n2, RendererNode n3, RendererNode n4, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
virtual ~GenericRendererQuadInfo() {};
private:
RendererNode m_edge1;
RendererNode m_edge2;
RendererNode m_edge3;
RendererNode m_edge4;
uint8_t m_red;
uint8_t m_green;
uint8_t m_blue;
uint8_t m_alpha;
};
class GenericRendererVertexInfo : public GenericRendererElementInfo {
public:
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
GenericRendererVertexInfo(RendererNode center, int32_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
virtual ~GenericRendererVertexInfo() {};
private:
RendererNode m_center;
int32_t m_size;
uint8_t m_red;
uint8_t m_green;
uint8_t m_blue;
uint8_t m_alpha;
};
class GenericRendererImageInfo : public GenericRendererElementInfo {
public:
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
GenericRendererImageInfo(RendererNode n, ImagePtr image, bool zoomed = true);
virtual ~GenericRendererImageInfo() {};
private:
RendererNode m_anchor;
ImagePtr m_image;
bool m_zoomed;
};
class GenericRendererAnimationInfo : public GenericRendererElementInfo {
public:
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
GenericRendererAnimationInfo(RendererNode n, AnimationPtr animation, bool zoomed = true);
virtual ~GenericRendererAnimationInfo() {};
private:
RendererNode m_anchor;
AnimationPtr m_animation;
uint32_t m_start_time;
float m_time_scale;
bool m_zoomed;
};
class GenericRendererTextInfo : public GenericRendererElementInfo {
public:
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
GenericRendererTextInfo(RendererNode n, IFont* font, std::string text, bool zoomed = true);
virtual ~GenericRendererTextInfo() {};
private:
RendererNode m_anchor;
IFont* m_font;
std::string m_text;
bool m_zoomed;
};
class GenericRendererResizeInfo : public GenericRendererElementInfo {
public:
void render(Camera* cam, Layer* layer, RenderList& instances, RenderBackend* renderbackend);
GenericRendererResizeInfo(RendererNode n, ImagePtr image, int32_t width, int32_t height, bool zoomed = true);
virtual ~GenericRendererResizeInfo() {};
private:
RendererNode m_anchor;
ImagePtr m_image;
int32_t m_width;
int32_t m_height;
bool m_zoomed;
};
class GenericRenderer: public RendererBase {
public:
/** Constructor.
*
* @param renderbackend The renderbackend to use.
* @param position The position for this renderer in rendering pipeline.
* @ see setPipelinePosition
*/
GenericRenderer(RenderBackend* renderbackend, int32_t position);
/** Copy Constructor.
*/
GenericRenderer(const GenericRenderer& old);
/** Makes copy of this renderer.
*/
RendererBase* clone();
/** Destructor.
*/
virtual ~GenericRenderer();
/** This method is called by the view to ask renderer to draw its rendering aspect based on
* given parameters.
*
* @param cam Camera view to draw
* @param layer Current layer to be rendered
* @param instances Instances on the current layer
*/
void render(Camera* cam, Layer* layer, RenderList& instances);
/** Returns the renderer name.
*
* @return The name as string.
*/
std::string getName() { return "GenericRenderer"; }
/** Gets instance for interface access.
*/
static GenericRenderer* getInstance(IRendererContainer* cnt);
/** Adds a line.
*
* @param group The group name as string.
* @param n1 A RendererNode, contains the coordinates.
* @param n2 A RendererNode, contains the coordinates.
* @param r The value for red, range 0-255.
* @param g The value for green, range 0-255.
* @param b The value for blue, range 0-255.
* @param a The value for alpha, range 0-255. Default value is 255, full opaque.
*/
void addLine(const std::string &group, RendererNode n1, RendererNode n2, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
/** Adds a point.
*
* @param group The group name as string.
* @param n A RendererNode, contains the coordinates.
* @param r The value for red, range 0-255.
* @param g The value for green, range 0-255.
* @param b The value for blue, range 0-255.
* @param a The value for alpha, range 0-255. Default value is 255, full opaque.
*/
void addPoint(const std::string &group, RendererNode n, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
/** Adds a triangle.
*
* @param group The group name as string.
* @param n1 A RendererNode, contains the coordinates.
* @param n2 A RendererNode, contains the coordinates.
* @param n3 A RendererNode, contains the coordinates.
* @param r The value for red, range 0-255.
* @param g The value for green, range 0-255.
* @param b The value for blue, range 0-255.
* @param a The value for alpha, range 0-255. Default value is 255, full opaque.
*/
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);
/** Adds a quad.
*
* @param group The group name as string.
* @param n1 A RendererNode, contains the coordinates.
* @param n2 A RendererNode, contains the coordinates.
* @param n3 A RendererNode, contains the coordinates.
* @param n4 A RendererNode, contains the coordinates.
* @param r The value for red, range 0-255.
* @param g The value for green, range 0-255.
* @param b The value for blue, range 0-255.
* @param a The value for alpha, range 0-255. Default value is 255, full opaque.
*/
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);
/** Adds a vertex.
*
* @param group The group name as string.
* @param n A RendererNode, contains the coordinates.
* @param size The size of the vertex.
* @param r The value for red, range 0-255.
* @param g The value for green, range 0-255.
* @param b The value for blue, range 0-255.
* @param a The value for alpha, range 0-255. Default value is 255, full opaque.
*/
void addVertex(const std::string &group, RendererNode n, int32_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255);
/** Adds text.
*
* @param group The group name as string.
* @param n A RendererNode, contains the coordinates.
* @param font The used font.
* @param text The text as string.
* @param zoomed A flag that indicates whether the camera zoom to be used. Default is true.
*/
void addText(const std::string &group, RendererNode n, IFont* font, const std::string &text, bool zoomed = true);
/** Adds an image.
*
* @param group The group name as string.
* @param n A RendererNode, contains the coordinates.
* @param image The used image.
* @param zoomed A flag that indicates whether the camera zoom to be used. Default is true.
*/
void addImage(const std::string &group, RendererNode n, ImagePtr image, bool zoomed = true);
/** Adds an animation.
*
* @param group The group name as string.
* @param n A RendererNode, contains the coordinates.
* @param animation The used animation.
* @param zoomed A flag that indicates whether the camera zoom to be used. Default is true.
*/
void addAnimation(const std::string &group, RendererNode n, AnimationPtr animation, bool zoomed = true);
/** Adds an image with another size.
*
* @param group The group name as string.
* @param n A RendererNode, contains the coordinates.
* @param image The used image.
* @param width New width of the image.
* @param height New height of the image.
* @param zoomed A flag that indicates whether the camera zoom to be used. Default is true.
*/
void resizeImage(const std::string &group, RendererNode n, ImagePtr image, int32_t width, int32_t height, bool zoomed = true);
/** Removes all elements of a group.
*
* @param group The group name as string.
*/
void removeAll(const std::string &group);
/** Removes all elements.
*/
void removeAll();
/** Resets the renderer.
*/
void reset();
private:
//! A map that holds the groups together with the appended render elements.
std::map<std::string, std::vector<GenericRendererElementInfo*> > m_groups;
};
}
#endif
|