The DataViewer may be extended by an arbitrary amount overlays. These are classes derived from 'iplt::gui::Overlay', either directly in Python or written in C++ and then exported to Python. They are added dynamically to each viewer by means of the DataViewer::AddOverlay method.
An overlay can draw on top of an image in the OnDraw method. If it is the active Overlay, it also receives mouse and keyboard events via the OnMouseEvent and OnKeyEvent methods. A minimalistic overlay that demonstrates this functionality is given below, and can also be found in `src/gui/lib/null_overlay.hh'.
#include "overlay_base.hh" class NullOverlay: public iplt::gui::Overlay { public: // the ctor must initialize the Overlay base class with a name NullOverlay(): Overlay("NullOverlay") {} // This must be implemented to allow duplication virtual OverlayPtr Clone() const { return OverlayPtr(new NullOverlay(*this)); } // This method is called for each redraw of the image viewer, after the image itself // has been rendered in the view widget. The device context as well as the data viewer // panel are passed virtual void OnDraw(wxDC& dc, const iplt::gui::DataViewerPanel* dvp, bool is_active) { } // Called if this is the active overlay, passing the mouse event. Must return flag to // indicate wether the event was handled (true), or not (false), where the latter allows // the image viewer to handle the event itself virtual bool OnMouseEvent(const wxMouseEvent& e) { return false; } // dito for a key event virtual bool OnKeyEvent(const wxKeyEvent& e) { return false; } // allows a custom overlay menu to be included, a return of 0 indicates no menu virtual wxMenu* GetMenu() { return 0; } };
