Changing frame shape

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Raghu
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Oct 19, 2005 11:33 am

Changing frame shape

Post by Raghu » Mon Nov 14, 2005 6:28 am

How could I change the shape of the window frame. Window frame by default would be rectangular, how could I make it circular or oval.
SetShape() can be used to give polygon shape, but not useful in creating circular shape. Can somebody help me out?

Thank u

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Re: Changing frame shape

Post by upCASE » Mon Nov 14, 2005 7:54 am

Raghu wrote:How could I change the shape of the window frame. Window frame by default would be rectangular, how could I make it circular or oval.
SetShape() can be used to give polygon shape, but not useful in creating circular shape. Can somebody help me out?
The easiest way to achieve this would be using a bitmap as a mask and creating the wxRegion using this mask. For simple graphic primitives like a circle this can be done on the fly by using w wxMemoryDC.

Code: Select all

wxMemoryDC dc;
wxBitmap bitmap(200,200);
dc.SelectObject(bitmap);
dc.SetBrush(*wxGREEN_BRUSH);
dc.DrawCircle(100,100,50);
This would create a bitmap filled with a green circle on a black background. To create the region use

Code: Select all

wxRegion region(bitmap, *wxBLACK);
Resize the window to the bitmaps size and use SetShape() on it. For an ellipse it's essentialy the same.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

waterj
Earned a small fee
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am

Re: Changing frame shape

Post by waterj » Wed Nov 30, 2005 9:57 am

upCASE wrote:
Raghu wrote:How could I change the shape of the window frame. Window frame by default would be rectangular, how could I make it circular or oval.
SetShape() can be used to give polygon shape, but not useful in creating circular shape. Can somebody help me out?
The easiest way to achieve this would be using a bitmap as a mask and creating the wxRegion using this mask. For simple graphic primitives like a circle this can be done on the fly by using w wxMemoryDC.

Code: Select all

wxMemoryDC dc;
wxBitmap bitmap(200,200);
dc.SelectObject(bitmap);
dc.SetBrush(*wxGREEN_BRUSH);
dc.DrawCircle(100,100,50);
This would create a bitmap filled with a green circle on a black background. To create the region use

Code: Select all

wxRegion region(bitmap, *wxBLACK);
Resize the window to the bitmaps size and use SetShape() on it. For an ellipse it's essentialy the same.
wxRegion region(bitmap, *wxBLACK) has poor performance. Is there something like CreateEllipticRegion of windows GDI?

priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia » Wed Nov 30, 2005 2:40 pm

look at the samples\shaped in your wxWidgets installation folder.

CreateEllipticRgn in Win also restricts you from creating only elliptical region, wxRegion region(bitmap, *wxBLACK) does not cost more, I had used in my programs for several frames and the performance is negotiable for the beautiful effect it generates. Also if you want you can manually give the points to the region for shaping the frame.

Also see:http://forums.wxwidgets.org/viewtopic.php?t=5290

Post Reply