visual.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 by the FIFE team                              *
00003  *   http://www.fifengine.net                                              *
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 #ifndef FIFE_VIEW_VISUAL_H
00023 #define FIFE_VIEW_VISUAL_H
00024 
00025 // Standard C++ library includes
00026 
00027 // 3rd party library includes
00028 
00029 // FIFE includes
00030 // These includes are split up in two parts, separated by one empty line
00031 // First block: files included from the FIFE root src directory
00032 // Second block: files included from the same folder
00033 #include "model/metamodel/ivisual.h"
00034 #include "util/math/angles.h"
00035 #include "util/structures/rect.h"
00036 #include "video/animation.h"
00037 
00038 
00039 namespace FIFE {
00040     class Object;
00041     class Instance;
00042     class Action;
00043     class Image;
00044     class Camera;
00045 
00051     class Visual2DGfx: public IVisual {
00052     public:
00055         virtual ~Visual2DGfx();
00056 
00060         void setTransparency(uint8_t transparency) { m_transparency = transparency; }
00061 
00065         uint32_t getTransparency() { return m_transparency; }
00066 
00070         void setVisible(bool visible) { m_visible = visible; }
00071 
00075         uint32_t isVisible() { return m_visible; }
00076 
00077     protected:
00080         Visual2DGfx();
00081 
00082         uint8_t m_transparency;
00083         uint8_t m_visible;
00084 
00085     };
00086 
00089     class ObjectVisual: public Visual2DGfx {
00090     public:
00093         static ObjectVisual* create(Object* object);
00094 
00097         virtual ~ObjectVisual();
00098 
00108         void addStaticImage(uint32_t angle, int32_t image_index);
00109 
00113         int32_t getStaticImageIndexByAngle(int32_t angle);
00114 
00118         int32_t getClosestMatchingAngle(int32_t angle);
00119 
00122         void getStaticImageAngles(std::vector<int32_t>& angles);
00123 
00124     private:
00127         ObjectVisual();
00128 
00129         type_angle2id m_angle2img;
00130     };
00131 
00132 
00135     class InstanceVisual: public Visual2DGfx {
00136     public:
00139         static InstanceVisual* create(Instance* instance);
00140 
00143         virtual ~InstanceVisual();
00144 
00150         void setStackPosition(int32_t stackposition) { m_stackposition = stackposition; }
00151 
00155         int32_t getStackPosition() { return m_stackposition; }
00156 
00157     private:
00160         InstanceVisual();
00161         int32_t m_stackposition;
00162     };
00163 
00166     class ActionVisual: public Visual2DGfx {
00167     public:
00170         static ActionVisual* create(Action* action);
00171 
00174         virtual ~ActionVisual();
00175 
00178         void addAnimation(uint32_t angle, AnimationPtr animationptr);
00179 
00183         AnimationPtr getAnimationByAngle(int32_t angle);
00184 
00187         void getActionImageAngles(std::vector<int32_t>& angles);
00188 
00189     private:
00192         ActionVisual();
00193 
00194         // animations associated with this action
00195         typedef std::map<uint32_t, AnimationPtr> AngleAnimationMap;
00196         AngleAnimationMap m_animation_map;
00197 
00198         //@fixme need this map to use the getIndexByAngle() function in angles.h
00199         //should fix this
00200         type_angle2id m_map;
00201     };
00202 
00203 }
00204 #endif