[vtkusers] vtkSliderWidget subclassing
minjun
mey1k at naver.com
Tue Jul 24 20:44:25 EDT 2018
hello,
i want to show mouse cursor(VTK_CURSOR_HAND) at hovering vtkSliderWidget
below shows what I want to do. // vtkButtonWidget.cxx
void vtkButtonWidget::MoveAction(vtkAbstractWidget *w)
{
vtkButtonWidget *self = reinterpret_cast<vtkButtonWidget*>(w);
int X = self->Interactor->GetEventPosition()[0];
int Y = self->Interactor->GetEventPosition()[1];
// Motion while selecting is ignored
if ( self->WidgetState == vtkButtonWidget::Selecting )
{
self->EventCallbackCommand->SetAbortFlag(1);
return;
}
// Get the new state and compare it to the old
int renderRequired = 0;
int state = self->WidgetRep->ComputeInteractionState(X, Y);
if ( self->WidgetState == vtkButtonWidget::Hovering )
{
if ( state == vtkButtonRepresentation::Outside )
{
renderRequired = 1;
if ( self->ManagesCursor )
{
self->RequestCursorShape(VTK_CURSOR_DEFAULT);
}
self->WidgetRep->Highlight(vtkButtonRepresentation::HighlightNormal);
self->WidgetState = vtkButtonWidget::Start;
}
}
else //state is Start
{
if ( state == vtkButtonRepresentation::Inside )
{
renderRequired = 1;
if ( self->ManagesCursor )
{
self->RequestCursorShape(VTK_CURSOR_HAND);
}
self->WidgetRep->Highlight(vtkButtonRepresentation::HighlightHovering);
self->WidgetState = vtkButtonWidget::Hovering;
self->EventCallbackCommand->SetAbortFlag(1);
}
}
if ( renderRequired )
{
self->Render();
}
}
I got an idea here,
I want to show the mouse cursor by modifying below code(vtkSliderWidet.cxx)
void vtkSliderWidget::MoveAction(vtkAbstractWidget *w)
{
vtkSliderWidget *self = reinterpret_cast<vtkSliderWidget*>(w);
// See whether we're active
if ( self->WidgetState == vtkSliderWidget::Start ||
self->WidgetState == vtkSliderWidget::Animating )
{
return;
}
// Definitely moving the slider, get the updated position
double eventPos[2];
eventPos[0] = self->Interactor->GetEventPosition()[0];
eventPos[1] = self->Interactor->GetEventPosition()[1];
self->WidgetRep->WidgetInteraction(eventPos);
// Interact, if desired
self->EventCallbackCommand->SetAbortFlag(1);
self->InvokeEvent(vtkCommand::InteractionEvent,NULL);
self->Render();
}
To use modified code, I think I should use subclassing.
But after modifying the code, I don't know how to apply it.
//vtkSliderWidget.cxx
vtkSliderWidget::vtkSliderWidget()
{
// Set the initial state
this->WidgetState = vtkSliderWidget::Start;
// Assign initial values
this->AnimationMode = vtkSliderWidget::Jump;
this->NumberOfAnimationSteps = 24;
// Okay, define the events
this->CallbackMapper->SetCallbackMethod(vtkCommand::LeftButtonPressEvent,
vtkWidgetEvent::Select,
this,
vtkSliderWidget::SelectAction);
this->CallbackMapper->SetCallbackMethod(vtkCommand::MouseMoveEvent,
vtkWidgetEvent::Move,
this,
vtkSliderWidget::MoveAction);
this->CallbackMapper->SetCallbackMethod(vtkCommand::LeftButtonReleaseEvent,
vtkWidgetEvent::EndSelect,
this,
vtkSliderWidget::EndSelectAction);
}
i'm now use callback event as below
vtkSmartPointer<vtkSliderCallback> callback =
vtkSmartPointer<vtkSliderCallback>::New();
AddObserver(vtkCommand::InteractionEvent, callback);
But I want to know how to call the modified moveAction event.
If you have an idea about this issue, I would like help.
Thanks for reading. :)
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list