Simplify code to add a draw command (subclass)

Change-Id: Ie7bd304f80ddfa55dc2ed986fa033b25e845d449
Reviewed-on: https://gerrit.libreoffice.org/68698
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl
2019-02-08 21:49:19 +01:00
committed by Tomaž Vajngerl
parent 394bf64515
commit d81a11220d

View File

@@ -11,7 +11,6 @@
#include <widgetdraw/WidgetDefinition.hxx> #include <widgetdraw/WidgetDefinition.hxx>
#include <sal/config.h> #include <sal/config.h>
#include <tools/stream.hxx>
#include <unordered_map> #include <unordered_map>
namespace vcl namespace vcl
@@ -92,17 +91,16 @@ void WidgetDefinitionState::addDrawRectangle(Color aStrokeColor, sal_Int32 nStro
Color aFillColor, float fX1, float fY1, float fX2, Color aFillColor, float fX1, float fY1, float fX2,
float fY2, sal_Int32 nRx, sal_Int32 nRy) float fY2, sal_Int32 nRx, sal_Int32 nRy)
{ {
std::shared_ptr<DrawCommand> pCommand(std::make_shared<RectangleDrawCommand>()); auto pCommand(std::make_shared<RectangleDrawCommand>());
pCommand->maStrokeColor = aStrokeColor; pCommand->maStrokeColor = aStrokeColor;
pCommand->maFillColor = aFillColor; pCommand->maFillColor = aFillColor;
pCommand->mnStrokeWidth = nStrokeWidth; pCommand->mnStrokeWidth = nStrokeWidth;
RectangleDrawCommand& rRectCommand = static_cast<RectangleDrawCommand&>(*pCommand); pCommand->mnRx = nRx;
rRectCommand.mnRx = nRx; pCommand->mnRy = nRy;
rRectCommand.mnRy = nRy; pCommand->mfX1 = fX1;
rRectCommand.mfX1 = fX1; pCommand->mfY1 = fY1;
rRectCommand.mfY1 = fY1; pCommand->mfX2 = fX2;
rRectCommand.mfX2 = fX2; pCommand->mfY2 = fY2;
rRectCommand.mfY2 = fY2;
mpDrawCommands.push_back(std::move(pCommand)); mpDrawCommands.push_back(std::move(pCommand));
} }
@@ -110,29 +108,27 @@ void WidgetDefinitionState::addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeW
Color aFillColor, float fX1, float fY1, float fX2, Color aFillColor, float fX1, float fY1, float fX2,
float fY2) float fY2)
{ {
std::shared_ptr<DrawCommand> pCommand(std::make_shared<CircleDrawCommand>()); auto pCommand(std::make_shared<CircleDrawCommand>());
pCommand->maStrokeColor = aStrokeColor; pCommand->maStrokeColor = aStrokeColor;
pCommand->maFillColor = aFillColor; pCommand->maFillColor = aFillColor;
pCommand->mnStrokeWidth = nStrokeWidth; pCommand->mnStrokeWidth = nStrokeWidth;
CircleDrawCommand& rCircleCommand = static_cast<CircleDrawCommand&>(*pCommand); pCommand->mfX1 = fX1;
rCircleCommand.mfX1 = fX1; pCommand->mfY1 = fY1;
rCircleCommand.mfY1 = fY1; pCommand->mfX2 = fX2;
rCircleCommand.mfX2 = fX2; pCommand->mfY2 = fY2;
rCircleCommand.mfY2 = fY2;
mpDrawCommands.push_back(std::move(pCommand)); mpDrawCommands.push_back(std::move(pCommand));
} }
void WidgetDefinitionState::addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1, void WidgetDefinitionState::addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1,
float fY1, float fX2, float fY2) float fY1, float fX2, float fY2)
{ {
std::shared_ptr<DrawCommand> pCommand(std::make_shared<LineDrawCommand>()); auto pCommand(std::make_shared<LineDrawCommand>());
pCommand->maStrokeColor = aStrokeColor; pCommand->maStrokeColor = aStrokeColor;
pCommand->mnStrokeWidth = nStrokeWidth; pCommand->mnStrokeWidth = nStrokeWidth;
LineDrawCommand& rLineCommand = static_cast<LineDrawCommand&>(*pCommand); pCommand->mfX1 = fX1;
rLineCommand.mfX1 = fX1; pCommand->mfY1 = fY1;
rLineCommand.mfY1 = fY1; pCommand->mfX2 = fX2;
rLineCommand.mfX2 = fX2; pCommand->mfY2 = fY2;
rLineCommand.mfY2 = fY2;
mpDrawCommands.push_back(std::move(pCommand)); mpDrawCommands.push_back(std::move(pCommand));
} }