|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
#define NOMINMAX
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "ext/Selector.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tgl.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "drawutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tmathutil.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace ToonzExt;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const GLfloat s_normalColor[] = {250.0 / 255.0, 127 / 255.0, 240 / 255.0};
|
|
Toshihiro Shimizu |
890ddd |
const GLfloat s_highlightedColor[] = {150.0 / 255.0, 255.0 / 255.0, 140.0 / 255.0};
|
|
Toshihiro Shimizu |
890ddd |
const double s_sqrt_2 = sqrt(2.0);
|
|
Toshihiro Shimizu |
890ddd |
const double s_radius = 5.0;
|
|
Toshihiro Shimizu |
890ddd |
const double s_over_size = 10;
|
|
Toshihiro Shimizu |
890ddd |
const double s_length = 15;
|
|
Toshihiro Shimizu |
890ddd |
const double s_square_size = 5;
|
|
Toshihiro Shimizu |
890ddd |
const double s_arrow_ratio = 2.5;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void drawArrow(const TPointD &from,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &direction,
|
|
Toshihiro Shimizu |
890ddd |
double length,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &arrowDirection = TPointD(0.0, -1.0),
|
|
Toshihiro Shimizu |
890ddd |
double arrowLength = 0.0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (length <= 0 ||
|
|
Toshihiro Shimizu |
890ddd |
arrowLength < 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (arrowLength == 0.0)
|
|
Toshihiro Shimizu |
890ddd |
arrowLength = 0.2 * length;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
pnt(from),
|
|
Toshihiro Shimizu |
890ddd |
myDir = normalize(direction);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
myArrowDirection(arrowDirection);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (arrowDirection.y <= 0.0)
|
|
Toshihiro Shimizu |
890ddd |
myArrowDirection = normalize(TPointD(-0.5, 0.8));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (direction * TPointD(1, 0) <= 0.0)
|
|
Toshihiro Shimizu |
890ddd |
myArrowDirection.x = -myArrowDirection.x;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
myDir = myDir * length;
|
|
Toshihiro Shimizu |
890ddd |
myArrowDirection = myArrowDirection * arrowLength;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glBegin(GL_LINES);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(pnt);
|
|
Toshihiro Shimizu |
890ddd |
pnt += myDir;
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(pnt);
|
|
Toshihiro Shimizu |
890ddd |
glEnd();
|
|
Toshihiro Shimizu |
890ddd |
glBegin(GL_TRIANGLES);
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
up = myDir + myArrowDirection;
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(from + up);
|
|
Toshihiro Shimizu |
890ddd |
//tglVertex(pnt);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(pnt);
|
|
Toshihiro Shimizu |
890ddd |
myArrowDirection.y = -myArrowDirection.y;
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
down = myDir + myArrowDirection;
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(from + down);
|
|
Toshihiro Shimizu |
890ddd |
glEnd();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Selector::Selector(double stroke_length,
|
|
Toshihiro Shimizu |
890ddd |
double min_val,
|
|
Toshihiro Shimizu |
890ddd |
double max_val)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
original_stroke_length_ = stroke_length;
|
|
Toshihiro Shimizu |
890ddd |
range_ = TPointD(min_val, max_val);
|
|
Toshihiro Shimizu |
890ddd |
isVisible_ = false;
|
|
Toshihiro Shimizu |
890ddd |
pixel_size_ = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
w_ = 0.5;
|
|
Toshihiro Shimizu |
890ddd |
this->init();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Selector::init()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
strokeRef_ = 0;
|
|
Toshihiro Shimizu |
890ddd |
signum_ = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
isSelected_ = NONE;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Selector::~Selector()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
Selector::getUp() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!strokeRef_)
|
|
Toshihiro Shimizu |
890ddd |
return TPointD();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint
|
|
Toshihiro Shimizu |
890ddd |
pnt = strokeRef_->getPoint(w_);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
p = convert(pnt),
|
|
Toshihiro Shimizu |
890ddd |
p1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
v0,
|
|
Toshihiro Shimizu |
890ddd |
v1,
|
|
Toshihiro Shimizu |
890ddd |
v = normalize(rotate90(strokeRef_->getSpeed(w_)));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const double delta = TConsts::epsilon;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (w_ - delta >= 0.0)
|
|
Toshihiro Shimizu |
890ddd |
v0 = rotate90(strokeRef_->getSpeed(w_ - delta));
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
v0 = rotate90(strokeRef_->getSpeed(0));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (w_ + delta <= 1.0)
|
|
Toshihiro Shimizu |
890ddd |
v1 = rotate90(strokeRef_->getSpeed(w_ + delta));
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
v1 = rotate90(strokeRef_->getSpeed(1.0));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!isAlmostZero(v * v0) ||
|
|
Toshihiro Shimizu |
890ddd |
!isAlmostZero(v * v1))
|
|
Toshihiro Shimizu |
890ddd |
v = normalize(v1 + v0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return v;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Selector::draw(Designer *designer)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!strokeRef_ ||
|
|
Toshihiro Shimizu |
890ddd |
!isVisible_)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pixel_size_ = designer ? sqrt(designer->getPixelSize2()) : 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
v = this->getUp(),
|
|
Toshihiro Shimizu |
890ddd |
n = normalize(rotate90(v));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint
|
|
Toshihiro Shimizu |
890ddd |
pnt = strokeRef_->getThickPoint(w_);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
height_ = (pnt.thick + s_over_size) * pixel_size_;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
p(pnt.x, pnt.y),
|
|
Toshihiro Shimizu |
890ddd |
up = p + v * height_,
|
|
Toshihiro Shimizu |
890ddd |
down = p - v * height_;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glColor3fv(s_normalColor);
|
|
Toshihiro Shimizu |
890ddd |
glBegin(GL_LINES);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(down);
|
|
Toshihiro Shimizu |
890ddd |
tglVertex(up);
|
|
Toshihiro Shimizu |
890ddd |
glEnd();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (isSelected_ == POSITION)
|
|
Toshihiro Shimizu |
890ddd |
glColor3fv(s_highlightedColor);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
glColor3fv(s_normalColor);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double
|
|
Toshihiro Shimizu |
890ddd |
radius = s_radius * pixel_size_;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (isSelected_ == POSITION)
|
|
Toshihiro Shimizu |
890ddd |
tglDrawDisk(up + v * radius,
|
|
Toshihiro Shimizu |
890ddd |
radius);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(up + v * radius,
|
|
Toshihiro Shimizu |
890ddd |
radius);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (isSelected_ == LENGTH)
|
|
Toshihiro Shimizu |
890ddd |
glColor3fv(s_highlightedColor);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
glColor3fv(s_normalColor);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// the circle center is in
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
down = -this->getUp(),
|
|
Toshihiro Shimizu |
890ddd |
center = pnt + down * (height_);
|
|
Toshihiro Shimizu |
890ddd |
const double
|
|
Toshihiro Shimizu |
890ddd |
length = s_square_size * 0.5 * pixel_size_;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
// offset(length, 0.0),
|
|
Toshihiro Shimizu |
890ddd |
offset(length,
|
|
Toshihiro Shimizu |
890ddd |
length),
|
|
Toshihiro Shimizu |
890ddd |
bottom_left = center - offset,
|
|
Toshihiro Shimizu |
890ddd |
top_rigth = center + offset;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectD
|
|
Toshihiro Shimizu |
890ddd |
rectangle(bottom_left,
|
|
Toshihiro Shimizu |
890ddd |
top_rigth);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (isSelected_ == LENGTH)
|
|
Toshihiro Shimizu |
890ddd |
tglFillRect(rectangle);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglDrawRect(rectangle);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
arrowDirection(-0.5,0.8);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if( signum_ < 0.0 )
|
|
Toshihiro Shimizu |
890ddd |
arrowDirection.x = -arrowDirection.x;
|
|
Toshihiro Shimizu |
890ddd |
const double
|
|
Toshihiro Shimizu |
890ddd |
length = s_length * pixel_size_,
|
|
Toshihiro Shimizu |
890ddd |
arrow_length = length/s_arrow_ratio;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
drawArrow(down,
|
|
Toshihiro Shimizu |
890ddd |
TPointD(1,0),
|
|
Toshihiro Shimizu |
890ddd |
length,
|
|
Toshihiro Shimizu |
890ddd |
arrowDirection,
|
|
Toshihiro Shimizu |
890ddd |
arrow_length);
|
|
Toshihiro Shimizu |
890ddd |
drawArrow(down,
|
|
Toshihiro Shimizu |
890ddd |
TPointD(-1,0),
|
|
Toshihiro Shimizu |
890ddd |
length,
|
|
Toshihiro Shimizu |
890ddd |
arrowDirection,
|
|
Toshihiro Shimizu |
890ddd |
arrow_length);
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
// draw stroke related information
|
|
Toshihiro Shimizu |
890ddd |
if (designer &&
|
|
Toshihiro Shimizu |
890ddd |
this->isSelected())
|
|
Toshihiro Shimizu |
890ddd |
designer->draw(this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if 0 //def _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint
|
|
Toshihiro Shimizu |
890ddd |
pnt = strokeRef_->getThickPoint(w_);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
up = this->getUp(),
|
|
Toshihiro Shimizu |
890ddd |
down = -up;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double
|
|
Toshihiro Shimizu |
890ddd |
radius = s_radius * pixel_size_;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// the circle center is in
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
center = pnt + up * ( height_ + radius);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
glColor3d(1.0,0.0,1.0);
|
|
Toshihiro Shimizu |
890ddd |
tglDrawCircle(center,radius+pixel_size_);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// one pixel of tolerance
|
|
Toshihiro Shimizu |
890ddd |
center = pnt + down * ( height_ );
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const double
|
|
Toshihiro Shimizu |
890ddd |
length = s_length * pixel_size_;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
offset(length, 0.0),
|
|
Toshihiro Shimizu |
890ddd |
bottom_left = center - offset,
|
|
Toshihiro Shimizu |
890ddd |
top_rigth = center + offset;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectD
|
|
Toshihiro Shimizu |
890ddd |
rectangle(bottom_left,
|
|
Toshihiro Shimizu |
890ddd |
top_rigth);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
rectangle = rectangle.enlarge( 2.0* pixel_size_);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
tglDrawRect(rectangle);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Selector::mouseDown(const TPointD &pos)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
click_ =
|
|
Toshihiro Shimizu |
890ddd |
curr_ =
|
|
Toshihiro Shimizu |
890ddd |
pos;
|
|
Toshihiro Shimizu |
890ddd |
if (!strokeRef_)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
stroke_length_ =
|
|
Toshihiro Shimizu |
890ddd |
original_stroke_length_;
|
|
Toshihiro Shimizu |
890ddd |
prev_ = curr_;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Selector::mouseUp(const TPointD &pos)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
curr_ = pos;
|
|
Toshihiro Shimizu |
890ddd |
if (!strokeRef_)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
original_stroke_length_ =
|
|
Toshihiro Shimizu |
890ddd |
stroke_length_;
|
|
Toshihiro Shimizu |
890ddd |
prev_ = curr_;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Selector::mouseMove(const TPointD &pos)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
curr_ = pos;
|
|
Toshihiro Shimizu |
890ddd |
if (!strokeRef_)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
isSelected_ = this->getSelection(pos);
|
|
Toshihiro Shimizu |
890ddd |
prev_ = curr_;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Selector::mouseDrag(const TPointD &pos)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
curr_ = pos;
|
|
Toshihiro Shimizu |
890ddd |
if (!strokeRef_)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double
|
|
Toshihiro Shimizu |
890ddd |
val = original_stroke_length_;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const double
|
|
Toshihiro Shimizu |
890ddd |
stroke_length = strokeRef_->getLength();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double
|
|
Toshihiro Shimizu |
890ddd |
max_val = std::min(stroke_length, range_.y);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
v = curr_ - prev_;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
signum_ = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
switch (isSelected_) {
|
|
Toshihiro Shimizu |
890ddd |
case POSITION:
|
|
Toshihiro Shimizu |
890ddd |
w_ = strokeRef_->getW(pos);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case LENGTH:
|
|
Toshihiro Shimizu |
890ddd |
signum_ = v * TPointD(1.0, 0.0) < 0.0 ? -1.0 : 1.0;
|
|
Toshihiro Shimizu |
890ddd |
val = original_stroke_length_ + signum_ * pixel_size_ * norm(v);
|
|
Toshihiro Shimizu |
890ddd |
stroke_length_ = std::max(std::min(max_val, val), range_.x);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
default:
|
|
Toshihiro Shimizu |
890ddd |
assert(false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
prev_ = curr_;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Selector::setStroke(const TStroke *ref)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//if(strokeRef_ &&
|
|
Toshihiro Shimizu |
890ddd |
// strokeRef_ != ref )
|
|
Toshihiro Shimizu |
890ddd |
// w_=strokeRef_->getParameterAtLength( strokeRef_->getLength()*0.5);
|
|
Toshihiro Shimizu |
890ddd |
//else
|
|
Toshihiro Shimizu |
890ddd |
// w_=0.5;
|
|
Toshihiro Shimizu |
890ddd |
this->init();
|
|
Toshihiro Shimizu |
890ddd |
strokeRef_ = ref;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Selector::Selection
|
|
Toshihiro Shimizu |
890ddd |
Selector::getSelection(const TPointD &pos)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!strokeRef_ ||
|
|
Toshihiro Shimizu |
890ddd |
!isVisible_)
|
|
Toshihiro Shimizu |
890ddd |
return NONE;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint
|
|
Toshihiro Shimizu |
890ddd |
pnt = strokeRef_->getThickPoint(w_);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
up = this->getUp(),
|
|
Toshihiro Shimizu |
890ddd |
down = -up;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double
|
|
Toshihiro Shimizu |
890ddd |
radius = s_radius * pixel_size_;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// the circle center is in
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
center = pnt + up * (height_ + radius);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// one pixel of tolerance
|
|
Toshihiro Shimizu |
890ddd |
if (tdistance2(center, pos) <= sq(radius + pixel_size_))
|
|
Toshihiro Shimizu |
890ddd |
return POSITION;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
center = pnt + down * (height_);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// const double length = s_length * pixel_size_;
|
|
Toshihiro Shimizu |
890ddd |
const double length = s_square_size * 0.5 * pixel_size_;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD
|
|
Toshihiro Shimizu |
890ddd |
// offset(length, 0.0),
|
|
Toshihiro Shimizu |
890ddd |
offset(length,
|
|
Toshihiro Shimizu |
890ddd |
length),
|
|
Toshihiro Shimizu |
890ddd |
bottom_left = center - offset,
|
|
Toshihiro Shimizu |
890ddd |
top_rigth = center + offset;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectD
|
|
Toshihiro Shimizu |
890ddd |
rectangle(bottom_left,
|
|
Toshihiro Shimizu |
890ddd |
top_rigth);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
rectangle = rectangle.enlarge(2.0 * pixel_size_);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (rectangle.contains(pos))
|
|
Toshihiro Shimizu |
890ddd |
return LENGTH;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return NONE;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double
|
|
Toshihiro Shimizu |
890ddd |
Selector::getLength() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return stroke_length_;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void Selector::setLength(double length)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
stroke_length_ =
|
|
Toshihiro Shimizu |
890ddd |
original_stroke_length_ = length;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// End Of File
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|