annotate engine/core/view/renderers/genericrenderer.cpp @ 105:2241b0d5379e

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