Skip to content

Commit

Permalink
add: overlay and portrait backgrounds
Browse files Browse the repository at this point in the history
Signed-off-by: Syahriel Ibnu Irfansyah <[email protected]>
  • Loading branch information
EmiyaSyahriel committed Feb 25, 2024
1 parent e96e668 commit 1157043
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 41 deletions.
40 changes: 39 additions & 1 deletion launcher_app/src/main/java/id/psw/vshlauncher/types/CifLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class CifLoader {
private val _animIconSync = Object()
private val _backdropSync = Object()
private val _portBackdropSync = Object()
private val _backdropOverlaySync = Object()
private val _portBackdropOverlaySync = Object()
private val _backSoundSync = Object()
private lateinit var vsh : Vsh
private var root = ArrayList<File>()
Expand Down Expand Up @@ -119,7 +121,9 @@ class CifLoader {
val hasAnimIconLoaded get() = _hasAnimIconLoaded
val hasBackSoundLoaded get() = _backSound.exists()
val hasBackdropLoaded get() = _backdrop.isLoaded
val hasBackdropOverlayLoaded get() = _backOverlay.isLoaded
val hasPortBackdropLoaded get() = _portBackdrop.isLoaded
val hasPortBackdropOverlayLoaded get() = _portBackOverlay.isLoaded
private fun <K> MutableMap<File, Ref<K>>.getOrMake(k:File, refDefVal:K) = getOrMake<File, Ref<K>>(k){ Ref<K>(refDefVal) }
private fun ArrayList<File>.checkAnyExists() : Boolean = any { it.delayedExistenceCheck(ioc.getOrMake(it, 0), ios.getOrMake(it, false)) }
val hasBackdrop : Boolean get() = !disableBackdrop && backdropFiles.checkAnyExists()
Expand Down Expand Up @@ -198,13 +202,47 @@ class CifLoader {
val f = backdropFiles.find {
it.exists()
}
if(f != null) BitmapFactory.decodeFile(f.absolutePath)else null
if(f != null) BitmapFactory.decodeFile(f.absolutePath) else null

})

_backOverlay = BitmapRef("${itemId}_backdropOverlay", {
val f = backdropOverlayFiles.find {
it.exists()
}

if(f != null) BitmapFactory.decodeFile(f.absolutePath) else null
})

_portBackdrop = BitmapRef("${itemId}_backdrop_p", {
val f = portraitBackdropFiles.find {
it.exists()
}
if(f != null) BitmapFactory.decodeFile(f.absolutePath) else null

})

_portBackOverlay = BitmapRef("${itemId}_backdropOverlay_p", {
val f = portraitBackdropOverlayFiles.find {
it.exists()
}

if(f != null) BitmapFactory.decodeFile(f.absolutePath) else null
})
}

fun unloadBackdrop(){
if(_backdrop.id != default_bitmap.id) _backdrop.release()
_backdrop = default_bitmap

if(_portBackdrop.id != default_bitmap.id) _portBackdrop.release()
_portBackdrop = default_bitmap

if(_backOverlay.id != default_bitmap.id) _backOverlay.release()
_backOverlay = default_bitmap

if(_portBackOverlay.id != default_bitmap.id) _portBackOverlay.release()
_portBackOverlay = default_bitmap
}

