From 2e5ea437cde230d9c802b99414af829fd32598a7 Mon Sep 17 00:00:00 2001 From: cuu Date: Mon, 28 Jan 2019 23:13:05 +0800 Subject: [PATCH] add SpeedScroll --- sys.py/UI/Emulator/fav_list_page.py | 40 +++++++++++++++++++-------- sys.py/UI/Emulator/rom_list_page.py | 43 +++++++++++++++++++++-------- sys.py/UI/main_screen.py | 1 + sys.py/UI/page.py | 3 +- sys.py/run.py | 1 + 5 files changed, 64 insertions(+), 24 deletions(-) diff --git a/sys.py/UI/Emulator/fav_list_page.py b/sys.py/UI/Emulator/fav_list_page.py index 261d734..c4ea24c 100644 --- a/sys.py/UI/Emulator/fav_list_page.py +++ b/sys.py/UI/Emulator/fav_list_page.py @@ -3,7 +3,7 @@ import os import pygame import glob - +import time from libs.roundrects import aa_round_rect ## local UI import @@ -255,30 +255,33 @@ class FavListPage(Page): if len(self._MyList) == 0: return - self._PsIndex -= 1 + tmp = self._PsIndex + self._PsIndex -= self._ScrollStep + if self._PsIndex < 0: self._PsIndex = 0 - + dy = tmp - self._PsIndex cur_li = self._MyList[self._PsIndex] if cur_li._PosY < 0: for i in range(0, len(self._MyList)): - self._MyList[i]._PosY += self._MyList[i]._Height - - self._Scrolled += 1 + self._MyList[i]._PosY += self._MyList[i]._Height*dy + self._Scrolled +=dy def ScrollDown(self): if len(self._MyList) == 0: return - - self._PsIndex +=1 + tmp = self._PsIndex + self._PsIndex +=self._ScrollStep if self._PsIndex >= len(self._MyList): self._PsIndex = len(self._MyList) -1 - + + dy = self._PsIndex - tmp cur_li = self._MyList[self._PsIndex] if cur_li._PosY +cur_li._Height > self._Height: for i in range(0,len(self._MyList)): - self._MyList[i]._PosY -= self._MyList[i]._Height - self._Scrolled -=1 + self._MyList[i]._PosY -= self._MyList[i]._Height*dy + self._Scrolled -= dy + def SyncScroll(self): ## if self._Scrolled == 0: @@ -374,6 +377,19 @@ class FavListPage(Page): self._Screen.Draw() self._Screen.SwapAndShow() + def SpeedScroll(self, thekey): + if self._Screen._LastKey == thekey: + self._ScrollStep+=1 + if self._ScrollStep >=5: + self._ScrollStep = 5 + else: + self._ScrollStep = 1 + + cur_time = time.time() + + if cur_time - self._Screen._LastKeyDown > 0.3: + self._ScrollStep = 1 + def KeyDown(self,event): if event.key == CurKeys["Menu"] or event.key == CurKeys["Left"]: @@ -383,10 +399,12 @@ class FavListPage(Page): if event.key == CurKeys["Up"]: + self.SpeedScroll(event.key) self.ScrollUp() self._Screen.Draw() self._Screen.SwapAndShow() if event.key == CurKeys["Down"]: + self.SpeedScroll(event.key) self.ScrollDown() self._Screen.Draw() self._Screen.SwapAndShow() diff --git a/sys.py/UI/Emulator/rom_list_page.py b/sys.py/UI/Emulator/rom_list_page.py index 4bdf2bd..12c560a 100644 --- a/sys.py/UI/Emulator/rom_list_page.py +++ b/sys.py/UI/Emulator/rom_list_page.py @@ -9,7 +9,7 @@ import shutil import gobject import validators #from pySmartDL import SmartDL - +import time from libs.roundrects import aa_round_rect @@ -114,8 +114,8 @@ class RomListPage(Page): _BGheight = 70 _RomSoConfirmDownloadPage = None - - + + def __init__(self): Page.__init__(self) @@ -289,28 +289,32 @@ class RomListPage(Page): if len(self._MyList) == 0: return - self._PsIndex -= 1 + tmp = self._PsIndex + self._PsIndex -= self._ScrollStep + if self._PsIndex < 0: self._PsIndex = 0 + dy = tmp - self._PsIndex cur_li = self._MyList[self._PsIndex] if cur_li._PosY < 0: for i in range(0, len(self._MyList)): - self._MyList[i]._PosY += self._MyList[i]._Height - self._Scrolled +=1 + self._MyList[i]._PosY += self._MyList[i]._Height*dy + self._Scrolled +=dy def ScrollDown(self): if len(self._MyList) == 0: return - - self._PsIndex +=1 + tmp = self._PsIndex + self._PsIndex +=self._ScrollStep if self._PsIndex >= len(self._MyList): self._PsIndex = len(self._MyList) -1 - + + dy = self._PsIndex - tmp cur_li = self._MyList[self._PsIndex] if cur_li._PosY +cur_li._Height > self._Height: for i in range(0,len(self._MyList)): - self._MyList[i]._PosY -= self._MyList[i]._Height - self._Scrolled -= 1 + self._MyList[i]._PosY -= self._MyList[i]._Height*dy + self._Scrolled -= dy def SyncScroll(self): ## @@ -408,7 +412,20 @@ class RomListPage(Page): self.ReScan() self._Screen.Draw() self._Screen.SwapAndShow() - + + def SpeedScroll(self, thekey): + if self._Screen._LastKey == thekey: + self._ScrollStep+=1 + if self._ScrollStep >=5: + self._ScrollStep = 5 + else: + self._ScrollStep = 1 + + cur_time = time.time() + + if cur_time - self._Screen._LastKeyDown > 0.3: + self._ScrollStep = 1 + def KeyDown(self,event): if event.key == CurKeys["Menu"] : @@ -423,11 +440,13 @@ class RomListPage(Page): self._Screen.SwapAndShow() if event.key == CurKeys["Up"]: + self.SpeedScroll(event.key) self.ScrollUp() self._Screen.Draw() self._Screen.SwapAndShow() if event.key == CurKeys["Down"]: + self.SpeedScroll(event.key) self.ScrollDown() self._Screen.Draw() self._Screen.SwapAndShow() diff --git a/sys.py/UI/main_screen.py b/sys.py/UI/main_screen.py index c410557..ffb96bc 100644 --- a/sys.py/UI/main_screen.py +++ b/sys.py/UI/main_screen.py @@ -146,6 +146,7 @@ class MainScreen(Widget): _CounterScreen = None _LastKey = -1 + _LastKeyDown = -1 def __init__(self): self._Pages = [] diff --git a/sys.py/UI/page.py b/sys.py/UI/page.py index 565798c..231498e 100644 --- a/sys.py/UI/page.py +++ b/sys.py/UI/page.py @@ -100,7 +100,8 @@ class Page(Widget): _EasingDur = 30 _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 = [] diff --git a/sys.py/run.py b/sys.py/run.py index e57cec8..070e940 100644 --- a/sys.py/run.py +++ b/sys.py/run.py @@ -416,6 +416,7 @@ def event_process(event,main_screen): if callable( key_down_cb ): main_screen.KeyDown(event) + main_screen._LastKeyDown = everytime_keydown return def gobject_pygame_event_poll_timer(main_screen):