Optimized drawing
This commit is contained in:
parent
2f15a6f625
commit
be85e92397
4 changed files with 27 additions and 14 deletions
8
.idea/deploymentTargetSelector.xml
generated
8
.idea/deploymentTargetSelector.xml
generated
|
|
@ -4,6 +4,14 @@
|
|||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2025-08-08T10:50:02.571721922Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="LocalEmulator" identifier="path=/home/secondbeam/.android/avd/Pixel_3.avd" />
|
||||
</handle>
|
||||
</Target>
|
||||
</DropdownSelection>
|
||||
<DialogSelection />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
</component>
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.KtHeightMap"
|
||||
tools:targetApi="31">
|
||||
<profileable android:shell="true" />
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.KtHeightMap">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ fun MapCanvas(
|
|||
tileContainer: TileContainer,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val offsetX = rememberSaveable { mutableFloatStateOf(0F) }
|
||||
val offsetY = rememberSaveable { mutableFloatStateOf(0F) }
|
||||
val offsetX = rememberSaveable { mutableFloatStateOf(-TILE_SIZE) }
|
||||
val offsetY = rememberSaveable { mutableFloatStateOf(-TILE_SIZE) }
|
||||
val textMeasurer = rememberTextMeasurer()
|
||||
Canvas(
|
||||
modifier = modifier.fillMaxSize()
|
||||
|
|
@ -50,15 +50,15 @@ fun MapCanvas(
|
|||
val level = scale.floatValue.toInt()
|
||||
|
||||
if (oldLevel > level) {
|
||||
offsetX.floatValue -= size.width / 2F
|
||||
offsetY.floatValue -= size.height / 2F
|
||||
offsetX.floatValue -= size.width / 2F + TILE_SIZE
|
||||
offsetY.floatValue -= size.height / 2F + TILE_SIZE
|
||||
offsetX.floatValue /= 2F
|
||||
offsetY.floatValue /= 2F
|
||||
} else if (oldLevel < level) {
|
||||
offsetX.floatValue *= 2F
|
||||
offsetY.floatValue *= 2F
|
||||
offsetX.floatValue += size.width / 2F
|
||||
offsetY.floatValue += size.height / 2F
|
||||
offsetX.floatValue += size.width / 2F + TILE_SIZE
|
||||
offsetY.floatValue += size.height / 2F + TILE_SIZE
|
||||
}
|
||||
val tileOffsetX = (offsetX.floatValue / TILE_SIZE).toInt()
|
||||
val tileOffsetY = (offsetY.floatValue / TILE_SIZE).toInt()
|
||||
|
|
@ -82,7 +82,7 @@ fun MapCanvas(
|
|||
val tileY = tileOffsetY + cellY
|
||||
val localOffsetY = TILE_SIZE * (cellY - 1)
|
||||
|
||||
val bitmap = tiles.find { it.x == tileX && it.y == tileY && it.level == level }?.getBitmap()
|
||||
val bitmap = tiles.find { it.x == tileX && it.y == tileY && it.level == level }?.toBitmap()
|
||||
|
||||
bitmap?.let {
|
||||
val imageBitmap = bitmap.asImageBitmap()
|
||||
|
|
@ -91,7 +91,7 @@ fun MapCanvas(
|
|||
topLeft = Offset(localOffsetX, localOffsetY) - offset
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
drawRect(
|
||||
color = gridColor,
|
||||
size = Size(TILE_SIZE, TILE_SIZE),
|
||||
|
|
@ -111,6 +111,7 @@ fun MapCanvas(
|
|||
topLeft = Offset(localOffsetX, localOffsetY) - offset,
|
||||
size = Size(TILE_SIZE, TILE_SIZE)
|
||||
)
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.graphics.Bitmap
|
|||
import android.graphics.BitmapFactory
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Ignore
|
||||
import java.util.Base64
|
||||
|
||||
@Entity(tableName = "tiles", primaryKeys = [ "x", "y", "level" ])
|
||||
|
|
@ -20,6 +21,9 @@ class Tile {
|
|||
@ColumnInfo(name = "data")
|
||||
var base64: String? = null
|
||||
|
||||
@Ignore
|
||||
var bitmap: Bitmap? = null
|
||||
|
||||
constructor()
|
||||
|
||||
constructor(x: Int, y: Int, level: Int) {
|
||||
|
|
@ -35,11 +39,11 @@ class Tile {
|
|||
this.base64 = base64
|
||||
}
|
||||
|
||||
fun getBitmap(): Bitmap? {
|
||||
if (this.base64 == null)
|
||||
return null
|
||||
fun toBitmap(): Bitmap? {
|
||||
if (bitmap != null || base64 == null)
|
||||
return bitmap
|
||||
val ba = Base64.getDecoder().decode(this.base64)
|
||||
val bmp = BitmapFactory.decodeByteArray(ba, 0, ba.size)
|
||||
return bmp
|
||||
bitmap = BitmapFactory.decodeByteArray(ba, 0, ba.size)
|
||||
return bitmap
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue