visual.h

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 #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/abstractvisual.h"
00034 #include "view/camera.h"
00035 
00036 namespace FIFE {
00037     class Object;
00038     class Instance;
00039     class Action;
00040     class Image;
00041 
00047     class Visual2DGfx: public AbstractVisual {
00048     public:
00051         virtual ~Visual2DGfx();
00052 
00056         void setTransparency(uint8_t transparency) { m_transparency = transparency; }
00057 
00061         unsigned int getTransparency() { return m_transparency; }
00062 
00066         void setVisible(bool visible) { m_visible = visible; }
00067 
00071         unsigned int isVisible() { return m_visible; }
00072 
00073     protected:
00076         Visual2DGfx();
00077 
00078         uint8_t m_transparency;
00079         uint8_t m_visible;
00080 
00081     };
00082 
00085     class ObjectVisual: public Visual2DGfx {
00086     public:
00089         static ObjectVisual* create(Object* object);
00090 
00093         virtual ~ObjectVisual();
00094 
00104         void addStaticImage(unsigned int angle, int image_index);
00105 
00109         int getStaticImageIndexByAngle(int angle);
00110 
00114         int getClosestMatchingAngle(int angle);
00115 
00118         void getStaticImageAngles(std::vector<int>& angles);
00119 
00120     private:
00123         ObjectVisual();
00124 
00125         type_angle2id m_angle2img;
00126     };
00127 
00132     class InstanceVisualCacheItem {
00133     public:
00134         InstanceVisualCacheItem();
00135 
00140         int getStaticImageIndexByAngle(unsigned int angle, Instance* instance);
00141 
00142         // point where instance was drawn during the previous render
00143         ScreenPoint screenpoint;
00144 
00145         // dimensions of this visual during the previous render
00146         Rect dimensions;
00147 
00148         // image used during previous render
00149         Image* image;
00150 
00151         // current facing angle
00152         int facing_angle;
00153     private:
00154         int m_cached_static_img_id;
00155         int m_cached_static_img_angle;
00156     };
00157 
00160     class InstanceVisual: public Visual2DGfx {
00161     public:
00164         static InstanceVisual* create(Instance* instance);
00165 
00168         virtual ~InstanceVisual();
00169 
00175         void setStackPosition(int stackposition) { m_stackposition = stackposition; }
00176 
00180         int getStackPosition() { return m_stackposition; }
00181 
00185         inline InstanceVisualCacheItem& getCacheItem(Camera* cam) { return m_cache[cam]; }
00186 
00187     private:
00190         InstanceVisual();
00191         int m_stackposition;
00192         // there is separate cache item for each camera
00193         std::map<Camera*, InstanceVisualCacheItem> m_cache;
00194     };
00195 
00198     class ActionVisual: public Visual2DGfx {
00199     public:
00202         static ActionVisual* create(Action* action);
00203 
00206         virtual ~ActionVisual();
00207 
00210         void addAnimation(unsigned int angle, int animation_index);
00211 
00215         int getAnimationIndexByAngle(int angle);
00216 
00219         void getActionImageAngles(std::vector<int>& angles);
00220 
00221     private:
00224         ActionVisual();
00225 
00226         // animations associated with this action (handles to pool)
00227         //   mapping = direction -> animation
00228         type_angle2id m_animations;
00229     };
00230 
00231 }
00232 #endif
Generated by  doxygen 1.6.2-20100208