Mercurial > fife-parpg
annotate engine/core/view/renderers/genericrenderer.cpp @ 30:9c3f37432a28
fix clone constructor
author | spq@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 11 Jul 2008 13:08:44 +0000 |
parents | 0cb049f291e1 |
children | 9a9f4447af7c |
rev | line source |
---|---|
23 | 1 /*************************************************************************** |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program 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 * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 | |
24 // 3rd party library includes | |
25 | |
26 // FIFE includes | |
27 // These includes are split up in two parts, separated by one empty line | |
28 // First block: files included from the FIFE root src directory | |
29 // Second block: files included from the same folder | |
30 #include "video/renderbackend.h" | |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
31 #include "video/imagepool.h" |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
32 #include "video/animation.h" |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
33 #include "video/animationpool.h" |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
34 #include "video/fonts/abstractfont.h" |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
35 #include "video/image.h" |
23 | 36 #include "util/math/fife_math.h" |
37 #include "util/log/logger.h" | |
38 #include "model/metamodel/grids/cellgrid.h" | |
39 #include "model/structures/instance.h" | |
40 #include "model/structures/layer.h" | |
41 #include "model/structures/location.h" | |
42 | |
43 #include "view/camera.h" | |
44 #include "genericrenderer.h" | |
45 | |
46 | |
47 namespace FIFE { | |
48 static Logger _log(LM_VIEWVIEW); | |
49 | |
50 GenericRendererNode::GenericRendererNode(Instance* attached_instance, Location* relative_location, const Point &relative_point): | |
51 m_instance(attached_instance), | |
52 m_location(relative_location), | |
53 m_point(relative_point) { | |
54 } | |
55 GenericRendererNode::GenericRendererNode(Instance* attached_instance, const Point &relative_point): | |
56 m_instance(attached_instance), | |
57 m_location(NULL), | |
58 m_point(relative_point) { | |
59 } | |
60 GenericRendererNode::GenericRendererNode(Location* attached_location, const Point &relative_point): | |
61 m_instance(NULL), | |
62 m_location(attached_location), | |
63 m_point(relative_point) { | |
64 } | |
65 GenericRendererNode::GenericRendererNode(const Point &attached_point): | |
66 m_instance(NULL), | |
67 m_location(NULL), | |
68 m_point(attached_point) { | |
69 } | |
70 GenericRendererNode::~GenericRendererNode() { | |
71 } | |
72 | |
26
70f41ea8e7db
fix compile errors in node setters...
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
25
diff
changeset
|
73 void GenericRendererNode::setAttached(Instance* attached_instance, Location* relative_location, const Point &relative_point) { |
25
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
74 m_instance = attached_instance; |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
75 m_location = relative_location; |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
76 m_point = relative_point; |
23 | 77 } |
26
70f41ea8e7db
fix compile errors in node setters...
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
25
diff
changeset
|
78 void GenericRendererNode::setAttached(Instance* attached_instance, Location* relative_location) { |
25
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
79 m_instance = attached_instance; |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
80 m_location = relative_location; |
23 | 81 } |
82 void GenericRendererNode::setAttached(Instance* attached_instance, const Point &relative_point) { | |
25
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
83 m_instance = attached_instance; |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
84 m_point = relative_point; |
23 | 85 } |
86 void GenericRendererNode::setAttached(Instance* attached_instance) { | |
25
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
87 m_instance = attached_instance; |
23 | 88 } |
26
70f41ea8e7db
fix compile errors in node setters...
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
25
diff
changeset
|
89 void GenericRendererNode::setAttached(Location* attached_location, const Point &relative_point) { |
25
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
90 m_instance = NULL; |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
91 m_location = attached_location; |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
92 m_point = relative_point; |
23 | 93 } |
26
70f41ea8e7db
fix compile errors in node setters...
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
25
diff
changeset
|
94 void GenericRendererNode::setAttached(Location* attached_location) { |
25
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
95 m_instance = NULL; |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
96 m_location = attached_location; |
23 | 97 } |
98 void GenericRendererNode::setAttached(const Point &attached_point) { | |
25
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
99 m_instance = NULL; |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
100 m_location = NULL; |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
101 m_point = attached_point; |
23 | 102 } |
103 | |
26
70f41ea8e7db
fix compile errors in node setters...
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
25
diff
changeset
|
104 void GenericRendererNode::setRelative(Location* relative_location) { |
25
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
105 if(m_instance == NULL) { |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
106 throw NotSupported("No instance attached."); |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
107 } |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
108 m_location = relative_location; |
23 | 109 } |
26
70f41ea8e7db
fix compile errors in node setters...
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
25
diff
changeset
|
110 void GenericRendererNode::setRelative(Location* relative_location, Point relative_point) { |
25
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
111 if(m_instance == NULL) { |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
112 throw NotSupported("No instance attached."); |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
113 } |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
114 m_location = relative_location; |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
115 m_point = relative_point; |
23 | 116 } |
117 void GenericRendererNode::setRelative(const Point &relative_point) { | |
25
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
118 if(m_instance == NULL or m_location == NULL) { |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
119 throw NotSupported("No instance or location attached."); |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
120 } |
fc6713d72b80
add setter for nodes
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
24
diff
changeset
|
121 m_point = relative_point; |
23 | 122 } |
123 | |
124 Instance* GenericRendererNode::getAttachedInstance() { | |
125 if(m_instance == NULL) { | |
24
cb87d40e9342
fix exceptions and cleanup code
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
23
diff
changeset
|
126 throw NotSupported("No instance attached."); |
23 | 127 } |
128 return m_instance; | |
129 } | |
130 Location* GenericRendererNode::getAttachedLocation() { | |
131 if(m_instance != NULL or m_location == NULL) { | |
24
cb87d40e9342
fix exceptions and cleanup code
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
23
diff
changeset
|
132 throw NotSupported("No location attached."); |
23 | 133 } |
134 return m_location; | |
135 } | |
136 Point GenericRendererNode::getAttachedPoint() { | |
137 if(m_instance != NULL or m_location != NULL) { | |
24
cb87d40e9342
fix exceptions and cleanup code
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
23
diff
changeset
|
138 throw NotSupported("No point attached."); |
23 | 139 } |
140 return m_point; | |
141 } | |
142 | |
143 Location* GenericRendererNode::getOffsetLocation() { | |
24
cb87d40e9342
fix exceptions and cleanup code
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
23
diff
changeset
|
144 if(m_instance == NULL or m_location == NULL) { |
cb87d40e9342
fix exceptions and cleanup code
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
23
diff
changeset
|
145 throw NotSupported("No location as offset used."); |
23 | 146 } |
147 return m_location; | |
148 } | |
149 Point GenericRendererNode::getOffsetPoint() { | |
150 if(m_instance == NULL and m_location == NULL) { | |
24
cb87d40e9342
fix exceptions and cleanup code
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
23
diff
changeset
|
151 throw NotSupported("No point as offset used."); |
23 | 152 } |
153 return m_point; | |
154 } | |
155 | |
156 Instance* GenericRendererNode::getInstance() { | |
157 return m_instance; | |
158 } | |
159 Location* GenericRendererNode::getLocation() { | |
160 return m_location; | |
161 } | |
162 Point GenericRendererNode::getPoint() { | |
163 return m_point; | |
164 } | |
165 | |
166 Point GenericRendererNode::getCalculatedPoint(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { | |
167 ScreenPoint p; | |
168 if(m_instance != NULL) { | |
169 if(m_location != NULL) { | |
170 p = cam->toScreenCoordinates(m_instance->getLocationRef().getMapCoordinates() + m_location->getMapCoordinates()); | |
171 } | |
172 else { | |
173 p = cam->toScreenCoordinates(m_instance->getLocation().getMapCoordinates()); | |
174 } | |
175 } | |
176 else if(m_location != NULL) { | |
177 p = cam->toScreenCoordinates(m_location->getMapCoordinates()); | |
178 } | |
179 else | |
180 return m_point; | |
181 return Point(m_point.x + p.x, m_point.y + p.y); | |
182 } | |
183 | |
184 GenericRendererLineInfo::GenericRendererLineInfo(GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b): | |
185 GenericRendererElementInfo(), | |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
186 m_edge1(n1), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
187 m_edge2(n2), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
188 m_red(r), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
189 m_green(g), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
190 m_blue(b) { |
23 | 191 } |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
192 void GenericRendererLineInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
193 Point p1 = m_edge1.getCalculatedPoint(cam, layer, instances); |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
194 Point p2 = m_edge2.getCalculatedPoint(cam, layer, instances); |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
195 renderbackend->drawLine(p1, p2, m_red, m_green, m_blue); |
23 | 196 } |
197 | |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
198 GenericRendererPointInfo::GenericRendererPointInfo(GenericRendererNode anchor, uint8_t r, uint8_t g, uint8_t b): |
23 | 199 GenericRendererElementInfo(), |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
200 m_anchor(anchor), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
201 m_red(r), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
202 m_green(g), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
203 m_blue(b) { |
23 | 204 } |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
205 void GenericRendererPointInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
206 Point p = m_anchor.getCalculatedPoint(cam, layer, instances); |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
207 renderbackend->putPixel(p.x, p.y, m_red, m_green, m_blue); |
23 | 208 } |
209 | |
210 GenericRendererQuadInfo::GenericRendererQuadInfo(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b): | |
211 GenericRendererElementInfo(), | |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
212 m_edge1(n1), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
213 m_edge2(n2), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
214 m_edge3(n3), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
215 m_edge4(n4), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
216 m_red(r), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
217 m_green(g), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
218 m_blue(b) { |
23 | 219 } |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
220 void GenericRendererQuadInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
221 Point p1 = m_edge1.getCalculatedPoint(cam, layer, instances); |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
222 Point p2 = m_edge2.getCalculatedPoint(cam, layer, instances); |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
223 Point p3 = m_edge3.getCalculatedPoint(cam, layer, instances); |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
224 Point p4 = m_edge4.getCalculatedPoint(cam, layer, instances); |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
225 renderbackend->drawQuad(p1, p2, p3, p4, m_red, m_green, m_blue); |
23 | 226 } |
227 | |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
228 GenericRendererImageInfo::GenericRendererImageInfo(GenericRendererNode anchor, int image): |
23 | 229 GenericRendererElementInfo(), |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
230 m_anchor(anchor), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
231 m_image(image) { |
23 | 232 } |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
233 void GenericRendererImageInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
234 Point p = m_anchor.getCalculatedPoint(cam, layer, instances); |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
235 Image* img = &imagepool->getImage(m_image); |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
236 Rect r; |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
237 r.x = p.x-img->getWidth()/2; |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
238 r.y = p.y-img->getHeight()/2; |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
239 r.w = img->getWidth(); |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
240 r.h = img->getHeight(); |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
241 img->render(r); |
23 | 242 } |
243 | |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
244 GenericRendererAnimationInfo::GenericRendererAnimationInfo(GenericRendererNode anchor, int animation): |
23 | 245 GenericRendererElementInfo(), |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
246 m_anchor(anchor), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
247 m_animation(animation) { |
23 | 248 } |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
249 void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { |
23 | 250 return; |
251 } | |
252 | |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
253 GenericRendererTextInfo::GenericRendererTextInfo(GenericRendererNode anchor, AbstractFont* font, std::string text): |
23 | 254 GenericRendererElementInfo(), |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
255 m_anchor(anchor), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
256 m_font(font), |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
257 m_text(text) { |
23 | 258 } |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
259 void GenericRendererTextInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { |
29
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
260 Point p = m_anchor.getCalculatedPoint(cam, layer, instances); |
0cb049f291e1
make members private and prefix with m_
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
27
diff
changeset
|
261 Image* img = m_font->getAsImageMultiline(m_text); |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
262 Rect r; |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
263 r.x = p.x-img->getWidth()/2; |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
264 r.y = p.y-img->getHeight()/2; |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
265 r.w = img->getWidth(); |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
266 r.h = img->getHeight(); |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
267 img->render(r); |
23 | 268 } |
269 | |
270 GenericRenderer* GenericRenderer::getInstance(IRendererContainer* cnt) { | |
271 return dynamic_cast<GenericRenderer*>(cnt->getRenderer("GenericRenderer")); | |
272 } | |
273 | |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
274 GenericRenderer::GenericRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool): |
23 | 275 RendererBase(renderbackend, position), |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
276 m_imagepool(imagepool), |
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
277 m_animationpool(animpool), |
23 | 278 m_infos() { |
279 setEnabled(false); | |
280 } | |
281 | |
282 GenericRenderer::GenericRenderer(const GenericRenderer& old): | |
30
9c3f37432a28
fix clone constructor
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
29
diff
changeset
|
283 RendererBase(old), |
9c3f37432a28
fix clone constructor
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
29
diff
changeset
|
284 m_imagepool(old.m_imagepool), |
9c3f37432a28
fix clone constructor
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
29
diff
changeset
|
285 m_animationpool(old.m_animationpool), |
9c3f37432a28
fix clone constructor
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
29
diff
changeset
|
286 m_infos() { |
23 | 287 setEnabled(false); |
288 } | |
289 | |
290 RendererBase* GenericRenderer::clone() { | |
291 return new GenericRenderer(*this); | |
292 } | |
293 | |
294 GenericRenderer::~GenericRenderer() { | |
295 } | |
296 void GenericRenderer::addLine(GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b) { | |
297 GenericRendererElementInfo* info = new GenericRendererLineInfo(n1, n2, r, g, b); | |
298 m_infos.push_back(info); | |
299 } | |
300 void GenericRenderer::addPoint(GenericRendererNode n, uint8_t r, uint8_t g, uint8_t b) { | |
301 GenericRendererElementInfo* info = new GenericRendererPointInfo(n, r, g, b); | |
302 m_infos.push_back(info); | |
303 } | |
304 void GenericRenderer::addQuad(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b) { | |
305 GenericRendererElementInfo* info = new GenericRendererQuadInfo(n1, n2, n3, n4, r, g, b); | |
306 m_infos.push_back(info); | |
307 } | |
308 void GenericRenderer::addText(GenericRendererNode n, AbstractFont* font, std::string text) { | |
309 GenericRendererElementInfo* info = new GenericRendererTextInfo(n, font, text); | |
310 m_infos.push_back(info); | |
311 } | |
312 void GenericRenderer::addImage(GenericRendererNode n, int image) { | |
313 GenericRendererElementInfo* info = new GenericRendererImageInfo(n, image); | |
314 m_infos.push_back(info); | |
315 } | |
316 void GenericRenderer::addAnimation(GenericRendererNode n, int animation) { | |
317 GenericRendererElementInfo* info = new GenericRendererAnimationInfo(n, animation); | |
318 m_infos.push_back(info); | |
319 } | |
320 void GenericRenderer::removeAll() { | |
24
cb87d40e9342
fix exceptions and cleanup code
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
23
diff
changeset
|
321 std::vector<GenericRendererElementInfo*>::const_iterator info_it = m_infos.begin(); |
cb87d40e9342
fix exceptions and cleanup code
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
23
diff
changeset
|
322 for (;info_it != m_infos.end(); ++info_it) { |
cb87d40e9342
fix exceptions and cleanup code
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
23
diff
changeset
|
323 delete *info_it; |
cb87d40e9342
fix exceptions and cleanup code
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
23
diff
changeset
|
324 } |
23 | 325 m_infos.clear(); |
326 } | |
327 | |
328 void GenericRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { | |
329 std::vector<GenericRendererElementInfo*>::const_iterator info_it = m_infos.begin(); | |
330 for (;info_it != m_infos.end(); ++info_it) { | |
331 GenericRendererElementInfo* info = *info_it; | |
27
788cb9525b2f
add image and text renderer to generic renderer
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
26
diff
changeset
|
332 info->render(cam, layer, instances, m_renderbackend, m_imagepool, m_animationpool); |
23 | 333 } |
334 } | |
335 } |