Hello. I'm having some difficulties understanding lifecycles of hdi_core Tool class and hope you'll point me in the right direction.
For simplicity lets say I'm building a tool that makes a triangle from a base line and a point.
I've created a tool. I want it to draw a line when dragged and then create a triangle from a point where user made a click. So I make a drag callback
Line drawn while dragging doesnt stay on the artboard. I assume this is due to some undo calls under the hood. Everything drawn outside of this callback stays. What I want is to make a mouse up counter for this tool that gets incremented on mouse up callback. Lets say I have a mouse up callback like this
So far so good.
What I want is to get a behaviour similar to drag callback inside the track callback - user moves cursor, triangle draft gets drawn until a click is made. However I do not fully understand how to handle undo function in such a scenario. I imagine track function to look something like this
However I am not sure when should I call undo for current document to give my track callback behaviour similar to dragging(or if this is even a correct approach to this sort of scenarios).
For simplicity lets say I'm building a tool that makes a triangle from a base line and a point.
Code:
Tool = hdi::core::Tool(hdi::core::Tool(), NULL,"Tool","Tool",ID, ID);
Tool.setTrackCallback(HDI_CORE_CALLBACK(Toolset, this, TrackTool));
Tool.setDragCallback(HDI_CORE_CALLBACK(Toolset, this, DragTool));
Tool.setMouseUpCallback(HDI_CORE_CALLBACK(Toolset, this, MouseUpTool));
I've created a tool. I want it to draw a line when dragged and then create a triangle from a point where user made a click. So I make a drag callback
Code:
void Toolset::DragTool()
{
std::auto_ptr<hdi::core::HitData> startHit = Tool.mouseDownHitData(0, hdi::core::AnyHitRequestNoGuides);
if( !startHit.get() )
return;
std::auto_ptr<hdi::core::HitData> endHit = Tool.cursorHitData(hdi::core::AnyHitRequestNoGuides);
if( !endHit.get() )
return;
hdi::core::draw::line(startHit->point(), endHit->point());
}
Code:
void Toolset::MouseUpTool()
{
mouseUp++;
if(mouseUp == 1) //save points for base
if(mouseUp == 2)
{
//draw triangle
mouseUp = 0;
}
}
So far so good.
What I want is to get a behaviour similar to drag callback inside the track callback - user moves cursor, triangle draft gets drawn until a click is made. However I do not fully understand how to handle undo function in such a scenario. I imagine track function to look something like this
Code:
void Toolset::TrackTool()
{
if(mouseUp != 1) return;
//get current end hit, draw triangle based on saved base and this point
}