Unverified Commit 0f799c3e authored by Nikolay Igotti's avatar Nikolay Igotti Committed by GitHub

Make setters more Kotlin'ish (#213)

parent 0f19f7ae
...@@ -124,9 +124,9 @@ class Renderer( ...@@ -124,9 +124,9 @@ class Renderer(
val typeface = Typeface.makeFromFile("fonts/JetBrainsMono-Regular.ttf") val typeface = Typeface.makeFromFile("fonts/JetBrainsMono-Regular.ttf")
val font = Font(typeface, 40f) val font = Font(typeface, 40f)
val paint = Paint().apply { val paint = Paint().apply {
setColor(0xff9BC730L.toInt()) color = 0xff9BC730L.toInt()
setMode(PaintMode.FILL) mode = PaintMode.FILL
setStrokeWidth(1f) strokeWidth = 1f
} }
var canvas: Canvas? = null var canvas: Canvas? = null
...@@ -165,10 +165,18 @@ private val fontCollection = FontCollection() ...@@ -165,10 +165,18 @@ private val fontCollection = FontCollection()
fun displayScene(renderer: Renderer, width: Int, height: Int, nanoTime: Long, xpos: Int, ypos: Int, state: State) { fun displayScene(renderer: Renderer, width: Int, height: Int, nanoTime: Long, xpos: Int, ypos: Int, state: State) {
val canvas = renderer.canvas!! val canvas = renderer.canvas!!
val watchFill = Paint().setColor(0xFFFFFFFF.toInt()) val watchFill = Paint().apply { color = 0xFFFFFFFF.toInt() }
val watchStroke = Paint().setColor(0xFF000000.toInt()).setMode(PaintMode.STROKE).setStrokeWidth(1f) val watchStroke = Paint().apply {
val watchStrokeAA = Paint().setColor(0xFF000000.toInt()).setMode(PaintMode.STROKE).setStrokeWidth(1f) color = 0xFF000000.toInt()
val watchFillHover = Paint().setColor(0xFFE4FF01.toInt()) mode = PaintMode.STROKE
strokeWidth = 1f
}
val watchStrokeAA = Paint().apply {
color = 0xFF000000.toInt()
mode = PaintMode.STROKE
strokeWidth = 1f
}
val watchFillHover = Paint().apply { color = 0xFFE4FF01.toInt() }
for (x in 0 .. (width - 50) step 50) { for (x in 0 .. (width - 50) step 50) {
for (y in 20 .. (height - 50) step 50) { for (y in 20 .. (height - 50) step 50) {
val hover = xpos > x + 0 && xpos < x + 50 && ypos > y + 0 && ypos < y + 50 val hover = xpos > x + 0 && xpos < x + 50 && ypos > y + 0 && ypos < y + 50
......
...@@ -89,13 +89,19 @@ class Font : Managed { ...@@ -89,13 +89,19 @@ class Font : Managed {
* *
* @return true if all glyphs are hinted * @return true if all glyphs are hinted
*/ */
val isAutoHintingForced: Boolean var isAutoHintingForced: Boolean
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
_nIsAutoHintingForced(_ptr) _nIsAutoHintingForced(_ptr)
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) = try {
Stats.onNativeCall()
_nSetAutoHintingForced(_ptr, value)
} finally {
reachabilityBarrier(this)
}
/** /**
* @return true if font engine may return glyphs from font bitmaps instead of from outlines * @return true if font engine may return glyphs from font bitmaps instead of from outlines
...@@ -112,13 +118,19 @@ class Font : Managed { ...@@ -112,13 +118,19 @@ class Font : Managed {
/** /**
* @return true if glyphs may be drawn at sub-pixel offsets * @return true if glyphs may be drawn at sub-pixel offsets
*/ */
val isSubpixel: Boolean var isSubpixel: Boolean
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
_nIsSubpixel(_ptr) _nIsSubpixel(_ptr)
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) = try {
Stats.onNativeCall()
_nSetSubpixel(_ptr, value)
} finally {
reachabilityBarrier(this)
}
/** /**
* @return true if font and glyph metrics are requested to be linearly scalable * @return true if font and glyph metrics are requested to be linearly scalable
...@@ -138,13 +150,19 @@ class Font : Managed { ...@@ -138,13 +150,19 @@ class Font : Managed {
* *
* @return true if bold is approximated through stroke width * @return true if bold is approximated through stroke width
*/ */
val isEmboldened: Boolean var isEmboldened: Boolean
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
_nIsEmboldened(_ptr) _nIsEmboldened(_ptr)
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) = try {
Stats.onNativeCall()
_nSetEmboldened(_ptr, value)
} finally {
reachabilityBarrier(this)
}
/** /**
* Returns true if baselines will be snapped to pixel positions when the current transformation * Returns true if baselines will be snapped to pixel positions when the current transformation
...@@ -152,130 +170,53 @@ class Font : Managed { ...@@ -152,130 +170,53 @@ class Font : Managed {
* *
* @return true if baselines may be snapped to pixels * @return true if baselines may be snapped to pixels
*/ */
val isBaselineSnapped: Boolean var isBaselineSnapped: Boolean
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
_nIsBaselineSnapped(_ptr) _nIsBaselineSnapped(_ptr)
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) = try {
/** Stats.onNativeCall()
* Sets whether to always hint glyphs. If forceAutoHinting is set, instructs the font manager to always hint glyphs. Only affects platforms that use FreeType as the font manager. _nSetBaselineSnapped(_ptr, value)
* } finally {
* @param value setting to always hint glyphs reachabilityBarrier(this)
* @return this }
*/
fun setAutoHintingForced(value: Boolean): Font {
Stats.onNativeCall()
_nSetAutoHintingForced(_ptr, value)
return this
}
/**
* Requests, but does not require, to use bitmaps in fonts instead of outlines.
*
* @param value setting to use bitmaps in fonts
* @return this
*/
fun setBitmapsEmbedded(value: Boolean): Font {
Stats.onNativeCall()
_nSetBitmapsEmbedded(_ptr, value)
return this
}
/**
* Requests, but does not require, that glyphs respect sub-pixel positioning.
*
* @param value setting for sub-pixel positioning
* @return this
*/
fun setSubpixel(value: Boolean): Font {
Stats.onNativeCall()
_nSetSubpixel(_ptr, value)
return this
}
/**
* Requests, but does not require, linearly scalable font and glyph metrics.
*
* For outline fonts 'true' means font and glyph metrics should ignore hinting and rounding.
* Note that some bitmap formats may not be able to scale linearly and will ignore this flag.
*
* @param value setting for linearly scalable font and glyph metrics.
* @return this
*/
fun setMetricsLinear(value: Boolean): Font {
Stats.onNativeCall()
_nSetMetricsLinear(_ptr, value)
return this
}
/**
* Increases stroke width when creating glyph bitmaps to approximate a bold typeface.
*
* @param value setting for bold approximation
* @return this
*/
fun setEmboldened(value: Boolean): Font {
Stats.onNativeCall()
_nSetEmboldened(_ptr, value)
return this
}
/**
* Requests that baselines be snapped to pixels when the current transformation matrix is axis
* aligned.
*
* @param value setting for baseline snapping to pixels
* @return this
*/
fun setBaselineSnapped(value: Boolean): Font {
Stats.onNativeCall()
_nSetBaselineSnapped(_ptr, value)
return this
}
/** /**
* Whether edge pixels draw opaque or with partial transparency. * Whether edge pixels draw opaque or with partial transparency.
*/ */
val edging: FontEdging var edging: FontEdging
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
FontEdging.values().get(_nGetEdging(_ptr)) FontEdging.values().get(_nGetEdging(_ptr))
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) = try {
/** Stats.onNativeCall()
* Requests, but does not require, that edge pixels draw opaque or with _nSetEdging(_ptr, value.ordinal)
* partial transparency. } finally {
*/ reachabilityBarrier(this)
fun setEdging(value: FontEdging): Font { }
Stats.onNativeCall()
_nSetEdging(_ptr, value.ordinal)
return this
}
/** /**
* @return level of glyph outline adjustment * @return level of glyph outline adjustment
*/ */
val hinting: FontHinting var hinting: FontHinting
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
FontHinting.values().get(_nGetHinting(_ptr)) FontHinting.values().get(_nGetHinting(_ptr))
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) = try {
/** Stats.onNativeCall()
* Sets level of glyph outline adjustment. Does not check for valid values of hintingLevel. _nSetHinting(_ptr, value.ordinal)
*/ } finally {
fun setHinting(value: FontHinting): Font { reachabilityBarrier(this)
Stats.onNativeCall() }
_nSetHinting(_ptr, value.ordinal)
return this
}
/** /**
* Returns a font with the same attributes of this font, but with the specified size. * Returns a font with the same attributes of this font, but with the specified size.
...@@ -310,35 +251,54 @@ class Font : Managed { ...@@ -310,35 +251,54 @@ class Font : Managed {
/** /**
* @return text size in points * @return text size in points
*/ */
val size: Float var size: Float
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
Font_nGetSize(_ptr) Font_nGetSize(_ptr)
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) = try {
Stats.onNativeCall()
_nSetSize(_ptr, value)
} finally {
reachabilityBarrier(this)
}
/** /**
* @return text scale on x-axis. Default value is 1 * @return text scale on x-axis. Default value is 1
*/ */
val scaleX: Float var scaleX: Float
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
_nGetScaleX(_ptr) _nGetScaleX(_ptr)
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) = try {
Stats.onNativeCall()
_nSetScaleX(_ptr, value)
} finally {
reachabilityBarrier(this)
}
/** /**
* @return text skew on x-axis. Default value is 0 * @return text skew on x-axis. Default value is 0
*/ */
val skewX: Float var skewX: Float
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
_nGetSkewX(_ptr) _nGetSkewX(_ptr)
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) = try {
Stats.onNativeCall()
_nSetSkewX(_ptr, value)
} finally {
reachabilityBarrier(this)
}
/** /**
* Sets Typeface to typeface. Pass null to use the default typeface. * Sets Typeface to typeface. Pass null to use the default typeface.
...@@ -356,33 +316,6 @@ class Font : Managed { ...@@ -356,33 +316,6 @@ class Font : Managed {
} }
} }
/**
* Sets text size in points. Has no effect if value is not greater than or equal to zero.
*/
fun setSize(value: Float): Font {
Stats.onNativeCall()
_nSetSize(_ptr, value)
return this
}
/**
* Sets text scale on x-axis. Default value is 1.
*/
fun setScaleX(value: Float): Font {
Stats.onNativeCall()
_nSetScaleX(_ptr, value)
return this
}
/**
* Sets text skew on x-axis. Default value is 0.
*/
fun setSkewX(value: Float): Font {
Stats.onNativeCall()
_nSetSkewX(_ptr, value)
return this
}
/** /**
* Converts text into glyph indices. * Converts text into glyph indices.
* *
......
...@@ -90,20 +90,12 @@ class Paint : Managed { ...@@ -90,20 +90,12 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setAntiAlias(value) Stats.onNativeCall()
_nSetAntiAlias(_ptr, value)
} finally {
reachabilityBarrier(this)
} }
/**
* Requests, but does not require, that edge pixels draw opaque or with partial transparency.
*
* @param value setting for antialiasing
*/
fun setAntiAlias(value: Boolean): Paint {
Stats.onNativeCall()
_nSetAntiAlias(_ptr, value)
return this
}
/** /**
* Requests, but does not require, to distribute color error. * Requests, but does not require, to distribute color error.
...@@ -117,22 +109,13 @@ class Paint : Managed { ...@@ -117,22 +109,13 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setDither(value) Stats.onNativeCall()
_nSetDither(_ptr, value)
} finally {
reachabilityBarrier(this)
} }
/**
* Requests, but does not require, to distribute color error.
*
* @param value setting for ditering
* @return this
*/
fun setDither(value: Boolean): Paint {
Stats.onNativeCall()
_nSetDither(_ptr, value)
return this
}
/** /**
* Sets whether the geometry is filled, stroked, or filled and stroked. * Sets whether the geometry is filled, stroked, or filled and stroked.
* *
...@@ -149,23 +132,13 @@ class Paint : Managed { ...@@ -149,23 +132,13 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setMode(value) Stats.onNativeCall()
_nSetMode(_ptr, value.ordinal)
} finally {
reachabilityBarrier(this)
} }
/**
* Sets whether the geometry is filled, stroked, or filled and stroked.
*
* @see [https://fiddle.skia.org/c/@Paint_setStyle](https://fiddle.skia.org/c/@Paint_setStyle)
*
* @see [https://fiddle.skia.org/c/@Stroke_Width](https://fiddle.skia.org/c/@Stroke_Width)
*/
fun setMode(style: PaintMode): Paint {
Stats.onNativeCall()
_nSetMode(_ptr, style.ordinal)
return this
}
/** /**
* Set paint's mode to STROKE if true, or FILL if false. * Set paint's mode to STROKE if true, or FILL if false.
* *
...@@ -196,24 +169,13 @@ class Paint : Managed { ...@@ -196,24 +169,13 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setColor(value) Stats.onNativeCall()
_nSetColor(_ptr, value)
} finally {
reachabilityBarrier(this)
} }
/**
* Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
* unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
*
* @param color unpremultiplied ARGB
*
* @see [https://fiddle.skia.org/c/@Paint_setColor](https://fiddle.skia.org/c/@Paint_setColor)
*/
fun setColor(color: Int): Paint {
Stats.onNativeCall()
_nSetColor(_ptr, color)
return this
}
/** /**
* Sets alpha and RGB used when stroking and filling. The color is four floating * Sets alpha and RGB used when stroking and filling. The color is four floating
* point values, unpremultiplied. The color values are interpreted as being in sRGB. * point values, unpremultiplied. The color values are interpreted as being in sRGB.
...@@ -231,19 +193,8 @@ class Paint : Managed { ...@@ -231,19 +193,8 @@ class Paint : Managed {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) {
setColor4f(value) setColor4f(value, null)
} }
/**
* Sets alpha and RGB used when stroking and filling. The color is four floating
* point values, unpremultiplied. The color values are interpreted as being in sRGB.
*
* @param color unpremultiplied RGBA
* @return this
*/
fun setColor4f(color: Color4f): Paint {
return setColor4f(color, null)
}
/** /**
* Sets alpha and RGB used when stroking and filling. The color is four floating * Sets alpha and RGB used when stroking and filling. The color is four floating
...@@ -285,8 +236,9 @@ class Paint : Managed { ...@@ -285,8 +236,9 @@ class Paint : Managed {
* *
* @return alpha ranging from 0, fully transparent, to 255, fully opaque * @return alpha ranging from 0, fully transparent, to 255, fully opaque
*/ */
val alpha: Int var alpha: Int
get() = round(alphaf * 255f).toInt() get() = round(alphaf * 255f).toInt()
set(value) { setAlphaf(value / 255f) }
/** /**
* *
...@@ -305,22 +257,6 @@ class Paint : Managed { ...@@ -305,22 +257,6 @@ class Paint : Managed {
return this return this
} }
/**
*
* Replaces alpha, leaving RGB unchanged. An out of range value triggers
* an assert in the debug build. a is a value from 0 to 255.
*
*
* a set to zero makes color fully transparent; a set to 255 makes color
* fully opaque.
*
* @param a alpha component of color
* @return this
*/
fun setAlpha(a: Int): Paint {
return setAlphaf(a / 255f)
}
/** /**
* Sets color used when drawing solid fills. The color components range from 0 to 255. * Sets color used when drawing solid fills. The color components range from 0 to 255.
* The color is unpremultiplied; alpha sets the transparency independent of RGB. * The color is unpremultiplied; alpha sets the transparency independent of RGB.
...@@ -359,27 +295,13 @@ class Paint : Managed { ...@@ -359,27 +295,13 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setStrokeWidth(value) Stats.onNativeCall()
_nSetStrokeWidth(_ptr, value)
} finally {
reachabilityBarrier(this)
} }
/**
* Sets the thickness of the pen used by the paint to outline the shape.
* A stroke-width of zero is treated as "hairline" width. Hairlines are always exactly one
* pixel wide in device space (their thickness does not change as the canvas is scaled).
* Negative stroke-widths are invalid; setting a negative width will have no effect.
*
* @param width zero thickness for hairline; greater than zero for pen thickness
*
* @see [https://fiddle.skia.org/c/@Miter_Limit](https://fiddle.skia.org/c/@Miter_Limit)
*
* @see [https://fiddle.skia.org/c/@Paint_setStrokeWidth](https://fiddle.skia.org/c/@Paint_setStrokeWidth)
*/
fun setStrokeWidth(width: Float): Paint {
Stats.onNativeCall()
_nSetStrokeWidth(_ptr, width)
return this
}
/** /**
* Sets the limit at which a sharp corner is drawn beveled. * Sets the limit at which a sharp corner is drawn beveled.
...@@ -399,25 +321,13 @@ class Paint : Managed { ...@@ -399,25 +321,13 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setStrokeMiter(value) Stats.onNativeCall()
_nSetStrokeMiter(_ptr, value)
} finally {
reachabilityBarrier(this)
} }
/**
* Sets the limit at which a sharp corner is drawn beveled.
* Valid values are zero and greater.
* Has no effect if miter is less than zero.
*
* @param miter zero and greater miter limit
* @return this
*
* @see [https://fiddle.skia.org/c/@Paint_setStrokeMiter](https://fiddle.skia.org/c/@Paint_setStrokeMiter)
*/
fun setStrokeMiter(miter: Float): Paint {
Stats.onNativeCall()
_nSetStrokeMiter(_ptr, miter)
return this
}
/** /**
* Sets the geometry drawn at the beginning and end of strokes. * Sets the geometry drawn at the beginning and end of strokes.
...@@ -435,26 +345,13 @@ class Paint : Managed { ...@@ -435,26 +345,13 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setStrokeCap(value) Stats.onNativeCall()
_nSetStrokeCap(_ptr, value.ordinal)
} finally {
reachabilityBarrier(this)
} }
/**
* Sets the geometry drawn at the beginning and end of strokes.
*
* @return this
*
* @see [https://fiddle.skia.org/c/@Paint_setStrokeCap_a](https://fiddle.skia.org/c/@Paint_setStrokeCap_a)
*
* @see [https://fiddle.skia.org/c/@Paint_setStrokeCap_b](https://fiddle.skia.org/c/@Paint_setStrokeCap_b)
*/
fun setStrokeCap(cap: PaintStrokeCap): Paint {
Stats.onNativeCall()
_nSetStrokeCap(_ptr, cap.ordinal)
return this
}
/** /**
* Sets the geometry drawn at the corners of strokes. * Sets the geometry drawn at the corners of strokes.
* *
...@@ -469,23 +366,13 @@ class Paint : Managed { ...@@ -469,23 +366,13 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setStrokeJoin(value) Stats.onNativeCall()
_nSetStrokeJoin(_ptr, value.ordinal)
} finally {
reachabilityBarrier(this)
} }
/**
* Sets the geometry drawn at the corners of strokes.
*
* @return this
*
* @see [https://fiddle.skia.org/c/@Paint_setStrokeJoin](https://fiddle.skia.org/c/@Paint_setStrokeJoin)
*/
fun setStrokeJoin(join: PaintStrokeJoin): Paint {
Stats.onNativeCall()
_nSetStrokeJoin(_ptr, join.ordinal)
return this
}
/** /**
* Returns the filled equivalent of the stroked path. * Returns the filled equivalent of the stroked path.
* *
...@@ -549,26 +436,13 @@ class Paint : Managed { ...@@ -549,26 +436,13 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setShader(value)
}
/**
* @param shader how geometry is filled with color; if null, color is used instead
*
* @see [https://fiddle.skia.org/c/@Color_Filter_Methods](https://fiddle.skia.org/c/@Color_Filter_Methods)
*
* @see [https://fiddle.skia.org/c/@Paint_setShader](https://fiddle.skia.org/c/@Paint_setShader)
*/
fun setShader(shader: Shader?): Paint {
return try {
Stats.onNativeCall() Stats.onNativeCall()
_nSetShader(_ptr, getPtr(shader)) _nSetShader(_ptr, getPtr(value))
this
} finally { } finally {
reachabilityBarrier(shader) reachabilityBarrier(value)
reachabilityBarrier(this)
} }
}
/** /**
* @param colorFilter [ColorFilter] to apply to subsequent draw * @param colorFilter [ColorFilter] to apply to subsequent draw
...@@ -588,29 +462,16 @@ class Paint : Managed { ...@@ -588,29 +462,16 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setColorFilter(value)
}
/**
* @param colorFilter [ColorFilter] to apply to subsequent draw
*
* @see [https://fiddle.skia.org/c/@Blend_Mode_Methods](https://fiddle.skia.org/c/@Blend_Mode_Methods)
*
* @see [https://fiddle.skia.org/c/@Paint_setColorFilter](https://fiddle.skia.org/c/@Paint_setColorFilter)
*/
fun setColorFilter(colorFilter: ColorFilter?): Paint {
return try {
Stats.onNativeCall() Stats.onNativeCall()
_nSetColorFilter( _nSetColorFilter(
_ptr, _ptr,
getPtr(colorFilter) getPtr(value)
) )
this
} finally { } finally {
reachabilityBarrier(colorFilter) reachabilityBarrier(this)
reachabilityBarrier(value)
} }
}
/** /**
* Sets SkBlendMode to mode. Does not check for valid input. * Sets SkBlendMode to mode. Does not check for valid input.
...@@ -627,22 +488,13 @@ class Paint : Managed { ...@@ -627,22 +488,13 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setBlendMode(value) Stats.onNativeCall()
_nSetBlendMode(_ptr, value.ordinal)
} finally {
reachabilityBarrier(this)
} }
/**
* Sets SkBlendMode to mode. Does not check for valid input.
*
* @param mode BlendMode used to combine source color and destination
* @return this
*/
fun setBlendMode(mode: BlendMode): Paint {
Stats.onNativeCall()
_nSetBlendMode(_ptr, mode.ordinal)
return this
}
/** /**
* @return true if BlendMode is BlendMode.SRC_OVER, the default. * @return true if BlendMode is BlendMode.SRC_OVER, the default.
*/ */
...@@ -667,27 +519,13 @@ class Paint : Managed { ...@@ -667,27 +519,13 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setPathEffect(value)
}
/**
* @param p replace [Path] with a modification when drawn
*
* @see [https://fiddle.skia.org/c/@Mask_Filter_Methods](https://fiddle.skia.org/c/@Mask_Filter_Methods)
*
* @see [https://fiddle.skia.org/c/@Paint_setPathEffect](https://fiddle.skia.org/c/@Paint_setPathEffect)
*/
fun setPathEffect(p: PathEffect?): Paint {
return try {
Stats.onNativeCall() Stats.onNativeCall()
_nSetPathEffect(_ptr, getPtr(p)) _nSetPathEffect(_ptr, getPtr(value))
this
} finally { } finally {
reachabilityBarrier(p) reachabilityBarrier(this)
reachabilityBarrier(value)
} }
}
/** /**
* maskFilter modifies clipping mask generated from drawn geometry * maskFilter modifies clipping mask generated from drawn geometry
...@@ -707,30 +545,16 @@ class Paint : Managed { ...@@ -707,30 +545,16 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setMaskFilter(value)
}
/**
* @param maskFilter modifies clipping mask generated from drawn geometry
* @return this
*
* @see [https://fiddle.skia.org/c/@Paint_setMaskFilter](https://fiddle.skia.org/c/@Paint_setMaskFilter)
*
* @see [https://fiddle.skia.org/c/@Typeface_Methods](https://fiddle.skia.org/c/@Typeface_Methods)
*/
fun setMaskFilter(maskFilter: MaskFilter?): Paint {
return try {
Stats.onNativeCall() Stats.onNativeCall()
_nSetMaskFilter( _nSetMaskFilter(
_ptr, _ptr,
getPtr(maskFilter) getPtr(value)
) )
this
} finally { } finally {
reachabilityBarrier(maskFilter) reachabilityBarrier(this)
reachabilityBarrier(value)
} }
}
/** /**
* imageFilter how SkImage is sampled when transformed * imageFilter how SkImage is sampled when transformed
...@@ -750,29 +574,16 @@ class Paint : Managed { ...@@ -750,29 +574,16 @@ class Paint : Managed {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setImageFilter(value)
}
/**
* @param imageFilter how SkImage is sampled when transformed
*
* @see [https://fiddle.skia.org/c/@Draw_Looper_Methods](https://fiddle.skia.org/c/@Draw_Looper_Methods)
*
* @see [https://fiddle.skia.org/c/@Paint_setImageFilter](https://fiddle.skia.org/c/@Paint_setImageFilter)
*/
fun setImageFilter(imageFilter: ImageFilter?): Paint {
return try {
Stats.onNativeCall() Stats.onNativeCall()
_nSetImageFilter( _nSetImageFilter(
_ptr, _ptr,
getPtr(imageFilter) getPtr(value)
) )
this
} finally { } finally {
reachabilityBarrier(imageFilter) reachabilityBarrier(this)
reachabilityBarrier(value)
} }
}
/** /**
* *
...@@ -797,7 +608,6 @@ class Paint : Managed { ...@@ -797,7 +608,6 @@ class Paint : Managed {
} }
} }
@ExternalSymbolName("org_jetbrains_skia_Paint__1nGetFinalizer") @ExternalSymbolName("org_jetbrains_skia_Paint__1nGetFinalizer")
private external fun Paint_nGetFinalizer(): NativePointer private external fun Paint_nGetFinalizer(): NativePointer
......
...@@ -224,7 +224,7 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol ...@@ -224,7 +224,7 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol
* @param other Path to compare * @param other Path to compare
* @return true if this and Path are equivalent * @return true if this and Path are equivalent
*/ */
override fun _nativeEquals(other: Native?): Boolean { override fun _nativeEquals(other: Native?): Boolean {
return try { return try {
Path_nEquals(_ptr, getPtr(other)) Path_nEquals(_ptr, getPtr(other))
} finally { } finally {
...@@ -309,15 +309,12 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol ...@@ -309,15 +309,12 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setFillMode(value) Stats.onNativeCall()
_nSetFillMode(_ptr, value.ordinal)
} finally {
reachabilityBarrier(this)
} }
fun setFillMode(fillMode: PathFillMode): Path {
Stats.onNativeCall()
_nSetFillMode(_ptr, fillMode.ordinal)
return this
}
/** /**
* Returns true if the path is convex. If necessary, it will first compute the convexity. * Returns true if the path is convex. If necessary, it will first compute the convexity.
...@@ -482,9 +479,11 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol ...@@ -482,9 +479,11 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
Stats.onNativeCall() Stats.onNativeCall()
Path_nSetVolatile(_ptr, value) Path_nSetVolatile(_ptr, value)
} finally {
reachabilityBarrier(this)
} }
/** /**
...@@ -1919,13 +1918,16 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol ...@@ -1919,13 +1918,16 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol
* *
* @see [https://fiddle.skia.org/c/@Path_getLastPt](https://fiddle.skia.org/c/@Path_getLastPt) * @see [https://fiddle.skia.org/c/@Path_getLastPt](https://fiddle.skia.org/c/@Path_getLastPt)
*/ */
val lastPt: Point var lastPt: Point
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
_nGetLastPt(_ptr) _nGetLastPt(_ptr)
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) {
setLastPt(value.x, value.y)
}
/** /**
* Sets last point to (x, y). If Point array is empty, append [PathVerb.MOVE] to * Sets last point to (x, y). If Point array is empty, append [PathVerb.MOVE] to
...@@ -1943,17 +1945,6 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol ...@@ -1943,17 +1945,6 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol
return this return this
} }
/**
* Sets the last point on the path. If Point array is empty, append [PathVerb.MOVE] to
* verb array and append p to Point array.
*
* @param p set value of last point
* @return this
*/
fun setLastPt(p: Point): Path {
return setLastPt(p.x, p.y)
}
/** /**
* *
* Returns a mask, where each set bit corresponds to a SegmentMask constant * Returns a mask, where each set bit corresponds to a SegmentMask constant
......
...@@ -34,19 +34,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) { ...@@ -34,19 +34,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setStrutStyle(value)
}
fun setStrutStyle(s: StrutStyle?): ParagraphStyle {
return try {
Stats.onNativeCall() Stats.onNativeCall()
_nSetStrutStyle(_ptr, getPtr(s)) _nSetStrutStyle(_ptr, getPtr(value))
this
} finally { } finally {
reachabilityBarrier(s) reachabilityBarrier(this)
reachabilityBarrier(value)
} }
}
var textStyle: TextStyle var textStyle: TextStyle
get() = try { get() = try {
...@@ -55,19 +49,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) { ...@@ -55,19 +49,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setTextStyle(value)
}
fun setTextStyle(style: TextStyle?): ParagraphStyle {
return try {
Stats.onNativeCall() Stats.onNativeCall()
_nSetTextStyle(_ptr, getPtr(style)) _nSetTextStyle(_ptr, getPtr(value))
this
} finally { } finally {
reachabilityBarrier(style) reachabilityBarrier(value)
reachabilityBarrier(this)
} }
}
var direction: Direction var direction: Direction
get() = try { get() = try {
...@@ -76,15 +64,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) { ...@@ -76,15 +64,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setDirection(value) Stats.onNativeCall()
_nSetDirection(_ptr, value.ordinal)
} finally {
reachabilityBarrier(this)
} }
fun setDirection(style: Direction): ParagraphStyle {
Stats.onNativeCall()
_nSetDirection(_ptr, style.ordinal)
return this
}
var alignment: Alignment var alignment: Alignment
get() = try { get() = try {
...@@ -93,16 +79,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) { ...@@ -93,16 +79,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setAlignment(value) Stats.onNativeCall()
_nSetAlignment(_ptr, value.ordinal)
} finally {
reachabilityBarrier(this)
} }
fun setAlignment(alignment: Alignment): ParagraphStyle {
Stats.onNativeCall()
_nSetAlignment(_ptr, alignment.ordinal)
return this
}
var maxLinesCount: Int var maxLinesCount: Int
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
...@@ -110,16 +93,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) { ...@@ -110,16 +93,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setMaxLinesCount(value) Stats.onNativeCall()
_nSetMaxLinesCount(_ptr, value)
} finally {
reachabilityBarrier(this)
} }
fun setMaxLinesCount(count: Int): ParagraphStyle {
Stats.onNativeCall()
_nSetMaxLinesCount(_ptr, count)
return this
}
var ellipsis: String var ellipsis: String
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
...@@ -127,16 +107,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) { ...@@ -127,16 +107,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setEllipsis(value) Stats.onNativeCall()
_nSetEllipsis(_ptr, value)
} finally {
reachabilityBarrier(this)
} }
fun setEllipsis(ellipsis: String?): ParagraphStyle {
Stats.onNativeCall()
_nSetEllipsis(_ptr, ellipsis)
return this
}
var height: Float var height: Float
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
...@@ -144,15 +121,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) { ...@@ -144,15 +121,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setHeight(value) Stats.onNativeCall()
_nSetHeight(_ptr, value)
} finally {
reachabilityBarrier(this)
} }
fun setHeight(height: Float): ParagraphStyle {
Stats.onNativeCall()
_nSetHeight(_ptr, height)
return this
}
var heightMode: HeightMode var heightMode: HeightMode
get() = try { get() = try {
...@@ -161,16 +136,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) { ...@@ -161,16 +136,13 @@ class ParagraphStyle : Managed(ParagraphStyle_nMake(), _FinalizerHolder.PTR) {
} finally { } finally {
reachabilityBarrier(this) reachabilityBarrier(this)
} }
set(value) { set(value) = try {
setHeightMode(value) Stats.onNativeCall()
_nSetHeightMode(_ptr, value.ordinal)
} finally {
reachabilityBarrier(this)
} }
fun setHeightMode(behavior: HeightMode): ParagraphStyle {
Stats.onNativeCall()
_nSetHeightMode(_ptr, behavior.ordinal)
return this
}
val effectiveAlignment: Alignment val effectiveAlignment: Alignment
get() = try { get() = try {
Stats.onNativeCall() Stats.onNativeCall()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment