1 /*!
2  * \file   MiniMapDrawn.h
3  * \date   13 April 2011
4  * \author StefanP.MUC
5  * \brief  header for the minimap
6  *
7  *  Copyright (C) 2011-2016  OpenDungeons Team
8  *
9  *  This program is free software: you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation, either version 3 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef MINIMAPDRAWN_H_
24 #define MINIMAPDRAWN_H_
25 
26 #include "gamemap/MiniMap.h"
27 
28 #include <OgreHardwarePixelBuffer.h>
29 #include <OgrePixelFormat.h>
30 #include <OgreTexture.h>
31 #include <OgreVector2.h>
32 #include <OgreVector3.h>
33 
34 #include <vector>
35 
36 namespace CEGUI
37 {
38     class Window;
39 }
40 
41 class CameraManager;
42 class GameMap;
43 
44 struct Color
45 {
46 public:
47     Ogre::uint8 RR;
48     Ogre::uint8 GG;
49     Ogre::uint8 BB;
50 
ColorColor51     Color():
52         RR(0),
53         GG(0),
54         BB(0)
55     {}
56 
ColorColor57     Color(Ogre::uint8 rr, Ogre::uint8 gg, Ogre::uint8 bb):
58         RR(rr),
59         GG(gg),
60         BB(bb)
61     {}
62 };
63 
64 //! \brief The class handling the minimap seen top-right of the in-game screen
65 //! FIXME: The pixel are displayed without taking in account the camera current roll value.
66 class MiniMapDrawn : public MiniMap
67 {
68 public:
69     MiniMapDrawn(CEGUI::Window* miniMapWindow);
70     ~MiniMapDrawn();
71 
getWidth()72     Ogre::uint getWidth() const
73     { return mWidth; }
74 
getHeight()75     Ogre::uint getHeight() const
76     { return mHeight; }
77 
78     void update(Ogre::Real timeSinceLastFrame, const std::vector<Ogre::Vector3>& cornerTiles) override;
79 
80     Ogre::Vector2 camera_2dPositionFromClick(int xx, int yy) override;
81 
82 private:
83     CEGUI::Window* mMiniMapWindow;
84 
85     int mTopLeftCornerX;
86     int mTopLeftCornerY;
87     int mGrainSize;
88 
89     Ogre::uint mWidth;
90     Ogre::uint mHeight;
91 
92     Ogre::Vector2 mCamera_2dPosition;
93     double mCosRotation, mSinRotation;
94 
95     //!brief Vector containing colours to be drawn.
96     //NOTE: The tiles are laid out Y,X in the vector to iterate in the right order when drawing.
97     std::vector<Color> mTiles;
98 
99     Ogre::PixelBox mPixelBox;
100     Ogre::TexturePtr mMiniMapOgreTexture;
101     Ogre::HardwarePixelBufferSharedPtr mPixelBuffer;
102 
drawPixel(int xx,int yy,Ogre::uint8 RR,Ogre::uint8 GG,Ogre::uint8 BB)103     inline void drawPixel(int xx, int yy, Ogre::uint8 RR, Ogre::uint8 GG, Ogre::uint8 BB)
104     {
105         for(int gg = 0; gg < mGrainSize; ++gg)
106         {
107             for(int hh = 0; hh < mGrainSize; ++hh)
108             {
109                 mTiles[xx + gg + ((yy + hh) * mWidth)] = Color(RR, GG, BB);
110             }
111         }
112 
113     }
114 
drawPixelToMemory(Ogre::uint8 * & pDest,unsigned char RR,unsigned char GG,unsigned char BB)115     inline void drawPixelToMemory(Ogre::uint8*& pDest, unsigned char RR, unsigned char GG, unsigned char BB)
116     {
117         pDest++; //A, unused, shouldn't be here
118         // this is the order of colors I empirically found outto be working :)
119         *pDest++ = BB;  //B
120         *pDest++ = GG;  //G
121         *pDest++ = RR;  //R
122     }
123 
124     GameMap& mGameMap;
125     CameraManager& mCameraManager;
126 };
127 
128 #endif // MINIMAPDRAWN_H_
129