2019-04-11 14:40:54 +08:00
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2020-01-21 10:09:55 +08:00
|
|
|
//
|
2019-03-31 01:37:06 +08:00
|
|
|
// 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:
|
2020-01-21 10:09:55 +08:00
|
|
|
//
|
2019-03-31 01:37:06 +08:00
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
2020-01-21 10:09:55 +08:00
|
|
|
//
|
2019-03-31 01:37:06 +08:00
|
|
|
// 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
|
2019-11-13 14:33:15 +08:00
|
|
|
#include <kiwano/core/ObjectBase.h>
|
2020-01-17 16:55:47 +08:00
|
|
|
#include <kiwano/render/Texture.h>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
2020-01-21 10:09:55 +08:00
|
|
|
KGE_DECLARE_SMART_PTR(Frame);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
* @brief 图像帧
|
2020-01-21 10:09:55 +08:00
|
|
|
*/
|
|
|
|
|
class KGE_API Frame : public virtual ObjectBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-02-06 16:54:47 +08:00
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建图像帧
|
|
|
|
|
/// @param file_path 图像路径
|
2020-02-19 12:09:50 +08:00
|
|
|
static FramePtr Create(const String& file_path);
|
2020-02-06 16:54:47 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建图像帧
|
|
|
|
|
/// @param res 图像资源
|
2020-02-19 12:09:50 +08:00
|
|
|
static FramePtr Create(const Resource& res);
|
2020-02-06 16:54:47 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 创建图像帧
|
|
|
|
|
/// @param texture 纹理
|
2020-02-06 16:54:47 +08:00
|
|
|
static FramePtr Create(TexturePtr texture);
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 构建空图像帧
|
2020-01-21 10:09:55 +08:00
|
|
|
Frame();
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 加载图像
|
|
|
|
|
/// @param file_path 图像路径
|
2020-02-19 12:09:50 +08:00
|
|
|
bool Load(const String& file_path);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 加载图像
|
|
|
|
|
/// @param res 图像资源
|
2020-02-19 12:09:50 +08:00
|
|
|
bool Load(const Resource& res);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 裁剪图像帧为矩形
|
|
|
|
|
/// @param crop_rect 裁剪矩形定义
|
2020-02-19 12:09:50 +08:00
|
|
|
void SetCropRect(const Rect& crop_rect);
|
2020-01-21 10:09:55 +08:00
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 设置纹理
|
|
|
|
|
/// @param texture 纹理
|
2020-01-21 10:09:55 +08:00
|
|
|
void SetTexture(TexturePtr texture);
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 是否有效
|
2020-01-21 10:09:55 +08:00
|
|
|
bool IsValid() const;
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取宽度
|
2020-01-21 10:09:55 +08:00
|
|
|
float GetWidth() const;
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取高度
|
2020-01-21 10:09:55 +08:00
|
|
|
float GetHeight() const;
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取大小
|
2020-01-21 10:09:55 +08:00
|
|
|
Size GetSize() const;
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取裁剪位置
|
2020-01-21 10:09:55 +08:00
|
|
|
Point GetCropPoint() const;
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取裁剪矩形
|
2020-02-19 12:09:50 +08:00
|
|
|
const Rect& GetCropRect() const;
|
2020-01-21 10:09:55 +08:00
|
|
|
|
2020-02-13 12:05:20 +08:00
|
|
|
/// \~chinese
|
|
|
|
|
/// @brief 获取图像原宽度
|
|
|
|
|
float GetSourceWidth() const;
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
/// @brief 获取图像原高度
|
|
|
|
|
float GetSourceHeight() const;
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
/// @brief 获取图像原大小
|
|
|
|
|
Size GetSourceSize() const;
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
/// \~chinese
|
2020-02-10 17:32:04 +08:00
|
|
|
/// @brief 获取纹理
|
2020-01-21 10:09:55 +08:00
|
|
|
TexturePtr GetTexture() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TexturePtr texture_;
|
|
|
|
|
Rect crop_rect_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inline bool Frame::IsValid() const
|
|
|
|
|
{
|
|
|
|
|
return texture_ && texture_->IsValid();
|
|
|
|
|
}
|
2020-02-06 16:54:47 +08:00
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
inline float Frame::GetWidth() const
|
|
|
|
|
{
|
|
|
|
|
return crop_rect_.GetWidth();
|
|
|
|
|
}
|
2020-02-06 16:54:47 +08:00
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
inline float Frame::GetHeight() const
|
|
|
|
|
{
|
|
|
|
|
return crop_rect_.GetHeight();
|
|
|
|
|
}
|
2020-02-06 16:54:47 +08:00
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
inline Size Frame::GetSize() const
|
|
|
|
|
{
|
|
|
|
|
return crop_rect_.GetSize();
|
|
|
|
|
}
|
2020-02-06 16:54:47 +08:00
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
inline Point Frame::GetCropPoint() const
|
|
|
|
|
{
|
|
|
|
|
return crop_rect_.GetLeftTop();
|
|
|
|
|
}
|
2020-02-06 16:54:47 +08:00
|
|
|
|
2020-02-19 12:09:50 +08:00
|
|
|
inline const Rect& Frame::GetCropRect() const
|
2020-01-21 10:09:55 +08:00
|
|
|
{
|
|
|
|
|
return crop_rect_;
|
|
|
|
|
}
|
2020-02-06 16:54:47 +08:00
|
|
|
|
2020-02-13 12:05:20 +08:00
|
|
|
inline float Frame::GetSourceWidth() const
|
|
|
|
|
{
|
|
|
|
|
if (texture_)
|
|
|
|
|
{
|
|
|
|
|
return texture_->GetWidth();
|
|
|
|
|
}
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline float Frame::GetSourceHeight() const
|
|
|
|
|
{
|
|
|
|
|
if (texture_)
|
|
|
|
|
{
|
|
|
|
|
return texture_->GetHeight();
|
|
|
|
|
}
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline Size Frame::GetSourceSize() const
|
|
|
|
|
{
|
|
|
|
|
if (texture_)
|
|
|
|
|
{
|
|
|
|
|
return texture_->GetSize();
|
|
|
|
|
}
|
|
|
|
|
return Size();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
inline TexturePtr Frame::GetTexture() const
|
|
|
|
|
{
|
|
|
|
|
return texture_;
|
2019-03-31 01:37:06 +08:00
|
|
|
}
|
2020-02-06 16:54:47 +08:00
|
|
|
|
2020-01-21 10:09:55 +08:00
|
|
|
} // namespace kiwano
|