1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBlockItem.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkBlockItem
* @brief a vtkContextItem that draws a block (optional label).
*
* This is a vtkContextItem that can be placed into a vtkContextScene. It draws
* a block of the given dimensions, and reacts to mouse events.
*
* vtkBlockItem can also be used to render label in the scene. The label
* properties can be set using `vtkTextProperty` accessed via
* `GetLabelProperties`.
*
*/
#ifndef vtkBlockItem_h
#define vtkBlockItem_h
#include "vtkContextItem.h"
#include "vtkNew.h" // For vtkNew
#include "vtkRenderingContext2DModule.h" // For export macro
#include "vtkStdString.h" // For vtkStdString ivars
VTK_ABI_NAMESPACE_BEGIN
class vtkContext2D;
class vtkTextProperty;
class vtkBrush;
class vtkPen;
class VTKRENDERINGCONTEXT2D_EXPORT vtkBlockItem : public vtkContextItem
{
public:
vtkTypeMacro(vtkBlockItem, vtkContextItem);
void PrintSelf(ostream& os, vtkIndent indent) override;
static vtkBlockItem* New();
/**
* Paint event for the item.
*/
bool Paint(vtkContext2D* painter) override;
/**
* Returns true if the supplied x, y coordinate is inside the item.
*/
bool Hit(const vtkContextMouseEvent& mouse) override;
/**
* Mouse enter event.
*/
bool MouseEnterEvent(const vtkContextMouseEvent& mouse) override;
/**
* Mouse move event.
*/
bool MouseMoveEvent(const vtkContextMouseEvent& mouse) override;
/**
* Mouse leave event.
*/
bool MouseLeaveEvent(const vtkContextMouseEvent& mouse) override;
/**
* Mouse button down event.
*/
bool MouseButtonPressEvent(const vtkContextMouseEvent& mouse) override;
/**
* Mouse button release event.
*/
bool MouseButtonReleaseEvent(const vtkContextMouseEvent& mouse) override;
/**
* Set the block label.
*/
virtual void SetLabel(const vtkStdString& label);
/**
* Get the block label.
*/
virtual vtkStdString GetLabel();
///@{
/**
* Set the dimensions of the block, elements 0 and 1 are the x and y
* coordinate of the bottom corner. Elements 2 and 3 are the width and
* height.
* Initial value is (0,0,0,0).
*/
vtkSetVector4Macro(Dimensions, float);
///@}
///@{
/**
* Get the dimensions of the block, elements 0 and 1 are the x and y
* coordinate of the bottom corner. Elements 2 and 3 are the width and
* height.
* Initial value is (0,0,0,0)
*/
vtkGetVector4Macro(Dimensions, float);
///@}
///@{
/**
* When set to true, the dimensions for the block are computed automatically
* using the anchor point, alignment at the size of the label.
* Otherwise the `Dimensions` are used.
*
* Default is false i.e `Dimensions` will be used.
*/
vtkSetMacro(AutoComputeDimensions, bool);
vtkGetMacro(AutoComputeDimensions, bool);
vtkBooleanMacro(AutoComputeDimensions, bool);
///@}
enum
{
LEFT = 0,
CENTER,
RIGHT,
TOP,
BOTTOM,
CUSTOM
};
///@{
/**
* Set/Get the horizontal alignment of the legend to the point specified.
* Valid values are LEFT, CENTER and RIGHT.
*/
vtkSetMacro(HorizontalAlignment, int);
vtkGetMacro(HorizontalAlignment, int);
///@}
///@{
/**
* Set/Get the vertical alignment of the legend to the point specified.
* Valid values are TOP, CENTER and BOTTOM.
*/
vtkSetMacro(VerticalAlignment, int);
vtkGetMacro(VerticalAlignment, int);
///@}
///@{
/**
* When AutoComputeDimensions is true, these are the padding for the label
* within the block.
*
* Default is (5, 5).
*/
vtkSetVector2Macro(Padding, int);
vtkGetVector2Macro(Padding, int);
///@}
///@{
/**
* When AutoComputeDimensions is true, these are the margins from the edge of
* the viewport to use when placing the block based on HorizontalAlignment and
* VerticalAlignment preferences.
*/
vtkSetVector2Macro(Margins, int);
vtkGetVector2Macro(Margins, int);
///@}
///@{
/**
* Get pen used to draw the block item outline.
*/
vtkGetObjectMacro(Pen, vtkPen);
///@}
///@{
/**
* Get the brush used to draw the block item background.
*/
vtkGetObjectMacro(Brush, vtkBrush);
///@}
///@{
/**
* Get the brush used to draw the block item background when the
* item is "hit" i.e. interaction is enabled and the mouse is over the block.
*/
vtkGetObjectMacro(MouseOverBrush, vtkBrush);
///@}
///@{
/**
* Provides access to the vtkTextProperty object that controls the way the
* label is rendered.
*/
void SetLabelProperties(vtkTextProperty*);
vtkGetObjectMacro(LabelProperties, vtkTextProperty);
///@}
void SetScalarFunctor(double (*scalarFunction)(double, double));
protected:
vtkBlockItem();
~vtkBlockItem() override;
float Dimensions[4];
vtkStdString Label;
bool MouseOver;
// Some function pointers to optionally do funky things...
double (*scalarFunction)(double, double);
private:
vtkBlockItem(const vtkBlockItem&) = delete;
void operator=(const vtkBlockItem&) = delete;
vtkTextProperty* LabelProperties;
vtkNew<vtkTextProperty> CachedTextProp;
vtkNew<vtkPen> Pen;
vtkNew<vtkPen> CachedPen;
vtkNew<vtkBrush> Brush;
vtkNew<vtkBrush> MouseOverBrush;
vtkNew<vtkBrush> CachedBrush;
int HorizontalAlignment;
int VerticalAlignment;
bool AutoComputeDimensions;
int Padding[2];
int Margins[2];
};
VTK_ABI_NAMESPACE_END
#endif // vtkBlockItem_h
|