Kiwano Engine v1.3.x
SpriteFrame.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/Common.h>
23#include <kiwano/math/Math.h>
24#include <kiwano/render/Texture.h>
25
26namespace kiwano
27{
28
33class KGE_API SpriteFrame
34{
35public:
37
41 SpriteFrame(StringView file_path);
42
46 SpriteFrame(const Resource& res);
47
52
57 SpriteFrame(StringView file_path, const Rect& crop_rect);
58
63 SpriteFrame(const Resource& res, const Rect& crop_rect);
64
69 SpriteFrame(RefPtr<Texture> texture, const Rect& crop_rect);
70
74 bool Load(StringView file_path);
75
79 bool Load(const Resource& res);
80
83 bool IsValid() const;
84
87 const Rect& GetCropRect() const;
88
91 RefPtr<Texture> GetTexture() const;
92
95 Size GetSize() const;
96
100 void SetCropRect(const Rect& crop_rect);
101
105 void SetTexture(RefPtr<Texture> texture);
106
114 Vector<SpriteFrame> Split(int cols, int rows, int max_num = -1, float padding_x = 0, float padding_y = 0);
115
116private:
117 RefPtr<Texture> texture_;
118 Rect crop_rect_;
119};
120
121inline bool SpriteFrame::IsValid() const
122{
123 return texture_ && texture_->IsValid();
124}
125
126inline const Rect& SpriteFrame::GetCropRect() const
127{
128 return crop_rect_;
129}
130
132{
133 return texture_;
134}
135
137{
138 return crop_rect_.GetSize();
139}
140
141} // namespace kiwano
引用计数智能指针
Definition: RefBasePtr.hpp:35
资源
Definition: Resource.h:41
精灵帧
Definition: SpriteFrame.h:34
RefPtr< Texture > GetTexture() const
获取纹理
Definition: SpriteFrame.h:131
Size GetSize() const
获取精灵帧大小
Definition: SpriteFrame.h:136
const Rect & GetCropRect() const
获取裁剪矩形
Definition: SpriteFrame.h:126
bool IsValid() const
是否有效
Definition: SpriteFrame.h:121