spin blur fx gadget: lock AR / angle with modifier keys

This commit is contained in:
shun-iwasawa 2022-04-19 17:53:31 +09:00 committed by manongjohn
parent c580b5c484
commit 8a94219dfd

View file

@ -53,28 +53,22 @@ void drawSpinField(const TRectD geom, const TPointD center,
} }
// obtain the nearest and the furthest pos inside the geom // obtain the nearest and the furthest pos inside the geom
TPointD nearestPos; TPointD nearestPos;
nearestPos.x = (center.x <= geom.x0) nearestPos.x = (center.x <= geom.x0) ? geom.x0
? geom.x0 : (center.x >= geom.x1) ? geom.x1
: (center.x >= geom.x1) ? geom.x1 : center.x; : center.x;
nearestPos.y = (center.y <= geom.y0) nearestPos.y = (center.y <= geom.y0) ? geom.y0
? geom.y0 : (center.y >= geom.y1) ? geom.y1
: (center.y >= geom.y1) ? geom.y1 : center.y; : center.y;
double minDist = norm(nearestPos - center); double minDist = norm(nearestPos - center);
TPointD farthestPos; TPointD farthestPos;
farthestPos.x = (center.x <= geom.x0) farthestPos.x = (center.x <= geom.x0) ? geom.x1
? geom.x1 : (center.x >= geom.x1) ? geom.x0
: (center.x >= geom.x1) : ((center.x - geom.x0) >= (geom.x1 - center.x)) ? geom.x0
? geom.x0 : geom.x1;
: ((center.x - geom.x0) >= (geom.x1 - center.x)) farthestPos.y = (center.y <= geom.y0) ? geom.y1
? geom.x0 : (center.y >= geom.y1) ? geom.y0
: geom.x1; : ((center.y - geom.y0) >= (geom.y1 - center.y)) ? geom.y0
farthestPos.y = (center.y <= geom.y0) : geom.y1;
? geom.y1
: (center.y >= geom.y1)
? geom.y0
: ((center.y - geom.y0) >= (geom.y1 - center.y))
? geom.y0
: geom.y1;
double maxDist = norm(farthestPos - center); double maxDist = norm(farthestPos - center);
double scale[2] = {1.0, 1.0}; double scale[2] = {1.0, 1.0};
// adjust size for ellipse // adjust size for ellipse
@ -124,28 +118,22 @@ void drawRadialField(const TRectD geom, const TPointD center,
const double pivot) { const double pivot) {
// obtain the nearest and the furthest pos inside the geom // obtain the nearest and the furthest pos inside the geom
TPointD nearestPos; TPointD nearestPos;
nearestPos.x = (center.x <= geom.x0) nearestPos.x = (center.x <= geom.x0) ? geom.x0
? geom.x0 : (center.x >= geom.x1) ? geom.x1
: (center.x >= geom.x1) ? geom.x1 : center.x; : center.x;
nearestPos.y = (center.y <= geom.y0) nearestPos.y = (center.y <= geom.y0) ? geom.y0
? geom.y0 : (center.y >= geom.y1) ? geom.y1
: (center.y >= geom.y1) ? geom.y1 : center.y; : center.y;
double minDist = norm(nearestPos - center); double minDist = norm(nearestPos - center);
TPointD farthestPos; TPointD farthestPos;
farthestPos.x = (center.x <= geom.x0) farthestPos.x = (center.x <= geom.x0) ? geom.x1
? geom.x1 : (center.x >= geom.x1) ? geom.x0
: (center.x >= geom.x1) : ((center.x - geom.x0) >= (geom.x1 - center.x)) ? geom.x0
? geom.x0 : geom.x1;
: ((center.x - geom.x0) >= (geom.x1 - center.x)) farthestPos.y = (center.y <= geom.y0) ? geom.y1
? geom.x0 : (center.y >= geom.y1) ? geom.y0
: geom.x1; : ((center.y - geom.y0) >= (geom.y1 - center.y)) ? geom.y0
farthestPos.y = (center.y <= geom.y0) : geom.y1;
? geom.y1
: (center.y >= geom.y1)
? geom.y0
: ((center.y - geom.y0) >= (geom.y1 - center.y))
? geom.y0
: geom.y1;
double maxDist = norm(farthestPos - center); double maxDist = norm(farthestPos - center);
double scale[2] = {1.0, 1.0}; double scale[2] = {1.0, 1.0};
// adjust size for ellipse // adjust size for ellipse
@ -1657,7 +1645,7 @@ void LinearRangeFxGadget::leftButtonDown(const TPointD &pos,
if (m_handle == None) return; if (m_handle == None) return;
m_clickedPos = pos; m_clickedPos = pos;
m_targetPos = (m_handle == Start || m_handle == Body) ? getValue(m_start) m_targetPos = (m_handle == Start || m_handle == Body) ? getValue(m_start)
: getValue(m_end); : getValue(m_end);
m_anotherPos = (m_handle == Start || m_handle == Body) ? getValue(m_end) m_anotherPos = (m_handle == Start || m_handle == Body) ? getValue(m_end)
: getValue(m_start); : getValue(m_start);
} }
@ -2318,29 +2306,34 @@ void EllipseFxGadget::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
TPointD old_v = m_pos - center; TPointD old_v = m_pos - center;
TPointD new_v = pos - center; TPointD new_v = pos - center;
if (old_v == TPointD() || new_v == TPointD()) return; if (old_v == TPointD() || new_v == TPointD()) return;
// AR // AR
double aspect_ratio = getValue(m_aspect_ratio); if (!e.isShiftPressed()) { // lock AR when shift is pressed
double pre_axisLength = 2.0 * aspect_ratio / (aspect_ratio + 1.0); double aspect_ratio = getValue(m_aspect_ratio);
double ratio = norm(new_v) / norm(old_v); double pre_axisLength = 2.0 * aspect_ratio / (aspect_ratio + 1.0);
if (ratio == 0.) return; double ratio = norm(new_v) / norm(old_v);
double new_axisLength = pre_axisLength * ratio; if (ratio == 0.) return;
double new_ar = new_axisLength / (2.0 - new_axisLength); double new_axisLength = pre_axisLength * ratio;
if (new_ar < 0.1) double new_ar = new_axisLength / (2.0 - new_axisLength);
new_ar = 0.1; if (new_ar < 0.1)
else if (new_ar > 10.0) new_ar = 0.1;
new_ar = 10.0; else if (new_ar > 10.0)
setValue(m_aspect_ratio, new_ar); new_ar = 10.0;
setValue(m_aspect_ratio, new_ar);
}
// angle // angle
double angle = getValue(m_angle); if (!e.isCtrlPressed()) { // lock angle when ctrl is pressed
double d_angle = double angle = getValue(m_angle);
std::atan2(new_v.y, new_v.x) - std::atan2(old_v.y, old_v.x); double d_angle =
double new_angle = angle + d_angle * M_180_PI; std::atan2(new_v.y, new_v.x) - std::atan2(old_v.y, old_v.x);
if (new_angle < -180.0) double new_angle = angle + d_angle * M_180_PI;
new_angle += 360.0; if (new_angle < -180.0)
else if (new_angle > 180.0) new_angle += 360.0;
new_angle -= 360.0; else if (new_angle > 180.0)
setValue(m_angle, new_angle); new_angle -= 360.0;
setValue(m_angle, new_angle);
}
m_pos = pos; m_pos = pos;
} else if (m_handle == Twist) { } else if (m_handle == Twist) {
@ -2709,4 +2702,3 @@ TRectD FxGadgetController::getCameraRect() {
return (m_tool->getViewer()) ? m_tool->getViewer()->getCameraRect() return (m_tool->getViewer()) ? m_tool->getViewer()->getCameraRect()
: TRectD(); : TRectD();
} }