dc tutorial clipping when resizing
Posted: 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
line.cpp
main.h
main.cpp
what am i missing?
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();
};
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);
}
Code: Select all
#include <wx/wx.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
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;
}