From d3922a93a096e07ab54e91fd0dd7c86302f33b78 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 22 Mar 2019 10:16:39 +0900 Subject: Rename DrawCommand* to WidgetDrawAction*, remove unused circ draw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Icef900e75255d477812a198fdb29e0cdebba35b8 Reviewed-on: https://gerrit.libreoffice.org/69654 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- vcl/inc/widgetdraw/WidgetDefinition.hxx | 66 ++++++--------- .../widgetdraw/WidgetDefinitionReaderTest.cxx | 13 +-- vcl/qa/cppunit/widgetdraw/data/definition1.xml | 8 +- vcl/source/gdi/FileDefinitionWidgetDraw.cxx | 99 +++++++++------------- vcl/source/gdi/WidgetDefinition.cxx | 31 ++----- vcl/source/gdi/WidgetDefinitionReader.cxx | 25 ------ 6 files changed, 86 insertions(+), 156 deletions(-) (limited to 'vcl') diff --git a/vcl/inc/widgetdraw/WidgetDefinition.hxx b/vcl/inc/widgetdraw/WidgetDefinition.hxx index 77baf0922cd8..d5f5b3728abd 100644 --- a/vcl/inc/widgetdraw/WidgetDefinition.hxx +++ b/vcl/inc/widgetdraw/WidgetDefinition.hxx @@ -24,32 +24,40 @@ namespace vcl { -enum class DrawCommandType +enum class WidgetDrawActionType { RECTANGLE, - CIRCLE, LINE, IMAGE, EXTERNAL }; -class VCL_DLLPUBLIC DrawCommand +class VCL_DLLPUBLIC WidgetDrawAction { public: - DrawCommand(DrawCommandType aType) + WidgetDrawAction(WidgetDrawActionType aType) : maType(aType) - , mnStrokeWidth(-1) { } - DrawCommandType maType; + WidgetDrawActionType maType; +}; + +class VCL_DLLPUBLIC WidgetDrawActionShape : public WidgetDrawAction +{ +public: + WidgetDrawActionShape(WidgetDrawActionType aType) + : WidgetDrawAction(aType) + , mnStrokeWidth(-1) + { + } Color maStrokeColor; Color maFillColor; sal_Int32 mnStrokeWidth; }; -class VCL_DLLPUBLIC RectangleDrawCommand : public DrawCommand +class VCL_DLLPUBLIC WidgetDrawActionRectangle : public WidgetDrawActionShape { public: sal_Int32 mnRx; @@ -60,8 +68,8 @@ public: float mfX2; float mfY2; - RectangleDrawCommand() - : DrawCommand(DrawCommandType::RECTANGLE) + WidgetDrawActionRectangle() + : WidgetDrawActionShape(WidgetDrawActionType::RECTANGLE) , mnRx(0) , mnRy(0) , mfX1(0.0f) @@ -72,25 +80,7 @@ public: } }; -class VCL_DLLPUBLIC CircleDrawCommand : public DrawCommand -{ -public: - float mfX1; - float mfY1; - float mfX2; - float mfY2; - - CircleDrawCommand() - : DrawCommand(DrawCommandType::CIRCLE) - , mfX1(0.0f) - , mfY1(0.0f) - , mfX2(1.0f) - , mfY2(1.0f) - { - } -}; - -class VCL_DLLPUBLIC LineDrawCommand : public DrawCommand +class VCL_DLLPUBLIC WidgetDrawActionLine : public WidgetDrawActionShape { public: float mfX1; @@ -98,30 +88,30 @@ public: float mfX2; float mfY2; - LineDrawCommand() - : DrawCommand(DrawCommandType::LINE) + WidgetDrawActionLine() + : WidgetDrawActionShape(WidgetDrawActionType::LINE) { } }; -class VCL_DLLPUBLIC ImageDrawCommand : public DrawCommand +class VCL_DLLPUBLIC WidgetDrawActionImage : public WidgetDrawAction { public: OUString msSource; - ImageDrawCommand() - : DrawCommand(DrawCommandType::IMAGE) + WidgetDrawActionImage() + : WidgetDrawAction(WidgetDrawActionType::IMAGE) { } }; -class VCL_DLLPUBLIC ExternalSourceDrawCommand : public DrawCommand +class VCL_DLLPUBLIC WidgetDrawActionExternal : public WidgetDrawAction { public: OUString msSource; - ExternalSourceDrawCommand() - : DrawCommand(DrawCommandType::EXTERNAL) + WidgetDrawActionExternal() + : WidgetDrawAction(WidgetDrawActionType::EXTERNAL) { } }; @@ -179,12 +169,10 @@ public: OString const& sSelected, OString const& sButtonValue, OString const& sExtra); - std::vector> mpDrawCommands; + std::vector> mpWidgetDrawActions; void addDrawRectangle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor, float fX1, float fY1, float fX2, float fY2, sal_Int32 nRx, sal_Int32 nRy); - void addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor, float fX1, - float fY1, float fX2, float fY2); void addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1, float fY1, float fX2, float fY2); diff --git a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx index 75dc559067fc..843f449b7901 100644 --- a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx +++ b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx @@ -62,10 +62,11 @@ void WidgetDefinitionReaderTest::testRead() CPPUNIT_ASSERT_EQUAL(size_t(2), aStates.size()); - CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpDrawCommands.size()); - CPPUNIT_ASSERT_EQUAL(vcl::DrawCommandType::RECTANGLE, - aStates[0]->mpDrawCommands[0]->maType); - CPPUNIT_ASSERT_EQUAL(vcl::DrawCommandType::CIRCLE, aStates[0]->mpDrawCommands[1]->maType); + CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpWidgetDrawActions.size()); + CPPUNIT_ASSERT_EQUAL(vcl::WidgetDrawActionType::RECTANGLE, + aStates[0]->mpWidgetDrawActions[0]->maType); + CPPUNIT_ASSERT_EQUAL(vcl::WidgetDrawActionType::LINE, + aStates[0]->mpWidgetDrawActions[1]->maType); } // Radiobutton @@ -75,7 +76,7 @@ void WidgetDefinitionReaderTest::testRead() ->getStates(ControlType::Radiobutton, ControlPart::Entire, ControlState::NONE, ImplControlValue(ButtonValue::On)); CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size()); - CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpDrawCommands.size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpWidgetDrawActions.size()); } { @@ -84,7 +85,7 @@ void WidgetDefinitionReaderTest::testRead() ->getStates(ControlType::Radiobutton, ControlPart::Entire, ControlState::NONE, ImplControlValue(ButtonValue::Off)); CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size()); - CPPUNIT_ASSERT_EQUAL(size_t(1), aStates[0]->mpDrawCommands.size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), aStates[0]->mpWidgetDrawActions.size()); } } diff --git a/vcl/qa/cppunit/widgetdraw/data/definition1.xml b/vcl/qa/cppunit/widgetdraw/data/definition1.xml index 4fb1c4230853..041e8fc24754 100644 --- a/vcl/qa/cppunit/widgetdraw/data/definition1.xml +++ b/vcl/qa/cppunit/widgetdraw/data/definition1.xml @@ -56,7 +56,7 @@ - + @@ -71,11 +71,11 @@ - + - - + + diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx index 1263c1a12aee..0cfe446f53a3 100644 --- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx +++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx @@ -253,97 +253,76 @@ void drawFromDrawCommands(gfx::DrawRoot const& rDrawRoot, SalGraphics& rGraphics } } -void munchDrawCommands(std::vector> const& rDrawCommands, +void munchDrawCommands(std::vector> const& rDrawActions, SalGraphics& rGraphics, long nX, long nY, long nWidth, long nHeight) { - for (std::shared_ptr const& pDrawCommand : rDrawCommands) + for (std::shared_ptr const& pDrawAction : rDrawActions) { - switch (pDrawCommand->maType) + switch (pDrawAction->maType) { - case DrawCommandType::RECTANGLE: + case WidgetDrawActionType::RECTANGLE: { - auto const& rRectDrawCommand - = static_cast(*pDrawCommand); + auto const& rWidgetDraw + = static_cast(*pDrawAction); basegfx::B2DRectangle rRect( - nX + (nWidth * rRectDrawCommand.mfX1), nY + (nHeight * rRectDrawCommand.mfY1), - nX + (nWidth * rRectDrawCommand.mfX2), nY + (nHeight * rRectDrawCommand.mfY2)); + nX + (nWidth * rWidgetDraw.mfX1), nY + (nHeight * rWidgetDraw.mfY1), + nX + (nWidth * rWidgetDraw.mfX2), nY + (nHeight * rWidgetDraw.mfY2)); basegfx::B2DPolygon aB2DPolygon = basegfx::utils::createPolygonFromRect( - rRect, rRectDrawCommand.mnRx / rRect.getWidth() * 2.0, - rRectDrawCommand.mnRy / rRect.getHeight() * 2.0); + rRect, rWidgetDraw.mnRx / rRect.getWidth() * 2.0, + rWidgetDraw.mnRy / rRect.getHeight() * 2.0); rGraphics.SetLineColor(); - rGraphics.SetFillColor(rRectDrawCommand.maFillColor); + rGraphics.SetFillColor(rWidgetDraw.maFillColor); rGraphics.DrawPolyPolygon(basegfx::B2DHomMatrix(), basegfx::B2DPolyPolygon(aB2DPolygon), 0.0f, nullptr); - rGraphics.SetLineColor(rRectDrawCommand.maStrokeColor); + rGraphics.SetLineColor(rWidgetDraw.maStrokeColor); rGraphics.SetFillColor(); - rGraphics.DrawPolyLine(basegfx::B2DHomMatrix(), aB2DPolygon, 0.0f, - basegfx::B2DVector(rRectDrawCommand.mnStrokeWidth, - rRectDrawCommand.mnStrokeWidth), - basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND, - 0.0f, false, nullptr); + rGraphics.DrawPolyLine( + basegfx::B2DHomMatrix(), aB2DPolygon, 0.0f, + basegfx::B2DVector(rWidgetDraw.mnStrokeWidth, rWidgetDraw.mnStrokeWidth), + basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND, 0.0f, false, nullptr); } break; - case DrawCommandType::CIRCLE: + case WidgetDrawActionType::LINE: { - auto const& rCircleDrawCommand - = static_cast(*pDrawCommand); - - basegfx::B2DRectangle rRect(nX + (nWidth * rCircleDrawCommand.mfX1), - nY + (nHeight * rCircleDrawCommand.mfY1), - nX + (nWidth * rCircleDrawCommand.mfX2), - nY + (nHeight * rCircleDrawCommand.mfY2)); - - basegfx::B2DPolygon aB2DPolygon = basegfx::utils::createPolygonFromEllipse( - rRect.getCenter(), rRect.getWidth() / 2.0, rRect.getHeight() / 2.0); - - rGraphics.SetLineColor(rCircleDrawCommand.maStrokeColor); - rGraphics.SetFillColor(rCircleDrawCommand.maFillColor); - rGraphics.DrawPolyPolygon(basegfx::B2DHomMatrix(), - basegfx::B2DPolyPolygon(aB2DPolygon), 0.0f, nullptr); - } - break; - case DrawCommandType::LINE: - { - auto const& rLineDrawCommand = static_cast(*pDrawCommand); + auto const& rWidgetDraw = static_cast(*pDrawAction); Point aRectPoint(nX + 1, nY + 1); Size aRectSize(nWidth - 1, nHeight - 1); rGraphics.SetFillColor(); - rGraphics.SetLineColor(rLineDrawCommand.maStrokeColor); + rGraphics.SetLineColor(rWidgetDraw.maStrokeColor); basegfx::B2DPolygon aB2DPolygon{ - { aRectPoint.X() + (aRectSize.Width() * rLineDrawCommand.mfX1), - aRectPoint.Y() + (aRectSize.Height() * rLineDrawCommand.mfY1) }, - { aRectPoint.X() + (aRectSize.Width() * rLineDrawCommand.mfX2), - aRectPoint.Y() + (aRectSize.Height() * rLineDrawCommand.mfY2) }, + { aRectPoint.X() + (aRectSize.Width() * rWidgetDraw.mfX1), + aRectPoint.Y() + (aRectSize.Height() * rWidgetDraw.mfY1) }, + { aRectPoint.X() + (aRectSize.Width() * rWidgetDraw.mfX2), + aRectPoint.Y() + (aRectSize.Height() * rWidgetDraw.mfY2) }, }; - rGraphics.DrawPolyLine(basegfx::B2DHomMatrix(), aB2DPolygon, 0.0f, - basegfx::B2DVector(rLineDrawCommand.mnStrokeWidth, - rLineDrawCommand.mnStrokeWidth), - basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND, - 0.0f, false, nullptr); + rGraphics.DrawPolyLine( + basegfx::B2DHomMatrix(), aB2DPolygon, 0.0f, + basegfx::B2DVector(rWidgetDraw.mnStrokeWidth, rWidgetDraw.mnStrokeWidth), + basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND, 0.0f, false, nullptr); } break; - case DrawCommandType::IMAGE: + case WidgetDrawActionType::IMAGE: { - double nScaleFactor = 1.0; + double nScaleFactor = 2.0; if (comphelper::LibreOfficeKit::isActive()) nScaleFactor = comphelper::LibreOfficeKit::getDPIScale(); - auto const& rDrawCommand = static_cast(*pDrawCommand); + auto const& rWidgetDraw = static_cast(*pDrawAction); auto& rCacheImages = ImplGetSVData()->maGDIData.maThemeImageCache; - OUString rCacheKey = rDrawCommand.msSource + "@" + OUString::number(nScaleFactor); + OUString rCacheKey = rWidgetDraw.msSource + "@" + OUString::number(nScaleFactor); auto& aIterator = rCacheImages.find(rCacheKey); BitmapEx aBitmap; if (aIterator == rCacheImages.end()) { - SvFileStream aFileStream(rDrawCommand.msSource, StreamMode::READ); + SvFileStream aFileStream(rWidgetDraw.msSource, StreamMode::READ); vcl::bitmap::loadFromSvg(aFileStream, "", aBitmap, nScaleFactor); if (!!aBitmap) @@ -377,19 +356,20 @@ void munchDrawCommands(std::vector> const& rDrawCom } } break; - case DrawCommandType::EXTERNAL: + case WidgetDrawActionType::EXTERNAL: { - auto const& rDrawCommand = static_cast(*pDrawCommand); + auto const& rWidgetDraw + = static_cast(*pDrawAction); auto& rCacheDrawCommands = ImplGetSVData()->maGDIData.maThemeDrawCommandsCache; - auto& aIterator = rCacheDrawCommands.find(rDrawCommand.msSource); + auto& aIterator = rCacheDrawCommands.find(rWidgetDraw.msSource); gfx::DrawRoot aDrawRoot; if (aIterator == rCacheDrawCommands.end()) { - SvFileStream aFileStream(rDrawCommand.msSource, StreamMode::READ); + SvFileStream aFileStream(rWidgetDraw.msSource, StreamMode::READ); uno::Reference xContext( comphelper::getProcessComponentContext()); @@ -412,7 +392,7 @@ void munchDrawCommands(std::vector> const& rDrawCom if (pDrawRoot) { rCacheDrawCommands.insert( - std::make_pair(rDrawCommand.msSource, *pDrawRoot)); + std::make_pair(rWidgetDraw.msSource, *pDrawRoot)); drawFromDrawCommands(*pDrawRoot, rGraphics, nX, nY, nWidth, nHeight); } } @@ -444,7 +424,8 @@ bool FileDefinitionWidgetDraw::resolveDefinition(ControlType eType, ControlPart // use last defined state auto const& pState = aStates.back(); { - munchDrawCommands(pState->mpDrawCommands, m_rGraphics, nX, nY, nWidth, nHeight); + munchDrawCommands(pState->mpWidgetDrawActions, m_rGraphics, nX, nY, nWidth, + nHeight); bOK = true; } } diff --git a/vcl/source/gdi/WidgetDefinition.cxx b/vcl/source/gdi/WidgetDefinition.cxx index 668fe74bf403..6eb6ae7fa3ac 100644 --- a/vcl/source/gdi/WidgetDefinition.cxx +++ b/vcl/source/gdi/WidgetDefinition.cxx @@ -134,7 +134,7 @@ void WidgetDefinitionState::addDrawRectangle(Color aStrokeColor, sal_Int32 nStro Color aFillColor, float fX1, float fY1, float fX2, float fY2, sal_Int32 nRx, sal_Int32 nRy) { - auto pCommand(std::make_shared()); + auto pCommand(std::make_shared()); pCommand->maStrokeColor = aStrokeColor; pCommand->maFillColor = aFillColor; pCommand->mnStrokeWidth = nStrokeWidth; @@ -144,49 +144,34 @@ void WidgetDefinitionState::addDrawRectangle(Color aStrokeColor, sal_Int32 nStro pCommand->mfY1 = fY1; pCommand->mfX2 = fX2; pCommand->mfY2 = fY2; - mpDrawCommands.push_back(std::move(pCommand)); -} - -void WidgetDefinitionState::addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeWidth, - Color aFillColor, float fX1, float fY1, float fX2, - float fY2) -{ - auto pCommand(std::make_shared()); - pCommand->maStrokeColor = aStrokeColor; - pCommand->maFillColor = aFillColor; - pCommand->mnStrokeWidth = nStrokeWidth; - pCommand->mfX1 = fX1; - pCommand->mfY1 = fY1; - pCommand->mfX2 = fX2; - pCommand->mfY2 = fY2; - mpDrawCommands.push_back(std::move(pCommand)); + mpWidgetDrawActions.push_back(std::move(pCommand)); } void WidgetDefinitionState::addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1, float fY1, float fX2, float fY2) { - auto pCommand(std::make_shared()); + auto pCommand(std::make_shared()); pCommand->maStrokeColor = aStrokeColor; pCommand->mnStrokeWidth = nStrokeWidth; pCommand->mfX1 = fX1; pCommand->mfY1 = fY1; pCommand->mfX2 = fX2; pCommand->mfY2 = fY2; - mpDrawCommands.push_back(std::move(pCommand)); + mpWidgetDrawActions.push_back(std::move(pCommand)); } void WidgetDefinitionState::addDrawImage(OUString const& sSource) { - auto pCommand(std::make_shared()); + auto pCommand(std::make_shared()); pCommand->msSource = sSource; - mpDrawCommands.push_back(std::move(pCommand)); + mpWidgetDrawActions.push_back(std::move(pCommand)); } void WidgetDefinitionState::addDrawExternal(OUString const& sSource) { - auto pCommand(std::make_unique()); + auto pCommand(std::make_unique()); pCommand->msSource = sSource; - mpDrawCommands.push_back(std::move(pCommand)); + mpWidgetDrawActions.push_back(std::move(pCommand)); } } // end vcl namespace diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx index c183cb717e9c..f825addd0042 100644 --- a/vcl/source/gdi/WidgetDefinitionReader.cxx +++ b/vcl/source/gdi/WidgetDefinitionReader.cxx @@ -226,31 +226,6 @@ void WidgetDefinitionReader::readDrawingDefinition(tools::XmlWalker& rWalker, rpState->addDrawRectangle(aStrokeColor, nStrokeWidth, aFillColor, fX1, fY1, fX2, fY2, nRx, nRy); } - else if (rWalker.name() == "circ") - { - Color aStrokeColor; - readColor(rWalker.attribute("stroke"), aStrokeColor); - Color aFillColor; - readColor(rWalker.attribute("fill"), aFillColor); - OString sStrokeWidth = rWalker.attribute("stroke-width"); - sal_Int32 nStrokeWidth = -1; - if (!sStrokeWidth.isEmpty()) - nStrokeWidth = sStrokeWidth.toInt32(); - - OString sX1 = rWalker.attribute("x1"); - float fX1 = sX1.isEmpty() ? 0.0 : sX1.toFloat(); - - OString sY1 = rWalker.attribute("y1"); - float fY1 = sY1.isEmpty() ? 0.0 : sY1.toFloat(); - - OString sX2 = rWalker.attribute("x2"); - float fX2 = sX2.isEmpty() ? 1.0 : sX2.toFloat(); - - OString sY2 = rWalker.attribute("y2"); - float fY2 = sY2.isEmpty() ? 1.0 : sY2.toFloat(); - - rpState->addDrawCircle(aStrokeColor, nStrokeWidth, aFillColor, fX1, fY1, fX2, fY2); - } else if (rWalker.name() == "line") { Color aStrokeColor; -- cgit