mirror of
https://github.com/clockworkpi/launcher.git
synced 2025-12-12 17:58:50 +01:00
Allows for the rendering and rescaling of images to be used as a background to the launcher
This commit is contained in:
parent
a9220fc66e
commit
24d711e538
@ -6,55 +6,61 @@ from sys import exit
|
||||
import os
|
||||
import sys
|
||||
import math
|
||||
import fnmatch
|
||||
import random
|
||||
|
||||
|
||||
from libs import easing
|
||||
|
||||
#import base64
|
||||
#from beeprint import pp
|
||||
# import base64
|
||||
# from beeprint import pp
|
||||
|
||||
### local import
|
||||
from constants import ALIGN,icon_width,icon_height,Width,Height,ICON_TYPES
|
||||
# local import
|
||||
from constants import ALIGN, icon_width, icon_height, Width, Height, ICON_TYPES
|
||||
from util_funcs import midRect
|
||||
from keys_def import CurKeys, IsKeyStartOrA, IsKeyMenuOrB
|
||||
from icon_pool import MyIconPool
|
||||
from lang_manager import MyLangManager
|
||||
from widget import Widget
|
||||
|
||||
|
||||
class PageStack:
|
||||
def __init__(self):
|
||||
self.stack = list()
|
||||
|
||||
def Push(self,data):
|
||||
def Push(self, data):
|
||||
if data not in self.stack:
|
||||
self.stack.append(data)
|
||||
return True
|
||||
return False
|
||||
|
||||
def Pop(self):
|
||||
if len(self.stack)<=0:
|
||||
return None,False
|
||||
return self.stack.pop(),True
|
||||
if len(self.stack) <= 0:
|
||||
return None, False
|
||||
return self.stack.pop(), True
|
||||
|
||||
def Length(self):
|
||||
return len(self.stack)
|
||||
|
||||
|
||||
class PageSelector(Widget):
|
||||
|
||||
_Parent = None
|
||||
_Alpha = 0
|
||||
_OnShow = True
|
||||
_IconSurf = None
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def Init(self,x,y,w,h,alpha):
|
||||
def Init(self, x, y, w, h, alpha):
|
||||
self._PosX = x
|
||||
self._PosY = y
|
||||
self._Width = w
|
||||
self._Height = h
|
||||
self._Alpha = alpha
|
||||
|
||||
def Adjust(self,x,y,w,h,alpha):
|
||||
def Adjust(self, x, y, w, h, alpha):
|
||||
self._PosX = x
|
||||
self._PosY = y
|
||||
self._Width = w
|
||||
@ -68,42 +74,52 @@ class PageSelector(Widget):
|
||||
|
||||
if idx < len(self._Parent._Icons):
|
||||
x = self._Parent._Icons[idx]._PosX+self._Parent._PosX
|
||||
y = self._Parent._Icons[iconidx]._PosY ## only use current icon's PosY
|
||||
# only use current icon's PosY
|
||||
y = self._Parent._Icons[iconidx]._PosY
|
||||
|
||||
rect = midRect(x,y,self._Width,self._Height,self._Parent._Width,self._Parent._Height)
|
||||
if rect.width <=0 or rect.height <= 0 :
|
||||
rect = midRect(x, y, self._Width, self._Height,
|
||||
self._Parent._Width, self._Parent._Height)
|
||||
if rect.width <= 0 or rect.height <= 0:
|
||||
return
|
||||
|
||||
#color = (244,197,66,50)
|
||||
#pygame.draw.rect(canvas,color,rect,1)
|
||||
# color = (244,197,66,50)
|
||||
# pygame.draw.rect(canvas,color,rect,1)
|
||||
if self._IconSurf != None:
|
||||
self._Parent._CanvasHWND.blit(self._IconSurf,rect)
|
||||
self._Parent._CanvasHWND.blit(self._IconSurf, rect)
|
||||
|
||||
|
||||
class Page(Widget):
|
||||
_Icons = []
|
||||
_Ps = None
|
||||
_PsIndex = 0
|
||||
_IconNumbers = 0
|
||||
_IconIndex = 0 ## shows which icon current selected, the Selector can not move here
|
||||
_PrevIconIndex = 0 ## for remember the Highlighted Icon ,restore it's PosY to average
|
||||
_IconIndex = 0 # shows which icon current selected, the Selector can not move here
|
||||
_PrevIconIndex = 0 # for remember the Highlighted Icon ,restore it's PosY to average
|
||||
_Index = 0
|
||||
_Align = ALIGN["SLeft"]
|
||||
_CanvasHWND = None #
|
||||
_HWND = None #
|
||||
_CanvasHWND = None
|
||||
_HWND = None
|
||||
_OnShow = False
|
||||
_Name = ""
|
||||
_Screen = None ## Should be the Screen Class
|
||||
_Screen = None # Should be the Screen Class
|
||||
_PageIconMargin = 20
|
||||
_FootMsg = ["Nav","","","","Enter"] ## Default Page Foot info
|
||||
|
||||
_SelectedIconTopOffset=20
|
||||
_FootMsg = ["Nav", "", "", "", "Enter"] # Default Page Foot info
|
||||
_Wallpaper = None
|
||||
_SelectedIconTopOffset = 20
|
||||
_EasingDur = 30
|
||||
_Padding = pygame.Rect(0,0,0,0)# x,y,w,h
|
||||
_Margin = pygame.Rect(0,0,0,0)
|
||||
_Padding = pygame.Rect(0, 0, 0, 0) # x,y,w,h
|
||||
_Margin = pygame.Rect(0, 0, 0, 0)
|
||||
_ScrollStep = 1
|
||||
|
||||
def __init__(self):
|
||||
self._Icons = []
|
||||
path = '/home/cpi/launcher/skin/default/Menu/GameShell/Wallpaper/'
|
||||
|
||||
if os.path.exists(path):
|
||||
image = os.listdir(path)[0]
|
||||
if image:
|
||||
self._Wallpaper = pygame.transform.scale(pygame.image.load(path+image).convert(), (320,240))
|
||||
|
||||
|
||||
|
||||
def AdjustHLeftAlign(self): ## adjust coordinator and append the PageSelector
|
||||
@ -185,7 +201,7 @@ class Page(Widget):
|
||||
it._Parent = self
|
||||
it._Index = 0
|
||||
it.Adjust(start_x,start_y,icon_width,icon_height,0)
|
||||
#it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
|
||||
# it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
|
||||
|
||||
elif self._IconNumbers == 2:
|
||||
start_x = (self._Width - self._PageIconMargin - self._IconNumbers*icon_width) / 2 + icon_width/2
|
||||
@ -196,7 +212,7 @@ class Page(Widget):
|
||||
it._Parent = self
|
||||
it._Index = i
|
||||
it.Adjust(start_x+i*self._PageIconMargin + i*icon_width,start_y, icon_width, icon_height,0)
|
||||
#it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
|
||||
# it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
|
||||
|
||||
elif self._IconNumbers > 2:
|
||||
for i in range(0,self._IconNumbers):
|
||||
@ -204,7 +220,7 @@ class Page(Widget):
|
||||
it._Parent = self
|
||||
it._Index = i
|
||||
it.Adjust(start_x+i*self._PageIconMargin + i*icon_width,start_y,icon_width,icon_height,0)
|
||||
#it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
|
||||
# it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
|
||||
|
||||
ps = PageSelector()
|
||||
ps._IconSurf = MyIconPool._Icons["blueselector"]
|
||||
@ -512,7 +528,7 @@ class Page(Widget):
|
||||
self._Screen._CurrentPage = child_page
|
||||
elif cur_icon._MyType == ICON_TYPES["FUNC"]:
|
||||
print("IconClick API: %d"%(cur_icon._Index))
|
||||
#print("%s"% cur_icon._CmdPath)
|
||||
# print("%s"% cur_icon._CmdPath)
|
||||
api_cb = getattr(cur_icon._CmdPath,"API",None)
|
||||
if api_cb != None:
|
||||
if callable(api_cb):
|
||||
@ -523,7 +539,7 @@ class Page(Widget):
|
||||
def ReturnToUpLevelPage(self):
|
||||
pop_page,ok = self._Screen._MyPageStack.Pop()
|
||||
if ok == True:
|
||||
#self._Screen._CurrentPage.ResetPageSelector()
|
||||
# self._Screen._CurrentPage.ResetPageSelector()
|
||||
pop_page.Draw()
|
||||
self._Screen._CurrentPage = pop_page
|
||||
on_return_back_cb = getattr(self._Screen._CurrentPage,"OnReturnBackCb",None)
|
||||
@ -538,8 +554,12 @@ class Page(Widget):
|
||||
print("OnTopLevel ",self._Screen._PageIndex)
|
||||
|
||||
def ClearCanvas(self):
|
||||
if self._Wallpaper:
|
||||
self._CanvasHWND.blit(self._Wallpaper,(0,0))
|
||||
else:
|
||||
self._CanvasHWND.fill(self._Screen._SkinManager.GiveColor("White"))
|
||||
|
||||
|
||||
def ClearIcons(self):
|
||||
for i in range(0,self._IconNumbers):
|
||||
self._Icons[i].Clear()
|
||||
@ -548,7 +568,7 @@ class Page(Widget):
|
||||
for i in range(0,self._IconNumbers):
|
||||
self._Icons[i].Draw()
|
||||
|
||||
##make sure the Class has the _MyList
|
||||
# make sure the Class has the _MyList
|
||||
def ScrollDown(self):
|
||||
if len(self._MyList) == 0:
|
||||
return
|
||||
@ -650,4 +670,3 @@ class Page(Widget):
|
||||
self.DrawIcons()
|
||||
self.DrawPageSelector()
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user