Mercurial > fife-parpg
comparison engine/core/view/renderers/coordinaterenderer.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
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" | |
31 #include "video/image.h" | |
32 #include "video/imagepool.h" | |
33 #include "video/fonts/abstractfont.h" | |
34 #include "util/math/fife_math.h" | |
35 #include "util/log/logger.h" | |
36 #include "model/metamodel/grids/cellgrid.h" | |
37 #include "model/metamodel/action.h" | |
38 #include "model/structures/instance.h" | |
39 #include "model/structures/layer.h" | |
40 #include "model/structures/location.h" | |
41 | |
42 #include "view/camera.h" | |
43 #include "view/visual.h" | |
44 #include "coordinaterenderer.h" | |
45 | |
46 | |
47 namespace FIFE { | |
48 static Logger _log(LM_VIEWVIEW); | |
49 | |
50 CoordinateRenderer::CoordinateRenderer(RenderBackend* renderbackend, int position, AbstractFont* font): | |
51 RendererBase(renderbackend, position), | |
52 m_layer_area(), | |
53 m_tmploc(), | |
54 m_c(), | |
55 m_font(font) { | |
56 setEnabled(false); | |
57 } | |
58 | |
59 CoordinateRenderer::CoordinateRenderer(const CoordinateRenderer& old): | |
60 m_layer_area(), | |
61 m_tmploc(), | |
62 m_c(), | |
63 m_font(old.m_font) { | |
64 setEnabled(false); | |
65 } | |
66 | |
67 CoordinateRenderer::~CoordinateRenderer() { | |
68 } | |
69 | |
70 RendererBase* CoordinateRenderer::clone() { | |
71 return new CoordinateRenderer(*this); | |
72 } | |
73 | |
74 void CoordinateRenderer::adjustLayerArea() { | |
75 m_tmploc.setMapCoordinates(m_c); | |
76 ModelCoordinate c = m_tmploc.getLayerCoordinates(); | |
77 m_layer_area.x = std::min(c.x, m_layer_area.x); | |
78 m_layer_area.w = std::max(c.x, m_layer_area.w); | |
79 m_layer_area.y = std::min(c.y, m_layer_area.y); | |
80 m_layer_area.h = std::max(c.y, m_layer_area.h); | |
81 } | |
82 | |
83 const int MIN_COORD = -9999999; | |
84 const int MAX_COORD = 9999999; | |
85 void CoordinateRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) { | |
86 m_layer_area.x = MAX_COORD; | |
87 m_layer_area.y = MAX_COORD; | |
88 m_layer_area.w = MIN_COORD; | |
89 m_layer_area.h = MIN_COORD; | |
90 | |
91 m_tmploc.setLayer(layer); | |
92 Rect cv = cam->getViewPort(); | |
93 m_c = cam->toMapCoordinates(ScreenPoint(cv.x, cv.y), false); | |
94 adjustLayerArea(); | |
95 m_c = cam->toMapCoordinates(ScreenPoint(cv.x+cv.w, cv.y), false); | |
96 adjustLayerArea(); | |
97 m_c = cam->toMapCoordinates(ScreenPoint(cv.x, cv.y+cv.h), false); | |
98 adjustLayerArea(); | |
99 m_c = cam->toMapCoordinates(ScreenPoint(cv.x+cv.w, cv.y+cv.h), false); | |
100 adjustLayerArea(); | |
101 | |
102 Rect r = Rect(); | |
103 for (int x = m_layer_area.x-1; x < m_layer_area.w+1; x++) { | |
104 for (int y = m_layer_area.y-1; y < m_layer_area.h+1; y++) { | |
105 ModelCoordinate mc(x, y); | |
106 m_tmploc.setLayerCoordinates(mc); | |
107 ScreenPoint drawpt = cam->toScreenCoordinates(m_tmploc.getMapCoordinates()); | |
108 if ((drawpt.x >= cv.x) && (drawpt.x <= cv.x + cv.w) && | |
109 (drawpt.y >= cv.y) && (drawpt.y <= cv.y + cv.h)) { | |
110 std::stringstream ss; | |
111 ss << mc.x <<","<< mc.y; | |
112 m_font->setColor(255,255,255); | |
113 Image * img = m_font->getAsImage(ss.str()); | |
114 r.x = drawpt.x; | |
115 r.y = drawpt.y; | |
116 r.w = img->getWidth(); | |
117 r.h = img->getHeight(); | |
118 img->render(r); | |
119 } | |
120 | |
121 } | |
122 } | |
123 } | |
124 } |