From 15e039f278e2318d74df88c736c65cde724d2638 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Fri, 6 Apr 2018 11:31:24 +0800 Subject: [PATCH] refactor functions --- core/Common/Image.cpp | 46 +++++++++++++++++++++---------------------- core/Node/Sprite.cpp | 22 ++++++++++----------- core/ecommon.h | 36 ++++++++++++++++----------------- core/enode.h | 6 +++--- core/etool.h | 18 ++++++++--------- 5 files changed, 64 insertions(+), 64 deletions(-) diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index 348841b7..8a106ae1 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -6,10 +6,10 @@ static std::map s_mBitmapsFromFile; e2d::Image::Image() : m_pBitmap(nullptr) - , m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) + , m_fSourceCropX(0) + , m_fSourceCropY(0) + , m_fSourceCropWidth(0) + , m_fSourceCropHeight(0) { } @@ -18,10 +18,10 @@ e2d::Image::Image(String strFileName) this->open(strFileName); } -e2d::Image::Image(String strFileName, double nClipX, double nClipY, double nClipWidth, double nClipHeight) +e2d::Image::Image(String strFileName, double nCropX, double nCropY, double nCropWidth, double nCropHeight) { this->open(strFileName); - this->clip(nClipX, nClipY, nClipWidth, nClipHeight); + this->crop(nCropX, nCropY, nCropWidth, nCropHeight); } e2d::Image::~Image() @@ -42,35 +42,35 @@ void e2d::Image::open(String strFilePath) } m_pBitmap = s_mBitmapsFromFile.at(strFilePath.getHashCode()); - m_fSourceClipX = m_fSourceClipY = 0; - m_fSourceClipWidth = m_pBitmap->GetSize().width; - m_fSourceClipHeight = m_pBitmap->GetSize().height; + m_fSourceCropX = m_fSourceCropY = 0; + m_fSourceCropWidth = m_pBitmap->GetSize().width; + m_fSourceCropHeight = m_pBitmap->GetSize().height; } -void e2d::Image::clip(double x, double y, double width, double height) +void e2d::Image::crop(double x, double y, double width, double height) { if (m_pBitmap) { - m_fSourceClipX = min(max(x, 0), this->getSourceWidth()); - m_fSourceClipY = min(max(y, 0), this->getSourceHeight()); - m_fSourceClipWidth = min(max(width, 0), this->getSourceWidth() - m_fSourceClipX); - m_fSourceClipHeight = min(max(height, 0), this->getSourceHeight() - m_fSourceClipY); + m_fSourceCropX = min(max(x, 0), this->getSourceWidth()); + m_fSourceCropY = min(max(y, 0), this->getSourceHeight()); + m_fSourceCropWidth = min(max(width, 0), this->getSourceWidth() - m_fSourceCropX); + m_fSourceCropHeight = min(max(height, 0), this->getSourceHeight() - m_fSourceCropY); } } double e2d::Image::getWidth() const { - return m_fSourceClipWidth; + return m_fSourceCropWidth; } double e2d::Image::getHeight() const { - return m_fSourceClipHeight; + return m_fSourceCropHeight; } e2d::Size e2d::Image::getSize() const { - return Size(m_fSourceClipWidth, m_fSourceClipHeight); + return Size(m_fSourceCropWidth, m_fSourceCropHeight); } double e2d::Image::getSourceWidth() const @@ -109,19 +109,19 @@ e2d::Size e2d::Image::getSourceSize() const } } -double e2d::Image::getClipX() const +double e2d::Image::getCropX() const { - return m_fSourceClipX; + return m_fSourceCropX; } -double e2d::Image::getClipY() const +double e2d::Image::getCropY() const { - return m_fSourceClipY; + return m_fSourceCropY; } -e2d::Point e2d::Image::getClipPos() const +e2d::Point e2d::Image::getCropPos() const { - return Point(m_fSourceClipX, m_fSourceClipY); + return Point(m_fSourceCropX, m_fSourceCropY); } bool e2d::Image::preload(String fileName) diff --git a/core/Node/Sprite.cpp b/core/Node/Sprite.cpp index 938de964..ca5dc3d2 100644 --- a/core/Node/Sprite.cpp +++ b/core/Node/Sprite.cpp @@ -22,7 +22,7 @@ e2d::Sprite::Sprite(String imageFileName, double x, double y, double width, doub : m_pImage(nullptr) { open(imageFileName); - clip(x, y, width, height); + crop(x, y, width, height); } e2d::Sprite::~Sprite() @@ -47,12 +47,12 @@ void e2d::Sprite::open(String imageFileName) open(new Image(imageFileName)); } -void e2d::Sprite::clip(double x, double y, double width, double height) +void e2d::Sprite::crop(double x, double y, double width, double height) { - m_pImage->clip(x, y, width, height); + m_pImage->crop(x, y, width, height); Node::setSize( - min(max(width, 0), m_pImage->getSourceWidth() - m_pImage->getClipX()), - min(max(height, 0), m_pImage->getSourceHeight() - m_pImage->getClipY()) + min(max(width, 0), m_pImage->getSourceWidth() - m_pImage->getCropX()), + min(max(height, 0), m_pImage->getSourceHeight() - m_pImage->getCropY()) ); } @@ -66,8 +66,8 @@ void e2d::Sprite::onRender() if (m_pImage && m_pImage->getBitmap()) { // 获取图片裁剪位置 - float fClipX = static_cast(m_pImage->getClipX()); - float fClipY = static_cast(m_pImage->getClipY()); + float fCropX = static_cast(m_pImage->getCropX()); + float fCropY = static_cast(m_pImage->getCropY()); // 渲染图片 Renderer::getRenderTarget()->DrawBitmap( m_pImage->getBitmap(), @@ -75,10 +75,10 @@ void e2d::Sprite::onRender() m_fDisplayOpacity, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1::RectF( - fClipX, - fClipY, - fClipX + m_fWidth, - fClipY + m_fHeight + fCropX, + fCropY, + fCropX + m_fWidth, + fCropY + m_fHeight ) ); } diff --git a/core/ecommon.h b/core/ecommon.h index 543e71a1..c960d63b 100644 --- a/core/ecommon.h +++ b/core/ecommon.h @@ -490,11 +490,11 @@ public: // 从本地文件中读取资源 Image( - String strFilePath,/* 图片文件路径 */ - double nClipX, /* 裁剪位置 X 坐标 */ - double nClipY, /* 裁剪位置 Y 坐标 */ - double nClipWidth, /* 裁剪宽度 */ - double nClipHeight /* 裁剪高度 */ + String strFilePath, /* 图片文件路径 */ + double nCropX, /* 裁剪位置 X 坐标 */ + double nCropY, /* 裁剪位置 Y 坐标 */ + double nCropWidth, /* 裁剪宽度 */ + double nCropHeight /* 裁剪高度 */ ); virtual ~Image(); @@ -504,12 +504,12 @@ public: String strFilePath ); - // 裁剪图片 - void clip( - double nClipX, /* 裁剪位置 X 坐标 */ - double nClipY, /* 裁剪位置 Y 坐标 */ - double nClipWidth, /* 裁剪宽度 */ - double nClipHeight /* 裁剪高度 */ + // 将图片裁剪为矩形 + void crop( + double nCropX, /* 裁剪位置 X 坐标 */ + double nCropY, /* 裁剪位置 Y 坐标 */ + double nCropWidth, /* 裁剪宽度 */ + double nCropHeight /* 裁剪高度 */ ); // 获取宽度 @@ -531,13 +531,13 @@ public: virtual Size getSourceSize() const; // 获取裁剪位置 X 坐标 - virtual double getClipX() const; + virtual double getCropX() const; // 获取裁剪位置 Y 坐标 - virtual double getClipY() const; + virtual double getCropY() const; // 获取裁剪位置 - virtual Point getClipPos() const; + virtual Point getCropPos() const; // 获取 ID2D1Bitmap 对象 ID2D1Bitmap * getBitmap(); @@ -551,10 +551,10 @@ public: static void clearCache(); protected: - double m_fSourceClipX; - double m_fSourceClipY; - double m_fSourceClipWidth; - double m_fSourceClipHeight; + double m_fSourceCropX; + double m_fSourceCropY; + double m_fSourceCropWidth; + double m_fSourceCropHeight; ID2D1Bitmap * m_pBitmap; }; diff --git a/core/enode.h b/core/enode.h index 2865db84..d772a88c 100644 --- a/core/enode.h +++ b/core/enode.h @@ -487,7 +487,7 @@ public: String imageFileName ); - // 从文件图片创建精灵并裁剪 + // 创建精灵并裁剪图片 Sprite( String imageFileName, double x, @@ -508,8 +508,8 @@ public: Image * image ); - // 裁剪图片 - virtual void clip( + // 将图片裁剪为矩形 + virtual void crop( double x, double y, double width, diff --git a/core/etool.h b/core/etool.h index 6918c7cf..ab342cd8 100644 --- a/core/etool.h +++ b/core/etool.h @@ -105,15 +105,15 @@ public: ); protected: - String m_sName; - bool m_bRunning; - bool m_bAtOnce; - bool m_bAutoRelease; - bool m_bClear; - int m_nRunTimes; - int m_nUpdateTimes; - double m_fInterval; - double m_fLast; + String m_sName; + bool m_bRunning; + bool m_bAtOnce; + bool m_bAutoRelease; + bool m_bClear; + int m_nRunTimes; + int m_nUpdateTimes; + double m_fInterval; + double m_fLast; Function m_Callback; };