MyGUI  3.2.0
MyGUI_Canvas.h
Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of MyGUI.
00008 
00009     MyGUI is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     MyGUI is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 #ifndef __MYGUI_CANVAS_H__
00023 #define __MYGUI_CANVAS_H__
00024 
00025 #include "MyGUI_Prerequest.h"
00026 #include "MyGUI_Widget.h"
00027 #include "MyGUI_ITexture.h"
00028 
00029 namespace MyGUI
00030 {
00031 
00036     class MYGUI_EXPORT Canvas :
00037         public Widget,
00038         public ITextureInvalidateListener
00039     {
00040         MYGUI_RTTI_DERIVED( Canvas )
00041 
00042     public:
00043         Canvas();
00044 
00045         struct Event
00046         {
00047             Event( bool _textureChanged, bool _widgetResized, bool _requested ) :
00048                 textureChanged( _textureChanged ),
00049                 widgetResized( _widgetResized ),
00050                 requested( _requested )
00051             {
00052             }
00053 
00054             bool textureChanged;
00055             bool widgetResized;
00056 
00058             bool requested;
00059         };
00060 
00061         typedef delegates::CMultiDelegate1<Canvas*> EventHandle_CanvasPtr;
00062         typedef delegates::CDelegate2<Canvas*, Event> EventHandle_CanvasPtrEvent;
00063 
00064         //FIXME
00069         enum TextureResizeMode
00070         {
00071             //
00072             TRM_PT_CONST_SIZE, 
00073             TRM_PT_VIEW_REQUESTED, 
00074             TRM_PT_VIEW_ALL 
00075         };
00076 
00077     public:
00079         void createTexture(TextureResizeMode _resizeMode, TextureUsage _usage = getDefaultTextureUsage(), PixelFormat _format = getDefaultTextureFormat());
00080 
00082         void createTexture(int _width, int _height, TextureResizeMode _resizeMode, TextureUsage _usage = getDefaultTextureUsage(), PixelFormat _format = getDefaultTextureFormat());
00083 
00085         void createTexture(const IntSize& _size, TextureResizeMode _resizeMode, TextureUsage _usage = getDefaultTextureUsage(), PixelFormat _format = getDefaultTextureFormat());
00086 
00088         void destroyTexture();
00089 
00091         void updateTexture();
00092 
00094         void* lock(TextureUsage _usage = TextureUsage::Write);
00095 
00097         void unlock();
00098 
00100         bool isLocked() const;
00101 
00103         int getTextureRealWidth() const;
00104 
00106         int getTextureRealHeight() const;
00107 
00109         IntSize getTextureRealSize() const;
00110 
00112         int getTextureSrcWidth() const;
00113 
00115         int getTextureSrcHeight() const;
00116 
00118         IntSize getTextureSrcSize() const;
00119 
00121         PixelFormat getTextureFormat() const;
00122 
00124         const std::string& getTextureName() const;
00125 
00127         virtual void setSize(const IntSize& _value);
00129         virtual void setCoord(const IntCoord& _value);
00130 
00132         void setSize(int _width, int _height);
00134         void setCoord(int _left, int _top, int _width, int _height);
00135 
00137         TextureResizeMode getResizeMode() const;
00138 
00140         void setResizeMode(TextureResizeMode _value);
00141 
00143         bool isTextureSrcSize() const;
00144 
00146         bool isTextureCreated() const;
00147 
00149         bool isTextureManaged() const;
00150 
00152         ITexture* getTexture() const;
00153 
00155         void setTextureManaged(bool _value);
00156 
00158         static TextureUsage getDefaultTextureUsage();
00159 
00161         static PixelFormat getDefaultTextureFormat();
00162 
00163     /*events:*/
00168         EventHandle_CanvasPtr eventPreTextureChanges;
00169 
00175         EventHandle_CanvasPtrEvent requestUpdateCanvas;
00176 
00177     protected:
00178         virtual void shutdownOverride();
00179         virtual void initialiseOverride();
00180 
00182         void _destroyTexture(bool _sendEvent);
00183 
00185         void validate(int& _width, int& _height, TextureUsage& _usage, PixelFormat& _format) const;
00186 
00188         void createExactTexture(int _width, int _height, TextureUsage _usage, PixelFormat _format);
00189 
00191         bool checkCreate(int _width, int _height) const;
00192 
00194         void resize(const IntSize& _size);
00195 
00197         void correctUV();
00198 
00200         void frameAdvise(bool _advise);
00201 
00203         void frameEntered(float _time);
00204 
00205         virtual void textureInvalidate(ITexture* _texture);
00206 
00207         void _setUVSet(const FloatRect& _rect);
00208 
00209     protected:
00211         ITexture* mTexture;
00212 
00214         IntSize mReqTexSize;
00215 
00217         std::string mGenTexName;
00218 
00220         TextureResizeMode mTexResizeMode;
00221 
00223         uint8* mTexData;
00224 
00226         bool mTexManaged;
00227 
00229         bool mFrameAdvise;
00230 
00231         bool mInvalidateData;
00232     };
00233 
00234 } // namespace MyGUI
00235 
00236 #endif // __MYGUI_CANVAS_H__