vcl/inc/widgetdraw/WidgetDefinition.hxx | 29 +++++++++++++--- vcl/source/gdi/FileDefinitionWidgetDraw.cxx | 45 +++++++++++++------------- vcl/source/gdi/WidgetDefinition.cxx | 18 +++++++--- vcl/source/gdi/WidgetDefinitionReader.cxx | 35 ++++++++++++++------ vcl/uiconfig/theme_definitions/definition.xml | 11 ++---- 5 files changed, 90 insertions(+), 48 deletions(-)
New commits: commit 1042c2c5a349588c03a00f45c77fb1b8f1f1d4ea Author: Tomaž Vajngerl <[email protected]> AuthorDate: Tue Jan 29 13:45:12 2019 +0100 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Mon Mar 4 22:17:31 2019 +0100 use basegfx to convert circle/roundrect to a polygon The tools::Polygon functions to draw a circle, roundrect are lower quality. Change-Id: I6226ac917d600b2a14a99c9a27aa371233799e16 Reviewed-on: https://gerrit.libreoffice.org/68692 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx index 209ed169773e..bc46bcbdd67f 100644 --- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx +++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx @@ -15,6 +15,9 @@ #include <rtl/bootstrap.hxx> #include <config_folders.h> +#include <basegfx/range/b2drectangle.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> + namespace vcl { namespace @@ -101,12 +104,15 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom { auto const& rRectDrawCommand = static_cast<RectangleDrawCommand const&>(*pDrawCommand); - Point aRectPoint(nX, nY); - Size aRectSize(nWidth - 1, nHeight - 1); - tools::Polygon aPolygon(tools::Rectangle(aRectPoint, aRectSize), - rRectDrawCommand.mnRx, rRectDrawCommand.mnRy); - basegfx::B2DPolygon aB2DPolygon(aPolygon.getB2DPolygon()); + basegfx::B2DRectangle rRect( + nX + (nWidth * rRectDrawCommand.mfX1), nY + (nHeight * rRectDrawCommand.mfY1), + nX + (nWidth * rRectDrawCommand.mfX2), nY + (nHeight * rRectDrawCommand.mfY2)); + + basegfx::B2DPolygon aB2DPolygon = basegfx::utils::createPolygonFromRect( + rRect, rRectDrawCommand.mnRx / rRect.getWidth() * 2.0, + rRectDrawCommand.mnRy / rRect.getHeight() * 2.0); + rGraphics.SetLineColor(); rGraphics.SetFillColor(rRectDrawCommand.maFillColor); rGraphics.DrawPolyPolygon(basegfx::B2DHomMatrix(), @@ -124,14 +130,15 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom { auto const& rCircleDrawCommand = static_cast<CircleDrawCommand const&>(*pDrawCommand); - Point aRectPoint(nX + 1, nY + 1); - Size aRectSize(nWidth - 1, nHeight - 1); - tools::Rectangle aRectangle(aRectPoint, aRectSize); - tools::Polygon aPolygon(aRectangle.Center(), aRectangle.GetWidth() >> 1, - aRectangle.GetHeight() >> 1); + 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); - basegfx::B2DPolygon aB2DPolygon(aPolygon.getB2DPolygon()); rGraphics.SetLineColor(rCircleDrawCommand.maStrokeColor); rGraphics.SetFillColor(rCircleDrawCommand.maFillColor); rGraphics.DrawPolyPolygon(basegfx::B2DHomMatrix(), @@ -177,10 +184,10 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart bool bOldAA = m_rGraphics.getAntiAliasB2DDraw(); m_rGraphics.setAntiAliasB2DDraw(true); - long nWidth = rControlRegion.GetWidth(); - long nHeight = rControlRegion.GetHeight(); - long nX = rControlRegion.Left() + 1; - long nY = rControlRegion.Top() + 1; + long nWidth = rControlRegion.GetWidth() - 1; + long nHeight = rControlRegion.GetHeight() - 1; + long nX = rControlRegion.Left(); + long nY = rControlRegion.Top(); bool bOK = false; commit 2f8eb233b8de5a7a3a7b997734290b20bf86bd14 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Tue Jan 29 13:29:43 2019 +0100 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Mon Mar 4 22:17:23 2019 +0100 remove margin param. and replace it with a relative "rectangle" Relative rectangle - x1, y1, x2, y2 with valid values in the range between 0.0 and 1.0, where 0, 0 is top left corner and 1, 1 is the bottom right corner of the control rectangle. Change-Id: I2b782a43e91328cf43dc0722e50c55414fb3e867 Reviewed-on: https://gerrit.libreoffice.org/68691 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/vcl/inc/widgetdraw/WidgetDefinition.hxx b/vcl/inc/widgetdraw/WidgetDefinition.hxx index 486d61802654..f1035c694cfe 100644 --- a/vcl/inc/widgetdraw/WidgetDefinition.hxx +++ b/vcl/inc/widgetdraw/WidgetDefinition.hxx @@ -37,7 +37,6 @@ public: DrawCommand(DrawCommandType aType) : maType(aType) , mnStrokeWidth(-1) - , mnMargin(0) { } @@ -46,7 +45,6 @@ public: Color maStrokeColor; Color maFillColor; sal_Int32 mnStrokeWidth; - sal_Int32 mnMargin; }; class VCL_DLLPUBLIC RectangleDrawCommand : public DrawCommand @@ -55,10 +53,19 @@ public: sal_Int32 mnRx; sal_Int32 mnRy; + float mfX1; + float mfY1; + float mfX2; + float mfY2; + RectangleDrawCommand() : DrawCommand(DrawCommandType::RECTANGLE) , mnRx(0) , mnRy(0) + , mfX1(0.0f) + , mfY1(0.0f) + , mfX2(1.0f) + , mfY2(1.0f) { } }; @@ -66,8 +73,17 @@ 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) { } }; @@ -139,10 +155,11 @@ public: std::vector<std::shared_ptr<DrawCommand>> mpDrawCommands; - void addDrawRectangle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor, - sal_Int32 nRx, sal_Int32 nRy, sal_Int32 nMargin); - void addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor, - sal_Int32 nMargin); + 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/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx index 9b4aa8a8c8c9..209ed169773e 100644 --- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx +++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx @@ -124,10 +124,8 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom { auto const& rCircleDrawCommand = static_cast<CircleDrawCommand const&>(*pDrawCommand); - Point aRectPoint(nX + 1 + rCircleDrawCommand.mnMargin, - nY + 1 + rCircleDrawCommand.mnMargin); - Size aRectSize(nWidth - 1 - 2 * rCircleDrawCommand.mnMargin, - nHeight - 1 - 2 * rCircleDrawCommand.mnMargin); + Point aRectPoint(nX + 1, nY + 1); + Size aRectSize(nWidth - 1, nHeight - 1); tools::Rectangle aRectangle(aRectPoint, aRectSize); tools::Polygon aPolygon(aRectangle.Center(), aRectangle.GetWidth() >> 1, @@ -143,11 +141,9 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom case DrawCommandType::LINE: { auto const& rLineDrawCommand = static_cast<LineDrawCommand const&>(*pDrawCommand); - Point aRectPoint(nX + 1 + rLineDrawCommand.mnMargin, - nY + 1 + rLineDrawCommand.mnMargin); + Point aRectPoint(nX + 1, nY + 1); - Size aRectSize(nWidth - 1 - 2 * rLineDrawCommand.mnMargin, - nHeight - 1 - 2 * rLineDrawCommand.mnMargin); + Size aRectSize(nWidth - 1, nHeight - 1); rGraphics.SetFillColor(); rGraphics.SetLineColor(rLineDrawCommand.maStrokeColor); diff --git a/vcl/source/gdi/WidgetDefinition.cxx b/vcl/source/gdi/WidgetDefinition.cxx index 36d362479c27..8b717a035c91 100644 --- a/vcl/source/gdi/WidgetDefinition.cxx +++ b/vcl/source/gdi/WidgetDefinition.cxx @@ -89,28 +89,36 @@ WidgetDefinitionState::WidgetDefinitionState(OString const& sEnabled, OString co } void WidgetDefinitionState::addDrawRectangle(Color aStrokeColor, sal_Int32 nStrokeWidth, - Color aFillColor, sal_Int32 nRx, sal_Int32 nRy, - sal_Int32 nMargin) + Color aFillColor, float fX1, float fY1, float fX2, + float fY2, sal_Int32 nRx, sal_Int32 nRy) { std::shared_ptr<DrawCommand> pCommand(std::make_shared<RectangleDrawCommand>()); pCommand->maStrokeColor = aStrokeColor; pCommand->maFillColor = aFillColor; pCommand->mnStrokeWidth = nStrokeWidth; - pCommand->mnMargin = nMargin; RectangleDrawCommand& rRectCommand = static_cast<RectangleDrawCommand&>(*pCommand); rRectCommand.mnRx = nRx; rRectCommand.mnRy = nRy; + rRectCommand.mfX1 = fX1; + rRectCommand.mfY1 = fY1; + rRectCommand.mfX2 = fX2; + rRectCommand.mfY2 = fY2; mpDrawCommands.push_back(std::move(pCommand)); } void WidgetDefinitionState::addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeWidth, - Color aFillColor, sal_Int32 nMargin) + Color aFillColor, float fX1, float fY1, float fX2, + float fY2) { std::shared_ptr<DrawCommand> pCommand(std::make_shared<CircleDrawCommand>()); pCommand->maStrokeColor = aStrokeColor; pCommand->maFillColor = aFillColor; pCommand->mnStrokeWidth = nStrokeWidth; - pCommand->mnMargin = nMargin; + CircleDrawCommand& rCircleCommand = static_cast<CircleDrawCommand&>(*pCommand); + rCircleCommand.mfX1 = fX1; + rCircleCommand.mfY1 = fY1; + rCircleCommand.mfX2 = fX2; + rCircleCommand.mfY2 = fY2; mpDrawCommands.push_back(std::move(pCommand)); } diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx index bc9ce749dfad..7f45a99b1aff 100644 --- a/vcl/source/gdi/WidgetDefinitionReader.cxx +++ b/vcl/source/gdi/WidgetDefinitionReader.cxx @@ -185,12 +185,20 @@ void WidgetDefinitionReader::readDrawingDefinition(tools::XmlWalker& rWalker, if (!sRy.isEmpty()) nRy = sRy.toInt32(); - sal_Int32 nMargin = 0; - OString sMargin = rWalker.attribute("margin"); - if (!sMargin.isEmpty()) - nMargin = sMargin.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->addDrawRectangle(aStrokeColor, nStrokeWidth, aFillColor, nRx, nRy, nMargin); + rpState->addDrawRectangle(aStrokeColor, nStrokeWidth, aFillColor, fX1, fY1, fX2, fY2, + nRx, nRy); } else if (rWalker.name() == "circ") { @@ -203,12 +211,19 @@ void WidgetDefinitionReader::readDrawingDefinition(tools::XmlWalker& rWalker, if (!sStrokeWidth.isEmpty()) nStrokeWidth = sStrokeWidth.toInt32(); - sal_Int32 nMargin = 0; - OString sMargin = rWalker.attribute("margin"); - if (!sMargin.isEmpty()) - nMargin = sMargin.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, nMargin); + rpState->addDrawCircle(aStrokeColor, nStrokeWidth, aFillColor, fX1, fY1, fX2, fY2); } else if (rWalker.name() == "line") { diff --git a/vcl/uiconfig/theme_definitions/definition.xml b/vcl/uiconfig/theme_definitions/definition.xml index 91c473f290a6..0fdbdb659683 100644 --- a/vcl/uiconfig/theme_definitions/definition.xml +++ b/vcl/uiconfig/theme_definitions/definition.xml @@ -57,11 +57,10 @@ <pushbutton> <part value="Entire"> <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any"> - <rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" rx="5" ry="5" margin="0"/> + <rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" rx="7" ry="7" /> </state> - <state enabled="true" focused="any" pressed="any" rollover="true" default="any" selected="any" button-value="any"> - <rect stroke="#007AFF" fill="#007AFF" stroke-width="1" rx="5" ry="5" margin="0"/> + <rect stroke="#007AFF" fill="#007AFF" stroke-width="1" rx="7" ry="7" /> </state> </part> </pushbutton> @@ -69,11 +68,11 @@ <radiobutton> <part value="Entire"> <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="false"> - <circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/> + <circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" /> </state> <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="true"> - <circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/> - <circ stroke="#007AFF" fill="#007AFF" stroke-width="1" margin="3"/> + <circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" /> + <circ stroke="#007AFF" fill="#007AFF" stroke-width="1" x1="0.1" y1="0.1" x2="0.9" y2="0.9"/> </state> </part> </radiobutton> _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
