142 lines
3.7 KiB
C++
142 lines
3.7 KiB
C++
// Copyright (c) 2016-2018 Kiwano - Nomango
|
||
//
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
// of this software and associated documentation files (the "Software"), to deal
|
||
// in the Software without restriction, including without limitation the rights
|
||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
// copies of the Software, and to permit persons to whom the Software is
|
||
// furnished to do so, subject to the following conditions:
|
||
//
|
||
// The above copyright notice and this permission notice shall be included in
|
||
// all copies or substantial portions of the Software.
|
||
//
|
||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||
// THE SOFTWARE.
|
||
|
||
#pragma once
|
||
#include <kiwano/core/Common.h>
|
||
#include <kiwano/math/Math.h>
|
||
#include <kiwano/render/Texture.h>
|
||
|
||
namespace kiwano
|
||
{
|
||
|
||
/**
|
||
* \~chinese
|
||
* @brief ¾«ÁéÖ¡
|
||
*/
|
||
class KGE_API SpriteFrame
|
||
{
|
||
public:
|
||
SpriteFrame();
|
||
|
||
/// \~chinese
|
||
/// @brief ´´½¨¾«ÁéÖ¡
|
||
/// @param file_path ͼÏñ·¾¶
|
||
SpriteFrame(const String& file_path);
|
||
|
||
/// \~chinese
|
||
/// @brief ´´½¨¾«ÁéÖ¡
|
||
/// @param res ͼÏñ×ÊÔ´
|
||
SpriteFrame(const Resource& res);
|
||
|
||
/// \~chinese
|
||
/// @brief ´´½¨¾«ÁéÖ¡
|
||
/// @param texture ÎÆÀí
|
||
SpriteFrame(TexturePtr texture);
|
||
|
||
/// \~chinese
|
||
/// @brief ´´½¨¾«ÁéÖ¡
|
||
/// @param file_path ͼÏñ·¾¶
|
||
/// @param crop_rect ²Ã¼ô¾ØÐÎ
|
||
SpriteFrame(const String& file_path, const Rect& crop_rect);
|
||
|
||
/// \~chinese
|
||
/// @brief ´´½¨¾«ÁéÖ¡
|
||
/// @param res ͼÏñ×ÊÔ´
|
||
/// @param crop_rect ²Ã¼ô¾ØÐÎ
|
||
SpriteFrame(const Resource& res, const Rect& crop_rect);
|
||
|
||
/// \~chinese
|
||
/// @brief ´´½¨¾«ÁéÖ¡
|
||
/// @param texture ÎÆÀí
|
||
/// @param crop_rect ²Ã¼ô¾ØÐÎ
|
||
SpriteFrame(TexturePtr texture, const Rect& crop_rect);
|
||
|
||
/// \~chinese
|
||
/// @brief ¼ÓÔØÍ¼Ïñ
|
||
/// @param file_path ͼÏñ·¾¶
|
||
bool Load(const String& file_path);
|
||
|
||
/// \~chinese
|
||
/// @brief ¼ÓÔØÍ¼Ïñ
|
||
/// @param res ͼÏñ×ÊÔ´
|
||
bool Load(const Resource& res);
|
||
|
||
/// \~chinese
|
||
/// @brief ÊÇ·ñÓÐЧ
|
||
bool IsValid() const;
|
||
|
||
/// \~chinese
|
||
/// @brief »ñÈ¡²Ã¼ô¾ØÐÎ
|
||
const Rect& GetCropRect() const;
|
||
|
||
/// \~chinese
|
||
/// @brief »ñÈ¡ÎÆÀí
|
||
TexturePtr GetTexture() const;
|
||
|
||
/// \~chinese
|
||
/// @brief »ñÈ¡¾«ÁéÖ¡´óС
|
||
Size GetSize() const;
|
||
|
||
/// \~chinese
|
||
/// @brief ²Ã¼ô¾«Áé֡Ϊ¾ØÐÎ
|
||
/// @param crop_rect ²Ã¼ô¾ØÐÎ
|
||
void SetCropRect(const Rect& crop_rect);
|
||
|
||
/// \~chinese
|
||
/// @brief ÉèÖÃÎÆÀí²¢ÖØÖòüô¾ØÐÎ
|
||
/// @param texture ÎÆÀí
|
||
void SetTexture(TexturePtr texture);
|
||
|
||
/// \~chinese
|
||
/// @brief °´ÐÐÁзָÁéÖ¡
|
||
/// @param cols ÁÐÊý
|
||
/// @param rows ÐÐÊý
|
||
/// @param max_num ×î´óÖ¡ÊýÁ¿£¬Éè-1Ϊ½«·Ö¸îºóµÄͼÏñÈ«²¿×÷ΪÐòÁÐÖ¡
|
||
/// @param padding_x X·½Ïò¼ä¸ô
|
||
/// @param padding_y Y·½Ïò¼ä¸ô
|
||
Vector<SpriteFrame> Split(int cols, int rows, int max_num = -1, float padding_x = 0, float padding_y = 0);
|
||
|
||
private:
|
||
TexturePtr texture_;
|
||
Rect crop_rect_;
|
||
};
|
||
|
||
inline bool SpriteFrame::IsValid() const
|
||
{
|
||
return texture_ && texture_->IsValid();
|
||
}
|
||
|
||
inline const Rect& SpriteFrame::GetCropRect() const
|
||
{
|
||
return crop_rect_;
|
||
}
|
||
|
||
inline TexturePtr SpriteFrame::GetTexture() const
|
||
{
|
||
return texture_;
|
||
}
|
||
|
||
inline Size SpriteFrame::GetSize() const
|
||
{
|
||
return crop_rect_.GetSize();
|
||
}
|
||
|
||
} // namespace kiwano
|