13
13
import android .view .MotionEvent ;
14
14
import android .view .View ;
15
15
16
- import junit .framework .Assert ;
17
-
18
16
import java .util .HashMap ;
19
17
import java .util .List ;
20
18
import java .util .Map ;
30
28
import cn .hzw .doodle .core .IDoodleTouchDetector ;
31
29
32
30
import static cn .hzw .doodle .util .DrawUtil .drawCircle ;
31
+ import static cn .hzw .doodle .util .DrawUtil .drawRect ;
33
32
import static cn .hzw .doodle .util .DrawUtil .rotatePoint ;
34
33
35
34
/**
@@ -79,11 +78,12 @@ public class DoodleView extends View implements IDoodle {
79
78
80
79
private float mTouchX , mTouchY ;
81
80
private boolean mEnableZoomer = false ; // 放大镜功能
81
+ private boolean mEnableOverview = true ; // 全图预览功能,建立在放大镜功能开启的前提下
82
82
private float mLastZoomerY ;
83
83
private float mZoomerRadius ;
84
84
private Path mZoomerPath ;
85
85
private float mZoomerScale = 0 ; // 放大镜的倍数
86
- private Paint mZooomerPaint ;
86
+ private Paint mZooomerPaint , mZoomerTouchPaint ;
87
87
private int mZoomerHorizonX ; // 放大器的位置的x坐标,使其水平居中
88
88
private boolean mIsScrollingDoodle = false ; // 是否正在滑动,只要用于标志触摸时才显示放大镜
89
89
@@ -139,6 +139,12 @@ public DoodleView(Context context, Bitmap bitmap, IDoodleListener listener, IDoo
139
139
mZooomerPaint .setStrokeCap (Paint .Cap .ROUND );// 圆滑
140
140
mZooomerPaint .setStrokeWidth (Util .dp2px (getContext (), 10 ));
141
141
142
+ mZoomerTouchPaint = new Paint ();
143
+ mZoomerTouchPaint .setStyle (Paint .Style .STROKE );
144
+ mZoomerTouchPaint .setAntiAlias (true );
145
+ mZoomerTouchPaint .setStrokeJoin (Paint .Join .ROUND );
146
+ mZoomerTouchPaint .setStrokeCap (Paint .Cap .ROUND );// 圆滑
147
+
142
148
mDefaultTouchDetector = defaultDetector ;
143
149
144
150
mInner = new DoodleViewInner ();
@@ -311,7 +317,9 @@ protected void dispatchDraw(Canvas canvas) {
311
317
if (mIsScrollingDoodle && mEnableZoomer && mZoomerScale > 0 ) { //启用放大镜
312
318
canvas .save ();
313
319
314
- if (mTouchY <= mZoomerRadius * 2 ) { // 在放大镜的范围内, 把放大镜仿制底部
320
+ float unitSize = getUnitSize ();
321
+
322
+ if (mTouchY <= mZoomerRadius * 2 ) { // 在放大镜的范围内, 把放大镜放在底部
315
323
mLastZoomerY = getHeight () - mZoomerRadius * 2 ;
316
324
} else if (mTouchY >= getHeight () - mZoomerRadius * 2 ) {
317
325
mLastZoomerY = 0 ;
@@ -327,11 +335,52 @@ protected void dispatchDraw(Canvas canvas) {
327
335
// draw inner
328
336
canvas .rotate (mDoodleRotateDegree , getWidth () / 2 , getHeight () / 2 );
329
337
mInner .onDraw (canvas );
338
+
339
+ // 触摸点
340
+ float left = getAllTranX ();
341
+ float top = getAllTranY ();
342
+ // 画布和图片共用一个坐标系,只需要处理屏幕坐标系到图片(画布)坐标系的映射关系
343
+ canvas .translate (left , top ); // 偏移画布
344
+ scale = getAllScale ();
345
+ canvas .scale (scale , scale ); // 缩放画布
346
+ mZoomerTouchPaint .setStrokeWidth (getUnitSize ());
347
+ mZoomerTouchPaint .setColor (0xaa000000 );
348
+ drawCircle (canvas , toX (mTouchX ), toY (mTouchY ), mSize / 2 , mZoomerTouchPaint );
349
+ mZoomerTouchPaint .setColor (0xaaffffff );
350
+ drawCircle (canvas , toX (mTouchX ), toY (mTouchY ), mSize / 2 - unitSize / 4 , mZoomerTouchPaint );
351
+
330
352
canvas .restore ();
331
353
332
354
// 画放大器的边框
333
355
drawCircle (canvas , mZoomerRadius , mZoomerRadius , mZoomerRadius , mZooomerPaint );
334
356
canvas .restore ();
357
+
358
+ // overview
359
+ canvas .save ();
360
+ canvas .translate (mZoomerHorizonX , mLastZoomerY );
361
+ scale = (mZoomerRadius / 2 ) / getWidth ();
362
+ canvas .scale (scale , scale );
363
+ float strokeWidth = 1 / scale ;
364
+ canvas .clipRect (-strokeWidth , -strokeWidth , getWidth () + strokeWidth , getHeight () + strokeWidth );
365
+ canvas .drawColor (0x88888888 );
366
+ canvas .save ();
367
+ canvas .rotate (mDoodleRotateDegree , getWidth () / 2 , getHeight () / 2 );
368
+ float tempScale = mScale ;
369
+ float tempTransX = mTransX ;
370
+ float tempTransY = mTransY ;
371
+ mScale = 1 ;
372
+ mTransX = mTransY = 0 ;
373
+ mInner .onDraw (canvas );
374
+ mScale = tempScale ;
375
+ mTransX = tempTransX ;
376
+ mTransY = tempTransY ;
377
+ canvas .restore ();
378
+ mZoomerTouchPaint .setStrokeWidth (strokeWidth );
379
+ mZoomerTouchPaint .setColor (0xaa000000 );
380
+ drawRect (canvas , 0 , 0 , getWidth (), getHeight (), mZoomerTouchPaint );
381
+ mZoomerTouchPaint .setColor (0xaaffffff );
382
+ drawRect (canvas , strokeWidth , strokeWidth , getWidth () - strokeWidth , getHeight () - strokeWidth , mZoomerTouchPaint );
383
+ canvas .restore ();
335
384
}
336
385
337
386
}
@@ -837,6 +886,22 @@ public boolean isEnableZoomer() {
837
886
return mEnableZoomer ;
838
887
}
839
888
889
+ /**
890
+ * 设置是否开启全图预览功能,开启后可以在放大镜功能下显示全图涂鸦
891
+ * @param enableOverview
892
+ */
893
+ public void enableOverview (boolean enableOverview ) {
894
+ mEnableOverview = enableOverview ;
895
+ }
896
+
897
+ /**
898
+ * 是否开启全图预览功能
899
+ * @return
900
+ */
901
+ public boolean isEnableOverview () {
902
+ return mEnableOverview ;
903
+ }
904
+
840
905
/**
841
906
* 是否正在滚动涂鸦,只要用于标志触摸时才显示放大镜
842
907
*
0 commit comments