crystalwindow 3.8.4__py3-none-any.whl → 3.8.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crystalwindow/__init__.py +2 -1
- crystalwindow/color_handler.py +123 -0
- crystalwindow/gui.py +0 -4
- crystalwindow/gui_ext.py +34 -16
- {crystalwindow-3.8.4.dist-info → crystalwindow-3.8.6.dist-info}/METADATA +1 -1
- {crystalwindow-3.8.4.dist-info → crystalwindow-3.8.6.dist-info}/RECORD +9 -8
- {crystalwindow-3.8.4.dist-info → crystalwindow-3.8.6.dist-info}/WHEEL +0 -0
- {crystalwindow-3.8.4.dist-info → crystalwindow-3.8.6.dist-info}/licenses/LICENSE +0 -0
- {crystalwindow-3.8.4.dist-info → crystalwindow-3.8.6.dist-info}/top_level.txt +0 -0
crystalwindow/__init__.py
CHANGED
|
@@ -44,6 +44,7 @@ from .draw_tool import CrystalDraw
|
|
|
44
44
|
# === Misc Helpers ===
|
|
45
45
|
from .fun_helpers import random_name, DebugOverlay
|
|
46
46
|
from .camera import Camera
|
|
47
|
+
from .color_handler import Colors, Color
|
|
47
48
|
|
|
48
49
|
# === 3D Engine ===
|
|
49
50
|
from .crystal3d import CW3D
|
|
@@ -81,7 +82,7 @@ __all__ = [
|
|
|
81
82
|
"gradient_rect", "CameraShake", "DrawHelper", "DrawTextManager", "CrystalDraw",
|
|
82
83
|
|
|
83
84
|
# --- Misc ---
|
|
84
|
-
"random_name", "DebugOverlay", "Camera",
|
|
85
|
+
"random_name", "DebugOverlay", "Camera", "Colors", "Color",
|
|
85
86
|
|
|
86
87
|
# --- 3D ---
|
|
87
88
|
"CW3D",
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# --------------------------------------
|
|
2
|
+
# CrystalWindow Color System v2.0
|
|
3
|
+
# --------------------------------------
|
|
4
|
+
|
|
5
|
+
class Colors:
|
|
6
|
+
# BASIC COLORS
|
|
7
|
+
Black = (0, 0, 0)
|
|
8
|
+
White = (255, 255, 255)
|
|
9
|
+
Red = (255, 0, 0)
|
|
10
|
+
Green = (0, 255, 0)
|
|
11
|
+
Blue = (0, 0, 255)
|
|
12
|
+
Yellow = (255, 255, 0)
|
|
13
|
+
Cyan = (0, 255, 255)
|
|
14
|
+
Magenta = (255, 0, 255)
|
|
15
|
+
Gray = (120, 120, 120)
|
|
16
|
+
DarkGray = (40, 40, 40)
|
|
17
|
+
|
|
18
|
+
# CRYSTALWINDOW CUSTOM
|
|
19
|
+
CrystalBlue = (87, 199, 255)
|
|
20
|
+
Accent = (87, 199, 255)
|
|
21
|
+
Success = (76, 255, 111)
|
|
22
|
+
Error = (255, 68, 68)
|
|
23
|
+
Transparent = (0, 0, 0, 0) # full alpha
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Color:
|
|
27
|
+
COLOR_NAMES = {name.lower(): value for name, value in Colors.__dict__.items()
|
|
28
|
+
if not name.startswith("__")}
|
|
29
|
+
|
|
30
|
+
def __init__(self, r=None, g=None, b=None, a=255, hex_value=None):
|
|
31
|
+
# -------------------------------------------------
|
|
32
|
+
# 1) raw tuple variable: Color(Blue)
|
|
33
|
+
# -------------------------------------------------
|
|
34
|
+
if isinstance(r, (tuple, list)):
|
|
35
|
+
if len(r) == 3: # rgb
|
|
36
|
+
self.r, self.g, self.b = r
|
|
37
|
+
self.a = a
|
|
38
|
+
elif len(r) == 4: # rgba
|
|
39
|
+
self.r, self.g, self.b, self.a = r
|
|
40
|
+
return
|
|
41
|
+
|
|
42
|
+
# -------------------------------------------------
|
|
43
|
+
# 2) name string: Color("blue")
|
|
44
|
+
# -------------------------------------------------
|
|
45
|
+
if isinstance(r, str):
|
|
46
|
+
name = r.lower()
|
|
47
|
+
if name not in self.COLOR_NAMES:
|
|
48
|
+
raise ValueError(f"unknown color name: {r}")
|
|
49
|
+
data = self.COLOR_NAMES[name]
|
|
50
|
+
if len(data) == 4:
|
|
51
|
+
self.r, self.g, self.b, self.a = data
|
|
52
|
+
else:
|
|
53
|
+
self.r, self.g, self.b = data
|
|
54
|
+
self.a = a
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
# -------------------------------------------------
|
|
58
|
+
# 3) HEX input
|
|
59
|
+
# -------------------------------------------------
|
|
60
|
+
if hex_value is not None:
|
|
61
|
+
self.r, self.g, self.b, self.a = self.hex_to_rgba(hex_value)
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
# -------------------------------------------------
|
|
65
|
+
# 4) manual RGB
|
|
66
|
+
# -------------------------------------------------
|
|
67
|
+
self.r = r or 0
|
|
68
|
+
self.g = g or 0
|
|
69
|
+
self.b = b or 0
|
|
70
|
+
self.a = a
|
|
71
|
+
|
|
72
|
+
# convert hex -> rgba
|
|
73
|
+
@staticmethod
|
|
74
|
+
def hex_to_rgba(hex_value: str):
|
|
75
|
+
hex_value = hex_value.replace("#", "")
|
|
76
|
+
if len(hex_value) == 6:
|
|
77
|
+
r = int(hex_value[0:2], 16)
|
|
78
|
+
g = int(hex_value[2:4], 16)
|
|
79
|
+
b = int(hex_value[4:6], 16)
|
|
80
|
+
a = 255
|
|
81
|
+
elif len(hex_value) == 8:
|
|
82
|
+
r = int(hex_value[0:2], 16)
|
|
83
|
+
g = int(hex_value[2:4], 16)
|
|
84
|
+
b = int(hex_value[4:6], 16)
|
|
85
|
+
a = int(hex_value[6:8], 16)
|
|
86
|
+
else:
|
|
87
|
+
raise ValueError("bad hex bruh")
|
|
88
|
+
return r, g, b, a
|
|
89
|
+
|
|
90
|
+
# return pygame-friendly color tuple
|
|
91
|
+
def to_tuple(self):
|
|
92
|
+
return (self.r, self.g, self.b, self.a)
|
|
93
|
+
|
|
94
|
+
# rgba -> hex
|
|
95
|
+
def to_hex(self):
|
|
96
|
+
return "#{:02X}{:02X}{:02X}{:02X}".format(self.r, self.g, self.b, self.a)
|
|
97
|
+
|
|
98
|
+
# quick alpha edit
|
|
99
|
+
def set_alpha(self, a):
|
|
100
|
+
self.a = max(0, min(255, a))
|
|
101
|
+
return self
|
|
102
|
+
|
|
103
|
+
# color math
|
|
104
|
+
def brighten(self, amt=30):
|
|
105
|
+
self.r = min(255, self.r + amt)
|
|
106
|
+
self.g = min(255, self.g + amt)
|
|
107
|
+
self.b = min(255, self.b + amt)
|
|
108
|
+
return self
|
|
109
|
+
|
|
110
|
+
def darken(self, amt=30):
|
|
111
|
+
self.r = max(0, self.r - amt)
|
|
112
|
+
self.g = max(0, self.g - amt)
|
|
113
|
+
self.b = max(0, self.b - amt)
|
|
114
|
+
return self
|
|
115
|
+
|
|
116
|
+
@staticmethod
|
|
117
|
+
def lerp(c1, c2, t: float):
|
|
118
|
+
"""blend between two colors"""
|
|
119
|
+
r = c1.r + (c2.r - c1.r) * t
|
|
120
|
+
g = c1.g + (c2.g - c1.g) * t
|
|
121
|
+
b = c1.b + (c2.b - c1.b) * t
|
|
122
|
+
a = c1.a + (c2.a - c1.a) * t
|
|
123
|
+
return Color(int(r), int(g), int(b), int(a))
|
crystalwindow/gui.py
CHANGED
|
@@ -9,10 +9,6 @@ def hex_to_rgb(hex_str):
|
|
|
9
9
|
hex_str = hex_str.lstrip("#")
|
|
10
10
|
return tuple(int(hex_str[i:i+2], 16) for i in (0, 2, 4))
|
|
11
11
|
|
|
12
|
-
def random_color():
|
|
13
|
-
"""Return a random RGB color"""
|
|
14
|
-
return (random.randint(0,255), random.randint(0,255), random.randint(0,255))
|
|
15
|
-
|
|
16
12
|
def lerp_color(c1, c2, t):
|
|
17
13
|
"""Linearly interpolate between two colors"""
|
|
18
14
|
return tuple(int(a + (b-a)*t) for a,b in zip(c1,c2))
|
crystalwindow/gui_ext.py
CHANGED
|
@@ -3,35 +3,48 @@ from .window import Window
|
|
|
3
3
|
from .assets import load_image
|
|
4
4
|
from .sprites import Sprite
|
|
5
5
|
from .gui import Button
|
|
6
|
+
from .color_handler import Colors, Color
|
|
7
|
+
|
|
8
|
+
def parse_color(c):
|
|
9
|
+
if isinstance(c, tuple):
|
|
10
|
+
return c
|
|
11
|
+
if isinstance(c, Color):
|
|
12
|
+
return c.to_tuple()
|
|
13
|
+
if isinstance(c, str):
|
|
14
|
+
if hasattr(Colors, c):
|
|
15
|
+
return getattr(Colors, c).to_tuple()
|
|
16
|
+
return (255,255,255)
|
|
17
|
+
return (255,255,255)
|
|
6
18
|
|
|
7
19
|
class Toggle:
|
|
8
|
-
def __init__(self, rect, value=False, color=
|
|
9
|
-
# rect = (x, y, w, h)
|
|
20
|
+
def __init__(self, rect, value=False, color="gray", hover_color="white", cooldown=0.1):
|
|
10
21
|
self.rect = rect
|
|
11
22
|
self.value = value
|
|
12
|
-
|
|
13
|
-
self.
|
|
23
|
+
|
|
24
|
+
self.color = parse_color(color)
|
|
25
|
+
self.hover_color = parse_color(hover_color)
|
|
26
|
+
|
|
14
27
|
self.hovered = False
|
|
15
28
|
self.cooldown = cooldown
|
|
16
|
-
self._last_toggle = 0
|
|
29
|
+
self._last_toggle = 0
|
|
17
30
|
|
|
18
31
|
def update(self, win: Window):
|
|
19
32
|
mx, my = win.mouse_pos
|
|
20
33
|
x, y, w, h = self.rect
|
|
21
34
|
self.hovered = x <= mx <= x + w and y <= my <= y + h
|
|
22
35
|
|
|
23
|
-
# check cooldown timer
|
|
24
36
|
now = time.time()
|
|
25
37
|
can_toggle = now - self._last_toggle >= self.cooldown
|
|
26
38
|
|
|
27
39
|
if self.hovered and win.mouse_pressed(1) and can_toggle:
|
|
28
40
|
self.value = not self.value
|
|
29
|
-
self._last_toggle = now
|
|
41
|
+
self._last_toggle = now
|
|
30
42
|
|
|
31
43
|
def draw(self, win: Window):
|
|
32
44
|
draw_color = self.hover_color if self.hovered else self.color
|
|
33
45
|
win.draw_rect(draw_color, self.rect)
|
|
34
|
-
|
|
46
|
+
|
|
47
|
+
# ON glow
|
|
35
48
|
if self.value:
|
|
36
49
|
inner = (
|
|
37
50
|
self.rect[0] + 4,
|
|
@@ -43,13 +56,15 @@ class Toggle:
|
|
|
43
56
|
|
|
44
57
|
|
|
45
58
|
class Slider:
|
|
46
|
-
def __init__(self, rect, min_val=0, max_val=100, value=50, color=
|
|
47
|
-
# rect = (x, y, w, h)
|
|
59
|
+
def __init__(self, rect, min_val=0, max_val=100, value=50, color="lightgray", handle_color="red", handle_radius=10):
|
|
48
60
|
self.rect = rect
|
|
49
61
|
self.min_val = min_val
|
|
50
62
|
self.max_val = max_val
|
|
51
63
|
self.value = value
|
|
52
|
-
|
|
64
|
+
|
|
65
|
+
self.color = parse_color(color)
|
|
66
|
+
self.handle_color = parse_color(handle_color)
|
|
67
|
+
|
|
53
68
|
self.handle_radius = handle_radius
|
|
54
69
|
self.dragging = False
|
|
55
70
|
|
|
@@ -60,21 +75,24 @@ class Slider:
|
|
|
60
75
|
handle_x = x + ((self.value - self.min_val) / (self.max_val - self.min_val)) * w
|
|
61
76
|
handle_y = y + h // 2
|
|
62
77
|
|
|
63
|
-
# start drag if mouse clicks inside slider bar area
|
|
64
78
|
if win.mouse_pressed(1):
|
|
65
79
|
if not self.dragging and (x <= mx <= x+w and y <= my <= y+h):
|
|
66
80
|
self.dragging = True
|
|
67
81
|
else:
|
|
68
|
-
self.dragging = False
|
|
82
|
+
self.dragging = False
|
|
69
83
|
|
|
70
|
-
# update value while dragging
|
|
71
84
|
if self.dragging:
|
|
72
|
-
rel_x = max(0, min(mx - x, w))
|
|
85
|
+
rel_x = max(0, min(mx - x, w))
|
|
73
86
|
self.value = self.min_val + (rel_x / w) * (self.max_val - self.min_val)
|
|
74
87
|
|
|
75
88
|
def draw(self, win: Window):
|
|
76
89
|
x, y, w, h = self.rect
|
|
90
|
+
|
|
91
|
+
# bar
|
|
77
92
|
win.draw_rect(self.color, (x, y + h//2 - 2, w, 4))
|
|
93
|
+
|
|
94
|
+
# handle
|
|
78
95
|
handle_x = x + ((self.value - self.min_val) / (self.max_val - self.min_val)) * w
|
|
79
96
|
handle_y = y + h // 2
|
|
80
|
-
|
|
97
|
+
|
|
98
|
+
win.draw_circle(self.handle_color, (int(handle_x), int(handle_y)), self.handle_radius)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: crystalwindow
|
|
3
|
-
Version: 3.8.
|
|
3
|
+
Version: 3.8.6
|
|
4
4
|
Summary: A Tkinter powered window + GUI toolkit made by Crystal (MEEEEEE)! Easier apps, smoother UI and all-in-one helpers!
|
|
5
5
|
Home-page: https://pypi.org/project/crystalwindow/
|
|
6
6
|
Author: CrystalBallyHereXD
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
crystalwindow/FileHelper.py,sha256=aUnnRG7UwvzJt-idjWjmpwy3RM6nqLlC3-7Bae6Yb94,5471
|
|
2
|
-
crystalwindow/__init__.py,sha256=
|
|
2
|
+
crystalwindow/__init__.py,sha256=Ugp3GLsfYK_OAA8J9WnGc95P4Uev5fAePmzNNXmpSKQ,2144
|
|
3
3
|
crystalwindow/animation.py,sha256=zHjrdBXQeyNaLAuaGPldJueX05OZ5j31YR8NizmR0uQ,427
|
|
4
4
|
crystalwindow/assets.py,sha256=2Cj0zdhMWo3mWjdr9KU5n-9_8iKj_fJ9uShMFA-27HU,5193
|
|
5
5
|
crystalwindow/camera.py,sha256=tbn4X-jxMIszAUg3Iu-89gJN5nij0mjPMEzGotcLbJI,712
|
|
6
6
|
crystalwindow/clock.py,sha256=iryeURnfXx6TIDyJhpxe0KkeSaHCdxrMckN6Tby00i0,461
|
|
7
7
|
crystalwindow/collision.py,sha256=hpkHTp_KparghVK-itp_rxuYdd2GbQMxICHlUBv0rSw,472
|
|
8
|
+
crystalwindow/color_handler.py,sha256=ZnXnz8552GPiRAnCkW_8wycwRRMAaFRFLlCcsrv0j2E,4071
|
|
8
9
|
crystalwindow/crystal3d.py,sha256=-Te9IJgbtzl8Mpuc4BPi2bn2apnvBNTI2GwxSLd8sqg,2006
|
|
9
10
|
crystalwindow/draw_helpers.py,sha256=HqjI5fTbdnA55g4LKYEuMUdIjrWaBm2U8RmeUXjcQGw,821
|
|
10
11
|
crystalwindow/draw_rects.py,sha256=o7siET3y35N2LPeNBGe8QhsQbOH8J-xF6fOUz07rymU,1484
|
|
@@ -12,8 +13,8 @@ crystalwindow/draw_text_helper.py,sha256=qv5fFCuTCKWeGDk9Z_ZpOzrTFP8YYwlgQrrorwr
|
|
|
12
13
|
crystalwindow/draw_tool.py,sha256=1YYEqjmgt4HpV3S15sTjCSmcqgHup4fD8gskTkxU0t4,1638
|
|
13
14
|
crystalwindow/fun_helpers.py,sha256=fo5yTwGENltdtVIVwgITtUkvzpsImujOcqTxe8XPzR8,760
|
|
14
15
|
crystalwindow/gravity.py,sha256=pZJykZzO-mKVBPsZRP55nnlvUoYQfR29wPgJcI4IbBs,2904
|
|
15
|
-
crystalwindow/gui.py,sha256=
|
|
16
|
-
crystalwindow/gui_ext.py,sha256=
|
|
16
|
+
crystalwindow/gui.py,sha256=vqI2Qpus0RHEwEsef0gojXb54yOFo6p-9TnDF4bEnSg,3538
|
|
17
|
+
crystalwindow/gui_ext.py,sha256=aOZ5Fa0VoBJd3SiEW2zgH2Sw1NwnK2mW1YtGdJijDVg,3045
|
|
17
18
|
crystalwindow/math.py,sha256=slOY3KQZ99VDMUMxsSJabMyRtJcwVzEyxR2RoXspHho,963
|
|
18
19
|
crystalwindow/player.py,sha256=4wpIdUZLTlRXV8fDRQ11yVJRbx_cv8Ekpn2y7pQGgAQ,3442
|
|
19
20
|
crystalwindow/sprites.py,sha256=2kYW4QfSnyUwRLedZCkb99wUSxn2a0JdWOHcfkxcG0U,3411
|
|
@@ -31,8 +32,8 @@ crystalwindow/gametests/guitesting.py,sha256=SrOssY5peCQEV6TQ1AiOWtjb9phVGdRzW-Q
|
|
|
31
32
|
crystalwindow/gametests/sandbox.py,sha256=Oo2tU2N0y3BPVa6T5vs_h9N6islhQrjSrr_78XLut5I,1007
|
|
32
33
|
crystalwindow/gametests/squaremove.py,sha256=poP2Zjl2oc2HVvIAgIK34H2jVj6otL4jEdvAOR6L9sI,572
|
|
33
34
|
crystalwindow/gametests/windowtesting.py,sha256=_9X6wnV1-_X_PtNS-0zu-k209NtFIwAc4vpxLPp7V2o,97
|
|
34
|
-
crystalwindow-3.8.
|
|
35
|
-
crystalwindow-3.8.
|
|
36
|
-
crystalwindow-3.8.
|
|
37
|
-
crystalwindow-3.8.
|
|
38
|
-
crystalwindow-3.8.
|
|
35
|
+
crystalwindow-3.8.6.dist-info/licenses/LICENSE,sha256=Gt5cJRchdNt0guxyQMHKsATN5PM5mjuDhdO6Gzs9qQc,1096
|
|
36
|
+
crystalwindow-3.8.6.dist-info/METADATA,sha256=VooxfUadE7ciIboTfZUUwY0N8FVaaLX5pm7pg3kivlo,7340
|
|
37
|
+
crystalwindow-3.8.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
38
|
+
crystalwindow-3.8.6.dist-info/top_level.txt,sha256=PeQSld4b19XWT-zvbYkvE2Xg8sakIMbDzSzSdOSRN8o,14
|
|
39
|
+
crystalwindow-3.8.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|