simplify DrawingPanel classes w. dynamic_cast<>

Use dynamic_cast<wxWindow*>(this) in the DrawingPanel abstract class to
implement GetWindow() and Delete() so that all concrete classes do not
have to duplicate the code.
This commit is contained in:
Rafael Kitover 2016-10-23 11:38:54 -07:00
parent d543217f6a
commit 0192d9a362
2 changed files with 5 additions and 35 deletions

View File

@ -6,14 +6,6 @@
class BasicDrawingPanel : public DrawingPanel, public wxPanel {
public:
BasicDrawingPanel(wxWindow* parent, int _width, int _height);
wxWindow* GetWindow()
{
return this;
}
void Delete()
{
Destroy();
}
protected:
void PaintEv2(wxPaintEvent& ev)
@ -33,14 +25,6 @@ class GLDrawingPanel : public DrawingPanel, public wxGLCanvas {
public:
GLDrawingPanel(wxWindow* parent, int _width, int _height);
virtual ~GLDrawingPanel();
wxWindow* GetWindow()
{
return this;
}
void Delete()
{
Destroy();
}
protected:
void PaintEv2(wxPaintEvent& ev)
@ -64,14 +48,6 @@ protected:
class DXDrawingPanel : public DrawingPanel, public wxPanel {
public:
DXDrawingPanel(wxWindow* parent, int _width, int _height);
wxWindow* GetWindow()
{
return this;
}
void Delete()
{
Destroy();
}
protected:
void PaintEv2(wxPaintEvent& ev)
@ -93,14 +69,6 @@ class CairoDrawingPanel : public DrawingPanel, public wxPanel {
public:
CairoDrawingPanel(wxWindow* parent, int _width, int _height);
~CairoDrawingPanel();
wxWindow* GetWindow()
{
return this;
}
void Delete()
{
Destroy();
}
protected:
void PaintEv2(wxPaintEvent& ev)

View File

@ -628,9 +628,11 @@ public:
DrawingPanel(int _width, int _height);
~DrawingPanel();
void DrawArea(uint8_t** pixels);
// the following wouldn't be necessary with virtual inheritance
virtual wxWindow* GetWindow() = 0;
virtual void Delete() = 0;
// using dynamic_cast<> to not force trivial reimplementation in concrete classes
// TODO: figure something out for PaintEv as well
virtual wxWindow* GetWindow() { return dynamic_cast<wxWindow*>(this); }
virtual void Delete() { (dynamic_cast<wxWindow*>(this))->Destroy(); }
protected:
virtual void DrawArea(wxWindowDC&) = 0;