Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
carrotech
doodle
提交
8e993fc8
D
doodle
项目概览
carrotech
/
doodle
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
doodle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8e993fc8
编写于
10月 14, 2016
作者:
forward123_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
去掉了mPathStackBackup
上级
3aa08acd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
36 deletion
+39
-36
GraffitiLib/src/main/java/cn/hzw/graffiti/GraffitiView.java
GraffitiLib/src/main/java/cn/hzw/graffiti/GraffitiView.java
+39
-36
未找到文件。
GraffitiLib/src/main/java/cn/hzw/graffiti/GraffitiView.java
浏览文件 @
8e993fc8
...
...
@@ -18,7 +18,6 @@ import cn.forward.androids.utils.ThreadUtil;
/**
* Created by huangziwei on 2016/9/3.
*
*/
public
class
GraffitiView
extends
View
{
...
...
@@ -49,7 +48,7 @@ public class GraffitiView extends View {
private
float
mPaintSize
;
private
GraffitiColor
mColor
;
// 画笔底色
private
float
mScale
;
// 缩放倍数, 图片真实的缩放倍数为 mPrivateScale*mScale
private
float
mTransX
=
0
,
mTransY
=
0
;
private
float
mTransX
=
0
,
mTransY
=
0
;
// 偏移量,图片真实偏移量为 mCentreTranX + mTransX
private
boolean
mIsPainting
=
false
;
// 是否正在绘制
private
boolean
isJustDrawOriginal
;
// 是否只绘制原图
...
...
@@ -57,7 +56,7 @@ public class GraffitiView extends View {
// 保存涂鸦操作,便于撤销
private
CopyOnWriteArrayList
<
GraffitiPath
>
mPathStack
=
new
CopyOnWriteArrayList
<
GraffitiPath
>();
private
CopyOnWriteArrayList
<
GraffitiPath
>
p
athStackBackup
=
new
CopyOnWriteArrayList
<
GraffitiPath
>();
// private CopyOnWriteArrayList<GraffitiPath> mP
athStackBackup = new CopyOnWriteArrayList<GraffitiPath>();
/**
* 画笔
...
...
@@ -143,11 +142,6 @@ public class GraffitiView extends View {
mTouchX
+=
VALUE
;
// 为了仅点击时也能出现绘图,模拟滑动一个像素点
mTouchY
+=
VALUE
;
if
(
mPathStack
.
size
()
>
3
)
{
// 当前栈大于3,则拷贝到备份栈
pathStackBackup
.
addAll
(
mPathStack
);
mPathStack
.
clear
();
}
if
(
mPen
==
Pen
.
COPY
&&
mCopyLocation
.
isInIt
(
toX4C
(
mTouchX
),
toY4C
(
mTouchY
)))
{
// 点击copy
mCopyLocation
.
isRelocating
=
true
;
mCopyLocation
.
isCopying
=
false
;
...
...
@@ -198,6 +192,8 @@ public class GraffitiView extends View {
mCopyLocation
.
mCopyStartY
+
toY4C
(
mTouchY
)
-
mCopyLocation
.
mTouchStartY
);
}
GraffitiPath
path
=
null
;
// 把操作记录到加入的堆栈中
if
(
mShape
==
Shape
.
HAND_WRITE
)
{
// 手写
mCurrPath
.
quadTo
(
...
...
@@ -205,13 +201,14 @@ public class GraffitiView extends View {
toY
(
mLastTouchY
),
toX
((
mTouchX
+
mLastTouchX
)
/
2
),
toY
((
mTouchY
+
mLastTouchY
)
/
2
));
mPathStack
.
add
(
GraffitiPath
.
toPath
(
mPen
,
mShape
,
mPaintSize
,
mColor
.
copy
(),
mCurrPath
,
mPen
==
Pen
.
COPY
?
new
Matrix
(
mShaderMatrix
)
:
null
)
);
path
=
GraffitiPath
.
toPath
(
mPen
,
mShape
,
mPaintSize
,
mColor
.
copy
(),
mCurrPath
,
mPen
==
Pen
.
COPY
?
new
Matrix
(
mShaderMatrix
)
:
null
);
}
else
{
// 画图形
mPathStack
.
add
(
GraffitiPath
.
toShape
(
mPen
,
mShape
,
mPaintSize
,
mColor
.
copy
(),
path
=
GraffitiPath
.
toShape
(
mPen
,
mShape
,
mPaintSize
,
mColor
.
copy
(),
toX
(
mTouchDownX
),
toY
(
mTouchDownY
),
toX
(
mTouchX
),
toY
(
mTouchY
),
mPen
==
Pen
.
COPY
?
new
Matrix
(
mShaderMatrix
)
:
null
)
)
;
mPen
==
Pen
.
COPY
?
new
Matrix
(
mShaderMatrix
)
:
null
);
}
draw
(
mBitmapCanvas
,
mPathStack
,
false
);
// 保存到图片中
mPathStack
.
add
(
path
);
draw
(
mBitmapCanvas
,
path
,
false
);
// 保存到图片中
mIsPainting
=
false
;
}
}
...
...
@@ -364,13 +361,17 @@ public class GraffitiView extends View {
private
void
draw
(
Canvas
canvas
,
CopyOnWriteArrayList
<
GraffitiPath
>
pathStack
,
boolean
is4Canvas
)
{
// 还原堆栈中的记录的操作
for
(
GraffitiPath
path
:
pathStack
)
{
mPaint
.
setStrokeWidth
(
path
.
mStrokeWidth
);
if
(
path
.
mShape
==
Shape
.
HAND_WRITE
)
{
// 手写
draw
(
canvas
,
path
.
mPen
,
mPaint
,
path
.
mPath
,
path
.
mMatrix
,
is4Canvas
,
path
.
mColor
);
}
else
{
// 画图形
draw
(
canvas
,
path
.
mPen
,
path
.
mShape
,
mPaint
,
path
.
mSx
,
path
.
mSy
,
path
.
mDx
,
path
.
mDy
,
path
.
mMatrix
,
is4Canvas
,
path
.
mColor
);
}
draw
(
canvas
,
path
,
is4Canvas
);
}
}
private
void
draw
(
Canvas
canvas
,
GraffitiPath
path
,
boolean
is4Canvas
)
{
mPaint
.
setStrokeWidth
(
path
.
mStrokeWidth
);
if
(
path
.
mShape
==
Shape
.
HAND_WRITE
)
{
// 手写
draw
(
canvas
,
path
.
mPen
,
mPaint
,
path
.
mPath
,
path
.
mMatrix
,
is4Canvas
,
path
.
mColor
);
}
else
{
// 画图形
draw
(
canvas
,
path
.
mPen
,
path
.
mShape
,
mPaint
,
path
.
mSx
,
path
.
mSy
,
path
.
mDx
,
path
.
mDy
,
path
.
mMatrix
,
is4Canvas
,
path
.
mColor
);
}
}
...
...
@@ -421,6 +422,7 @@ public class GraffitiView extends View {
/**
* 坐标换算
* (公式由toX()中的公式推算出)
*
* @param touchX 触摸坐标
* @param graffitiX 在涂鸦图片中的坐标
* @return 偏移量
...
...
@@ -448,13 +450,14 @@ public class GraffitiView extends View {
}
private
static
class
GraffitiPath
{
Pen
mPen
;
Shape
mShape
;
float
mStrokeWidth
;
GraffitiColor
mColor
;
Path
mPath
;
float
mSx
,
mSy
,
mDx
,
mDy
;
Matrix
mMatrix
;
Pen
mPen
;
// 画笔类型
Shape
mShape
;
// 画笔形状
float
mStrokeWidth
;
// 大小
GraffitiColor
mColor
;
// 颜色
Path
mPath
;
// 画笔的路径
float
mSx
,
mSy
;
// 起始坐标(手指点击)
float
mDx
,
mDy
;
// 终止坐标(手指触摸)
Matrix
mMatrix
;
// 仿制图片的偏移矩阵
static
GraffitiPath
toShape
(
Pen
pen
,
Shape
shape
,
float
width
,
GraffitiColor
color
,
float
sx
,
float
sy
,
float
dx
,
float
dy
,
Matrix
matrix
)
{
...
...
@@ -555,7 +558,6 @@ public class GraffitiView extends View {
}
/**
*
* 仿制的定位器
*/
private
class
CopyLocation
{
...
...
@@ -719,7 +721,7 @@ public class GraffitiView extends View {
*/
public
void
save
()
{
// initCanvas();
// draw(mBitmapCanvas,
p
athStackBackup, false);
// draw(mBitmapCanvas,
mP
athStackBackup, false);
// draw(mBitmapCanvas, mPathStack, false);
mGraffitiListener
.
onSaved
(
mGraffitiBitmap
);
}
...
...
@@ -729,7 +731,7 @@ public class GraffitiView extends View {
*/
public
void
clear
()
{
mPathStack
.
clear
();
p
athStackBackup
.
clear
();
// mP
athStackBackup.clear();
initCanvas
();
invalidate
();
}
...
...
@@ -741,14 +743,8 @@ public class GraffitiView extends View {
if
(
mPathStack
.
size
()
>
0
)
{
mPathStack
.
remove
(
mPathStack
.
size
()
-
1
);
initCanvas
();
draw
(
mBitmapCanvas
,
pathStackBackup
,
false
);
draw
(
mBitmapCanvas
,
mPathStack
,
false
);
invalidate
();
}
else
if
(
pathStackBackup
.
size
()
>
0
)
{
pathStackBackup
.
remove
(
pathStackBackup
.
size
()
-
1
);
initCanvas
();
draw
(
mBitmapCanvas
,
pathStackBackup
,
false
);
invalidate
();
}
}
...
...
@@ -756,7 +752,7 @@ public class GraffitiView extends View {
* 是否有修改
*/
public
boolean
isModified
()
{
return
mPathStack
.
size
()
!=
0
||
pathStackBackup
.
size
()
!=
0
;
return
mPathStack
.
size
()
!=
0
;
}
/**
...
...
@@ -825,6 +821,7 @@ public class GraffitiView extends View {
/**
* 设置画笔底色
*
* @param color
*/
public
void
setColor
(
int
color
)
{
...
...
@@ -854,6 +851,7 @@ public class GraffitiView extends View {
/**
* 缩放倍数,图片真实的缩放倍数为 mPrivateScale*mScale
*
* @param scale
*/
public
void
setScale
(
float
scale
)
{
...
...
@@ -869,6 +867,7 @@ public class GraffitiView extends View {
/**
* 设置画笔
*
* @param pen
*/
public
void
setPen
(
Pen
pen
)
{
...
...
@@ -886,6 +885,7 @@ public class GraffitiView extends View {
/**
* 设置画笔形状
*
* @param shape
*/
public
void
setShape
(
Shape
shape
)
{
...
...
@@ -910,6 +910,7 @@ public class GraffitiView extends View {
/**
* 设置图片偏移
*
* @param transX
*/
public
void
setTransX
(
float
transX
)
{
...
...
@@ -946,12 +947,14 @@ public class GraffitiView extends View {
/**
* 保存图片
*
* @param bitmap
*/
void
onSaved
(
Bitmap
bitmap
);
/**
* 出错
*
* @param i
* @param msg
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录