mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 11:46:32 +00:00
Scales up quest pixel art in party details
Introduces a forceScaleUp option to PixelArtView, used for gifs on the party details.
This commit is contained in:
parent
2955c4e020
commit
98c1098b86
2 changed files with 14 additions and 9 deletions
|
|
@ -285,6 +285,7 @@ class PartyDetailFragment : BaseFragment<FragmentPartyDetailBinding>() {
|
|||
binding?.questTitleView?.text = questContent.text
|
||||
binding?.questScrollImageView?.loadImage("inventory_quest_scroll_" + questContent.key)
|
||||
if (questContent.hasGifImage()) {
|
||||
binding?.questImageView?.forceScaleUp = true
|
||||
binding?.questImageView?.loadImage("quest_" + questContent.key, "gif")
|
||||
} else {
|
||||
context?.let { context ->
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ constructor(
|
|||
defStyleAttr: Int = 0
|
||||
) : androidx.appcompat.widget.AppCompatImageView(context, attrs, defStyleAttr) {
|
||||
private var targetRect = Rect(0, 0, 0, 0)
|
||||
var forceScaleUp: Boolean = false
|
||||
|
||||
var bitmap: Bitmap? = null
|
||||
set(value) {
|
||||
|
|
@ -44,22 +45,24 @@ constructor(
|
|||
private fun updateTargetRect() {
|
||||
var targetWidth = bitmap?.width ?: 0
|
||||
var targetHeight = bitmap?.height ?: 0
|
||||
val smallestSide = min(width, height)
|
||||
val divisor = if (targetWidth % 3 == 0 && targetHeight % 3 == 0) 3 else 2
|
||||
val smallestSide = if (forceScaleUp) width else min(width, height)
|
||||
val divisor = if (forceScaleUp) 1 else if (targetWidth % 3 == 0 && targetHeight % 3 == 0) 3 else 2
|
||||
|
||||
val factor =
|
||||
val factor = if (forceScaleUp) {
|
||||
if (smallestSide > 0 && targetWidth > 0) {
|
||||
(smallestSide.toFloat() / (targetWidth.toFloat() / divisor)).toInt().coerceAtLeast(1)
|
||||
} else 1
|
||||
} else {
|
||||
min(
|
||||
if (smallestSide > 0 && targetWidth > 0 && smallestSide != targetWidth) {
|
||||
smallestSide / (targetWidth / divisor)
|
||||
} else {
|
||||
1
|
||||
},
|
||||
} else 1,
|
||||
if (smallestSide > 0 && targetHeight > 0 && smallestSide != targetHeight) {
|
||||
smallestSide / (targetHeight / divisor)
|
||||
} else {
|
||||
1
|
||||
}
|
||||
} else 1
|
||||
)
|
||||
}
|
||||
|
||||
targetWidth = (targetWidth / divisor) * factor
|
||||
targetHeight = (targetHeight / divisor) * factor
|
||||
val left = (width - targetWidth) / 2
|
||||
|
|
@ -67,6 +70,7 @@ constructor(
|
|||
targetRect = Rect(left, top, left + targetWidth, top + targetHeight)
|
||||
}
|
||||
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
if (bitmap == null) {
|
||||
super.onDraw(canvas)
|
||||
|
|
|
|||
Loading…
Reference in a new issue