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. GDI+ and RoundRect

GDI+ and RoundRect

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswinformsquestion
3 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.
  • A Offline
    A Offline
    Andreas Hallberg
    wrote on last edited by
    #1

    Hi, Does anyone know if the Gdiplus::Graphics class sports a [Fill|Draw]RoundRect() function (or similar.) I know I can use a GraphicsPath object (with lines and arcs) to represent the same shape, but it seems strange that such a basic function could be omitted by the implementation? /Andreas

    C 1 Reply Last reply
    0
    • A Andreas Hallberg

      Hi, Does anyone know if the Gdiplus::Graphics class sports a [Fill|Draw]RoundRect() function (or similar.) I know I can use a GraphicsPath object (with lines and arcs) to represent the same shape, but it seems strange that such a basic function could be omitted by the implementation? /Andreas

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Nope - not there. I did it like this:

      GraphicsPath* CGPaintShape::MakeRoundRect(Point topLeft, Point bottomRight, INT percentageRounded)
      {
      ASSERT (percentageRounded >= 0 && percentageRounded <= 100);

      // Like they said in the X Files - Trust No One.  Rather than crash and burn,
      // I just pull out the correct edges from the points given, regardless of if they were wrong.
      
      INT left  = MIN(topLeft.X, bottomRight.X);
      INT right = MAX(topLeft.X, bottomRight.X);
      
      INT top    = MIN(topLeft.Y, bottomRight.Y);
      INT bottom = MAX(topLeft.Y, bottomRight.Y);
      
      INT offsetX = (right-left)\*percentageRounded/100;  
      INT offsetY = (bottom-top)\*percentageRounded/100;
      
      GraphicsPath \* path = new GraphicsPath;
      
      path->AddArc(right-offsetX, top, offsetX, offsetY, 270, 90);
      
      path->AddArc(right-offsetX, bottom-offsetY, offsetX, offsetY, 0, 90);
      
      path->AddArc(left, bottom - offsetY, offsetX, offsetY, 90, 90);
      
      path->AddArc(left, top, offsetX, offsetY, 180, 90);
      
      path->AddLine(left + offsetX, top, right - offsetX/2, top);
      
      return path;
      

      }

      Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001

      Sonork ID 100.10002:MeanManOz

      I live in Bob's HungOut now

      A 1 Reply Last reply
      0
      • C Christian Graus

        Nope - not there. I did it like this:

        GraphicsPath* CGPaintShape::MakeRoundRect(Point topLeft, Point bottomRight, INT percentageRounded)
        {
        ASSERT (percentageRounded >= 0 && percentageRounded <= 100);

        // Like they said in the X Files - Trust No One.  Rather than crash and burn,
        // I just pull out the correct edges from the points given, regardless of if they were wrong.
        
        INT left  = MIN(topLeft.X, bottomRight.X);
        INT right = MAX(topLeft.X, bottomRight.X);
        
        INT top    = MIN(topLeft.Y, bottomRight.Y);
        INT bottom = MAX(topLeft.Y, bottomRight.Y);
        
        INT offsetX = (right-left)\*percentageRounded/100;  
        INT offsetY = (bottom-top)\*percentageRounded/100;
        
        GraphicsPath \* path = new GraphicsPath;
        
        path->AddArc(right-offsetX, top, offsetX, offsetY, 270, 90);
        
        path->AddArc(right-offsetX, bottom-offsetY, offsetX, offsetY, 0, 90);
        
        path->AddArc(left, bottom - offsetY, offsetX, offsetY, 90, 90);
        
        path->AddArc(left, top, offsetX, offsetY, 180, 90);
        
        path->AddLine(left + offsetX, top, right - offsetX/2, top);
        
        return path;
        

        }

        Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001

        Sonork ID 100.10002:MeanManOz

        I live in Bob's HungOut now

        A Offline
        A Offline
        Andreas Hallberg
        wrote on last edited by
        #3

        Ok, that's what I suspected anyway... I have to deal with different vectors for the ARC, but that should not present any problem. Just wan't to make sure I don't reinvent the wheel to many times :-) Thanks for the reply and sample /Andreas

        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