Rotating a shape within a bounding rect?
-
Hello All, I am working on a drawing package. The user can drag and drop shapes (i.e. rect, elipse, star,...) and text into defined boxes on the screen. One requirement is to allow the user to rotate the shapes within the boxes. I have the rotation code down, but I am having trouble keeping the rotated shape in the box. For example when the user drops an elipse (tall and narrow) into a box. When I rotate this elipse 45 degrees it becomes bigger than the bounding box. Any ideas on how to allow the rotation but still keep the shape in the bounding box. Thanks! Craig
-
Hello All, I am working on a drawing package. The user can drag and drop shapes (i.e. rect, elipse, star,...) and text into defined boxes on the screen. One requirement is to allow the user to rotate the shapes within the boxes. I have the rotation code down, but I am having trouble keeping the rotated shape in the box. For example when the user drops an elipse (tall and narrow) into a box. When I rotate this elipse 45 degrees it becomes bigger than the bounding box. Any ideas on how to allow the rotation but still keep the shape in the bounding box. Thanks! Craig
Do you want to make the shape smaller so it fits, or clip the shape to the size of the box? To make it smaller, you'll need to use your maths and recalculate the size of the shape. To clip the shape to the box, use
CRgn::CreateRectRgn()
andCDC::SelectClipRgn()
to create a rectangular region and clip the drawing to that region.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Do you want to make the shape smaller so it fits, or clip the shape to the size of the box? To make it smaller, you'll need to use your maths and recalculate the size of the shape. To clip the shape to the box, use
CRgn::CreateRectRgn()
andCDC::SelectClipRgn()
to create a rectangular region and clip the drawing to that region.Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
I want to make the shape smaller so it fits in the box, I guess I'll get out the geometry text books... Craig
:) Yeah, and when you figure it out, think about writing an article to post. That would be cool :cool: It shouldn't be too difficult, but will depend on the shape you're working with. If you're dealing with a polygon, you can calculate the distance out of the box for each point, and scale all the points so that the furthest one fits in the box. Sounds complex, but I don't think it is really, just takes a bit of thought :)
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"