I'm just learning wxWidgets and I'm facing an issue with a custom control I'm creating that's derived from wxWindow. I've created a method to handle the wxEVT_PAINT event, but it doesn't seem to be called. I set a breakpoint on the first line of paintEvent(), but it doesn't break.
I'm using the latest stable version of wxWidgets on Windows 10.
FNDie.h:
Code: Select all
#ifndef FNDIE_H
#define FNDIE_H
#include <wx/window.h> // Base class: wxWindow
#include <wx/wx.h>
class FNDie : public wxWindow
{
int m_value;
bool m_selected;
bool m_enabled;
bool m_mouseDown;
public:
void paintEvent(wxPaintEvent& evt);
void mouseDown(wxMouseEvent& evt);
void mouseLeftWindow(wxMouseEvent& evt);
void mouseUp(wxMouseEvent& evt);
FNDie(wxFrame* parent, int id);
~FNDie();
};
#endif // FNDIE_H
Code: Select all
#include "FNDie.h"
FNDie::FNDie(wxFrame* parent, int id)
{
Bind(wxEVT_PAINT, &FNDie::paintEvent, this);
}
FNDie::~FNDie()
{
}
void FNDie::mouseDown(wxMouseEvent& evt)
{
m_mouseDown = true;
evt.Skip(true);
}
void FNDie::mouseLeftWindow(wxMouseEvent& evt)
{
m_mouseDown = false;
}
void FNDie::mouseUp(wxMouseEvent& evt)
{
if (m_mouseDown)
{
// handle mouse click.
m_mouseDown = false;
}
}
void FNDie::paintEvent(wxPaintEvent& evt)
{
wxPaintDC dc(this);
dc.SetBrush(wxBrush(*wxBLACK, wxBRUSHSTYLE_SOLID));
dc.SetPen(wxPen(*wxBLACK, 5, wxPENSTYLE_SOLID));
wxSize size = this->GetClientSize();
dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
}