MyGUI: MyGUI_Canvas.h Source File

MyGUI 3.4.3

MyGUI_Canvas.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_CANVAS_H_
8#define MYGUI_CANVAS_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Widget.h"
12#include "MyGUI_ITexture.h"
13
14namespace MyGUI
15{
16
21 class MYGUI_EXPORT Canvas : public Widget, public ITextureInvalidateListener
22 {
23 MYGUI_RTTI_DERIVED(Canvas)
24
25 public:
26 Canvas();
27
28 struct Event
29 {
30 Event(bool _textureChanged, bool _widgetResized, bool _requested) :
31 textureChanged(_textureChanged),
32 widgetResized(_widgetResized),
33 requested(_requested)
34 {
35 }
36
37 bool textureChanged;
38 bool widgetResized;
39
41 bool requested;
42 };
43
44 using EventHandle_CanvasPtr = delegates::MultiDelegate<Canvas*>;
45 using EventHandle_CanvasPtrEvent = delegates::Delegate<Canvas*, Event>;
46
51 enum TextureResizeMode
52 {
57 // Размер указаный при создании текстуры увеличиваеться до степени двойки и больше не меняется.
58 // Текстура всегда растягиваеться во весь виджет.
59 TRM_PT_CONST_SIZE,
60
69 // Размер указаный при создании текстуры игнорируется.
70 // Текстура всегда больше размера окна и кратна степени двойки.
71 // Если размер виджета становится больше чем размер текстуры, текстура пересоздается.
72 // Текстура всегда отображатся пиксель в пиксель на виджет, образуя рабочую область текстуры.
73 TRM_PT_VIEW_REQUESTED,
74
82 // Размер указаный при создании текстуры игнорируется.
83 // Текстура всегда больше размера окна и кратна степени двойки.
84 // Если размер виджета становится больше чем размер текстуры, текстура пересоздается.
85 // Текстура всегда растягиваеться во весь виджет.
86 TRM_PT_VIEW_ALL
87 };
88
89 public:
91 void createTexture(
92 TextureResizeMode _resizeMode,
93 TextureUsage _usage = getDefaultTextureUsage(),
94 PixelFormat _format = getDefaultTextureFormat());
95
97 void createTexture(
98 int _width,
99 int _height,
100 TextureResizeMode _resizeMode,
101 TextureUsage _usage = getDefaultTextureUsage(),
102 PixelFormat _format = getDefaultTextureFormat());
103
105 void createTexture(
106 const IntSize& _size,
107 TextureResizeMode _resizeMode,
108 TextureUsage _usage = getDefaultTextureUsage(),
109 PixelFormat _format = getDefaultTextureFormat());
110
112 void destroyTexture();
113
115 void updateTexture();
116
118 void* lock(TextureUsage _usage = TextureUsage::Write);
119
121 void unlock();
122
124 bool isLocked() const;
125
127 int getTextureRealWidth() const;
128
130 int getTextureRealHeight() const;
131
133 IntSize getTextureRealSize() const;
134
136 int getTextureSrcWidth() const;
137
139 int getTextureSrcHeight() const;
140
142 IntSize getTextureSrcSize() const;
143
145 PixelFormat getTextureFormat() const;
146
148 const std::string& getTextureName() const;
149
151 void setSize(const IntSize& _size) override;
153 void setCoord(const IntCoord& _coord) override;
154
155 using Widget::setPosition;
156 using Widget::setSize;
157 using Widget::setCoord;
158
160 TextureResizeMode getResizeMode() const;
161
163 void setResizeMode(TextureResizeMode _value);
164
166 bool isTextureSrcSize() const;
167
169 bool isTextureCreated() const;
170
172 bool isTextureManaged() const;
173
175 ITexture* getTexture() const;
176
178 void setTextureManaged(bool _value);
179
181 static TextureUsage getDefaultTextureUsage();
182
184 static PixelFormat getDefaultTextureFormat();
185
186 /*events:*/
191 EventHandle_CanvasPtr eventPreTextureChanges;
192
198 EventHandle_CanvasPtrEvent requestUpdateCanvas;
199
200 protected:
201 void shutdownOverride() override;
202 void initialiseOverride() override;
203
205 void _destroyTexture(bool _sendEvent);
206
208 void validate(int& _width, int& _height, TextureUsage& _usage, PixelFormat& _format) const;
209
211 void createExactTexture(int _width, int _height, TextureUsage _usage, PixelFormat _format);
212
214 bool checkCreate(int _width, int _height) const;
215
217 void resize(const IntSize& _size);
218
220 void correctUV();
221
223 void frameAdvise(bool _advise);
224
226 void frameEntered(float _time);
227
228 void textureInvalidate(ITexture* _texture) override;
229
230 void _setUVSet(const FloatRect& _rect);
231
232 protected:
234 ITexture* mTexture{nullptr};
235
237 IntSize mReqTexSize;
238
240 std::string mGenTexName;
241
243 TextureResizeMode mTexResizeMode{TRM_PT_CONST_SIZE};
244
246 uint8* mTexData{nullptr};
247
249 bool mTexManaged{true};
250
252 bool mFrameAdvise{false};
253
254 bool mInvalidateData{false};
255 };
256
257} // namespace MyGUI
258
259#endif // MYGUI_CANVAS_H_
MyGUI_ITexture.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:69
MyGUI_Widget.h
MyGUI::Canvas::mReqTexSize
IntSize mReqTexSize
Requested bu user sizes.
Definition MyGUI_Canvas.h:237
MyGUI::Canvas::frameAdvise
void frameAdvise(bool _advise)
For updating once per frame.
Definition MyGUI_Canvas.cpp:215
MyGUI::Canvas::correctUV
void correctUV()
Correct texture uv-coordinates.
Definition MyGUI_Canvas.cpp:179
MyGUI::Canvas::frameEntered
void frameEntered(float _time)
For updating once per frame.
Definition MyGUI_Canvas.cpp:235
MyGUI::Canvas::createExactTexture
void createExactTexture(int _width, int _height, TextureUsage _usage, PixelFormat _format)
Creates the texture itself.
Definition MyGUI_Canvas.cpp:42
MyGUI::Canvas::mFrameAdvise
bool mFrameAdvise
For updating once per frame. True state means updating before next frame starts.
Definition MyGUI_Canvas.h:252
MyGUI::Canvas::requestUpdateCanvas
EventHandle_CanvasPtrEvent requestUpdateCanvas
Definition MyGUI_Canvas.h:198
MyGUI::Canvas::mTexManaged
bool mTexManaged
true if we own the texture (can delete it or replace by another instance), otherwise false
Definition MyGUI_Canvas.h:249
MyGUI::Canvas::EventHandle_CanvasPtr
delegates::MultiDelegate< Canvas * > EventHandle_CanvasPtr
Definition MyGUI_Canvas.h:44
MyGUI::Canvas::initialiseOverride
void initialiseOverride() override
Definition MyGUI_Canvas.cpp:161
MyGUI::Canvas::mTexResizeMode
TextureResizeMode mTexResizeMode
Texture resize mode.
Definition MyGUI_Canvas.h:243
MyGUI::Canvas::resize
void resize(const IntSize &_size)
Calls when resize widget.
Definition MyGUI_Canvas.cpp:60
MyGUI::Canvas::_setUVSet
void _setUVSet(const FloatRect &_rect)
Definition MyGUI_Canvas.cpp:269
MyGUI::Canvas::_destroyTexture
void _destroyTexture(bool _sendEvent)
Destroys texture.
Definition MyGUI_Canvas.cpp:165
MyGUI::Canvas::Canvas
Canvas()
Definition MyGUI_Canvas.cpp:17
MyGUI::Canvas::textureInvalidate
void textureInvalidate(ITexture *_texture) override
Definition MyGUI_Canvas.cpp:264
MyGUI::Canvas::mTexData
uint8 * mTexData
Saved pointer from last calling lock.
Definition MyGUI_Canvas.h:246
MyGUI::Canvas::shutdownOverride
void shutdownOverride() override
Definition MyGUI_Canvas.cpp:155
MyGUI::Canvas::mInvalidateData
bool mInvalidateData
Definition MyGUI_Canvas.h:254
MyGUI::Canvas::mTexture
ITexture * mTexture
Current texture.
Definition MyGUI_Canvas.h:234
MyGUI::Canvas::eventPreTextureChanges
EventHandle_CanvasPtr eventPreTextureChanges
Definition MyGUI_Canvas.h:191
MyGUI::Canvas::validate
void validate(int &_width, int &_height, TextureUsage &_usage, PixelFormat &_format) const
Update entered parameters according to current texture resize mode(size) and restore (if can) paramet...
Definition MyGUI_Canvas.cpp:131
MyGUI::Canvas::TextureResizeMode
TextureResizeMode
Definition MyGUI_Canvas.h:52
MyGUI::Canvas::TRM_PT_VIEW_ALL
@ TRM_PT_VIEW_ALL
Definition MyGUI_Canvas.h:86
MyGUI::Canvas::TRM_PT_VIEW_REQUESTED
@ TRM_PT_VIEW_REQUESTED
Definition MyGUI_Canvas.h:73
MyGUI::Canvas::TRM_PT_CONST_SIZE
@ TRM_PT_CONST_SIZE
Definition MyGUI_Canvas.h:59
MyGUI::Canvas::mGenTexName
std::string mGenTexName
Generated texture name.
Definition MyGUI_Canvas.h:240
MyGUI::Canvas::checkCreate
bool checkCreate(int _width, int _height) const
Checks if we need to create a texture with such sizes.
Definition MyGUI_Canvas.cpp:120
MyGUI::Canvas::EventHandle_CanvasPtrEvent
delegates::Delegate< Canvas *, Event > EventHandle_CanvasPtrEvent
Definition MyGUI_Canvas.h:45
MyGUI::ITexture
Definition MyGUI_ITexture.h:28
MyGUI::ITextureInvalidateListener
Definition MyGUI_ITexture.h:20
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_Widget.cpp:693
MyGUI::Widget::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_Widget.cpp:676
MyGUI::Widget::setCoord
void setCoord(const IntCoord &_coord) override
Definition MyGUI_Widget.cpp:730
MyGUI::delegates::Delegate
Definition MyGUI_Delegate.h:158
MyGUI::delegates::MultiDelegate
Definition MyGUI_Delegate.h:190
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::uint8
uint8_t uint8
Definition MyGUI_Types.h:46
MyGUI::FloatRect
types::TRect< float > FloatRect
Definition MyGUI_Types.h:34
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::Canvas::Event::Event
Event(bool _textureChanged, bool _widgetResized, bool _requested)
Definition MyGUI_Canvas.h:30
MyGUI::Canvas::Event::widgetResized
bool widgetResized
Definition MyGUI_Canvas.h:38
MyGUI::Canvas::Event::textureChanged
bool textureChanged
Definition MyGUI_Canvas.h:37
MyGUI::Canvas::Event::requested
bool requested
This update was caused by calling updateTexture();.
Definition MyGUI_Canvas.h:41
MyGUI::PixelFormat
Definition MyGUI_RenderFormat.h:50
MyGUI::TextureUsage
Definition MyGUI_RenderFormat.h:98
MyGUI::TextureUsage::Write
@ Write
Definition MyGUI_RenderFormat.h:106