I am trying to write an editable rectangle vector class.
With DClick on rectangle the rectangle object must delete.
That is the delete method must be in rect class as well as event must be in same class.
But how i must write the rect class?
In the way i have write the class, compiler says that there is no Connect function in object rect* r( r->Connect).
So how i must write class? There is some sample to see?
Thanks
Jim
Code: Select all
class rect : public wxEvtHandler
{
public:
rect(wxWindow *parent,wxDC& dc, wxPoint& startPoint, wxPoint& endPoint)
{
//ctor
dc.SetPen( wxPen( wxColour( 128, 0, 0 ), 3 ));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(startPoint.x,startPoint.y,endPoint.x-startPoint.x,endPoint.y-startPoint.y);
}
virtual ~rect(){};
void deleterect( wxMouseEvent& event )
{
wxMessageBox("ok i just delete rectangle");
}
protected:
private:
};
class myview : public wxScrolledWindow
{
friend rect;
public:
myview(wxWindow *parent);
private:
void UpdateBitmap();
void OnMouseDown(wxMouseEvent& event);
void OnMouseUp(wxMouseEvent& event);
void OnMouseMove(wxMouseEvent& event);
void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
wxStaticBitmap *m_content;
bool draggingPage;
wxPoint startpoint;
wxPoint endpoint;
DECLARE_EVENT_TABLE()
rect* r;
};
BEGIN_EVENT_TABLE(myview, wxScrolledWindow)
EVT_LEFT_DOWN(myview::OnMouseDown)
EVT_LEFT_UP(myview::OnMouseUp)
EVT_MOTION(myview::OnMouseMove)
EVT_MOUSE_CAPTURE_LOST(myview::OnMouseCaptureLost)
END_EVENT_TABLE()
myview::myview(wxWindow *parent)
: wxScrolledWindow(parent,
wxID_ANY,
wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE)
{
wxBitmap dummyBitmap(16, 16);
m_content = new wxStaticBitmap(this, wxID_ANY, dummyBitmap);
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(m_content, wxSizerFlags(1).Expand());
SetSizer(sizer);
m_content->Connect
(
wxEVT_LEFT_DOWN,
wxMouseEventHandler(myview::OnMouseDown),
NULL,
this
);
r->Connect
(
wxEVT_LEFT_DCLICK,
wxMouseEventHandler( rect::deleterect ),
NULL,
this
);
}
.................
void myview::OnMouseDown(wxMouseEvent& event)
{
wxPoint view_origin;
GetViewStart(&view_origin.x, &view_origin.y);
wxPoint pos = event.GetPosition();
draggingPage = true;
startpoint = pos;
event.Skip();
CaptureMouse();
}
void myview::OnMouseUp(wxMouseEvent& event)
{
const wxPoint pos = event.GetPosition();
draggingPage = false;
endpoint = pos;
ReleaseMouse();
event.Skip();
wxPaintDC dc(this);
r=new rect(this,dc,startpoint,endpoint);
}