Skip to main content

墨水操作

矢量和光栅墨水操控的处理方式各不相同。 矢量操控修改生成的几何图形,而光栅擦除器仅“覆盖”笔划。

Raster Ink

目前的光栅墨水仅提供部分擦除器功能。

橡皮擦

擦除器被配置为一种类似于刷子的工具。 它使用特定的模糊模式BlendMode.DESTINATION_OUT覆盖笔划,以达到擦除的目的。

import com.wacom.ink.Calculator
import com.wacom.ink.PathPoint
import com.wacom.ink.PathPointLayout
import com.wacom.ink.rendering.BlendMode
...

class EraserRasterTool(context: Context) : RasterTool(context) {

companion object {
val uri = URIBuilder.getToolURI("raster", "eraser")
}

override var brush = BrushPalette.eraser(context)

override fun getLayout(): PathPointLayout {
return PathPointLayout(
PathPoint.Property.X,
PathPoint.Property.Y,
PathPoint.Property.SIZE,
PathPoint.Property.RED,
PathPoint.Property.GREEN,
PathPoint.Property.BLUE,
PathPoint.Property.ALPHA
)
}

override val touchCalculator: Calculator = { previous, current, next ->
// Use the following to compute size based on speed:
var size = current.computeValueBasedOnSpeed(
previous,
next,
minValue = 8f,
maxValue = 112f,
minSpeed = 720f,
maxSpeed = 3900f
)
if (size == null) size = 8f

PathPoint(current.x, current.y, size = size,
red = 1f, green = 1f, blue = 1f, alpha = 1f)
}

override val stylusCalculator: Calculator = { previous, current, next ->
// Use the following to compute size based on speed:
var size = current.computeValueBasedOnSpeed(
previous,
next,
minValue = 8f,
maxValue = 112f,
minSpeed = 720f,
maxSpeed = 3900f
)
if (size == null) size = 8f

PathPoint(current.x, current.y, size = size,
red = 1f, green = 1f, blue = 1f, alpha = 1f)
}

override fun getBlendMode(): BlendMode {
return BlendMode.DESTINATION_OUT
}

}

**注意:**笔划并未从模型中擦除,仅是被覆盖了。

Vector Ink

矢量墨水提供更多的笔划操控功能:

  • 部分笔划擦除器
  • 完整笔划擦除器
  • 操控选项

部分擦除 / 分割

擦除器工具的工作原理与刷子工具类似。 因此需要定义它的计算器。 可在此确定擦除器宽度是否随压力或速度而改变。 还可定义不同手指或触控笔输入行为。

class EraserVectorTool : VectorTool() {

companion object {
val uri = "tool@erase_vector"
}

override var brush = BrushPalette.circle()

override fun getLayout(): PathPointLayout {
return PathPointLayout(
PathPoint.Property.X,
PathPoint.Property.Y,
PathPoint.Property.SIZE,
PathPoint.Property.RED,
PathPoint.Property.GREEN,
PathPoint.Property.BLUE
)
}

override var drawingMode = DrawingMode.ERASING_PARTIAL_STROKE

override val touchCalculator: Calculator = { previous, current, next ->
// Use the following to compute size based on speed:
var size = current.computeValueBasedOnSpeed(
previous,
next,
minValue = 8f,
maxValue = 112f,
minSpeed = 720f,
maxSpeed = 3900f
)
if (size == null) size = 1.0f
PathPoint(current.x, current.y, size = size, red = 1f, green = 1f, blue = 1f, alpha = 0.5f)
}

override val stylusCalculator: Calculator = { previous, current, next ->
// Use the following to compute size based on speed:
var size = current.computeValueBasedOnSpeed(
previous,
next,
minValue = 8f,
maxValue = 112f,
minSpeed = 720f,
maxSpeed = 3900f
)
if (size == null) size = 1.0f
PathPoint(current.x, current.y, size = size, red = 1f, green = 1f, blue = 1f)
}
}

完整笔划橡皮擦


class EraserWholeStrokeTool : VectorTool() {

companion object {
val uri = URIBuilder.getToolURI("vector", "eraser_whole_stroke")
}

override var brush = BrushPalette.basic()

override fun getLayout(): PathPointLayout {
return PathPointLayout(
PathPoint.Property.X,
PathPoint.Property.Y,
PathPoint.Property.SIZE
)
}

override var drawingMode = DrawingMode.ERASING_WHOLE_STROKE

override val touchCalculator: Calculator = { previous, current, next ->
//Use the following to compute size based on speed:
PathPoint(current.x, current.y, size = 3f)
}

override val stylusCalculator: Calculator = { previous, current, next ->
//Use the following to compute size based on speed:
PathPoint(current.x, current.y, size = 3f)
}
}

选择

如果需要通过下列操作操控墨水笔划:

  • 平移
  • 旋转
  • 缩放

您很可能会使用套框工具选择笔划的一部分或全部。 而使用这项技术,我们对部分选择笔划和完整选择笔划作了区分。

部分选择

还是一样,我们需要定义工具。

class SelectorPartialStrokeTool : VectorTool() {

companion object {
val uri = "tool@selector_parcial_stroke"
}

override var brush = BrushPalette.basic()

override fun getLayout(): PathPointLayout {
return PathPointLayout(
PathPoint.Property.X,
PathPoint.Property.Y,
PathPoint.Property.SIZE,
PathPoint.Property.RED,
PathPoint.Property.GREEN,
PathPoint.Property.BLUE
)
}

override var drawingMode = DrawingMode.SELECTING_PARTIAL_STROKE

override val touchCalculator: Calculator = { previous, current, next ->
// Use the following to compute size based on speed:
PathPoint(current.x, current.y, size = 3f, red = 1f, green = 1f, blue = 1f)
}

override val stylusCalculator: Calculator = { previous, current, next ->
// Use the following to compute size based on speed:
PathPoint(current.x, current.y, size = 3f, red = 1f, green = 1f, blue = 1f)
}
}

完整笔划选择器

class SelectorWholeStrokeTool : VectorTool() {

companion object {
val uri = "tool@selector_whole_stroke"
}

override var brush = BrushPalette.basic()

override fun getLayout(): PathPointLayout {
return PathPointLayout(
PathPoint.Property.X,
PathPoint.Property.Y,
PathPoint.Property.SIZE,
PathPoint.Property.RED,
PathPoint.Property.GREEN,
PathPoint.Property.BLUE
)
}

override var drawingMode = DrawingMode.SELECTING_WHOLE_STROKE

override val touchCalculator: Calculator = { previous, current, next ->
//Use the following to compute size based on speed:
PathPoint(current.x, current.y, size = 3f, red = 1f, green = 1f, blue = 1f)
}

override val stylusCalculator: Calculator = { previous, current, next ->
//Use the following to compute size based on speed:
PathPoint(current.x, current.y, size = 3f, red = 1f, green = 1f, blue = 1f)
}
}