.. index:: pair: class; EE::Graphics::TextureRegion .. _doxid-class_e_e_1_1_graphics_1_1_texture_region: class EE::Graphics::TextureRegion ================================= .. toctree:: :hidden: Overview ~~~~~~~~ A :ref:`TextureRegion ` is a part of a texture that represent an sprite. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class TextureRegion: public :ref:`EE::Graphics::DrawableResource` { public: // construction :ref:`TextureRegion`(); :ref:`TextureRegion`(:ref:`Texture`* tex, const std::string& name = ""); :ref:`TextureRegion`(:ref:`Texture`* tex, const :ref:`Rect`& srcRect, const std::string& name = ""); :ref:`TextureRegion`(:ref:`Texture`* tex, const :ref:`Rect`& srcRect, const :ref:`Sizef`& destSize, const std::string& name = ""); :ref:`TextureRegion`(:ref:`Texture`* tex, const :ref:`Rect`& srcRect, const :ref:`Sizef`& destSize, const :ref:`Vector2i`& offset, const std::string& name = ""); virtual :target:`~TextureRegion`(); // methods static TextureRegion* :target:`New`(); static TextureRegion* :target:`New`(const :ref:`Uint32`& TexId, const std::string& name = ""); static TextureRegion* :target:`New`(const :ref:`Uint32`& TexId, const :ref:`Rect`& srcRect, const std::string& name = ""); static TextureRegion* :target:`New`(const :ref:`Uint32`& TexId, const :ref:`Rect`& srcRect, const :ref:`Sizef`& destSize, const std::string& name = ""); static TextureRegion* :target:`New`(const :ref:`Uint32`& TexId, const :ref:`Rect`& srcRect, const :ref:`Sizef`& destSize, const :ref:`Vector2i`& offset, const std::string& name = ""); static TextureRegion* :target:`New`(:ref:`Texture`* tex, const std::string& name = ""); static TextureRegion* :target:`New`(:ref:`Texture`* tex, const :ref:`Rect`& srcRect, const std::string& name = ""); static TextureRegion* :target:`New`(:ref:`Texture`* tex, const :ref:`Rect`& srcRect, const :ref:`Sizef`& destSize, const std::string& name = ""); static TextureRegion* :target:`New`(:ref:`Texture`* tex, const :ref:`Rect`& srcRect, const :ref:`Sizef`& destSize, const :ref:`Vector2i`& offset, const std::string& name = ""); void :ref:`setTextureId`(const :ref:`Uint32`& TexId); void :ref:`setTexture`(:ref:`Texture`* texture); const :ref:`Rect`& :ref:`getSrcRect`() const; void :ref:`setSrcRect`(const :ref:`Rect`& rect); const :ref:`Sizef`& :ref:`getDestSize`() const; void :ref:`setDestSize`(const :ref:`Sizef`& destSize); const :ref:`Vector2i`& :ref:`getOffset`() const; void :ref:`setOffset`(const :ref:`Vector2i`& offset); void :target:`draw`( const :ref:`Float`& X, const :ref:`Float`& Y, const :ref:`Color`& color = Color::White, const :ref:`Float`& Angle = 0.f, const :ref:`Vector2f`& Scale = Vector2f::One, const :ref:`BlendMode`& Blend = :ref:`BlendMode::Alpha`(), const :ref:`RenderMode`& Effect = :ref:`RENDER_NORMAL`, :ref:`OriginPoint` Center = :ref:`OriginPoint`(OriginPoint::OriginCenter) ); void :target:`draw`( const :ref:`Float`& X, const :ref:`Float`& Y, const :ref:`Float`& Angle, const :ref:`Vector2f`& Scale, const :ref:`Color`& Color0 = Color::White, const :ref:`Color`& Color1 = Color::White, const :ref:`Color`& Color2 = Color::White, const :ref:`Color`& Color3 = Color::White, const :ref:`BlendMode`& Blend = :ref:`BlendMode::Alpha`(), const :ref:`RenderMode`& Effect = :ref:`RENDER_NORMAL`, :ref:`OriginPoint` Center = :ref:`OriginPoint`(OriginPoint::OriginCenter) ); void :target:`draw`( const :ref:`Quad2f` Q, const :ref:`Vector2f`& offset = :ref:`Vector2f`(), const :ref:`Float`& Angle = 0.f, const :ref:`Vector2f`& Scale = Vector2f::One, const :ref:`Color`& Color0 = Color::White, const :ref:`Color`& Color1 = Color::White, const :ref:`Color`& Color2 = Color::White, const :ref:`Color`& Color3 = Color::White, const :ref:`BlendMode`& Blend = :ref:`BlendMode::Alpha`() ); virtual void :target:`draw`(); virtual void :target:`draw`(const :ref:`Vector2f`& position); virtual void :target:`draw`(const :ref:`Vector2f`& position, const :ref:`Sizef`& size); virtual bool :target:`isStateful`(); :ref:`Graphics::Texture`* :ref:`getTexture`(); void :ref:`replaceColor`(:ref:`Color` ColorKey, :ref:`Color` NewColor); void :ref:`createMaskFromColor`(:ref:`Color` ColorKey, :ref:`Uint8` Alpha); void :ref:`createMaskFromColor`(:ref:`RGB` ColorKey, :ref:`Uint8` Alpha); void :ref:`cacheAlphaMask`(); void :ref:`cacheColors`(); :ref:`Uint8` :ref:`getAlphaAt`(const :ref:`Int32`& X, const :ref:`Int32`& Y); :ref:`Color` :ref:`getColorAt`(const :ref:`Int32`& X, const :ref:`Int32`& Y); void :ref:`setColorAt`(const :ref:`Int32`& X, const :ref:`Int32`& Y, const :ref:`Color`& Color); void :ref:`clearCache`(); :ref:`Uint8`* :ref:`lock`(); bool :ref:`unlock`(const bool& KeepData = false, const bool& Modified = false); :ref:`Sizei` :ref:`getRealSize`(); virtual :ref:`Sizef` :ref:`getSize`(); const :ref:`Uint8`* :ref:`getPixelsPtr`(); bool :ref:`saveToFile`(const std::string& filepath, const :ref:`Image::SaveType`& Format, const :ref:`Image::FormatConfiguration`& imageFormatConfiguration = :ref:`Image::FormatConfiguration`()); void :ref:`resetDestSize`(); :ref:`Float` :target:`getPixelDensity`() const; void :target:`setPixelDensity`(const :ref:`Float`& pixelDensity); :ref:`Sizei` :target:`getDpSize`(); virtual :ref:`Sizef` :target:`getPixelsSize`(); :ref:`Sizef` :target:`getOriDestSize`() const; void :target:`setOriDestSize`(const :ref:`Sizef`& oriDestSize); }; Inherited Members ----------------- .. ref-code-block:: cpp :class: doxyrest-overview-inherited-code-block public: // typedefs typedef std::function`, :ref:`Event`, :ref:`DrawableResource`*)> :ref:`OnResourceChangeCallback`; // enums enum :ref:`Type`; enum :ref:`Event`; // methods virtual :ref:`Sizef` :ref:`getSize`() = 0; virtual :ref:`Sizef` :ref:`getPixelsSize`() = 0; virtual void :ref:`draw`() = 0; virtual void :ref:`draw`(const :ref:`Vector2f`& position) = 0; virtual void :ref:`draw`(const :ref:`Vector2f`& position, const :ref:`Sizef`& size) = 0; virtual bool :ref:`isStateful`() = 0; void :ref:`setAlpha`(:ref:`Uint8` alpha); const :ref:`Uint8`& :ref:`getAlpha`(); void :ref:`setColor`(const :ref:`Color`& color); const :ref:`Color`& :ref:`getColor`() const; void :ref:`setColorFilter`(const :ref:`Color`& color); :ref:`RGB` :ref:`getColorFilter`(); void :ref:`clearColor`(); void :ref:`clearColorFilter`(); void :ref:`resetAlpha`(); :ref:`Type` :ref:`getDrawableType`() const; const :ref:`Vector2f`& :ref:`getPosition`() const; void :ref:`setPosition`(const :ref:`Vector2f`& position); virtual bool :ref:`isDrawableResource`() const; const :ref:`String::HashType`& :ref:`getId`() const; const std::string :ref:`getName`() const; void :ref:`setName`(const std::string& name); virtual bool :ref:`isDrawableResource`() const; :ref:`Uint32` :ref:`pushResourceChangeCallback`(const :ref:`OnResourceChangeCallback`& cb); bool :ref:`popResourceChangeCallback`(const :ref:`Uint32`& callbackId); .. _details-class_e_e_1_1_graphics_1_1_texture_region: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ A :ref:`TextureRegion ` is a part of a texture that represent an sprite. Construction ------------ .. index:: pair: function; TextureRegion .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a601efdd77873789edbd476b40c081232: .. ref-code-block:: cpp :class: doxyrest-title-code-block TextureRegion() Creates an empty :ref:`TextureRegion ` .. index:: pair: function; TextureRegion .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1aa6a67d4969b63fac9302d13049873769: .. ref-code-block:: cpp :class: doxyrest-title-code-block TextureRegion(:ref:`Texture`* tex, const std::string& name = "") Creates a :ref:`TextureRegion ` from a :ref:`Texture `. It will use the full :ref:`Texture ` as a :ref:`TextureRegion `. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - tex - The texture * - name - The texture name ( if any ) .. index:: pair: function; TextureRegion .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a1d9a6b89b97e1b14a7befb708c9529ad: .. ref-code-block:: cpp :class: doxyrest-title-code-block TextureRegion(:ref:`Texture`* tex, const :ref:`Rect`& srcRect, const std::string& name = "") Creates a :ref:`TextureRegion ` of the indicated part of the texture. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - tex - The texture * - srcRect - The texture part that will be used as the :ref:`TextureRegion `. * - name - The texture name ( if any ) .. index:: pair: function; TextureRegion .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a60800b88b5673b0efa388fe0e76ed354: .. ref-code-block:: cpp :class: doxyrest-title-code-block TextureRegion(:ref:`Texture`* tex, const :ref:`Rect`& srcRect, const :ref:`Sizef`& destSize, const std::string& name = "") Creates a :ref:`TextureRegion ` of the indicated part of the texture. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - tex - The texture * - srcRect - The texture part that will be used as the :ref:`TextureRegion `. * - destSize - The destination size that the :ref:`TextureRegion ` will have when rendered. * - name - The texture name ( if any ) .. index:: pair: function; TextureRegion .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a367d547bc20aa78bd53f5ff82c17d687: .. ref-code-block:: cpp :class: doxyrest-title-code-block TextureRegion(:ref:`Texture`* tex, const :ref:`Rect`& srcRect, const :ref:`Sizef`& destSize, const :ref:`Vector2i`& offset, const std::string& name = "") Creates a :ref:`TextureRegion ` of the indicated part of the texture. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - tex - The texture * - srcRect - The texture part that will be used as the :ref:`TextureRegion `. * - destSize - The destination size that the :ref:`TextureRegion ` will have when rendered. * - offset - The offset that will be added to the position passed when any Draw call is used. * - name - The texture name ( if any ) Methods ------- .. index:: pair: function; setTextureId .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a2f20e07a4070d9f8e1418a2dc9517603: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setTextureId(const :ref:`Uint32`& TexId) Set the :ref:`Texture ` Id that holds the :ref:`TextureRegion `. .. index:: pair: function; setTexture .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a39dd6547caa97b31887eafd478bbf019: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setTexture(:ref:`Texture`* texture) Set the :ref:`Texture ` that holds the :ref:`TextureRegion `. .. index:: pair: function; getSrcRect .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a3c7a40d2a93aa3886a0c798ac6fef934: .. ref-code-block:: cpp :class: doxyrest-title-code-block const :ref:`Rect`& getSrcRect() const .. rubric:: Returns: The :ref:`Texture ` sector that represents the :ref:`TextureRegion ` .. index:: pair: function; setSrcRect .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a32b5220e9b350a9961526afe36a23327: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setSrcRect(const :ref:`Rect`& rect) Sets the :ref:`Texture ` sector that represents the :ref:`TextureRegion ` .. index:: pair: function; getDestSize .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1ae04e778f8c41db42296ac3de675dc92d: .. ref-code-block:: cpp :class: doxyrest-title-code-block const :ref:`Sizef`& getDestSize() const .. rubric:: Returns: The Destination Size of the :ref:`TextureRegion `. .. index:: pair: function; setDestSize .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a6233877fecc26a2bfe5fa431ef62cddd: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setDestSize(const :ref:`Sizef`& destSize) Sets the Destination Size of the :ref:`TextureRegion `. The size can be different from the original size of the :ref:`TextureRegion `. For example if the :ref:`TextureRegion ` width is 32 pixels, by default the destination width is 32 pixels, but it can be changed to anything you want. .. index:: pair: function; getOffset .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1ab940beab81a4bf435009af0d8d749448: .. ref-code-block:: cpp :class: doxyrest-title-code-block const :ref:`Vector2i`& getOffset() const .. rubric:: Returns: The :ref:`TextureRegion ` default offset. The offset is added to the position passed when is drawed. .. index:: pair: function; setOffset .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a1307a505a35172a1207755dbd24fbd71: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setOffset(const :ref:`Vector2i`& offset) Set the :ref:`TextureRegion ` offset. .. index:: pair: function; getTexture .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1acc0a8b3151cac6b8c415a77f4057a7bf: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Graphics::Texture`* getTexture() .. rubric:: Returns: The texture instance used by the :ref:`TextureRegion `. .. index:: pair: function; replaceColor .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a87941386c95fe7f51fbcd8803aa8aa33: .. ref-code-block:: cpp :class: doxyrest-title-code-block void replaceColor(:ref:`Color` ColorKey, :ref:`Color` NewColor) Replaces a color in the :ref:`TextureRegion ` ( needs Lock() ) .. index:: pair: function; createMaskFromColor .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a6219cf9c4f299c2002270114f0fe9ea0: .. ref-code-block:: cpp :class: doxyrest-title-code-block void createMaskFromColor(:ref:`Color` ColorKey, :ref:`Uint8` Alpha) Creates a mask from a color. .. index:: pair: function; createMaskFromColor .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a07f7620d683981620b376b8006f66db4: .. ref-code-block:: cpp :class: doxyrest-title-code-block void createMaskFromColor(:ref:`RGB` ColorKey, :ref:`Uint8` Alpha) Creates a mask from a color. .. index:: pair: function; cacheAlphaMask .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a714b394047d2a7371bfcc7aa33e6a504: .. ref-code-block:: cpp :class: doxyrest-title-code-block void cacheAlphaMask() Creates a copy of the alpha mask to memory from the texture loaded in VRAM. .. index:: pair: function; cacheColors .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1ade1ce71b78b52673b58ad75924c9176f: .. ref-code-block:: cpp :class: doxyrest-title-code-block void cacheColors() Creates a copy in memory from the texture loaded in VRAM. .. index:: pair: function; getAlphaAt .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a048285cbe38a5a1b8135c0ba672ac134: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Uint8` getAlphaAt(const :ref:`Int32`& X, const :ref:`Int32`& Y) .. rubric:: Returns: The alpha value that corresponds to the position indicated in the :ref:`TextureRegion `. If the :ref:`TextureRegion ` wasn't locked before this call, it will be locked automatically. .. index:: pair: function; getColorAt .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a8f12d24ab89f1463cc5456528176853d: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Color` getColorAt(const :ref:`Int32`& X, const :ref:`Int32`& Y) .. rubric:: Returns: The color that corresponds to the position indicated in the :ref:`TextureRegion `. If the :ref:`TextureRegion ` wasn't locked before this call, it will be locked automatically. .. index:: pair: function; setColorAt .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a084d0aa3bb117b6002aaa2e4dd2fa19f: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setColorAt(const :ref:`Int32`& X, const :ref:`Int32`& Y, const :ref:`Color`& Color) Set a color to the position indicated in the :ref:`TextureRegion `. If the :ref:`TextureRegion ` wasn't locked before this call, it will be locked automatically. .. index:: pair: function; clearCache .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a05e51f59b4faf45d10fefe33ec06c4e9: .. ref-code-block:: cpp :class: doxyrest-title-code-block void clearCache() Deletes the texture buffer from memory ( not from VRAM ) if it was cached before ( using Lock() ). .. index:: pair: function; lock .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a21042d4aae855877f9a3c9d79f32bed7: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Uint8`* lock() Locks the texture to be able to perform read/write operations. .. rubric:: See also: Texture::Lock .. index:: pair: function; unlock .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a3cbd8c09f8ef67fea8dd87d1f8c047de: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool unlock(const bool& KeepData = false, const bool& Modified = false) Unlocks the current texture locked. .. rubric:: See also: Texture::Unlock .. index:: pair: function; getRealSize .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1ab2ffe94cd2536270046ee8802558a296: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Sizei` getRealSize() .. rubric:: Returns: The :ref:`TextureRegion ` size in the texture. This is the source rect size. .. index:: pair: function; getSize .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a1ef78a1f64cad5e0daaca1d485c47b00: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual :ref:`Sizef` getSize() .. rubric:: Returns: This is the same as Destination Size but with the values rounded as integers. .. index:: pair: function; getPixelsPtr .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a96b9fc890264d4be75d3691e5b7954e0: .. ref-code-block:: cpp :class: doxyrest-title-code-block const :ref:`Uint8`* getPixelsPtr() .. rubric:: Returns: A pixel pointer to the texture loaded in memory ( downloaded from VRAM doing Lock()/Unlock() ). .. index:: pair: function; saveToFile .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1a454821693e62806b1a09ee3df684b8fd: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool saveToFile(const std::string& filepath, const :ref:`Image::SaveType`& Format, const :ref:`Image::FormatConfiguration`& imageFormatConfiguration = :ref:`Image::FormatConfiguration`()) Saves the :ref:`TextureRegion ` to a file in the file format specified. This will get the :ref:`Texture ` from VRAM ( it will not work with OpenGL ES ) .. index:: pair: function; resetDestSize .. _doxid-class_e_e_1_1_graphics_1_1_texture_region_1ab6204cbcb7948e6ba971f85f68d0dd7a: .. ref-code-block:: cpp :class: doxyrest-title-code-block void resetDestSize() Sets the Destination Size as the Source Rect Size ( the real size of the :ref:`TextureRegion `) multiplied by the pixel density.