wxMDIClientWindow Paint event

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
mariusz
In need of some credit
In need of some credit
Posts: 4
Joined: Wed May 24, 2006 10:12 am

wxMDIClientWindow Paint event

Post by mariusz »

Hi!

I'd like to redraw Client area of the wxMDIClientWindow with bitmap this way

Code: Select all

void MainWnd::OnPaint(wxPaintEvent& event)
{

    wxMDIClientWindow* cwindow = this->wxMDIParentFrame::GetClientWindow();

    wxPaintDC dc(cwindow);


    int vX,vY,vW,vH;                 // Dimensions of client area in pixels
 /*ver1*/   wxRegionIterator upd(GetUpdateRegion());
/*ver2*/   wxRegionIterator upd(cwindow->GetUpdateRegion());

    while (upd)
    {
      vX = upd.GetX();
      vY = upd.GetY();
      vW = upd.GetW();
      vH = upd.GetH();

      dc.SetClippingRegion(vX,vY,vW,vH);

      int xs = (vX/logo->GetWidth())*logo->GetWidth();
      int ys = (vY/logo->GetHeight())*logo->GetHeight();

      int w = (vW / logo->GetWidth())+1 ;
      int h = (vH / logo->GetHeight())+1 ;

      for(int a=0;a<w;a++){
        for(int b=0;b<h;b++){
          dc.DrawBitmap(*logo,xs+(a*logo->GetWidth()),ys+(b*logo->GetHeight()));
        }
      }
      upd ++ ;
    }

}
this is an event enabled by:

Code: Select all

EVT_PAINT(MainWnd::OnPaint)
I got very strange results. With code marked as "ver1" OnPaint is called very often (I have wxThreads that are painting stuff in child frames if that would matter) and with only one region to update that is whole parent window size (not only client area).
In code with "ver2" remark I get no rectangles to update at all :/
I must made a stupid mistake. I'm very fresh with wxWidgets...

Any help ? I can't go with "ver1" since it's doing whole lot of redraws and is kill my application performance.

Thanks !
Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor »

wxPaintEvent is sent to the window to repaint and not to its parent, so if you want to redraw child client area, you must intercept draw event for wxMDIClientWindow.
You just have to overide wxMDIClientWindow and intercept wxPaintEvent as you do but for wxMDIClientWindow derived class.

Note that wxPaintEvent is a classical event, not a wxCommandEvent, so it dont walk up to parent windows.
What is little and green, witch go up and down ??
Yoda playing with the force.
mariusz
In need of some credit
In need of some credit
Posts: 4
Joined: Wed May 24, 2006 10:12 am

Post by mariusz »

Maybe I was't clear enougth. I want to paint on the background of client area of parent window. The area that all child windows are consisted in.
Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor »

As said in the wxMDIParentFrame doc [1], you must derive wxMDIClientWindow to implement your background paint and override wxMDIParentFrame::OnCreateClient to explicitly use your own wxMDIClientWindow class.

[1] : http://www.wxwidgets.org/manuals/2.6.3/ ... eateclient
What is little and green, witch go up and down ??
Yoda playing with the force.
mariusz
In need of some credit
In need of some credit
Posts: 4
Joined: Wed May 24, 2006 10:12 am

Post by mariusz »

Thanks, this sounds good, but I'm not able to make any usefull code out of this :/ Any pointer to Samples ?
Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor »

I cant test here but something like thatshould work :

Code: Select all

class MyClient : public wxMDIClientWindow{
protected:
  DECLARE_EVENT_TABLE()
  void OnEraseBg(wxEraseEvent& event);
...
};

void MyClient::OnEraseBg(wxEraseEvent& event){
  event.GetDC().DrawImage(...); // Blit your image directly.
}

BEGIN_EVENT_TABLE(MyClient, wxMDIClientWindow)
  EVT_ERASE_BACKGROUND(MyClient::OnEraseBg)
END_EVENT_TABLE()

class MyFrame : public wxMDIParentFrame{
protected:
  virtual wxMDIClientWindow* OnCreateClient();
  ...
};

wxMDIClientWindow* MyFrame::OnCreateClient(){
  return new MyClient(this);
}

bool MyApp:OnInit(){
  MyFrame* frame = new MyFrame;
  frame->Create();
  ...
  return true;
}
What is little and green, witch go up and down ??
Yoda playing with the force.
Post Reply