blockinginforenderer.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 // Standard C++ library includes
00023 
00024 // 3rd party library includes
00025 
00026 // FIFE includes
00027 // These includes are split up in two parts, separated by one empty line
00028 // First block: files included from the FIFE root src directory
00029 // Second block: files included from the same folder
00030 #include "video/renderbackend.h"
00031 #include "util/math/fife_math.h"
00032 #include "util/log/logger.h"
00033 #include "model/metamodel/grids/cellgrid.h"
00034 #include "model/structures/instance.h"
00035 #include "model/structures/layer.h"
00036 #include "model/structures/location.h"
00037 
00038 #include "view/camera.h"
00039 #include "blockinginforenderer.h"
00040 
00041 
00042 namespace FIFE {
00043     static Logger _log(LM_VIEWVIEW);
00044 
00045     BlockingInfoRenderer::BlockingInfoRenderer(RenderBackend* renderbackend, int position):
00046         RendererBase(renderbackend, position) {
00047         setEnabled(false);
00048     }
00049 
00050     BlockingInfoRenderer::BlockingInfoRenderer(const BlockingInfoRenderer& old):
00051         RendererBase(old) {
00052     }
00053 
00054     RendererBase* BlockingInfoRenderer::clone() {
00055         return new BlockingInfoRenderer(*this);
00056     }
00057 
00058     BlockingInfoRenderer::~BlockingInfoRenderer() {
00059     }
00060 
00061     void BlockingInfoRenderer::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances) {
00062         CellGrid* cg = layer->getCellGrid();
00063         if (!cg) {
00064             FL_WARN(_log, "No cellgrid assigned to layer, cannot draw grid");
00065             return;
00066         }
00067         
00068         Rect cv = cam->getViewPort();
00069         std::vector<Instance*>::const_iterator instance_it = instances.begin();
00070         for (;instance_it != instances.end(); ++instance_it) {
00071             Instance* instance = *instance_it;
00072             if (!instance->getObject()->isBlocking()) {
00073                 continue;
00074             }
00075             std::vector<ExactModelCoordinate> vertices;
00076             cg->getVertices(vertices, instance->getLocationRef().getLayerCoordinates());
00077             int halfind = vertices.size() / 2;
00078             ScreenPoint spt1 = cam->toScreenCoordinates(cg->toMapCoordinates(vertices[0]));
00079             Point pt1(spt1.x, spt1.y);
00080             ScreenPoint spt2 = cam->toScreenCoordinates(cg->toMapCoordinates(vertices[halfind]));
00081             Point pt2(spt2.x, spt2.y);
00082             m_renderbackend->drawLine(pt1, pt2, 0, 255, 0);
00083         }
00084     }
00085 }