summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-01-25 16:43:54 +0100
committerTomaž Vajngerl <quikee@gmail.com>2019-03-04 12:31:42 +0100
commita31aea4355c32d44ae7584eedc5e6fc71bc5c233 (patch)
tree70ca49cf26f4f8f0bb55590f6d9f7e39ff2fba4e
parentDraw basic Editbox from the theme definition (diff)
downloadcore-a31aea4355c32d44ae7584eedc5e6fc71bc5c233.tar.gz
core-a31aea4355c32d44ae7584eedc5e6fc71bc5c233.zip
support drawing a line in theme definition
Change-Id: I5cd861714a98ede80ab46e41d6d3638bdd5da97e Reviewed-on: https://gerrit.libreoffice.org/68669 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--vcl/inc/widgetdraw/WidgetDefinitionReader.hxx19
-rw-r--r--vcl/source/gdi/FileDefinitionWidgetDraw.cxx26
-rw-r--r--vcl/source/gdi/WidgetDefinitionReader.cxx39
3 files changed, 83 insertions, 1 deletions
diff --git a/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx b/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx
index 5a53621c9c58..77548c72aa0c 100644
--- a/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx
+++ b/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx
@@ -25,7 +25,8 @@ namespace vcl
enum class DrawCommandType
{
RECTANGLE,
- CIRCLE
+ CIRCLE,
+ LINE
};
class VCL_DLLPUBLIC DrawCommand
@@ -69,6 +70,20 @@ public:
}
};
+class VCL_DLLPUBLIC LineDrawCommand : public DrawCommand
+{
+public:
+ float mfX1;
+ float mfY1;
+ float mfX2;
+ float mfY2;
+
+ LineDrawCommand()
+ : DrawCommand(DrawCommandType::LINE)
+ {
+ }
+};
+
class VCL_DLLPUBLIC WidgetDefinitionState
{
public:
@@ -90,6 +105,8 @@ public:
sal_Int32 nRx, sal_Int32 nRy, sal_Int32 nMargin);
void addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor,
sal_Int32 nMargin);
+ void addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1, float fY1, float fX2,
+ float fY2);
};
class VCL_DLLPUBLIC WidgetDefinition
diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
index 2e3822d6c05d..600b736c3c7c 100644
--- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
+++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
@@ -133,6 +133,32 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom
basegfx::B2DPolyPolygon(aB2DPolygon), 0.0f, nullptr);
}
break;
+ case DrawCommandType::LINE:
+ {
+ auto const& rLineDrawCommand = static_cast<LineDrawCommand const&>(*pDrawCommand);
+ Point aRectPoint(nX + 1 + rLineDrawCommand.mnMargin,
+ nY + 1 + rLineDrawCommand.mnMargin);
+
+ Size aRectSize(nWidth - 1 - 2 * rLineDrawCommand.mnMargin,
+ nHeight - 1 - 2 * rLineDrawCommand.mnMargin);
+
+ rGraphics.SetFillColor();
+ rGraphics.SetLineColor(rLineDrawCommand.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) },
+ };
+
+ rGraphics.DrawPolyLine(basegfx::B2DHomMatrix(), aB2DPolygon, 0.0f,
+ basegfx::B2DVector(rLineDrawCommand.mnStrokeWidth,
+ rLineDrawCommand.mnStrokeWidth),
+ basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND,
+ 0.0f, false, nullptr);
+ }
+ break;
}
}
}
diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx
index 37053a56b877..3a8848f50617 100644
--- a/vcl/source/gdi/WidgetDefinitionReader.cxx
+++ b/vcl/source/gdi/WidgetDefinitionReader.cxx
@@ -114,6 +114,31 @@ void WidgetDefinitionReader::readDrawingDefinition(tools::XmlWalker& rWalker,
rpState->addDrawCircle(aStrokeColor, nStrokeWidth, aFillColor, nMargin);
}
+ else if (rWalker.name() == "line")
+ {
+ Color aStrokeColor;
+ readColor(rWalker.attribute("stroke"), aStrokeColor);
+
+ 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() ? -1.0 : sX1.toFloat();
+
+ OString sY1 = rWalker.attribute("y1");
+ float fY1 = sY1.isEmpty() ? -1.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->addDrawLine(aStrokeColor, nStrokeWidth, fX1, fY1, fX2, fY2);
+ }
+
rWalker.next();
}
rWalker.parent();
@@ -483,6 +508,20 @@ void WidgetDefinitionState::addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeW
mpDrawCommands.push_back(std::move(pCommand));
}
+void WidgetDefinitionState::addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1,
+ float fY1, float fX2, float fY2)
+{
+ std::shared_ptr<DrawCommand> pCommand(std::make_shared<LineDrawCommand>());
+ pCommand->maStrokeColor = aStrokeColor;
+ pCommand->mnStrokeWidth = nStrokeWidth;
+ LineDrawCommand& rLineCommand = static_cast<LineDrawCommand&>(*pCommand);
+ rLineCommand.mfX1 = fX1;
+ rLineCommand.mfY1 = fY1;
+ rLineCommand.mfX2 = fX2;
+ rLineCommand.mfY2 = fY2;
+ mpDrawCommands.push_back(std::move(pCommand));
+}
+
} // end vcl namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */