common paint: revise bounds interface.

we don't use the reference style for user interfaces.

Change-Id: Id70682bf8c2d8ea9ffab2ea6fb567eaa8639da60
This commit is contained in:
Hermet Park 2020-05-22 16:30:13 +09:00
parent 19999e7abd
commit a0521c83c3
6 changed files with 25 additions and 19 deletions

View file

@ -81,7 +81,7 @@ public:
virtual int scale(float factor) = 0;
virtual int translate(float x, float y) = 0;
virtual int bounds(float&x, float& y, float& w, float& h) const = 0;
virtual int bounds(float* x, float* y, float* w, float* h) const = 0;
};
@ -153,7 +153,7 @@ public:
int stroke(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept;
size_t stroke(const size_t** dashPattern) const noexcept;
int bounds(float&x, float& y, float& w, float& h) const noexcept override;
int bounds(float* x, float* y, float* w, float* h) const noexcept override;
static std::unique_ptr<Shape> gen() noexcept;
@ -183,7 +183,7 @@ public:
int scale(float factor) noexcept override;
int translate(float x, float y) noexcept override;
int bounds(float&x, float& y, float& w, float& h) const noexcept override;
int bounds(float* x, float* y, float* w, float* h) const noexcept override;
static std::unique_ptr<Scene> gen() noexcept;

View file

@ -91,16 +91,11 @@ int Scene::translate(float x, float y) noexcept
}
int Scene::bounds(float& x, float& y, float& w, float& h) const noexcept
int Scene::bounds(float* x, float* y, float* w, float* h) const noexcept
{
auto impl = pImpl.get();
assert(impl);
x = FLT_MAX;
y = FLT_MAX;
w = 0;
h = 0;
if (!impl->bounds(x, y, w, h)) return -1;
return 0;

View file

@ -100,8 +100,13 @@ struct Scene::Impl
return true;
}
bool bounds(float& x, float& y, float& w, float& h)
bool bounds(float* px, float* py, float* pw, float* ph)
{
auto x = FLT_MAX;
auto y = FLT_MAX;
auto w = 0.0f;
auto h = 0.0f;
for(auto paint: paints) {
auto x2 = FLT_MAX;
auto y2 = FLT_MAX;
@ -109,9 +114,9 @@ struct Scene::Impl
auto h2 = 0.0f;
if (auto scene = dynamic_cast<Scene*>(paint)) {
if (!SCENE_IMPL->bounds(x2, y2, w2, h2)) return false;
if (!SCENE_IMPL->bounds(&x2, &y2, &w2, &h2)) return false;
} else if (auto shape = dynamic_cast<Shape*>(paint)) {
if (!SHAPE_IMPL->bounds(x2, y2, w2, h2)) return false;
if (!SHAPE_IMPL->bounds(&x2, &y2, &w2, &h2)) return false;
}
//Merge regions
@ -120,6 +125,12 @@ struct Scene::Impl
if (y2 < y) y = x2;
if (y + h < y2 + h2) h = (y2 + h2) - y;
}
if (px) *px = x;
if (py) *py = y;
if (pw) *pw = w;
if (ph) *ph = h;
return true;
}

View file

@ -269,7 +269,7 @@ int Shape::translate(float x, float y) noexcept
}
int Shape::bounds(float& x, float& y, float& w, float& h) const noexcept
int Shape::bounds(float* x, float* y, float* w, float* h) const noexcept
{
auto impl = pImpl.get();
assert(impl);

View file

@ -99,7 +99,7 @@ struct Shape::Impl
return false;
}
bool bounds(float& x, float& y, float& w, float& h)
bool bounds(float* x, float* y, float* w, float* h)
{
assert(path);
return path->bounds(x, y, w, h);

View file

@ -113,7 +113,7 @@ struct ShapePath
cmds[cmdCnt++] = PathCommand::Close;
}
bool bounds(float& x, float& y, float& w, float& h)
bool bounds(float* x, float* y, float* w, float* h)
{
if (ptsCnt == 0) return false;
@ -127,10 +127,10 @@ struct ShapePath
if (pts[i].y > max.y) max.y = pts[i].y;
}
x = min.x;
y = min.y;
w = max.x - min.x;
h = max.y - min.y;
if (x) *x = min.x;
if (y) *y = min.y;
if (w) *w = max.x - min.x;
if (h) *h = max.y - min.y;
return true;
}