mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-01-27 16:05:32 +00:00
Merge branch 'main' into ui/home_screen
This commit is contained in:
commit
5d996edc1e
@ -31,17 +31,20 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import com.github.nacabaro.vbhelper.utils.getObscuredBitmap
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
@Composable
|
||||
fun CharacterEntry(
|
||||
icon: BitmapData,
|
||||
obscure: Boolean = false,
|
||||
modifier: Modifier = Modifier,
|
||||
shape: Shape = MaterialTheme.shapes.medium,
|
||||
multiplier: Int = 3,
|
||||
onClick: () -> Unit = { }
|
||||
) {
|
||||
val bitmap = remember (icon.bitmap) {
|
||||
icon.getBitmap()
|
||||
if(obscure) icon.getObscuredBitmap() else icon.getBitmap()
|
||||
}
|
||||
val imageBitmap = remember(bitmap) { bitmap.asImageBitmap() }
|
||||
val density: Float = LocalContext.current.resources.displayMetrics.density
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.github.nacabaro.vbhelper.screens
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
@ -54,6 +55,7 @@ fun DiMScreen(
|
||||
items(characterList.value) { character ->
|
||||
CharacterEntry(
|
||||
onClick = { },
|
||||
obscure = true,
|
||||
icon = BitmapData(
|
||||
bitmap = character.sprite1,
|
||||
width = character.spritesWidth,
|
||||
|
||||
@ -14,6 +14,30 @@ fun BitmapData.getBitmap(): Bitmap {
|
||||
return Bitmap.createBitmap(createARGBIntArray(), this.width, this.height, Bitmap.Config.HARDWARE)
|
||||
}
|
||||
|
||||
object ARGBMasks {
|
||||
const val ALPHA = (0xFF shl 24)
|
||||
const val RED = (0xFF shl 16)
|
||||
const val GREEN = (0xFF shl 8)
|
||||
const val BLUE = 0xFF
|
||||
|
||||
}
|
||||
|
||||
const val BLACK = ARGBMasks.ALPHA
|
||||
|
||||
fun BitmapData.getObscuredBitmap(): Bitmap {
|
||||
val argbPixels = createARGBIntArray()
|
||||
for(i in argbPixels.indices) {
|
||||
val currentPixel = argbPixels[i]
|
||||
if( currentPixel and ARGBMasks.ALPHA != 0) {
|
||||
// non transparent pixel
|
||||
argbPixels[i] = BLACK
|
||||
}
|
||||
}
|
||||
return Bitmap.createBitmap(argbPixels, this.width, this.height, Bitmap.Config.HARDWARE)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun BitmapData.createARGBIntArray(): IntArray {
|
||||
// hack to get it into correct format by relying on the DIM Sprites methods since we haven't changed the raw pixel data at this point.
|
||||
val bytes = SpriteData.Sprite.builder().width(this.width).height(this.height).pixelData(this.bitmap).build()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user