diff --git a/docs/Controls/CircleProgress.md b/docs/Controls/CircleProgress.md new file mode 100644 index 00000000..e425ba3b --- /dev/null +++ b/docs/Controls/CircleProgress.md @@ -0,0 +1,111 @@ +# CircleProgress(环形进度条) + +`CircleProgress` 继承了 `Progress` 控件属性和方法,更多可用属性和方法请参考:[Progress](Progress.md) 控件 + +## 可用属性 + +| 属性名称 | 默认值 | 参数类型 | 用途 | +| :--- | :--- | :--- | :--- | +| circlewidth | 1 | INT | 环形进度条的宽度,如(10) | +| indicator | | STRING | 设置进度指示移动图标 | +| clockwise | true | BOOL |设置递增方向 | +| bgcolor | | STRING | 设置进度条背景颜色 | +| fgcolor | | STRING | 设置进度条背前景色 | +| gradientcolor | | STRING | 设置进度条前景渐变颜色,与 fgcolor 同时使用,可以不设置则无渐变效果 | + +## 可用接口 + +| 接口名称 | 用途 | +| :--- | :--- | +| [SetCircular](#SetCircular) | 设置圆形滚动条样式,默认为普通进度条 | +| [SetClockwiseRotation](#SetClockwiseRotation) | 设置递增方向 | +| [SetCircleWidth](#SetCircleWidth) | 设置圆环宽度 | +| [SetBackgroudColor](#SetBackgroudColor) | 设置进度条背景颜色 | +| [SetForegroudColor](#SetForegroudColor) | 设置进度条前景颜色 | +| [SetCircleGradientColor](#SetCircleGradientColor) | 设置进度条前景渐变颜色,与 SetForegroudColor 同时使用,可以不设置则无渐变效果 | +| [SetIndicator](#SetIndicator) | 设置进度指示移动图标 | + + +### SetCircular + +设置圆形滚动条,默认为普通进度条 + +```cpp +void SetCircular(bool bCircular = true) +``` + + - 参 数: + - `bCircular` bCircular 为 true 时设置为圆形滚动条,false 时设置为父级滚动条,默认为 true + - 返回值:无 + +### SetClockwiseRotation + +设置递增方向 + +```cpp +void SetClockwiseRotation(bool bClockwise = true) +``` + + - 参 数: + - `bClockwise` bClockwise 为 true 时设置为顺时针,false 时设置为逆时针,默认为 true + - 返回值:无 + +### SetCircleWidth + +设置圆环宽度 + +```cpp +void SetCircleWidth(int nCircleWidth) +``` + + - 参 数: + - `nCircleWidth` nCircleWidth 宽度数值 + - 返回值:无 + +### SetBackgroudColor + +设置进度条背景颜色 + +```cpp +void SetBackgroudColor(const std::wstring& strColor) +``` + + - 参 数: + - `strColor` strColor要设置的背景颜色字符串,该字符串必须在 global.xml 中存在 + - 返回值:无 + +### SetForegroudColor + +设置进度条前景颜色 + +```cpp +void SetForegroudColor(const std::wstring& strColor) +``` + + - 参 数: + - `strColor` strColor要设置的前景颜色字符串,该字符串必须在 global.xml 中存在 + - 返回值:无 + +### SetCircleGradientColor + +设置进度条前景渐变颜色,与 SetForegroudColor 同时使用,可以不设置,则无渐变效果 + +```cpp +void SetCircleGradientColor(const std::wstring& strColor) +``` + + - 参 数: + - `strColor` strColor要设置的前景渐变颜色字符串,该字符串必须在 global.xml 中存在 + - 返回值:无 + +### SetIndicator + +设置进度指示移动图标 + +```cpp +void SetIndicator(const std::wstring& sIndicatorImage); +``` + + - 参 数: + - `sIndicatorImage` sIndicatorImage 要设置的图片 + - 返回值:无 diff --git a/docs/Controls/README.md b/docs/Controls/README.md index 17301505..f863f2f1 100644 --- a/docs/Controls/README.md +++ b/docs/Controls/README.md @@ -9,6 +9,7 @@ - [Option](Option.md) ѡ - [Label](Label.md) ı - [Progress](Progress.md) + - [CircleProgress](CircleProgress.md) ν - [Slider](Slider.md) - [RichEdit](RichEdit.md) ı - [ScrollBar](ScrollBar.md) diff --git a/tool_kits/duilib/Control/CircleProgress.cpp b/tool_kits/duilib/Control/CircleProgress.cpp index b1698ff5..63355586 100644 --- a/tool_kits/duilib/Control/CircleProgress.cpp +++ b/tool_kits/duilib/Control/CircleProgress.cpp @@ -4,203 +4,202 @@ namespace ui { - CircleProgress::CircleProgress() : - m_bCircular(true), - m_bClockwise(true), - m_nCircleWidth(1), - m_dwBackgroundColor(0), - m_dwForegroundColor(0), - m_dwGradientColor(0), - m_pIndicator(nullptr) - { - + +CircleProgress::CircleProgress() : + m_bCircular(true), + m_bClockwise(true), + m_nCircleWidth(1), + m_dwBackgroundColor(0), + m_dwForegroundColor(0), + m_dwGradientColor(0), + m_pIndicator(nullptr) +{ + +} + +void CircleProgress::SetAttribute(const std::wstring& srName, const std::wstring& strValue) +{ + if (srName == _T("circular")) SetCircular(strValue == _T("true")); + else if (srName == _T("circlewidth")) SetCircleWidth(_ttoi(strValue.c_str())); + else if (srName == _T("indicator")) SetIndicator(strValue); + else if (srName == _T("clockwise")) SetClockwiseRotation(strValue == _T("true")); + else if (srName == _T("bgcolor")) { + LPCTSTR pValue = strValue.c_str(); + while (*pValue > _T('\0') && *pValue <= _T(' ')) pValue = ::CharNext(pValue); + SetBackgroudColor(pValue); + } + else if (srName == _T("fgcolor")) { + LPCTSTR pValue = strValue.c_str(); + while (*pValue > _T('\0') && *pValue <= _T(' ')) pValue = ::CharNext(pValue); + SetForegroudColor(pValue); } + else if (srName == _T("gradientcolor")) { + LPCTSTR pValue = strValue.c_str(); + while (*pValue > _T('\0') && *pValue <= _T(' ')) pValue = ::CharNext(pValue); + SetCircleGradientColor(pValue); + } + else Progress::SetAttribute(srName, strValue); +} - void CircleProgress::SetAttribute(const std::wstring& srName, const std::wstring& strValue) +void CircleProgress::PaintStatusImage(IRenderContext* pRender) +{ + Progress::PaintStatusImage(pRender); + if (m_bCircular) { - if (srName == _T("circular")) SetCircular(strValue == _T("true")); - else if (srName == _T("circlewidth")) SetCircleWidth(_ttoi(strValue.c_str())); - else if (srName == _T("indicator")) SetIndicator(strValue); - else if (srName == _T("clockwise")) SetClockwiseRotation(strValue == _T("true")); - else if (srName == _T("bgcolor")) { - LPCTSTR pValue = strValue.c_str(); - while (*pValue > _T('\0') && *pValue <= _T(' ')) pValue = ::CharNext(pValue); - SetBackgroudColor(pValue); - } - else if (srName == _T("fgcolor")) { - LPCTSTR pValue = strValue.c_str(); - while (*pValue > _T('\0') && *pValue <= _T(' ')) pValue = ::CharNext(pValue); - SetForegroudColor(pValue); + //ĿǰIRenderContextкܶGDI+ӿδʵ֣ʱֱgdi+ͼ + //Ժܻʵ1DrawArc 2Penbrush() 3Graphics + int direction = m_bClockwise ? 1 : -1; //ת + int bordersize = 1; //ȿĿǰʹ1 + + Gdiplus::Graphics graphics(pRender->GetDC()); + graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); + Gdiplus::Pen bgPen(m_dwBackgroundColor, m_nCircleWidth); + // Բ + CPoint center; + center.x = m_rcItem.left + (m_rcItem.right - m_rcItem.left) / 2; + center.y = m_rcItem.top + (m_rcItem.bottom - m_rcItem.top) / 2; + + // ؼڵεı߽ + int side = min(m_rcItem.right - m_rcItem.left, m_rcItem.bottom - m_rcItem.top); + //UiRect rcBorder; ȻUiRect RectFתֱgdiRectF + Gdiplus::RectF rcBorder; + rcBorder.X = center.x - side / 2; + rcBorder.Y = center.y - side / 2; + rcBorder.Width = rcBorder.Height = side; + + Gdiplus::RectF outer = rcBorder; + if (m_pIndicator) { + outer.Inflate(-1.0F *m_pIndicator->GetWidth() / 2, -1.0F * m_pIndicator->GetWidth() / 2); } - else if (srName == _T("gradientcolor")) { - LPCTSTR pValue = strValue.c_str(); - while (*pValue > _T('\0') && *pValue <= _T(' ')) pValue = ::CharNext(pValue); - SetCircleGradientColor(pValue); - } - else Progress::SetAttribute(srName, strValue); - } + else + { + outer.Inflate(-0.5 * m_nCircleWidth, -0.5 * m_nCircleWidth); + } + outer.Inflate(-1, -1); - void CircleProgress::PaintStatusImage(IRenderContext* pRender) - { - Progress::PaintStatusImage(pRender); - if (m_bCircular) + + if (m_dwGradientColor == 0) { - //ĿǰIRenderContextкܶGDI+ӿδʵ֣ʱֱgdi+ͼ - //Ժܻʵ1DrawArc 2Penbrush() 3Graphics - int direction = m_bClockwise ? 1 : -1; //ת - int bordersize = 1; //ȿĿǰʹ1 - - Gdiplus::Graphics graphics(pRender->GetDC()); - graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); - Gdiplus::Pen bgPen(m_dwBackgroundColor, m_nCircleWidth); - // Բ - CPoint center; - center.x = m_rcItem.left + (m_rcItem.right - m_rcItem.left) / 2; - center.y = m_rcItem.top + (m_rcItem.bottom - m_rcItem.top) / 2; - - // ؼڵεı߽ - int side = min(m_rcItem.right - m_rcItem.left, m_rcItem.bottom - m_rcItem.top); - //UiRect rcBorder; ȻUiRect RectFתֱgdiRectF - Gdiplus::RectF rcBorder; - rcBorder.X = center.x - side / 2; - rcBorder.Y = center.y - side / 2; - rcBorder.Width = rcBorder.Height = side; - - Gdiplus::RectF outer = rcBorder; - if (m_pIndicator) { - outer.Inflate(-1.0F *m_pIndicator->GetWidth() / 2, -1.0F * m_pIndicator->GetWidth() / 2); - } - else - { - outer.Inflate(-0.5 * m_nCircleWidth, -0.5 * m_nCircleWidth); - } - outer.Inflate(-1, -1); - - - if (m_dwGradientColor == 0) - { - //ʹýɫֱǰɫ - Gdiplus::Pen fgPen(m_dwForegroundColor, m_nCircleWidth); - graphics.DrawArc(&bgPen, outer, 270, 360); //270濪ʼΪ0Ļұ߿ʼ - graphics.DrawArc(&fgPen, outer, 270, direction * 360 * (m_nValue - m_nMin) / (m_nMax - m_nMin)); - } - else - { - Gdiplus::REAL factors[4] = { 0.0f, 0.4f, 0.6f, 1.0f }; - Gdiplus::REAL positions[4] = { 0.0f, 0.2f, 0.8f, 1.0f }; - - Gdiplus::LinearGradientBrush lgbrush(rcBorder, m_dwForegroundColor, m_dwGradientColor, Gdiplus::LinearGradientModeVertical); - lgbrush.SetBlend(factors, positions, 4); - graphics.DrawArc(&bgPen, outer, 270, 360); - Gdiplus::Pen fgPen(&lgbrush, m_nCircleWidth); - graphics.DrawArc(&fgPen, outer, 270, direction * 360 * (m_nValue - m_nMin) / (m_nMax - m_nMin)); - - } - - //תָʾͼ꣬Ҫõ - if (m_pIndicator) - { - Gdiplus::Matrix matrix; - matrix.RotateAt(direction * 360 * (m_nValue - m_nMin) / (m_nMax - m_nMin), Gdiplus::PointF(center.x, center.y), Gdiplus::MatrixOrderAppend); - graphics.SetTransform(&matrix); - Gdiplus::RectF rectf; - rectf.X = center.x - m_pIndicator->GetWidth() / 2; - rectf.Y = outer.Y + bordersize / 2 -m_pIndicator->GetHeight() / 2; - rectf.Width = m_pIndicator->GetWidth(); - rectf.Height = m_pIndicator->GetHeight(); - graphics.DrawImage(m_pIndicator, rectf); - } + //ʹýɫֱǰɫ + Gdiplus::Pen fgPen(m_dwForegroundColor, m_nCircleWidth); + graphics.DrawArc(&bgPen, outer, 270, 360); //270濪ʼΪ0Ļұ߿ʼ + graphics.DrawArc(&fgPen, outer, 270, direction * 360 * (m_nValue - m_nMin) / (m_nMax - m_nMin)); + } + else + { + Gdiplus::REAL factors[4] = { 0.0f, 0.4f, 0.6f, 1.0f }; + Gdiplus::REAL positions[4] = { 0.0f, 0.2f, 0.8f, 1.0f }; + + Gdiplus::LinearGradientBrush lgbrush(rcBorder, m_dwForegroundColor, m_dwGradientColor, Gdiplus::LinearGradientModeVertical); + lgbrush.SetBlend(factors, positions, 4); + graphics.DrawArc(&bgPen, outer, 270, 360); + Gdiplus::Pen fgPen(&lgbrush, m_nCircleWidth); + graphics.DrawArc(&fgPen, outer, 270, direction * 360 * (m_nValue - m_nMin) / (m_nMax - m_nMin)); } - } - void CircleProgress::ClearImageCache() - { - __super::ClearImageCache(); + //תָʾͼ꣬Ҫõ if (m_pIndicator) { - delete m_pIndicator; - m_pIndicator = nullptr; + Gdiplus::Matrix matrix; + matrix.RotateAt(direction * 360 * (m_nValue - m_nMin) / (m_nMax - m_nMin), Gdiplus::PointF(center.x, center.y), Gdiplus::MatrixOrderAppend); + graphics.SetTransform(&matrix); + Gdiplus::RectF rectf; + rectf.X = center.x - m_pIndicator->GetWidth() / 2; + rectf.Y = outer.Y + bordersize / 2 - m_pIndicator->GetHeight() / 2; + rectf.Width = m_pIndicator->GetWidth(); + rectf.Height = m_pIndicator->GetHeight(); + graphics.DrawImage(m_pIndicator, rectf); } - } - + } +} - void CircleProgress::SetCircular(bool bCircular /*= true*/) +void CircleProgress::ClearImageCache() +{ + __super::ClearImageCache(); + if (m_pIndicator) { - m_bCircular = bCircular; - Invalidate(); + delete m_pIndicator; + m_pIndicator = nullptr; } +} +void CircleProgress::SetCircular(bool bCircular /*= true*/) +{ + m_bCircular = bCircular; + Invalidate(); +} - void CircleProgress::SetClockwiseRotation(bool bClockwise /*= true*/) +void CircleProgress::SetClockwiseRotation(bool bClockwise /*= true*/) +{ + if (bClockwise != m_bClockwise) { - if (bClockwise != m_bClockwise) + m_bClockwise = bClockwise; + if (m_pIndicator) { - m_bClockwise = bClockwise; - if (m_pIndicator) - { - //ѾתͼƬת෴ķ - m_pIndicator->RotateFlip(Gdiplus::Rotate180FlipNone); - } - + //ѾתͼƬת෴ķ + m_pIndicator->RotateFlip(Gdiplus::Rotate180FlipNone); } - } - void CircleProgress::SetCircleWidth(int nCircleWidth) - { - m_nCircleWidth = nCircleWidth; - Invalidate(); } +} +void CircleProgress::SetCircleWidth(int nCircleWidth) +{ + m_nCircleWidth = nCircleWidth; + Invalidate(); +} - void CircleProgress::SetBackgroudColor(const std::wstring& strColor) - { - m_dwBackgroundColor = GlobalManager::GetTextColor(strColor); - ASSERT(m_dwBackgroundColor != 0); - Invalidate(); - } - void CircleProgress::SetForegroudColor(const std::wstring& strColor) - { - m_dwForegroundColor = GlobalManager::GetTextColor(strColor); - ASSERT(m_dwForegroundColor != 0); - Invalidate(); - } +void CircleProgress::SetBackgroudColor(const std::wstring& strColor) +{ + m_dwBackgroundColor = GlobalManager::GetTextColor(strColor); + ASSERT(m_dwBackgroundColor != 0); + Invalidate(); +} + +void CircleProgress::SetForegroudColor(const std::wstring& strColor) +{ + m_dwForegroundColor = GlobalManager::GetTextColor(strColor); + ASSERT(m_dwForegroundColor != 0); + Invalidate(); +} - void CircleProgress::SetIndicator(const std::wstring& sIndicatorImage) +void CircleProgress::SetIndicator(const std::wstring& sIndicatorImage) +{ + if (m_sIndicatorImage != sIndicatorImage) { - if (m_sIndicatorImage != sIndicatorImage) + m_sIndicatorImage = sIndicatorImage; + if (m_pIndicator) { - m_sIndicatorImage = sIndicatorImage; - if (m_pIndicator) - { - delete m_pIndicator; - m_pIndicator = nullptr; - } - std::wstring imagepath = m_sIndicatorImage; - if (!::PathFileExistsW(imagepath.c_str())) { - imagepath = GlobalManager::GetResourcePath() + m_pWindow->GetWindowResourcePath() + imagepath; - } - if (!::PathFileExistsW(imagepath.c_str())) { - return; - } - m_pIndicator = new Gdiplus::Image(imagepath.c_str()); - - Gdiplus::Status state = m_pIndicator->GetLastStatus(); - if (Gdiplus::Ok == state) - { - // ٶͼƬָ - m_pIndicator->RotateFlip(m_bClockwise ? Gdiplus::Rotate90FlipNone : Gdiplus::Rotate270FlipNone); - Invalidate(); - } + delete m_pIndicator; + m_pIndicator = nullptr; } - } + std::wstring imagepath = m_sIndicatorImage; + if (!::PathFileExistsW(imagepath.c_str())) { + imagepath = GlobalManager::GetResourcePath() + m_pWindow->GetWindowResourcePath() + imagepath; + } + if (!::PathFileExistsW(imagepath.c_str())) { + return; + } + m_pIndicator = new Gdiplus::Image(imagepath.c_str()); - void CircleProgress::SetCircleGradientColor(const std::wstring& strColor) - { - m_dwGradientColor = GlobalManager::GetTextColor(strColor); - ASSERT(m_dwGradientColor != 0); - Invalidate(); + Gdiplus::Status state = m_pIndicator->GetLastStatus(); + if (Gdiplus::Ok == state) + { + // ٶͼƬָ + m_pIndicator->RotateFlip(m_bClockwise ? Gdiplus::Rotate90FlipNone : Gdiplus::Rotate270FlipNone); + Invalidate(); + } } } + +void CircleProgress::SetCircleGradientColor(const std::wstring& strColor) +{ + m_dwGradientColor = GlobalManager::GetTextColor(strColor); + ASSERT(m_dwGradientColor != 0); + Invalidate(); +} + +} diff --git a/tool_kits/duilib/Control/CircleProgress.h b/tool_kits/duilib/Control/CircleProgress.h index 069dd1a2..b2288c62 100644 --- a/tool_kits/duilib/Control/CircleProgress.h +++ b/tool_kits/duilib/Control/CircleProgress.h @@ -13,71 +13,71 @@ namespace ui { - class UILIB_API CircleProgress : public Progress - { - public: - CircleProgress(); +class UILIB_API CircleProgress : public Progress +{ +public: + CircleProgress(); + + /// д෽ṩԻܣο + virtual void SetAttribute(const std::wstring& strName, const std::wstring& strValue) override; + virtual void PaintStatusImage(IRenderContext* pRender) override; + virtual void ClearImageCache() override; - /// д෽ṩԻܣο - virtual void SetAttribute(const std::wstring& strName, const std::wstring& strValue) override; - virtual void PaintStatusImage(IRenderContext* pRender) override; - virtual void ClearImageCache() override; + /** + * @brief ԲιĬΪͨ + * @param[in] bCircular Ϊ true ʱΪԲιfalse ʱΪĬΪ true + * @return + */ + void SetCircular(bool bCircular = true); + /** + * @brief õ + * @param[in] bClockwise Ϊ true ʱΪ˳ʱ룬false ʱΪʱ룬ĬΪ true + * @return + */ + void SetClockwiseRotation(bool bClockwise = true); + /** + * @brief Բ + * @param[in] nCircleWidth ֵ + * @return + */ + void SetCircleWidth(int nCircleWidth); + /** + * @brief ýɫ + * @param[in] strColorҪõıɫַַ global.xml д + * @return + */ + void SetBackgroudColor(const std::wstring& strColor); + /** + * @brief ýǰɫ + * @param[in] strColorҪõǰɫַַ global.xml д + * @return + */ + void SetForegroudColor(const std::wstring& strColor); + /** + * @brief ýǰɫ SetForegroudColor ͬʱʹãԲ,޽Ч + * @param[in] strColorҪõǰɫַַ global.xml д + * @return + */ + void SetCircleGradientColor(const std::wstring& strColor); + /** + * @brief ýָʾƶͼ + * @param[in] sIndicatorImage ҪõͼƬ + * @return + */ + void SetIndicator(const std::wstring& sIndicatorImage); - /** - * @brief Բι - * @param[in] bCircular Ϊ true ʱΪԲιfalse ʱΪĬΪ true - * @return - */ - void SetCircular(bool bCircular = true); - /** - * @brief õ - * @param[in] bClockwise Ϊ true ʱΪ˳ʱ룬false ʱΪʱ룬ĬΪ true - * @return - */ - void SetClockwiseRotation(bool bClockwise = true); - /** - * @brief Բ - * @param[in] nCircleWidth ֵ - * @return - */ - void SetCircleWidth(int nCircleWidth); - /** - * @brief ýɫ - * @param[in] strColorҪõıɫַַ global.xml д - * @return - */ - void SetBackgroudColor(const std::wstring& strColor); - /** - * @brief ýǰɫ - * @param[in] strColorҪõǰɫַַ global.xml д - * @return - */ - void SetForegroudColor(const std::wstring& strColor); - /** - * @brief ýǰɫForegroudColorͬʱʹãԲ,޽Ч - * @param[in] strColorҪõǰɫַַ global.xml д - * @return - */ - void SetCircleGradientColor(const std::wstring& strColor); - /** - * @brief ýָʾƶͼ - * @param[in] sIndicatorImageҪõͼƬ - * @return - */ - void SetIndicator(const std::wstring& sIndicatorImage); - - protected: - bool m_bCircular; - bool m_bClockwise; - int m_nCircleWidth; - DWORD m_dwBackgroundColor; - DWORD m_dwForegroundColor; - DWORD m_dwGradientColor; - //Image m_IndicatorImage; //ʹimage޷Ҫþ任 - Gdiplus::Image* m_pIndicator; //ĿǰάԴ - std::wstring m_sIndicatorImage; +protected: + bool m_bCircular; + bool m_bClockwise; + int m_nCircleWidth; + DWORD m_dwBackgroundColor; + DWORD m_dwForegroundColor; + DWORD m_dwGradientColor; + //Image m_IndicatorImage; //ʹimage޷Ҫþ任 + Gdiplus::Image* m_pIndicator; //ĿǰάԴ + std::wstring m_sIndicatorImage; - }; +}; } // namespace ui