Last active
May 2, 2023 08:34
-
-
Save hoc081098/cd8a596d6df9311676f566e75169c75e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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