Skip to content
Snippets Groups Projects
Commit b58a68c3 authored by Mathieu Westphal (Kitware)'s avatar Mathieu Westphal (Kitware) :zap: Committed by Kitware Robot
Browse files

Merge topic 'WindowLocationInBorderRepresentation'


0b59a4e7 Put WindowLocation in BorderRepresentation

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarThomas Galland <thomas.galland@kitware.com>
Acked-by: default avatarTimothee Chabat <timothee.chabat@kitware.com>
Merge-request: !8674
parents 6d9ff100 0b59a4e7
No related branches found
No related tags found
No related merge requests found
# Move WindowLocation API in BorderRepresentation
The WindowLocation API has been moved from TextRepresentation
to BorderReprensentation so it can be used by any class inheriting
BorderRepresentation.
......@@ -813,6 +813,55 @@ void vtkBorderRepresentation::GetPolygonRGBA(double& r, double& g, double& b, do
a = this->GetPolygonOpacity();
}
//------------------------------------------------------------------------------
void vtkBorderRepresentation::UpdateWindowLocation()
{
if (this->WindowLocation != vtkBorderRepresentation::AnyLocation)
{
double* pos2 = this->Position2Coordinate->GetValue();
switch (this->WindowLocation)
{
case vtkBorderRepresentation::LowerLeftCorner:
this->SetPosition(0.01, 0.01);
break;
case vtkBorderRepresentation::LowerRightCorner:
this->SetPosition(0.99 - pos2[0], 0.01);
break;
case vtkBorderRepresentation::LowerCenter:
this->SetPosition((1 - pos2[0]) / 2.0, 0.01);
break;
case vtkBorderRepresentation::UpperLeftCorner:
this->SetPosition(0.01, 0.99 - pos2[1]);
break;
case vtkBorderRepresentation::UpperRightCorner:
this->SetPosition(0.99 - pos2[0], 0.99 - pos2[1]);
break;
case vtkBorderRepresentation::UpperCenter:
this->SetPosition((1 - pos2[0]) / 2.0, 0.99 - pos2[1]);
break;
default:
break;
}
}
}
//------------------------------------------------------------------------------
void vtkBorderRepresentation::SetWindowLocation(int enumLocation)
{
if (this->WindowLocation == enumLocation)
{
return;
}
this->WindowLocation = enumLocation;
if (this->WindowLocation != vtkBorderRepresentation::AnyLocation)
{
this->UpdateWindowLocation();
}
this->Modified();
}
//------------------------------------------------------------------------------
void vtkBorderRepresentation::PrintSelf(ostream& os, vtkIndent indent)
{
......@@ -889,4 +938,30 @@ void vtkBorderRepresentation::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "PolygonColor: (" << this->PolygonColor[0] << ", " << this->PolygonColor[1]
<< ", " << this->PolygonColor[2] << ")" << endl;
os << indent << "PolygonOpacity: " << this->PolygonOpacity << endl;
os << indent << "Window Location: ";
switch (this->WindowLocation)
{
case vtkBorderRepresentation::LowerLeftCorner:
os << "LowerLeftCorner\n";
break;
case vtkBorderRepresentation::LowerRightCorner:
os << "LowerRightCorner\n";
break;
case vtkBorderRepresentation::LowerCenter:
os << "LowerCenter\n";
break;
case vtkBorderRepresentation::UpperLeftCorner:
os << "UpperLeftCorner\n";
break;
case vtkBorderRepresentation::UpperRightCorner:
os << "UpperRightCorner\n";
break;
case vtkBorderRepresentation::UpperCenter:
os << "UpperCenter\n";
break;
case vtkBorderRepresentation::AnyLocation:
os << "Any Location\n";
break;
}
}
......@@ -225,6 +225,33 @@ public:
vtkBooleanMacro(Moving, vtkTypeBool);
///@}
enum
{
AnyLocation = 0,
LowerLeftCorner,
LowerRightCorner,
LowerCenter,
UpperLeftCorner,
UpperRightCorner,
UpperCenter
};
///@{
/**
* Set the representation position, by enumeration (
* AnyLocation = 0,
* LowerLeftCorner,
* LowerRightCorner,
* LowerCenter,
* UpperLeftCorner,
* UpperRightCorner,
* UpperCenter)
* related to the render window
*/
virtual void SetWindowLocation(int enumLocation);
vtkGetMacro(WindowLocation, int);
///@}
/**
* Define the various states that the representation can be in.
*/
......@@ -372,6 +399,10 @@ protected:
vtkNew<vtkCoordinate> PositionCoordinate;
vtkNew<vtkCoordinate> Position2Coordinate;
// Window location by enumeration
int WindowLocation = AnyLocation;
virtual void UpdateWindowLocation();
// Sometimes subclasses must negotiate with their superclasses
// to achieve the correct layout.
int Negotiated;
......
......@@ -307,6 +307,27 @@ void vtkBorderWidget::SelectRegion(double* vtkNotUsed(eventPos[2]))
this->InvokeEvent(vtkCommand::WidgetActivateEvent, nullptr);
}
//------------------------------------------------------------------------------
vtkTypeBool vtkBorderWidget::GetProcessEvents()
{
auto representation = this->GetRepresentation();
if (representation)
{
auto borderRepresentation = vtkBorderRepresentation::SafeDownCast(representation);
if (borderRepresentation)
{
bool isRelativeLocation =
borderRepresentation->GetWindowLocation() != vtkBorderRepresentation::AnyLocation;
if (isRelativeLocation)
{
return false;
}
}
}
return this->Superclass::GetProcessEvents();
}
//------------------------------------------------------------------------------
void vtkBorderWidget::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -140,6 +140,12 @@ public:
*/
void CreateDefaultRepresentation() override;
/**
* Reimplement ProcessEvents to disable it when using relative location with
* windowLocation. When using exact location this override has no effect.
*/
vtkTypeBool GetProcessEvents() override;
protected:
vtkBorderWidget();
~vtkBorderWidget() override;
......
......@@ -61,7 +61,6 @@ vtkTextRepresentation::vtkTextRepresentation()
this->SetShowBorder(vtkBorderRepresentation::BORDER_ACTIVE);
this->BWActorEdges->VisibilityOff();
this->WindowLocation = AnyLocation;
}
//------------------------------------------------------------------------------
......@@ -308,26 +307,13 @@ void vtkTextRepresentation::CheckTextBoundary()
this->Position2Coordinate->SetValue(posX, posY, 0);
this->Modified();
}
if (this->WindowLocation != AnyLocation)
if (this->WindowLocation != vtkBorderRepresentation::AnyLocation)
{
this->UpdateWindowLocation();
}
}
}
//------------------------------------------------------------------------------
void vtkTextRepresentation::SetWindowLocation(int enumLocation)
{
if (this->WindowLocation == enumLocation)
{
return;
}
this->WindowLocation = enumLocation;
this->CheckTextBoundary();
this->Modified();
}
//------------------------------------------------------------------------------
void vtkTextRepresentation::SetPosition(double x, double y)
{
......@@ -341,38 +327,6 @@ void vtkTextRepresentation::SetPosition(double x, double y)
this->Modified();
}
//------------------------------------------------------------------------------
void vtkTextRepresentation::UpdateWindowLocation()
{
if (this->WindowLocation != AnyLocation)
{
double* pos2 = this->Position2Coordinate->GetValue();
switch (this->WindowLocation)
{
case LowerLeftCorner:
this->SetPosition(0.01, 0.01);
break;
case LowerRightCorner:
this->SetPosition(0.99 - pos2[0], 0.01);
break;
case LowerCenter:
this->SetPosition((1 - pos2[0]) / 2.0, 0.01);
break;
case UpperLeftCorner:
this->SetPosition(0.01, 0.99 - pos2[1]);
break;
case UpperRightCorner:
this->SetPosition(0.99 - pos2[0], 0.99 - pos2[1]);
break;
case UpperCenter:
this->SetPosition((1 - pos2[0]) / 2.0, 0.99 - pos2[1]);
break;
default:
break;
}
}
}
//------------------------------------------------------------------------------
void vtkTextRepresentation::SetPadding(int padding)
{
......@@ -391,27 +345,4 @@ void vtkTextRepresentation::PrintSelf(ostream& os, vtkIndent indent)
this->Superclass::PrintSelf(os, indent);
os << indent << "Text Actor: " << this->TextActor << "\n";
os << indent << "Window Location: ";
switch (this->WindowLocation)
{
case LowerLeftCorner:
os << "LowerLeftCorner\n";
break;
case LowerRightCorner:
os << "LowerRightCorner\n";
break;
case LowerCenter:
os << "LowerCenter\n";
break;
case UpperLeftCorner:
os << "UpperLeftCorner\n";
break;
case UpperRightCorner:
os << "UpperRightCorner\n";
break;
case UpperCenter:
os << "UpperCenter\n";
break;
}
}
......@@ -91,33 +91,6 @@ public:
vtkTypeBool HasTranslucentPolygonalGeometry() override;
///@}
enum
{
AnyLocation = 0,
LowerLeftCorner,
LowerRightCorner,
LowerCenter,
UpperLeftCorner,
UpperRightCorner,
UpperCenter
};
///@{
/**
* Set the text position, by enumeration (
* AnyLocation = 0,
* LowerLeftCorner,
* LowerRightCorner,
* LowerCenter,
* UpperLeftCorner,
* UpperRightCorner,
* UpperCenter)
* related to the render window
*/
virtual void SetWindowLocation(int enumLocation);
vtkGetMacro(WindowLocation, int);
///@}
///@{
/**
* Set the text position, by overriding the same function of
......@@ -198,10 +171,6 @@ protected:
vtkTextActor* TextActor;
vtkTextProperty* TextProperty;
// Window location by enumeration
int WindowLocation;
virtual void UpdateWindowLocation();
// observer to observe internal TextActor and TextProperty
vtkTextRepresentationObserver* Observer;
......
......@@ -62,34 +62,6 @@ vtkTextActor* vtkTextWidget::GetTextActor()
}
}
/**
* This disables ProcessEvents when we are using relative location in
* our TextWidgets. When using exact location this override has no effect.
*
* We can achieve this since this method is an override of
* vtkAbstractWidget:GetProcessEvent() which determines if we can process
* events in this widget.
*/
vtkTypeBool vtkTextWidget::GetProcessEvents()
{
auto representation = this->GetRepresentation();
if (representation)
{
auto textRepresentation = vtkTextRepresentation::SafeDownCast(representation);
if (textRepresentation)
{
bool isRelativeLocation =
textRepresentation->GetWindowLocation() != vtkTextRepresentation::AnyLocation;
if (isRelativeLocation)
{
return false;
}
}
}
return this->Superclass::GetProcessEvents();
}
//------------------------------------------------------------------------------
void vtkTextWidget::CreateDefaultRepresentation()
{
......
......@@ -76,12 +76,6 @@ public:
*/
void CreateDefaultRepresentation() override;
/**
* This allows us to set interactivity in the widget
* since this method can block vtkAbstractWidget::ProcessEventsHandler
*/
vtkTypeBool GetProcessEvents() override;
protected:
vtkTextWidget();
~vtkTextWidget() override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment