部分全局枚举类型修改为类内嵌套枚举

This commit is contained in:
Nomango 2018-05-17 15:22:14 +08:00
parent 084671fa1c
commit c297d7d0e3
23 changed files with 473 additions and 628 deletions

View File

@ -24,7 +24,7 @@ bool e2d::Game::init(const String& name, const String& mutexName)
if (!mutexName.isEmpty())
{
// 创建进程互斥体
HANDLE hMutex = ::CreateMutex(NULL, TRUE, L"Easy2DApp-" + mutexName);
HANDLE hMutex = ::CreateMutex(nullptr, TRUE, L"Easy2DApp-" + mutexName);
if (hMutex == nullptr)
{
@ -41,7 +41,7 @@ bool e2d::Game::init(const String& name, const String& mutexName)
}
// 初始化 COM 组件
CoInitialize(NULL);
CoInitialize(nullptr);
// 创建设备无关资源
if (!Renderer::__createDeviceIndependentResources())

View File

@ -165,65 +165,25 @@ bool Input::isKeyRelease(KeyCode key)
return false;
}
bool Input::isMouseLButtonDown()
bool e2d::Input::isMouseDown(MouseCode code)
{
if (s_MouseState.rgbButtons[0] & 0x80)
if (s_MouseState.rgbButtons[static_cast<int>(code)] & 0x80)
return true;
return false;
}
bool Input::isMouseRButtonDown()
bool e2d::Input::isMousePress(MouseCode code)
{
if (s_MouseState.rgbButtons[1] & 0x80)
if ((s_MouseState.rgbButtons[static_cast<int>(code)] & 0x80) &&
!(s_MouseRecordState.rgbButtons[static_cast<int>(code)] & 0x80))
return true;
return false;
}
bool Input::isMouseMButtonDown()
bool e2d::Input::isMouseRelease(MouseCode code)
{
if (s_MouseState.rgbButtons[2] & 0x80)
return true;
return false;
}
bool Input::isMouseLButtonPress()
{
if ((s_MouseState.rgbButtons[0] & 0x80) && !(s_MouseRecordState.rgbButtons[0] & 0x80))
return true;
return false;
}
bool Input::isMouseRButtonPress()
{
if ((s_MouseState.rgbButtons[1] & 0x80) && !(s_MouseRecordState.rgbButtons[1] & 0x80))
return true;
return false;
}
bool Input::isMouseMButtonPress()
{
if ((s_MouseState.rgbButtons[2] & 0x80) && !(s_MouseRecordState.rgbButtons[2] & 0x80))
return true;
return false;
}
bool Input::isMouseLButtonRelease()
{
if (!(s_MouseState.rgbButtons[0] & 0x80) && (s_MouseRecordState.rgbButtons[0] & 0x80))
return true;
return false;
}
bool Input::isMouseRButtonRelease()
{
if (!(s_MouseState.rgbButtons[1] & 0x80) && (s_MouseRecordState.rgbButtons[1] & 0x80))
return true;
return false;
}
bool Input::isMouseMButtonRelease()
{
if (!(s_MouseState.rgbButtons[2] & 0x80) && (s_MouseRecordState.rgbButtons[2] & 0x80))
if (!(s_MouseState.rgbButtons[static_cast<int>(code)] & 0x80) &&
(s_MouseRecordState.rgbButtons[static_cast<int>(code)] & 0x80))
return true;
return false;
}

View File

@ -30,7 +30,7 @@ bool e2d::Renderer::__createDeviceIndependentResources()
// 创建 WIC 绘图工厂,用于统一处理各种格式的图片
hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
reinterpret_cast<void**>(&s_pIWICFactory)
@ -60,7 +60,7 @@ bool e2d::Renderer::__createDeviceIndependentResources()
// 创建文本格式化对象
hr = s_pDWriteFactory->CreateTextFormat(
L"",
NULL,
nullptr,
DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
@ -204,7 +204,7 @@ void e2d::Renderer::__render()
D2D1_LINE_JOIN_ROUND
);
pTextLayout->Draw(NULL, s_pTextRenderer, 10, 0);
pTextLayout->Draw(nullptr, s_pTextRenderer, 10, 0);
SafeReleaseInterface(pTextLayout);
}
@ -236,7 +236,7 @@ e2d::Color e2d::Renderer::getBackgroundColor()
void e2d::Renderer::setBackgroundColor(Color color)
{
s_nClearColor = color.toColorF();
s_nClearColor = color.toD2DColorF();
}
void e2d::Renderer::showFps(bool show)

View File

