forked from Opticos/GWSL-Source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpticUI.py
776 lines (609 loc) · 23.8 KB
/
OpticUI.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# OpticUI 1.0
# Copyright Paul-E andOpticos Studios 2020
import PIL, os
from PIL import ImageFilter as ImageFilterOrig
from PIL import Image
from winreg import *
import imtools, ctypes
# from io import BytesIO
# import cairosvg
pygame = None
WIDTH, HEIGHT = 0, 0
ppi = 0
icon_pack_path = None
asset_dir = ""
icons = {}
def hex_to_rgb(value):
value = value.lstrip('#')
lv = len(value)
return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
def get_color():
"""
Return the Windows 10 accent color used by the user in a HEX format
"""
try:
# Open the registry
registry = ConnectRegistry(None, HKEY_CURRENT_USER)
# Navigate to the key that contains the accent color info
# key = OpenKey(registry, r'SOFTWARE\Microsoft\Windows\DWM')
# key_value = QueryValueEx(key,'AccentColor')
key = OpenKey(registry, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent')
key_value = QueryValueEx(key, 'StartColorMenu')
key_value2 = QueryValueEx(key, 'AccentPalette')
value = key_value2[0]
import codecs
c = codecs.encode(value, "hex")
bins = str(" ".join([hex(ch)[2:] for ch in value])).split(" ")
bins = [b + "0" if b == "0" else b for b in bins]
# print(bins[0] + bins[1] + bins[2])
color = 4
color = color * 3
rgb = list(hex_to_rgb('#' + bins[color] + bins[color + 1] + bins[color + 2]))
rgb = rgb[:3]
if len(rgb) > 3:
rgb = [rgb[0], rgb[1], rgb[2]]
if rgb[0] < 0 or rgb[0] > 255 or rgb[1] < 0 or rgb[1] > 255 or rgb[2] < 0 or rgb[2] > 255:
rgb = [0, 150, 150]
# Make the color lighter if needed
lightness = int((rgb[0] + rgb[1] + rgb[2]) / 3)
if lightness < 30:
rgb = [0, 150, 150]
return rgb
# Junk code
"""
# Convert the interger to Hex and remove its offset
accent_int = key_value[0]
accent_hex = hex(accent_int + 4278190080) # Remove FF offset and convert to HEX again
accent_hex = str(accent_hex)[5:] # -1] #Remove prefix and suffix
accent = accent_hex[4:6] + accent_hex[2:4] + accent_hex[0:2]
rgb = hex_to_rgb('#' + accent)
rgb = rgb[:2]
print(1, rgb)
if rgb[0] < 0 or rgb[0] > 255 or rgb[1] < 0 or rgb[1] > 255 or rgb[2] < 0 or rgb[2] > 255:
rgb = [0, 200, 200]
print(2, rgb)
return rgb
"""
except:
print("failing")
return [0, 200, 200]
def set_icons(iconpack_path):
global icon_pack_path, icons
icon_pack_path = iconpack_path
icons = {}
for root, dirs, files in os.walk(icon_pack_path):
for file in files:
full = os.path.join(root, file)
icons.update({file: full})
def icon_path(name, spec=None):
filename = None # "assets/chat.png"
name = name.lower()
names = None
n = 0
if " " in name:
names = name.split(" ")
name = names[0]
name = name.lower()
elif "." in name:
names = name.split(".")
name = names[0]
name = name.lower()
# name = name.replace(" ", "-")
if names == None:
names = [name]
for name in names:
for f in icons:
full = icons[f]
files = f[:-4].split("-")
if str(name) == str(f)[:-4].lower():
filename = full
break
elif str(name) == str(f).lower():
filename = full
break
elif str(name) == files[0]:
filename = full
elif name in full:
if spec == None:
filename = full
break
else:
if spec in full:
filename = full
break
if filename != None:
break
if filename != None:
break
if filename == None:
filename = "link.png"
if name == "":
filename = "link.png"
try:
if filename.endswith(".svg") == True:
pass
# out = BytesIO()
# cairosvg.svg2png(url=filename, write_to=out)
# imager = Image.open(out)
else:
try:
imager = Image.open(filename)
except:
with open(filename) as f:
reader = f.read()
if ".png" in reader:
filename = os.path.dirname(filename) + "\\" + reader
#imager = Image.open(filename)
else:
#imager = Image.open(asset_dir + "link.png")
filename = asset_dir + "link.png"
return filename#imager
except:
#imager = Image.open(asset_dir + "link.png")
return asset_dir + "link.png"#imager
return asset_dir + "link.png"
def icon(name, spec=None):
filename = None # "assets/chat.png"
name = name.lower()
names = None
n = 0
if " " in name:
names = name.split(" ")
name = names[0]
name = name.lower()
elif "." in name:
names = name.split(".")
name = names[0]
name = name.lower()
# name = name.replace(" ", "-")
if names == None:
names = [name]
for name in names:
for f in icons:
full = icons[f]
files = f[:-4].split("-")
if str(name) == str(f)[:-4].lower():
filename = full
break
elif str(name) == str(f).lower():
filename = full
break
elif str(name) == files[0]:
filename = full
elif name in full:
if spec == None:
filename = full
break
else:
if spec in full:
filename = full
break
if filename != None:
break
if filename != None:
break
if filename == None:
filename = "link.png"
if name == "":
filename = "link.png"
try:
if filename.endswith(".svg") == True:
pass
# out = BytesIO()
# cairosvg.svg2png(url=filename, write_to=out)
# imager = Image.open(out)
else:
try:
imager = Image.open(filename)
except:
with open(filename) as f:
reader = f.read()
if ".png" in reader:
filename = os.path.dirname(filename) + "\\" + reader
imager = Image.open(filename)
else:
imager = Image.open(asset_dir + "link.png")
return imager
except:
imager = Image.open(asset_dir + "link.png")
return imager
return img
def pygame_icon(name, spec=None):
filename = None # "assets/chat.png"
name = name.lower()
names = None
n = 0
if " " in name:
names = name.split(" ")
name = names[0]
name = name.lower()
elif "." in name:
names = name.split(".")
name = names[0]
name = name.lower()
# name = name.replace(" ", "-")
if names == None:
names = [name]
for name in names:
for f in icons:
full = icons[f]
files = f[:-4].split("-")
if str(name) == str(f)[:-4].lower():
filename = full
break
elif str(name) == str(f).lower():
filename = full
break
elif str(name) == files[0]:
filename = full
elif name in full:
if spec == None:
filename = full
break
else:
if spec in full:
filename = full
break
if filename != None:
break
if filename != None:
break
if filename == None or filename == "":
filename = asset_dir + "\\link.png"
try:
try:
imager = pygame.image.load(filename).convert_alpha()
except:
with open(filename) as f:
reader = f.read()
if ".png" in reader:
filename = os.path.dirname(filename) + "\\" + reader
imager = pygame.image.load(filename).convert_alpha()
else:
imager = pygame.image.load(asset_dir + "\\link.png").convert_alpha()
return imager
except:
imager = pygame.image.load(asset_dir + "\\link.png").convert_alpha()
return imager
def iris(canvas, pos, size, tint, radius=10, shadow_enabled=True, shadow_size=0.08, alpha=255):
intensity = int((alpha / 255) * 30)
s = pygame.Surface(size)
s.blit(canvas, [0, 0], [pos[0], pos[1], size[0], size[1]])
pygame.gfxdraw.filled_polygon(s, [[0, 0], [size[0], 0], size, [0, size[1]]], tint + [intensity])
rad = radius
b = pygame.image.tostring(s, "RGBA", False)
b = PIL.Image.frombytes("RGBA", size, b)
b = b.filter(PIL.ImageFilter.GaussianBlur(radius=int(rad)))
b = pygame.image.frombuffer(b.tobytes(), b.size, b.mode).convert()
b.set_alpha(alpha)
if shadow_enabled == True:
w_expand = (size[0] / size[1]) - 1
if w_expand == 0:
w_expand = 1
shade = pygame.transform.scale(shadow, [size[0] + 2 * w(shadow_size * w_expand),
size[1] + 2 * h(shadow_size)])
shadow_alpha = int((alpha / 255) * 150)
shade.set_alpha(shadow_alpha)
canvas.blit(shade, [pos[0] - w(shadow_size * w_expand),
pos[1] - h(shadow_size)])
canvas.blit(b, pos)
def iris_light(canvas, pos, size, tint, radius=10, shadow_enabled=True, shadow_size=0.08, alpha=255):
intensity = int((alpha / 255) * 30)
size = [int(size[0]), int(size[1])]
resolution = 30 # percentage of pixels to use for blur
s = pygame.Surface(size) # , pygame.SRCALPHA)
s.blit(canvas, [0, 0], [pos[0], pos[1], size[0], size[1]])
s = pygame.transform.rotozoom(s, 0, (resolution / 100.0) * 1)
size2 = s.get_size()
pygame.gfxdraw.filled_polygon(s, [[0, 0], [size2[0], 0], size2, [0, size2[1]]], tint + [intensity])
rad = radius
b = pygame.image.tostring(s, "RGBA", False)
b = PIL.Image.frombytes("RGBA", size2, b)
b = replace_color(b, [0, 0, 0], [255, 0, 0])
b = b.filter(PIL.ImageFilter.GaussianBlur(radius=int(rad)))
b = pygame.image.frombuffer(b.tobytes(), b.size, b.mode).convert_alpha()
if shadow_enabled == True:
w_expand = (size[0] / size[1]) - 1
if w_expand == 0:
w_expand = 1
shade = pygame.transform.scale(shadow, [size[0] + 2 * w(shadow_size * w_expand),
size[1] + 2 * h(shadow_size)])
shadow_alpha = int((alpha / 255) * 150)
shade.set_alpha(shadow_alpha)
canvas.blit(shade, [pos[0] - w(shadow_size * w_expand),
pos[1] - h(shadow_size)])
# b = pygame.transform.rotozoom(b, 0, (100.0 / resolution) * 1)
b = pygame.transform.scale(b, size)
b.set_alpha(alpha)
canvas.blit(b, pos) # , special_flags=pygame.BLEND_RGBA_BLEND)
fancy = True
mode = "dark"
def set_blur(blur_on):
global fancy
fancy = blur_on
def toggle_quality():
global fancy
if fancy == True:
fancy = False
else:
fancy = True
def toggle_mode():
global mode
if mode == "light":
mode = "dark"
else:
mode = "light"
def iris2(canvas, pos, size, tint, radius=10, shadow_enabled=True, rounded=0, shadow_size=0.08, alpha=255,
resolution=20, anti_glitch=False):
global fancy, mode
intensity = int((alpha / 255) * 30)
if intensity > 255:
intensity = 255
elif intensity < 0:
intensity = 0
size = [int(size[0]), int(size[1])]
if fancy == False:
tnt = list(pygame.transform.average_color(canvas, [0, 0, 50, 50]))[:3]
resolution = resolution # percentage of pixels per inch to use. If one inch is 300 pixels, use 150 is var is set to 50%
r = (resolution / 100.0) * inch2pix(1)
inches_w = size[0] / inch2pix(1)
r2 = inches_w * r
resolution = (r2 / size[0]) * 100
smooth_pad = 0
if anti_glitch == True:
smooth_pad = 5
if fancy == False:
smooth_pad = 0
s = pygame.Surface([size[0] + int(2 * smooth_pad), size[1] + int(2 * smooth_pad)]) # , pygame.SRCALPHA)
if fancy == True:
s.blit(canvas, [0, 0], [pos[0] - smooth_pad, pos[1] - smooth_pad, size[0] + smooth_pad * 2,
size[1] + smooth_pad * 2]) # , special_flags=pygame.BLEND_RGBA_ADD)
s = pygame.transform.rotozoom(s, 0, (resolution / 100.0) * 1)
size2 = s.get_size()
if tint != False:
pygame.gfxdraw.filled_polygon(s, [[0, 0], [size2[0], 0], size2, [0, size2[1]]], tint + [intensity])
if mode == "light":
pygame.gfxdraw.filled_polygon(s, [[0, 0], [size2[0], 0], size2, [0, size2[1]]],
[255, 255, 255] + [int(70 * (alpha / 255))])
rad = radius
b = pygame.image.tostring(s, "RGBA", False)
b = PIL.Image.frombytes("RGBA", size2, b)
# b = replace_color(b, [0, 0, 0], [255, 0, 0])
b = b.filter(PIL.ImageFilter.GaussianBlur(radius=int(rad)))
# b = b.crop((smooth_pad, smooth_pad, size2[0] - smooth_pad, size2[1] - smooth_pad))
# maxsize = (size)
# b.thumbnail(maxsize, PIL.Image.ANTIALIAS)
if size[0] <= 0:
size[0] = 1
if size[1] <= 0:
size[1] = 1
b = b.resize(size)
if rounded != 0:
b = imtools.round_image(b, {}, False, None, rounded, 255, back_color="#00000000")
b = pygame.image.frombuffer(b.tobytes(), b.size, b.mode).convert_alpha()
else:
pass
"""
s.blit(canvas, [0, 0], [pos[0], pos[1], size[0], size[1]])
size2 = size
pygame.gfxdraw.filled_polygon(s, [[0, 0], [size2[0], 0], size2, [0, size2[1]]], tint + [200])
b = s
"""
# pygame.draw.rect(canvas, [0, 200, 0], [pos[0], pos[1], size[0], size[1]])
if shadow_enabled == True:
shadow_default = inch2pix(0.1)
shadow_width = int(shadow_default * shadow_size)
# Corners
shadow_alpha = int((alpha / 255) * 150)
s_cornera = s_corner.copy()
s_cornera.set_alpha(shadow_alpha)
scaled_corner = pygame.transform.scale(s_cornera, [shadow_width, shadow_width])
# TR
canvas.blit(scaled_corner, [pos[0] - shadow_width, pos[1] - shadow_width])
# TL
canvas.blit(pygame.transform.rotate(scaled_corner, -90), [pos[0] + size[0], pos[1] - shadow_width])
# BR
canvas.blit(pygame.transform.rotate(scaled_corner, -180), [pos[0] + size[0], pos[1] + size[1]])
# BL
canvas.blit(pygame.transform.rotate(scaled_corner, 90), [pos[0] - shadow_width, pos[1] + size[1]])
# edges
s_edgea = s_edge.copy()
s_edgea.set_alpha(shadow_alpha)
# R
scaled_r = pygame.transform.scale(s_edgea, [shadow_width, size[1]])
canvas.blit(scaled_r, [pos[0] - shadow_width, pos[1]])
# T
rotated_t = pygame.transform.rotate(s_edgea, -90) # pygame.transform.rotozoom(s_edge, -90, 1)
canvas.blit(pygame.transform.scale(rotated_t, [size[0], shadow_width]), [pos[0], pos[1] - shadow_width])
# L
rotated_l = pygame.transform.flip(s_edgea, True, False)
canvas.blit(pygame.transform.scale(rotated_l, [shadow_width, size[1]]), [pos[0] + size[0], pos[1]])
# B
rotated_b = pygame.transform.rotate(s_edgea, 90)
canvas.blit(pygame.transform.scale(rotated_b, [size[0], shadow_width]), [pos[0], pos[1] + size[1]])
# b = pygame.transform.rotozoom(b, 0, (100.0 / resolution) * 1)
# if fancy == True:
# b = pygame.transform.scale(b, size)
if fancy == True:
b.set_alpha(alpha)
canvas.blit(b, pos) # , special_flags=pygame.BLEND_RGBA_ADD)
else:
"""
pygame.gfxdraw.filled_polygon(canvas, [pos,
[pos[0] + size[0], pos[1]],
[pos[0] + size[0], pos[1] + size[1]],
[pos[0], pos[1] + size[1]]], tint + [int(50 * (alpha / 255))])
"""
if mode == "light":
pygame.gfxdraw.filled_polygon(canvas, [pos,
[pos[0] + size[0], pos[1]],
[pos[0] + size[0], pos[1] + size[1]],
[pos[0], pos[1] + size[1]]],
[255, 255, 255] + [int(255 * (alpha / 255))])
else:
pygame.gfxdraw.filled_polygon(canvas, [pos,
[pos[0] + size[0], pos[1]],
[pos[0] + size[0], pos[1] + size[1]],
[pos[0], pos[1] + size[1]]],
[50, 50, 50] + [int(255 * (alpha / 255))])
"""
pygame.gfxdraw.filled_polygon(canvas, [pos,
[pos[0] + size[0], pos[1]],
[pos[0] + size[0], pos[1] + size[1]],
[pos[0], pos[1] + size[1]]], tnt + [int(100 * (alpha / 255))])
"""
def replace_color(img, color):
data = np.array(img)
red, green, blue, alpha = data.T
replaced_areas = (alpha != 0)
data[..., :][replaced_areas.T] = tuple(color + [255])
img2 = Image.fromarray(data)
return img2
def add_shadow(surface):
new_surf = pygame.Surface([surface.get_width() + 15, surface.get_height() + 15], pygame.SRCALPHA)
drop_shadow(new_surf, surface, [3, 3], alpha=80)
new_surf.blit(surface, [8, 8], special_flags=pygame.BLEND_RGBA_ADD)
return new_surf
def drop_shadow(canvas, surface, posit, radius=2, alpha=255, resolution=100):
global fancy, mode
intensity = int((alpha / 255) * 30)
if intensity > 255:
intensity = 255
elif intensity < 0:
intensity = 0
size = surface.get_size()
resolution = resolution # percentage of pixels per inch to use. If one inch is 300 pixels, use 150 is var is set to 50%
r = (resolution / 100.0) * inch2pix(1)
inches_w = size[0] / inch2pix(1)
r2 = inches_w * r
resolution = (r2 / size[0]) * 100
s = pygame.Surface([size[0] + int((100 / resolution) * radius * 3), size[1] + int((100 / resolution) * radius * 3)],
pygame.SRCALPHA)
s.blit(surface, [int((100 / resolution) * radius), int((100 / resolution) * radius)])
size = s.get_size()
s = pygame.transform.rotozoom(s, 0, (resolution / 100.0) * 1)
size2 = s.get_size()
rad = radius
b = pygame.image.tostring(s, "RGBA", False)
b = PIL.Image.frombytes("RGBA", size2, b)
b = replace_color(b, [0, 0, 0])
b = b.filter(PIL.ImageFilter.GaussianBlur(radius=int(rad)))
# b = b.crop((smooth_pad, smooth_pad, size2[0] - smooth_pad, size2[1] - smooth_pad))
if size[0] <= 0:
size[0] = 1
if size[1] <= 0:
size[1] = 1
b = b.resize(size)
b = pygame.image.frombuffer(b.tobytes(), b.size, b.mode).convert_alpha()
b.set_alpha(int(80 * (alpha / 255)))
canvas.blit(b, [posit[0] - int(int((100 / resolution) * (radius / 2))),
posit[1] - int((100 / resolution) * int(radius / 2))])
def noise(size, color, transparency, difference_range):
"""size, color, transparency (0-255), difference range"""
clear = pygame.Surface(size)
b = pygame.image.tostring(clear, "RGBA", False)
UI = PIL.Image.frombytes("RGBA", size, b)
UI = UI.convert("RGBA")
UIpix = UI.load()
for x in range(size[0]):
for y in range(size[1]):
random_color = [color[0] + random.randrange(-difference_range, difference_range),
color[1] + random.randrange(-difference_range, difference_range),
color[2] + random.randrange(-difference_range, difference_range), transparency]
if random_color[0] < 0 or random_color[0] > 255:
random_color[0] = color[0]
if random_color[1] < 0 or random_color[1] > 255:
random_color[1] = color[1]
if random_color[2] < 0 or random_color[2] > 255:
random_color[2] = color[2]
random_color = tuple(random_color)
UIpix[x, y] = random_color
UI = pygame.image.frombuffer(UI.tobytes(), UI.size, UI.mode).convert_alpha()
return UI
font_names = {}
class fakefont:
def __init__(self, font_name, font_size):
self.font = pygame.font.Font(font_name, font_size)
self.texts = {}
def render(self, text, alias, color):
if text not in self.texts:
text_surface = self.font.render(text, alias, color)
self.texts.update({text: text_surface})
return text_surface
else:
return self.texts[text]
font_scale = 1
def font(font_name, size):
global font_names
font_size = int(size * font_scale)
##print(font_names)
if font_name not in font_names:
font = fonter(font_name, font_size) # pygame.font.Font
##print("new name")
font_names.update({font_name: {font_size: font}})
elif font_name in font_names:
current_font_name = font_names[font_name]
if font_size not in current_font_name:
font = fonter(font_name, font_size) # pygame.font.Font
font_names[font_name].update({font_size: font})
##print("new_size_needed")
elif font_size in current_font_name:
##print("font_exists")
font = current_font_name[font_size]
return font
class iris_efficient:
def __init__(self):
self.last_image = None
def draw(self, canvas, pos, size, tint, radius=10, shadow_enabled=True, shadow_size=0.08, alpha=255):
iris_light(canvas, pos, size, tint, old_img, radius=10, shadow_enabled=True, shadow_size=0.08, alpha=255)
def update():
pass
scale = 1
def set_scale(scale_factor):
global scale
scale = scale_factor
def get_ppi():
# root = tkinter.Tk()
# root.withdraw()
ppi = 96
sysDpi = ctypes.windll.user32.GetDpiForSystem()
sf = sysDpi / 96 # root.winfo_id()) / 96
ppi *= sf
return ppi
def init(scale_mode): # , tk, tk_root):
global WIDTH, HEIGHT, scalemode, ppi, font_scale # , tkinter, root
# root = tk_root
# tkinter = tk
scalemode = scale_mode
ppi = get_ppi()
def start_graphics(pg, assets):
global s_edge, s_corner, pygame, asset_dir, fonter
pygame = pg
import pygame.gfxdraw
class fonter(pygame.font.Font):
font.bold = False
font.italic = False
pygame.display.init()
pygame.font.init()
asset_dir = assets
s_corner = pygame.image.load(asset_dir + "shadows/corner.png").convert_alpha()
s_edge = pygame.image.load(asset_dir + "shadows/edge.png").convert_alpha()
def set_size(size):
global WIDTH, HEIGHT, scalemode, ppi
WIDTH, HEIGHT = size[0], size[1]
def inch2pix(inches):
return int(ppi * inches * scale)
def h(proportion):
global WIDTH, HEIGHT
if scalemode == "dpi":
p = (proportion) * ppi * scale
elif scalemode == "stretch":
p = float(proportion) * (HEIGHT / 600.0)
return int(p)
def w(proportion):
global WIDTH, HEIGHT
if scalemode == "dpi":
p = (proportion) * ppi * scale
elif scalemode == "stretch":
p = float(proportion) * (WIDTH / 900.0)
return int(p)