Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Rotating a shape within a bounding rect?

Rotating a shape within a bounding rect?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialgraphicsquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cdsmith
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • C cdsmith

      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

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      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() and CDC::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"

      C 1 Reply Last reply
      0
      • R Ryan Binns

        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() and CDC::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"

        C Offline
        C Offline
        cdsmith
        wrote on last edited by
        #3

        I want to make the shape smaller so it fits in the box, I guess I'll get out the geometry text books... Craig

        R 1 Reply Last reply
        0
        • C cdsmith

          I want to make the shape smaller so it fits in the box, I guess I'll get out the geometry text books... Craig

          R Offline
          R Offline
          Ryan Binns
          wrote on last edited by
          #4

          :) 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"

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups