Clean up functions

This commit is contained in:
Nutbuster 2021-07-18 17:47:35 +10:00
parent a905747e2c
commit 3357355a8a
1 changed files with 15 additions and 19 deletions

View File

@ -22,7 +22,7 @@ init python:
Data structure that holds the data for each cg and button Data structure that holds the data for each cg and button
item is name, fn is fullpath item is name, fn is fullpath
ext is the file extension ext is the file extension
{ item: string; fn: string, cg: Displayable; ext: string }[] { item: str; fn: str; cg: Displayable; ext: str; wh: [] }[]
(reference in this init python, actually used in screens) (reference in this init python, actually used in screens)
""" """
gallery_items = [] gallery_items = []
@ -33,10 +33,9 @@ init python:
gallery_dic[cp['name']] = [] # gallery_dic[cp['name']] = [] #
# Make a scaled cg button # Make a scaled cg button
# (cg: string; ext: string; w: float; h: float # (cg: string; ext: string; w: float
def cg(fname, ext, w, h): def cg(fname, ext, w):
wh = {'x': w, 'y': h} scale = PREFERRED_WIDTH * 100.0 / w / 100.0
scale = PREFERRED_WIDTH * 100.0 / float(wh['x']) / 100.0
#scale = box_ratio(wh) #scale = box_ratio(wh)
return im.FactorScale(fname, scale, scale, False) return im.FactorScale(fname, scale, scale, False)
@ -56,13 +55,12 @@ init python:
if renpy.loadable(_str): #brute force if renpy.loadable(_str): #brute force
image = renpy.image_size(Image(_str)) image = renpy.image_size(Image(_str))
# Create an object in g:Gallery, add to galleryItems
# (imageName: string; ext: string; w: float; h: float) -> None
gallery_dic[cp['name']] += [{ gallery_dic[cp['name']] += [{
"item": str, "item": str,
"fn": _str, "fn": _str,
"cg": cg(_str, ext, image[0], image[1]), "cg": cg(_str, ext, image[0]),
"ext": ext "ext": ext,
"wh": image
}] }]
return return
@ -194,13 +192,11 @@ screen flag_button(item, yoffset, origin):
if flag: if flag:
button: button:
action ShowMenu('view_image_a', item['fn'], ShowMenu('cg_gallery_0', yoffset, origin), 0.0) action ShowMenu('view_image_a', item, ShowMenu('cg_gallery_0', yoffset, origin), 0.0)
xcenter 0.5 ycenter 0.5 xcenter 0.5 ycenter 0.5
padding (1,0,1,2) padding (1,0,1,2)
vbox: vbox:
transform: text item["item"] xalign 0.5
#xmaximum (PREFERRED_WIDTH, PREFERRED_HEIGHT)
text item["item"] xalign 0.5
add item["cg"] fit 'contain' xcenter 0.5 ycenter 0.5 size (PREFERRED_WIDTH, PREFERRED_HEIGHT) add item["cg"] fit 'contain' xcenter 0.5 ycenter 0.5 size (PREFERRED_WIDTH, PREFERRED_HEIGHT)
else: else:
vbox: vbox:
@ -213,23 +209,23 @@ screen flag_button(item, yoffset, origin):
""" """
view_image, Loads the image in fullscreen with viewport control. view_image, Loads the image in fullscreen with viewport control.
""" """
screen view_image(fn, _origin, zoom=0.0, flag='a'): screen view_image(item, _origin, zoom=0.0, flag='a'):
python: python:
if zoom == 0.0: if zoom == 0.0:
zoom = zoom_arr.index(1.0) zoom = zoom_arr.index(1.0)
zoom_a = zoom+1 zoom_a = zoom+1
zoom_a_f = ShowMenu('view_image_'+flag, fn, _origin, zoom_a) zoom_a_f = ShowMenu('view_image_'+flag, item, _origin, zoom_a)
zoom_b = zoom-1 zoom_b = zoom-1
zoom_b_f = ShowMenu('view_image_'+flag, fn, _origin, zoom_b) zoom_b_f = ShowMenu('view_image_'+flag, item, _origin, zoom_b)
tag menu tag menu
key "game_menu" action _origin key "game_menu" action _origin
# mousewheel & insert+delete # mousewheel & insert+delete
if zoom_a < len(zoom_arr): if zoom_a < len(zoom_arr): #zoom in
key 'mousedown_4' action zoom_a_f key 'mousedown_4' action zoom_a_f
key 'K_INSERT' action zoom_a_f key 'K_INSERT' action zoom_a_f
if zoom_b > 0: if zoom_b > 0: #and (item['wh'][0] <= 1920 or item['wh'][1] <= 1080):
key 'mousedown_5' action zoom_b_f key 'mousedown_5' action zoom_b_f
key 'K_DELETE' action zoom_b_f key 'K_DELETE' action zoom_b_f
@ -243,7 +239,7 @@ screen view_image(fn, _origin, zoom=0.0, flag='a'):
pagekeys True pagekeys True
xfill False xfill False
yfill False yfill False
add fn zoom zoom_arr[zoom] anchor (0.55, 0.55) add item['fn'] zoom zoom_arr[zoom] anchor (0.55, 0.55)
#Reuse quick buttons, Ren'Py handles touch input lazy, it doesn't have #Reuse quick buttons, Ren'Py handles touch input lazy, it doesn't have
#double finger pinch zoom, it translates taps as mouse events - have to use #double finger pinch zoom, it translates taps as mouse events - have to use