Kaydet (Commit) a31aea43 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

support drawing a line in theme definition

Change-Id: I5cd861714a98ede80ab46e41d6d3638bdd5da97e
Reviewed-on: https://gerrit.libreoffice.org/68669
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst abb9ce6c
......@@ -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
......
......@@ -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;
}
}
}
......
......@@ -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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment