Commit 74068827 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

ENH: Further refactoring of the items/scene.

Placing the appropriate functions in the common base, refactoring to
support a richer scene API.
parent 0c9f4a63
......@@ -31,6 +31,53 @@ void vtkAbstractContextItem::Update()
{
}
//-----------------------------------------------------------------------------
bool vtkAbstractContextItem::Hit(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkAbstractContextItem::MouseEnterEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkAbstractContextItem::MouseMoveEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkAbstractContextItem::MouseLeaveEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkAbstractContextItem::MouseButtonPressEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkAbstractContextItem::MouseButtonReleaseEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkAbstractContextItem::MouseWheelEvent(const vtkContextMouseEvent &, int)
{
return false;
}
// ----------------------------------------------------------------------------
void vtkAbstractContextItem::ReleaseGraphicsResources()
{
}
//-----------------------------------------------------------------------------
void vtkAbstractContextItem::PrintSelf(ostream &os, vtkIndent indent)
{
......
......@@ -27,6 +27,7 @@
#include "vtkObject.h"
class vtkContext2D;
class vtkContextMouseEvent;
class VTK_CHARTS_EXPORT vtkAbstractContextItem : public vtkObject
{
......@@ -44,6 +45,53 @@ public:
// Paint event for the item, called whenever the item needs to be drawn.
virtual bool Paint(vtkContext2D *painter) = 0;
// Description:
// Release graphics resources hold by the item. The default implementation
// is empty.
virtual void ReleaseGraphicsResources();
//BTX
// Description:
// Return true if the supplied x, y coordinate is inside the item.
virtual bool Hit(const vtkContextMouseEvent &mouse);
// Description:
// Mouse enter event.
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseEnterEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse move event.
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse leave event.
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseLeaveEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse button down event
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse button release event.
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse wheel event, positive delta indicates forward movement of the wheel.
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseWheelEvent(const vtkContextMouseEvent &mouse, int delta);
//ETX
//BTX
protected:
vtkAbstractContextItem();
......
......@@ -25,6 +25,7 @@
class vtkPlot;
class vtkAxis;
class vtkTransform2D;
class vtkPlotGrid;
class vtkTable;
class vtkChartLegend;
......@@ -146,7 +147,7 @@ public:
virtual void SetScene(vtkContextScene *scene);
// Description:
// Return the Stacked plot accumulator so that each vtkPlotStacked can
// Return the Stacked plot accumulator so that each vtkPlotStacked can
// use it to determine its base and contribute to the position of the next
// stacked plot.
vtkDataArray *GetStackedPlotAccumulator(int dataType, int n);
......
......@@ -52,53 +52,6 @@ vtkContextScene* vtkContextItem::GetScene()
return this->Scene.GetPointer();
}
//-----------------------------------------------------------------------------
bool vtkContextItem::Hit(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkContextItem::MouseEnterEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkContextItem::MouseMoveEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkContextItem::MouseLeaveEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkContextItem::MouseButtonPressEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkContextItem::MouseButtonReleaseEvent(const vtkContextMouseEvent &)
{
return false;
}
//-----------------------------------------------------------------------------
bool vtkContextItem::MouseWheelEvent(const vtkContextMouseEvent &, int)
{
return false;
}
// ----------------------------------------------------------------------------
void vtkContextItem::ReleaseGraphicsResources()
{
}
//-----------------------------------------------------------------------------
void vtkContextItem::PrintSelf(ostream &os, vtkIndent indent)
{
......
......@@ -25,10 +25,7 @@
#include "vtkAbstractContextItem.h"
#include "vtkWeakPointer.h" // Needed for weak pointer references to the scene
class vtkContext2D;
class vtkContextScene;
class vtkTransform2D;
class vtkContextMouseEvent;
class VTK_CHARTS_EXPORT vtkContextItem : public vtkAbstractContextItem
{
......@@ -36,48 +33,6 @@ public:
vtkTypeMacro(vtkContextItem, vtkAbstractContextItem);
virtual void PrintSelf(ostream &os, vtkIndent indent);
//BTX
// Description:
// Return true if the supplied x, y coordinate is inside the item.
virtual bool Hit(const vtkContextMouseEvent &mouse);
// Description:
// Mouse enter event.
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseEnterEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse move event.
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseMoveEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse leave event.
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseLeaveEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse button down event
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse button release event.
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);
// Description:
// Mouse wheel event, positive delta indicates forward movement of the wheel.
// Return true if the item holds the event, false if the event can be
// propagated to other items.
virtual bool MouseWheelEvent(const vtkContextMouseEvent &mouse, int delta);
//ETX
// Description:
// Get the visibility of the item (should it be drawn).
vtkGetMacro(Visible, bool);
......@@ -102,11 +57,6 @@ public:
// Get the vtkContextScene for the item, always set for an item in a scene.
vtkContextScene* GetScene();
// Description:
// Release graphics resources hold by the item. The default implementation
// is empty.
virtual void ReleaseGraphicsResources();
//BTX
protected:
vtkContextItem();
......
......@@ -138,7 +138,7 @@ public:
}
}
vtkstd::vector<vtkContextItem *> items;
vtkstd::vector<vtkAbstractContextItem *> items;
vtkstd::vector<bool> itemState;
int itemMousePressCurrent; // Index of the item with a current mouse down
vtkContextMouseEvent Event; // Mouse event structure
......@@ -237,10 +237,14 @@ void vtkContextScene::PaintIds()
}
//-----------------------------------------------------------------------------
void vtkContextScene::AddItem(vtkContextItem *item)
void vtkContextScene::AddItem(vtkAbstractContextItem *item)
{
item->Register(this);
item->SetScene(this);
vtkContextItem *citem = vtkContextItem::SafeDownCast(item);
if (citem)
{
citem->SetScene(this);
}
this->Storage->items.push_back(item);
this->Storage->itemState.push_back(false);
}
......@@ -252,7 +256,7 @@ int vtkContextScene::GetNumberOfItems()
}
//-----------------------------------------------------------------------------
vtkContextItem * vtkContextScene::GetItem(int index)
vtkAbstractContextItem * vtkContextScene::GetItem(int index)
{
if (index < this->GetNumberOfItems())
{
......@@ -336,7 +340,7 @@ void vtkContextScene::ReleaseGraphicsResources()
{
this->BufferId->ReleaseGraphicsResources();
}
vtkstd::vector<vtkContextItem *>::iterator it;
vtkstd::vector<vtkAbstractContextItem *>::iterator it;
for (it = this->Storage->items.begin(); it != this->Storage->items.end(); ++it)
{
(*it)->ReleaseGraphicsResources();
......
......@@ -28,7 +28,7 @@
#include "vtkVector.h" // Needed for vtkVector2f
class vtkContext2D;
class vtkContextItem;
class vtkAbstractContextItem;
class vtkTransform2D;
class vtkContextMouseEvent;
......@@ -54,14 +54,14 @@ public:
// Description:
// Add an item to the scene.
void AddItem(vtkContextItem *item);
void AddItem(vtkAbstractContextItem *item);
// Description:
// Get the number of items in the scene.
int GetNumberOfItems();
// Get the item at the specified index.
vtkContextItem * GetItem(int index);
vtkAbstractContextItem * GetItem(int index);
// Description:
// Set the vtkAnnotationLink for the chart.
......@@ -122,7 +122,7 @@ public:
// Description:
// Release graphics resources hold by the scene.
void ReleaseGraphicsResources();
// Description:
// Last painter used.
// Not part of the end-user API. Can be used by context items to
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment