box point test fix
This commit is contained in:
parent
9c8f585bf4
commit
9ba2cf6613
@ -424,8 +424,10 @@ b32 UI_IsPointInBox(UI_Box *box, Vec2 point)
|
|||||||
/* TODO: More efficient test. This logic is just copied from the renderer's SDF function for now. */
|
/* TODO: More efficient test. This logic is just copied from the renderer's SDF function for now. */
|
||||||
Vec2 p0 = box->p0;
|
Vec2 p0 = box->p0;
|
||||||
Vec2 p1 = box->p1;
|
Vec2 p1 = box->p1;
|
||||||
f32 inside_edge_dist = MinF32(MinF32(point.x - p0.x, p1.x - point.x), MinF32(point.y - p0.y, p1.y - point.y));
|
b32 is_corner = 0;
|
||||||
if (inside_edge_dist > 0)
|
f32 non_corner_edge_dist = MinF32(MinF32(point.x - p0.x, p1.x - point.x), MinF32(point.y - p0.y, p1.y - point.y));
|
||||||
|
f32 corner_edge_dist = 0;
|
||||||
|
if (non_corner_edge_dist >= 0)
|
||||||
{
|
{
|
||||||
f32 tl_radius = box->rounding_tl;
|
f32 tl_radius = box->rounding_tl;
|
||||||
f32 tr_radius = box->rounding_tr;
|
f32 tr_radius = box->rounding_tr;
|
||||||
@ -435,12 +437,12 @@ b32 UI_IsPointInBox(UI_Box *box, Vec2 point)
|
|||||||
Vec2 tr = VEC2(p1.x - tr_radius, p0.y + tr_radius);
|
Vec2 tr = VEC2(p1.x - tr_radius, p0.y + tr_radius);
|
||||||
Vec2 br = VEC2(p1.x - br_radius, p1.y - br_radius);
|
Vec2 br = VEC2(p1.x - br_radius, p1.y - br_radius);
|
||||||
Vec2 bl = VEC2(p0.x + bl_radius, p1.y - bl_radius);
|
Vec2 bl = VEC2(p0.x + bl_radius, p1.y - bl_radius);
|
||||||
if (point.x < tl.x && point.y < tl.y) inside_edge_dist = MinF32(inside_edge_dist, tl_radius - Vec2Len(SubVec2(tl, point)));
|
if (point.x < tl.x && point.y < tl.y) corner_edge_dist = MinF32(corner_edge_dist, tl_radius - Vec2Len(SubVec2(tl, point)));
|
||||||
if (point.x > tr.x && point.y < tr.y) inside_edge_dist = MinF32(inside_edge_dist, tr_radius - Vec2Len(SubVec2(tr, point)));
|
if (point.x > tr.x && point.y < tr.y) corner_edge_dist = MinF32(corner_edge_dist, tr_radius - Vec2Len(SubVec2(tr, point)));
|
||||||
if (point.x > br.x && point.y > br.y) inside_edge_dist = MinF32(inside_edge_dist, br_radius - Vec2Len(SubVec2(br, point)));
|
if (point.x > br.x && point.y > br.y) corner_edge_dist = MinF32(corner_edge_dist, br_radius - Vec2Len(SubVec2(br, point)));
|
||||||
if (point.x < bl.x && point.y > bl.y) inside_edge_dist = MinF32(inside_edge_dist, bl_radius - Vec2Len(SubVec2(bl, point)));
|
if (point.x < bl.x && point.y > bl.y) corner_edge_dist = MinF32(corner_edge_dist, bl_radius - Vec2Len(SubVec2(bl, point)));
|
||||||
}
|
}
|
||||||
return inside_edge_dist >= 0;
|
return non_corner_edge_dist >= 0 && corner_edge_dist >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user