2018-01-30 16:45:38 +08:00
|
|
|
|
#include "..\enodes.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Sprite::Sprite()
|
2018-02-03 22:04:43 +08:00
|
|
|
|
: m_pImage(nullptr)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Sprite::Sprite(Image * image)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
: m_pImage(nullptr)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-03-02 23:49:57 +08:00
|
|
|
|
open(image);
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-30 01:41:29 +08:00
|
|
|
|
e2d::Sprite::Sprite(String imageFileName)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
: m_pImage(nullptr)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-03-02 23:49:57 +08:00
|
|
|
|
open(imageFileName);
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-30 01:41:29 +08:00
|
|
|
|
e2d::Sprite::Sprite(String imageFileName, double x, double y, double width, double height)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
: m_pImage(nullptr)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-03-02 23:49:57 +08:00
|
|
|
|
open(imageFileName);
|
2018-01-30 16:45:38 +08:00
|
|
|
|
clip(x, y, width, height);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Sprite::~Sprite()
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
SafeRelease(&m_pImage);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-02 23:49:57 +08:00
|
|
|
|
void e2d::Sprite::open(Image * image)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (image)
|
|
|
|
|
|
{
|
|
|
|
|
|
SafeRelease(&m_pImage);
|
|
|
|
|
|
m_pImage = image;
|
|
|
|
|
|
m_pImage->retain();
|
|
|
|
|
|
|
2018-03-01 19:28:22 +08:00
|
|
|
|
Node::setSize(m_pImage->getWidth(), m_pImage->getHeight());
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-30 01:41:29 +08:00
|
|
|
|
void e2d::Sprite::open(String imageFileName)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-03-02 23:49:57 +08:00
|
|
|
|
open(new Image(imageFileName));
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Sprite::clip(double x, double y, double width, double height)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
m_pImage->clip(x, y, width, height);
|
2018-03-01 19:28:22 +08:00
|
|
|
|
Node::setSize(
|
2018-02-03 22:04:43 +08:00
|
|
|
|
min(max(width, 0), m_pImage->getSourceWidth() - m_pImage->getClipX()),
|
|
|
|
|
|
min(max(height, 0), m_pImage->getSourceHeight() - m_pImage->getClipY())
|
|
|
|
|
|
);
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Image * e2d::Sprite::getImage() const
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
return m_pImage;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Sprite::onRender()
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
if (m_pImage && m_pImage->getBitmap())
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-03-30 01:41:29 +08:00
|
|
|
|
// <20><>ȡͼƬ<CDBC>ü<EFBFBD>λ<EFBFBD><CEBB>
|
2018-02-27 21:07:43 +08:00
|
|
|
|
float fClipX = static_cast<float>(m_pImage->getClipX());
|
|
|
|
|
|
float fClipY = static_cast<float>(m_pImage->getClipY());
|
2018-02-03 22:04:43 +08:00
|
|
|
|
// <20><>ȾͼƬ
|
2018-02-07 16:37:12 +08:00
|
|
|
|
Renderer::getRenderTarget()->DrawBitmap(
|
2018-02-03 22:04:43 +08:00
|
|
|
|
m_pImage->getBitmap(),
|
2018-02-27 21:07:43 +08:00
|
|
|
|
D2D1::RectF(0, 0, m_fWidth, m_fHeight),
|
2018-01-30 16:45:38 +08:00
|
|
|
|
m_fDisplayOpacity,
|
|
|
|
|
|
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
|
|
|
|
|
|
D2D1::RectF(
|
2018-02-27 21:07:43 +08:00
|
|
|
|
fClipX,
|
|
|
|
|
|
fClipY,
|
|
|
|
|
|
fClipX + m_fWidth,
|
|
|
|
|
|
fClipY + m_fHeight
|
2018-01-30 16:45:38 +08:00
|
|
|
|
)
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|