Magic_Game/src/kiwano/2d/Sprite.h

108 lines
2.7 KiB
C
Raw Normal View History

2019-04-11 14:40:54 +08:00
// 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
2019-10-11 21:55:29 +08:00
#include <kiwano/2d/Actor.h>
#include <kiwano/2d/Frame.h>
2019-04-11 14:40:54 +08:00
namespace kiwano
{
2019-12-23 18:05:08 +08:00
KGE_DECLARE_SMART_PTR(Sprite);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
2019-04-11 14:40:54 +08:00
class KGE_API Sprite
2019-08-14 00:28:25 +08:00
: public Actor
{
public:
Sprite();
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20>ӱ<EFBFBD><D3B1><EFBFBD>ͼƬ<CDBC><C6AC><EFBFBD><EFBFBD><ECBEAB>
/// @param file_path <20><><EFBFBD><EFBFBD>ͼƬ·<C6AC><C2B7>
explicit Sprite(String const& file_path);
2019-08-18 17:49:13 +08:00
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><>ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><ECBEAB>
/// @param res ͼƬ<CDBC><C6AC>Դ
explicit Sprite(Resource const& res);
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><>ͼ<EFBFBD><CDBC>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><ECBEAB>
/// @param[in] frame ͼ<><CDBC>֡
explicit Sprite(FramePtr frame);
2019-08-18 17:49:13 +08:00
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20>ӱ<EFBFBD><D3B1><EFBFBD>ͼƬ<CDBC><C6AC><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD>
/// @param file_path <20><><EFBFBD><EFBFBD>ͼƬ·<C6AC><C2B7>
/// @param crop_rect <20>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>
Sprite(String const& file_path, Rect const& crop_rect);
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><>ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD>
/// @param res ͼƬ<CDBC><C6AC>Դ
/// @param crop_rect <20>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>
Sprite(Resource const& res, Rect const& crop_rect);
virtual ~Sprite();
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><><EFBFBD>ر<EFBFBD><D8B1><EFBFBD>ͼƬ
/// @param file_path <20><><EFBFBD><EFBFBD>ͼƬ·<C6AC><C2B7>
bool Load(String const& file_path);
2019-08-18 17:49:13 +08:00
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Դ
/// @param res ͼƬ<CDBC><C6AC>Դ
bool Load(Resource const& res);
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief ʹ<>þ<EFBFBD><C3BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>
/// @param crop_rect <20>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>
void SetCropRect(const Rect& crop_rect);
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><>ȡ֡ͼ<D6A1><CDBC>
FramePtr GetFrame() const;
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>֡
/// @param[in] frame ͼ<><CDBC>֡
void SetFrame(FramePtr frame);
2019-08-20 19:32:36 +08:00
void OnRender(RenderTarget* rt) override;
2019-12-23 18:05:08 +08:00
private:
FramePtr frame_;
};
2019-12-23 18:05:08 +08:00
/** @} */
inline FramePtr Sprite::GetFrame() const { return frame_; }
}