|
Toshihiro Shimizu |
890ddd |
#include "rulertool.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tscenehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevelhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/toolutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttoonzimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tools/cursors.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "trasterimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tgl.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/stage2.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshsimplelevel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/icongenerator.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tenv.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tconst.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tframehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
RulerTool::RulerTool()
|
|
Toshihiro Shimizu |
890ddd |
: TTool("T_Ruler"), m_firstPos(TConst::nowhere), m_secondPos(TConst::nowhere), m_mousePos(TConst::nowhere), m_dragMode(MakeNewRuler), m_justClicked(false)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bind(TTool::AllTargets);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void RulerTool::setToolOptionsBox(RulerToolOptionsBox *toolOptionsBox)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_toolOptionsBox.push_back(toolOptionsBox);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void RulerTool::onImageChanged()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*--位置をリセット--*/
|
|
Toshihiro Shimizu |
890ddd |
m_firstPos = TConst::nowhere;
|
|
Toshihiro Shimizu |
890ddd |
m_secondPos = TConst::nowhere;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)m_toolOptionsBox.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
m_toolOptionsBox[i]->resetValues();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void RulerTool::draw()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*--- 始点が設定されていたら、描画 ---*/
|
|
Toshihiro Shimizu |
890ddd |
if (m_firstPos != TConst::nowhere) {
|
|
Toshihiro Shimizu |
890ddd |
tglColor((m_dragMode == MoveFirstPos) ? TPixel32(51, 204, 26) : TPixel32::Red);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(m_firstPos, 4);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(m_firstPos, 2);
|
|
Toshihiro Shimizu |
890ddd |
/*--- 終点が設定されていたら、その区間を描画 ---*/
|
|
Toshihiro Shimizu |
890ddd |
if (m_secondPos != TConst::nowhere) {
|
|
Toshihiro Shimizu |
890ddd |
tglColor((m_dragMode == MoveRuler) ? TPixel32(51, 204, 26) : TPixel32::Red);
|
|
Toshihiro Shimizu |
890ddd |
glBegin(GL_LINE_STRIP);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(m_firstPos);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(m_secondPos);
|
|
Toshihiro Shimizu |
890ddd |
glEnd();
|
|
Toshihiro Shimizu |
890ddd |
tglColor((m_dragMode == MoveSecondPos) ? TPixel32(51, 204, 26) : TPixel32::Red);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(m_secondPos, 4);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void RulerTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_dragMode == MakeNewRuler)
|
|
Toshihiro Shimizu |
890ddd |
m_justClicked = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void RulerTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*-- 最初のドラッグ --*/
|
|
Toshihiro Shimizu |
890ddd |
if (m_justClicked && m_dragMode == MakeNewRuler) {
|
|
Toshihiro Shimizu |
890ddd |
m_firstPos = m_mousePos;
|
|
Toshihiro Shimizu |
890ddd |
m_justClicked = false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- ドラッグモードがMakeNewRuler/MoveSecondPosのとき、secondPosを更新 --*/
|
|
Toshihiro Shimizu |
890ddd |
if (m_dragMode == MakeNewRuler || m_dragMode == MoveSecondPos) {
|
|
Toshihiro Shimizu |
890ddd |
/*-- Shiftキーが押されていたら:0,45,90度に角度固定の直線を引く --*/
|
|
Toshihiro Shimizu |
890ddd |
if (e.isShiftPressed())
|
|
Toshihiro Shimizu |
890ddd |
m_secondPos = getHVCoordinatedPos(pos, m_firstPos);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_secondPos = pos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- ドラッグモードがMoveFirstPosのとき、firstPosを更新 --*/
|
|
Toshihiro Shimizu |
890ddd |
else if (m_dragMode == MoveFirstPos) {
|
|
Toshihiro Shimizu |
890ddd |
/*-- Shiftキーが押されていたら:0,45,90度に角度固定の直線を引く --*/
|
|
Toshihiro Shimizu |
890ddd |
if (e.isShiftPressed())
|
|
Toshihiro Shimizu |
890ddd |
m_firstPos = getHVCoordinatedPos(pos, m_secondPos);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_firstPos = pos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- Ruler全体を移動するモード --*/
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TPointD d = pos - m_mousePos;
|
|
Toshihiro Shimizu |
890ddd |
m_firstPos += d;
|
|
Toshihiro Shimizu |
890ddd |
m_secondPos += d;
|
|
Toshihiro Shimizu |
890ddd |
/*-- マウス位置を更新 --*/
|
|
Toshihiro Shimizu |
890ddd |
m_mousePos = pos;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
updateToolOption(); /*-- ToolOptionの表示を更新 --*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void RulerTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_justClicked = false;
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void RulerTool::mouseMove(const TPointD &pos, const TMouseEvent &e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*-- マウス位置を更新 --*/
|
|
Toshihiro Shimizu |
890ddd |
m_mousePos = pos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- マウスクリックしてたら無視 --*/
|
|
Toshihiro Shimizu |
890ddd |
if (e.isLeftButtonPressed())
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- マウスがRulerの端点/Rulerそのものに近い場合はドラッグモードを変更する。--*/
|
|
Toshihiro Shimizu |
890ddd |
if (m_firstPos != TConst::nowhere && tdistance2(pos, m_firstPos) < 16)
|
|
Toshihiro Shimizu |
890ddd |
m_dragMode = MoveFirstPos;
|
|
Toshihiro Shimizu |
890ddd |
else if (m_secondPos != TConst::nowhere && tdistance2(pos, m_secondPos) < 16)
|
|
Toshihiro Shimizu |
890ddd |
m_dragMode = MoveSecondPos;
|
|
Toshihiro Shimizu |
890ddd |
else if (isNearRuler())
|
|
Toshihiro Shimizu |
890ddd |
m_dragMode = MoveRuler;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_dragMode = MakeNewRuler;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
invalidate();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void RulerTool::onActivate()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*-- 位置をリセット --*/
|
|
Toshihiro Shimizu |
890ddd |
m_firstPos = TConst::nowhere;
|
|
Toshihiro Shimizu |
890ddd |
m_secondPos = TConst::nowhere;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)m_toolOptionsBox.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
m_toolOptionsBox[i]->resetValues();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int RulerTool::getCursorId() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_dragMode == MakeNewRuler)
|
|
Toshihiro Shimizu |
890ddd |
return ToolCursor::RulerNewCursor;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
return ToolCursor::RulerModifyCursor;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*-- ToolOptionの表示を更新 --*/
|
|
Toshihiro Shimizu |
890ddd |
void RulerTool::updateToolOption()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TTool::Application *app = TTool::getApplication();
|
|
Toshihiro Shimizu |
890ddd |
TFrameHandle *currentFrame = app->getCurrentFrame();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double x, y, w, h, a, l;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- Level編集モードのとき、そのLevelのDPIに合わせてInchの値を得る。Pixelの値も出力する。 --*/
|
|
Toshihiro Shimizu |
890ddd |
if (currentFrame->isEditingLevel()) {
|
|
Toshihiro Shimizu |
890ddd |
TXshLevelHandle *currentLevel = app->getCurrentLevel();
|
|
Toshihiro Shimizu |
890ddd |
TXshLevel *xl = currentLevel->getLevel();
|
|
Toshihiro Shimizu |
890ddd |
if (xl) {
|
|
Toshihiro Shimizu |
890ddd |
TXshSimpleLevel *sl = xl->getSimpleLevel();
|
|
Toshihiro Shimizu |
890ddd |
if (sl) {
|
|
Toshihiro Shimizu |
890ddd |
int subsampling = sl->getImageSubsampling(getCurrentFid());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD dpiScale = getViewer()->getDpiScale();
|
|
Toshihiro Shimizu |
890ddd |
TPointD pp1 = TPointD(m_firstPos.x / dpiScale.x, m_firstPos.y / dpiScale.y);
|
|
Toshihiro Shimizu |
890ddd |
TPointD pp2 = TPointD(m_secondPos.x / dpiScale.x, m_secondPos.y / dpiScale.y);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD p1 = TScale(1.0 / subsampling) * pp1 + TPointD(-0.5, -0.5);
|
|
Toshihiro Shimizu |
890ddd |
TPointD p2 = TScale(1.0 / subsampling) * pp2 + TPointD(-0.5, -0.5);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageP image = getImage(false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPoint pix1, pix2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TToonzImageP ti = image;
|
|
Toshihiro Shimizu |
890ddd |
TRasterImageP ri = image;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (ti || ri) {
|
|
Toshihiro Shimizu |
890ddd |
if (ti) {
|
|
Toshihiro Shimizu |
890ddd |
TDimension size = ti->getSize();
|
|
Toshihiro Shimizu |
890ddd |
pix1 = TPoint(tround(0.5 * size.lx + p1.x), tround(0.5 * size.ly + p1.y));
|
|
Toshihiro Shimizu |
890ddd |
pix2 = TPoint(tround(0.5 * size.lx + p2.x), tround(0.5 * size.ly + p2.y));
|
|
Toshihiro Shimizu |
890ddd |
} else if (ri) {
|
|
Toshihiro Shimizu |
890ddd |
TDimension size = ri->getRaster()->getSize();
|
|
Toshihiro Shimizu |
890ddd |
pix1 = TPoint(tround(0.5 * size.lx + p1.x), tround(0.5 * size.ly + p1.y));
|
|
Toshihiro Shimizu |
890ddd |
pix2 = TPoint(tround(0.5 * size.lx + p2.x), tround(0.5 * size.ly + p2.y));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
int xPix, yPix, wPix, hPix;
|
|
Toshihiro Shimizu |
890ddd |
TPointD dpi = sl->getDpi(getCurrentFid());
|
|
Toshihiro Shimizu |
890ddd |
xPix = pix1.x;
|
|
Toshihiro Shimizu |
890ddd |
yPix = pix1.y;
|
|
Toshihiro Shimizu |
890ddd |
wPix = pix2.x - pix1.x;
|
|
Toshihiro Shimizu |
890ddd |
hPix = pix2.y - pix1.y;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
x = (double)xPix / dpi.x;
|
|
Toshihiro Shimizu |
890ddd |
y = (double)yPix / dpi.y;
|
|
Toshihiro Shimizu |
890ddd |
w = (double)wPix / dpi.x;
|
|
Toshihiro Shimizu |
890ddd |
h = (double)hPix / dpi.y;
|
|
Toshihiro Shimizu |
890ddd |
a = atan2(h, w) * 180.0 / 3.14159264;
|
|
Toshihiro Shimizu |
890ddd |
l = sqrt(w * w + h * h);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)m_toolOptionsBox.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
m_toolOptionsBox[i]->updateValues(true, x, y, w, h, a, l,
|
|
Toshihiro Shimizu |
890ddd |
xPix, yPix, wPix, hPix);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- シーン編集モードのとき、Stage::inchで割った値がInch値となる --*/
|
|
Toshihiro Shimizu |
890ddd |
x = m_firstPos.x / Stage::inch;
|
|
Toshihiro Shimizu |
890ddd |
y = m_firstPos.y / Stage::inch;
|
|
Toshihiro Shimizu |
890ddd |
w = (m_secondPos.x - m_firstPos.x) / Stage::inch;
|
|
Toshihiro Shimizu |
890ddd |
h = (m_secondPos.y - m_firstPos.y) / Stage::inch;
|
|
Toshihiro Shimizu |
890ddd |
a = atan2(h, w) * 180.0 / 3.14159264;
|
|
Toshihiro Shimizu |
890ddd |
l = sqrt(w * w + h * h);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)m_toolOptionsBox.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
m_toolOptionsBox[i]->updateValues(false, x, y, w, h, a, l);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! 現在のマウス位置がRulerに十分近ければTrueを返す
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
bool RulerTool::isNearRuler()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double a, b, c;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD vec = m_secondPos - m_firstPos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
a = -vec.y;
|
|
Toshihiro Shimizu |
890ddd |
b = vec.x;
|
|
Toshihiro Shimizu |
890ddd |
c = -a * m_firstPos.x - b * m_firstPos.y;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double k = a * m_mousePos.x + b * m_mousePos.y + c;
|
|
Toshihiro Shimizu |
890ddd |
double d2 = k * k / (a * a + b * b);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- 距離が4より遠ければfalse --*/
|
|
Toshihiro Shimizu |
890ddd |
if (d2 > 16)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*-- 垂線の足がRuler上にあるかを判断。Rulerを対角線とするRectにマウス位置が収まるかどうか --*/
|
|
Toshihiro Shimizu |
890ddd |
TRectD rect = TRectD(m_firstPos, m_secondPos).enlarge(4);
|
|
Toshihiro Shimizu |
890ddd |
return rect.contains(m_mousePos);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! 基準点に対し、マウス位置を0,45,90度にフィットさせた位置を返す
|
|
Toshihiro Shimizu |
890ddd |
斜め方向では、X/Yの値のうち絶対値の小さいほうに合わせる。
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
TPointD RulerTool::getHVCoordinatedPos(TPointD p, TPointD centerPos)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TPointD vec = p - centerPos;
|
|
Toshihiro Shimizu |
890ddd |
double degree = (vec.x == 0.0) ? 90.0 : atan(vec.y / vec.x) * 180.0 / 3.1415926536;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD outPoint;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (degree <= -67.5) /*--垂直--*/
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
outPoint.x = centerPos.x;
|
|
Toshihiro Shimizu |
890ddd |
outPoint.y = p.y;
|
|
Toshihiro Shimizu |
890ddd |
} else if (degree < -22.5) /*--右斜め下--*/
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (abs(vec.x) > abs(vec.y))
|
|
Toshihiro Shimizu |
890ddd |
outPoint = centerPos + TPointD(-vec.y, vec.y);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
outPoint = centerPos + TPointD(vec.x, -vec.x);
|
|
Toshihiro Shimizu |
890ddd |
} else if (degree <= 22.5) /*--水平--*/
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
outPoint.x = p.x;
|
|
Toshihiro Shimizu |
890ddd |
outPoint.y = centerPos.y;
|
|
Toshihiro Shimizu |
890ddd |
} else if (degree < 67.5) /*--右斜め上--*/
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (abs(vec.x) > abs(vec.y))
|
|
Toshihiro Shimizu |
890ddd |
outPoint = centerPos + TPointD(vec.y, vec.y);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
outPoint = centerPos + TPointD(vec.x, vec.x);
|
|
Toshihiro Shimizu |
890ddd |
} else /*--再び垂直--*/
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
outPoint.x = centerPos.x;
|
|
Toshihiro Shimizu |
890ddd |
outPoint.y = p.y;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return outPoint;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
RulerTool RulerTool;
|