MyGUI 3.0.1
|
00001 00007 /* 00008 This file is part of MyGUI. 00009 00010 MyGUI is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 MyGUI is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 #ifndef __MYGUI_CANVAS_H__ 00024 #define __MYGUI_CANVAS_H__ 00025 00026 #include "MyGUI_Prerequest.h" 00027 #include "MyGUI_Widget.h" 00028 #include "MyGUI_ITexture.h" 00029 00030 namespace MyGUI 00031 { 00032 00037 class MYGUI_EXPORT Canvas : 00038 public Widget, 00039 public ITextureInvalidateListener 00040 { 00041 MYGUI_RTTI_DERIVED( Canvas ) 00042 00043 public: 00044 Canvas(); 00045 00046 struct Event 00047 { 00048 Event( bool _textureChanged, bool _widgetResized, bool _requested ) : 00049 textureChanged( _textureChanged ), 00050 widgetResized( _widgetResized ), 00051 requested( _requested ) 00052 { 00053 } 00054 00055 bool textureChanged; 00056 bool widgetResized; 00057 00059 bool requested; 00060 }; 00061 00062 typedef delegates::CDelegate1<Canvas*> EventInfo_Canvas; 00063 typedef delegates::CDelegate2<Canvas*, Event> EventInfo_CanvasEvent; 00064 00065 //FIXME 00070 enum TextureResizeMode 00071 { 00072 // 00073 TRM_PT_CONST_SIZE, 00074 TRM_PT_VIEW_REQUESTED, 00075 TRM_PT_VIEW_ALL 00076 }; 00077 00078 public: 00079 00081 void createTexture( TextureResizeMode _resizeMode, TextureUsage _usage = getDefaultTextureUsage(), PixelFormat _format = getDefaultTextureFormat() ); 00082 00084 void createTexture( int _width, int _height, TextureResizeMode _resizeMode, TextureUsage _usage = getDefaultTextureUsage(), PixelFormat _format = getDefaultTextureFormat() ); 00085 00087 void createTexture( const IntSize& _size, TextureResizeMode _resizeMode, TextureUsage _usage = getDefaultTextureUsage(), PixelFormat _format = getDefaultTextureFormat() ); 00088 00090 void destroyTexture(); 00091 00093 void updateTexture(); 00094 00096 void* lock(TextureUsage _usage = TextureUsage::Write); 00097 00099 void unlock(); 00100 00102 bool isLocked() const { return mTexture->isLocked(); } 00103 00105 int getTextureRealWidth() const { return (int) mTexture->getWidth(); } 00106 00108 int getTextureRealHeight() const { return (int) mTexture->getHeight(); } 00109 00111 IntSize getTextureRealSize() const { return IntSize( getTextureRealWidth(), getTextureRealHeight() ); } 00112 00114 int getTextureSrcWidth() const { return mReqTexSize.width; } 00115 00117 int getTextureSrcHeight() const { return mReqTexSize.height; } 00118 00120 IntSize getTextureSrcSize() const { return mReqTexSize; } 00121 00123 PixelFormat getTextureFormat() const { return mTexture->getFormat(); } 00124 00126 const std::string& getTextureName() const { return mTexture->getName(); } 00127 00129 virtual void setSize(const IntSize& _value); 00131 virtual void setCoord(const IntCoord& _value); 00132 00134 void setSize(int _width, int _height) { setSize(IntSize(_width, _height)); } 00136 void setCoord(int _left, int _top, int _width, int _height) { setCoord(IntCoord(_left, _top, _width, _height)); } 00137 00139 TextureResizeMode getResizeMode() const { return mTexResizeMode; } 00140 00142 void setResizeMode( TextureResizeMode _set ) { mTexResizeMode = _set; } 00143 00145 bool isTextureSrcSize() const; 00146 00148 bool isTextureCreated() const { return mTexture != nullptr; } 00149 00151 bool isTextureManaged() const { return mTexManaged; } 00152 00154 ITexture* getTexture() { return mTexture; } 00155 00157 void setTextureManaged( bool _value ) { mTexManaged = _value; } 00158 00160 static TextureUsage getDefaultTextureUsage() { return TextureUsage::Stream | TextureUsage::Write; } 00161 00163 static PixelFormat getDefaultTextureFormat() { return PixelFormat::R8G8B8A8; } 00164 00165 /*event:*/ 00170 EventInfo_Canvas eventPreTextureChanges; 00171 00177 EventInfo_CanvasEvent requestUpdateCanvas; 00178 00179 /*internal:*/ 00180 virtual void _initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name); 00181 00182 protected: 00183 virtual ~Canvas(); 00184 00186 void _destroyTexture( bool _sendEvent ); 00187 00189 void validate( int& _width, int& _height, TextureUsage& _usage, PixelFormat& _format ) const; 00190 00192 void createExactTexture( int _width, int _height, TextureUsage _usage, PixelFormat _format ); 00193 00195 bool checkCreate( int _width, int _height ) const; 00196 00198 void resize( const IntSize& _size ); 00199 00201 void correctUV(); 00202 00204 void baseChangeWidgetSkin( ResourceSkin* _info ); 00205 00207 void initialiseWidgetSkin( ResourceSkin* _info ); 00208 00210 void shutdownWidgetSkin(); 00211 00213 void frameAdvise( bool _advise ); 00214 00216 void frameEntered( float _time ); 00217 00218 virtual void textureInvalidate(ITexture* _texture); 00219 00220 protected: 00222 ITexture* mTexture; 00223 00225 IntSize mReqTexSize; 00226 00228 std::string mGenTexName; 00229 00231 TextureResizeMode mTexResizeMode; 00232 00234 uint8* mTexData; 00235 00237 bool mTexManaged; 00238 00240 bool mFrameAdvise; 00241 00242 }; 00243 00244 } // namespace MyGUI 00245 00246 #endif // __MYGUI_CANVAS_H__