transform interfaces are getting duplicated in derived classes.
we moved to the super for smaller apis count.
Applied strategy pattern to hide the inheritance.
Change-Id: I7b0c3ff9317e9bf3c97bb0c849bf55e79ee9a591
class TVG_EXPORT Paint
{
public:
- virtual ~Paint() {}
+ virtual ~Paint();
+
+ Result rotate(float degree) noexcept;
+ Result scale(float factor) noexcept;
+ Result translate(float x, float y) noexcept;
+ Result transform(const Matrix& m) noexcept;
+ Result bounds(float* x, float* y, float* w, float* h) const noexcept;
_TVG_DECALRE_IDENTIFIER();
+ _TVG_DECLARE_PRIVATE(Paint);
};
Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
Result fill(std::unique_ptr<Fill> f) noexcept;
- //Transform
- Result rotate(float degree) noexcept;
- Result scale(float factor) noexcept;
- Result translate(float x, float y) noexcept;
- Result transform(const Matrix& m) noexcept;
-
//Getters
uint32_t pathCommands(const PathCommand** cmds) const noexcept;
uint32_t pathCoords(const Point** pts) const noexcept;
Result fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
const Fill* fill() const noexcept;
- Result bounds(float* x, float* y, float* w, float* h) const noexcept;
float strokeWidth() const noexcept;
Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
Result reserve(uint32_t size) noexcept;
Result load(const std::string& path) noexcept;
- Result rotate(float degree) noexcept;
- Result scale(float factor) noexcept;
- Result translate(float x, float y) noexcept;
- Result transform(const Matrix& m) noexcept;
-
- Result bounds(float* x, float* y, float* w, float* h) const noexcept;
-
static std::unique_ptr<Scene> gen() noexcept;
_TVG_DECLARE_ACCESSOR(Canvas);
'tvgInitializer.cpp',
'tvgLinearGradient.cpp',
'tvgLoaderMgr.cpp',
+ 'tvgPaint.cpp',
'tvgRadialGradient.cpp',
'tvgRender.cpp',
'tvgScene.cpp',
#include "tvgLoader.h"
#include "tvgLoaderMgr.h"
#include "tvgRender.h"
+#include "tvgPaint.h"
#include "tvgShapePath.h"
#include "tvgShapeImpl.h"
#include "tvgSceneImpl.h"
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef _TVG_PAINT_CPP_
+#define _TVG_PAINT_CPP_
+
+#include "tvgCommon.h"
+
+/************************************************************************/
+/* Internal Class Implementation */
+/************************************************************************/
+
+Paint :: Paint() : pImpl(make_unique<Impl>())
+{
+}
+
+
+Paint :: ~Paint()
+{
+}
+
+
+/************************************************************************/
+/* External Class Implementation */
+/************************************************************************/
+
+Result Paint::rotate(float degree) noexcept
+{
+ if (pImpl.get()->ts->rotate(degree)) return Result::Success;
+ return Result::FailedAllocation;
+}
+
+
+Result Paint::scale(float factor) noexcept
+{
+ if (pImpl.get()->ts->scale(factor)) return Result::Success;
+ return Result::FailedAllocation;
+}
+
+
+Result Paint::translate(float x, float y) noexcept
+{
+ if (pImpl.get()->ts->translate(x, y)) return Result::Success;
+ return Result::FailedAllocation;
+}
+
+
+Result Paint::transform(const Matrix& m) noexcept
+{
+ if (pImpl.get()->ts->transform(m)) return Result::Success;
+ return Result::FailedAllocation;
+}
+
+
+Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept
+{
+ if (pImpl.get()->ts->bounds(x, y, w, h)) return Result::Success;
+ return Result::InsufficientCondition;
+}
+
+#endif //_TVG_PAINT_CPP_
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef _TVG_PAINT_H_
+#define _TVG_PAINT_H_
+
+namespace tvg
+{
+ struct ITransformMethod
+ {
+ virtual ~ITransformMethod(){}
+ virtual bool rotate(float degree) = 0;
+ virtual bool scale(float factor) = 0;
+ virtual bool translate(float x, float y) = 0;
+ virtual bool transform(const Matrix& m) = 0;
+ virtual bool bounds(float* x, float* y, float* w, float* h) const = 0;
+ };
+
+ struct Paint::Impl
+ {
+ ITransformMethod* ts = nullptr;
+
+ ~Impl() {
+ if (ts) delete(ts);
+ }
+ };
+
+
+ template<class T>
+ struct TransformMethod : ITransformMethod
+ {
+ T* _inst = nullptr;
+
+ TransformMethod(T* inst) : _inst(inst) {}
+ ~TransformMethod(){}
+
+ bool rotate(float degree) override
+ {
+ return _inst->rotate(degree);
+ }
+
+ bool scale(float factor) override
+ {
+ return _inst->scale(factor);
+ }
+
+ bool translate(float x, float y) override
+ {
+ return _inst->translate(x, y);
+ }
+
+ bool transform(const Matrix& m) override
+ {
+ return _inst->transform(m);
+ }
+
+ bool bounds(float* x, float* y, float* w, float* h) const override
+ {
+ return _inst->bounds(x, y, w, h);
+ }
+ };
+}
+
+#endif //_TVG_PAINT_H_
\ No newline at end of file
Scene::Scene() : pImpl(make_unique<Impl>())
{
_id = PAINT_ID_SCENE;
+
+ Paint::pImpl.get()->ts = pImpl.get()->transformMethod();
}
}
-Result Scene::scale(float factor) noexcept
-{
- auto impl = pImpl.get();
- if (!impl) return Result::MemoryCorruption;
-
- if (!impl->scale(factor)) return Result::FailedAllocation;
-
- return Result::Success;
-}
-
-
-Result Scene::rotate(float degree) noexcept
-{
- auto impl = pImpl.get();
- if (!impl) return Result::MemoryCorruption;
-
- if (!impl->rotate(degree)) return Result::FailedAllocation;
-
- return Result::Success;
-}
-
-
-Result Scene::translate(float x, float y) noexcept
-{
- auto impl = pImpl.get();
- if (!impl) return Result::MemoryCorruption;
-
- if (!impl->translate(x, y)) return Result::FailedAllocation;
-
- return Result::Success;
-}
-
-
-Result Scene::transform(const Matrix& m) noexcept
-{
- auto impl = pImpl.get();
- if (!impl) return Result::MemoryCorruption;
-
- if (!impl->transform(m)) return Result::FailedAllocation;
-
- return Result::Success;
-}
-
-
-Result Scene::bounds(float* x, float* y, float* w, float* h) const noexcept
-{
- auto impl = pImpl.get();
- if (!impl) return Result::MemoryCorruption;
-
- if (!impl->bounds(x, y, w, h)) return Result::InsufficientCondition;
-
- return Result::Success;
-}
-
-
Result Scene::load(const std::string& path) noexcept
{
if (path.empty()) return Result::InvalidArguments;
if (!loader->read()) return Result::Unknown;
return Result::Success;
}
+
+ ITransformMethod* transformMethod()
+ {
+ return new TransformMethod<Scene::Impl>(this);
+ }
+
};
#endif //_TVG_SCENE_IMPL_H_
\ No newline at end of file
/************************************************************************/
constexpr auto PATH_KAPPA = 0.552284f;
-
/************************************************************************/
/* External Class Implementation */
/************************************************************************/
Shape :: Shape() : pImpl(make_unique<Impl>())
{
_id = PAINT_ID_SHAPE;
+
+ Paint::pImpl.get()->ts = pImpl.get()->transformMethod();
}
}
-Result Shape::scale(float factor) noexcept
-{
- auto impl = pImpl.get();
- if (!impl) return Result::MemoryCorruption;
-
- if (!impl->scale(factor)) return Result::FailedAllocation;
-
- return Result::Success;
-}
-
-
-Result Shape::rotate(float degree) noexcept
-{
- auto impl = pImpl.get();
- if (!impl) return Result::MemoryCorruption;
-
- if (!impl->rotate(degree)) return Result::FailedAllocation;
-
- return Result::Success;
-}
-
-
-Result Shape::translate(float x, float y) noexcept
-{
- auto impl = pImpl.get();
- if (!impl) return Result::MemoryCorruption;
-
- if (!impl->translate(x, y)) return Result::FailedAllocation;
-
- return Result::Success;
-}
-
-
-Result Shape::transform(const Matrix& m) noexcept
-{
- auto impl = pImpl.get();
- if (!impl) return Result::MemoryCorruption;
-
- if (!impl->transform(m)) return Result::FailedAllocation;
-
- return Result::Success;
-}
-
-
-Result Shape::bounds(float* x, float* y, float* w, float* h) const noexcept
-{
- auto impl = pImpl.get();
- if (!impl) return Result::MemoryCorruption;
-
- if (!impl->bounds(x, y, w, h)) return Result::InsufficientCondition;
-
- return Result::Success;
-}
-
-
Result Shape::stroke(float width) noexcept
{
auto impl = pImpl.get();
return true;
}
+
+
+ ITransformMethod* transformMethod()
+ {
+ return new TransformMethod<Shape::Impl>(this);
+ }
};
#endif //_TVG_SHAPE_IMPL_H_
\ No newline at end of file