MyGUI_Canvas.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_CANVAS_H_
#define MYGUI_CANVAS_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_Widget.h"
#include "MyGUI_ITexture.h"
namespace MyGUI
{
class MYGUI_EXPORT Canvas : public Widget, public ITextureInvalidateListener
{
MYGUI_RTTI_DERIVED(Canvas)
public:
Canvas();
struct Event
{
Event(bool _textureChanged, bool _widgetResized, bool _requested) :
textureChanged(_textureChanged),
widgetResized(_widgetResized),
requested(_requested)
{
}
bool textureChanged;
bool widgetResized;
bool requested;
};
using EventHandle_CanvasPtr = delegates::MultiDelegate<Canvas*>;
using EventHandle_CanvasPtrEvent = delegates::Delegate<Canvas*, Event>;
enum TextureResizeMode
{
// Размер указаный при создании текстуры увеличиваеться до степени двойки и больше не меняется.
// Текстура всегда растягиваеться во весь виджет.
TRM_PT_CONST_SIZE,
// Размер указаный при создании текстуры игнорируется.
// Текстура всегда больше размера окна и кратна степени двойки.
// Если размер виджета становится больше чем размер текстуры, текстура пересоздается.
// Текстура всегда отображатся пиксель в пиксель на виджет, образуя рабочую область текстуры.
TRM_PT_VIEW_REQUESTED,
// Размер указаный при создании текстуры игнорируется.
// Текстура всегда больше размера окна и кратна степени двойки.
// Если размер виджета становится больше чем размер текстуры, текстура пересоздается.
// Текстура всегда растягиваеться во весь виджет.
TRM_PT_VIEW_ALL
};
public:
void createTexture(
TextureResizeMode _resizeMode,
TextureUsage _usage = getDefaultTextureUsage(),
PixelFormat _format = getDefaultTextureFormat());
void createTexture(
int _width,
int _height,
TextureResizeMode _resizeMode,
TextureUsage _usage = getDefaultTextureUsage(),
PixelFormat _format = getDefaultTextureFormat());
void createTexture(
const IntSize& _size,
TextureResizeMode _resizeMode,
TextureUsage _usage = getDefaultTextureUsage(),
PixelFormat _format = getDefaultTextureFormat());
void destroyTexture();
void updateTexture();
void* lock(TextureUsage _usage = TextureUsage::Write);
void unlock();
bool isLocked() const;
int getTextureRealWidth() const;
int getTextureRealHeight() const;
IntSize getTextureRealSize() const;
int getTextureSrcWidth() const;
int getTextureSrcHeight() const;
IntSize getTextureSrcSize() const;
PixelFormat getTextureFormat() const;
const std::string& getTextureName() const;
void setSize(const IntSize& _size) override;
void setCoord(const IntCoord& _coord) override;
using Widget::setPosition;
using Widget::setSize;
using Widget::setCoord;
TextureResizeMode getResizeMode() const;
void setResizeMode(TextureResizeMode _value);
bool isTextureSrcSize() const;
bool isTextureCreated() const;
bool isTextureManaged() const;
ITexture* getTexture() const;
void setTextureManaged(bool _value);
static TextureUsage getDefaultTextureUsage();
static PixelFormat getDefaultTextureFormat();
/*events:*/
EventHandle_CanvasPtr eventPreTextureChanges;
EventHandle_CanvasPtrEvent requestUpdateCanvas;
protected:
void shutdownOverride() override;
void initialiseOverride() override;
void _destroyTexture(bool _sendEvent);
void validate(int& _width, int& _height, TextureUsage& _usage, PixelFormat& _format) const;
void createExactTexture(int _width, int _height, TextureUsage _usage, PixelFormat _format);
bool checkCreate(int _width, int _height) const;
void resize(const IntSize& _size);
void correctUV();
void frameAdvise(bool _advise);
void frameEntered(float _time);
void textureInvalidate(ITexture* _texture) override;
void _setUVSet(const FloatRect& _rect);
protected:
ITexture* mTexture{nullptr};
IntSize mReqTexSize;
std::string mGenTexName;
TextureResizeMode mTexResizeMode{TRM_PT_CONST_SIZE};
uint8* mTexData{nullptr};
bool mTexManaged{true};
bool mFrameAdvise{false};
bool mInvalidateData{false};
};
} // namespace MyGUI
#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