@@ -21,7 +21,7 @@ public class CursorDrawer extends BaseDrawer {
2121 private int cursorColor ;// 光标颜色 没有设置时默认黑色
2222 private Paint cursorPaint ;
2323
24- public CursorDrawer (boolean showCursor , int cursorDuration , int cursorWidth , int cursorHeight ,int cursorColor ) {
24+ public CursorDrawer (boolean showCursor , int cursorDuration , int cursorWidth , int cursorHeight , int cursorColor ) {
2525 this .showCursor = showCursor ;
2626 this .cursorDuration = cursorDuration ;
2727 this .cursorWidth = cursorWidth ;
@@ -45,30 +45,40 @@ public void setFocused(boolean isFocused) {
4545
4646 @ Override
4747 public void drawCanvas () {
48+ drawCursor ();
49+ }
50+
4851
52+ private void drawCursorLine () {
53+ Rect rect = blockRects .get (currentBlockIndex );
54+ int startX = rect .centerX () - cursorWidth / 2 ;
55+ int endX = startX ;
56+ int padding = Math .max ((rect .height () - cursorHeight ) / 2 , 0 );
57+
58+ int startY = padding ;
59+ int endY = startY + cursorHeight ;
60+ canvas .drawLine (startX , startY , endX , endY , cursorPaint );
4961 }
5062
63+ private void clearCursor () {
64+ clearCanvas (canvas );
65+ }
5166
5267 public void drawCursor () {
5368 if (!showCursor ) { // 不显示光标
54- clearCanvas ( canvas );
69+ clearCursor ( );
5570 return ;
5671 }
5772 if (!isFocused ()) { // 失去焦点
58- clearCanvas ( canvas );
73+ clearCursor ( );
5974 return ;
6075 }
6176 if (currentBlockIndex >= blockRects .size ()) { // 已经输入完成
62- clearCanvas ( canvas );
77+ clearCursor ( );
6378 return ;
6479 }
6580 clearCanvas (canvas );
66- Rect rect = blockRects .get (currentBlockIndex );
67- int startX = rect .centerX () - cursorWidth / 2 ;
68- int endX = startX ;
69- int startY = rect .centerY () - (rect .bottom - rect .top ) / 6 ;
70- int endY = rect .centerY () + (rect .bottom - rect .top ) / 6 ;
71- canvas .drawLine (startX , startY , endX , endY , cursorPaint );
81+ drawCursorLine ();
7282 }
7383
7484 public void cancelCursor () {
0 commit comments