Page 1 of 1

cast subclassed widget

Posted: Tue Jun 12, 2018 10:08 pm
by papillon68
Hello and sorry for the newbie question. I'm using the OpenGL/pyramid sample and I'd like to the glCanvas into a wxPanel rather than the main frame.
In the sample:

Code: Select all

if ( accepted ) 		m_mycanvas = new MyGLCanvas(this, vAttrs);
the canvas this parent is a subclassed wxFrame (MyFrame).

I'd like to go this way instead:

Code: Select all

wxPanel *oglPane = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(300, 200));
 if ( accepted ) 		m_mycanvas = new MyGLCanvas(oglPane, vAttrs);
Now, I've searched and tried using wxDynamicCast but no matter what, I can't find a way to overcome the issue. Any suggestion is greatly appreciated.

Re: cast to subclassed widget

Posted: Tue Jun 12, 2018 10:24 pm
by doublemax
What's the definition of the MyGLCanvas constructor? Most likely the first parameter is a wxFrame*. Change it to wxWindow* and it will probably work. If not, post the error message (and more code).

Re: cast to subclassed widget

Posted: Wed Jun 13, 2018 9:20 am
by papillon68
Hi and thanks for the help. I did as you suggested and the code compiles fine; however, the OpenGL canvas doesn't show anything.
In the case somebody might take a look, I'm attaching the source code (it's the pyramid sample slightly changed): I basically would like to have a wxPanel with some controls, and a separate wxPanel with the OpenGL canvas.
I'm not sure why isn't working correctly, I created both wxPanel's and added the controls accordingly. Thanks.
testingWx.zip
(30.39 KiB) Downloaded 67 times

Re: cast subclassed widget

Posted: Wed Jun 13, 2018 3:08 pm
by Manolo
Your issue may come from using fixed sizes and positions. Better create one or several wxsizers and let them do the windows layouts.

The layout may be something like

Code: Select all

main Frame
_____________ _____________
|   panel   | |  glcanvas  |
|           | |            |
___________________________
|       static text        |
|__________________________|
then use two wxBozSizer's:
a) sizerH horizontal, handling panel and glcanvas (there's no obvious profit in putting a glcanvas as child of a panel)
b) sizerV vertical: handles sizerH and the static text

If the panel has several controls, then use another sizer for them.

Re: cast subclassed widget

Posted: Wed Jun 13, 2018 3:50 pm
by papillon68
Thanks Manolo that makes sense. Will follow your hints and report...