Skip to content

Commit

Permalink
Fade mouse cursor trace out. Only react to left mouse button
Browse files Browse the repository at this point in the history
  • Loading branch information
soerface committed Oct 31, 2024
1 parent 2f34d65 commit 8e2ecc9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions drinks_touch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
]

COLORS = {
"infragelb": (246, 198, 0),
"disabled": (50, 50, 50),
"infragelb": (246, 198, 0, 255),
"disabled": (50, 50, 50, 255),
}

if bn := os.environ.get("BUILD_NUMBER"):
Expand Down
4 changes: 2 additions & 2 deletions drinks_touch/elements/base_elm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def events(self, events, pos=None):
for child in self.children:
child.events(events, transformed_pos)

if event.type == pygame.MOUSEBUTTONDOWN:
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
if collides:
self.focus = True
else:
self.focus = False

elif event.type == pygame.MOUSEBUTTONUP:
elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
if not hasattr(self, "on_click"):
continue

Expand Down
19 changes: 13 additions & 6 deletions drinks_touch/overlays.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def _render_click_animation(self):
return
if radius_inner >= radius_outer:
return
# pygame.draw.circle(self.screen, self.color, self.click_pos, radius)
for angel in range(0, 360, 30):
start_pos = (
self.click_pos[0] + radius_inner * math.cos(math.radians(angel)),
Expand All @@ -49,8 +48,6 @@ def _render_click_animation(self):
self.click_pos[0] + radius_outer * math.cos(math.radians(angel)),
self.click_pos[1] + radius_outer * math.sin(math.radians(angel)),
)
# pygame.draw.circle(self.screen, (255, 0, 255), start_pos, 1)
# pygame.draw.circle(self.screen, (0, 255, 0), end_pos, 1)
pygame.draw.line(
self.screen,
self.color,
Expand All @@ -66,7 +63,17 @@ def _render_mouse_pos(self):

def _render_mouse_path(self):
if len(self.mouse_path) > 2:
pygame.draw.lines(self.screen, self.color, False, self.mouse_path, 1)
last_pos = self.mouse_path[0][1]
new_mouse_path = []
surface = pygame.Surface(self.screen.get_size(), pygame.SRCALPHA)
for i, (color, pos) in enumerate(self.mouse_path):
pygame.draw.line(surface, color, last_pos, pos, 1)
color = (color[0], color[1], color[2], max(0, color[3] - 30))
if color[3] > 0:
new_mouse_path.append((color, pos))
last_pos = pos
self.mouse_path = new_mouse_path
self.screen.blit(surface, (0, 0))

def events(self, events):
self.mouse_pressed = pygame.mouse.get_pressed()[0]
Expand All @@ -76,8 +83,8 @@ def events(self, events):
if event.type == pygame.MOUSEMOTION:
self.mouse_pos = event.pos
if self.mouse_pressed:
self.mouse_path.append(event.pos)
elif event.type == pygame.MOUSEBUTTONUP:
self.mouse_path.append((self.color, event.pos))
elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
self.click_pos = event.pos
self.reset()

Expand Down

0 comments on commit 8e2ecc9

Please sign in to comment.