Kiwano Engine
v1.3.x
Sprite.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/2d/Actor.h>
23
24
namespace
kiwano
25
{
26
36
class
KGE_API
Sprite
:
public
Actor
37
{
38
public
:
39
Sprite
();
40
45
Sprite
(
RefPtr<Image>
image,
const
Rect
& src_rect =
Rect
());
46
49
RefPtr<Image>
GetImage()
const
;
50
53
RefPtr<Bitmap>
GetBitmap()
const
;
54
60
void
SetImage(
RefPtr<Image>
image,
const
Rect
& src_rect =
Rect
(),
bool
reset_size =
true
);
61
67
void
SetBitmap(
RefPtr<Bitmap>
bitmap,
const
Rect
& src_rect =
Rect
(),
bool
reset_size =
true
);
68
71
Rect
GetSourceRect()
const
;
72
76
void
SetSourceRect(
const
Rect
& src_rect);
77
78
void
OnRender(
RenderContext
& ctx)
override
;
79
80
protected
:
81
bool
CheckVisibility(
RenderContext
& ctx)
const override
;
82
83
private
:
84
bool
is_bitmap_ =
false
;
85
RefPtr<Image>
image_;
86
Rect
src_rect_;
87
};
88
91
inline
RefPtr<Image>
Sprite::GetImage
()
const
92
{
93
return
image_;
94
}
95
96
inline
RefPtr<Bitmap>
Sprite::GetBitmap
()
const
97
{
98
return
is_bitmap_ ?
RefPtr<Bitmap>
(
dynamic_cast<
Bitmap
*
>
(image_.Get())) :
nullptr
;
99
}
100
101
inline
Rect
Sprite::GetSourceRect
()
const
102
{
103
return
src_rect_;
104
}
105
106
inline
void
Sprite::SetSourceRect
(
const
Rect
& src_rect)
107
{
108
src_rect_ = src_rect;
109
}
110
111
}
// namespace kiwano
kiwano::Actor
角色
Definition:
Actor.h:63
kiwano::Bitmap
位图
Definition:
Bitmap.h:95
kiwano::RefBasePtr
引用计数智能指针
Definition:
RefBasePtr.hpp:35
kiwano::RenderContext
渲染上下文
Definition:
RenderContext.h:62
kiwano::Sprite
精灵
Definition:
Sprite.h:37
kiwano::Sprite::GetImage
RefPtr< Image > GetImage() const
获取图像
Definition:
Sprite.h:91
kiwano::Sprite::SetSourceRect
void SetSourceRect(const Rect &src_rect)
设置源矩形
Definition:
Sprite.h:106
kiwano::Sprite::GetBitmap
RefPtr< Bitmap > GetBitmap() const
获取位图(仅当设置为位图时生效)
Definition:
Sprite.h:96
kiwano::Sprite::GetSourceRect
Rect GetSourceRect() const
获取源矩形
Definition:
Sprite.h:101
kiwano::math::RectT< float >
src
kiwano
2d
Sprite.h
制作者
1.9.4