diff --git a/src/editor.py b/src/editor.py index 94fa753..9806e0b 100644 --- a/src/editor.py +++ b/src/editor.py @@ -29,7 +29,8 @@ class Editor: self.running: bool = False self.image_handler: ImageHandler = ImageHandler(self.MAPS_DIR, self.MAP_SIZE) self.clock: pygame.time.Clock = pygame.time.Clock() - self.drag_pos: Optional[tuple[int, int]] = None + self.left_drag_pos: Optional[tuple[int, int]] = None + self.mid_drag_pos: Optional[tuple[int, int]] = None self.font: pygame.font.Font = pygame.font.SysFont("Ubuntu", 20) self.loading_font: pygame.font.Font = pygame.font.SysFont("Ubuntu", 30) self.zooms_texts: list[pygame.Surface] = list(map( @@ -54,6 +55,7 @@ class Editor: def process_events(self) -> None: events = pygame.event.get() + keys = pygame.key.get_pressed() for event in events: if event.type == pygame.QUIT: self.state = State.STOPPING @@ -69,12 +71,19 @@ class Editor: self.zoom_out() elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 2: - self.drag_pos = event.pos + self.mid_drag_pos = event.pos + elif event.button == 1 and keys[pygame.K_LCTRL]: + self.left_drag_pos = event.pos + elif event.button == 4: + self.zoom_in() + elif event.button == 5: + self.zoom_out() elif event.type == pygame.MOUSEBUTTONUP: if event.button == 2: - self.drag_pos = None + self.mid_drag_pos = None + elif event.button == 1: + self.left_drag_pos = None - keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.center[0] -= 4 / self.zoom if keys[pygame.K_RIGHT]: @@ -86,12 +95,16 @@ class Editor: mbtns = pygame.mouse.get_pressed() mpos = pygame.mouse.get_pos() - if mbtns[1]: - dx = mpos[0] - self.drag_pos[0] - dy = mpos[1] - self.drag_pos[1] + if mbtns[1] or (mbtns[0] and keys[pygame.K_LCTRL]): + drag_pos = self.mid_drag_pos if mbtns[1] else self.left_drag_pos + dx = mpos[0] - drag_pos[0] + dy = mpos[1] - drag_pos[1] self.center[0] -= dx / self.zoom self.center[1] -= dy / self.zoom - self.drag_pos = mpos + if mbtns[0] and keys[pygame.K_LCTRL]: + self.left_drag_pos = mpos + if mbtns[1]: + self.mid_drag_pos = mpos def render(self) -> None: self.win.fill((0, 0, 0))