Windows and sub-windows

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
lukeluke
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Nov 10, 2011 5:50 pm

Windows and sub-windows

Post 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.
asadilan
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Jul 27, 2010 10:42 pm

Re: Windows and sub-windows

Post by asadilan »

moveable second window.
try wxAUI
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Windows and sub-windows

Post by Auria »

or the MDI framework but you will only get small-window-in-big-window behavior on Windows
"Keyboard not detected. Press F1 to continue"
-- Windows
DerKleineNik
Knows some wx things
Knows some wx things
Posts: 29
Joined: Fri Sep 09, 2011 9:59 am

Re: Windows and sub-windows

Post 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
lukeluke
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Nov 10, 2011 5:50 pm

Re: Windows and sub-windows

Post 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??
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Windows and sub-windows

Post 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
lukeluke
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Nov 10, 2011 5:50 pm

Re: Windows and sub-windows

Post 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!!!
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Windows and sub-windows

Post 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
Use the source, Luke!
Post Reply