Need suggestions about creating special-shaped widget from wxControl or draw them with OpenGL Topic is solved

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
User avatar
JohnKnow
Knows some wx things
Knows some wx things
Posts: 41
Joined: Tue Aug 31, 2021 4:14 am

Need suggestions about creating special-shaped widget from wxControl or draw them with OpenGL

Post by JohnKnow »

Hello,
I'm going to create a special-shaped control.
It looks like this, there are 5 buttons in it.
sample.png
sample.png (4.19 KiB) Viewed 3434 times
I'm not sure what is a good way to this goal.
As I know, widgets always take a rectangle area. It is impossible to make a widget occupy some area of another one?
So, I may create a combined widget which contain some shaped area as buttons myself. Should I draw with wxControl's OnPaint directly or wxGLCanvas?
No, I know everything.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Need suggestions about creating special-shaped widget from wxControl or draw them with OpenGL

Post by ONEEYEMAN »

Hi,
Take a look at the shaped sample.

Thank you.
User avatar
JohnKnow
Knows some wx things
Knows some wx things
Posts: 41
Joined: Tue Aug 31, 2021 4:14 am

Re: Need suggestions about creating special-shaped widget from wxControl or draw them with OpenGL

Post by JohnKnow »

Hello,
I browsed shaped.cpp.
Seems only wxNonOwnedWindow can have a shape. But its derived window is "non-child windows".
No, I know everything.
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Need suggestions about creating special-shaped widget from wxControl or draw them with OpenGL

Post by doublemax »

I don't think you'll be able to make 1-5 individual windows as their boxes would overlap. But it should be possible to make the whole thing a custom control, but you'd have to handle mouse events on the 5 individual areas yourself.

On top of that, you'll probably wait until this PR is applied to the master branch: https://github.com/wxWidgets/wxWidgets/pull/23498
Use the source, Luke!
User avatar
JohnKnow
Knows some wx things
Knows some wx things
Posts: 41
Joined: Tue Aug 31, 2021 4:14 am

Re: Need suggestions about creating special-shaped widget from wxControl or draw them with OpenGL

Post by JohnKnow »

ONEEYEMAN, doublemax,
Thank you for the suggestion.

I made a little change then used a chip solution (though have a limitation) which allow some overlap between controls.
1. Add a panel with XRC, create 5 buttons in the panel with code.
2. Create button images with alpha channel, background should be transparent.
3. Adjust their position. There will be some overlap area between the 5 buttons. Need ensure that the overlap area is all background, no foreground in it, or one foreground will be overwrite by another background.
4. Add wxBORDER_NONE flag to button style.
No, I know everything.
Post Reply