Kaydet (Commit) fb6d2b74 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

Rename DrawCommand* to WidgetDrawAction*, remove unused circ draw

Reviewed-on: https://gerrit.libreoffice.org/69654
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit d3922a93)

Change-Id: Icef900e75255d477812a198fdb29e0cdebba35b8
üst e1e29426
......@@ -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<std::shared_ptr<DrawCommand>> mpDrawCommands;
std::vector<std::shared_ptr<WidgetDrawAction>> 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);
......
......@@ -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());
}
}
......
......@@ -56,7 +56,7 @@
<part value="Entire">
<state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
<rect stroke="#808080" fill="#FFFFFF" stroke-width="1.0" rx="5" ry="5" margin="1"/>
<circ stroke="#808080" fill="#808080" stroke-width="1.0" margin="1"/>
<line stroke="#808080" fill="#808080" stroke-width="1.0"/>
</state>
<state enabled="true" focused="any" pressed="any" rollover="true" default="true" selected="any" button-value="any">
<rect stroke="#808080" fill="#808080" stroke-width="1.0" rx="5" ry="5" margin="1"/>
......@@ -71,11 +71,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"/>
<rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/>
</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"/>
<rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/>
<rect stroke="#007AFF" fill="#007AFF" stroke-width="1" margin="3"/>
</state>
</part>
</radiobutton>
......
......@@ -254,95 +254,75 @@ void drawFromDrawCommands(gfx::DrawRoot const& rDrawRoot, SalGraphics& rGraphics
}
}
void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCommands,
void munchDrawCommands(std::vector<std::shared_ptr<WidgetDrawAction>> const& rDrawActions,
SalGraphics& rGraphics, long nX, long nY, long nWidth, long nHeight)
{
for (std::shared_ptr<DrawCommand> const& pDrawCommand : rDrawCommands)
for (std::shared_ptr<WidgetDrawAction> const& pDrawAction : rDrawActions)
{
switch (pDrawCommand->maType)
switch (pDrawAction->maType)
{
case DrawCommandType::RECTANGLE:
case WidgetDrawActionType::RECTANGLE:
{
auto const& rRectDrawCommand
= static_cast<RectangleDrawCommand const&>(*pDrawCommand);
auto const& rWidgetDraw
= static_cast<WidgetDrawActionRectangle const&>(*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(ImplColorToSal(rRectDrawCommand.maFillColor));
rGraphics.SetFillColor(ImplColorToSal(rWidgetDraw.maFillColor));
rGraphics.DrawPolyPolygon(basegfx::B2DPolyPolygon(aB2DPolygon), 0.0f, nullptr);
rGraphics.SetLineColor(ImplColorToSal(rRectDrawCommand.maStrokeColor));
rGraphics.SetLineColor(ImplColorToSal(rWidgetDraw.maStrokeColor));
rGraphics.SetFillColor();
rGraphics.DrawPolyLine(aB2DPolygon, 0.0f,
basegfx::B2DVector(rRectDrawCommand.mnStrokeWidth,
rRectDrawCommand.mnStrokeWidth),
basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND,
0.0f, nullptr);
rGraphics.DrawPolyLine(
aB2DPolygon, 0.0f,
basegfx::B2DVector(rWidgetDraw.mnStrokeWidth, rWidgetDraw.mnStrokeWidth),
basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND, 0.0f, nullptr);
}
break;
case DrawCommandType::CIRCLE:
case WidgetDrawActionType::LINE:
{
auto const& rCircleDrawCommand
= static_cast<CircleDrawCommand const&>(*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(ImplColorToSal(rCircleDrawCommand.maStrokeColor));
rGraphics.SetFillColor(ImplColorToSal(rCircleDrawCommand.maFillColor));
rGraphics.DrawPolyPolygon(basegfx::B2DPolyPolygon(aB2DPolygon), 0.0f, nullptr);
}
break;
case DrawCommandType::LINE:
{
auto const& rLineDrawCommand = static_cast<LineDrawCommand const&>(*pDrawCommand);
auto const& rWidgetDraw = static_cast<WidgetDrawActionLine const&>(*pDrawAction);
Point aRectPoint(nX + 1, nY + 1);
Size aRectSize(nWidth - 1, nHeight - 1);
rGraphics.SetFillColor();
rGraphics.SetLineColor(ImplColorToSal(rLineDrawCommand.maStrokeColor));
rGraphics.SetLineColor(ImplColorToSal(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(aB2DPolygon, 0.0f,
basegfx::B2DVector(rLineDrawCommand.mnStrokeWidth,
rLineDrawCommand.mnStrokeWidth),
basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND,
0.0f, nullptr);
rGraphics.DrawPolyLine(
aB2DPolygon, 0.0f,
basegfx::B2DVector(rWidgetDraw.mnStrokeWidth, rWidgetDraw.mnStrokeWidth),
basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND, 0.0f, nullptr);
}
break;
case DrawCommandType::IMAGE:
case WidgetDrawActionType::IMAGE:
{
double nScaleFactor = 1.0;
if (comphelper::LibreOfficeKit::isActive())
nScaleFactor = comphelper::LibreOfficeKit::getDPIScale();
auto const& rDrawCommand = static_cast<ImageDrawCommand const&>(*pDrawCommand);
auto const& rWidgetDraw = static_cast<WidgetDrawActionImage const&>(*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)
......@@ -376,19 +356,20 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom
}
}
break;
case DrawCommandType::EXTERNAL:
case WidgetDrawActionType::EXTERNAL:
{
auto const& rDrawCommand = static_cast<ImageDrawCommand const&>(*pDrawCommand);
auto const& rWidgetDraw
= static_cast<WidgetDrawActionExternal const&>(*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<uno::XComponentContext> xContext(
comphelper::getProcessComponentContext());
......@@ -411,7 +392,7 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> 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);
}
}
......@@ -443,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;
}
}
......
......@@ -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<RectangleDrawCommand>());
auto pCommand(std::make_shared<WidgetDrawActionRectangle>());
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<CircleDrawCommand>());
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<LineDrawCommand>());
auto pCommand(std::make_shared<WidgetDrawActionLine>());
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<ImageDrawCommand>());
auto pCommand(std::make_shared<WidgetDrawActionImage>());
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_shared<ExternalSourceDrawCommand>());
auto pCommand(std::make_shared<WidgetDrawActionExternal>());
pCommand->msSource = sSource;
mpDrawCommands.push_back(std::move(pCommand));
mpWidgetDrawActions.push_back(std::move(pCommand));
}
} // end vcl namespace
......
......@@ -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;
......
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