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
item is name, fn is fullpath
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)
"""
gallery_items = []
@ -33,10 +33,9 @@ init python:
gallery_dic[cp['name']] = [] #
# Make a scaled cg button
# (cg: string; ext: string; w: float; h: float
def cg(fname, ext, w, h):
wh = {'x': w, 'y': h}
scale = PREFERRED_WIDTH * 100.0 / float(wh['x']) / 100.0
# (cg: string; ext: string; w: float
def cg(fname, ext, w):
scale = PREFERRED_WIDTH * 100.0 / w / 100.0
#scale = box_ratio(wh)
return im.FactorScale(fname, scale, scale, False)
@ -56,13 +55,12 @@ init python:
if renpy.loadable(_str): #brute force
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']] += [{
"item": str,
"fn": _str,
"cg": cg(_str, ext, image[0], image[1]),
"ext": ext
"cg": cg(_str, ext, image[0]),
"ext": ext,
"wh": image
}]
return
@ -194,13 +192,11 @@ screen flag_button(item, yoffset, origin):
if flag:
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
padding (1,0,1,2)
vbox:
transform:
#xmaximum (PREFERRED_WIDTH, PREFERRED_HEIGHT)
text item["item"] xalign 0.5
text item["item"] xalign 0.5
add item["cg"] fit 'contain' xcenter 0.5 ycenter 0.5 size (PREFERRED_WIDTH, PREFERRED_HEIGHT)
else:
vbox:
@ -213,23 +209,23 @@ screen flag_button(item, yoffset, origin):
"""
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:
if zoom == 0.0:
zoom = zoom_arr.index(1.0)
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_f = ShowMenu('view_image_'+flag, fn, _origin, zoom_b)
zoom_b_f = ShowMenu('view_image_'+flag, item, _origin, zoom_b)
tag menu
key "game_menu" action _origin
# 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 '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 'K_DELETE' action zoom_b_f
@ -243,7 +239,7 @@ screen view_image(fn, _origin, zoom=0.0, flag='a'):
pagekeys True
xfill 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
#double finger pinch zoom, it translates taps as mouse events - have to use