提交 9ed1ebb0 编写于 作者: O openharmony_ci 提交者: Gitee

!423 增加旋转表冠惯性滑动控制因子接口

Merge pull request !423 from JayLeeHW/master-rotate-inertial
......@@ -246,28 +246,36 @@ void UIAbstractScroll::CalculateDragDistance(Point currentPos,
if ((direction_ == VERTICAL) || (direction_ == HORIZONTAL_AND_VERTICAL)) {
dragDistanceY = currentPos.y - lastPos.y;
if (isRotating_) {
dragDistanceY *= ROTATE_DISTANCE_COEFFICIENT;
// 255 : uint8 max value
uint8_t coeff = (rotateAccCoefficient_ >= 255 - ROTATE_DISTANCE_COEFFICIENT) ?
255 : (ROTATE_DISTANCE_COEFFICIENT + rotateAccCoefficient_); // 255 : uint8 max value
dragDistanceY *= coeff;
} else {
dragDistanceY *= DRAG_DISTANCE_COEFFICIENT;
}
if (dragDistanceY > 0 || (dragDistanceY == 0 && dragDirection == DragEvent::DIRECTION_TOP_TO_BOTTOM)) {
dragDistanceY += GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
} else if (dragDistanceY < 0 || (dragDistanceY == 0 && dragDirection == DragEvent::DIRECTION_BOTTOM_TO_TOP)) {
dragDistanceY -= GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
if (dragDistanceY > 0 || (dragDistanceY == 0 && dragDirection == DragEvent::DIRECTION_TOP_TO_BOTTOM)) {
dragDistanceY += GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
} else if (dragDistanceY < 0 ||
(dragDistanceY == 0 && dragDirection == DragEvent::DIRECTION_BOTTOM_TO_TOP)) {
dragDistanceY -= GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
}
}
}
if ((direction_ == HORIZONTAL) || (direction_ == HORIZONTAL_AND_VERTICAL)) {
dragDistanceX = currentPos.x - lastPos.x;
if (isRotating_) {
dragDistanceX *= ROTATE_DISTANCE_COEFFICIENT;
// 255 : uint8 max value
uint8_t coeff = (rotateAccCoefficient_ >= 255 - ROTATE_DISTANCE_COEFFICIENT) ?
255 : (ROTATE_DISTANCE_COEFFICIENT + rotateAccCoefficient_); // 255 : uint8 max value
dragDistanceX *= coeff;
} else {
dragDistanceX *= DRAG_DISTANCE_COEFFICIENT;
}
if (dragDistanceX > 0 || (dragDistanceX == 0 && dragDirection == DragEvent::DIRECTION_LEFT_TO_RIGHT)) {
dragDistanceX += GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
} else if (dragDistanceX < 0 || (dragDistanceX == 0 && dragDirection == DragEvent::DIRECTION_RIGHT_TO_LEFT)) {
dragDistanceX -= GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
if (dragDistanceX > 0 || (dragDistanceX == 0 && dragDirection == DragEvent::DIRECTION_LEFT_TO_RIGHT)) {
dragDistanceX += GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
} else if (dragDistanceX < 0 ||
(dragDistanceX == 0 && dragDirection == DragEvent::DIRECTION_RIGHT_TO_LEFT)) {
dragDistanceX -= GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
}
}
}
......
......@@ -223,6 +223,30 @@ public:
}
#if ENABLE_ROTATE_INPUT
/**
* @brief Sets coefficient for rotation dragthrow animation. The view will roll farther with larger coeffcient.
*
* @param value Indicates the coefficient to set. The default value is <b>0</b>.
* @since 1.0
* @version 1.0
*/
void SetRotateACCLevel(uint16_t value)
{
rotateAccCoefficient_ = value;
}
/**
* @brief Obtains the coefficient for rotation drag throw animation.
*
* @return Returns the coefficient for rotation drag throw animation.
* @since 1.0
* @version 1.0
*/
uint8_t GetRotateACCLevel() const
{
return rotateAccCoefficient_;
}
/**
* @brief Obtains the rotation factor.
*
......@@ -252,10 +276,10 @@ public:
}
/**
* @brief 设置触发惯性滑动的组件大小比例阈值.
* @brief Sets threshold for rotation drag throw animation. The view will roll easier with larger threshold.
*
* @param threshold Indicates the rotation factor to set.
*
* @param threshold 设置触发惯性滑动的比例阈值.
* 旋转表冠结束,如果最后一次旋转位移数值大于组件的宽或高除以threshold,则触发惯性滑动.
* @since 6
*/
void SetRotateThrowThreshold(uint8_t threshold)
......@@ -434,6 +458,7 @@ protected:
ListAnimatorCallback animatorCallback_;
Animator scrollAnimator_;
#if ENABLE_ROTATE_INPUT
uint8_t rotateAccCoefficient_ = 0;
float rotateFactor_;
int16_t rotateThrowthreshold_;
int16_t lastRotateLen_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册