mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 19:44:28 +00:00
common: code refactoring.
changed just internal variable & method names. no logical changes. Change-Id: I01782ec59dec3ff2232e03de7b3863100d9cc27f
This commit is contained in:
parent
8dca270a30
commit
39b77361c5
7 changed files with 32 additions and 34 deletions
|
@ -56,7 +56,7 @@ struct Canvas::Impl
|
|||
if (!renderer->clear()) return Result::InsufficientCondition;
|
||||
|
||||
for (auto paint : paints) {
|
||||
paint->IMPL->method->dispose(*renderer);
|
||||
paint->IMPL->method()->dispose(*renderer);
|
||||
delete(paint);
|
||||
}
|
||||
paints.clear();
|
||||
|
@ -70,13 +70,13 @@ struct Canvas::Impl
|
|||
|
||||
//Update single paint node
|
||||
if (paint) {
|
||||
if (!paint->IMPL->method->update(*renderer, nullptr, RenderUpdateFlag::None)) {
|
||||
if (!paint->IMPL->method()->update(*renderer, nullptr, RenderUpdateFlag::None)) {
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
//Update retained all paint nodes
|
||||
} else {
|
||||
for(auto paint: paints) {
|
||||
if (!paint->IMPL->method->update(*renderer, nullptr, RenderUpdateFlag::None)) {
|
||||
if (!paint->IMPL->method()->update(*renderer, nullptr, RenderUpdateFlag::None)) {
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ struct Canvas::Impl
|
|||
if (!renderer->preRender()) return Result::InsufficientCondition;
|
||||
|
||||
for(auto paint: paints) {
|
||||
if(!paint->IMPL->method->render(*renderer)) return Result::InsufficientCondition;
|
||||
if(!paint->IMPL->method()->render(*renderer)) return Result::InsufficientCondition;
|
||||
}
|
||||
|
||||
if (!renderer->postRender()) return Result::InsufficientCondition;
|
||||
|
|
|
@ -39,35 +39,35 @@ Paint :: ~Paint()
|
|||
|
||||
Result Paint::rotate(float degree) noexcept
|
||||
{
|
||||
if (IMPL->method->rotate(degree)) return Result::Success;
|
||||
if (IMPL->method()->rotate(degree)) return Result::Success;
|
||||
return Result::FailedAllocation;
|
||||
}
|
||||
|
||||
|
||||
Result Paint::scale(float factor) noexcept
|
||||
{
|
||||
if (IMPL->method->scale(factor)) return Result::Success;
|
||||
if (IMPL->method()->scale(factor)) return Result::Success;
|
||||
return Result::FailedAllocation;
|
||||
}
|
||||
|
||||
|
||||
Result Paint::translate(float x, float y) noexcept
|
||||
{
|
||||
if (IMPL->method->translate(x, y)) return Result::Success;
|
||||
if (IMPL->method()->translate(x, y)) return Result::Success;
|
||||
return Result::FailedAllocation;
|
||||
}
|
||||
|
||||
|
||||
Result Paint::transform(const Matrix& m) noexcept
|
||||
{
|
||||
if (IMPL->method->transform(m)) return Result::Success;
|
||||
if (IMPL->method()->transform(m)) return Result::Success;
|
||||
return Result::FailedAllocation;
|
||||
}
|
||||
|
||||
|
||||
Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept
|
||||
{
|
||||
if (IMPL->method->bounds(x, y, w, h)) return Result::Success;
|
||||
if (IMPL->method()->bounds(x, y, w, h)) return Result::Success;
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
namespace tvg
|
||||
{
|
||||
struct PaintMethod
|
||||
struct StrategyMethod
|
||||
{
|
||||
virtual ~PaintMethod(){}
|
||||
virtual ~StrategyMethod(){}
|
||||
|
||||
virtual bool dispose(RenderMethod& renderer) = 0;
|
||||
virtual bool update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t pFlag) = 0;
|
||||
|
@ -37,21 +37,31 @@ namespace tvg
|
|||
|
||||
struct Paint::Impl
|
||||
{
|
||||
PaintMethod* method = nullptr;
|
||||
StrategyMethod* smethod = nullptr;
|
||||
|
||||
~Impl() {
|
||||
if (method) delete(method);
|
||||
if (smethod) delete(smethod);
|
||||
}
|
||||
|
||||
void method(StrategyMethod* method)
|
||||
{
|
||||
smethod = method;
|
||||
}
|
||||
|
||||
StrategyMethod* method()
|
||||
{
|
||||
return smethod;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
struct TransformMethod : PaintMethod
|
||||
struct PaintMethod : StrategyMethod
|
||||
{
|
||||
T* inst = nullptr;
|
||||
|
||||
TransformMethod(T* inst) : inst(_inst) {}
|
||||
~TransformMethod(){}
|
||||
PaintMethod(T* _inst) : inst(_inst) {}
|
||||
~PaintMethod(){}
|
||||
|
||||
bool rotate(float degree) override
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
Scene::Scene() : pImpl(make_unique<Impl>())
|
||||
{
|
||||
Paint::IMPL->method = IMPL->transformMethod();
|
||||
Paint::IMPL->method(new PaintMethod<Scene::Impl>(IMPL));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ struct Scene::Impl
|
|||
bool dispose(RenderMethod& renderer)
|
||||
{
|
||||
for (auto paint : paints) {
|
||||
paint->IMPL->method->dispose(renderer);
|
||||
paint->IMPL->method()->dispose(renderer);
|
||||
delete(paint);
|
||||
}
|
||||
paints.clear();
|
||||
|
@ -51,7 +51,7 @@ struct Scene::Impl
|
|||
bool updateInternal(RenderMethod &renderer, const RenderTransform* transform, uint32_t flag)
|
||||
{
|
||||
for(auto paint: paints) {
|
||||
if (!paint->IMPL->method->update(renderer, transform, flag)) return false;
|
||||
if (!paint->IMPL->method()->update(renderer, transform, flag)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ struct Scene::Impl
|
|||
bool render(RenderMethod &renderer)
|
||||
{
|
||||
for(auto paint: paints) {
|
||||
if(!paint->IMPL->method->render(renderer)) return false;
|
||||
if(!paint->IMPL->method()->render(renderer)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ struct Scene::Impl
|
|||
auto w2 = 0.0f;
|
||||
auto h2 = 0.0f;
|
||||
|
||||
if (paint->IMPL->method->bounds(&x2, &y2, &w2, &h2)) return false;
|
||||
if (paint->IMPL->method()->bounds(&x2, &y2, &w2, &h2)) return false;
|
||||
|
||||
//Merge regions
|
||||
if (x2 < x) x = x2;
|
||||
|
@ -203,12 +203,6 @@ struct Scene::Impl
|
|||
if (!loader->read()) return Result::Unknown;
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
PaintMethod* transformMethod()
|
||||
{
|
||||
return new TransformMethod<Scene::Impl>(this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //_TVG_SCENE_IMPL_H_
|
|
@ -31,7 +31,7 @@ constexpr auto PATH_KAPPA = 0.552284f;
|
|||
|
||||
Shape :: Shape() : pImpl(make_unique<Impl>(this))
|
||||
{
|
||||
Paint::IMPL->method = IMPL->transformMethod();
|
||||
Paint::IMPL->method(new PaintMethod<Shape::Impl>(IMPL));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -236,12 +236,6 @@ struct Shape::Impl
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
PaintMethod* transformMethod()
|
||||
{
|
||||
return new TransformMethod<Shape::Impl>(this);
|
||||
}
|
||||
};
|
||||
|
||||
#endif //_TVG_SHAPE_IMPL_H_
|
Loading…
Add table
Reference in a new issue