Page 1 of 1

Windows and sub-windows

Posted: Wed Nov 16, 2011 6:25 pm
by lukeluke
Hi,

i want to write a simple app with wxWidgtes. The app have to:

1] create the main window (with menu, toolbar etc...)
2] create another window that stay *inside* the main window, centered in it, with no border, bars, icons...just a plain square window. I will render in it
something with OpenGL. This second window should be moveable, resizable by code.

Using one of the wxWidgets examples (toolbar) I am at the point 2 but am unable to make the 2° window inside the 1° one. How can i do that?
Thx.

Re: Windows and sub-windows

Posted: Wed Nov 16, 2011 8:50 pm
by asadilan
moveable second window.
try wxAUI

Re: Windows and sub-windows

Posted: Wed Nov 16, 2011 9:52 pm
by Auria
or the MDI framework but you will only get small-window-in-big-window behavior on Windows

Re: Windows and sub-windows

Posted: Thu Nov 17, 2011 7:19 am
by DerKleineNik
with no border, bars, icons...just a plain square window
you can use then a panel or does it have to be an wxWindow?
By using a panel you just have to set an sizer and add this panel to the sizer. You can move and resize the panel using code as you said and you can easily build a canvas in that panel to render using opengl

Re: Windows and sub-windows

Posted: Thu Nov 17, 2011 5:49 pm
by lukeluke
Ok, i am trying the auidemo, since it seems really advanced but not too complex to understand.

I would like to add a wxPanel to the wxAuiNotebook control. It is really simple>


wxAuiNotebook* ctrl = new wxAuiNotebook(this, wxID_ANY,
wxPoint(client_size.x, client_size.y),
wxSize(430,200),
m_notebook_style);


ctrl->AddPage( new wxPanel( ctrl ), wxT("MyPanel") );

and it works perfectly.

But, if i create a subclass of wxPanel in order to implement my OnPaint() method, it doens't work:


/**
*/
class CGamePanel : public wxPanel
{
public:



CGamePanel(wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTAB_TRAVERSAL | wxNO_BORDER,
const wxString& name = wxPanelNameStr) : wxPanel( parent, winid, pos, size, style, name)
{
}


void OnPaint(wxPaintEvent& event)
{
wxPanel::OnPaint( event );
}


void OnSize(wxSizeEvent& event)
{

// this is also necessary to update the context on some platforms
wxPanel::OnSize(event);

}



void OnEnterWindow( wxMouseEvent& WXUNUSED(event) )
{
SetFocus();
}


DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(CGamePanel, wxPanel)
EVT_PAINT(CGamePanel::OnPaint)
EVT_SIZE(CGamePanel::OnSize)
EVT_ENTER_WINDOW( CGamePanel::OnEnterWindow )
END_EVENT_TABLE()



As you can see, the code of CGamePanel is really simple: it just intercept the paint event and call the original Paint method, but it does not work properly.

What am i doing wrong??

Re: Windows and sub-windows

Posted: Thu Nov 17, 2011 7:30 pm
by DavidHart
Hi,
What am i doing wrong??
Apart from forgetting to use code-tags, you mean? ;)

See the first paragraph of the wxPaintDC doc.

Regards,

David

Re: Windows and sub-windows

Posted: Thu Nov 17, 2011 10:26 pm
by lukeluke
David, thx!! It worked immediately.
What i am trying to do is to use OpenGL and wxWidgets.
But i don't want to follow the cube example, i am trying to do another thing.

Suppose that you have a image, produced in memory after some elaborations (of WxHx4 bytes (an RGBA image)).
This image is produced using OpenGL: in practice i render the scene on an invisible window, 30 times per second.

I would like to draw this image at the center of the panel, using wxPaintDC.

So, my questions are:

1. Given a char * pointing to a WxHx4 RGBA image, how do i draw it to a wxPanel client area? My image will always be an RGBA image.
2. I have a timer called 30 times per seconds. Inside the callback, i call my render method and retrieve the image
from the back buffer. How can i force the update of the wxPanel in order to show the new image? How to do this without
introducing flickering?

Thx!!!

Re: Windows and sub-windows

Posted: Thu Nov 17, 2011 11:28 pm
by doublemax
1. Given a char * pointing to a WxHx4 RGBA image, how do i draw it to a wxPanel client area? My image will always be an RGBA image.
http://forums.wxwidgets.org/viewtopic.p ... 267#p86267
After you have the wxBitmap you can blit it onto your wxPaintDC
How can i force the update of the wxPanel in order to show the new image? How to do this without
introducing flickering?
Just call Refresh() on the panel.
http://wiki.wxwidgets.org/Drawing_on_a_ ... flickering