fun loadSound(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ open class XmbItem(private val vsh: Vsh) {
open val animatedIcon : XmbFrameAnimation get() = XmbItem.TRANSPARENT_ANIM_BITMAP
open val backdrop : Bitmap get() = XmbItem.TRANSPARENT_BITMAP
open val portraitBackdrop : Bitmap get() = XmbItem.TRANSPARENT_BITMAP
open val backdropOverlay : Bitmap get() = XmbItem.TRANSPARENT_BITMAP
open val portraitBackdropOverlay : Bitmap get() = XmbItem.TRANSPARENT_BITMAP
open val backSound : File get() = SILENT_AUDIO

open val menuItems : ArrayList<XmbMenuItem>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,41 @@ class XmbAppItem(private val vsh: Vsh, val resInfo : ResolveInfo) : XmbItem(vsh)

private val cif = CifLoader(vsh, resInfo, FileQuery(VshBaseDirs.APPS_DIR).withNames(resInfo.uniqueActivityName).execute(vsh))

// Icon
override val hasIcon: Boolean get()= true
override val isIconLoaded: Boolean get()= cif.icon.isLoaded
override val icon: Bitmap get()= cif.icon.bitmap

// Animated Icon
override val hasAnimatedIcon: Boolean get() = cif.hasAnimatedIcon
override val isAnimatedIconLoaded: Boolean get() = cif.hasAnimIconLoaded
override val animatedIcon: XmbFrameAnimation get() = synchronized(cif.animIcon) { cif.animIcon }

// BGM
override val hasBackSound: Boolean get() = cif.hasBackSound
override val isBackSoundLoaded: Boolean get() = cif.hasBackSoundLoaded
override val isBackdropLoaded: Boolean get() = cif.hasBackdropLoaded
override val isPortraitBackdropLoaded: Boolean get() = cif.hasPortBackdropLoaded
override val backSound: File get() = cif.backSound

override val hasIcon: Boolean get()= true
// Backdrop
override val hasBackdrop: Boolean get() = cif.hasBackdrop
override val hasPortraitBackdrop: Boolean get() = cif.hasPortraitBackdrop
override val isBackdropLoaded: Boolean get() = cif.hasBackdropLoaded
override val backdrop: Bitmap get() = cif.backdrop.bitmap

// Backdrop Overlay
override val hasBackOverlay: Boolean get() = cif.hasBackOverlay
override val isBackdropOverlayLoaded: Boolean get() = cif.hasBackdropOverlayLoaded
override val backdropOverlay: Bitmap get() = cif.backOverlay.bitmap

// Backdrop Portrait
override val hasPortraitBackdrop: Boolean get() = cif.hasPortraitBackdrop
override val isPortraitBackdropLoaded: Boolean get() = cif.hasPortBackdropLoaded
override val portraitBackdrop: Bitmap get() = cif.portBackdrop.bitmap

// Backdrop Overlay Portrait
override val hasPortraitBackdropOverlay: Boolean get() = cif.hasPortraitBackdropOverlay
override val hasBackSound: Boolean get() = cif.hasBackSound
override val hasAnimatedIcon: Boolean get() = cif.hasAnimatedIcon
override val isPortraitBackdropOverlayLoaded: Boolean get() = cif.hasPortBackdropOverlayLoaded
override val portraitBackdropOverlay: Bitmap get() = cif.portBackOverlay.bitmap

private var iniFile = IniFile()

override val hasMenu: Boolean get() = true
Expand Down Expand Up @@ -133,10 +155,6 @@ class XmbAppItem(private val vsh: Vsh, val resInfo : ResolveInfo) : XmbItem(vsh)
override val id: String get()= iconId
override val description: String get()= displayedDescription
override val displayName: String get()= _customAppLabel.isEmpty().select(appLabel, _customAppLabel)
override val icon: Bitmap get()= cif.icon.bitmap
override val backdrop: Bitmap get() = cif.backdrop.bitmap
override val backSound: File get() = cif.backSound
override val animatedIcon: XmbFrameAnimation get() = synchronized(cif.animIcon) { cif.animIcon }
override val hasDescription: Boolean get() = description.isNotEmpty()
override val menuItems: ArrayList<XmbMenuItem> = arrayListOf()
private var apkFile : File? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,37 +159,34 @@ class XmbMainMenu(view : XmbView) : XmbScreen(view) {

private fun drawBackground(ctx:Canvas){

// statusFillPaint.color = FColor.setAlpha(Color.BLACK, 0.25f)
// ctx.drawRect(scaling.target, statusFillPaint)
if(verticalMenu.showBackdrop){
val isPortrait = scaling.screen.height() > scaling.screen.width()
val activeItem = vsh.items?.visibleItems?.find{it.id == context.vsh.selectedItemId}
var isChanged = false
val opa = dimOpacity / 10.0f

if(verticalMenu.showBackdrop && activeItem != null){
try{
val activeItem = vsh.items?.visibleItems?.find{it.id == context.vsh.selectedItemId}
if(activeItem != null){
context.vsh.itemBackdropAlphaTime =context.vsh.itemBackdropAlphaTime.coerceIn(0f, 1f)
backgroundPaint.alpha = (context.vsh.itemBackdropAlphaTime * 255).roundToInt().coerceIn(0, 255)
val opa = dimOpacity / 10.0f
if((scaling.screen.height() > scaling.screen.width()) && activeItem.hasPortraitBackdrop){
if(activeItem.isPortraitBackdropLoaded){
ctx.drawBitmap(
activeItem.portraitBackdrop,
null,
scaling.viewport,
backgroundPaint,
FittingMode.FILL, 0.5f, 0.5f)
ctx.drawARGB((context.vsh.itemBackdropAlphaTime * opa * 255).toInt(), 0,0,0)
if(context.vsh.itemBackdropAlphaTime < 1.0f) context.vsh.itemBackdropAlphaTime += (time.deltaTime) * 2.0f
}
}else if(activeItem.hasBackdrop){
if(activeItem.isBackdropLoaded){
ctx.drawBitmap(
activeItem.backdrop,
null,
scaling.viewport,
backgroundPaint,
FittingMode.FILL, 0.5f, 0.5f)
ctx.drawARGB((context.vsh.itemBackdropAlphaTime * opa * 255).toInt(), 0,0,0)
if(context.vsh.itemBackdropAlphaTime < 1.0f) context.vsh.itemBackdropAlphaTime += (time.deltaTime) * 2.0f
}
context.vsh.itemBackdropAlphaTime =context.vsh.itemBackdropAlphaTime.coerceIn(0f, 1f)
backgroundPaint.alpha = (context.vsh.itemBackdropAlphaTime * 255).roundToInt().coerceIn(0, 255)
if(isPortrait){
if(activeItem.hasPortraitBackdrop && activeItem.isPortraitBackdropLoaded){
ctx.drawBitmap(
activeItem.portraitBackdrop,
null,
scaling.viewport,
backgroundPaint,
FittingMode.FILL, 0.5f, 0.5f)
isChanged = true
}
}else {
if(activeItem.hasBackdrop && activeItem.isBackdropLoaded){
ctx.drawBitmap(
activeItem.backdrop,
null,
scaling.viewport,
backgroundPaint,
FittingMode.FILL, 0.5f, 0.5f)
isChanged = true
}
}
}catch(cme:ConcurrentModificationException){
Expand All @@ -200,6 +197,37 @@ class XmbMainMenu(view : XmbView) : XmbScreen(view) {
val focusAlpha = widgets.sideMenu.showMenuDisplayFactor.toLerp(0f, 128f).toInt()
ctx.drawARGB(focusAlpha, 0,0,0)

if(isChanged){
ctx.drawARGB((context.vsh.itemBackdropAlphaTime * opa * 255).toInt(), 0,0,0)
if(context.vsh.itemBackdropAlphaTime < 1.0f) context.vsh.itemBackdropAlphaTime += (time.deltaTime) * 2.0f
}

if(verticalMenu.showBackdrop && activeItem != null){
try{
if(isPortrait){
if(activeItem.hasPortraitBackdropOverlay && activeItem.isPortraitBackdropOverlayLoaded){
ctx.drawBitmap(
activeItem.portraitBackdropOverlay,
null,
scaling.viewport,
backgroundPaint,
FittingMode.FIT, 0.5f, 0.5f)
}
}else{
if(activeItem.hasBackOverlay && activeItem.isBackdropOverlayLoaded) {
ctx.drawBitmap(
activeItem.backdropOverlay,
null,
scaling.viewport,
backgroundPaint,
FittingMode.FIT, 0.5f, 0.5f)
}
}
}catch(cme:ConcurrentModificationException){
cme.printStackTrace()
}
}

}

private fun drawHorizontalMenu(ctx:Canvas) {
Expand Down

0 comments on commit 1157043

Please sign in to comment.