-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_autoxywh.py
80 lines (52 loc) · 1.97 KB
/
test_autoxywh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import asyncio
import pygame
import pygame_widgets
from pygame_widgets.button import Button
pygame.init()
# reference/idealized screen pixels
REFX = 1980
REFY = 1080
# screen pixels (real, hardware)
WIDTH = 1024 # {{cookiecutter.width}}
HEIGHT = 600 # {{cookiecutter.height}}
def u(real, ref, v):
if abs(v) < 0.9999999:
result = int((float(real) / 100.0) * (v * 1000))
if v < 0:
return real + result
return result
return int((real / ref) * v)
def ux(*argv):
global WIDTH, REFX
acc = 0
for v in argv:
acc += u(WIDTH, REFX, v)
return acc
def uy(*argv):
global HEIGHT, REFY
acc = 0
for v in argv:
acc += u(HEIGHT, REFY, v)
return acc
__import__("builtins").const = lambda x:x
async def main():
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# use fake const keyword so "compiler" can apply litteral without evaluating
# just parsing code.
# note that keyword also exists in micropython/circuitpython etc ...
# where it is also optimized this way
pad = const(15) # relative to reference (here 1980) !
padx = const(ux(pad)) # report to 1024
pady = const(uy(pad)) # report to 600
screen.fill("aquamarine4")
# padx, pady, width 50% -padx, height 33% - pady
button = Button(screen, padx, pady, ux(0.050) - padx, uy(0.033) - pady, text="Row 1_C1")
button = Button(screen, ux(.050) + padx, pady, ux(.040) -padx, uy(.033)-pady, text="Row 1_C2")
button = Button(screen, padx, uy(.033)+padx, ux(.090)-pady, uy(.033)-pady, text="Row 2_span")
# or use pad as second value
button = Button(screen, ux(pad), uy(.066, +pad), ux(.090, -pad) , uy(0.033, -pad) , text="Row 3_span" )
# here -10% from max X instead of 90% from 0
button = Button(screen, ux(-.010, +pad), uy(pad), ux(.010, -2*pad) , uy(0.100, -2*pad) , text="span_C3" )
pygame_widgets.update(pygame.event.get())
pygame.display.update()
asyncio.run(main())