lugre_texatlas.h

Go to the documentation of this file.
00001 /*
00002 http://www.opensource.org/licenses/mit-license.php  (MIT-License)
00003 
00004 Copyright (c) 2007 Lugre-Team
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a copy
00007 of this software and associated documentation files (the "Software"), to deal
00008 in the Software without restriction, including without limitation the rights
00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022 THE SOFTWARE.
00023 */
00024 #ifndef LUGRE_TEXATLAS_H
00025 #define LUGRE_TEXATLAS_H
00026 
00027 #include "lugre_smartptr.h"
00028 #include <Ogre.h>
00029 #include <vector>
00030 #include <list>
00031         
00032 class lua_State;
00033     
00034 namespace Lugre {
00035 
00037 class cTexAtlas : public cSmartPointable { public:
00038     
00041     cTexAtlas   (const int iW, const int iH, const int iMaxSubW = -1, const int iMaxSubH = -1);
00042     
00046     bool                AddImage    (Ogre::Image& pSrc,Ogre::Rectangle& pOutTexCoords,const int iBorderPixels=4,const bool bWrap=true);
00047     
00049     Ogre::TexturePtr    MakeTexture (const Ogre::String &name, const Ogre::String &group=Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00050     
00052     void                MakeImage   (Ogre::Image& pDest);
00053     
00054     // lua binding
00055     static void     LuaRegister     (lua_State *L);
00056     
00057     // internal
00058     private:
00059         
00060     void    MarkAsFreeSpace(const int x,const int y,const int w,const int h);
00061         
00062     void    FillRect(const int x, const int y, const int w, const int h, const float r, const float g, const float b, const float a);
00063     
00064     // freespace data
00065     struct cFreeSpaceCell { int x,y,w,h; cFreeSpaceCell() {} cFreeSpaceCell(const int x,const int y,const int w,const int h) : x(x),y(y),w(w),h(h) {} };
00066     std::list<cFreeSpaceCell> mlFreeSpace;
00067     
00071     bool            RequestArea         (const int w,const int h,int& l,int& r,int& t,int& b);
00072     
00073     // texatlas data
00074     inline void*    GetPixelPointer     (const int x,const int y) { return (void*)&mData[y*miW+x]; }
00075     inline void*    GetBasePointer      () { return (void*)&mData[0]; }
00076     inline int      GetBufferSize       () { return mData.size()*sizeof(Ogre::uint32); } 
00077     std::vector<Ogre::uint32> mData;
00078     Ogre::PixelFormat miFormat;
00079     const int   miW;
00080     const int   miH;
00081     const int   miMaxSubW;
00082     const int   miMaxSubH;
00083     
00084     const int   miMinFreeSpaceSize;
00085     
00086     int miCurrentLineH;
00087     int miBrushX;
00088     int miBrushY;
00089 };
00090 
00091 };
00092 
00093 #endif

Generated on Wed May 23 06:00:13 2012 for cpp by  doxygen 1.5.6