@ -13,15 +13,15 @@ bool e2d::Window::__init()
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpszClassName = L"Easy2DApp";
wcex.hIcon = NULL;
wcex.hIcon = nullptr;
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = Window::WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = sizeof(LONG_PTR);
wcex.hInstance = HINST_THISCOMPONENT;
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = nullptr;
wcex.lpszMenuName = nullptr;
wcex.hCursor = ::LoadCursor(nullptr, IDC_ARROW);
RegisterClassEx(&wcex);
@ -53,10 +53,10 @@ bool e2d::Window::__init()
dwStyle,
(screenWidth - nWidth) / 2, (screenHeight - nHeight) / 2,
nWidth, nHeight,
NULL,
NULL,
nullptr,
nullptr,
HINST_THISCOMPONENT,
NULL
nullptr
);
HRESULT hr = s_HWnd ? S_OK : E_FAIL;
@ -105,7 +105,7 @@ void e2d::Window::__poll()
{
static MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
while (::PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
@ -182,7 +182,7 @@ void e2d::Window::setTitle(const String& title)
void e2d::Window::setIcon(int iconID)
{
HINSTANCE hInstance = ::GetModuleHandle(NULL);
HINSTANCE hInstance = ::GetModuleHandle(nullptr);
HICON hIcon = (HICON)::LoadImage(hInstance, MAKEINTRESOURCE(iconID), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
// 设置窗口的图标
::SendMessage(s_HWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
@ -191,7 +191,7 @@ void e2d::Window::setIcon(int iconID)
void e2d::Window::setCursor(Cursor cursor)
{
LPCWSTR pCursorName = NULL;
LPCWSTR pCursorName = nullptr;
switch (cursor)
{
case Cursor::NORMAL:
@ -218,7 +218,7 @@ void e2d::Window::setCursor(Cursor cursor)
break;
}
HCURSOR hCursor = ::LoadCursor(NULL, pCursorName);
HCURSOR hCursor = ::LoadCursor(nullptr, pCursorName);
::SetCursor(hCursor);
}
@ -335,7 +335,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
case WM_DISPLAYCHANGE:
{
// 重绘客户区
InvalidateRect(hWnd, NULL, FALSE);
InvalidateRect(hWnd, nullptr, FALSE);
}
result = 0;
hasHandled = true;
@ -345,7 +345,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
case WM_PAINT:
{
e2d::Renderer::__render();
ValidateRect(hWnd, NULL);
ValidateRect(hWnd, nullptr);
}
result = 0;
hasHandled = true;

View File

@ -54,13 +54,13 @@ void e2d::Collider::_render()
// 获取纯色画刷
ID2D1SolidColorBrush * pBrush = Renderer::getSolidColorBrush();
// 设置画刷颜色和透明度
pBrush->SetColor(_color.toColorF());
pBrush->SetColor(_color.toD2DColorF());
// 绘制几何碰撞体
Renderer::getRenderTarget()->DrawGeometry(_transformed, pBrush);
}
}
e2d::Relation e2d::Collider::getRelationWith(Collider * pCollider) const
e2d::Collider::Relation e2d::Collider::getRelationWith(Collider * pCollider) const
{
if (_transformed && pCollider->_transformed)
{

View File

@ -1,12 +1,12 @@
#include "..\e2dcommon.h"
static const UINT32 sc_redShift = 16;
static const UINT32 sc_greenShift = 8;
static const UINT32 sc_blueShift = 0;
static const UINT sc_redShift = 16;
static const UINT sc_greenShift = 8;
static const UINT sc_blueShift = 0;
static const UINT32 sc_redMask = 0xff << sc_redShift;
static const UINT32 sc_greenMask = 0xff << sc_greenShift;
static const UINT32 sc_blueMask = 0xff << sc_blueShift;
static const UINT sc_redMask = 0xff << sc_redShift;
static const UINT sc_greenMask = 0xff << sc_greenShift;
static const UINT sc_blueMask = 0xff << sc_blueShift;
e2d::Color::Color()
: r(0)
@ -32,17 +32,17 @@ e2d::Color::Color(double r, double g, double b, double alpha)
{
}
e2d::Color::Color(UINT32 rgb)
e2d::Color::Color(UINT rgb)
{
_init(rgb, 1);
}
e2d::Color::Color(UINT32 rgb, double alpha)
e2d::Color::Color(UINT rgb, double alpha)
{
_init(rgb, alpha);
}
void e2d::Color::_init(UINT32 rgb, double alpha)
void e2d::Color::_init(UINT rgb, double alpha)
{
r = float((rgb & sc_redMask) >> sc_redShift) / 255.f;
g = float((rgb & sc_greenMask) >> sc_greenShift) / 255.f;
@ -50,7 +50,7 @@ void e2d::Color::_init(UINT32 rgb, double alpha)
a = float(alpha);
}
D2D1_COLOR_F e2d::Color::toColorF() const
D2D1_COLOR_F e2d::Color::toD2DColorF() const
{
return D2D1::ColorF(r, g, b, a);
}

View File

@ -195,7 +195,7 @@ bool e2d::Image::preload(const String& filePath)
// 创建解码器
hr = Renderer::getIWICImagingFactory()->CreateDecoderFromFilename(
filePath,
NULL,
nullptr,
GENERIC_READ,
WICDecodeMetadataCacheOnLoad,
&pDecoder
@ -221,7 +221,7 @@ bool e2d::Image::preload(const String& filePath)
pSource,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
NULL,
nullptr,
0.f,
WICBitmapPaletteTypeMedianCut
);
@ -232,7 +232,7 @@ bool e2d::Image::preload(const String& filePath)
// 从 WIC 位图创建一个 Direct2D 位图
hr = Renderer::getRenderTarget()->CreateBitmapFromWicBitmap(
pConverter,
NULL,
nullptr,
&pBitmap
);
}
@ -325,7 +325,7 @@ bool e2d::Image::preload(int resNameId, const String& resType)
// 创建流的解码器
hr = Renderer::getIWICImagingFactory()->CreateDecoderFromStream(
pStream,
NULL,
nullptr,
WICDecodeMetadataCacheOnLoad,
&pDecoder
);
@ -351,7 +351,7 @@ bool e2d::Image::preload(int resNameId, const String& resType)
pSource,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
NULL,
nullptr,
0.f,
WICBitmapPaletteTypeMedianCut
);
@ -362,7 +362,7 @@ bool e2d::Image::preload(int resNameId, const String& resType)
// 从 WIC 位图创建一个 Direct2D 位图
hr = Renderer::getRenderTarget()->CreateBitmapFromWicBitmap(
pConverter,
NULL,
nullptr,
&pBitmap
);
}

View File

@ -78,7 +78,7 @@ e2d::String e2d::String::format(const char * format, ...)
{
std::string tmp;
va_list marker = NULL;
va_list marker = nullptr;
va_start(marker, format);
size_t nu_of_chars = _vscprintf(format, marker);
@ -100,7 +100,7 @@ e2d::String e2d::String::format(const wchar_t * format, ...)
{
std::wstring tmp;
va_list marker = NULL;
va_list marker = nullptr;
va_start(marker, format);
size_t nu_of_chars = _vscwprintf(format, marker);

View File

@ -1,53 +0,0 @@
#include "..\e2dnode.h"
e2d::TextStyle::TextStyle()
: fontFamily("")
, fontSize(22)
, color(Color::WHITE)
, fontWeight(FontWeight::NORMAL)
, italic(false)
, alignment(TextAlign::LEFT)
, wrapping(false)
, wrappingWidth(0.0)
, lineSpacing(0.0)
, hasUnderline(false)
, hasStrikethrough(false)
, hasOutline(true)
, outlineColor(Color(Color::BLACK, 0.5))
, outlineWidth(1.0)
, outlineJoin(LineJoin::ROUND)
{}
e2d::TextStyle::TextStyle(
const String& fontFamily,
double fontSize,
Color color,
UINT32 fontWeight,
bool italic,
TextAlign alignment,
bool wrapping,
double wrappingWidth,
double lineSpacing,
bool hasUnderline,
bool hasStrikethrough,
bool hasOutline,
Color outlineColor,
double outlineWidth,
LineJoin outlineJoin
)
: fontFamily(fontFamily)
, fontSize(fontSize)
, color(color)
, fontWeight(fontWeight)
, italic(italic)
, alignment(alignment)
, wrapping(wrapping)
, wrappingWidth(wrappingWidth)
, lineSpacing(lineSpacing)
, hasUnderline(hasUnderline)
, hasStrikethrough(hasStrikethrough)
, hasOutline(hasOutline)
, outlineColor(outlineColor)
, outlineWidth(outlineWidth)
, outlineJoin(outlineJoin)
{}

View File

@ -57,12 +57,12 @@ STDMETHODIMP CustomTextRenderer::DrawGlyphRun(
{
HRESULT hr = S_OK;
ID2D1PathGeometry* pPathGeometry = NULL;
ID2D1PathGeometry* pPathGeometry = nullptr;
hr = pD2DFactory_->CreatePathGeometry(
&pPathGeometry
);
ID2D1GeometrySink* pSink = NULL;
ID2D1GeometrySink* pSink = nullptr;
if (SUCCEEDED(hr))
{
hr = pPathGeometry->Open(
@ -95,7 +95,7 @@ STDMETHODIMP CustomTextRenderer::DrawGlyphRun(
baselineOriginX, baselineOriginY
);
ID2D1TransformedGeometry* pTransformedGeometry = NULL;
ID2D1TransformedGeometry* pTransformedGeometry = nullptr;
if (SUCCEEDED(hr))
{
hr = pD2DFactory_->CreateTransformedGeometry(
@ -105,10 +105,9 @@ STDMETHODIMP CustomTextRenderer::DrawGlyphRun(
);
}
ID2D1StrokeStyle * pStrokeStyle = NULL;
if (SUCCEEDED(hr))
if (SUCCEEDED(hr) && bShowOutline_)
{
ID2D1StrokeStyle * pStrokeStyle = nullptr;
hr = Renderer::getID2D1Factory()->CreateStrokeStyle(
D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT,
@ -118,15 +117,12 @@ STDMETHODIMP CustomTextRenderer::DrawGlyphRun(
2.0f,
D2D1_DASH_STYLE_SOLID,
0.0f),
NULL,
nullptr,
0,
&pStrokeStyle
);
}
if (SUCCEEDED(hr))
{
if (bShowOutline_)
if (SUCCEEDED(hr))
{
pBrush_->SetColor(sOutlineColor_);
@ -137,7 +133,10 @@ STDMETHODIMP CustomTextRenderer::DrawGlyphRun(
pStrokeStyle
);
}
}
if (SUCCEEDED(hr))
{
pBrush_->SetColor(sFillColor_);
pRT_->FillGeometry(
@ -170,7 +169,7 @@ STDMETHODIMP CustomTextRenderer::DrawUnderline(
underline->offset + underline->thickness
);
ID2D1RectangleGeometry* pRectangleGeometry = NULL;
ID2D1RectangleGeometry* pRectangleGeometry = nullptr;
hr = pD2DFactory_->CreateRectangleGeometry(
&rect,
&pRectangleGeometry
@ -182,7 +181,7 @@ STDMETHODIMP CustomTextRenderer::DrawUnderline(
baselineOriginX, baselineOriginY
);
ID2D1TransformedGeometry* pTransformedGeometry = NULL;
ID2D1TransformedGeometry* pTransformedGeometry = nullptr;
if (SUCCEEDED(hr))
{
hr = pD2DFactory_->CreateTransformedGeometry(
@ -192,10 +191,9 @@ STDMETHODIMP CustomTextRenderer::DrawUnderline(
);
}
ID2D1StrokeStyle * pStrokeStyle = NULL;
if (SUCCEEDED(hr))
if (SUCCEEDED(hr) && bShowOutline_)
{
ID2D1StrokeStyle * pStrokeStyle = nullptr;
hr = Renderer::getID2D1Factory()->CreateStrokeStyle(
D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT,
@ -205,15 +203,12 @@ STDMETHODIMP CustomTextRenderer::DrawUnderline(
2.0f,
D2D1_DASH_STYLE_SOLID,
0.0f),
NULL,
nullptr,
0,
&pStrokeStyle
);
}
if (SUCCEEDED(hr))
{
if (bShowOutline_)
if (SUCCEEDED(hr))
{
pBrush_->SetColor(sOutlineColor_);
@ -224,7 +219,10 @@ STDMETHODIMP CustomTextRenderer::DrawUnderline(
pStrokeStyle
);
}
}
if (SUCCEEDED(hr))
{
pBrush_->SetColor(sFillColor_);
pRT_->FillGeometry(
@ -256,7 +254,7 @@ STDMETHODIMP CustomTextRenderer::DrawStrikethrough(
strikethrough->offset + strikethrough->thickness
);
ID2D1RectangleGeometry* pRectangleGeometry = NULL;
ID2D1RectangleGeometry* pRectangleGeometry = nullptr;
hr = pD2DFactory_->CreateRectangleGeometry(
&rect,
&pRectangleGeometry
@ -268,7 +266,7 @@ STDMETHODIMP CustomTextRenderer::DrawStrikethrough(
baselineOriginX, baselineOriginY
);
ID2D1TransformedGeometry* pTransformedGeometry = NULL;
ID2D1TransformedGeometry* pTransformedGeometry = nullptr;
if (SUCCEEDED(hr))
{
hr = pD2DFactory_->CreateTransformedGeometry(
@ -278,10 +276,9 @@ STDMETHODIMP CustomTextRenderer::DrawStrikethrough(
);
}
ID2D1StrokeStyle * pStrokeStyle = NULL;
if (SUCCEEDED(hr))
if (SUCCEEDED(hr) && bShowOutline_)
{
ID2D1StrokeStyle * pStrokeStyle = nullptr;
hr = Renderer::getID2D1Factory()->CreateStrokeStyle(
D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT,
@ -291,15 +288,12 @@ STDMETHODIMP CustomTextRenderer::DrawStrikethrough(
2.0f,
D2D1_DASH_STYLE_SOLID,
0.0f),
NULL,
nullptr,
0,
&pStrokeStyle
);
}
if (SUCCEEDED(hr))
{
if (bShowOutline_)
if (SUCCEEDED(hr))
{
pBrush_->SetColor(sOutlineColor_);
@ -310,7 +304,10 @@ STDMETHODIMP CustomTextRenderer::DrawStrikethrough(
pStrokeStyle
);
}
}
if (SUCCEEDED(hr))
{
pBrush_->SetColor(sFillColor_);
pRT_->FillGeometry(
@ -406,7 +403,7 @@ STDMETHODIMP CustomTextRenderer::QueryInterface(
}
else
{
*ppvObject = NULL;
*ppvObject = nullptr;
return E_FAIL;
}

View File

@ -114,9 +114,9 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
if (IsCollideWith(pActiveNode, pPassiveNode))
{
// 判断两碰撞体交集情况
Relation relation = pActiveCollider->getRelationWith(pPassiveCollider);
Collider::Relation relation = pActiveCollider->getRelationWith(pPassiveCollider);
// 忽略 UNKNOWN 和 DISJOINT 情况
if (relation != Relation::UNKNOWN && relation != Relation::DISJOINT)
if (relation != Collider::Relation::UNKNOWN && relation != Collider::Relation::DISJOINT)
{
s_pActiveNode = pActiveNode;
s_pPassiveNode = pPassiveNode;

View File

@ -209,7 +209,7 @@ void e2d::Button::onFixedUpdate()
if (_enable && _visiable && _normal)
{
if (Input::isMouseLButtonRelease())
if (Input::isMouseRelease(Input::MouseCode::LEFT))
{
// 鼠标左键抬起时,判断鼠标坐标是否在按钮内部
if (_isSelected &&
@ -221,7 +221,7 @@ void e2d::Button::onFixedUpdate()
_isSelected = false;
}
if (Input::isMouseLButtonPress())
if (Input::isMousePress(Input::MouseCode::LEFT))
{
if (_normal->isPointIn(Input::getMousePos()))
{
@ -231,19 +231,19 @@ void e2d::Button::onFixedUpdate()
}
}
if (_isSelected && Input::isMouseLButtonDown())
if (_isSelected && Input::isMouseDown(Input::MouseCode::LEFT))
{
if (_normal->isPointIn(Input::getMousePos()))
{
_setState(ButtonState::SELECTED);
Window::setCursor(Cursor::HAND);
Window::setCursor(Window::Cursor::HAND);
return;
}
}
else if (_normal->isPointIn(Input::getMousePos()))
{
_setState(ButtonState::MOUSEOVER);
Window::setCursor(Cursor::HAND);
Window::setCursor(Window::Cursor::HAND);
return;
}
@ -252,7 +252,7 @@ void e2d::Button::onFixedUpdate()
if (_visiable && !_enable && _normal && _normal->isPointIn(Input::getMousePos()))
{
Window::setCursor(Cursor::NO);
Window::setCursor(Window::Cursor::NO);
}
}

View File

@ -1,7 +1,6 @@
#include "..\e2dnode.h"
#include "..\e2dmanager.h"
#include "..\e2daction.h"
#include "..\e2dcollider.h"
#include <algorithm>
// 默认中心点位置
@ -337,9 +336,9 @@ double e2d::Node::getOpacity() const
return _realOpacity;
}
e2d::NodeProperty e2d::Node::getProperty() const
e2d::Node::Property e2d::Node::getProperty() const
{
NodeProperty prop;
Property prop;
prop.visable = _visiable;
prop.posX = _posX;
prop.posY = _posY;
@ -534,7 +533,7 @@ void e2d::Node::setSize(Size size)
this->setSize(size.width, size.height);
}
void e2d::Node::setProperty(NodeProperty prop)
void e2d::Node::setProperty(Property prop)
{
this->setVisiable(prop.visable);
this->setPos(prop.posX, prop.posY);
@ -546,23 +545,23 @@ void e2d::Node::setProperty(NodeProperty prop)
this->setSkew(prop.skewAngleX, prop.skewAngleY);
}
void e2d::Node::setCollider(ColliderType nColliderType)
void e2d::Node::setCollider(Collider::Type type)
{
switch (nColliderType)
switch (type)
{
case ColliderType::RECT:
case Collider::Type::RECT:
{
this->setCollider(Create<ColliderRect>(this));
break;
}
case ColliderType::CIRCLE:
case Collider::Type::CIRCLE:
{
this->setCollider(Create<ColliderCircle>(this));
break;
}
case ColliderType::ELLIPSE:
case Collider::Type::ELLIPSE:
{
this->setCollider(Create<ColliderEllipse>(this));
break;
@ -913,9 +912,9 @@ bool e2d::Node::isIntersectWith(const Node * node) const
// 如果存在碰撞体,用碰撞体判断
if (this->_collider && node->_collider)
{
Relation relation = this->_collider->getRelationWith(node->_collider);
if ((relation != Relation::UNKNOWN) &&
(relation != Relation::DISJOINT))
Collider::Relation relation = this->_collider->getRelationWith(node->_collider);
if ((relation != Collider::Relation::UNKNOWN) &&
(relation != Collider::Relation::DISJOINT))
{
return true;
}

View File

@ -1,7 +1,7 @@
#include "..\..\e2dshape.h"
e2d::Shape::Shape()
: _style(ShapeStyle::SOLID)
: _style(Style::SOLID)
, _fillColor(Color::BLUE, 0.3)
, _lineColor(Color::BLUE, 0.5)
, _strokeWidth(1)
@ -19,26 +19,26 @@ void e2d::Shape::onRender()
switch (_style)
{
case ShapeStyle::FILL:
case Style::FILL:
{
pBrush->SetColor(_fillColor.toColorF());
pBrush->SetColor(_fillColor.toD2DColorF());
this->_renderFill();
pBrush->SetColor(_lineColor.toColorF());
pBrush->SetColor(_lineColor.toD2DColorF());
this->_renderLine();
break;
}
case ShapeStyle::ROUND:
case Style::ROUND:
{
pBrush->SetColor(_lineColor.toColorF());
pBrush->SetColor(_lineColor.toD2DColorF());
this->_renderLine();
break;
}
case ShapeStyle::SOLID:
case Style::SOLID:
{
pBrush->SetColor(_fillColor.toColorF());
pBrush->SetColor(_fillColor.toD2DColorF());
this->_renderFill();
break;
}
@ -63,7 +63,7 @@ double e2d::Shape::getStrokeWidth() const
return _strokeWidth;
}
e2d::ShapeStyle e2d::Shape::getStyle() const
e2d::Shape::Style e2d::Shape::getStyle() const
{
return _style;
}
@ -83,7 +83,7 @@ void e2d::Shape::setStrokeWidth(double strokeWidth)
_strokeWidth = float(strokeWidth);
}
void e2d::Shape::setStyle(ShapeStyle style)
void e2d::Shape::setStyle(Style style)
{
_style = style;
}

View File

@ -1,72 +1,88 @@
#include "..\e2dnode.h"
e2d::Text::Text()
: _style()
, _textLayout(nullptr)
, _textFormat(nullptr)
//-------------------------------------------------------
// Font
//-------------------------------------------------------
e2d::Text::Font::Font()
: family("")
, size(22)
, weight(Font::Weight::NORMAL)
, italic(false)
{
}
e2d::Text::Text(const String& text)
: _style()
, _textLayout(nullptr)
, _textFormat(nullptr)
, _text(text)
e2d::Text::Font::Font(const String & family, double size, UINT weight, bool italic)
: family(family)
, size(size)
, weight(weight)
, italic(italic)
{
_reset();
}
e2d::Text::Text(TextStyle textStyle)
: _style(textStyle)
, _textLayout(nullptr)
, _textFormat(nullptr)
{
_reset();
}
e2d::Text::Text(const String& text, TextStyle textStyle)
: _style(textStyle)
, _textLayout(nullptr)
, _textFormat(nullptr)
, _text(text)
{
_reset();
}
//-------------------------------------------------------
// Style
//-------------------------------------------------------
e2d::Text::Text(
const String& text,
const String& fontFamily,
double fontSize,
UINT32 color,
UINT32 fontWeight,
bool italic,
TextAlign alignment,
e2d::Text::Style::Style()
: color(Color::WHITE)
, alignment(Align::LEFT)
, wrapping(false)
, wrappingWidth(0.0)
, lineSpacing(0.0)
, hasUnderline(false)
, hasStrikethrough(false)
, hasOutline(true)
, outlineColor(Color(Color::BLACK, 0.5))
, outlineWidth(1.0)
, outlineJoin(LineJoin::ROUND)
{}
e2d::Text::Style::Style(
Color color,
Align alignment,
bool wrapping,
double wrappingWidth,
double lineSpacing,
bool hasUnderline,
bool hasUnderline,
bool hasStrikethrough,
bool hasOutline,
UINT32 outlineColor,
UINT32 outlineWidth
Color outlineColor,
double outlineWidth,
LineJoin outlineJoin
)
: _style(
fontFamily,
fontSize,
color,
fontWeight,
italic,
alignment,
wrapping,
wrappingWidth,
lineSpacing,
hasUnderline,
hasStrikethrough,
hasOutline,
outlineColor,
outlineWidth
)
: color(color)
, alignment(alignment)
, wrapping(wrapping)
, wrappingWidth(wrappingWidth)
, lineSpacing(lineSpacing)
, hasUnderline(hasUnderline)
, hasStrikethrough(hasStrikethrough)
, hasOutline(hasOutline)
, outlineColor(outlineColor)
, outlineWidth(outlineWidth)
, outlineJoin(outlineJoin)
{}
//-------------------------------------------------------
// Text
//-------------------------------------------------------
e2d::Text::Text()
: _font()
, _style()
, _textLayout(nullptr)
, _textFormat(nullptr)
{
}
e2d::Text::Text(const String & text, const Font & font, const Style & style)
: _font(font)
, _style(style)
, _textLayout(nullptr)
, _textFormat(nullptr)
, _text(text)
@ -79,24 +95,9 @@ e2d::Text * e2d::Text::create()
return Create<Text>();
}
e2d::Text * e2d::Text::create(const String & text)
e2d::Text * e2d::Text::create(const String & text, const Font & font, const Style & style)
{
return Create<Text>(text);
}
e2d::Text * e2d::Text::create(TextStyle textStyle)
{
return Create<Text>(textStyle);
}
e2d::Text * e2d::Text::create(const String & text, TextStyle textStyle)
{
return Create<Text>(text, textStyle);
}
e2d::Text * e2d::Text::create(const String & text, const String & fontFamily, double fontSize, UINT32 color, UINT32 fontWeight, bool italic, TextAlign alignment, bool wrapping, double wrappingWidth, double lineSpacing, bool hasUnderline, bool hasStrikethrough, bool hasOutline, UINT32 outlineColor, UINT32 outlineWidth)
{
return Create<Text>(text, fontFamily, fontSize, color, fontWeight, italic, alignment, wrapping, wrappingWidth, lineSpacing, hasUnderline, hasStrikethrough, hasOutline, outlineColor, outlineWidth);
return Create<Text>(text, font, style);
}
e2d::Text::~Text()
@ -110,24 +111,29 @@ e2d::String e2d::Text::getText() const
return _text;
}
e2d::TextStyle e2d::Text::getTextStyle() const
e2d::Text::Font e2d::Text::getFont() const
{
return _font;
}
e2d::Text::Style e2d::Text::getStyle() const
{
return _style;
}
e2d::String e2d::Text::getFontFamily() const
{
return _style.fontFamily;
return _font.family;
}
double e2d::Text::getFontSize() const
{
return _style.fontSize;
return _font.size;
}
UINT32 e2d::Text::getFontWeight() const
UINT e2d::Text::getFontWeight() const
{
return _style.fontWeight;
return _font.weight;
}
e2d::Color e2d::Text::getColor() const
@ -166,7 +172,7 @@ int e2d::Text::getLineCount() const
bool e2d::Text::isItalic() const
{
return _style.italic;
return _font.italic;
}
bool e2d::Text::hasStrikethrough() const
@ -190,27 +196,33 @@ void e2d::Text::setText(const String& text)
_reset();
}
void e2d::Text::setStyle(const TextStyle& textStyle)
void e2d::Text::setStyle(const Style& style)
{
_style = textStyle;
_style = style;
_reset();
}
void e2d::Text::setFontFamily(const String& fontFamily)
void e2d::Text::setFont(const Font & font)
{
_style.fontFamily = fontFamily;
_font = font;
_reset();
}
void e2d::Text::setFontSize(double fontSize)
void e2d::Text::setFontFamily(const String& family)
{
_style.fontSize = fontSize;
_font.family = family;
_reset();
}
void e2d::Text::setFontWeight(UINT32 fontWeight)
void e2d::Text::setFontSize(double size)
{
_style.fontWeight = fontWeight;
_font.size = size;
_reset();
}
void e2d::Text::setFontWeight(UINT weight)
{
_font.weight = weight;
_reset();
}
@ -221,7 +233,7 @@ void e2d::Text::setColor(Color color)
void e2d::Text::setItalic(bool value)
{
_style.italic = value;
_font.italic = value;
_reset();
}
@ -256,7 +268,7 @@ void e2d::Text::setLineSpacing(double lineSpacing)
}
}
void e2d::Text::setAlignment(TextAlign align)
void e2d::Text::setAlignment(Align align)
{
if (_style.alignment != align)
{
@ -318,13 +330,13 @@ void e2d::Text::onRender()
// »ñÈ¡Îı¾äÖȾÆ÷
auto pTextRenderer = Renderer::getCustomTextRenderer();
pTextRenderer->SetTextStyle(
_style.color.toColorF(),
_style.color.toD2DColorF(),
_style.hasOutline,
_style.outlineColor.toColorF(),
_style.outlineColor.toD2DColorF(),
float(_style.outlineWidth),
D2D1_LINE_JOIN(_style.outlineJoin)
);
_textLayout->Draw(NULL, pTextRenderer, 0, 0);
_textLayout->Draw(nullptr, pTextRenderer, 0, 0);
}
}
@ -341,12 +353,12 @@ void e2d::Text::_createFormat()
SafeReleaseInterface(_textFormat);
HRESULT hr = Renderer::getIDWriteFactory()->CreateTextFormat(
_style.fontFamily,
NULL,
DWRITE_FONT_WEIGHT(_style.fontWeight),
_style.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
_font.family,
nullptr,
DWRITE_FONT_WEIGHT(_font.weight),
_font.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
float(_style.fontSize),
float(_font.size),
L"",
&_textFormat
);
@ -399,7 +411,7 @@ void e2d::Text::_createLayout()
return;
}
UINT32 length = UINT32(_text.getLength());
UINT32 length = (UINT32)_text.getLength();
// ´´½¨ TextLayout
HRESULT hr;

View File

@ -18,10 +18,10 @@ bool e2d::Path::__init()
// 获取 AppData\Local 文件夹的路径
typedef HRESULT(WINAPI* pFunSHGetKnownFolderPath)(const GUID& rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath);
PWSTR pszPath = NULL;
PWSTR pszPath = nullptr;
HMODULE hModule = LoadLibrary(L"shell32.dll");
pFunSHGetKnownFolderPath SHGetKnownFolderPath = (pFunSHGetKnownFolderPath)GetProcAddress(hModule, "SHGetKnownFolderPath");
HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &pszPath);
HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &pszPath);
if (SUCCEEDED(hr))
{
@ -157,7 +157,7 @@ e2d::String e2d::Path::getSaveFilePath(const String& title, const String& defExt
ofn.nFilterIndex = 1; // 过滤器索引
ofn.lpstrFile = strFilename; // 接收返回的文件路径和文件名
ofn.nMaxFile = sizeof(strFilename); // 缓冲区长度
ofn.lpstrInitialDir = NULL; // 初始目录为默认
ofn.lpstrInitialDir = nullptr; // 初始目录为默认
ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
ofn.lpstrTitle = title; // 标题
ofn.lpstrDefExt = defExt; // 默认追加的扩展名

View File

@ -51,6 +51,17 @@ class Window
{
friend Game;
public:
// 鼠标指针样式
enum class Cursor : int
{
NORMAL, /* 默认指针样式 */
HAND, /* 手状指针 */
NO, /* 禁止指针 */
WAIT, /* 沙漏指针 */
ARROW_WAIT /* 默认指针和小沙漏 */
};
public:
// 修改窗口大小
static void setSize(
@ -178,6 +189,76 @@ class Input
{
friend Game;
public:
// 鼠标键值
enum class MouseCode : int
{
LEFT, /* 鼠标左键 */
RIGHT, /* 鼠标右键 */
MIDDLE /* 鼠标中键 */
};
// 键盘键值
enum class KeyCode : int
{
UP = 0xC8,
LEFT = 0xCB,
RIGHT = 0xCD,
DOWN = 0xD0,
ENTER = 0x1C,
SPACE = 0x39,
ESC = 0x01,
BACK = 0x0E,
TAB = 0x0F,
PAUSE = 0xC5,
Q = 0x10,
W = 0x11,
E = 0x12,
R = 0x13,
T = 0x14,
Y = 0x15,
U = 0x16,
I = 0x17,
O = 0x18,
P = 0x19,
A = 0x1E,
S = 0x1F,
D = 0x20,
F = 0x21,
G = 0x22,
H = 0x23,
J = 0x24,
K = 0x25,
L = 0x26,
Z = 0x2C,
X = 0x2D,
C = 0x2E,
V = 0x2F,
B = 0x30,
N = 0x31,
M = 0x32,
NUM1 = 0x02,
NUM2 = 0x03,
NUM3 = 0x04,
NUM4 = 0x05,
NUM5 = 0x06,
NUM6 = 0x07,
NUM7 = 0x08,
NUM8 = 0x09,
NUM9 = 0x0A,
NUM0 = 0x0B,
NUMPAD7 = 0x47,
NUMPAD8 = 0x48,
NUMPAD9 = 0x49,
NUMPAD4 = 0x4B,
NUMPAD5 = 0x4C,
NUMPAD6 = 0x4D,
NUMPAD1 = 0x4F,
NUMPAD2 = 0x50,
NUMPAD3 = 0x51,
NUMPAD0 = 0x52
};
public:
// 检测键盘某按键是否正被按下
static bool isKeyDown(
@ -194,32 +275,20 @@ public:
KeyCode key
);
// 检测鼠标左键是否正被按下
static bool isMouseLButtonDown();
// 检测鼠标按键是否正被按下
static bool isMouseDown(
MouseCode code
);
// 检测鼠标右键是否正被按下
static bool isMouseRButtonDown();
// 检测鼠标按键是否被点击
static bool isMousePress(
MouseCode code
);
// 检测鼠标中键是否正被按下
static bool isMouseMButtonDown();
// 检测鼠标左键是否被点击
static bool isMouseLButtonPress();
// 检测鼠标右键是否被点击
static bool isMouseRButtonPress();
// 检测鼠标中键是否被点击
static bool isMouseMButtonPress();
// 检测鼠标左键是否正在松开
static bool isMouseLButtonRelease();
// 检测鼠标右键是否正在松开
static bool isMouseRButtonRelease();
// 检测鼠标中键是否正在松开
static bool isMouseMButtonRelease();
// 检测鼠标按键是否正在松开
static bool isMouseRelease(
MouseCode code
);
// 获得鼠标X轴坐标值
static double getMouseX();

View File

@ -15,6 +15,25 @@ class Collider :
friend ColliderManager;
friend Node;
public:
// 碰撞体类别
enum class Type : int
{
RECT, /* 矩形 */
CIRCLE, /* 圆形 */
ELLIPSE /* 椭圆形 */
};
// 碰撞体交集关系
enum class Relation : int
{
UNKNOWN = 0, /* 关系不确定 */
DISJOINT = 1, /* 没有交集 */
IS_CONTAINED = 2, /* 完全被包含 */
CONTAINS = 3, /* 完全包含 */
OVERLAP = 4 /* 部分重叠 */
};
public:
Collider();

View File

@ -225,43 +225,32 @@ public:
);
Color(
UINT32 rgb
UINT rgb
);
Color(
UINT32 rgb,
UINT rgb,
double alpha
);
D2D1_COLOR_F toColorF() const;
D2D1_COLOR_F toD2DColorF() const;
public:
enum RGB_VALUE : UINT32
enum RGB_VALUE : UINT
{
ALICE_BLUE = 0xF0F8FF,
AQUA = 0x00FFFF,
AZURE = 0xF0FFFF,
BEIGE = 0xF5F5DC,
BLACK = 0x000000,
BLUE = 0x0000FF,
BLUE_VIOLET = 0x8A2BE2,
BROWN = 0xA52A2A,
CHOCOLATE = 0xD2691E,
CYAN = 0x00FFFF,
DARK_BLUE = 0x00008B,
DARK_CYAN = 0x008B8B,
DARK_GOLDENROD = 0xB8860B,
DARK_GRAY = 0xA9A9A9,
DARK_GREEN = 0x006400,
DARK_ORANGE = 0xFF8C00,
DARK_RED = 0x8B0000,
DARK_SEA_GREEN = 0x8FBC8F,
DARK_VIOLET = 0x9400D3,
DEEP_PINK = 0xFF1493,
DEEP_SKY_BLUE = 0x00BFFF,
FOREST_GREEN = 0x228B22,
GOLD = 0xFFD700,
GOLDENROD = 0xDAA520,
GRAY = 0x808080,
GREEN = 0x008000,
GREEN_YELLOW = 0xADFF2F,
@ -275,24 +264,14 @@ public:
LIGHT_SKY_BLUE = 0x87CEFA,
LIGHT_SLATE_GRAY = 0x778899,
LIGHT_YELLOW = 0xFFFFE0,
MEDIUM_BLUE = 0x0000CD,
MEDIUM_PURPLE = 0x9370DB,
MEDIUM_SEA_GREEN = 0x3CB371,
MEDIUM_SPRING_GREEN = 0x00FA9A,
MEDUIM_VIOLET_RED = 0xC71585,
MIDNIGHT_BLUE = 0x191970,
ORANGE = 0xFFA500,
ORANGE_RED = 0xFF4500,
PINK = 0xFFC0CB,
PURPLE = 0x800080,
RED = 0xFF0000,
SEA_GREEN = 0x2E8B57,
SEA_SHELL = 0xFFF5EE,
SILVER = 0xC0C0C0,
SKY_BLUE = 0x87CEEB,
SNOW = 0xFFFAFA,
SPRING_GREEN = 0x00FF7F,
TOMATO = 0xFF6347,
VIOLET = 0xEE82EE,
WHEAT = 0xF5DEB3,
WHITE = 0xFFFFFF,
@ -304,7 +283,7 @@ public:
protected:
void _init(
UINT32 rgb,
UINT rgb,
double alpha
);
@ -316,115 +295,6 @@ public:
};
// 字体粗细值
class FontWeight
{
public:
enum : UINT32
{
THIN = 100,
EXTRA_LIGHT = 200,
ULTRA_LIGHT = 200,
LIGHT = 300,
SEMI_LIGHT = 350,
NORMAL = 400,
REGULAR = 400,
MEDIUM = 500,
DEMI_BOLD = 600,
SEMI_BOLD = 600,
BOLD = 700,
EXTRA_BOLD = 800,
ULTRA_BOLD = 800,
BLACK = 900,
HEAVY = 900,
EXTRA_BLACK = 950,
ULTRA_BLACK = 950
};
};
// 文本对齐方式
enum class TextAlign : int
{
LEFT, /* 左对齐 */
RIGHT, /* 右对齐 */
CENTER /* 居中对齐 */
};
// 键值集合
enum class KeyCode : int
{
UP = 0xC8,
LEFT = 0xCB,
RIGHT = 0xCD,
DOWN = 0xD0,
ENTER = 0x1C,
SPACE = 0x39,
ESC = 0x01,
BACK = 0x0E,
TAB = 0x0F,
PAUSE = 0xC5,
Q = 0x10,
W = 0x11,
E = 0x12,
R = 0x13,
T = 0x14,
Y = 0x15,
U = 0x16,
I = 0x17,
O = 0x18,
P = 0x19,
A = 0x1E,
S = 0x1F,
D = 0x20,
F = 0x21,
G = 0x22,
H = 0x23,
J = 0x24,
K = 0x25,
L = 0x26,
Z = 0x2C,
X = 0x2D,
C = 0x2E,
V = 0x2F,
B = 0x30,
N = 0x31,
M = 0x32,
NUM1 = 0x02,
NUM2 = 0x03,
NUM3 = 0x04,
NUM4 = 0x05,
NUM5 = 0x06,
NUM6 = 0x07,
NUM7 = 0x08,
NUM8 = 0x09,
NUM9 = 0x0A,
NUM0 = 0x0B,
NUMPAD7 = 0x47,
NUMPAD8 = 0x48,
NUMPAD9 = 0x49,
NUMPAD4 = 0x4B,
NUMPAD5 = 0x4C,
NUMPAD6 = 0x4D,
NUMPAD1 = 0x4F,
NUMPAD2 = 0x50,
NUMPAD3 = 0x51,
NUMPAD0 = 0x52
};
// 鼠标指针样式
enum class Cursor : int
{
NORMAL, /* 默认指针样式 */
HAND, /* 手状指针 */
NO, /* 禁止指针 */
WAIT, /* 沙漏指针 */
ARROW_WAIT /* 默认指针和小沙漏 */
};
// 方向
enum class Direction : int
{
@ -435,17 +305,6 @@ enum class Direction : int
};
// 物体交集关系
enum class Relation : int
{
UNKNOWN = 0, /* 关系不确定 */
DISJOINT = 1, /* 没有交集 */
IS_CONTAINED = 2, /* 完全被包含 */
CONTAINS = 3, /* 完全包含 */
OVERLAP = 4 /* 部分重叠 */
};
// 线条相交样式
enum class LineJoin : int
{
@ -455,86 +314,6 @@ enum class LineJoin : int
};
// 形状样式
enum class ShapeStyle : int
{
SOLID, /* 填充 */
ROUND, /* 轮廓 */
FILL, /* 轮廓 + 填充 */
};
// 碰撞体类别
enum class ColliderType : int
{
RECT, /* 矩形 */
CIRCLE, /* 圆形 */
ELLIPSE /* 椭圆形 */
};
// 文本样式
class TextStyle
{
public:
String fontFamily; // 字体
double fontSize; // 字号
Color color; // 颜色
UINT32 fontWeight; // 粗细值
bool italic; // 斜体
TextAlign alignment; // 对齐方式
bool wrapping; // 打开自动换行
double wrappingWidth; // 自动换行宽度
double lineSpacing; // 行间距
bool hasUnderline; // 下划线
bool hasStrikethrough; // 删除线
bool hasOutline; // 显示描边
Color outlineColor; // 描边颜色
double outlineWidth; // 描边线宽
LineJoin outlineJoin; // 描边线相交样式
public:
TextStyle();
TextStyle(
const String& fontFamily,
double fontSize = 22,
Color color = Color::WHITE,
UINT32 fontWeight = FontWeight::NORMAL,
bool italic = false,
TextAlign alignment = TextAlign::LEFT,
bool wrapping = false,
double wrappingWidth = 0.0,
double lineSpacing = 0.0,
bool hasUnderline = false,
bool hasStrikethrough = false,
bool hasOutline = true,
Color outlineColor = Color(Color::BLACK, 0.5),
double outlineWidth = 1.0,
LineJoin outlineJoin = LineJoin::ROUND
);
};
// 节点属性
struct NodeProperty
{
bool visable; // 可见性
double posX; // X 坐标
double posY; // Y 坐标
double width; // 宽度
double height; // 高度
double opacity; // 透明度
double pivotX; // 中心点 X 坐标
double pivotY; // 中心点 Y 坐标
double scaleX; // 横向缩放
double scaleY; // 纵向缩放
double rotation; // 旋转角度
double skewAngleX; // 横向倾斜角度
double skewAngleY; // 纵向倾斜角度
};
// 函数对象
class Function
{

View File

@ -1,5 +1,6 @@
#pragma once
#include "e2dbase.h"
#include "e2dcollider.h"
namespace e2d
{
@ -7,7 +8,6 @@ namespace e2d
class Action;
class Transition;
class Collider;
class ColliderManager;
class Node :
@ -18,6 +18,25 @@ class Node :
friend Transition;
friend ColliderManager;
public:
// 节点属性
struct Property
{
bool visable; // 可见性
double posX; // X 坐标
double posY; // Y 坐标
double width; // 宽度
double height; // 高度
double opacity; // 透明度
double pivotX; // 中心点 X 坐标
double pivotY; // 中心点 Y 坐标
double scaleX; // 横向缩放
double scaleY; // 纵向缩放
double rotation; // 旋转角度
double skewAngleX; // 横向倾斜角度
double skewAngleY; // 纵向倾斜角度
};
public:
Node();
@ -114,7 +133,7 @@ public:
virtual double getOpacity() const;
// 获取节点属性
virtual NodeProperty getProperty() const;
virtual Property getProperty() const;
// 获取节点碰撞体
virtual Collider * getCollider() const;
@ -323,12 +342,12 @@ public:
// 设置节点属性
virtual void setProperty(
NodeProperty prop
Property prop
);
// 设置碰撞体
virtual void setCollider(
ColliderType nColliderType
Collider::Type type
);
// 设置碰撞体
@ -590,71 +609,101 @@ protected:
class Text :
public Node
{
public:
// 字体
class Font
{
public:
String family; // 字体族
double size; // 字号
UINT weight; // 粗细值
bool italic; // 斜体
public:
// 字体粗细值
enum Weight : UINT
{
THIN = 100,
EXTRA_LIGHT = 200,
LIGHT = 300,
SEMI_LIGHT = 350,
NORMAL = 400,
MEDIUM = 500,
DEMI_BOLD = 600,
BOLD = 700,
EXTRA_BOLD = 800,
BLACK = 900,
EXTRA_BLACK = 950
};
public:
Font();
Font(
const String& family,
double size = 22,
UINT weight = Font::Weight::NORMAL,
bool italic = false
);
};
// 文本对齐方式
enum class Align : int
{
LEFT, /* 左对齐 */
RIGHT, /* 右对齐 */
CENTER /* 居中对齐 */
};
// 文本样式
class Style
{
public:
Color color; // 颜色
Align alignment; // 对齐方式
bool wrapping; // 打开自动换行
double wrappingWidth; // 自动换行宽度
double lineSpacing; // 行间距
bool hasUnderline; // 下划线
bool hasStrikethrough; // 删除线
bool hasOutline; // 显示描边
Color outlineColor; // 描边颜色
double outlineWidth; // 描边线宽
LineJoin outlineJoin; // 描边线相交样式
public:
Style();
Style(
Color color,
Align alignment = Align::LEFT,
bool wrapping = false,
double wrappingWidth = 0.0,
double lineSpacing = 0.0,
bool hasUnderline = false,
bool hasStrikethrough = false,
bool hasOutline = true,
Color outlineColor = Color(Color::BLACK, 0.5),
double outlineWidth = 1.0,
LineJoin outlineJoin = LineJoin::ROUND
);
};
public:
Text();
Text(
const String& text /* 文字内容 */
);
Text(
TextStyle textStyle /* 文字样式 */
);
Text(
const String& text, /* 文字内容 */
TextStyle textStyle /* 文字样式 */
);
Text(
const String& text, /* 文字内容*/
const String& fontFamily, /* 字体 */
double fontSize = 22, /* 字号 */
UINT32 color = Color::WHITE, /* 颜色 */
UINT32 fontWeight = FontWeight::NORMAL, /* 粗细值 */
bool italic = false, /* 斜体 */
TextAlign alignment = TextAlign::LEFT, /* 对齐方式 */
bool wrapping = false, /* 打开自动换行 */
double wrappingWidth = 0.0, /* 自动换行宽度 */
double lineSpacing = 0.0, /* 行间距 */
bool hasUnderline = false, /* 下划线 */
bool hasStrikethrough = false, /* 删除线 */
bool hasOutline = true, /* 显示描边 */
UINT32 outlineColor = Color::BLACK, /* 描边颜色 */
UINT32 outlineWidth = 1.0 /* 描边线宽 */
const String& text, /* 文字内容 */
const Font& font = Font(), /* 字体 */
const Style& style = Style() /* 文本样式 */
);
static Text * create();
static Text * create(
const String& text /* 文字内容 */
);
static Text * create(
TextStyle textStyle /* 文字样式 */
);
static Text * create(
const String& text, /* 文字内容 */
TextStyle textStyle /* 文字样式 */
);
static Text * create(
const String& text, /* 文字内容*/
const String& fontFamily, /* 字体 */
double fontSize = 22, /* 字号 */
UINT32 color = Color::WHITE, /* 颜色 */
UINT32 fontWeight = FontWeight::NORMAL, /* 粗细值 */
bool italic = false, /* 斜体 */
TextAlign alignment = TextAlign::LEFT, /* 对齐方式 */
bool wrapping = false, /* 打开自动换行 */
double wrappingWidth = 0.0, /* 自动换行宽度 */
double lineSpacing = 0.0, /* 行间距 */
bool hasUnderline = false, /* 下划线 */
bool hasStrikethrough = false, /* 删除线 */
bool hasOutline = true, /* 显示描边 */
UINT32 outlineColor = Color::BLACK, /* 描边颜色 */
UINT32 outlineWidth = 1.0 /* 描边线宽 */
const String& text, /* 文字内容 */
const Font& font = Font(), /* 字体 */
const Style& style = Style() /* 文本样式 */
);
virtual ~Text();
@ -662,17 +711,20 @@ public:
// 获取文本
String getText() const;
// 获取文本样式
TextStyle getTextStyle() const;
// 获取字体
Font getFont() const;
// 获取文本样式
Style getStyle() const;
// 获取字体族
String getFontFamily() const;
// 获取当前字号
double getFontSize() const;
// 获取当前字体粗细值
UINT32 getFontWeight() const;
UINT getFontWeight() const;
// 获取文字颜色
Color getColor() const;
@ -708,22 +760,27 @@ public:
// 设置文本样式
void setStyle(
const TextStyle& textStyle
const Style& style
);
// 设置字体
void setFont(
const Font& font
);
// 设置字体族
void setFontFamily(
const String& fontFamily
const String& family
);
// 设置字号(默认值为 22
void setFontSize(
double fontSize
double size
);
// 设置字体粗细值(默认值为 FontWeight::NORMAL
// 设置字体粗细值(默认值为 Text::Font::Weight::NORMAL
void setFontWeight(
UINT32 fontWeight
UINT weight
);
// 设置文字颜色(默认值为 Color::WHITE
@ -751,9 +808,9 @@ public:
double lineSpacing
);
// 设置对齐方式(默认为 TextAlign::LEFT
// 设置对齐方式(默认为 Align::LEFT
void setAlignment(
TextAlign align
Align align
);
// 设置下划线(默认值为 false
@ -801,7 +858,8 @@ protected:
protected:
String _text;
TextStyle _style;
Font _font;
Style _style;
IDWriteTextFormat * _textFormat;
IDWriteTextLayout * _textLayout;
};

View File

@ -9,13 +9,22 @@ namespace e2d
class Shape :
public Node
{
public:
// ÐÎ×´Ñùʽ
enum class Style : int
{
SOLID, /* Ìî³ä */
ROUND, /* ÂÖÀª */
FILL, /* ÂÖÀª + Ìî³ä */
};
public:
Shape();
virtual ~Shape();
// »ñÈ¡Ñùʽ
ShapeStyle getStyle() const;
Style getStyle() const;
// »ñÈ¡Ìî³äÑÕÉ«
Color getFillColor() const;
@ -42,7 +51,7 @@ public:
);
// ÉèÖÃÑùʽ
void setStyle(ShapeStyle style);
void setStyle(Style style);
// äÖȾÐÎ×´
virtual void onRender() override;
@ -55,7 +64,7 @@ protected:
virtual void _renderFill() = 0;
protected:
ShapeStyle _style;
Style _style;
float _strokeWidth;
Color _lineColor;
Color _fillColor;

View File

@ -226,7 +226,6 @@
<ClCompile Include="..\..\core\Common\Animation.cpp" />
<ClCompile Include="..\..\core\Common\Color.cpp" />
<ClCompile Include="..\..\core\Common\Function.cpp" />
<ClCompile Include="..\..\core\Common\TextStyle.cpp" />
<ClCompile Include="..\..\core\Common\Object.cpp" />
<ClCompile Include="..\..\core\Common\Point.cpp" />
<ClCompile Include="..\..\core\Common\Scene.cpp" />

View File

@ -156,9 +156,6 @@
<ClCompile Include="..\..\core\Custom\CustomTextRenderer.cpp">
<Filter>Custom</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Common\TextStyle.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Common\Color.cpp">
<Filter>Common</Filter>
</ClCompile>