|
5 | 5 | import sys
|
6 | 6 | import os
|
7 | 7 | import time
|
| 8 | +import math |
8 | 9 | from enum import Enum
|
9 | 10 | import pygame
|
10 | 11 |
|
|
27 | 28 |
|
28 | 29 | # Delays to control the speed of the text
|
29 | 30 | # Default
|
30 |
| -CHARACTER_DELAY = 0.03 |
31 |
| -WORD_DELAY = 0.2 |
32 |
| -SENTENCE_DELAY = 1 |
33 |
| -PARAGRAPH_DELAY = 2 |
| 31 | +#CHARACTER_DELAY = 0.03 |
| 32 | +#WORD_DELAY = 0.2 |
| 33 | +#SENTENCE_DELAY = 1 |
| 34 | +#PARAGRAPH_DELAY = 2 |
34 | 35 |
|
35 | 36 | # Letter by Letter
|
36 | 37 | # CHARACTER_DELAY = 0.1
|
|
45 | 46 | # PARAGRAPH_DELAY = 0
|
46 | 47 |
|
47 | 48 | # No Delays
|
48 |
| -# CHARACTER_DELAY = 0 |
49 |
| -# WORD_DELAY = 0 |
50 |
| -# SENTENCE_DELAY = 0 |
51 |
| -# PARAGRAPH_DELAY = 0 |
| 49 | +CHARACTER_DELAY = 0 |
| 50 | +WORD_DELAY = 0 |
| 51 | +SENTENCE_DELAY = 0 |
| 52 | +PARAGRAPH_DELAY = 0 |
52 | 53 |
|
53 | 54 |
|
54 | 55 | # Whitespace Settings in Pixels
|
@@ -182,14 +183,25 @@ def handle_events(self):
|
182 | 183 | raise SystemExit
|
183 | 184 | if event.type == pygame.MOUSEBUTTONDOWN:
|
184 | 185 | if event.button == 1:
|
185 |
| - # If clicked in text area and book is still rendering, skip to the end |
186 |
| - print(f"Left mouse button pressed at {event.pos}") |
187 | 186 | # If button pressed while visible, trigger action
|
188 |
| - if self.back_button.is_in_bounds(event.pos): |
189 |
| - self.back_button.action() |
190 |
| - elif event.type == pygame.MOUSEBUTTONUP: |
191 |
| - # Not sure if we will need this |
192 |
| - print("Mouse button has been released") |
| 187 | + coords = self.rotate_mouse_pos(event.pos) |
| 188 | + for button in [self.back_button, self.next_button]: |
| 189 | + if button.is_in_bounds(coords): |
| 190 | + button.action() |
| 191 | + |
| 192 | + def rotate_mouse_pos(self, point): |
| 193 | + # Recalculate the mouse position based on the rotation of the screen |
| 194 | + # So that we have the coordinates relative to the upper left corner of the screen |
| 195 | + angle = 360 - self.rotation |
| 196 | + y, x = point |
| 197 | + x -= self.width // 2 |
| 198 | + y -= self.height // 2 |
| 199 | + x, y = x * math.sin(math.radians(angle)) + y * math.cos( |
| 200 | + math.radians(angle) |
| 201 | + ), x * math.cos(math.radians(angle)) - y * math.sin(math.radians(angle)) |
| 202 | + x += self.width // 2 |
| 203 | + y += self.height // 2 |
| 204 | + return (round(x), round(y)) |
193 | 205 |
|
194 | 206 | def add_page(self, paragraph=0, word=0):
|
195 | 207 | # Add rendered page information to make flipping between them easier
|
|
0 commit comments