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