Skip to content

Commit

Permalink
Merge pull request #1853 from dep5/slow_scroll
Browse files Browse the repository at this point in the history
マウスドラッグ時のスクロール速度を制限する
  • Loading branch information
berryzplus authored Jul 7, 2022
2 parents 75e1a56 + fa524e8 commit 2d51a13
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions sakura_core/view/CCaret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,38 @@ CLayoutInt CCaret::MoveCursor(
}
// To Here 2007.07.28 じゅうじ
if( bScroll ){
if( abs( (Int)nScrollRowNum ) < 7 &&
( m_pEditView->GetSelectionInfo().IsMouseSelecting() || m_pEditView->m_bDragMode )){
struct ScrollRowRecord{
Int nScrollRowNum;
DWORD dwTime;
};
static std::array<ScrollRowRecord, 512> s_records{};
static size_t s_recordPos = 0;
DWORD dwNow = GetTickCount();
Int nScrollRowsPerTiming = 0;
DWORD dwPerTiming = 80;
if( nScrollRowNum > 0 && m_pEditView->m_bDragMode ){
dwPerTiming = 30;
}

std::for_each(s_records.begin(), s_records.end(),
[ dwNow, dwPerTiming, &nScrollRowsPerTiming ]( ScrollRowRecord rec ){
if( ( dwNow - rec.dwTime ) <= dwPerTiming ){
nScrollRowsPerTiming += rec.nScrollRowNum;
}
});
if( abs( nScrollRowsPerTiming ) >= 1 ){
nScrollRowNum = 0;
}
auto& rec = s_records[s_recordPos];
rec.dwTime = dwNow;
rec.nScrollRowNum = nScrollRowNum;
++s_recordPos;
if( s_recordPos >= s_records.size() ){
s_recordPos = 0;
}
}
/* スクロール */
if( t_abs( nScrollColNum ) >= m_pEditView->GetTextArea().m_nViewColNum ||
t_abs( nScrollRowNum ) >= m_pEditView->GetTextArea().m_nViewRowNum ){
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/view/CEditView_Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ void CEditView::OnMOUSEMOVE( WPARAM fwKeys, int xPos_, int yPos_ )
}
}
}else{
GetCaret().MoveCursorToClientPoint( ptMouse, true, &ptNewCursor );
GetCaret().MoveCursorToClientPoint( ptMouse, false, &ptNewCursor );
}
GetSelectionInfo().m_ptMouseRollPosOld = ptMouse; // マウス範囲選択前回位置(XY座標)

Expand Down

0 comments on commit 2d51a13

Please sign in to comment.