|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/tool.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/cursors.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tframehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevelhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tscenehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/selectioncommandids.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/selection.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tproperty.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tdata.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tgl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tstroke.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimage.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/hook.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/toonzscene.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheet.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshcell.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshcolumn.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tstageobjecttree.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshsimplelevel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/levelproperties.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheethandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tw/keycodes.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <qmessagebox></qmessagebox>
|
|
Toshihiro Shimizu |
890ddd |
#include <math.h></math.h>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// For Qt translation support
|
|
Toshihiro Shimizu |
890ddd |
#include <qcoreapplication></qcoreapplication>
|
|
shun_iwasawa |
d51821 |
#include <qkeyevent></qkeyevent>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace ToolUtils;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class TrackerTool;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// TrackerRegionSelection
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// Ancora da definire.
|
|
Toshihiro Shimizu |
890ddd |
// under construction
|
|
Shinya Kitaoka |
d1f6c4 |
class TrackerRegionSelection final : public TSelection {
|
|
Shinya Kitaoka |
120a6e |
TXshLevelP m_level;
|
|
Shinya Kitaoka |
120a6e |
std::set<std::pair<int, int="">></std::pair<int,>
|
|
Shinya Kitaoka |
120a6e |
m_objtp; // objtp: 1=ObjectId 2=Tracker Region Index
|
|
Shinya Kitaoka |
120a6e |
TrackerTool *m_tool;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TrackerRegionSelection() : m_tool(0) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setTool(TrackerTool *tool) { m_tool = tool; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TSelection *clone() const { return new TrackerRegionSelection(*this); }
|
|
Shinya Kitaoka |
120a6e |
void setLevel(const TXshLevelP &level) { m_level = level; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void select(int objectId, int trackerRegionIndex) {
|
|
Shinya Kitaoka |
120a6e |
m_objtp.insert(std::make_pair(objectId, trackerRegionIndex));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
void deselect(int objectId, int trackerRegionIndex) {
|
|
Shinya Kitaoka |
120a6e |
m_objtp.erase(std::make_pair(objectId, trackerRegionIndex));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool isSelected(int objectId, int trackerRegionIndex) const {
|
|
Shinya Kitaoka |
120a6e |
return m_objtp.count(std::make_pair(objectId, trackerRegionIndex)) > 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
void invertSelection(int objectId, int trackerRegionIndex) {
|
|
Shinya Kitaoka |
120a6e |
if (isSelected(objectId, trackerRegionIndex))
|
|
Shinya Kitaoka |
120a6e |
deselect(objectId, trackerRegionIndex);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
select(objectId, trackerRegionIndex);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
bool isEmpty() const override { return m_objtp.empty(); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void selectNone() override { m_objtp.clear(); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
HookSet *getHookSet() const {
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();
|
|
Shinya Kitaoka |
120a6e |
// TXshLevel *xl = m_level.getPointer();
|
|
Shinya Kitaoka |
120a6e |
if (!xl) return 0;
|
|
Shinya Kitaoka |
120a6e |
return xl->getHookSet();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TDataP getData() { return TDataP(); }
|
|
Shinya Kitaoka |
120a6e |
TDataP cutData() { return TDataP(); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TDataP clearData() {
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
//HookData *data = new HookData();
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = getHookSet();
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = TTool::getApplication()->getCurrentFrame()->getFid();
|
|
Shinya Kitaoka |
120a6e |
if(!hookSet) return TDataP();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for(int i=0;i<hookset->getHookCount();i++)</hookset->
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
Hook *hook = hookSet->getHook(i);
|
|
Shinya Kitaoka |
120a6e |
if(!hook || hook->isEmpty()) continue;
|
|
Shinya Kitaoka |
120a6e |
if(isSelected(i,1) && isSelected(i,2))
|
|
Shinya Kitaoka |
120a6e |
hookSet->clearHook(hook);
|
|
Shinya Kitaoka |
120a6e |
else if(isSelected(i,2))
|
|
Shinya Kitaoka |
120a6e |
hook->setBPos(fid, hook->getAPos(fid));
|
|
Shinya Kitaoka |
120a6e |
else if(isSelected(i,1))
|
|
Shinya Kitaoka |
120a6e |
hook->setAPos(fid, hook->getBPos(fid));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
return TDataP(); */
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TDataP pasteData(const TDataP &data) { return TDataP(); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void resetData(const TDataP &data, bool insert) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool select(const TSelection *s) {
|
|
Shinya Kitaoka |
120a6e |
if (const TrackerRegionSelection *hs =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<const *="" trackerregionselection="">(s)) {</const>
|
|
Shinya Kitaoka |
120a6e |
m_level = hs->m_level;
|
|
Shinya Kitaoka |
120a6e |
m_objtp = hs->m_objtp;
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void enableCommands() override;
|
|
Shinya Kitaoka |
120a6e |
void convertToRegion();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// TrackerTool class declaration
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class TrackerTool final : public TTool {
|
|
Shinya Kitaoka |
120a6e |
Q_DECLARE_TR_FUNCTIONS(TrackerTool)
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TrackerRegionSelection m_selection;
|
|
Shinya Kitaoka |
120a6e |
TPointD m_firstPos, m_lastPos;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int m_hookSelectedIndex;
|
|
Shinya Kitaoka |
120a6e |
int m_lastHookSelectedIndex;
|
|
Shinya Kitaoka |
120a6e |
bool m_deselectArmed;
|
|
Shinya Kitaoka |
120a6e |
bool m_newObjectAdded; // serve al buttonUp per sapere se l'ultima tracker
|
|
Shinya Kitaoka |
120a6e |
// region
|
|
Shinya Kitaoka |
120a6e |
// aggiunta รจ un oggetto nuovo oppure no
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPropertyGroup m_prop;
|
|
Shinya Kitaoka |
120a6e |
TDoubleProperty m_toolSizeWidth;
|
|
Shinya Kitaoka |
120a6e |
TDoubleProperty m_toolSizeHeight;
|
|
Shinya Kitaoka |
120a6e |
TIntProperty m_toolPosX;
|
|
Shinya Kitaoka |
120a6e |
TIntProperty m_toolPosY;
|
|
Shinya Kitaoka |
120a6e |
TRectD m_shapeBBox;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool m_buttonDown;
|
|
Shinya Kitaoka |
120a6e |
bool m_dragged;
|
|
Shinya Kitaoka |
120a6e |
bool m_picked;
|
|
Shinya Kitaoka |
120a6e |
TPointD m_pos; // posizione del mouse
|
|
Shinya Kitaoka |
120a6e |
TPointD m_oldPos;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int m_what;
|
|
Shinya Kitaoka |
120a6e |
enum {
|
|
Shinya Kitaoka |
120a6e |
Outside,
|
|
Shinya Kitaoka |
120a6e |
Inside,
|
|
Shinya Kitaoka |
120a6e |
P00,
|
|
Shinya Kitaoka |
120a6e |
P01,
|
|
Shinya Kitaoka |
120a6e |
P10,
|
|
Shinya Kitaoka |
120a6e |
P11,
|
|
Shinya Kitaoka |
120a6e |
P1M,
|
|
Shinya Kitaoka |
120a6e |
PM1,
|
|
Shinya Kitaoka |
120a6e |
P0M,
|
|
Shinya Kitaoka |
120a6e |
PM0,
|
|
Shinya Kitaoka |
120a6e |
ADD_OBJECT,
|
|
Shinya Kitaoka |
120a6e |
NormalHook
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
TrackerTool();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
ToolType getToolType() const override { return TTool::LevelReadTool; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
void updateTranslation() override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TrackerObjectsSet *getTrackerObjectsSet() const;
|
|
Shinya Kitaoka |
120a6e |
HookSet *getHookSet() const;
|
|
Shinya Kitaoka |
473e70 |
void draw() override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void deleteSelectedTrackerRegion();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
void leftButtonDown(const TPointD &pos, const TMouseEvent &e) override;
|
|
Shinya Kitaoka |
473e70 |
void leftButtonDrag(const TPointD &pos, const TMouseEvent &e) override;
|
|
Shinya Kitaoka |
473e70 |
void leftButtonUp(const TPointD &pos, const TMouseEvent &) override;
|
|
Shinya Kitaoka |
473e70 |
void mouseMove(const TPointD &pos, const TMouseEvent &e) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
bool keyDown(int key, TUINT32 flags, const TPoint &pos) override;
|
|
Shinya Kitaoka |
120a6e |
// bool moveCursor(const TPointD &pos){}
|
|
Shinya Kitaoka |
473e70 |
void onEnter() override;
|
|
Shinya Kitaoka |
473e70 |
void onLeave() override;
|
|
Shinya Kitaoka |
473e70 |
void onActivate() override;
|
|
Shinya Kitaoka |
473e70 |
void onDeactivate() override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
void onImageChanged() override {}
|
|
Shinya Kitaoka |
473e70 |
void reset() override;
|
|
Shinya Kitaoka |
473e70 |
TPropertyGroup *getProperties(int targetType) override { return &m_prop; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void onSelectionChanged() { invalidate(); }
|
|
Shinya Kitaoka |
473e70 |
bool onPropertyChanged(std::string propertyName) override;
|
|
Shinya Kitaoka |
120a6e |
bool select(const TSelection *) { return false; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool pick(int &hookIndex, const TPointD &pos);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
int getCursorId() const override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
d51821 |
// returns true if the pressed key is recognized and processed.
|
|
shun_iwasawa |
d51821 |
bool isEventAcceptable(QEvent *e) override;
|
|
shun_iwasawa |
d51821 |
|
|
Toshihiro Shimizu |
890ddd |
} trackerTool;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// TrackerTool implementation
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TrackerTool::TrackerTool()
|
|
Shinya Kitaoka |
120a6e |
: TTool("T_Tracker")
|
|
Shinya Kitaoka |
120a6e |
, m_hookSelectedIndex(-1)
|
|
Shinya Kitaoka |
120a6e |
, m_lastHookSelectedIndex(-1)
|
|
Shinya Kitaoka |
120a6e |
, m_deselectArmed(false)
|
|
Shinya Kitaoka |
120a6e |
, m_toolSizeWidth("Width:", 0, 1000, 10) // W_ToolOptions
|
|
Shinya Kitaoka |
120a6e |
, m_toolSizeHeight("Height:", 0, 1000, 10) // W_ToolOptions
|
|
Shinya Kitaoka |
120a6e |
, m_toolPosX("X:", -9000, 9000, 10) // W_ToolOptions
|
|
Shinya Kitaoka |
120a6e |
, m_toolPosY("Y:", -9000, 9000, 10) // W_ToolOptions
|
|
Shinya Kitaoka |
120a6e |
, m_shapeBBox()
|
|
Shinya Kitaoka |
120a6e |
, m_buttonDown(false)
|
|
Shinya Kitaoka |
120a6e |
, m_dragged(false)
|
|
Shinya Kitaoka |
120a6e |
, m_oldPos(TPointD(0, 0))
|
|
Shinya Kitaoka |
120a6e |
, m_newObjectAdded(false) {
|
|
Shinya Kitaoka |
120a6e |
bind(TTool::CommonLevels);
|
|
Shinya Kitaoka |
120a6e |
m_prop.bind(m_toolSizeWidth);
|
|
Shinya Kitaoka |
120a6e |
m_prop.bind(m_toolSizeHeight);
|
|
Shinya Kitaoka |
120a6e |
m_prop.bind(m_toolPosX);
|
|
Shinya Kitaoka |
120a6e |
m_prop.bind(m_toolPosY);
|
|
Shinya Kitaoka |
120a6e |
m_selection.setTool(this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::updateTranslation() {
|
|
Shinya Kitaoka |
120a6e |
m_toolSizeWidth.setQStringName(tr("Width:"));
|
|
Shinya Kitaoka |
120a6e |
m_toolSizeHeight.setQStringName(tr("Height:"));
|
|
Shinya Kitaoka |
120a6e |
m_toolPosX.setQStringName(tr("X:"));
|
|
Shinya Kitaoka |
120a6e |
m_toolPosY.setQStringName(tr("Y:"));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TrackerObjectsSet *TrackerTool::getTrackerObjectsSet() const {
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = getHookSet();
|
|
Shinya Kitaoka |
120a6e |
if (!hookSet) return 0;
|
|
Shinya Kitaoka |
120a6e |
return hookSet->getTrackerObjectsSet();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
HookSet *TrackerTool::getHookSet() const {
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();
|
|
Shinya Kitaoka |
120a6e |
if (!xl) return 0;
|
|
Shinya Kitaoka |
120a6e |
return xl->getHookSet();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::draw() {
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = getHookSet();
|
|
Shinya Kitaoka |
120a6e |
if (!hookSet) return;
|
|
Shinya Kitaoka |
120a6e |
if (hookSet->getHookCount() <= m_hookSelectedIndex) m_hookSelectedIndex = -1;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = getCurrentFid();
|
|
Shinya Kitaoka |
120a6e |
int selectedObjectId;
|
|
Shinya Kitaoka |
120a6e |
if (m_hookSelectedIndex >= 0 && hookSet->getHook(m_hookSelectedIndex))
|
|
Shinya Kitaoka |
120a6e |
selectedObjectId =
|
|
Shinya Kitaoka |
120a6e |
hookSet->getHook(m_hookSelectedIndex)->getTrackerObjectId();
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
selectedObjectId = -1;
|
|
Shinya Kitaoka |
120a6e |
int i = 0;
|
|
Shinya Kitaoka |
120a6e |
double pixelSize = getPixelSize();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::vector<trectd> balloons; // this is used to avoid balloons overlapping</trectd>
|
|
Shinya Kitaoka |
120a6e |
// draw hooks
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < hookSet->getHookCount(); i++) {
|
|
Shinya Kitaoka |
120a6e |
Hook *hook = hookSet->getHook(i);
|
|
Shinya Kitaoka |
120a6e |
if (!hook || hook->isEmpty()) continue;
|
|
Shinya Kitaoka |
120a6e |
assert(hook);
|
|
Shinya Kitaoka |
120a6e |
// Se l'Hook ha una TrackerRegion allora la disegno
|
|
Shinya Kitaoka |
120a6e |
if (hook->getTrackerObjectId() >= 0) {
|
|
Shinya Kitaoka |
120a6e |
TRectD rect;
|
|
Shinya Kitaoka |
120a6e |
rect = hook->getTrackerRegion(fid);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 textColor(127, 127, 127);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 trackerObjectColor(0, 0, 0);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (hook->getTrackerObjectId() == selectedObjectId) {
|
|
Shinya Kitaoka |
120a6e |
if (m_hookSelectedIndex == i) {
|
|
Shinya Kitaoka |
120a6e |
TPixel32 frameColor(127, 127, 127);
|
|
Shinya Kitaoka |
120a6e |
drawSquare(0.5 * (rect.getP01() + rect.getP11()), pixelSize * 4,
|
|
Shinya Kitaoka |
120a6e |
frameColor); // scalaY
|
|
Shinya Kitaoka |
120a6e |
drawSquare(0.5 * (rect.getP11() + rect.getP10()), pixelSize * 4,
|
|
Shinya Kitaoka |
120a6e |
frameColor); // scalaX
|
|
Shinya Kitaoka |
120a6e |
drawSquare(rect.getP00(), pixelSize * 4, frameColor); // scala
|
|
Shinya Kitaoka |
120a6e |
drawSquare(rect.getP10(), pixelSize * 4, frameColor); // ridimensiona
|
|
Shinya Kitaoka |
120a6e |
trackerObjectColor = TPixel32(183, 227, 0);
|
|
Shinya Kitaoka |
120a6e |
textColor = TPixel32(155, 213, 219);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
textColor = TPixel32(183, 227, 0);
|
|
Shinya Kitaoka |
120a6e |
trackerObjectColor = TPixel32(155, 213, 219);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
trackerObjectColor = TPixel32(0, 0, 0);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
tglColor(trackerObjectColor);
|
|
Shinya Kitaoka |
120a6e |
tglDrawRect(rect);
|
|
Shinya Kitaoka |
120a6e |
tglColor(textColor);
|
|
Shinya Kitaoka |
120a6e |
glPushMatrix();
|
|
Shinya Kitaoka |
120a6e |
glTranslated(hook->getPos(fid).x, hook->getPos(fid).y, 0);
|
|
Shinya Kitaoka |
120a6e |
glScaled(pixelSize, pixelSize, 1);
|
|
Shinya Kitaoka |
120a6e |
int objectId = hook->getTrackerObjectId();
|
|
Shinya Kitaoka |
120a6e |
char *objectChar = (char *)malloc(2);
|
|
Shinya Kitaoka |
120a6e |
objectChar[0] = (char)(objectId + 65);
|
|
Shinya Kitaoka |
120a6e |
objectChar[1] = '\0';
|
|
Shinya Kitaoka |
120a6e |
std::string text(objectChar);
|
|
Shinya Kitaoka |
120a6e |
tglDrawText(TPointD(-15, 10), text);
|
|
Shinya Kitaoka |
120a6e |
glPopMatrix();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPointD p0 = hook->getAPos(fid);
|
|
Shinya Kitaoka |
120a6e |
TPointD p1 = hook->getBPos(fid);
|
|
Shinya Kitaoka |
120a6e |
bool linked = p0 == p1;
|
|
Shinya Kitaoka |
120a6e |
drawHook(p0, linked ? ToolUtils::NormalHook : ToolUtils::PassHookA,
|
|
Shinya Kitaoka |
120a6e |
m_hookSelectedIndex == i);
|
|
Shinya Kitaoka |
120a6e |
std::string hookName = std::to_string(i + 1);
|
|
Shinya Kitaoka |
120a6e |
TPixel32 balloonColor(200, 220, 205, 200);
|
|
Shinya Kitaoka |
120a6e |
TPoint balloonOffset(20, 20);
|
|
Shinya Kitaoka |
120a6e |
drawBalloon(p0, hookName, balloonColor, balloonOffset, false, &balloons);
|
|
Shinya Kitaoka |
120a6e |
if (!linked) {
|
|
Shinya Kitaoka |
120a6e |
drawHook(p1, PassHookB, m_selection.isSelected(i, 2));
|
|
Shinya Kitaoka |
120a6e |
drawBalloon(p1, hookName, balloonColor, balloonOffset, false, &balloons);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TrackerTool::pick(int &hookIndex, const TPointD &pos) {
|
|
Shinya Kitaoka |
120a6e |
double minDistance = -1;
|
|
Shinya Kitaoka |
120a6e |
m_what = Outside;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = getHookSet();
|
|
Shinya Kitaoka |
120a6e |
if (!hookSet) return false;
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = getCurrentFid();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double pixelSize = getPixelSize();
|
|
Shinya Kitaoka |
120a6e |
int i = 0;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)hookSet->getHookCount(); i++) {
|
|
Shinya Kitaoka |
120a6e |
Hook *hook = hookSet->getHook(i);
|
|
Shinya Kitaoka |
120a6e |
if (!hook || hook->isEmpty()) continue;
|
|
Shinya Kitaoka |
120a6e |
int trackerObjectId = hook->getTrackerObjectId();
|
|
Shinya Kitaoka |
120a6e |
if (trackerObjectId < 0) // se non รจ una trackeRregion
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
TPointD hookPos = hook->getPos(fid);
|
|
Shinya Kitaoka |
120a6e |
TRectD overArea =
|
|
Shinya Kitaoka |
120a6e |
TRectD(hookPos.x - 20 * pixelSize, hookPos.y - 20 * pixelSize,
|
|
Shinya Kitaoka |
120a6e |
hookPos.x + 20 * pixelSize, hookPos.y + 20 * pixelSize);
|
|
Shinya Kitaoka |
120a6e |
if (overArea.contains(pos)) {
|
|
Shinya Kitaoka |
120a6e |
hookIndex = i; // setto l'indice dell'hook
|
|
Shinya Kitaoka |
120a6e |
m_what = NormalHook;
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
TrackerObjectsSet *trackerObjectsSet = getTrackerObjectsSet();
|
|
Shinya Kitaoka |
120a6e |
if(!trackerObjectsSet) return false;
|
|
Shinya Kitaoka |
120a6e |
TrackerObject *trackerObject = trackerObjectsSet->getObjectFromIndex(i);
|
|
Shinya Kitaoka |
120a6e |
int j=0;
|
|
Shinya Kitaoka |
120a6e |
for(j=0;j<(int)trackerObject->getHooksCount();j++)
|
|
Shinya Kitaoka |
120a6e |
{*/
|
|
Shinya Kitaoka |
120a6e |
TPointD centerPos = hook->getPos(fid);
|
|
Shinya Kitaoka |
120a6e |
double width = hook->getTrackerRegionWidth();
|
|
Shinya Kitaoka |
120a6e |
double height = hook->getTrackerRegionHeight();
|
|
Shinya Kitaoka |
120a6e |
double distance = tdistance2(centerPos, pos);
|
|
Shinya Kitaoka |
120a6e |
TPointD localPos = pos - centerPos;
|
|
Shinya Kitaoka |
120a6e |
TRectD rect = hook->getTrackerRegion(fid);
|
|
Shinya Kitaoka |
120a6e |
TRectD overArea = TRectD(
|
|
Shinya Kitaoka |
120a6e |
rect.getP00().x - 4 * pixelSize, rect.getP00().y - 4 * pixelSize,
|
|
Shinya Kitaoka |
120a6e |
rect.getP11().x + 4 * pixelSize, rect.getP11().y + 4 * pixelSize);
|
|
Shinya Kitaoka |
120a6e |
// se pos รจ all'interno del'area sensibile del rettangolo
|
|
Shinya Kitaoka |
120a6e |
if (overArea.contains(pos)) {
|
|
Shinya Kitaoka |
120a6e |
if (distance < minDistance || minDistance == -1) {
|
|
Shinya Kitaoka |
120a6e |
minDistance = distance;
|
|
Shinya Kitaoka |
120a6e |
hookIndex = i;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_what = Inside;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// scale Y Area
|
|
Shinya Kitaoka |
120a6e |
double x =
|
|
Shinya Kitaoka |
120a6e |
0.5 * (rect.getP01().x + rect.getP11().x); // ascissa punto medio
|
|
Shinya Kitaoka |
120a6e |
TPointD my = TPointD(x, rect.getP11().y);
|
|
Shinya Kitaoka |
120a6e |
TRectD scaleYArea =
|
|
Shinya Kitaoka |
120a6e |
TRectD(my.x - 4 * pixelSize, my.y - 4 * pixelSize,
|
|
Shinya Kitaoka |
120a6e |
my.x + 4 * pixelSize, my.y + 4 * pixelSize);
|
|
Shinya Kitaoka |
120a6e |
if (scaleYArea.contains(pos)) m_what = PM1;
|
|
Shinya Kitaoka |
120a6e |
// scale X Area
|
|
Shinya Kitaoka |
120a6e |
double y = 0.5 * (rect.getP11().y +
|
|
Shinya Kitaoka |
120a6e |
rect.getP10().y); // ordinata punto medio
|
|
Shinya Kitaoka |
120a6e |
TPointD mx = TPointD(rect.getP10().x, y);
|
|
Shinya Kitaoka |
120a6e |
TRectD scaleXArea =
|
|
Shinya Kitaoka |
120a6e |
TRectD(mx.x - 4 * pixelSize, mx.y - 4 * pixelSize,
|
|
Shinya Kitaoka |
120a6e |
mx.x + 4 * pixelSize, mx.y + 4 * pixelSize);
|
|
Shinya Kitaoka |
120a6e |
if (scaleXArea.contains(pos)) m_what = P1M;
|
|
Shinya Kitaoka |
120a6e |
// resize area (scale X and Y)
|
|
Shinya Kitaoka |
120a6e |
TRectD resizeArea = TRectD(
|
|
Shinya Kitaoka |
120a6e |
rect.getP10().x - 4 * pixelSize, rect.getP10().y - 4 * pixelSize,
|
|
Shinya Kitaoka |
120a6e |
rect.getP10().x + 4 * pixelSize, rect.getP10().y + 4 * pixelSize);
|
|
Shinya Kitaoka |
120a6e |
if (resizeArea.contains(pos)) m_what = P10;
|
|
Shinya Kitaoka |
120a6e |
// scale area
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRectD scaleArea = TRectD(
|
|
Shinya Kitaoka |
120a6e |
rect.getP00().x - 4 * pixelSize, rect.getP00().y - 4 * pixelSize,
|
|
Shinya Kitaoka |
120a6e |
rect.getP00().x + 4 * pixelSize, rect.getP00().y + 4 * pixelSize);
|
|
Shinya Kitaoka |
120a6e |
if (scaleArea.contains(pos)) m_what = P00;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
//}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return (minDistance != -1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_buttonDown = true;
|
|
Shinya Kitaoka |
120a6e |
m_picked = true;
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();
|
|
Shinya Kitaoka |
120a6e |
if (!xl) return;
|
|
Shinya Kitaoka |
120a6e |
m_selection.setLevel(xl);
|
|
Shinya Kitaoka |
120a6e |
m_firstPos = m_lastPos = pos;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_deselectArmed = false;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_oldPos = pos;
|
|
Shinya Kitaoka |
120a6e |
double pixelSize = getPixelSize();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = xl->getHookSet();
|
|
Shinya Kitaoka |
120a6e |
if (!hookSet) return;
|
|
Shinya Kitaoka |
120a6e |
TrackerObjectsSet *trackerObjectsSet = getTrackerObjectsSet();
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = getCurrentFid();
|
|
Shinya Kitaoka |
120a6e |
if (!trackerObjectsSet) return;
|
|
Shinya Kitaoka |
120a6e |
if (pick(m_hookSelectedIndex, pos)) {
|
|
Shinya Kitaoka |
120a6e |
if (m_what == NormalHook) {
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
Hook *hook = hookSet->getHook(m_hookSelectedIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!hook) return;
|
|
Shinya Kitaoka |
120a6e |
m_selection.selectNone();
|
|
Shinya Kitaoka |
120a6e |
m_selection.select(m_hookSelectedIndex, m_hookSelectedIndex);
|
|
Shinya Kitaoka |
120a6e |
m_toolSizeWidth.setValue(hook->getTrackerRegionWidth());
|
|
Shinya Kitaoka |
120a6e |
m_toolSizeHeight.setValue(hook->getTrackerRegionHeight());
|
|
Shinya Kitaoka |
120a6e |
m_toolPosX.setValue(hook->getPos(fid).x);
|
|
Shinya Kitaoka |
120a6e |
m_toolPosY.setValue(hook->getPos(fid).y);
|
|
Shinya Kitaoka |
120a6e |
m_toolSizeWidth.notifyListeners();
|
|
Shinya Kitaoka |
120a6e |
m_toolSizeHeight.notifyListeners();
|
|
Shinya Kitaoka |
120a6e |
m_toolPosX.notifyListeners();
|
|
Shinya Kitaoka |
120a6e |
m_toolPosY.notifyListeners();
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_selection.selectNone();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (xl->getSimpleLevel() && !xl->getSimpleLevel()->isReadOnly()) {
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = getCurrentFid();
|
|
Shinya Kitaoka |
120a6e |
m_what = P10;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Se non รจ selezionato alcun oggetto allora aggiungo un nuovo oggetto e a
|
|
Shinya Kitaoka |
120a6e |
// questo
|
|
Shinya Kitaoka |
120a6e |
// aggiungo una trackerRegion
|
|
Shinya Kitaoka |
120a6e |
int trackerObjectId;
|
|
Shinya Kitaoka |
120a6e |
if (m_hookSelectedIndex == -1 ||
|
|
Shinya Kitaoka |
120a6e |
hookSet->getHook(m_hookSelectedIndex) == 0) {
|
|
Shinya Kitaoka |
120a6e |
trackerObjectId = trackerObjectsSet->addObject();
|
|
Shinya Kitaoka |
120a6e |
m_newObjectAdded = true;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
trackerObjectId =
|
|
Shinya Kitaoka |
120a6e |
hookSet->getHook(m_hookSelectedIndex)->getTrackerObjectId();
|
|
Shinya Kitaoka |
120a6e |
// se l'oggetto selezionato รจ un semplice Hook (senza region)
|
|
Shinya Kitaoka |
120a6e |
// allora creo un nuovo hook con region
|
|
Shinya Kitaoka |
120a6e |
if (trackerObjectId == -1) {
|
|
Shinya Kitaoka |
120a6e |
trackerObjectId = trackerObjectsSet->addObject();
|
|
Shinya Kitaoka |
120a6e |
m_newObjectAdded = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// aggiungo un Hook all'oggetto selezionato
|
|
Shinya Kitaoka |
120a6e |
Hook *newHook = hookSet->addHook();
|
|
Shinya Kitaoka |
120a6e |
if (newHook) {
|
|
Shinya Kitaoka |
120a6e |
newHook->setTrackerObjectId(trackerObjectId);
|
|
Shinya Kitaoka |
120a6e |
newHook->setAPos(fid, pos);
|
|
Shinya Kitaoka |
120a6e |
newHook->setTrackerRegionHeight(pixelSize * 10);
|
|
Shinya Kitaoka |
120a6e |
newHook->setTrackerRegionWidth(pixelSize * 10);
|
|
Shinya Kitaoka |
120a6e |
// setto l'indice della trackerRegion corrente
|
|
Shinya Kitaoka |
120a6e |
m_hookSelectedIndex = newHook->getId(); // hookSet->getHookCount()-1;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (hookSet->getHookCount() >= 20)
|
|
Shinya Kitaoka |
120a6e |
QMessageBox::warning(0, "TrackerTool Error",
|
|
Shinya Kitaoka |
120a6e |
"Hooks number must be at most 20");
|
|
Shinya Kitaoka |
120a6e |
m_hookSelectedIndex = -1;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_selection.makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::leftButtonDrag(const TPointD &pp, const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
if (!m_buttonDown) return;
|
|
Shinya Kitaoka |
120a6e |
if (m_hookSelectedIndex < 0 && m_what != NormalHook) return;
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = getHookSet();
|
|
Shinya Kitaoka |
120a6e |
if (!hookSet) return;
|
|
Shinya Kitaoka |
120a6e |
assert(hookSet->getHook(m_hookSelectedIndex) != 0);
|
|
Shinya Kitaoka |
120a6e |
TrackerObjectsSet *trackerObjectsSet = getTrackerObjectsSet();
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = getCurrentFid();
|
|
Shinya Kitaoka |
120a6e |
if (!trackerObjectsSet) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_dragged == false) {
|
|
Shinya Kitaoka |
120a6e |
m_dragged = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();
|
|
Shinya Kitaoka |
120a6e |
if (xl->getSimpleLevel() && xl->getSimpleLevel()->isReadOnly() &&
|
|
Shinya Kitaoka |
120a6e |
m_what != Inside && m_what != NormalHook)
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_dragged == true) {
|
|
Shinya Kitaoka |
120a6e |
Hook *hook = new Hook();
|
|
Shinya Kitaoka |
120a6e |
hook = getHookSet()->getHook(m_hookSelectedIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!hook || hook->isEmpty()) return;
|
|
Shinya Kitaoka |
120a6e |
TPointD deltaPos = pp - m_oldPos;
|
|
Shinya Kitaoka |
120a6e |
m_oldPos = pp;
|
|
Shinya Kitaoka |
120a6e |
double newWidth = hook->getTrackerRegionWidth();
|
|
Shinya Kitaoka |
120a6e |
double newHeight = hook->getTrackerRegionHeight();
|
|
Shinya Kitaoka |
120a6e |
TAffine aff;
|
|
Shinya Kitaoka |
120a6e |
const double epsilon = 1e-2;
|
|
Shinya Kitaoka |
120a6e |
TPointD posCenter = hook->getPos(fid);
|
|
Shinya Kitaoka |
120a6e |
double a = norm2(pp - posCenter);
|
|
Shinya Kitaoka |
120a6e |
double b = norm2(pp - deltaPos - posCenter);
|
|
Shinya Kitaoka |
120a6e |
switch (m_what) {
|
|
Shinya Kitaoka |
120a6e |
case Inside: // Traslazione
|
|
Shinya Kitaoka |
120a6e |
hook->setAPos(fid, hook->getPos(fid) + deltaPos);
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
case NormalHook: // Traslazione Hook
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
hook->setAPos(fid, hook->getPos(fid) + deltaPos);
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
case P00: // Scalatura
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
if (a <= epsilon || b <= epsilon) return;
|
|
Shinya Kitaoka |
120a6e |
aff = TScale(posCenter, sqrt(a / b));
|
|
Shinya Kitaoka |
120a6e |
TRectD rect = hook->getTrackerRegion(fid);
|
|
Shinya Kitaoka |
120a6e |
TPointD av(hook->getTrackerRegion(fid).getP00());
|
|
Shinya Kitaoka |
120a6e |
TPointD av2(hook->getTrackerRegion(fid).getP11());
|
|
Shinya Kitaoka |
120a6e |
av = aff * av;
|
|
Shinya Kitaoka |
120a6e |
av2 = aff * av2;
|
|
Shinya Kitaoka |
120a6e |
rect = TRectD(av, av2);
|
|
Shinya Kitaoka |
120a6e |
newWidth = rect.getLx();
|
|
Shinya Kitaoka |
120a6e |
newHeight = rect.getLy();
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
case P10: // Scalatura X e Y
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
TPointD pos = hook->getPos(fid);
|
|
Shinya Kitaoka |
120a6e |
TPointD diffPos = pp - pos;
|
|
Shinya Kitaoka |
120a6e |
int signumx = 1;
|
|
Shinya Kitaoka |
120a6e |
int signumy = 1;
|
|
Shinya Kitaoka |
120a6e |
if (diffPos.x < 0) signumx = -1;
|
|
Shinya Kitaoka |
120a6e |
if (diffPos.y < 0) signumy = -1;
|
|
Shinya Kitaoka |
120a6e |
newWidth = fabs(hook->getTrackerRegionWidth() + 2 * signumx * deltaPos.x);
|
|
Shinya Kitaoka |
120a6e |
newHeight =
|
|
Shinya Kitaoka |
120a6e |
fabs(hook->getTrackerRegionHeight() + 2 * signumy * deltaPos.y);
|
|
Shinya Kitaoka |
120a6e |
// double newWidth = fabs(2*diffPos.x-fabs(2*signumx*deltaPos.x));
|
|
Shinya Kitaoka |
120a6e |
// double newHeight = fabs(2*diffPos.y-fabs(2*signumy*deltaPos.y));
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
case P1M: // Ridimensiono X
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
TRectD rect = hook->getTrackerRegion(fid);
|
|
Shinya Kitaoka |
120a6e |
rect = rect.enlarge(deltaPos.x, 0);
|
|
Shinya Kitaoka |
120a6e |
newWidth = rect.getLx();
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
case PM1: // Ridimensiono Y
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
TRectD rect = hook->getTrackerRegion(fid);
|
|
Shinya Kitaoka |
120a6e |
rect = rect.enlarge(0, deltaPos.y);
|
|
Shinya Kitaoka |
120a6e |
newHeight = rect.getLy();
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
default:
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (newWidth > m_toolSizeWidth.getRange().second ||
|
|
Shinya Kitaoka |
120a6e |
newHeight > m_toolSizeHeight.getRange().second)
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
hook->setTrackerRegionWidth(newWidth);
|
|
Shinya Kitaoka |
120a6e |
hook->setTrackerRegionHeight(newHeight);
|
|
Shinya Kitaoka |
120a6e |
m_toolSizeWidth.setValue(hook->getTrackerRegionWidth());
|
|
Shinya Kitaoka |
120a6e |
m_toolSizeHeight.setValue(hook->getTrackerRegionHeight());
|
|
Shinya Kitaoka |
120a6e |
m_toolPosX.setValue(hook->getPos(fid).x);
|
|
Shinya Kitaoka |
120a6e |
m_toolPosY.setValue(hook->getPos(fid).y);
|
|
Shinya Kitaoka |
120a6e |
m_toolPosX.notifyListeners();
|
|
Shinya Kitaoka |
120a6e |
m_toolPosY.notifyListeners();
|
|
Shinya Kitaoka |
120a6e |
m_toolSizeWidth.notifyListeners();
|
|
Shinya Kitaoka |
120a6e |
m_toolSizeHeight.notifyListeners();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// TTool::Application *app = TTool::getApplication());
|
|
Shinya Kitaoka |
120a6e |
// app->getCurrentScene()->getScene()->getXsheet()->getPegbarTree()->invalidateAll();
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::leftButtonUp(const TPointD &pos, const TMouseEvent &) {
|
|
Shinya Kitaoka |
120a6e |
// note: apparently sometimes (when the user triple-clicks) we receive this
|
|
Shinya Kitaoka |
120a6e |
// event twice
|
|
Shinya Kitaoka |
120a6e |
if (!m_buttonDown) return;
|
|
Shinya Kitaoka |
120a6e |
// se clicco su una TrackerRegion giร selezionato lo deseleziono (per
|
|
Shinya Kitaoka |
120a6e |
// permettere
|
|
Shinya Kitaoka |
120a6e |
// poi l'aggiunta di un nuovo TrackerObject
|
|
Shinya Kitaoka |
120a6e |
if (m_dragged == false && m_hookSelectedIndex == m_lastHookSelectedIndex) {
|
|
Shinya Kitaoka |
120a6e |
m_hookSelectedIndex = -1;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (m_newObjectAdded) {
|
|
Shinya Kitaoka |
120a6e |
m_hookSelectedIndex = -1;
|
|
Shinya Kitaoka |
120a6e |
m_newObjectAdded = false;
|
|
Shinya Kitaoka |
120a6e |
// emit signal in order to update schematic
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_lastHookSelectedIndex = m_hookSelectedIndex;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_dragged = false;
|
|
Shinya Kitaoka |
120a6e |
m_buttonDown = false;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();
|
|
Shinya Kitaoka |
120a6e |
if (!xl || !xl->getSimpleLevel()) return;
|
|
Shinya Kitaoka |
120a6e |
xl->getSimpleLevel()->getProperties()->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// m_selection.selectNone();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::deleteSelectedTrackerRegion() {
|
|
Shinya Kitaoka |
120a6e |
TTool::Application *app = TTool::getApplication();
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *xl = app->getCurrentLevel()->getLevel();
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = xl->getHookSet();
|
|
Shinya Kitaoka |
120a6e |
if (!xl || !xl->getSimpleLevel() || !hookSet ||
|
|
Shinya Kitaoka |
120a6e |
xl->getSimpleLevel()->isReadOnly())
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// HookUndo *undo = new HookUndo(xl->getSimpleLevel());
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = getCurrentFid();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Hook *hook = hookSet->getHook(m_hookSelectedIndex);
|
|
Shinya Kitaoka |
120a6e |
m_hookSelectedIndex = -1;
|
|
Shinya Kitaoka |
120a6e |
if (!hook || hook->isEmpty()) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
hookSet->clearHook(hook);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// TUndoManager::manager()->add(undo);
|
|
Shinya Kitaoka |
120a6e |
app->getCurrentScene()
|
|
Shinya Kitaoka |
120a6e |
->getScene()
|
|
Shinya Kitaoka |
120a6e |
->getXsheet()
|
|
Shinya Kitaoka |
120a6e |
->getStageObjectTree()
|
|
Shinya Kitaoka |
120a6e |
->invalidateAll();
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// emit signal in order to update schematic
|
|
Shinya Kitaoka |
120a6e |
TTool::getApplication()->getCurrentXsheet()->notifyXsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*
|
|
Shinya Kitaoka |
120a6e |
int a = m_selectedObjectId;
|
|
Shinya Kitaoka |
120a6e |
int b = m_selectedTrackerRegionIndex;
|
|
Shinya Kitaoka |
120a6e |
if(m_selectedObjectId<0 ||m_selectedTrackerRegionIndex<0) return;
|
|
Shinya Kitaoka |
120a6e |
TrackerObjectsSet *trackerObjectsSet = getTrackerObjectsSet();
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = getCurrentFid();
|
|
Shinya Kitaoka |
120a6e |
if(!trackerObjectsSet) return;
|
|
Shinya Kitaoka |
120a6e |
TrackerObject *trackerObject=
|
|
Shinya Kitaoka |
120a6e |
trackerObjectsSet->getObject(m_selectedObjectId);
|
|
Shinya Kitaoka |
120a6e |
if(trackerObject==NULL) return;
|
|
Shinya Kitaoka |
120a6e |
if(trackerObject->getHooksCount()==0)
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
trackerObjectsSet->removeObject(m_selectedObjectId);
|
|
Shinya Kitaoka |
120a6e |
m_selectedObjectId = -1;
|
|
Shinya Kitaoka |
120a6e |
m_selectedTrackerRegionIndex = -1;
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
trackerObject->removeHook(m_selectedTrackerRegionIndex);
|
|
Shinya Kitaoka |
120a6e |
m_selectedTrackerRegionIndex = trackerObject->getHooksCount()-1;
|
|
Shinya Kitaoka |
120a6e |
invalidate(); */
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {
|
|
Shinya Kitaoka |
120a6e |
m_picked = true;
|
|
Shinya Kitaoka |
120a6e |
if (m_dragged == false) {
|
|
Shinya Kitaoka |
120a6e |
int hookSelectedIndex;
|
|
Shinya Kitaoka |
120a6e |
pick(hookSelectedIndex, pos);
|
|
Shinya Kitaoka |
120a6e |
if (hookSelectedIndex < 0) {
|
|
Shinya Kitaoka |
120a6e |
m_pos = pos;
|
|
Shinya Kitaoka |
120a6e |
m_picked = false;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
bool TrackerTool::onPropertyChanged(std::string propertyName) {
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = getHookSet();
|
|
Shinya Kitaoka |
120a6e |
if (!hookSet || m_hookSelectedIndex < 0) return false;
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = getCurrentFid();
|
|
Shinya Kitaoka |
120a6e |
Hook *hook = hookSet->getHook(m_hookSelectedIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!hook || hook->isEmpty()) return false;
|
|
Shinya Kitaoka |
120a6e |
if (propertyName == "Width:") {
|
|
Shinya Kitaoka |
120a6e |
double width = m_toolSizeWidth.getValue();
|
|
Shinya Kitaoka |
120a6e |
hook->setTrackerRegionWidth(width);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (propertyName == "Height:") {
|
|
Shinya Kitaoka |
120a6e |
double height = m_toolSizeHeight.getValue();
|
|
Shinya Kitaoka |
120a6e |
hook->setTrackerRegionHeight(height);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (propertyName == "X:") {
|
|
Shinya Kitaoka |
120a6e |
double x = m_toolPosX.getValue();
|
|
Shinya Kitaoka |
120a6e |
TPointD pos = hook->getPos(fid);
|
|
Shinya Kitaoka |
120a6e |
pos.x = x;
|
|
Shinya Kitaoka |
120a6e |
hook->setAPos(fid, pos);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (propertyName == "Y:") {
|
|
Shinya Kitaoka |
120a6e |
double y = m_toolPosY.getValue();
|
|
Shinya Kitaoka |
120a6e |
TPointD pos = hook->getPos(fid);
|
|
Shinya Kitaoka |
120a6e |
pos.y = y;
|
|
Shinya Kitaoka |
120a6e |
hook->setAPos(fid, pos);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
invalidate();
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::reset() { m_hookSelectedIndex = -1; }
|
|
Shinya Kitaoka |
120a6e |
int TrackerTool::getCursorId() const {
|
|
Shinya Kitaoka |
120a6e |
switch (m_what) {
|
|
Shinya Kitaoka |
120a6e |
case Outside:
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::TrackerCursor;
|
|
Shinya Kitaoka |
120a6e |
case Inside:
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::MoveCursor;
|
|
Shinya Kitaoka |
120a6e |
case NormalHook:
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::MoveCursor;
|
|
Shinya Kitaoka |
120a6e |
case P00:
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::ScaleCursor;
|
|
Shinya Kitaoka |
120a6e |
case P01:
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::MoveCursor;
|
|
Shinya Kitaoka |
120a6e |
case P10:
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::ScaleCursor;
|
|
Shinya Kitaoka |
120a6e |
case P1M:
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::ScaleHCursor;
|
|
Shinya Kitaoka |
120a6e |
case PM1:
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::ScaleVCursor;
|
|
Shinya Kitaoka |
120a6e |
case ADD_OBJECT:
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::SplineEditorCursorAdd;
|
|
Shinya Kitaoka |
120a6e |
default:
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::TrackerCursor;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return ToolCursor::TrackerCursor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
bool TrackerTool::keyDown(int key, TUINT32 flags, const TPoint &pos) {
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();
|
|
Shinya Kitaoka |
120a6e |
if (!xl) return false;
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = xl->getHookSet();
|
|
Shinya Kitaoka |
120a6e |
if (!hookSet) return false;
|
|
Shinya Kitaoka |
120a6e |
TFrameId fid = getCurrentFid();
|
|
Shinya Kitaoka |
120a6e |
Hook *hook = hookSet->getHook(m_hookSelectedIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!hook || hook->isEmpty()) return false;
|
|
Shinya Kitaoka |
120a6e |
TPointD hookPos = hook->getPos(fid);
|
|
Shinya Kitaoka |
120a6e |
TPointD delta(0, 0);
|
|
Shinya Kitaoka |
120a6e |
double pixelSize = getPixelSize();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (key == TwConsts::TK_UpArrow)
|
|
Shinya Kitaoka |
120a6e |
delta.y = 1;
|
|
Shinya Kitaoka |
120a6e |
else if (key == TwConsts::TK_DownArrow)
|
|
Shinya Kitaoka |
120a6e |
delta.y = -1;
|
|
Shinya Kitaoka |
120a6e |
else if (key == TwConsts::TK_LeftArrow)
|
|
Shinya Kitaoka |
120a6e |
delta.x = -1;
|
|
Shinya Kitaoka |
120a6e |
else if (key == TwConsts::TK_RightArrow)
|
|
Shinya Kitaoka |
120a6e |
delta.x = 1;
|
|
Shinya Kitaoka |
120a6e |
else if (key == TwConsts::TK_PageUp) // converto in Hook
|
|
Shinya Kitaoka |
120a6e |
hook->setTrackerObjectId(-1);
|
|
Shinya Kitaoka |
120a6e |
else if (key == TwConsts::TK_PageDown) // converto in trackerRegion
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
TrackerObjectsSet *trackerObjectsSet = getTrackerObjectsSet();
|
|
Shinya Kitaoka |
120a6e |
if (!trackerObjectsSet) return false;
|
|
Shinya Kitaoka |
120a6e |
int trackerObjectId = hook->getTrackerObjectId();
|
|
Shinya Kitaoka |
120a6e |
if (trackerObjectId != -1) return false;
|
|
Shinya Kitaoka |
120a6e |
trackerObjectId = trackerObjectsSet->addObject();
|
|
Shinya Kitaoka |
120a6e |
hook->setTrackerObjectId(trackerObjectId);
|
|
Shinya Kitaoka |
120a6e |
hook->setTrackerRegionHeight(pixelSize * 20);
|
|
Shinya Kitaoka |
120a6e |
hook->setTrackerRegionWidth(pixelSize * 20);
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
hookPos += delta;
|
|
Shinya Kitaoka |
120a6e |
hook->setAPos(fid, hookPos);
|
|
Shinya Kitaoka |
120a6e |
// TTool::getApplication()->getCurrentTool()->getTool()->notifyImageChanged();
|
|
Shinya Kitaoka |
120a6e |
// TNotifier::instance()->notify(TLevelChange());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// bool moveCursor(const TPointD &pos){}
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::onEnter() {
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = getHookSet();
|
|
Shinya Kitaoka |
120a6e |
if (!hookSet || hookSet->getHookCount() <= m_hookSelectedIndex)
|
|
Shinya Kitaoka |
120a6e |
m_hookSelectedIndex = -1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::onLeave() {
|
|
Shinya Kitaoka |
120a6e |
TrackerObjectsSet *trackerObjectsSet = getTrackerObjectsSet();
|
|
Shinya Kitaoka |
120a6e |
if (trackerObjectsSet) trackerObjectsSet->clearAll();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::onActivate() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerTool::onDeactivate() {
|
|
Shinya Kitaoka |
120a6e |
// m_selection.selectNone();
|
|
Shinya Kitaoka |
120a6e |
// TSelection::setCurrent(0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
d51821 |
//-----------------------------------------------------------------------------
|
|
shun_iwasawa |
d51821 |
|
|
shun_iwasawa |
d51821 |
// returns true if the pressed key is recognized and processed in the tool
|
|
shun_iwasawa |
d51821 |
// instead of triggering the shortcut command.
|
|
shun_iwasawa |
d51821 |
bool TrackerTool::isEventAcceptable(QEvent *e) {
|
|
shun_iwasawa |
d51821 |
if (!isEnabled()) return false;
|
|
shun_iwasawa |
d51821 |
TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();
|
|
shun_iwasawa |
d51821 |
if (!xl) return false;
|
|
shun_iwasawa |
d51821 |
HookSet *hookSet = xl->getHookSet();
|
|
shun_iwasawa |
d51821 |
if (!hookSet) return false;
|
|
shun_iwasawa |
d51821 |
Hook *hook = hookSet->getHook(m_hookSelectedIndex);
|
|
shun_iwasawa |
d51821 |
if (!hook || hook->isEmpty()) return false;
|
|
shun_iwasawa |
d51821 |
|
|
shun_iwasawa |
d51821 |
QKeyEvent *keyEvent = static_cast<qkeyevent *="">(e);</qkeyevent>
|
|
shun_iwasawa |
d51821 |
// shift + arrow will not be recognized for now
|
|
shun_iwasawa |
d51821 |
if (keyEvent->modifiers() & Qt::ShiftModifier) return false;
|
|
shun_iwasawa |
d51821 |
int key = keyEvent->key();
|
|
shun_iwasawa |
d51821 |
return (key == Qt::Key_Up || key == Qt::Key_Down || key == Qt::Key_Left ||
|
|
shun_iwasawa |
d51821 |
key == Qt::Key_Right);
|
|
shun_iwasawa |
d51821 |
// no need to override page up & down keys since they cannot be
|
|
shun_iwasawa |
d51821 |
// used as shortcut key for now
|
|
shun_iwasawa |
d51821 |
}
|
|
shun_iwasawa |
d51821 |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Campbell Barton |
8c6c57 |
static TTool *getTrackerToolTool() { return &trackerTool; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerRegionSelection::enableCommands() {
|
|
Shinya Kitaoka |
120a6e |
enableCommand(m_tool, MI_Clear, &TrackerTool::deleteSelectedTrackerRegion);
|
|
Shinya Kitaoka |
120a6e |
// enableCommand(m_tool, MI_ConvertToRegion,
|
|
Shinya Kitaoka |
120a6e |
// &TrackerRegionSelection::convertToRegion);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TrackerRegionSelection::convertToRegion() {
|
|
Shinya Kitaoka |
120a6e |
int i = 0;
|
|
Shinya Kitaoka |
120a6e |
TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();
|
|
Shinya Kitaoka |
120a6e |
if (!xl) return;
|
|
Shinya Kitaoka |
120a6e |
HookSet *hookSet = xl->getHookSet();
|
|
Shinya Kitaoka |
120a6e |
if (!hookSet) return;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < hookSet->getHookCount(); i++) {
|
|
Shinya Kitaoka |
120a6e |
if (isSelected(i, i)) {
|
|
Shinya Kitaoka |
120a6e |
int trackerObjectId = hookSet->getTrackerObjectsSet()->addObject();
|
|
Shinya Kitaoka |
120a6e |
Hook *hook = hookSet->getHook(i);
|
|
Shinya Kitaoka |
120a6e |
if (!hook || hook->isEmpty()) continue;
|
|
Shinya Kitaoka |
120a6e |
hook->setTrackerObjectId(trackerObjectId);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|