dc tutorial clipping when resizing Topic is solved

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
mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 449
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

dc tutorial clipping when resizing

Post by mael15 » Tue Jun 09, 2009 1:13 pm

hi,

i wanted to understand how redrawing and resizing work by customizing the very simple tutorial http://zetcode.com/tutorials/wxwidgetstutorial/gdi/

the problem is that the line is cut off when i maximaize the window. the direction is correct, but the line is no longer than the size of the device context BEFORE maximizing.

here are the files:

line.h

Code: Select all

#include <wx/wx.h>

class Line : public wxFrame
{
public:
    Line(const wxString& title);

    void OnSize(wxSizeEvent& event);
	void OnMax(wxMaximizeEvent& event);
	void drawStuff();
};
line.cpp

Code: Select all

#include "line.h"

Line::Line(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(400, 380))
{
  this->Connect(wxEVT_SIZE, wxSizeEventHandler(Line::OnSize));
  this->Connect(wxEVT_MAXIMIZE, wxMaximizeEventHandler(Line::OnMax));
  this->Centre();
}

void Line::OnSize(wxSizeEvent& event)
{
	if(!this->IsMaximized())
		drawStuff();
}

void Line::OnMax(wxMaximizeEvent& event){
	drawStuff();
}

void Line::drawStuff(){
	wxClientDC dc(this);
	dc.Clear();

	wxSize size = this->GetSize();

	wxCoord x1 = 10, y1 = 60;
	wxCoord x2 = size.x-10, y2 = size.y-30;

	this->SetFocus();
	dc.DrawLine(x1, y1, x2, y2);
}
main.h

Code: Select all

#include <wx/wx.h>

class MyApp : public wxApp
{
  public:
    virtual bool OnInit();
};
main.cpp

Code: Select all

#include "main.h"
#include "line.h"

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    Line *line = new Line(wxT("Line"));
    line->Show(true);

    return true;
}
what am i missing?

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Tue Jun 09, 2009 2:28 pm

Check the DC examples on the wiki; wxClientDC can be useful, but using it alone generally does not make it. Look into using paint events and using wxPaintDC. Then, you don't even need to catch the ONSize event, as a new paint event will be fired after the window is resized
"Keyboard not detected. Press F1 to continue"
-- Windows

Post Reply