diff --git a/src/kiwano/2d/Frame.h b/src/kiwano/2d/Frame.h index 6e00f428..4154c8c2 100644 --- a/src/kiwano/2d/Frame.h +++ b/src/kiwano/2d/Frame.h @@ -96,6 +96,18 @@ public: /// @brief 获取裁剪矩形 Rect const& GetCropRect() const; + /// \~chinese + /// @brief 获取图像原宽度 + float GetSourceWidth() const; + + /// \~chinese + /// @brief 获取图像原高度 + float GetSourceHeight() const; + + /// \~chinese + /// @brief 获取图像原大小 + Size GetSourceSize() const; + /// \~chinese /// @brief 获取纹理 TexturePtr GetTexture() const; @@ -135,6 +147,33 @@ inline Rect const& Frame::GetCropRect() const return crop_rect_; } +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(); +} + inline TexturePtr Frame::GetTexture() const { return texture_; diff --git a/src/kiwano/2d/Sprite.cpp b/src/kiwano/2d/Sprite.cpp index 1cf477cd..66d17663 100644 --- a/src/kiwano/2d/Sprite.cpp +++ b/src/kiwano/2d/Sprite.cpp @@ -102,12 +102,47 @@ bool Sprite::Load(Resource const& res, bool autoresize) return false; } +float Sprite::GetSourceWidth() const +{ + if (frame_) + { + return frame_->GetSourceWidth(); + } + return 0.0f; +} + +float Sprite::GetSourceHeight() const +{ + if (frame_) + { + return frame_->GetSourceHeight(); + } + return 0.0f; +} + +Size Sprite::GetSourceSize() const +{ + if (frame_) + { + return frame_->GetSourceSize(); + } + return Size(); +} + +Rect Sprite::GetCropRect() const +{ + if (frame_) + { + return frame_->GetCropRect(); + } + return Rect(); +} + void Sprite::SetCropRect(const Rect& crop_rect) { if (frame_) { frame_->SetCropRect(crop_rect); - SetSize(Size{ frame_->GetWidth(), frame_->GetHeight() }); } } @@ -118,7 +153,7 @@ void Sprite::SetFrame(FramePtr frame, bool autoresize) frame_ = frame; if (frame_ && autoresize) { - SetSize(Size{ frame_->GetWidth(), frame_->GetHeight() }); + SetSize(frame_->GetSize()); } } } diff --git a/src/kiwano/2d/Sprite.h b/src/kiwano/2d/Sprite.h index 410b560c..2d163989 100644 --- a/src/kiwano/2d/Sprite.h +++ b/src/kiwano/2d/Sprite.h @@ -72,15 +72,31 @@ public: /// \~chinese /// @brief 加载本地图片 /// @param file_path 本地图片路径 - /// @param[in] autoresize 是否自动调整自身大小为图像大小 + /// @param autoresize 是否自动调整自身大小为图像大小 bool Load(String const& file_path, bool autoresize = true); /// \~chinese /// @brief 加载图像资源 /// @param res 图片资源 - /// @param[in] autoresize 是否自动调整自身大小为图像大小 + /// @param autoresize 是否自动调整自身大小为图像大小 bool Load(Resource const& res, bool autoresize = true); + /// \~chinese + /// @brief 获取图像原宽度 + float GetSourceWidth() const; + + /// \~chinese + /// @brief 获取图像原高度 + float GetSourceHeight() const; + + /// \~chinese + /// @brief 获取图像原大小 + Size GetSourceSize() const; + + /// \~chinese + /// @brief 获取裁剪矩形 + Rect GetCropRect() const; + /// \~chinese /// @brief 使用矩形区域裁剪精灵 /// @param crop_rect 裁剪矩形 @@ -93,7 +109,7 @@ public: /// \~chinese /// @brief 设置图像帧 /// @param[in] frame 图像帧 - /// @param[in] autoresize 是否自动调整自身大小为图像大小 + /// @param autoresize 是否自动调整自身大小为图像大小 void SetFrame(FramePtr frame, bool autoresize = true); void OnRender(RenderContext& ctx) override; diff --git a/src/kiwano/2d/action/ActionHelper.h b/src/kiwano/2d/action/ActionHelper.h index ceba9ea7..fd4d169f 100644 --- a/src/kiwano/2d/action/ActionHelper.h +++ b/src/kiwano/2d/action/ActionHelper.h @@ -103,6 +103,11 @@ struct ActionHelper return ptr; } + inline ActionPtr operator->() const + { + return ptr; + } + private: ActionPtr ptr; }; @@ -199,6 +204,11 @@ struct TweenHelper return ptr; } + inline ActionTweenPtr operator->() const + { + return ptr; + } + private: ActionTweenPtr ptr; };