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:
parent
d543217f6a
commit
0192d9a362
|
@ -6,14 +6,6 @@
|
||||||
class BasicDrawingPanel : public DrawingPanel, public wxPanel {
|
class BasicDrawingPanel : public DrawingPanel, public wxPanel {
|
||||||
public:
|
public:
|
||||||
BasicDrawingPanel(wxWindow* parent, int _width, int _height);
|
BasicDrawingPanel(wxWindow* parent, int _width, int _height);
|
||||||
wxWindow* GetWindow()
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
void Delete()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void PaintEv2(wxPaintEvent& ev)
|
void PaintEv2(wxPaintEvent& ev)
|
||||||
|
@ -33,14 +25,6 @@ class GLDrawingPanel : public DrawingPanel, public wxGLCanvas {
|
||||||
public:
|
public:
|
||||||
GLDrawingPanel(wxWindow* parent, int _width, int _height);
|
GLDrawingPanel(wxWindow* parent, int _width, int _height);
|
||||||
virtual ~GLDrawingPanel();
|
virtual ~GLDrawingPanel();
|
||||||
wxWindow* GetWindow()
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
void Delete()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void PaintEv2(wxPaintEvent& ev)
|
void PaintEv2(wxPaintEvent& ev)
|
||||||
|
@ -64,14 +48,6 @@ protected:
|
||||||
class DXDrawingPanel : public DrawingPanel, public wxPanel {
|
class DXDrawingPanel : public DrawingPanel, public wxPanel {
|
||||||
public:
|
public:
|
||||||
DXDrawingPanel(wxWindow* parent, int _width, int _height);
|
DXDrawingPanel(wxWindow* parent, int _width, int _height);
|
||||||
wxWindow* GetWindow()
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
void Delete()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void PaintEv2(wxPaintEvent& ev)
|
void PaintEv2(wxPaintEvent& ev)
|
||||||
|
@ -93,14 +69,6 @@ class CairoDrawingPanel : public DrawingPanel, public wxPanel {
|
||||||
public:
|
public:
|
||||||
CairoDrawingPanel(wxWindow* parent, int _width, int _height);
|
CairoDrawingPanel(wxWindow* parent, int _width, int _height);
|
||||||
~CairoDrawingPanel();
|
~CairoDrawingPanel();
|
||||||
wxWindow* GetWindow()
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
void Delete()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void PaintEv2(wxPaintEvent& ev)
|
void PaintEv2(wxPaintEvent& ev)
|
||||||
|
|
|
@ -628,9 +628,11 @@ public:
|
||||||
DrawingPanel(int _width, int _height);
|
DrawingPanel(int _width, int _height);
|
||||||
~DrawingPanel();
|
~DrawingPanel();
|
||||||
void DrawArea(uint8_t** pixels);
|
void DrawArea(uint8_t** pixels);
|
||||||
// the following wouldn't be necessary with virtual inheritance
|
|
||||||
virtual wxWindow* GetWindow() = 0;
|
// using dynamic_cast<> to not force trivial reimplementation in concrete classes
|
||||||
virtual void Delete() = 0;
|
// 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:
|
protected:
|
||||||
virtual void DrawArea(wxWindowDC&) = 0;
|
virtual void DrawArea(wxWindowDC&) = 0;
|
||||||
|
|
Loading…
Reference in New Issue