Skip to content

Instantly share code, notes, and snippets.

@hoc081098
Last active May 2, 2023 08:34
Show Gist options
  • Save hoc081098/cd8a596d6df9311676f566e75169c75e to your computer and use it in GitHub Desktop.
Save hoc081098/cd8a596d6df9311676f566e75169c75e to your computer and use it in GitHub Desktop.
class MyEffectPreviewView : GLView {
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
private var index = 0
private var bitmaps: List<Bitmap> = emptyList()
override fun onGLDraw(canvas: ICanvasGL) {
val bitmaps = this.bitmaps
val index = this.index
bitmaps.getOrNull(index)?.let { bitmap ->
canvas.drawBitmap(
bitmap,
0,
0,
bitmap.width,
bitmap.height,
)
}
this.index = if (bitmaps.isEmpty()) {
0
} else {
(index + 1) % bitmaps.size
}
}
fun setBitmaps(bitmaps: List<Bitmap>) {
queueEvent {
this.index = 0
this.bitmaps = bitmaps
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment