BShape: move bounding box method to shape_data
* Makes it easier to get the bounding box from inside app_server
This commit is contained in:
@@ -27,6 +27,36 @@ struct shape_data {
|
|||||||
BPoint* ptList;
|
BPoint* ptList;
|
||||||
int32 ptCount;
|
int32 ptCount;
|
||||||
int32 ptSize;
|
int32 ptSize;
|
||||||
|
|
||||||
|
BRect DetermineBoundingBox() const
|
||||||
|
{
|
||||||
|
BRect bounds;
|
||||||
|
|
||||||
|
if (ptCount == 0)
|
||||||
|
return bounds;
|
||||||
|
|
||||||
|
// TODO: This implementation doesn't take into account curves at all.
|
||||||
|
bounds.left = ptList[0].x;
|
||||||
|
bounds.top = ptList[0].y;
|
||||||
|
bounds.right = ptList[0].x;
|
||||||
|
bounds.bottom = ptList[0].y;
|
||||||
|
|
||||||
|
for (int32 i = 1; i < ptCount; i++) {
|
||||||
|
if (bounds.left > ptList[i].x)
|
||||||
|
bounds.left = ptList[i].x;
|
||||||
|
|
||||||
|
if (bounds.top > ptList[i].y)
|
||||||
|
bounds.top = ptList[i].y;
|
||||||
|
|
||||||
|
if (bounds.right < ptList[i].x)
|
||||||
|
bounds.right = ptList[i].x;
|
||||||
|
|
||||||
|
if (bounds.bottom < ptList[i].y)
|
||||||
|
bounds.bottom = ptList[i].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -306,32 +306,7 @@ BRect
|
|||||||
BShape::Bounds() const
|
BShape::Bounds() const
|
||||||
{
|
{
|
||||||
shape_data* data = (shape_data*)fPrivateData;
|
shape_data* data = (shape_data*)fPrivateData;
|
||||||
BRect bounds;
|
return data->DetermineBoundingBox();
|
||||||
|
|
||||||
if (data->ptCount == 0)
|
|
||||||
return bounds;
|
|
||||||
|
|
||||||
// TODO: This implementation doesn't take into account curves at all.
|
|
||||||
bounds.left = data->ptList[0].x;
|
|
||||||
bounds.top = data->ptList[0].y;
|
|
||||||
bounds.right = data->ptList[0].x;
|
|
||||||
bounds.bottom = data->ptList[0].y;
|
|
||||||
|
|
||||||
for (int32 i = 1; i < data->ptCount; i++) {
|
|
||||||
if (bounds.left > data->ptList[i].x)
|
|
||||||
bounds.left = data->ptList[i].x;
|
|
||||||
|
|
||||||
if (bounds.top > data->ptList[i].y)
|
|
||||||
bounds.top = data->ptList[i].y;
|
|
||||||
|
|
||||||
if (bounds.right < data->ptList[i].x)
|
|
||||||
bounds.right = data->ptList[i].x;
|
|
||||||
|
|
||||||
if (bounds.bottom < data->ptList[i].y)
|
|
||||||
bounds.bottom = data->ptList[i].y;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bounds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user